-module(react_gleam@event). -compile(no_auto_import). -export([on/2, dispatch/1, on_click/1, on_mouse_down/1, on_mouse_up/1, on_mouse_enter/1, on_mouse_leave/1, on_mouse_over/1, on_mouse_out/1, on_keypress/1, on_keydown/1, on_keyup/1, on_input/1, on_check/1, on_submit/1, on_focus/1, on_blur/1]). -spec on(binary(), fun((gleam@dynamic:dynamic(), fun((GRY) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GRY). on(Name, Handler) -> react_gleam@attribute:event(Name, Handler). -spec dispatch(GSC) -> fun((fun((GSC) -> nil)) -> nil). dispatch(Action) -> fun(Dispatch) -> Dispatch(Action) end. -spec on_click(fun((fun((GSD) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GSD). on_click(Handler) -> on(<<"click"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_down(fun((fun((GSH) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GSH). on_mouse_down(Handler) -> on(<<"mouseDown"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_up(fun((fun((GSL) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GSL). on_mouse_up(Handler) -> on(<<"mouseUp"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_enter(fun((fun((GSP) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GSP). on_mouse_enter(Handler) -> on(<<"mouseEnter"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_leave(fun((fun((GST) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GST). on_mouse_leave(Handler) -> on(<<"mouseLeave"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_over(fun((fun((GSX) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GSX). on_mouse_over(Handler) -> on(<<"mouseOver"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_mouse_out(fun((fun((GTB) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTB). on_mouse_out(Handler) -> on(<<"mouseOut"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_keypress(fun((binary(), fun((GTF) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTF). on_keypress(Handler) -> on( <<"keyPress"/utf8>>, fun(E, Dispatch) -> {ok, Key@1} = case begin _pipe = E, (gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))( _pipe ) end of {ok, Key} -> {ok, Key}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"react_gleam/event"/utf8>>, function => <<"on_keypress"/utf8>>, line => 82}) end, Handler(Key@1, Dispatch) end ). -spec on_keydown(fun((binary(), fun((GTJ) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTJ). on_keydown(Handler) -> on( <<"keyDown"/utf8>>, fun(E, Dispatch) -> {ok, Key@1} = case begin _pipe = E, (gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))( _pipe ) end of {ok, Key} -> {ok, Key}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"react_gleam/event"/utf8>>, function => <<"on_keydown"/utf8>>, line => 97}) end, Handler(Key@1, Dispatch) end ). -spec on_keyup(fun((binary(), fun((GTN) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTN). on_keyup(Handler) -> on( <<"keyUp"/utf8>>, fun(E, Dispatch) -> {ok, Key@1} = case begin _pipe = E, (gleam@dynamic:field(<<"key"/utf8>>, fun gleam@dynamic:string/1))( _pipe ) end of {ok, Key} -> {ok, Key}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"react_gleam/event"/utf8>>, function => <<"on_keyup"/utf8>>, line => 112}) end, Handler(Key@1, Dispatch) end ). -spec on_input(fun((binary(), fun((GTR) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTR). on_input(Handler) -> on( <<"input"/utf8>>, fun(E, Dispatch) -> {ok, Value@1} = case begin _pipe = E, (gleam@dynamic:field( <<"target"/utf8>>, gleam@dynamic:field( <<"value"/utf8>>, fun gleam@dynamic:string/1 ) ))(_pipe) end of {ok, Value} -> {ok, Value}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"react_gleam/event"/utf8>>, function => <<"on_input"/utf8>>, line => 130}) end, Handler(Value@1, Dispatch) end ). -spec on_check(fun((boolean(), fun((GTV) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTV). on_check(Handler) -> on( <<"check"/utf8>>, fun(E, Dispatch) -> {ok, Value@1} = case begin _pipe = E, (gleam@dynamic:field( <<"target"/utf8>>, gleam@dynamic:field( <<"checked"/utf8>>, fun gleam@dynamic:bool/1 ) ))(_pipe) end of {ok, Value} -> {ok, Value}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"react_gleam/event"/utf8>>, function => <<"on_check"/utf8>>, line => 145}) end, Handler(Value@1, Dispatch) end ). -spec on_submit(fun((fun((GTZ) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GTZ). on_submit(Handler) -> on(<<"submit"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_focus(fun((fun((GUD) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GUD). on_focus(Handler) -> on(<<"focus"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end). -spec on_blur(fun((fun((GUH) -> nil)) -> nil)) -> react_gleam@attribute:attribute(any(), GUH). on_blur(Handler) -> on(<<"blur"/utf8>>, fun(_, Dispatch) -> Handler(Dispatch) end).