This file contains 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 from 'react' | |
import { Patch, produceWithPatches } from 'immer' | |
export interface StateManager<T = {}> { | |
handle<P>(signal: Signal<P>, callback: (state: T, event: P) => void): () => void | |
getState(): T | |
onStateChanged: Signal<{ state: T, changes: Patch[] }> | |
} |
This file contains 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
// MUTT - Micro Unit Testing Tool (for browsers) | |
let _testDepth = 0; | |
export function test(name, suite) { | |
const title = `🐶 ${name}`; | |
const ctx = { | |
count: 0, | |
failed: 0 | |
}; |
This file contains 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 { observable, computed, runInAction } from 'mobx' | |
import uid from './uid' | |
type UndoFn = () => void | |
type Command = () => UndoFn | Promise<UndoFn> | |
interface UndoContext { | |
id: string | |
label: string | |
command: Command |
This file contains 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
type UndoFn = () => void | |
type Command = () => UndoFn | Promise<UndoFn> | |
interface UndoContext { | |
command: Command | |
revert: UndoFn | Promise<UndoFn> | |
} | |
export class UndoManager { | |
undoStack: UndoContext[] = [] |
This file contains 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 _ from 'lodash' | |
class TagSet { | |
constructor({ name, slug, sortBy = 'title' }) { | |
/** @type {string} */ | |
this.name = name | |
/** @type {string} */ | |
this.slug = slug | |
/** @type {string} */ | |
this.sortBy = sortBy |
This file contains 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 { renderMarkdown, useCollection, useFiles, usePage, useSite, xml } from "../packages/tilt/index.js"; | |
export default function Feed(props, children) { | |
const site = useSite() | |
const posts = useCollection('posts') | |
const buildDate = (new Date()).toUTCString() | |
return xml`<?xml version="1.0" encoding="UTF-8"?> | |
<rss | |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
This file contains 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
let _stack = [{}] | |
export function getContext(key) { | |
return _stack[0][key] | |
} | |
export function setContext(key, value) { | |
_stack[0][key] = value | |
} |
This file contains 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
export function selectImage(accepts: string = "image/*"): Promise<File | null> { | |
return new Promise((resolve, reject) => { | |
const input = createFileInput(accepts) | |
let focusCount = 0 | |
let fileWasSelected = false | |
input.onchange = (e: any) => { | |
fileWasSelected = true | |
const file = e.target.files[0] |
This file contains 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 _tokenCache = new WeakMap<CockpitAPI, string>() | |
export class CockpitAPI { | |
constructor(public readonly baseUrl: string, token: string) { | |
_tokenCache.set(this, token) | |
} | |
setToken(token: string) { |
This file contains 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 * as React from 'react' | |
import { stream, scan } from 'flyd' | |
import merge from 'mergerino' | |
interface StreamedStateConfigObject<T, A> { | |
state: T, actions: (updater: (value: Partial<T>) => void) => A | |
} | |
type StreamedStateConfigBuilder<T, A> = () => StreamedStateConfigObject<T, A> |