This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback } from 'react'; | |
| function isElementDisabled(el: HTMLElement): boolean { | |
| return ( | |
| el.hasAttribute('disabled') || | |
| el.getAttribute('aria-disabled') === 'true' || | |
| el.getAttribute('data-disabled') === 'true' | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Ephemeral Element Capture & Injection | |
| * | |
| * Usage: | |
| * ephemera.startObserving(); | |
| * ephemera.trace(); // to see the captured HTML in the console | |
| * ephemera.injectElement(); | |
| */ | |
| const ephemera = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const propMapper = { | |
| typeMap: {}, | |
| trueTypeOf(obj) { | |
| const match = {}.toString.call(obj).match(/\s([a-zA-Z]+)/); | |
| const trueType = match?.[1]?.toLowerCase?.() ?? 'unknown'; | |
| return trueType === 'asyncgeneratorfunction' ? 'function' : trueType; | |
| }, | |
| inferType(value) { | |
| const type = propMapper.trueTypeOf(value); | |
| switch (type) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function whenDOMready(func ) { | |
| switch ((document.readyState + "")) { | |
| case "complete": | |
| case "loaded": | |
| case "interactive": | |
| func(); | |
| break; | |
| default: | |
| window.addEventListener("DOMContentLoaded", (e) => func()); | |
| } |
OlderNewer