Sha256: 0ed87de68a4057d360d0b643157dc8602339eea22449b1f5a96049dd3a102e94

Contents?: true

Size: 1.86 KB

Versions: 645

Compression:

Stored size: 1.86 KB

Contents

// eslint-disable-next-line
// @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

645 entries across 645 versions & 1 rubygems

Version Path
playbook_ui-14.11.1.pre.alpha.PLAY1720phonenumberinputformatAsYouType5377 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.play17725374 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.play17725372 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.12.0.pre.rc.4 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.hfhbrakemanplaybook5370 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.responsivetablerails5364 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.responsivetablerails5362 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.PBNTR769sticky5359 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.PBNTR573datepickerinvestigation5355 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5341 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5340 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5339 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.12.0.pre.rc.3 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.12.0.pre.rc.2 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.12.0.pre.rc.1 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.12.0.pre.rc.0 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5315 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5314 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.10.0.pre.alpha.PLAY1750pbcontenttagkitbutton5308 app/pb_kits/playbook/pb_enhanced_element/index.ts
playbook_ui-14.11.1 app/pb_kits/playbook/pb_enhanced_element/index.ts