Repository: League-of-Foundry-Developers/foundry-vtt-types
Pull request #2672 (2024-07-26 22:16:51)

Updated appv2 _types
Added missing interface contents


Patch:
diff --git a/src/foundry/client-esm/applications/_types.d.mts b/src/foundry/client-esm/applications/_types.d.mts
index db3f19d00..48f815804 100644
--- a/src/foundry/client-esm/applications/_types.d.mts
+++ b/src/foundry/client-esm/applications/_types.d.mts
@@ -17,7 +17,7 @@ interface ApplicationFormConfiguration extends ApplicationV2.FormConfiguration {
 
 interface ApplicationHeaderControlsEntry extends ApplicationV2.HeaderControlsEntry {}
 
-interface ApplicationConstructionParams extends ApplicationV2.ConstructionParams {}
+interface ApplicationConstructorParams extends ApplicationV2.ConstructorParams {}
 
 interface ApplicationRenderOptions extends ApplicationV2.RenderOptions {}
 
@@ -31,6 +31,8 @@ interface ApplicationFormSubmission extends ApplicationV2.FormSubmission {}
 
 interface ApplicationFormSubmission extends ApplicationV2.FormSubmission {}
 
-type FormNode = {};
+interface ApplicationTab extends ApplicationV2.Tab {}
 
-type FormFooterButton = {};
+interface FormNode extends ApplicationV2.FormNode {}
+
+interface FormFooterButton extends ApplicationV2.FormFooterButton {}
diff --git a/src/foundry/client-esm/applications/api/application.d.mts b/src/foundry/client-esm/applications/api/application.d.mts
index 4f9a393d7..51f0259ac 100644
--- a/src/foundry/client-esm/applications/api/application.d.mts
+++ b/src/foundry/client-esm/applications/api/application.d.mts
@@ -1,4 +1,4 @@
-import type { DeepPartial, InexactPartial } from "../../../../types/utils.d.mts";
+import type { DeepPartial, InexactPartial, MaybePromise } from "../../../../types/utils.d.mts";
 import type EventEmitterMixin from "../../../common/utils/event-emitter.d.mts";
 
 // TODO: Investigate use of DeepPartial vs Partial vs InexactPartial
@@ -72,32 +72,190 @@ declare namespace ApplicationV2 {
     zIndex: number;
   }
 
-  export interface WindowConfiguration {}
+  export interface WindowConfiguration {
+    /**
+     * Is this Application rendered inside a window frame?
+     * @defaultValue `true`
+     */
+    frame: boolean;
+
+    /**
+     * Can this Application be positioned via JavaScript or only by CSS
+     * @defaultValue `true`
+     */
+    positioned: boolean;
+
+    /** The window title. Displayed only if the application is framed */
+    title: string;
+
+    /** An optional Font Awesome icon class displayed left of the window title */
+    icon: string | false;
+
+    /** An array of window control entries */
+    controls: HeaderControlsEntry[];
+
+    /**
+     * Can the window app be minimized by double-clicking on the title
+     * @defaultValue `true`
+     */
+    minimizable: boolean;
+
+    /**
+     * Is this window resizable?
+     * @defaultValue `false`
+     */
+    resizable: boolean;
+
+    /**
+     * A specific tag name to use for the .window-content element
+     * @defaultValue `"section"`
+     */
+    contentTag: string;
+
+    /** Additional CSS classes to apply to the .window-content element */
+    contentClasses: string[];
+  }
+
+  export interface FormConfiguration {
+    handler: FormSubmission;
+
+    submitOnChange: boolean;
+
+    closeOnSubmit: boolean;
+  }
+
+  export interface HeaderControlsEntry {
+    /** A font-awesome icon class which denotes the control button */
+    icon: string;
 
-  export interface FormConfiguration {}
+    /** The text label for the control button. This label will be automatically localized when the button is rendered */
+    label: string;
 
-  export interface HeaderControlsEntry {}
+    /** The action name triggered by clicking the control button */
+    action: string;
 
-  export interface ConstructionParams {
+    /** Is the control button visible for the current client? */
+    visible: boolean;
+
+    /**
+     * A key or value in CONST.DOCUMENT_OWNERSHIP_LEVELS that restricts visibility of this option for the current user.
+     * This option only applies to DocumentSheetV2 instances.
+     */
+    ownership: string | number;
+  }
+
+  export interface ConstructorParams {
     position: Position;
   }
 
-  export interface RenderOptions {}
+  export interface RenderOptions {
+    /**
+     * Force application rendering. If true, an application which does not yet exist in the DOM is added.
+     * If false, only applications which already exist are rendered.
+     */
+    force: boolean;
 
-  export interface WindowRenderOptions {}
+    /** A specific position at which to render the Application */
+    position: Position;
+
+    /** Updates to the Application window frame */
+    window: WindowRenderOptions;
+
+    /**
+     * Some Application classes, for example the HandlebarsApplication,
+     * support re-rendering a subset of application parts instead of the full Application HTML.
+     */
+    parts: string[];
+
+    /** Is this render the first one for the application? This property is populated automatically. */
+    isFirstRender: boolean;
+  }
+
+  export interface WindowRenderOptions {
+    /** Update the window title with a new value? */
+    title: string;
+
+    /** Update the window icon with a new value? */
+    icon: string | false;
+
+    /** Re-render the window controls menu? */
+    controls: boolean;
+  }
 
   /**
    * Context data provided to the renderer
    */
   export interface RenderContext extends Record<string, unknown> {}
 
-  export interface ClosingOptions {}
+  export interface ClosingOptions {
+    /** Whether to animate the close, or perform it instantaneously */
+    animate: boolean;
+
+    /** Whether the application was closed via keypress. */
+    closeKey: boolean;
+  }
+
+  /** An on-click action supported by the Application. Run in the context of a HandlebarsApplication. */
+  export type ClickAction = (
+    /** The originating click event */
+    event: PointerEvent,
+
+    /** The capturing HTML element which defines the [data-action] */
+    target: HTMLElement,
+  ) => MaybePromise<void>;
 
-  export type ClickAction = (event: PointerEvent, target: HTMLElement) => Promise<void>;
+  /** A form submission handler method. Run in the context of a HandlebarsApplication */
+  export type FormSubmission = (
+    /** The originating form submission or input change event */
+    event: SubmitEvent | Event,
 
-  export type FormSubmission = () => Promise<void>;
+    /** The form element that was submitted */
+    form: HTMLFormElement,
 
-  export interface Tab {}
+    /** Processed data for the submitted form */
+    formData: FormDataExtended,
+  ) => MaybePromise<void>;
+
+  /** @remarks Used with `templates/generic/tab-navigation.hbs` */
+  export interface Tab {
+    id: string;
+    group: string;
+    icon: string;
+    label: string;
+    active: boolean;
+    cssClass: string;
+  }
+
+  /** @remarks Used with `templates/generic/form-fields.hbs` */
+  export interface FormNode {
+    fieldset: boolean;
+
+    legend?: string | undefined;
+
+    fields?: FormNode[] | undefined;
+
+    field?: foundry.data.fields.DataField | undefined;
+
+    value?: unknown | undefined;
+  }
+
+  /** @remarks Used with `templates/generic/form-footer.hbs` */
+  export interface FormFooterButton {
+    type: HTMLButtonElement["type"];
+
+    name?: string | undefined;
+
+    icon?: string | undefined;
+
+    label?: string | undefined;
+
+    action?: string | undefined;
+
+    cssClass?: string | undefined;
+
+    /** @defaultValue `false` */
+    disabled?: boolean | undefined;
+  }
 }
 
 /**
@@ -127,7 +285,7 @@ declare class ApplicationV2<
   /**
    * Application instance configuration options.
    */
-  options: DeepPartial<Configuration>;
+  options: Readonly<DeepPartial<Configuration>>;
 
   /**
    * Convenience references to window header elements.


Test patch:
diff --git a/tests/foundry/client-esm/applications/api/application.test-d.ts b/tests/foundry/client-esm/applications/api/application.test-d.ts
new file mode 100644
index 000000000..1ac403b93
--- /dev/null
+++ b/tests/foundry/client-esm/applications/api/application.test-d.ts
@@ -0,0 +1,15 @@
+const { ApplicationV2 } = foundry.applications.api;
+
+// Regression test for issue where synchronous actions were not being allowed.
+// Reported by @ethaks on Discord, see https://discord.com/channels/732325252788387980/793933527065690184/1266523231188422727.
+export class TestApp extends ApplicationV2 {
+  static override DEFAULT_OPTIONS = {
+    actions: {
+      someAction: this.someAction,
+    },
+  };
+
+  static someAction(): void {
+    return;
+  }
+}