SoHL's specialization of Foundry's ContextMenu UI control.

Extends the base context menu to accept SohlContextMenu.Entry definitions whose condition may be a string SafeExpression (compiled to a predicate) and whose callback may be omitted in favour of a named logic method (functionName). The constructor normalizes those entries into the function-based shape Foundry expects, and the class adds custom positioning (_setPosition) plus static helpers for resolving the triggering item/actor from the DOM.

The Foundry-free entry shape, condition compilation, and DOM resolution helpers live in import so the logic layer can use them without loading this Foundry-coupled UI class. The static helpers and namespace members here delegate to (and re-export) that module.

Hierarchy

  • any
    • SohlContextMenu

Indexable

  • [key: string]: any

Constructors

  • Build a context menu, compiling each entry into the function-based shape Foundry's base class expects.

    For every entry (via compileMenuEntry): the authored condition is compiled into Foundry's visible predicate, and when no explicit callback is supplied a default one is generated that resolves the context item, builds a SohlActionContext, and invokes the named functionName on the item's logic object.

    Parameters

    • container: HTMLElement

      The DOM element the menu is bound to.

    • selector: string

      CSS selector identifying the rows the menu attaches to.

    • menuItems: ContextMenuEntry[]

      The SoHL entry definitions to display.

    • options: sohl.apps.foundry.SohlContextMenu.Options = {}

      Optional context-menu configuration.

    Returns sohl.apps.foundry.SohlContextMenu

    Error if an entry has neither a callback nor a functionName.

Methods

  • Compile a context-menu condition into a predicate suitable for Foundry's ContextMenu base class.

    Parameters

    • source: ContextMenuCondition

      The condition source to compile.

    • entryName: string

      The entry name, used for error reporting.

    • Optionalparent: SohlLogic

      The owning document's logic, used as the compiled expression's parent (required for string conditions).

    Returns (target: HTMLElement) => boolean

    A predicate evaluating the condition against a target element.

  • Build the lazy evaluation context for a context-menu condition.

    Parameters

    • target: HTMLElement

      The element the context menu was opened on.

    Returns Record<string, unknown>

    The evaluation context exposed to the condition.

  • Resolve the SohlActor indicated by the closest [data-actor-id] ancestor of target.

    Parameters

    • target: HTMLElement

      The element the context menu was opened on.

    Returns undefined | SohlActor

    The resolved actor, or undefined if none is found.

  • Resolve the SohlItem indicated by the closest [data-item-id] ancestor of target.

    Parameters

    • target: HTMLElement

      The element the context menu was opened on.

    Returns undefined | SohlItem

    The resolved item, or undefined if none is found.