diff --git a/framework/core/js/dist-typings/@types/global.d.ts b/framework/core/js/dist-typings/@types/global.d.ts new file mode 100644 index 000000000..82019b82d --- /dev/null +++ b/framework/core/js/dist-typings/@types/global.d.ts @@ -0,0 +1,82 @@ +/** + * @deprecated Please import `app` from a namespace instead of using it as a global variable. + * + * @example App in forum JS + * ``` + * import app from 'flarum/forum/app'; + * ``` + * + * @example App in admin JS + * ``` + * import app from 'flarum/admin/app'; + * ``` + * + * @example App in common JS + * ``` + * import app from 'flarum/common/app'; + * ``` + */ +declare const app: never; + +declare const m: import('mithril').Static; +declare const dayjs: typeof import('dayjs'); + +type ESModule = { __esModule: true; [key: string]: unknown }; + +/** + * The global `flarum` variable. + * + * Contains the compiled ES Modules for all Flarum extensions and core. + * + * @example Check if `flarum-tags` is present + * if ('flarum-tags' in flarum.extensions) { + * // Tags is installed and enabled! + * } + */ +interface FlarumObject { + /** + * Contains the compiled ES Module for Flarum's core. + * + * You shouldn't need to access this directly for any reason. + */ + core: Readonly; + /** + * Contains the compiled ES Modules for all Flarum extensions. + * + * @example Check if `flarum-tags` is present + * if ('flarum-tags' in flarum.extensions) { + * // Tags is installed and enabled! + * } + */ + extensions: Readonly>; +} + +declare const flarum: FlarumObject; + +// Extend JQuery with our custom functions, defined with $.fn +interface JQuery { + /** + * Flarum's tooltip JQuery plugin. + * + * Do not use this directly. Instead use the `` component that + * is exported from `flarum/common/components/Tooltip`. + * + * This will be removed in a future version of Flarum. + * + * @deprecated + */ + tooltip: import('./tooltips/index').TooltipJQueryFunction; +} + +/** + * For more info, see: https://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking + * + * In a nutshell, we need to add `ElementAttributesProperty` to tell Typescript + * what property on component classes to look at for attribute typings. For our + * Component class, this would be `attrs` (e.g. `this.attrs...`) + */ +interface JSX { + ElementAttributesProperty: { + attrs: Record; + }; +} diff --git a/framework/core/js/dist-typings/@types/global/index.d.ts b/framework/core/js/dist-typings/@types/global/index.d.ts deleted file mode 100644 index 9d830686b..000000000 --- a/framework/core/js/dist-typings/@types/global/index.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Mithril -import Mithril from 'mithril'; - -// Other third-party libs -import * as _dayjs from 'dayjs'; -import 'dayjs/plugin/relativeTime'; -import * as _$ from 'jquery'; - -// Globals from flarum/core -import Application from '../../src/common/Application'; - -import type { TooltipJQueryFunction } from '../tooltips'; - -/** - * flarum/core exposes several extensions globally: - * - * - jQuery for convenient DOM manipulation - * - Mithril for VDOM and components - * - dayjs for date/time operations - * - * Since these are already part of the global namespace, extensions won't need - * to (and should not) bundle these themselves. - */ -declare global { - // $ is already defined by `@types/jquery` - const m: Mithril.Static; - const dayjs: typeof _dayjs; - - // Extend JQuery with our custom functions, defined with $.fn - interface JQuery { - tooltip: TooltipJQueryFunction; - } - - /** - * For more info, see: https://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking - * - * In a nutshell, we need to add `ElementAttributesProperty` to tell Typescript - * what property on component classes to look at for attribute typings. For our - * Component class, this would be `attrs` (e.g. `this.attrs...`) - */ - namespace JSX { - interface ElementAttributesProperty { - attrs: Record; - } - } -} - -/** - * All global variables owned by flarum/core. - */ -declare global { - const app: Application; -} diff --git a/framework/core/js/dist-typings/common/Component.d.ts b/framework/core/js/dist-typings/common/Component.d.ts index dc62b061f..1f4084a43 100644 --- a/framework/core/js/dist-typings/common/Component.d.ts +++ b/framework/core/js/dist-typings/common/Component.d.ts @@ -1,4 +1,4 @@ -import * as Mithril from 'mithril'; +import type Mithril from 'mithril'; export interface ComponentAttrs extends Mithril.Attributes { } /** diff --git a/framework/core/js/dist-typings/common/Fragment.d.ts b/framework/core/js/dist-typings/common/Fragment.d.ts index 18c76632b..594490dd6 100644 --- a/framework/core/js/dist-typings/common/Fragment.d.ts +++ b/framework/core/js/dist-typings/common/Fragment.d.ts @@ -1,4 +1,4 @@ -import * as Mithril from 'mithril'; +import type Mithril from 'mithril'; /** * The `Fragment` class represents a chunk of DOM that is rendered once with Mithril and then takes * over control of its own DOM and lifecycle. diff --git a/framework/core/js/dist-typings/common/app.d.ts b/framework/core/js/dist-typings/common/app.d.ts new file mode 100644 index 000000000..478b45bd3 --- /dev/null +++ b/framework/core/js/dist-typings/common/app.d.ts @@ -0,0 +1,6 @@ +import type Application from './Application'; +declare const _default: Application; +/** + * The instance of Application within the common namespace. + */ +export default _default; diff --git a/framework/core/js/dist-typings/common/components/Alert.d.ts b/framework/core/js/dist-typings/common/components/Alert.d.ts index 2eaed4376..8f3194500 100644 --- a/framework/core/js/dist-typings/common/components/Alert.d.ts +++ b/framework/core/js/dist-typings/common/components/Alert.d.ts @@ -1,5 +1,5 @@ import Component, { ComponentAttrs } from '../Component'; -import Mithril from 'mithril'; +import type Mithril from 'mithril'; export interface AlertAttrs extends ComponentAttrs { /** The type of alert this is. Will be used to give the alert a class name of `Alert--{type}`. */ type?: string; diff --git a/framework/core/js/dist-typings/common/helpers/avatar.d.ts b/framework/core/js/dist-typings/common/helpers/avatar.d.ts index d5f89c949..be04ffe40 100644 --- a/framework/core/js/dist-typings/common/helpers/avatar.d.ts +++ b/framework/core/js/dist-typings/common/helpers/avatar.d.ts @@ -1,4 +1,4 @@ -import * as Mithril from 'mithril'; +import type Mithril from 'mithril'; import User from '../models/User'; /** * The `avatar` helper displays a user's avatar. diff --git a/framework/core/js/dist-typings/common/helpers/fullTime.d.ts b/framework/core/js/dist-typings/common/helpers/fullTime.d.ts index 8d51227fd..f76f3b6d9 100644 --- a/framework/core/js/dist-typings/common/helpers/fullTime.d.ts +++ b/framework/core/js/dist-typings/common/helpers/fullTime.d.ts @@ -1,4 +1,4 @@ -import * as Mithril from 'mithril'; +import type Mithril from 'mithril'; /** * The `fullTime` helper displays a formatted time string wrapped in a