From 53a1d62e3c3854ea9cd45e8878956f5f2704f9fd Mon Sep 17 00:00:00 2001 From: Luke Abby Date: Thu, 2 Jan 2025 03:52:34 -0800 Subject: [PATCH] Move DropData to Document.DropData --- src/foundry/client/apps/forms/actor.d.mts | 4 +-- .../data/abstract/client-document.d.mts | 27 +++++-------------- src/foundry/client/hooks.d.mts | 3 +-- src/foundry/common/abstract/document.d.mts | 17 ++++++++++++ 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/foundry/client/apps/forms/actor.d.mts b/src/foundry/client/apps/forms/actor.d.mts index 4b2b79cba..cb62bac86 100644 --- a/src/foundry/client/apps/forms/actor.d.mts +++ b/src/foundry/client/apps/forms/actor.d.mts @@ -1,5 +1,5 @@ import type { GetDataReturnType, MaybePromise } from "../../../../utils/index.d.mts"; -import type { DropData as ClientDocumentMixinDropData } from "../../data/abstract/client-document.d.mts"; +import type Document from "../../../common/abstract/document.d.mts"; declare global { /** @@ -151,7 +151,7 @@ declare global { type: "Actor"; } - type Item = ClientDocumentMixinDropData & { + type Item = Document.DropData & { type: "Item"; }; diff --git a/src/foundry/client/data/abstract/client-document.d.mts b/src/foundry/client/data/abstract/client-document.d.mts index 5264298a8..f930bafdf 100644 --- a/src/foundry/client/data/abstract/client-document.d.mts +++ b/src/foundry/client/data/abstract/client-document.d.mts @@ -367,7 +367,7 @@ declare class InternalClientDocument; + toDragData(): Document.DropData>; /** * A helper function to handle obtaining the relevant Document from dropped data provided via a DataTransfer event. @@ -382,7 +382,7 @@ declare class InternalClientDocument( this: T, - data: DropData>>, + data: Document.DropData>>, options?: FromDropDataOptions, ): Promise | undefined>; @@ -606,6 +606,9 @@ declare const _ClientDocument: _ClientDocumentType; type ClientDocumentMixinBaseClass = Document.Internal.Constructor; declare global { + /** + * This class does not really exist at runtime. It's here for types only. + */ class ClientDocument extends _ClientDocument { // This may have be removed at some point in the future if it causes issues but the idea is to // prevent operations like `new ClientDocument()` or `extends ClientDocument` because this does @@ -694,22 +697,8 @@ declare global { } } -export type DropData = T extends { id: string | undefined } - ? InternalData & DropData.UUID - : InternalData; - -declare namespace DropData { - type Any = DropData; - - interface Data { - type: T["documentName"]; - data: T["_source"]; - } - - interface UUID { - uuid: string; - } -} +/** @deprecated {@link Document.DropData | `Document.DropData`} */ +export type DropData = Document.DropData; // This is yet another `AnyDocument` type. // It exists specifically because the `Document.AnyConstructor` type is too safe to be merged in with a mixin. @@ -721,8 +710,6 @@ declare class AnyDocument extends Document { constructor(...args: any[]); } -type InternalData = DropData.Data>; - interface FromDropDataOptions { /** * Import the provided document data into the World, if it is not already a World-level Document reference diff --git a/src/foundry/client/hooks.d.mts b/src/foundry/client/hooks.d.mts index c751d3b3f..0d0e768da 100644 --- a/src/foundry/client/hooks.d.mts +++ b/src/foundry/client/hooks.d.mts @@ -3,7 +3,6 @@ import type { DeepPartial, EmptyObject, InstanceType, ValueOf } from "../../util import type Document from "../common/abstract/document.d.mts"; import type { EffectChangeData } from "../common/documents/_types.d.mts"; import type { ProseMirrorDropDown } from "../common/prosemirror/menu.d.mts"; -import type { DropData } from "./data/abstract/client-document.d.mts"; // eslint-disable-next-line import/no-named-as-default import type ProseMirrorMenu from "../common/prosemirror/menu.d.mts"; @@ -209,7 +208,7 @@ declare global { * @remarks An explicit return value of `false` prevents the Document being created. * @see {@link Hotbar#_onDrop} */ - hotbarDrop: (hotbar: Hotbar, data: DropData, slot: number) => boolean | void; + hotbarDrop: (hotbar: Hotbar, data: Document.DropData, slot: number) => boolean | void; /** * A hook event that fires when the SceneNavigation menu is expanded or collapsed. diff --git a/src/foundry/common/abstract/document.d.mts b/src/foundry/common/abstract/document.d.mts index 3453ac96b..3d55e8024 100644 --- a/src/foundry/common/abstract/document.d.mts +++ b/src/foundry/common/abstract/document.d.mts @@ -1397,6 +1397,23 @@ declare namespace Document { type ConfiguredObjectClassFor = GetKey, "objectClass">; type ConfiguredLayerClassFor = GetKey, "layerClass">; + + type DropData = T extends { id: string | undefined } + ? DropData.Data & DropData.UUID + : DropData.Data; + + namespace DropData { + type Any = DropData; + + interface Data { + type: T["documentName"]; + data: T["_source"]; + } + + interface UUID { + uuid: string; + } + } } export type Operation = "create" | "update" | "delete";