Sha256: 7e091bc3c0bad901f5345256d0fdf9d3ef957e2856d624abd54d84514e7ddb5c

Contents?: true

Size: 1.89 KB

Versions: 79

Compression:

Stored size: 1.89 KB

Contents

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import ElementObserver from './element_observer'

export default class PbEnhancedElement {
  static _elements: Map<Element, PbEnhancedElement>
  static _observer: ElementObserver
  element: Element

  constructor(element: Element) {
    this.element = element
  }

  static get elements(): Map<Element, PbEnhancedElement> {
    return this._elements = (this._elements || new Map)
  }

  static get observer(): ElementObserver {
    return this._observer = (this._observer || new ElementObserver(this))
  }

  static get selector(): string {
    // eslint-disable-next-line no-console
    console.warn('Define a static property for selector or redefine the matches function in a subclass.', this)
    return null
  }

  static matches(node: Element): Array<Element> {
    if (!this.selector) return []

    const matches = []
    if (node.nodeType === Node.ELEMENT_NODE && node.matches(this.selector)) matches.push(node)
    matches.push(...node.querySelectorAll(this.selector))

    return (matches)
  }

  static addMatch(element: Element): void {
    if (element._pbEnhanced || this.elements.has(element)) return

    const enhansedElement = new this(element)
    enhansedElement.connect()
    this.elements.set(element, enhansedElement)
    element._pbEnhanced = enhansedElement
  }

  static removeMatch(element: Element): void {
    if (!this.elements.has(element)) return

    const enhansedElement = this.elements.get(element)
    enhansedElement.disconnect()
    this.elements.delete(element)
  }

  static start(): void {
    this.observer.start()
  }

  static stop(): void {
    this.mutationObserver.stop()
  }

  connect(): void {
    // eslint-disable-next-line no-console
    console.warn('Redefine the connect function in a subclass.', this)
  }

  // eslint-disable-next-line @typescript-eslint/no-empty-function
  disconnect(): void {}
}

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
playbook_ui-12.15.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.14.0.pre.alpha.lightboxcurrentphotoprop460 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.14.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown457 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.14.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown456 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.14.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.13.0.pre.alpha.PLAY693tooltipwrongbg440 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.13.0.pre.alpha.addingProductTokens439 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.13.0.pre.alpha.PLAY705phonenumberkit438 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.13.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.12.0.pre.alpha.PLAY697sandpacklayoutstyles413 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.12.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.11.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.10.0.pre.alpha.PLAY705phonenumberreturn372 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.10.0.pre.alpha.PLAY677richtexteditorts370 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.10.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.9.1.pre.alpha.play664tiptapinvestigation353 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.9.1.pre.alpha.PLAY689bugtxtinputlabel346 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.9.1.pre.alpha.menucleanup345 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.9.1.pre.alpha.menucleanup342 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-12.9.1 app/pb_kits/playbook/pb_enhanced_element/index.ts