Skip to content

Commit

Permalink
Move DropData to Document.DropData
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeAbby committed Jan 2, 2025
1 parent c249b3e commit b2f1261
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
27 changes: 7 additions & 20 deletions src/foundry/client/data/abstract/client-document.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ declare class InternalClientDocument<BaseDocument extends Document.Internal.Inst
/**
* Serialize salient information about this Document when dragging it.
*/
toDragData(): DropData<BaseDocument>;
toDragData(): Document.DropData<Document.Internal.Instance.Complete<BaseDocument>>;

/**
* A helper function to handle obtaining the relevant Document from dropped data provided via a DataTransfer event.
Expand All @@ -382,7 +382,7 @@ declare class InternalClientDocument<BaseDocument extends Document.Internal.Inst
*/
static fromDropData<T extends Document.AnyConstructor>(
this: T,
data: DropData<InstanceType<NoInfer<T>>>,
data: Document.DropData<InstanceType<NoInfer<T>>>,
options?: FromDropDataOptions,
): Promise<Document.ToConfiguredInstance<T> | undefined>;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -694,22 +697,8 @@ declare global {
}
}

export type DropData<T extends Document.Internal.Instance.Any> = T extends { id: string | undefined }
? InternalData<T> & DropData.UUID
: InternalData<T>;

declare namespace DropData {
type Any = DropData<any>;

interface Data<T extends Document.Any> {
type: T["documentName"];
data: T["_source"];
}

interface UUID {
uuid: string;
}
}
/** @deprecated {@link Document.DropData | `Document.DropData`} */
export type DropData<T extends Document.Any> = Document.DropData<T>;

// This is yet another `AnyDocument` type.
// It exists specifically because the `Document.AnyConstructor` type is too safe to be merged in with a mixin.
Expand All @@ -721,8 +710,6 @@ declare class AnyDocument extends Document<any, {}, any> {
constructor(...args: any[]);
}

type InternalData<T extends Document.Internal.Instance.Any> = DropData.Data<Document.Internal.Instance.Complete<T>>;

interface FromDropDataOptions {
/**
* Import the provided document data into the World, if it is not already a World-level Document reference
Expand Down
2 changes: 1 addition & 1 deletion src/foundry/client/hooks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ declare global {
* @remarks An explicit return value of `false` prevents the Document being created.
* @see {@link Hotbar#_onDrop}
*/
hotbarDrop: (hotbar: Hotbar, data: DropData<Macro.ConfiguredInstance>, slot: number) => boolean | void;
hotbarDrop: (hotbar: Hotbar, data: Document.DropData<Macro.ConfiguredInstance>, slot: number) => boolean | void;

/**
* A hook event that fires when the SceneNavigation menu is expanded or collapsed.
Expand Down
17 changes: 17 additions & 0 deletions src/foundry/common/abstract/document.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,23 @@ declare namespace Document {
type ConfiguredObjectClassFor<Name extends Document.Type> = GetKey<GetKey<CONFIG, Name>, "objectClass">;

type ConfiguredLayerClassFor<Name extends Document.Type> = GetKey<GetKey<CONFIG, Name>, "layerClass">;

type DropData<T extends Document.Any> = T extends { id: string | undefined }
? DropData.Data<T> & DropData.UUID
: DropData.Data<T>;

namespace DropData {
type Any = DropData<any>;

interface Data<T extends Document.Any> {
type: T["documentName"];
data: T["_source"];
}

interface UUID {
uuid: string;
}
}
}

export type Operation = "create" | "update" | "delete";
Expand Down

0 comments on commit b2f1261

Please sign in to comment.