Skip to content

Instantly share code, notes, and snippets.

@al6x
Last active June 30, 2023 21:26
Show Gist options
  • Save al6x/0956742b7c7e1ddb9815ff9466e96e71 to your computer and use it in GitHub Desktop.
Save al6x/0956742b7c7e1ddb9815ff9466e96e71 to your computer and use it in GitHub Desktop.
type SpecialInputKeys = 'alt' | 'ctrl' | 'meta' | 'shift'
interface ClickEvent { special_keys: SpecialInputKeys[] }
interface KeydownEvent { key: string, special_keys: SpecialInputKeys[] }
interface ChangeEvent { stub: string }
interface BlurEvent { stub: string }
interface InputEvent { value: string }
type InEvent =
{ kind: 'location', el: number[], location: string } | // el not needed for location but Nim requires it.
{ kind: 'click', el: number[], click: ClickEvent } |
{ kind: 'dblclick', el: number[], dblclick: ClickEvent } |
{ kind: 'keydown', el: number[], keydown: KeydownEvent } |
{ kind: 'change', el: number[], change: ChangeEvent } |
{ kind: 'blur', el: number[], blur: BlurEvent } |
{ kind: 'input', el: number[], input: InputEvent }
type OutEvent =
{ kind: 'eval', code: string } |
{ kind: 'update', diffs: Diff[] } |
{ kind: 'ignore' } |
{ kind: 'expired' } |
{ kind: 'error', message: string }
type InEventEnvelope =
{ kind: 'events', mono_id: string, events: InEvent[] } |
{ kind: 'pull', mono_id: string }
// Diff
type SafeHtml = string
type ElAttrKind = "string_prop" | "string_attr" | "bool_prop"
type ElAttrVal = [string, ElAttrKind] | string
type ElAttrDel = [string, ElAttrKind] | string
interface ApplyDiff {
replace(id: number[], html: SafeHtml): void
add_children(id: number[], els: SafeHtml[]): void
set_children_len(id: number[], len: number): void
set_attrs(id: number[], attrs: Record<string, ElAttrVal>): void
del_attrs(id: number[], attrs: ElAttrDel[]): void
set_text(id: number[], text: string): void
set_html(id: number[], html: SafeHtml): void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment