plzwrk-0.0.0.8: A front-end framework

Copyright(c) Mike Solomon 2020
LicenseGPL-3
Maintainermike@meeshkan.com
Stabilityexperimental
PortabilityPOSIX, Windows
Safe HaskellNone
LanguageHaskell2010

Web.Framework.Plzwrk

Description

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

Documentation

plzwrk Source #

Arguments

:: (state -> PwNode state jsval)

A function that takes a state and produces a DOM

-> state

An initial state

-> Browserful 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 -> Browserful jsval -> IO () Source #

A variation of plzwrk that inserts the node as a child of the document's body.

plzwrk'_ :: (() -> PwNode () jsval) -> Browserful jsval -> IO () Source #

A variation of plzwrk that takes no state.

plzwrkSSR Source #

Arguments

:: (state -> PwNode state jsval)

A function that takes a state and produces a DOM

-> state

An initial state

-> Browserful 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,

toHTML Source #

Arguments

:: (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.

data PwNode s opq Source #

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).

Constructors

PwElement 

Fields

PwTextNode 

Fields

Instances
Show (PwNode s opq) Source # 
Instance details

Defined in Web.Framework.Plzwrk.Base

Methods

showsPrec :: Int -> PwNode s opq -> ShowS #

show :: PwNode s opq -> String #

showList :: [PwNode s opq] -> ShowS #

data PwAttribute s opq Source #

Constructors

PwTextAttribute String 
PwFunctionAttribute (opq -> s -> IO s) 
Instances
Show (PwAttribute s opq) Source # 
Instance details

Defined in Web.Framework.Plzwrk.Base

Methods

showsPrec :: Int -> PwAttribute s opq -> ShowS #

show :: PwAttribute s opq -> String #

showList :: [PwAttribute s opq] -> ShowS #

data Browserful jsval Source #

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.

Browserful 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.

Constructors

Browserful 

Fields

plusplus :: [a] -> [a] -> [a] Source #

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

eventPreventDefault Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the event

-> IO ()

returns nothing

Take an event and prevent the default.

eventTargetBlur Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the event

-> IO ()

returns nothing

From an event, takes the target and blurs it.

eventTargetValue Source #

Arguments

:: Browserful 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.

elementSetAttribute Source #

Arguments

:: Browserful 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

elementTagName Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the element

-> IO (Maybe String)

Returns the tag name

Gets the tag name of an element. See Element.tagName

eventTargetAddEventListener Source #

Arguments

:: Browserful 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 #

Arguments

:: Browserful 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

getPropertyAsBool Source #

Arguments

:: Browserful 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.

getPropertyAsDouble Source #

Arguments

:: Browserful 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.

getPropertyAsInt Source #

Arguments

:: Browserful 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.

getPropertyAsString Source #

Arguments

:: Browserful 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 :: Browserful jsval -> jsval -> IO () Source #

Takes an element and clicks it. Useful for testing. See HTMLElement.click

consoleLogS :: Browserful jsval -> String -> IO () Source #

Logs a string. See Console.log

nodeAppendChild Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the node

-> jsval

the child to append

-> IO ()

returns nothing

Takes a node and appends a child. See Node.appendChild

nodeChildNodes Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the node

-> IO (Maybe [jsval]) 

Get the children of a node. See Node.childNodes

nodeInsertBefore Source #

Arguments

:: Browserful 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

nodeRemoveChild Source #

Arguments

:: Browserful 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

nodeTextContent Source #

Arguments

:: Browserful jsval

the browser

-> jsval

the node

-> IO (Maybe String)

the text content as a string

Gets the text content of a node. See Node.textContent