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
// use JSX with el instead of React.createElement | |
/** @jsx createElement */ | |
const Children = { | |
only(children) { | |
if (children.length > 1 || children.length === 0) { | |
throw new Error('The children must have only one element'); | |
} | |
return children[0]; | |
} |
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 target = document.documentElement; | |
// config object | |
const config = { | |
attributes: true, | |
attributeOldValue: true, | |
characterData: true, | |
characterDataOldValue: true, | |
childList: 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
function Catch(E, callback) { | |
return function (target, key: string, descriptor: PropertyDescriptor) { | |
if(descriptor === undefined) { | |
descriptor = Object.getOwnPropertyDescriptor(target, key); | |
} | |
var originalMethod = descriptor.value; | |
descriptor.value = function () { | |
try { |
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
// Based on https://hiddedevries.nl/en/blog/2017-01-29-using-javascript-to-trap-focus-in-an-element | |
import React, { useRef, useEffect } from 'react'; | |
const KEYCODE_TAB = 9; | |
function useFocusTrap() { | |
const elRef = useRef(null); | |
function handleFocus(e) { |
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 { | |
html, | |
LitElement | |
} from "https://unpkg.com/@polymer/[email protected]/lit-element.js?module"; | |
const KEYCODE_TAB = 9; | |
class FocusTrap extends LitElement { | |
constructor() { | |
super(); |
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
// used to retrieve template content | |
const templates = new Map; | |
// used to retrieve node updates | |
const updates = new WeakMap; | |
// hyperHTML, the nitty gritty | |
function hyperHTML(chunks, ...interpolations) { | |
// if the static chunks are unknown |
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 React, { Suspense, useState } from "react"; | |
import { unstable_createResource as createResource } from "react-cache"; | |
import { | |
Combobox, | |
ComboboxInput, | |
ComboboxList, | |
ComboboxOption | |
} from "./Combobox2.js"; | |
function App({ tabIndex, navigate }) { |
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 React, { useMemo } from "react"; | |
import useSubscription from "./useSubscription"; | |
// In this example, "source" is an event dispatcher (e.g. an HTMLInputElement) | |
// but it could be anything that emits an event and has a readable current value. | |
function Example({ source }) { | |
// In order to avoid removing and re-adding subscriptions each time this hook is called, | |
// the parameters passed to this hook should be memoized. | |
const subscription = useMemo( | |
() => ({ |
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 SwiftUI | |
import Combine | |
class MyDatabase: BindableObject { | |
let didChange = PassthroughSubject<MyDatabase, Never>() | |
var contacts: [Contact] = [ | |
Contact(id: 1, name: "Anna"), Contact(id: 2, name: "Beto"), | |
Contact(id: 3, name: "Jack"), Contact(id: 4, name: "Sam") | |
] { |
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
/* Box sizing rules */ | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
/* Remove default padding */ | |
ul[class], | |
ol[class] { |