Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TokenConfig and DefaultTokenConfig #2326

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions src/foundry/client/apps/placeables/token-config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ConfiguredDocumentClassForName } from "../../../../types/helperTypes";
import type { TokenData } from "../../../common/data/module.mjs";

declare global {
/**
Expand All @@ -7,18 +8,21 @@ declare global {
* be changed in v10.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A piece of this comment was removed in V10. It should also be removed here.

* @typeParam Options - The type of the options object
*/
class TokenConfig<Options extends FormApplicationOptions = FormApplicationOptions> extends FormApplication<
Options,
InstanceType<ConfiguredDocumentClassForName<"Token">> | InstanceType<ConfiguredDocumentClassForName<"Actor">>
> {
class TokenConfig<Options extends DocumentSheetOptions = DocumentSheetOptions> extends DocumentSheet<Options> {
constructor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comments for the parameters should be copied over from the sources.

object:
| InstanceType<ConfiguredDocumentClassForName<"Token">>
| InstanceType<ConfiguredDocumentClassForName<"Actor">>,
options?: Partial<Options>
);

/** The placed Token object in the Scene */
token: InstanceType<ConfiguredDocumentClassForName<"Token">> | PrototypeTokenDocument;
/** A reference to the Actor which the token depicts */
actor: InstanceType<ConfiguredDocumentClassForName<"Actor">>;
/** Preserve a copy of the original document before any changes are made. */
// TODO: unsure about this type.
original: TokenData["_source"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
original: TokenData["_source"];
original: BaseToken.Source;


/**
* @defaultValue
Expand All @@ -36,25 +40,22 @@ declare global {
* })
* ```
*/
static override get defaultOptions(): FormApplicationOptions;

override get id(): string;
static override get defaultOptions(): DocumentSheetOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the documented default return value.


/**
* A convenience accessor to test whether we are configuring the prototype Token for an Actor.
*/
get isPrototype(): boolean;

/**
* Convenience access to the Actor document that this Token represents
*/
get actor(): InstanceType<ConfiguredDocumentClassForName<"Actor">>;
override get id(): string;

override get title(): string;

override getData(options?: Partial<Options>): MaybePromise<object>;
override render(force?: boolean, options?: Application.RenderOptions<Options>): this;

protected override _canUserView(user: User): boolean;

override render(force?: boolean, options?: Application.RenderOptions<Options>): Promise<this>;
override getData(options?: Partial<Options>): MaybePromise<object>;

protected override _renderInner(args: object): Promise<JQuery>;

Expand All @@ -64,15 +65,25 @@ declare global {
*/
protected _getAlternateTokenImages(): Promise<Record<string, string>>;

protected override _getHeaderButtons(): Application.HeaderButton[];
override activateListeners(html: JQuery): void;

override close(options?: FormApplication.CloseOptions | undefined): Promise<void>;

protected override _getSubmitData(updateData?: object | null | undefined): Record<string, unknown>;

protected override _onChangeInput(event: JQuery.ChangeEvent<any, any, any, any>): Promise<void>;

/**
* Shim for {@link DocumentSheet#_onConfigureSheet} that will be replaced in v10 when this class subclasses it.
* @internal
* Mimic changes to the Token document as if they were true document updates.
* @param change - Data which simulates a document update
* @param reset - To know if this preview change is a reset. Defaults to false.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param reset - To know if this preview change is a reset. Defaults to false.
* @param reset - To know if this preview change is a reset. Defaults to false.

*/
protected _onConfigureSheet(event: JQuery.ClickEvent): void;
protected _previewChanges(change: Parameters<foundry.documents.BaseToken["_onUpdate"]>[0], reset?: boolean): void;

override activateListeners(html: JQuery): void;
/**
* Reset the temporary preview of the Token when the form is submitted or closed.
*/
protected _resetPreview(): void;

protected override _updateObject(event: Event, formData: TokenConfig.FormData): Promise<unknown>;

Expand All @@ -87,7 +98,16 @@ declare global {
* Handle changing the attribute bar in the drop-down selector to update the default current and max value
* @internal
*/
protected _onBarChange(ev: JQuery.ChangeEvent): void;
protected _onBarChange(event: JQuery.ChangeEvent): void;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has parameter documentation, which should be added.


/**
* Handle click events on a token configuration sheet action button
* @param event - The originating click event */
protected _onClickActionButton(event: JQuery.ClickEvent): void;
Comment on lines +105 to +106
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param event - The originating click event */
protected _onClickActionButton(event: JQuery.ClickEvent): void;
* @param event - The originating click event
*/
protected _onClickActionButton(event: JQuery.ClickEvent): void;

/**
* Disable the user's ability to edit the token image field if wildcard images are enabled and that user does not have
* file browser permissions. */
private _disableEditImage(): void;
Comment on lines +107 to +110
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Disable the user's ability to edit the token image field if wildcard images are enabled and that user does not have
* file browser permissions. */
private _disableEditImage(): void;
/**
* Disable the user's ability to edit the token image field if wildcard images are enabled and that user does not have
* file browser permissions.
*/
private _disableEditImage(): void;

}

namespace TokenConfig {
Expand Down Expand Up @@ -132,9 +152,7 @@ declare global {
/**
* A sheet that alters the values of the default Token configuration used when new Token documents are created.
*/
class DefaultTokenConfig<
Options extends FormApplicationOptions = FormApplicationOptions
> extends TokenConfig<Options> {
class DefaultTokenConfig<Options extends DocumentSheetOptions> extends TokenConfig<Options> {
constructor(object: unknown, options?: Partial<Options> | undefined);

data: foundry.data.TokenData;
Expand All @@ -158,7 +176,7 @@ declare global {
* })
* ```
*/
static override get defaultOptions(): FormApplicationOptions;
static override get defaultOptions(): DocumentSheetOptions;

override get id(): string;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getData's parameter is now optional.

Expand Down