Repository: League-of-Foundry-Developers/foundry-vtt-types
Pull request #2656 (2024-07-20 16:09:25)

V12/329
Updates for 12.329 as well as a number of fixes in previous typings


Patch:
diff --git a/package.json b/package.json
index 78c14e2ed..2e727be5b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "$schema": "https://json.schemastore.org/package.json",
   "name": "@league-of-foundry-developers/foundry-vtt-types",
-  "version": "12.328.0",
+  "version": "12.329.0",
   "description": "TypeScript type definitions for Foundry VTT",
   "type": "module",
   "exports": {
diff --git a/src/foundry/client-esm/applications/elements/document-tags.d.mts b/src/foundry/client-esm/applications/elements/document-tags.d.mts
index 55ea7d6e1..8d582e66f 100644
--- a/src/foundry/client-esm/applications/elements/document-tags.d.mts
+++ b/src/foundry/client-esm/applications/elements/document-tags.d.mts
@@ -7,7 +7,7 @@ import AbstractFormInputElement from "./form-element.mjs";
 declare class HTMLDocumentTagsElement extends AbstractFormInputElement<Record<string, string> | string | string[]> {
   constructor();
 
-  _value: {};
+  protected _value: Record<string, string>;
 
   set type(value: string);
 
@@ -53,13 +53,13 @@ declare class HTMLDocumentTagsElement extends AbstractFormInputElement<Record<st
    * @param document - A candidate document or compendium index entry to tag
    * @throws An error if the candidate document is not allowed
    */
-  _validateDocument(document: foundry.abstract.Document.Any | object): void;
+  _validateDocument(document: foundry.abstract.Document.Any | Record<string, unknown>): void;
 
   protected override _getValue(): string | string[];
 
   protected override _setValue(value: string | string[]): void;
 
-  protected override _toggleDisabled(disabled: any): void;
+  protected override _toggleDisabled(disabled: boolean): void;
 
   /**
    * Create a HTMLDocumentTagsElement using provided configuration data.
diff --git a/src/foundry/client-esm/applications/elements/file-picker.d.mts b/src/foundry/client-esm/applications/elements/file-picker.d.mts
index 5a534eb8c..0c015495e 100644
--- a/src/foundry/client-esm/applications/elements/file-picker.d.mts
+++ b/src/foundry/client-esm/applications/elements/file-picker.d.mts
@@ -39,11 +39,11 @@ declare class HTMLFilePickerElement extends AbstractFormInputElement<string> {
 
   protected override _buildElements(): (HTMLInputElement | HTMLButtonElement)[];
 
-  protected override _toggleDisabled(disabled: any): void;
+  protected override _toggleDisabled(disabled: boolean): void;
 
   protected override _activateListeners(): void;
 
-  protected override _onClick(event: any): void;
+  protected override _onClick(event: PointerEvent): void;
 
   /**
    * Create a HTMLFilePickerElement using provided configuration data.
diff --git a/src/foundry/client-esm/applications/elements/form-element.d.mts b/src/foundry/client-esm/applications/elements/form-element.d.mts
index dd70bf2e4..38bb547d3 100644
--- a/src/foundry/client-esm/applications/elements/form-element.d.mts
+++ b/src/foundry/client-esm/applications/elements/form-element.d.mts
@@ -1,7 +1,7 @@
 /**
  * An abstract custom HTMLElement designed for use with form inputs.
- * @fires {Event} input           An "input" event when the value of the input changes
- * @fires {Event} change          A "change" event when the value of the element changes
+ * @remarks Fires input  - An "input" event when the value of the input changes
+ * @remarks Fires change - A "change" event when the value of the element changes
  */
 export default abstract class AbstractFormInputElement<FormInputValueType> extends HTMLElement {
   constructor();
@@ -91,7 +91,7 @@ export default abstract class AbstractFormInputElement<FormInputValueType> exten
    * Apply key attributes on the containing custom HTML element to input elements contained within it.
    * @internal
    */
-  protected _applyInputAttributes(input: any): void;
+  protected _applyInputAttributes(input: HTMLInputElement): void;
 
   /**
    * Activate event listeners which add dynamic behavior to the custom element.
diff --git a/src/foundry/client-esm/applications/elements/hue-slider.d.mts b/src/foundry/client-esm/applications/elements/hue-slider.d.mts
index eb7f13074..51f6195ce 100644
--- a/src/foundry/client-esm/applications/elements/hue-slider.d.mts
+++ b/src/foundry/client-esm/applications/elements/hue-slider.d.mts
@@ -14,7 +14,7 @@ export default class HTMLHueSelectorSlider extends AbstractFormInputElement<numb
 
   protected override _activateListeners(): void;
 
-  protected override _setValue(value: any): void;
+  protected override _setValue(value: number): void;
 
-  protected override _toggleDisabled(disabled: any): void;
+  protected override _toggleDisabled(disabled: boolean): void;
 }
diff --git a/src/foundry/client-esm/applications/elements/multi-select.d.mts b/src/foundry/client-esm/applications/elements/multi-select.d.mts
index 7ae5afbcc..07df9bd3a 100644
--- a/src/foundry/client-esm/applications/elements/multi-select.d.mts
+++ b/src/foundry/client-esm/applications/elements/multi-select.d.mts
@@ -8,26 +8,30 @@ import AbstractFormInputElement from "./form-element.mjs";
  */
 export class AbstractMultiSelectElement extends AbstractFormInputElement<Set<string> | string[]> {
   constructor();
-  _value: Set<any>;
+
+  protected _value: Set<string>;
+
   /**
    * Predefined <option> and <optgroup> elements which were defined in the original HTML.
    */
   protected _options: (HTMLOptionElement | HTMLOptGroupElement)[];
+
   /**
    * An object which maps option values to displayed labels.
    */
-  protected _choices: {
-    [x: string]: string;
-  };
+  protected _choices: Record<string, string>;
+
   /**
    * Preserve existing <option> and <optgroup> elements which are defined in the original HTML.
    */
   protected _initialize(): void;
+
   /**
    * Mark a choice as selected.
    * @param value - The value to add to the chosen set
    */
   select(value: string): void;
+
   /**
    * Mark a choice as un-selected.
    * @param value - The value to delete from the chosen set
@@ -64,7 +68,7 @@ export class HTMLMultiSelectElement extends AbstractMultiSelectElement {
 
   protected override _buildElements(): (HTMLDivElement | HTMLSelectElement)[];
 
-  protected override _toggleDisabled(disabled: any): void;
+  protected override _toggleDisabled(disabled: boolean): void;
 }
 /**
  * Provide a multi-select workflow as a grid of input checkbox elements.
@@ -87,5 +91,5 @@ export class HTMLMultiSelectElement extends AbstractMultiSelectElement {
 export class HTMLMultiCheckboxElement extends AbstractMultiSelectElement {
   protected override _buildElements(): (HTMLFieldSetElement | HTMLLabelElement)[];
 
-  protected override _toggleDisabled(disabled: any): void;
+  protected override _toggleDisabled(disabled: boolean): void;
 }
diff --git a/src/foundry/client-esm/applications/elements/prosemirror-editor.d.mts b/src/foundry/client-esm/applications/elements/prosemirror-editor.d.mts
index 30d0a6237..2bfef541f 100644
--- a/src/foundry/client-esm/applications/elements/prosemirror-editor.d.mts
+++ b/src/foundry/client-esm/applications/elements/prosemirror-editor.d.mts
@@ -10,6 +10,9 @@ declare class HTMLProseMirrorElement extends AbstractFormInputElement<string> {
 
   static override tagName: "prose-mirror";
 
+  /**
+   * Actions to take when the custom element is removed from the document.
+   */
   disconnectedCallback(): void;
 
   override _buildElements(): (HTMLButtonElement | HTMLDivElement)[];
@@ -39,6 +42,9 @@ declare namespace HTMLProseMirrorElement {
     /** Does this editor instance support collaborative editing? */
     collaborate: boolean;
 
+    /** Should the editor be presented in compact mode? */
+    compact: boolean;
+
     /** A Document UUID. Required for collaborative editing */
     documentUUID: string;
   }
diff --git a/src/foundry/client-esm/applications/elements/string-tags.d.mts b/src/foundry/client-esm/applications/elements/string-tags.d.mts
index 880ef7f0a..77e2fe2ac 100644
--- a/src/foundry/client-esm/applications/elements/string-tags.d.mts
+++ b/src/foundry/client-esm/applications/elements/string-tags.d.mts
@@ -5,7 +5,7 @@ import AbstractFormInputElement from "./form-element.mjs";
  * A custom HTML element which allows for arbitrary assignment of a set of string tags.
  * This element may be used directly or subclassed to impose additional validation or functionality.
  */
-export default class HTMLStringTagsElement extends AbstractFormInputElement<Set<string> | string[]> {
+declare class HTMLStringTagsElement extends AbstractFormInputElement<Set<string> | string[]> {
   constructor();
 
   static override tagName: "string-tags";
@@ -60,5 +60,14 @@ export default class HTMLStringTagsElement extends AbstractFormInputElement<Set<
   /**
    * Create a HTMLStringTagsElement using provided configuration data.
    */
-  static create(config: FormInputConfig<Set<string> | string[]>): HTMLElement;
+  static create(config: HTMLStringTagsElement.StringTagsInputConfig): HTMLElement;
 }
+
+declare namespace HTMLStringTagsElement {
+  interface StringTagsInputConfig extends FormInputConfig<Set<string> | string[]> {
+    /** Automatically slugify provided strings? */
+    slug: boolean;
+  }
+}
+
+export default HTMLStringTagsElement;
diff --git a/src/foundry/client-esm/helpers/_types.d.mts b/src/foundry/client-esm/helpers/_types.d.mts
index 5ee346db8..73ea4f170 100644
--- a/src/foundry/client-esm/helpers/_types.d.mts
+++ b/src/foundry/client-esm/helpers/_types.d.mts
@@ -1,5 +1,51 @@
-export interface CompendiumArtInfo {}
+import type { SchemaField } from "../../common/data/fields.d.mts";
+import type { PrototypeToken } from "../data/_module.d.mts";
 
+export interface CompendiumArtInfo {
+  /**
+   * The path to the Actor's portrait image.
+   */
+  actor?: string | undefined;
+
+  /**
+   * The path to the token image, or an object to merge into the Actor's prototype token.
+   */
+  token?: string | SchemaField.InnerAssignmentType<PrototypeToken.Schema> | undefined;
+
+  /**
+   *An optional credit string for use by the game system to apply in an appropriate place.
+   */
+  credit?: string | undefined;
+}
+
+/**
+ * A mapping of compendium pack IDs to Document IDs to art information.
+ */
 export type CompendiumArtMapping = Record<string, Record<string, CompendiumArtInfo>>;
 
-export interface CompendiumArtDescriptor {}
+export interface CompendiumArtDescriptor {
+  /**
+   * The ID of the package providing the art.
+   */
+  packageId: string;
+
+  /**
+   * The title of the package providing the art.
+   */
+  title: string;
+
+  /**
+   * The path to the art mapping file.
+   */
+  mapping: string;
+
+  /**
+   * An optional credit string for use by the game system to apply in an appropriate place.
+   */
+  credit?: string | undefined;
+
+  /**
+   * The package's user-configured priority.
+   */
+  priority: number;
+}
diff --git a/src/foundry/client-esm/helpers/compendium-art.d.mts b/src/foundry/client-esm/helpers/compendium-art.d.mts
index b7c4cb8be..151f109ca 100644
--- a/src/foundry/client-esm/helpers/compendium-art.d.mts
+++ b/src/foundry/client-esm/helpers/compendium-art.d.mts
@@ -1,3 +1,47 @@
-declare class CompendiumArt extends Map {}
+import type { CompendiumArtDescriptor, CompendiumArtInfo, CompendiumArtMapping } from "./_types.d.mts";
+
+/**
+ * A class responsible for managing package-provided art and applying it to Documents in compendium packs.
+ */
+declare class CompendiumArt extends Map<string, CompendiumArtInfo> {
+  /**
+   * The key for the package manifest flag used to store the mapping information.
+   * @defaultValue `"compendiumArtMappings"`
+   */
+  readonly FLAG: string;
+
+  /**
+   * The key for the setting used to store the World's art preferences.
+   * @defaultValue `"compendiumArtConfiguration"`
+   */
+  readonly SETTING: string;
+
+  /**
+   * Whether art application is enabled. This should be switched off when performing client-side compendium migrations
+   * in order to avoid persisting injected data.
+   * @defaultValue `true`
+   */
+  enabled: boolean;
+
+  /**
+   * Retrieve all active packages that provide art mappings in priority order.
+   */
+  getPackages(): CompendiumArtDescriptor[];
+
+  /**
+   * Collate Document art mappings from active packages.
+   * @internal
+   */
+  _registerArt(): Promise<void>;
+
+  /**
+   * Parse a provided art mapping and store it for reference later, and update compendium indices to use the provided
+   * art.
+   * @param packageId - The ID of the package providing the mapping.
+   * @param mapping   - The art mapping information provided by the package.
+   * @param credit    - An optional credit string for use by the game system to apply in an appropriate place.
+   */
+  #parseArtMapping(packageId: string, mapping: CompendiumArtMapping, credit?: string): Promise<void>;
+}
 
 export default CompendiumArt;
diff --git a/src/foundry/common/abstract/module.d.mts b/src/foundry/common/abstract/module.d.mts
index 0e33e1c3a..3e711436b 100644
--- a/src/foundry/common/abstract/module.d.mts
+++ b/src/foundry/common/abstract/module.d.mts
@@ -1,6 +1,7 @@
 export { default as DataModel } from "./data.mts";
 export { default as TypeDataModel } from "./type-data.mts";
 export { default as Document } from "./document.mts";
+export { default as DocumentSocketResponse } from "./socket.mts";
 export { default as DatabaseBackend } from "./backend.mts";
 export { default as EmbeddedCollection } from "./embedded-collection.mts";
 export { default as EmbeddedCollectionDelta } from "./embedded-collection-delta.mts";
diff --git a/src/foundry/common/abstract/socket.d.mts b/src/foundry/common/abstract/socket.d.mts
new file mode 100644
index 000000000..5c1fd560f
--- /dev/null
+++ b/src/foundry/common/abstract/socket.d.mts
@@ -0,0 +1,36 @@
+import type { DocumentType } from "../../../types/helperTypes.d.mts";
+import type { DatabaseAction, DatabaseOperation, DocumentSocketRequest } from "./_types.d.mts";
+
+/**
+ * The data structure of a modifyDocument socket response.
+ */
+declare class DocumentSocketResponse<Action extends DatabaseAction> {
+  /**
+   * Prepare a response for an incoming request.
+   * @param request - The incoming request that is being responded to
+   */
+  constructor(request: DocumentSocketRequest<Action>);
+
+  /** The type of Document being transacted. */
+  type: DocumentType | undefined;
+
+  /** The database action that was performed. */
+  action: Action | undefined;
+
+  /** Was this response broadcast to other connected clients? */
+  broadcast: boolean | undefined;
+
+  /** The database operation that was requested. */
+  operation: DatabaseOperation | undefined;
+
+  /** The identifier of the requesting user. */
+  userId: string | undefined;
+
+  /** The result of the request. Present if successful */
+  result: Record<string, unknown>[] | string[] | undefined;
+
+  /** An error that occurred. Present if unsuccessful */
+  error: Error | undefined;
+}
+
+export default DocumentSocketResponse;
diff --git a/src/foundry/common/utils/event-emitter.d.mts b/src/foundry/common/utils/event-emitter.d.mts
index e5037520a..de60a1e18 100644
--- a/src/foundry/common/utils/event-emitter.d.mts
+++ b/src/foundry/common/utils/event-emitter.d.mts
@@ -1,9 +1,5 @@
 import type { InexactPartial, Mixin } from "../../../types/utils.d.mts";
 
-declare global {
-  type EmittedEventListener = (event: Event) => any;
-}
-
 /**
  * A mixin class which implements the behavior of EventTarget.
  * This is useful in cases where a class wants EventTarget-like behavior but needs to extend some other class.
@@ -12,6 +8,7 @@ declare global {
 declare class EventEmitter {
   /** @privateRemarks All mixin classses should accept anything for its constructor. */
   constructor(...args: any[]);
+
   /**
    * An array of event types which are valid for this class.
    */
@@ -26,7 +23,7 @@ declare class EventEmitter {
    */
   addEventListener(
     type: string,
-    listener: EmittedEventListener,
+    listener: EventEmitter.EmittedEventListener,
     options?: InexactPartial<{
       /**
        * Should the event only be responded to once and then removed
@@ -41,7 +38,7 @@ declare class EventEmitter {
    * @param type     - The type of event being removed
    * @param listener - The listener function being removed
    */
-  removeEventListener(type: string, listener: EmittedEventListener): void;
+  removeEventListener(type: string, listener: EventEmitter.EmittedEventListener): void;
 
   /**
    * Dispatch an event on this target.
@@ -52,6 +49,10 @@ declare class EventEmitter {
   dispatchEvent(event: Event): boolean;
 }
 
+declare namespace EventEmitter {
+  type EmittedEventListener = (event: Event) => void;
+}
+
 /**
  * Augment a base class with EventEmitter behavior.
  * @param BaseClass - Some base class augmented with event emitter functionality


Test patch:
diff --git a/tests/foundry/client-esm/helpers/compendium-art.test-d.ts b/tests/foundry/client-esm/helpers/compendium-art.test-d.ts
new file mode 100644
index 000000000..7c6dfc6d5
--- /dev/null
+++ b/tests/foundry/client-esm/helpers/compendium-art.test-d.ts
@@ -0,0 +1,18 @@
+import { expectTypeOf } from "vitest";
+import { types } from "../../../../src/foundry/client-esm/helpers/_module.mjs";
+
+const caInfo = { actor: "actorId", token: { randomImg: false }, credit: "Me" };
+expectTypeOf(caInfo).toMatchTypeOf<types.CompendiumArtInfo>;
+
+// @ts-expect-error Should reject object not matching prototype tokens schema
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+const caError: types.CompendiumArtInfo = { token: { badKey: "1" } };
+
+const compendiumArt = new foundry.helpers.CompendiumArt([
+  ["test", caInfo],
+  ["2", { token: "a/path" }],
+]);
+expectTypeOf(compendiumArt.FLAG).toEqualTypeOf<string>;
+expectTypeOf(compendiumArt.SETTING).toEqualTypeOf<string>;
+expectTypeOf(compendiumArt.enabled).toEqualTypeOf<boolean>;
+expectTypeOf(compendiumArt.getPackages()).toEqualTypeOf<types.CompendiumArtDescriptor[]>;