The FilePicker application renders contents of the server-side public directory. This app allows for navigating and uploading files to the public path.

HandlebarsApplication

Hierarchy (View Summary)

Constructors

  • Parameters

    • Optionaloptions: any = {}

      Options that configure the behavior of the FilePicker

    Returns FilePicker

Properties

activeSource: "data" | "public" | "s3"

Track the active source tab which is being browsed

button: null | HTMLElement

A button controlling the display of the picker UI

callback: null | Function

A callback function to trigger once a file has been selected

displayMode: string

The display mode of the FilePicker UI

extensions: string[] = ...

The current set of file extensions which are being filtered upon

field: null | HTMLElement

The target HTML element this file picker is bound to

options: Readonly<ApplicationConfiguration>

Application instance configuration options.

position: ApplicationPosition = ...

The current position of the application with respect to the window.document.body.

request: string

The full requested path given by the user

results: object = {}

The latest set of results browsed from the server

sources: Record<
    "data"
    | "public"
    | "s3",
    undefined | { bucket?: string; buckets?: string[]; target: string },
>

The file sources available for browsing

tabGroups: Record<string, null | string> = ...

If this Application uses tabbed navigation groups, this mapping is updated whenever the changeTab method is called. Reports the active tab for each group, with a value of null indicating no tab is active. Subclasses may override this property to define default tabs for each group.

type: string

The general file type which controls the set of extensions which will be accepted

_appId: number = 0

An incrementing integer Application ID.

_maxZ: number = ...

The current maximum z-index of any displayed Application.

BASE_APPLICATION: typeof ApplicationV2 = ApplicationV2

Designates which upstream Application class in this class' inheritance chain is the base application. Any DEFAULT_OPTIONS of super-classes further upstream of the BASE_APPLICATION are ignored. Hook events for super-classes further upstream of the BASE_APPLICATION are not dispatched.

DEFAULT_OPTIONS: {
    actions: {
        backTraverse: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        changeDisplayMode: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        goToFavorite: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        makeDirectory: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        pickDirectory: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        pickFile: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        removeFavorite: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        setFavorite: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
        togglePrivacy: (
            event: PointerEvent,
            target: HTMLElement,
        ) => void | Promise<void>;
    };
    form: {
        closeOnSubmit: boolean;
        handler: (
            event: Event | SubmitEvent,
            form: HTMLFormElement,
            formData: FormDataExtended,
        ) => Promise<any>;
        submitOnChange: boolean;
    };
    id: string;
    position: { width: number };
    tag: string;
    tileSize: boolean;
    window: { contentClasses: string[]; icon: string };
} = ...
DISPLAY_MODES: string[] = ...

Enumerate the allowed FilePicker display modes

emittedEvents: readonly ["render", "close", "position"] = ...
FILE_TYPES: string[] = ...

The allowed values for the type of this FilePicker instance.

LAST_BROWSED_DIRECTORY: string = ""

Record the last-browsed directory path so that re-opening a different FilePicker instance uses the same target

LAST_DISPLAY_MODE: string = "list"

Record the last-configured display mode so that re-opening a different FilePicker instance uses the same mode.

LAST_TILE_SIZE: null | number = null

Record the last-configured tile size which can automatically be applied to new FilePicker instances

PARTS: {
    body: { template: string };
    footer: { template: string };
    subfooter: { template: string };
    subheader: { template: string };
    tabs: { template: string };
} = ...
RENDER_STATES: Record<string, number> = ...

The sequence of rendering states that describe the Application life-cycle.

S3_BUCKETS: null | any[] = null

Cache the names of S3 buckets which can be used

TABS: {
    sources: {
        initial: string;
        labelPrefix: string;
        tabs: { icon: string; id: string }[];
    };
} = ...

Accessors

  • get canCreateFolder(): boolean

    Whether the current user is able to create folders.

    Returns boolean

  • get canUpload(): boolean

    Whether the current use is able to upload file content.

    Returns boolean

  • get classList(): DOMTokenList

    The CSS class list of this Application instance

    Returns DOMTokenList

  • get element(): HTMLElement

    The HTMLElement which renders this Application into the DOM.

    Returns HTMLElement

  • get form(): null | HTMLFormElement

    Does this Application have a top-level form element?

    Returns null | HTMLFormElement

  • get hasFrame(): boolean

    Does this Application instance render within an outer window frame?

    Returns boolean

  • get id(): string

    The HTML element ID of this Application instance. This provides a readonly view into the internal ID used by this application. This getter should not be overridden by subclasses, which should instead configure the ID in DEFAULT_OPTIONS or by defining a uniqueId during _initializeApplicationOptions.

    Returns string

  • get minimized(): boolean

    Is this Application instance currently minimized?

    Returns boolean

  • get rendered(): boolean

    Is this Application instance currently rendered?

    Returns boolean

  • get source(): object

    Return the source object for the currently active source

    Returns object

  • get state(): number

    The current render state of the Application.

    Returns number

  • get target(): string

    Return the target directory for the currently active source

    Returns string

  • get title(): string

    Returns string

  • get window(): {
        close: HTMLButtonElement;
        content: HTMLElement;
        controls: HTMLButtonElement;
        controlsDropdown: HTMLDivElement;
        header: HTMLElement;
        icon: HTMLElement;
        onDrag: Function;
        onResize: Function;
        pointerMoveThrottle: boolean;
        pointerStartPosition: ApplicationPosition;
        resize: HTMLElement;
        title: HTMLHeadingElement;
    }

    Convenience references to window header elements.

    Returns {
        close: HTMLButtonElement;
        content: HTMLElement;
        controls: HTMLButtonElement;
        controlsDropdown: HTMLDivElement;
        header: HTMLElement;
        icon: HTMLElement;
        onDrag: Function;
        onResize: Function;
        pointerMoveThrottle: boolean;
        pointerStartPosition: ApplicationPosition;
        resize: HTMLElement;
        title: HTMLHeadingElement;
    }

  • get implementation(): typeof FilePicker

    Retrieve the configured FilePicker implementation.

    Returns typeof FilePicker

  • get uploadURL(): string

    Return the upload URL to which the FilePicker should post uploaded files

    Returns string

Methods

  • Internal

    Wait for a CSS transition to complete for an element.

    Parameters

    • element: HTMLElement

      The element which is transitioning

    • timeout: number

      A timeout in milliseconds in case the transitionend event does not occur

    Returns Promise<void>

  • Internal

    Perform an event in the application life-cycle. Await an internal life-cycle method defined by the class. Optionally dispatch an event for any registered listeners.

    Parameters

    • handler: Function

      A handler function to call

    • options: {
          async?: boolean;
          debugText?: string;
          eventName?: string;
          handlerArgs?: any[];
          hookArgs?: any[];
          hookName?: string;
          hookResponse?: boolean;
          parentClassHooks?: boolean;
      } = {}

      Options which configure event handling

      • Optionalasync?: boolean

        Await the result of the handler function?

      • OptionaldebugText?: string

        Debugging text to log for the event

      • OptionaleventName?: string

        An event name to dispatch for registered listeners

      • OptionalhandlerArgs?: any[]

        Arguments passed to the handler function

      • OptionalhookArgs?: any[]

        Arguments passed to the requested hook function

      • OptionalhookName?: string

        A hook name to dispatch for this and all parent classes

      • OptionalhookResponse?: boolean

        Add the handler response to hookArgs

      • OptionalparentClassHooks?: boolean

        Call hooks for parent classes in the inheritance chain?

    Returns void | Promise<void>

    A promise which resoles once the handler is complete if async is true

  • Parameters

    • context: any
    • options: any

    Returns Promise<void>

  • Parameters

    • options: any

    Returns Promise<
        ApplicationRenderContext & {
            bucket: any;
            buckets: any;
            buttons: { icon: string; label: string; type: string }[];
            canCreateFolder: boolean;
            canGoBack: boolean;
            canSelect: boolean;
            canTogglePrivacy: boolean;
            canUpload: boolean;
            dirs: any;
            displayMode: string;
            extensions: string[];
            favorites: Record<string, FavoriteFolder>;
            files: any;
            isS3: boolean;
            noResults: boolean;
            rootId: string;
            selected: any;
            source: object;
            sources: Record<
                "data"
                | "public"
                | "s3",
                undefined | { bucket?: string; buckets?: string[]; target: string },
            >;
            target: string;
            tileSize: any;
            user: null | documents.User;
        },
    >

  • Parameters

    • group: any

    Returns Record<string, ApplicationTab>

  • Render an HTMLElement for the Application. An Application subclass must implement this method in order for the Application to be renderable.

    Parameters

    Returns Promise<any>

    The result of HTML rendering may be implementation specific. Whatever value is returned here is passed to _replaceHTML

  • Parameters

    • options: any

    Returns void

  • Add a new event listener for a certain type of event.

    Parameters

    • type: string

      The type of event being registered for

    • listener: EmittedEventListener

      The listener function called when the event occurs

    • Optionaloptions: { once?: boolean } = {}

      Options which configure the event listener

      • Optionalonce?: boolean

        Should the event only be responded to once and then removed

    Returns void

  • Bring this Application window to the front of the rendering stack by increasing its z-index. Once ApplicationV1 is deprecated we should switch from _maxZ to ApplicationV2#maxZ We should also eliminate ui.activeWindow in favor of only ApplicationV2#frontApp

    Returns void

  • Browse to a specific location for this FilePicker instance

    Parameters

    • Optionaltarget: string = ...

      The target within the currently active source location.

    • Optionaloptions: object = {}

      Browsing options

    Returns Promise<FilePicker>

  • Parameters

    • tab: any
    • group: any
    • options: any

    Returns void

  • Close the Application, removing it from the DOM.

    Parameters

    Returns Promise<FilePicker>

    A Promise which resolves to the closed Application instance

  • Restore the Application to its original dimensions.

    Returns Promise<void>

  • Minimize the Application, collapsing it to a minimal header.

    Returns Promise<void>

  • Parameters

    • ...args: any[]

    Returns Promise<FilePicker>

  • Update the Application element position using provided data which is merged with the prior position.

    Parameters

    Returns void | ApplicationPosition

    The updated application position

  • Programmatically submit an ApplicationV2 instance which implements a single top-level form.

    Parameters

    • OptionalsubmitOptions: object = {}

      Arbitrary options which are supported by and provided to the configured form submission handler.

    Returns Promise<any>

    A promise that resolves to the returned result of the form submission handler, if any.

  • Toggle display of the Application controls menu. Only applicable to window Applications.

    Parameters

    • Optionalexpanded: boolean

      Set the controls visibility to a specific state. Otherwise, the visible state is toggled from its current value

    • Optionaloptions: { animate?: boolean } = {}

      Options to configure the toggling behavior.

      • Optionalanimate?: boolean

        Animate the controls toggling.

    Returns Promise<void>

    A Promise which resolves once the control expansion animation is complete

  • Protected

    Attach event listeners to the Application frame.

    Returns void

  • Protected

    Test whether this Application is allowed to be rendered.

    Parameters

    Returns false | void

    Return false to prevent rendering

    An Error to display a warning message

  • Protected

    Modify the provided options passed to a render request.

    Parameters

    Returns void

  • Protected

    Create a ContextMenu instance used in this Application.

    Parameters

    • handler: () => ContextMenuEntry[]

      A handler function that provides initial context options

    • selector: string

      A CSS selector to which the ContextMenu will be bound

    • Optionaloptions: { container?: HTMLElement; hookName?: string; parentClassHooks?: boolean } = {}

      Additional options which affect ContextMenu construction

      • Optionalcontainer?: HTMLElement

        A parent HTMLElement which contains the selector target

      • OptionalhookName?: string

        The hook name

      • OptionalparentClassHooks?: boolean

        Whether to call hooks for the parent classes in the inheritance chain.

    Returns null | ContextMenu

    A created ContextMenu or null if no menu items were defined

  • Protected

    Iterate over header control buttons, filtering for controls which are visible for the current client.

    Returns Generator<ApplicationHeaderControlsEntry, any, any>

  • Protected

    Given a current file path, determine the directory to which it belongs.

    Parameters

    • target: string

      The currently requested target path

    Returns [source: string, revisedTarget: string]

    A tuple of the inferred source and target directory path

  • Protected

    Initialize configuration options for the Application instance. The default behavior of this method is to intelligently merge options for each class with those of their parents.

    • Array-based options are concatenated
    • Inner objects are merged
    • Otherwise, properties in the subclass replace those defined by a parent

    Parameters

    Returns ApplicationConfiguration

    Configured options for the application instance

  • Protected

    Insert the application HTML element into the DOM. Subclasses may override this method to customize how the application is inserted.

    Parameters

    • element: HTMLElement

      The element to insert

    Returns void

  • Protected

    Handle changes to an input element within the form.

    Parameters

    • formConfig: ApplicationFormConfiguration

      The form configuration for which this handler is bound

    • event: Event

      An input change event within the form

    Returns void

  • Protected

    Handle changes to the tile size.

    Parameters

    • event: Event

      The triggering event.

    Returns void

  • Protected

    A generic event handler for action clicks which can be extended by subclasses. Action handlers defined in DEFAULT_OPTIONS are called first. This method is only called for actions which have no defined handler.

    Parameters

    • event: PointerEvent

      The originating click event

    • target: HTMLElement

      The capturing HTML element which defined a [data-action]

    Returns void

  • Protected

    Handle click events on a tab within the Application.

    Parameters

    • event: PointerEvent

    Returns void

  • Protected

    Actions performed after closing the Application. Post-close steps are not awaited by the close process.

    Parameters

    Returns void

  • Protected

    Actions performed after the Application is re-positioned.

    Parameters

    Returns void

  • Protected

    Search among shown directories and files.

    Parameters

    • event: KeyboardEvent

      The triggering event

    • query: string

      The search input value

    • rgx: RegExp
    • html: HTMLElement

    Returns void

  • Protected

    Handle submission for an Application which uses the form element.

    Parameters

    • formConfig: ApplicationFormConfiguration

      The form configuration for which this handler is bound

    • event: Event | SubmitEvent

      The form submission event

    Returns Promise<void>

  • Protected

    Actions performed before closing the Application. Pre-close steps are awaited by the close process.

    Parameters

    Returns Promise<void>

  • Protected

    Actions performed before the Application is re-positioned. Pre-position steps are not awaited because setPosition is synchronous.

    Parameters

    Returns void

  • Protected

    Remove the application HTML element from the DOM. Subclasses may override this method to customize how the application element is removed.

    Parameters

    • element: HTMLElement

      The element to be removed

    Returns void

  • Protected

    Render the outer framing HTMLElement which wraps the inner HTML of the Application.

    Parameters

    Returns Promise<HTMLElement>

  • Protected

    Replace the HTML of the application with the result provided by the rendering backend. An Application subclass should implement this method in order for the Application to be renderable.

    Parameters

    • result: any

      The result returned by the application rendering backend

    • content: HTMLElement

      The content element into which the rendered result must be inserted

    • options: ApplicationRenderOptions

      Options which configure application rendering behavior

    Returns void

  • Protected

    When the Application is rendered, optionally update aspects of the window frame.

    Parameters

    Returns void

  • Protected

    Translate a requested application position updated into a resolved allowed position for the Application. Subclasses may override this method to implement more advanced positioning behavior.

    Parameters

    Returns ApplicationPosition

    Resolved Application positioning data

  • Browse files for a certain directory location

    Parameters

    • source: string

      The source location in which to browse: see FilePicker#sources for details.

    • target: string

      The target within the source location

    • options: { bucket?: string; extensions?: string[]; wildcard?: boolean } = {}

      Optional arguments

      • Optionalbucket?: string

        A bucket within which to search if using the S3 source

      • Optionalextensions?: string[]

        An Array of file extensions to filter on

      • Optionalwildcard?: boolean

        The requested dir represents a wildcard path

    Returns Promise<object>

    A Promise that resolves to the directories and files contained in the location

  • Configure metadata settings regarding a certain file system path

    Parameters

    • source: string

      The source location in which to browse: see FilePicker#sources for details.

    • target: string

      The target within the source location

    • options: object = {}

      Optional arguments modifying the request

    Returns Promise<object>

  • Create a subdirectory within a given source. The requested subdirectory path must not already exist.

    Parameters

    • source: string

      The source location in which to browse. See FilePicker#sources for details

    • target: string

      The target within the source location

    • options: object = {}

      Optional arguments which modify the request

    Returns Promise<object>

  • Bind the file picker to a new target field. Assumes the user will provide a HTMLButtonElement which has the data-target and data-type attributes The data-target attribute should provide the name of the input field which should receive the selected file The data-type attribute is a string in ["image", "audio"] which sets the file extensions which will be accepted

    Parameters

    • button: HTMLButtonElement

      The button element

    Returns FilePicker

  • Iterate over the inheritance chain of this Application. The chain includes this Application itself and all parents until the base application is encountered.

    Returns Generator<typeof ApplicationV2, void, unknown>

  • Test a URL to see if it matches a well known s3 key pattern

    Parameters

    • url: string

      An input URL to test

    Returns null | RegExpMatchArray

    A regular expression match

  • Parse a CSS style rule into a number of pixels which apply to that dimension.

    Parameters

    • style: string

      The CSS style rule

    • parentDimension: number

      The relevant dimension of the parent element

    Returns number | void

    The parsed style dimension in pixels

  • Request wildcard token images from the server and return them.

    Parameters

    • actorId: string

      The actor whose prototype token contains the wildcard image path.

    • Optionaloptions: { pack?: string } = {}
      • Optionalpack?: string

        The ID of the compendium the actor is in.

    Returns Promise<string[]>

  • Dispatch a POST request to the server containing a directory path and a file to upload

    Parameters

    • source: string

      The data source to which the file should be uploaded

    • path: string

      The destination path

    • file: File

      The File object to upload

    • Optionalbody: object = {}

      Additional file upload options sent in the POST body

    • Optionaloptions: { notify?: boolean } = {}

      Additional options to configure how the method behaves

      • Optionalnotify?: boolean

        Display a UI notification when the upload is processed

    Returns Promise<object>

    The response object

  • A convenience function that uploads a file to a given package's persistent /storage/ directory

    Parameters

    • packageId: string

      The id of the package to which the file should be uploaded. Only supports Systems and Modules.

    • path: string

      The relative destination path in the package's storage directory

    • file: File

      The File object to upload

    • Optionalbody: object = {}

      Additional file upload options sent in the POST body

    • Optionaloptions: { notify?: boolean } = {}

      Additional options to configure how the method behaves

      • Optionalnotify?: boolean

        Display a UI notification when the upload is processed

    Returns Promise<object>

    The response object

  • Wait for any images in the given element to load.

    Parameters

    • element: HTMLElement

      The element.

    Returns Promise<void>