facy - v0.1.0
    Preparing search index...

    Class Tag<T>

    Base class that manages a single native DOM node.

    Also provides a number of static factory functions to create common tags (e.g. Tag.div, Tag.span, Tag.h, Tag.p...).

    Instance functionality is separated into composition and usage concerns.

    This base class only exposes usage functionality, while ComposableTag adds composition functionality. By using this class as a return type, functions can effectively expose only usage functionality, reserving composition as an internal concern.

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    EVENT_CLASSES: EventClassRegistry = ...
    node: T

    Methods

    • Type Parameters

      • T extends keyof HTMLElementTagNameMap

      Parameters

      • type: T

      Returns HtmlTag<T>

    • Type Parameters

      • T extends keyof SVGElementTagNameMap

      Parameters

      • type: T

      Returns SvgTag<T>

    • Convenience function that creates a div with the CSS property display: flex. The given type is used to set flex-direction accordingly and set width: 100% in case of row. If no type is specified, row is assumed.

      Parameters

      • Optionaltype: "row" | "column"

      Returns HtmlTag<"div">

    • Like Tag.flex:DIV but creates a span with the CSS property display: inline-flex (and omits the width property).

      Parameters

      • type: "inline-row" | "inline-column"

      Returns HtmlTag<"span">

    • Convenience function that creates a div with the CSS property display: grid.

      Returns HtmlTag<"div">

    • Convenience function that creates a grid cell that is positioned according to the given coordinates. If you need to define a cell in any other way, just create your own element.

      Parameters

      • x: number
      • y: number
      • width: number = 1
      • height: number = 1

      Returns HtmlTag<"div">

    • Type Parameters

      • L extends 1 | 2 | 3 | 4 | 5 | 6

      Parameters

      • level: L
      • Optionaltext: any

      Returns HtmlTag<`h${L}`>

    • Parameters

      • Optionalurl: MaybeReactive<string>
      • target: MaybeReactive<string> = ...

      Returns HtmlTag<"a">

    • Parameters

      • type: "button" | "reset" | "submit" = 'button'

      Returns HtmlTag<"button">

    • Parse the given HTML fragment.

      Parameters

      • source: string

        HTML code

      • parse: HtmlParser = CONFIG.parseHtml

        how to parse and sanitize the source - always thoroughly sanitize untrusted code (i.e. any potential user input, including request parameters, local storage etc...)!

      Returns Tag<DocumentFragment>

    • Parse the given SVG code.

      Parameters

      • source: string

        SVG code

      • parse: HtmlParser = CONFIG.parseHtml

        how to parse and sanitize the source - always thoroughly sanitize untrusted code (i.e. any potential user input, including request parameters, local storage etc...)!

      Returns StylableTag<SVGSVGElement>

      Load SVGs at build time and embed them into the DOM, allowing them to be fully styled:

      import someSvg from '../assets/some.svg?raw'; // works with Vite - check how to import assets as string if you use another bundler

      Tag.parseSvg(someSvg).mount(document.body);
    • Registers the given event handler on this element.

      Be aware that Event.preventDefault is called for you, since this is almost always desirable. If ever you need to allow default handling, just return ALLOW_DEFAULT from the handler.

      Parameters

      • event: string
      • handler: EventHandler
      • Optionaloptions: AddEventListenerOptions

      Returns this

    • Like Tag.on:STRING but allows correct Event type checking in the handler for standard events.

      Type Parameters

      Parameters

      Returns this

    • Like Tag.on:STRING but identifies the event by its class instead of the conventional type string. This allows strong type checking in the handler even with custom events. It works by deferring the actual registration until an event is fired, at which time the type string can be determined from the event instance. For this reason this only works correctly for events dispatched through ComposableTag.fire (i.e. not for native events).

      Type Parameters

      Parameters

      Returns this

    • Unregisters one or all handlers of the given event. If no matching handler(s) is/are currently registered, this does nothing.

      Parameters

      • event: string | EventClass<any>

        either the type string or the class the handler was registered with.

      • Optionalhandler: EventHandler<Event>

        specific handler to remove, or omit to remove all handlers for the given event

      Returns this

    • Attach the underlying node to the given target, specified as an existing node or a selector.

      Parameters

      • target: string | Node

      Returns Cancel

      a function that unmounts and frees this tag.

    • Returns void