Copyright | (c) Mike Solomon 2020 |
---|---|
License | GPL-3 |
Maintainer | mike@meeshkan.com |
Stability | experimental |
Portability | POSIX, Windows |
Safe Haskell | None |
Language | Haskell2010 |
This module contains the base functions for plzwrk, notably the family of plzwrk functions needed for plzwrk to work. It also exports most of the utility functions used for building web applications, like event handling and attribute wrangling.
Synopsis
- plzwrk :: (state -> PwNode state jsval) -> state -> JSEnv jsval -> String -> IO ()
- plzwrk' :: (state -> PwNode state jsval) -> state -> JSEnv jsval -> IO ()
- plzwrk'_ :: (() -> PwNode () jsval) -> JSEnv jsval -> IO ()
- plzwrkSSR :: (state -> PwNode state jsval) -> state -> JSEnv jsval -> String -> IO ()
- toHTML :: (state -> PwNode state jsval) -> state -> String
- data PwNode s opq
- = PwElement {
- _elt_tag :: String
- _elt_attrs :: [(String, s -> PwAttribute s opq)]
- _elt_children :: [s -> PwNode s opq]
- | PwTextNode { }
- = PwElement {
- data PwAttribute s opq
- = PwTextAttribute String
- | PwFunctionAttribute (opq -> s -> IO s)
- data JSEnv jsval = JSEnv {
- castToArray :: jsval -> IO (Maybe [jsval])
- castToBool :: jsval -> IO (Maybe Bool)
- castToByteString :: jsval -> IO (Maybe ByteString)
- castToDouble :: jsval -> IO (Maybe Double)
- castToInt :: jsval -> IO (Maybe Int)
- castToString :: jsval -> IO (Maybe String)
- consoleLog :: jsval -> IO ()
- defaultRequestInit :: RequestInit jsval
- documentBody :: IO jsval
- documentCreateElement :: String -> IO jsval
- documentCreateTextNode :: String -> IO jsval
- documentGetElementById :: String -> IO (Maybe jsval)
- documentHead :: IO jsval
- fetch :: String -> RequestInit jsval -> IO jsval
- getPropertyAsOpaque :: jsval -> String -> IO (Maybe jsval)
- invokeOn0 :: jsval -> String -> IO jsval
- invokeOn1 :: jsval -> String -> jsval -> IO jsval
- invokeOn2 :: jsval -> String -> jsval -> jsval -> IO jsval
- jsValFromArray :: [jsval] -> IO jsval
- jsValFromBool :: Bool -> IO jsval
- jsValFromByteString :: ByteString -> IO jsval
- jsValFromDouble :: Double -> IO jsval
- jsValFromInt :: Int -> IO jsval
- jsValFromString :: String -> IO jsval
- makeObject :: IO jsval
- mathRandom :: IO Double
- setValue :: jsval -> String -> jsval -> IO ()
- _freeCallback :: jsval -> IO ()
- _makeHaskellCallback1 :: (jsval -> IO ()) -> IO jsval
- _makeHaskellCallback2 :: (jsval -> jsval -> IO ()) -> IO jsval
- _makeHaskellCallback3 :: (jsval -> jsval -> jsval -> IO ()) -> IO jsval
- pwx :: QuasiQuoter
- pwx' :: QuasiQuoter
- plusplus :: [a] -> [a] -> [a]
- parsePWX :: Monad m => (String, Int, Int) -> String -> m PWX
- parsePWX_ :: Monad m => String -> m PWX
- data PWX
- = PWXElement { }
- | PWXSelfClosingTag { }
- | PWXHaskellCode { }
- | PWXHaskellCodeList { }
- | PWXHaskellText { }
- | PWXBody { }
- data PWXAttribute
- pF :: (opq -> s -> IO s) -> s -> PwAttribute s opq
- pT :: String -> s -> PwAttribute s opq
- eventPreventDefault :: JSEnv jsval -> jsval -> IO ()
- eventTargetBlur :: JSEnv jsval -> jsval -> IO ()
- eventTargetValue :: JSEnv jsval -> jsval -> IO (Maybe String)
- elementSetAttribute :: JSEnv jsval -> jsval -> String -> String -> IO ()
- elementTagName :: JSEnv jsval -> jsval -> IO (Maybe String)
- eventTargetAddEventListener :: JSEnv jsval -> jsval -> String -> jsval -> IO ()
- eventTargetRemoveEventListener :: JSEnv jsval -> jsval -> String -> jsval -> IO ()
- getPropertyAsBool :: JSEnv jsval -> jsval -> String -> IO (Maybe Bool)
- getPropertyAsDouble :: JSEnv jsval -> jsval -> String -> IO (Maybe Double)
- getPropertyAsInt :: JSEnv jsval -> jsval -> String -> IO (Maybe Int)
- getPropertyAsString :: JSEnv jsval -> jsval -> String -> IO (Maybe String)
- htmlElemenetClick :: JSEnv jsval -> jsval -> IO ()
- consoleLogS :: JSEnv jsval -> String -> IO ()
- nodeAppendChild :: JSEnv jsval -> jsval -> jsval -> IO ()
- nodeChildNodes :: JSEnv jsval -> jsval -> IO (Maybe [jsval])
- nodeInsertBefore :: JSEnv jsval -> jsval -> jsval -> jsval -> IO ()
- nodeRemoveChild :: JSEnv jsval -> jsval -> jsval -> IO ()
- nodeTextContent :: JSEnv jsval -> jsval -> IO (Maybe String)
Documentation
:: (state -> PwNode state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> JSEnv jsval | A browser implementation, ie Asterius or the mock browser |
-> String | The id of the element into which the DOM is inserted. Note that plzwrk manages all children under this element. Touching the managed elements can break plzwrk. |
-> IO () | Returns nothing |
The main function that makes a web app.
plzwrk' :: (state -> PwNode state jsval) -> state -> JSEnv jsval -> IO () Source #
A variation of plzwrk that inserts the node as a child of the document's body.
plzwrk'_ :: (() -> PwNode () jsval) -> JSEnv jsval -> IO () Source #
A variation of plzwrk that takes no state.
:: (state -> PwNode state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> JSEnv jsval | A browser implementation, ie Asterius or the mock browser |
-> String | The id of the element into which the DOM is inserted. Note that plzwrk manages all children under this element. Touching the managed elements can break plzwrk. |
-> IO () | Returns nothing |
A variant of plzwrk that acts on a node already rendered to the DOM,
:: (state -> PwNode state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> String | The resulting HTML |
Converts a PwNode to HTML.
A DOM node.
The easiest way to create nodes is using tags such as
span
or br
.
PwNodes can be created for arbitrary tags using the PwElement
constructor.
PwNode is parameterized by two types
* s
- the type of the state
* opq
- the type of an opaque object in JavaScript
Note that nodes, when passed as an arguemnt to plzwrk
, need
to be Applicative Functors in the form (s -> PwNode s opq)
.
PwElement | |
| |
PwTextNode | |
data PwAttribute s opq Source #
PwTextAttribute String | |
PwFunctionAttribute (opq -> s -> IO s) |
Instances
Show (PwAttribute s opq) Source # | |
Defined in Web.Framework.Plzwrk.Base showsPrec :: Int -> PwAttribute s opq -> ShowS # show :: PwAttribute s opq -> String # showList :: [PwAttribute s opq] -> ShowS # |
A data class holding functions that operate on opaque
JavaScript types, parameterized by jsval
. When possible,
the real names of browser functions like addEventListener
and appendChild
are used.
JSEnv is currently implemented as data instead of as
a typeclass because it is unclear what type of additional
monadic transformer around IO would be most appropriate to
retain the state of jsval
objects, whereas when part of
a dataclass, the state retention is abstracted away.
JSEnv | |
|
pwx :: QuasiQuoter Source #
pwx' :: QuasiQuoter Source #
data PWXAttribute Source #
Instances
Eq PWXAttribute Source # | |
Defined in Web.Framework.Plzwrk.TH.PWX (==) :: PWXAttribute -> PWXAttribute -> Bool # (/=) :: PWXAttribute -> PWXAttribute -> Bool # | |
Show PWXAttribute Source # | |
Defined in Web.Framework.Plzwrk.TH.PWX showsPrec :: Int -> PWXAttribute -> ShowS # show :: PWXAttribute -> String # showList :: [PWXAttribute] -> ShowS # |
pF :: (opq -> s -> IO s) -> s -> PwAttribute s opq Source #
Creates a callback attribute wrapped in an applicative functor
pT :: String -> s -> PwAttribute s opq Source #
Creates a text attribute wrapped in an applicative functor
Take an event and prevent the default.
From an event, takes the target and blurs it.
:: JSEnv jsval | the browser |
-> jsval | the event |
-> IO (Maybe String) | the target value, or nothing if it doesn't exist |
From an event, gets the target's value.
:: JSEnv jsval | The browser |
-> jsval | the node |
-> String | the attribute name |
-> String | the attribute |
-> IO () | returns nothing |
Sets on an element an attribute. See Element.setAttribute
Gets the tag name of an element. See Element.tagName
eventTargetAddEventListener Source #
:: JSEnv jsval | the browser |
-> jsval | the element |
-> String | the listener name. note that this should be "click" or "input", not "onclick" nor "oninput" |
-> jsval | the listener |
-> IO () | returns nothing |
Takes a target and an event name and adds a listener. See EventTarget.addEventListener
eventTargetRemoveEventListener Source #
:: JSEnv jsval | the browser |
-> jsval | the element |
-> String | the listener name. note that this should be "click" or "input", not "onclick" nor "oninput" |
-> jsval | the listener |
-> IO () | returns nothing |
Takes a target and an event name and removes a listener. See EventTarget.removeEventListener
:: JSEnv jsval | the browser |
-> jsval | the object containing the property |
-> String | the property name |
-> IO (Maybe Bool) | the response if the property is a bool, else Nothing |
Gets a JavaScript property as a bool, returning Nothing
if the object being called is null or undefined or the property cannot be cast to a bool.
:: JSEnv jsval | the browser |
-> jsval | the object containing the property |
-> String | the property name |
-> IO (Maybe Double) | the response if the property is a double, else Nothing |
Gets a JavaScript property as a double, returning Nothing
if the object being called is null or undefined or the property cannot be cast to a double.
:: JSEnv jsval | the browser |
-> jsval | the object containing the property |
-> String | the property name |
-> IO (Maybe Int) | the response if the property is an int, else Nothing |
Gets a JavaScript property as an int, returning Nothing
if the object being called is null or undefined or the property cannot be cast to an int.
:: JSEnv jsval | the browser |
-> jsval | the object containing the property |
-> String | the property name |
-> IO (Maybe String) | the response |
Gets a JavaScript property as an string, returning Nothing
if the object being called is null or undefined.
htmlElemenetClick :: JSEnv jsval -> jsval -> IO () Source #
Takes an element and clicks it. Useful for testing. See HTMLElement.click
consoleLogS :: JSEnv jsval -> String -> IO () Source #
Logs a string. See Console.log
Takes a node and appends a child. See Node.appendChild
Get the children of a node. See Node.childNodes
:: JSEnv jsval | the browser |
-> jsval | the parent element |
-> jsval | the new node |
-> jsval | the pre-existing node |
-> IO () | returns nothing |
Inserts a node into an element before another node. See Node.insertBefore
:: JSEnv jsval | the browser |
-> jsval | the parent element |
-> jsval | the child to remove |
-> IO () | returns nothing |
Removes a child from a parent node. See Node.removeChild
Gets the text content of a node. See Node.textContent