This might be a reasonable MVP for making your page content editable.
In the Iframe
- find all the elements that contain text
- make them editable with
contentEditable = 'true'
- listen for text changes and pass those changes to the parent window
const direction = { | |
'↑': [-1, 0], | |
'↗': [-1, 1], | |
'→': [0, 1], | |
'↘': [1, 1], | |
'↓': [1, 0], | |
'↙': [1, -1], | |
'←': [0, -1], | |
'↖': [-1, -1], | |
} satisfies Record<string, [number, number]> |
class Heap<T> { | |
#heap: (T | undefined)[] = [undefined] | |
#prioritize: (a: T, b: T) => number | |
constructor(prioritize: (a: T, b: T) => number, toHeapify: T[] = []) { | |
this.#prioritize = prioritize | |
this.#heap = [undefined, ...toHeapify] | |
this.#heapify() | |
} |
So let's say I'm building a website to tell me what I should wear based on the current weather (raining, sunny, snowing).
I only use the app once per day, and the weather won't change while I'm looking at the app, so the clothing choice should be constant.
I also want the code to be easy to read so other members of my team can easily understand the code.
Why is it cool?
const pubSub = <UpdateType>() => { | |
type Subscriber = ({ update, unsubscribe }: { update: UpdateType; unsubscribe: () => void }) => void | |
const subscribers = new Set<Subscriber>() | |
const subscribe = (sub: Subscriber) => subscribers.add(sub) | |
const publish = (update: UpdateType) => { | |
subscribers.forEach((sub) => { | |
const unsubscribe = () => subscribers.delete(sub) | |
sub({ update, unsubscribe }) |
const createExposedPromise = <T>() => { | |
let resolve: (value: T | PromiseLike<T>) => void | |
let reject: (reason: any) => void | |
const promise = new Promise<T>((res, rej) => { | |
resolve = res | |
reject = rej | |
}) | |
return { |
import { memo, useEffect, useRef } from "react" | |
const Dialog: React.FC<{ open: boolean, className?:string, children:React.ReactElement }> = ({ open, className, children }) => { | |
const dialogRef = useRef<HTMLDialogElement>(null) | |
useEffect(() => { | |
if (open) { | |
if(dialogRef.current?.open){ | |
dialogRef.current?.close() | |
} |
const useRecords = () => { | |
const [record, setRecord] = useState<Record<string, string>>({ | |
'record 1': 'foo', | |
'record 2': 'foo', | |
'record 3': 'bar', | |
}) | |
return { | |
get uniqueRecords() { | |
const uniqueRecords = new Set(Object.values(record)) |