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 53a1d62
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/foundry/client/apps/forms/actor.d.mts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -151,7 +151,7 @@ declare global {
type: "Actor";
}

type Item = ClientDocumentMixinDropData<Item.ConfiguredInstance> & {
type Item = Document.DropData<Item.ConfiguredInstance> & {
type: "Item";
};

Expand Down
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
3 changes: 1 addition & 2 deletions src/foundry/client/hooks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<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 53a1d62

Please sign in to comment.