Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/common

Index

References

Extend

Renames and re-exports common/extend

app

Renames and re-exports default

Type aliases

ApiPayload

ApiQueryParams

ApiResponse

ApiResponse<M>: ApiResponseSingle<M> | ApiResponsePlural<M>

Type parameters

ApiResponsePlural

ApiResponsePlural<M>: M[] & { payload: ApiPayloadPlural }

Type parameters

ApiResponseSingle

ApiResponseSingle<M>: M & { payload: ApiPayloadSingle }

Type parameters

FlarumGenericRoute

FlarumGenericRoute: RouteItem<any, any, any>

FlarumScreens

FlarumScreens: "phone" | "tablet" | "desktop" | "desktop-hd"

LoginParams

LoginParams: { identification: string; password: string; remember: boolean }

Type declaration

  • identification: string

    The username/email

  • password: string
  • remember: boolean

ModelData

RouteItem

RouteItem<Attrs, Comp, RouteArgs>: { path: `/${string}` } & ({ component: new () => Comp; resolverClass?: new (component: new () => Comp, routeName: string) => DefaultResolver<Attrs, Comp, RouteArgs> } | { resolver: RouteResolver<Attrs, Comp, RouteArgs> })

A valid route definition.

Type parameters

Properties

default

default: Application

default

default: { Application: typeof Application; Component: typeof Component; Fragment: typeof Fragment; Model: typeof Model; Session: typeof Session; Store: typeof Store; Translator: typeof Translator; components/Alert: typeof Alert; components/AlertManager: typeof AlertManager; components/Badge: typeof Badge; components/Button: typeof Button; components/Checkbox: typeof Checkbox; components/ColorPreviewInput: typeof ColorPreviewInput; components/Dropdown: typeof Dropdown; components/EditUserModal: typeof EditUserModal; components/FieldSet: typeof FieldSet; components/GroupBadge: typeof GroupBadge; components/Link: typeof Link; components/LinkButton: typeof LinkButton; components/LoadingIndicator: typeof LoadingIndicator; components/Modal: typeof Modal; components/ModalManager: typeof ModalManager; components/Navigation: typeof Navigation; components/Page: typeof Page; components/Placeholder: typeof Placeholder; components/RequestErrorModal: typeof RequestErrorModal; components/Select: typeof Select; components/SelectDropdown: typeof SelectDropdown; components/Separator: typeof Separator; components/SplitDropdown: typeof SplitDropdown; components/Switch: typeof Switch; components/TextEditor: typeof TextEditor; components/TextEditorButton: typeof TextEditorButton; components/Tooltip: typeof Tooltip; extend: any; helpers/avatar: (user: null | User, attrs?: ComponentAttrs) => Mithril.Vnode; helpers/fullTime: (time: Date) => Mithril.Vnode; helpers/highlight: (string: string, phrase?: string | RegExp, length?: number) => Mithril.Vnode<any, any> | string; helpers/humanTime: (time: Date) => Mithril.Vnode; helpers/icon: (fontClass: string, attrs?: Attributes) => Mithril.Vnode; helpers/listItems: <Attrs>(rawItems: ModdedChildrenWithItemName[], customTag?: VnodeElementTag<Attrs, Component<Attrs, {}>>, attributes?: Attrs) => Mithril.Vnode[]; helpers/punctuateSeries: (items: Children[]) => Children; helpers/userOnline: (user: User) => Mithril.Vnode<{}, {}> | null; helpers/username: (user: undefined | null | false | User) => Mithril.Vnode; models/Discussion: typeof Discussion; models/Forum: typeof Forum; models/Group: typeof Group; models/Notification: typeof Notification; models/Post: typeof Post; models/User: typeof User; resolvers/DefaultResolver: typeof DefaultResolver; states/PaginatedListState: typeof PaginatedListState; utils/BasicEditorDriver: typeof BasicEditorDriver; utils/Drawer: typeof Drawer; utils/ItemList: typeof ItemList; utils/RequestError: typeof RequestError; utils/ScrollListener: typeof ScrollListener; utils/Stream: typeof Stream; utils/SubtreeRetainer: typeof SubtreeRetainer; utils/abbreviateNumber: (number: number) => string; utils/anchorScroll: (element: string | HTMLElement | Element | SVGElement, callback: () => void) => void; utils/classList: (...inputs: ClassValue[]) => string; utils/computed: <T, M>(...args: [...string[], (...args: unknown[]) => T]) => () => T; utils/escapeRegExp: (input: string) => string; utils/evented: { handlers: Record<string, unknown>; getHandlers: any; off: any; on: any; one: any; trigger: any }; utils/extract: <T, K>(object: T, property: K) => T[K]; utils/extractText: (vdom: Children) => string; utils/focusTrap: __module; utils/formatNumber: (number: number, locale?: string) => string; utils/humanTime: (time: undefined | null | string | number | Date | Dayjs) => string; utils/insertText: (textarea: HTMLTextAreaElement, __namedParameters: SelectionRange) => void; utils/isObject: (obj: unknown) => obj is object; utils/liveHumanTimes: () => void; utils/mapRoutes: (routes: Record<string, FlarumGenericRoute>, basePath?: string) => Record<string, RouteResolver<Record<string, unknown>, Component<{ routeName: string }, undefined>, Record<string, unknown>>>; utils/mixin: (Parent: object, ...mixins: Record<string, any>[]) => object; utils/patchMithril: (global: any) => void; utils/proxifyCompat: (compat: Record<string, unknown>, namespace: string) => Record<string, unknown>; utils/setRouteWithForcedRefresh: (route: string, params?: null, options?: RouteOptions) => void; utils/string: __module; utils/stringToColor: (string: string) => string; utils/styleSelectedText: (textarea: HTMLTextAreaElement, styleArgs: StyleArgs) => void; utils/subclassOf: (A: any, B: any) => any; utils/throttleDebounce: __module; utils/withAttr: (key: string, cb: Function) => () => void }

Type declaration

  • Application: typeof Application
  • Component: typeof Component
  • Fragment: typeof Fragment
  • Model: typeof Model
  • Session: typeof Session
  • Store: typeof Store
  • Translator: typeof Translator
  • components/Alert: typeof Alert
  • components/AlertManager: typeof AlertManager
  • components/Badge: typeof Badge
  • components/Button: typeof Button
  • components/Checkbox: typeof Checkbox
  • components/ColorPreviewInput: typeof ColorPreviewInput
  • components/Dropdown: typeof Dropdown
  • components/EditUserModal: typeof EditUserModal
  • components/FieldSet: typeof FieldSet
  • components/GroupBadge: typeof GroupBadge
  • components/Link: typeof Link
  • components/LinkButton: typeof LinkButton
  • components/LoadingIndicator: typeof LoadingIndicator
  • components/Modal: typeof Modal
  • components/ModalManager: typeof ModalManager
  • components/Navigation: typeof Navigation
  • components/Page: typeof Page
  • components/Placeholder: typeof Placeholder
  • components/RequestErrorModal: typeof RequestErrorModal
  • components/Select: typeof Select
  • components/SelectDropdown: typeof SelectDropdown
  • components/Separator: typeof Separator
  • components/SplitDropdown: typeof SplitDropdown
  • components/Switch: typeof Switch
  • components/TextEditor: typeof TextEditor
  • components/TextEditorButton: typeof TextEditorButton
  • components/Tooltip: typeof Tooltip
  • extend: any
  • helpers/avatar: (user: null | User, attrs?: ComponentAttrs) => Mithril.Vnode
      • The avatar helper displays a user's avatar.

        Parameters

        Returns Mithril.Vnode

  • helpers/fullTime: (time: Date) => Mithril.Vnode
      • (time: Date): Mithril.Vnode
      • The fullTime helper displays a formatted time string wrapped in a

        Parameters

        Returns Mithril.Vnode

  • helpers/highlight: (string: string, phrase?: string | RegExp, length?: number) => Mithril.Vnode<any, any> | string
      • (string: string, phrase?: string | RegExp, length?: number): Mithril.Vnode<any, any> | string
      • The highlight helper searches for a word phrase in a string, and wraps matches with the tag.

        Parameters

        • string: string

          The string to highlight.

        • Optional phrase: string | RegExp

          The word or words to highlight.

        • Optional length: number

        Returns Mithril.Vnode<any, any> | string

  • helpers/humanTime: (time: Date) => Mithril.Vnode
      • (time: Date): Mithril.Vnode
      • The humanTime helper displays a time in a human-friendly time-ago format (e.g. '12 days ago'), wrapped in a

        Parameters

        Returns Mithril.Vnode

  • helpers/icon: (fontClass: string, attrs?: Attributes) => Mithril.Vnode
      • (fontClass: string, attrs?: Attributes): Mithril.Vnode
      • The icon helper displays an icon.

        Parameters

        • fontClass: string

          The full icon class, prefix and the icon’s name.

        • attrs: Attributes = {}

          Any other attributes to apply.

        Returns Mithril.Vnode

  • helpers/listItems: <Attrs>(rawItems: ModdedChildrenWithItemName[], customTag?: VnodeElementTag<Attrs, Component<Attrs, {}>>, attributes?: Attrs) => Mithril.Vnode[]
      • The listItems helper wraps an array of components in the provided tag, stripping out any unnecessary Separator components.

        By default, this tag is an <li> tag, but this is customisable through the second function parameter, customTag.

        Type parameters

        Parameters

        Returns Mithril.Vnode[]

  • helpers/punctuateSeries: (items: Children[]) => Children
      • (items: Children[]): Children
      • The punctuateSeries helper formats a list of strings (e.g. names) to read fluently in the application's locale.

        punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion
        

        Parameters

        • items: Children[]

        Returns Children

        ')}

  • helpers/userOnline: (user: User) => Mithril.Vnode<{}, {}> | null
      • (user: User): Mithril.Vnode<{}, {}> | null
      • The useronline helper displays a green circle if the user is online

        Parameters

        Returns Mithril.Vnode<{}, {}> | null

  • helpers/username: (user: undefined | null | false | User) => Mithril.Vnode
      • (user: undefined | null | false | User): Mithril.Vnode
      • The username helper displays a user's username in a tag. If the user doesn't exist, the username will be displayed as [deleted].

        Parameters

        • user: undefined | null | false | User

        Returns Mithril.Vnode

  • models/Discussion: typeof Discussion
  • models/Forum: typeof Forum
  • models/Group: typeof Group
  • models/Notification: typeof Notification
  • models/Post: typeof Post
  • models/User: typeof User
  • resolvers/DefaultResolver: typeof DefaultResolver
  • states/PaginatedListState: typeof PaginatedListState
  • utils/BasicEditorDriver: typeof BasicEditorDriver
  • utils/Drawer: typeof Drawer
  • utils/ItemList: typeof ItemList
  • utils/RequestError: typeof RequestError
  • utils/ScrollListener: typeof ScrollListener
  • utils/Stream: typeof Stream
  • utils/SubtreeRetainer: typeof SubtreeRetainer
  • utils/abbreviateNumber: (number: number) => string
      • (number: number): string
      • The abbreviateNumber utility converts a number to a shorter localized form.

        example

        abbreviateNumber(1234); // "1.2K"

        Parameters

        • number: number

        Returns string

  • utils/anchorScroll: (element: string | HTMLElement | Element | SVGElement, callback: () => void) => void
      • The anchorScroll utility saves the scroll position relative to an element, and then restores it after a callback has been run.

        This is useful if a redraw will change the page's content above the viewport. Normally doing this will result in the content in the viewport being pushed down or pulled up. By wrapping the redraw with this utility, the scroll position can be anchor to an element that is in or below the viewport, so the content in the viewport will stay the same.

        Parameters

        • element: string | HTMLElement | Element | SVGElement

          The element to anchor the scroll position to.

        • callback: () => void

          The callback to run that will change page content.

            • (): void
            • Returns void

        Returns void

  • utils/classList: (...inputs: ClassValue[]) => string
      • (...inputs: ClassValue[]): string
      • Parameters

        • Rest ...inputs: ClassValue[]

        Returns string

  • utils/computed: <T, M>(...args: [...string[], (...args: unknown[]) => T]) => () => T
      • <T, M>(...args: [...string[], (...args: unknown[]) => T]): () => T
      • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

        Type parameters

        Parameters

        • Rest ...args: [...string[], (...args: unknown[]) => T]

        Returns () => T

          • (): T
          • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

            Returns T

  • utils/escapeRegExp: (input: string) => string
  • utils/evented: { handlers: Record<string, unknown>; getHandlers: any; off: any; on: any; one: any; trigger: any }
    • handlers: Record<string, unknown>
    • getHandlers:function
    • off:function
      • off(event: string, handler: Function): void
      • Unregister an event handler.

        deprecated

        Parameters

        • event: string

          The name of the event.

        • handler: Function

          The function that handles the event.

        Returns void

    • on:function
      • on(event: string, handler: Function): void
      • Register an event handler.

        deprecated

        Parameters

        • event: string

          The name of the event.

        • handler: Function

          The function to handle the event.

        Returns void

    • one:function
      • one(event: string, handler: Function): void
      • Register an event handler so that it will run only once, and then unregister itself.

        deprecated

        Parameters

        • event: string

          The name of the event.

        • handler: Function

          The function to handle the event.

        Returns void

    • trigger:function
      • trigger(event: string, ...args: any[]): void
      • Trigger an event.

        deprecated

        Parameters

        • event: string

          The name of the event.

        • Rest ...args: any[]

          Arguments to pass to event handlers.

        Returns void

  • utils/extract: <T, K>(object: T, property: K) => T[K]
      • <T, K>(object: T, property: K): T[K]
      • The extract utility deletes a property from an object and returns its value.

        Type parameters

        • T

        • K: string | number | symbol

        Parameters

        • object: T

          The object that owns the property

        • property: K

          The name of the property to extract

        Returns T[K]

        The value of the property

  • utils/extractText: (vdom: Children) => string
      • (vdom: Children): string
      • Extract the text nodes from a virtual element.

        Parameters

        • vdom: Children

        Returns string

  • utils/focusTrap: __module
  • utils/formatNumber: (number: number, locale?: string) => string
      • (number: number, locale?: string): string
      • The formatNumber utility localizes a number into a string with the appropriate punctuation based on the provided locale otherwise will default to the users locale.

        example

        formatNumber(1234); // 1,234

        Parameters

        • number: number
        • locale: string = app.data.locale

        Returns string

  • utils/humanTime: (time: undefined | null | string | number | Date | Dayjs) => string
      • (time: undefined | null | string | number | Date | Dayjs): string
      • The humanTime utility converts a date to a localized, human-readable time- ago string.

        Parameters

        • time: undefined | null | string | number | Date | Dayjs

        Returns string

  • utils/insertText: (textarea: HTMLTextAreaElement, __namedParameters: SelectionRange) => void
  • utils/isObject: (obj: unknown) => obj is object
      • (obj: unknown): obj is object
      • Returns if the passed value is an object.

        In this context, "object" refers to any non-primitive value, including arrays, function, maps, dates, and more.

        example

        isObject({}); // true

        example

        isObject([]); // true

        example

        isObject(function () {}); // true

        example

        isObject(Object(1)); // true

        example

        isObject(null); // false

        example

        isObject(1); // false

        example

        isObject("hello world"); // false

        see

        https://github.com/jashkenas/underscore/blob/943977e34e2279503528a71ddcc2dd5f96483945/underscore.js#L87-L91

        Parameters

        • obj: unknown

        Returns obj is object

  • utils/liveHumanTimes: () => void
      • (): void
      • The liveHumanTimes initializer sets up a loop every 1 second to update timestamps rendered with the humanTime helper.

        Returns void

  • utils/mapRoutes: (routes: Record<string, FlarumGenericRoute>, basePath?: string) => Record<string, RouteResolver<Record<string, unknown>, Component<{ routeName: string }, undefined>, Record<string, unknown>>>
      • The mapRoutes utility converts a map of named application routes into a format that can be understood by Mithril, and wraps them in route resolvers to provide each route with the current route name.

        see

        https://mithril.js.org/route.html#signature

        Parameters

        Returns Record<string, RouteResolver<Record<string, unknown>, Component<{ routeName: string }, undefined>, Record<string, unknown>>>

  • utils/mixin: (Parent: object, ...mixins: Record<string, any>[]) => object
      • (Parent: object, ...mixins: Record<string, any>[]): object
      • The mixin utility assigns the properties of a set of 'mixin' objects to the prototype of a parent object.

        example

        class MyClass extends mixin(ExistingClass, evented, etc) {}

        Parameters

        • Parent: object

          The class to extend the new class from.

        • Rest ...mixins: Record<string, any>[]

          The objects to mix in.

        Returns object

        A new class that extends Parent and contains the mixins.

  • utils/patchMithril: (global: any) => void
      • (global: any): void
      • Parameters

        • global: any

        Returns void

  • utils/proxifyCompat: (compat: Record<string, unknown>, namespace: string) => Record<string, unknown>
      • (compat: Record<string, unknown>, namespace: string): Record<string, unknown>
      • Parameters

        • compat: Record<string, unknown>
        • namespace: string

        Returns Record<string, unknown>

  • utils/setRouteWithForcedRefresh: (route: string, params?: null, options?: RouteOptions) => void
      • (route: string, params?: null, options?: RouteOptions): void
      • Mithril 2 does not completely rerender the page if a route change leads to the same route (or the same component handling a different route). This util calls m.route.set, forcing a reonit.

        see

        https://mithril.js.org/route.html#key-parameter

        Parameters

        • route: string
        • params: null = null
        • options: RouteOptions = {}

        Returns void

  • utils/string: __module
  • utils/stringToColor: (string: string) => string
      • (string: string): string
      • Convert the given string to a unique color.

        Parameters

        • string: string

        Returns string

  • utils/styleSelectedText: (textarea: HTMLTextAreaElement, styleArgs: StyleArgs) => void
  • utils/subclassOf: (A: any, B: any) => any
      • (A: any, B: any): any
      • Check if class A is the same as or a subclass of class B.

        Parameters

        • A: any
        • B: any

        Returns any

  • utils/throttleDebounce: __module
  • utils/withAttr: (key: string, cb: Function) => () => void

Functions

extend

  • extend<T, K>(object: T, methods: K | K[], callback: (val: ReturnType<T[K]>, ...args: Parameters<T[K]>) => void): void
  • Extend an object's method by running its output through a mutating callback every time it is called.

    The callback accepts the method's return value and should perform any mutations directly on this value. For this reason, this function will not be effective on methods which return scalar values (numbers, strings, booleans).

    Care should be taken to extend the correct object – in most cases, a class' prototype will be the desired target of extension, not the class itself.

    example

    Example usage of extending one method. extend(Discussion.prototype, 'badges', function(badges) { // do something with badges });

    example

    Example usage of extending multiple methods. extend(IndexPage.prototype, ['oncreate', 'onupdate'], function(vnode) { // something that needs to be run on creation and update });

    Type parameters

    • T: Record<string, any>

    • K: string | number | symbol

    Parameters

    • object: T

      The object that owns the method

    • methods: K | K[]

      The name or names of the method(s) to extend

    • callback: (val: ReturnType<T[K]>, ...args: Parameters<T[K]>) => void

      A callback which mutates the method's output

        • (val: ReturnType<T[K]>, ...args: Parameters<T[K]>): void
        • Parameters

          • val: ReturnType<T[K]>
          • Rest ...args: Parameters<T[K]>

          Returns void

    Returns void

override

  • override<T, K>(object: T, methods: K | K[], newMethod: (orig: T[K], ...args: Parameters<T[K]>) => void): void
  • Override an object's method by replacing it with a new function, so that the new function will be run every time the object's method is called.

    The replacement function accepts the original method as its first argument, which is like a call to super. Any arguments passed to the original method are also passed to the replacement.

    Care should be taken to extend the correct object – in most cases, a class' prototype will be the desired target of extension, not the class itself.

    example

    Example usage of overriding one method. override(Discussion.prototype, 'badges', function(original) { const badges = original(); // do something with badges return badges; });

    example

    Example usage of overriding multiple methods. extend(Discussion.prototype, ['oncreate', 'onupdate'], function(original, vnode) { // something that needs to be run on creation and update });

    Type parameters

    • T: Record<any, any>

    • K: string | number | symbol

    Parameters

    • object: T

      The object that owns the method

    • methods: K | K[]

      The name or names of the method(s) to override

    • newMethod: (orig: T[K], ...args: Parameters<T[K]>) => void

      The method to replace it with

        • (orig: T[K], ...args: Parameters<T[K]>): void
        • Parameters

          • orig: T[K]
          • Rest ...args: Parameters<T[K]>

          Returns void

    Returns void

payloadIsPlural

Type literals

__type

__type

Application

Application: typeof Application = Application

Component

Component: typeof Component = Component

Fragment

Fragment: typeof Fragment = Fragment

Model

Model: typeof Model = Model

Session

Session: typeof Session = Session

Store

Store: typeof Store = Store

Translator

Translator: typeof Translator = Translator

components/Alert

components/Alert: typeof Alert = Alert

components/AlertManager

components/AlertManager: typeof AlertManager = AlertManager

components/Badge

components/Badge: typeof Badge = Badge

components/Button

components/Button: typeof Button = Button

components/Checkbox

components/Checkbox: typeof Checkbox = Checkbox

components/ColorPreviewInput

components/ColorPreviewInput: typeof ColorPreviewInput = ColorPreviewInput

components/Dropdown

components/Dropdown: typeof Dropdown = Dropdown

components/EditUserModal

components/EditUserModal: typeof EditUserModal = EditUserModal

components/FieldSet

components/FieldSet: typeof FieldSet = FieldSet

components/GroupBadge

components/GroupBadge: typeof GroupBadge = GroupBadge

components/Link

components/Link: typeof Link = Link

components/LinkButton

components/LinkButton: typeof LinkButton = LinkButton

components/LoadingIndicator

components/LoadingIndicator: typeof LoadingIndicator = LoadingIndicator

components/Modal

components/Modal: typeof Modal = Modal

components/ModalManager

components/ModalManager: typeof ModalManager = ModalManager

components/Navigation

components/Navigation: typeof Navigation = Navigation

components/Page

components/Page: typeof Page = Page

components/Placeholder

components/Placeholder: typeof Placeholder = Placeholder

components/RequestErrorModal

components/RequestErrorModal: typeof RequestErrorModal = RequestErrorModal

components/Select

components/Select: typeof Select = Select

components/SelectDropdown

components/SelectDropdown: typeof SelectDropdown = SelectDropdown

components/Separator

components/Separator: typeof Separator = Separator

components/SplitDropdown

components/SplitDropdown: typeof SplitDropdown = SplitDropdown

components/Switch

components/Switch: typeof Switch = Switch

components/TextEditor

components/TextEditor: typeof TextEditor = TextEditor

components/TextEditorButton

components/TextEditorButton: typeof TextEditorButton = TextEditorButton

components/Tooltip

components/Tooltip: typeof Tooltip = Tooltip

extend

extend: any = extend

helpers/avatar

helpers/avatar: (user: null | User, attrs?: ComponentAttrs) => Mithril.Vnode = avatar

Type declaration

    • The avatar helper displays a user's avatar.

      Parameters

      Returns Mithril.Vnode

helpers/fullTime

helpers/fullTime: (time: Date) => Mithril.Vnode = fullTime

Type declaration

    • (time: Date): Mithril.Vnode
    • The fullTime helper displays a formatted time string wrapped in a

      Parameters

      Returns Mithril.Vnode

helpers/highlight

helpers/highlight: (string: string, phrase?: string | RegExp, length?: number) => Mithril.Vnode<any, any> | string = highlight

Type declaration

    • (string: string, phrase?: string | RegExp, length?: number): Mithril.Vnode<any, any> | string
    • The highlight helper searches for a word phrase in a string, and wraps matches with the tag.

      Parameters

      • string: string

        The string to highlight.

      • Optional phrase: string | RegExp

        The word or words to highlight.

      • Optional length: number

      Returns Mithril.Vnode<any, any> | string

helpers/humanTime

helpers/humanTime: (time: Date) => Mithril.Vnode = humanTimeHelper

Type declaration

    • (time: Date): Mithril.Vnode
    • The humanTime helper displays a time in a human-friendly time-ago format (e.g. '12 days ago'), wrapped in a

      Parameters

      Returns Mithril.Vnode

helpers/icon

helpers/icon: (fontClass: string, attrs?: Attributes) => Mithril.Vnode = icon

Type declaration

    • (fontClass: string, attrs?: Attributes): Mithril.Vnode
    • The icon helper displays an icon.

      Parameters

      • fontClass: string

        The full icon class, prefix and the icon’s name.

      • attrs: Attributes = {}

        Any other attributes to apply.

      Returns Mithril.Vnode

helpers/listItems

helpers/listItems: <Attrs>(rawItems: ModdedChildrenWithItemName[], customTag?: VnodeElementTag<Attrs, Component<Attrs, {}>>, attributes?: Attrs) => Mithril.Vnode[] = listItems

Type declaration

    • The listItems helper wraps an array of components in the provided tag, stripping out any unnecessary Separator components.

      By default, this tag is an <li> tag, but this is customisable through the second function parameter, customTag.

      Type parameters

      Parameters

      Returns Mithril.Vnode[]

helpers/punctuateSeries

helpers/punctuateSeries: (items: Children[]) => Children = punctuateSeries

Type declaration

    • (items: Children[]): Children
    • The punctuateSeries helper formats a list of strings (e.g. names) to read fluently in the application's locale.

      punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion
      

      Parameters

      • items: Children[]

      Returns Children

      ')}

helpers/userOnline

helpers/userOnline: (user: User) => Mithril.Vnode<{}, {}> | null = userOnline

Type declaration

    • (user: User): Mithril.Vnode<{}, {}> | null
    • The useronline helper displays a green circle if the user is online

      Parameters

      Returns Mithril.Vnode<{}, {}> | null

helpers/username

helpers/username: (user: undefined | null | false | User) => Mithril.Vnode = username

Type declaration

    • (user: undefined | null | false | User): Mithril.Vnode
    • The username helper displays a user's username in a tag. If the user doesn't exist, the username will be displayed as [deleted].

      Parameters

      • user: undefined | null | false | User

      Returns Mithril.Vnode

models/Discussion

models/Discussion: typeof Discussion = Discussion

models/Forum

models/Forum: typeof Forum = Forum

models/Group

models/Group: typeof Group = Group

models/Notification

models/Notification: typeof Notification = Notification

models/Post

models/Post: typeof Post = Post

models/User

models/User: typeof User = User

resolvers/DefaultResolver

resolvers/DefaultResolver: typeof DefaultResolver = DefaultResolver

states/PaginatedListState

states/PaginatedListState: typeof PaginatedListState = PaginatedListState

utils/BasicEditorDriver

utils/BasicEditorDriver: typeof BasicEditorDriver = BasicEditorDriver

utils/Drawer

utils/Drawer: typeof Drawer = Drawer

utils/ItemList

utils/ItemList: typeof ItemList = ItemList

utils/RequestError

utils/RequestError: typeof RequestError = RequestError

utils/ScrollListener

utils/ScrollListener: typeof ScrollListener = ScrollListener

utils/Stream

utils/Stream: typeof Stream = Stream

utils/SubtreeRetainer

utils/SubtreeRetainer: typeof SubtreeRetainer = SubtreeRetainer

utils/abbreviateNumber

utils/abbreviateNumber: (number: number) => string = abbreviateNumber

Type declaration

    • (number: number): string
    • The abbreviateNumber utility converts a number to a shorter localized form.

      example

      abbreviateNumber(1234); // "1.2K"

      Parameters

      • number: number

      Returns string

utils/anchorScroll

utils/anchorScroll: (element: string | HTMLElement | Element | SVGElement, callback: () => void) => void = anchorScroll

Type declaration

    • The anchorScroll utility saves the scroll position relative to an element, and then restores it after a callback has been run.

      This is useful if a redraw will change the page's content above the viewport. Normally doing this will result in the content in the viewport being pushed down or pulled up. By wrapping the redraw with this utility, the scroll position can be anchor to an element that is in or below the viewport, so the content in the viewport will stay the same.

      Parameters

      • element: string | HTMLElement | Element | SVGElement

        The element to anchor the scroll position to.

      • callback: () => void

        The callback to run that will change page content.

          • (): void
          • Returns void

      Returns void

utils/classList

utils/classList: (...inputs: ClassValue[]) => string = classList

Type declaration

    • (...inputs: ClassValue[]): string
    • Parameters

      • Rest ...inputs: ClassValue[]

      Returns string

utils/computed

utils/computed: <T, M>(...args: [...string[], (...args: unknown[]) => T]) => () => T = computed

Type declaration

    • <T, M>(...args: [...string[], (...args: unknown[]) => T]): () => T
    • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

      Type parameters

      Parameters

      • Rest ...args: [...string[], (...args: unknown[]) => T]

      Returns () => T

        • (): T
        • The computed utility creates a function that will cache its output until any of the dependent values are dirty.

          Returns T

utils/escapeRegExp

utils/escapeRegExp: (input: string) => string = escapeRegExp

Type declaration

utils/evented

utils/evented: { handlers: Record<string, unknown>; getHandlers: any; off: any; on: any; one: any; trigger: any } = evented

Type declaration

  • handlers: Record<string, unknown>
  • getHandlers:function
  • off:function
    • off(event: string, handler: Function): void
    • Unregister an event handler.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function that handles the event.

      Returns void

  • on:function
    • on(event: string, handler: Function): void
    • Register an event handler.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function to handle the event.

      Returns void

  • one:function
    • one(event: string, handler: Function): void
    • Register an event handler so that it will run only once, and then unregister itself.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • handler: Function

        The function to handle the event.

      Returns void

  • trigger:function
    • trigger(event: string, ...args: any[]): void
    • Trigger an event.

      deprecated

      Parameters

      • event: string

        The name of the event.

      • Rest ...args: any[]

        Arguments to pass to event handlers.

      Returns void

utils/extract

utils/extract: <T, K>(object: T, property: K) => T[K] = extract

Type declaration

    • <T, K>(object: T, property: K): T[K]
    • The extract utility deletes a property from an object and returns its value.

      Type parameters

      • T

      • K: string | number | symbol

      Parameters

      • object: T

        The object that owns the property

      • property: K

        The name of the property to extract

      Returns T[K]

      The value of the property

utils/extractText

utils/extractText: (vdom: Children) => string = extractText

Type declaration

    • (vdom: Children): string
    • Extract the text nodes from a virtual element.

      Parameters

      • vdom: Children

      Returns string

utils/focusTrap

utils/focusTrap: __module = FocusTrap

utils/formatNumber

utils/formatNumber: (number: number, locale?: string) => string = formatNumber

Type declaration

    • (number: number, locale?: string): string
    • The formatNumber utility localizes a number into a string with the appropriate punctuation based on the provided locale otherwise will default to the users locale.

      example

      formatNumber(1234); // 1,234

      Parameters

      • number: number
      • locale: string = app.data.locale

      Returns string

utils/humanTime

utils/humanTime: (time: undefined | null | string | number | Date | Dayjs) => string = humanTime

Type declaration

    • (time: undefined | null | string | number | Date | Dayjs): string
    • The humanTime utility converts a date to a localized, human-readable time- ago string.

      Parameters

      • time: undefined | null | string | number | Date | Dayjs

      Returns string

utils/insertText

utils/insertText: (textarea: HTMLTextAreaElement, __namedParameters: SelectionRange) => void = insertText

Type declaration

utils/isObject

utils/isObject: (obj: unknown) => obj is object = isObject

Type declaration

    • (obj: unknown): obj is object
    • Returns if the passed value is an object.

      In this context, "object" refers to any non-primitive value, including arrays, function, maps, dates, and more.

      example

      isObject({}); // true

      example

      isObject([]); // true

      example

      isObject(function () {}); // true

      example

      isObject(Object(1)); // true

      example

      isObject(null); // false

      example

      isObject(1); // false

      example

      isObject("hello world"); // false

      see

      https://github.com/jashkenas/underscore/blob/943977e34e2279503528a71ddcc2dd5f96483945/underscore.js#L87-L91

      Parameters

      • obj: unknown

      Returns obj is object

utils/liveHumanTimes

utils/liveHumanTimes: () => void = liveHumanTimes

Type declaration

    • (): void
    • The liveHumanTimes initializer sets up a loop every 1 second to update timestamps rendered with the humanTime helper.

      Returns void

utils/mapRoutes

utils/mapRoutes: (routes: Record<string, FlarumGenericRoute>, basePath?: string) => Record<string, RouteResolver<Record<string, unknown>, Component<{ routeName: string }, undefined>, Record<string, unknown>>> = mapRoutes

Type declaration

    • The mapRoutes utility converts a map of named application routes into a format that can be understood by Mithril, and wraps them in route resolvers to provide each route with the current route name.

      see

      https://mithril.js.org/route.html#signature

      Parameters

      Returns Record<string, RouteResolver<Record<string, unknown>, Component<{ routeName: string }, undefined>, Record<string, unknown>>>

utils/mixin

utils/mixin: (Parent: object, ...mixins: Record<string, any>[]) => object = mixin

Type declaration

    • (Parent: object, ...mixins: Record<string, any>[]): object
    • The mixin utility assigns the properties of a set of 'mixin' objects to the prototype of a parent object.

      example

      class MyClass extends mixin(ExistingClass, evented, etc) {}

      Parameters

      • Parent: object

        The class to extend the new class from.

      • Rest ...mixins: Record<string, any>[]

        The objects to mix in.

      Returns object

      A new class that extends Parent and contains the mixins.

utils/patchMithril

utils/patchMithril: (global: any) => void = patchMithril

Type declaration

    • (global: any): void
    • Parameters

      • global: any

      Returns void

utils/proxifyCompat

utils/proxifyCompat: (compat: Record<string, unknown>, namespace: string) => Record<string, unknown> = proxifyCompat

Type declaration

    • (compat: Record<string, unknown>, namespace: string): Record<string, unknown>
    • Parameters

      • compat: Record<string, unknown>
      • namespace: string

      Returns Record<string, unknown>

utils/setRouteWithForcedRefresh

utils/setRouteWithForcedRefresh: (route: string, params?: null, options?: RouteOptions) => void = setRouteWithForcedRefresh

Type declaration

    • (route: string, params?: null, options?: RouteOptions): void
    • Mithril 2 does not completely rerender the page if a route change leads to the same route (or the same component handling a different route). This util calls m.route.set, forcing a reonit.

      see

      https://mithril.js.org/route.html#key-parameter

      Parameters

      • route: string
      • params: null = null
      • options: RouteOptions = {}

      Returns void

utils/string

utils/string: __module = string

utils/stringToColor

utils/stringToColor: (string: string) => string = stringToColor

Type declaration

    • (string: string): string
    • Convert the given string to a unique color.

      Parameters

      • string: string

      Returns string

utils/styleSelectedText

utils/styleSelectedText: (textarea: HTMLTextAreaElement, styleArgs: StyleArgs) => void = styleSelectedText

Type declaration

utils/subclassOf

utils/subclassOf: (A: any, B: any) => any = subclassOf

Type declaration

    • (A: any, B: any): any
    • Check if class A is the same as or a subclass of class B.

      Parameters

      • A: any
      • B: any

      Returns any

utils/throttleDebounce

utils/throttleDebounce: __module = ThrottleDebounce

utils/withAttr

utils/withAttr: (key: string, cb: Function) => () => void = withAttr

Type declaration

Generated using TypeDoc version 0.22.10