-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Composable algebraic editors
--   
--   This package provides a type class <a>Editable</a> and combinators to
--   easily put together form-like editors for algebraic datatypes.
--   
--   NOTE: This library contains examples, but they are not built by
--   default. To build and install the example, use the
--   <tt>buildExamples</tt> flag like this
--   
--   <pre>
--   cabal install threepenny-editors -fbuildExamples
--   </pre>
@package threepenny-editors
@version 0.5.6

module Data.HasEmpty

-- | This class defines how to represent empty values in a UI. A generic
--   derivation is available for every SOP type.
class HasEmpty a
emptyValue :: HasEmpty a => a
emptyValue :: (HasEmpty a, Generic a, HasEmptyCode (Code a), All HasEmpty (Head (Code a))) => a
class HasEmptyCode (xs :: [k])
gEmptyValue :: forall a. (Generic a, HasEmptyCode (Code a), All HasEmpty (Head (Code a))) => a
instance Data.HasEmpty.HasEmpty GHC.Types.Bool
instance Data.HasEmpty.HasEmpty GHC.Types.Char
instance Data.HasEmpty.HasEmpty GHC.Types.Int
instance Data.HasEmpty.HasEmpty GHC.Types.Double
instance Data.HasEmpty.HasEmpty Data.Text.Internal.Text
instance Data.HasEmpty.HasEmpty [a]
instance Data.HasEmpty.HasEmpty (GHC.Base.Maybe a)
instance Data.HasEmpty.HasEmpty ()
instance (Data.HasEmpty.HasEmpty a, Data.HasEmpty.HasEmpty b) => Data.HasEmpty.HasEmpty (a, b)
instance Data.HasEmpty.HasEmpty a => Data.HasEmpty.HasEmpty (Data.Functor.Identity.Identity a)
instance GHC.Classes.Ord k => Data.HasEmpty.HasEmpty (Data.Map.Internal.Map k v)
instance GHC.Classes.Ord k => Data.HasEmpty.HasEmpty (Data.Set.Internal.Set k)
instance Data.HasEmpty.HasEmpty (Data.Sequence.Internal.Seq k)
instance forall k (x :: k) (xs :: [k]). Data.HasEmpty.HasEmptyCode (x : xs)


-- | A custom layout engine and combinators.
module Graphics.UI.Threepenny.Editors.Layout

-- | Closely related to <a>Widget</a>, this class represents types that can
--   be rendered to an <a>Element</a>, either directly or via
--   <a>Layout</a>.
class Renderable w
render :: Renderable w => w -> UI Element
getLayout :: Renderable w => w -> Layout

-- | A rathe limited, grid layout builder, probably not fit for general
--   purpose use yet.
data Layout

-- | A non empty list of rows, where all the rows are assumed to have the
--   same length
Grid :: (Seq (Seq Layout)) -> Layout
beside :: Layout -> Layout -> Layout
above :: Layout -> Layout -> Layout

-- | A monoidal layout builder that places everything in a single column
newtype Vertical
Vertical :: Layout -> Vertical
[getVertical] :: Vertical -> Layout
vertical :: Renderable w => w -> Vertical

-- | A monoidal layout builder that places everything in a single row
newtype Horizontal
Horizontal :: Layout -> Horizontal
[getHorizontal] :: Horizontal -> Layout
horizontal :: Renderable w => w -> Horizontal

-- | A monoidal layout builder that lays elements in columns
data Columns

-- | Continue in the same column
Next :: Layout -> Columns

-- | Continue in the next column
Break :: Layout -> Columns

-- | Type level Horizontal layouts
data a (|*|) b
(:|*|) :: a -> b -> (|*|) a b

-- | Type level Vertical layouts
data a (-*-) b
(:-*-) :: a -> b -> (-*-) a b
instance Generics.SOP.Universe.Generic (a Graphics.UI.Threepenny.Editors.Layout.-*- b)
instance Generics.SOP.Universe.HasDatatypeInfo (a Graphics.UI.Threepenny.Editors.Layout.-*- b)
instance Generics.SOP.Universe.Generic (a Graphics.UI.Threepenny.Editors.Layout.|*| b)
instance Generics.SOP.Universe.HasDatatypeInfo (a Graphics.UI.Threepenny.Editors.Layout.|*| b)
instance Data.Bifunctor.Bifunctor (Graphics.UI.Threepenny.Editors.Layout.-*-)
instance Data.Bifoldable.Bifoldable (Graphics.UI.Threepenny.Editors.Layout.-*-)
instance Data.Biapplicative.Biapplicative (Graphics.UI.Threepenny.Editors.Layout.-*-)
instance (Graphics.UI.Threepenny.Editors.Layout.Renderable a, Graphics.UI.Threepenny.Editors.Layout.Renderable b) => Graphics.UI.Threepenny.Editors.Layout.Renderable (a Graphics.UI.Threepenny.Editors.Layout.-*- b)
instance (Data.HasEmpty.HasEmpty a, Data.HasEmpty.HasEmpty b) => Data.HasEmpty.HasEmpty (a Graphics.UI.Threepenny.Editors.Layout.-*- b)
instance Data.Bifunctor.Bifunctor (Graphics.UI.Threepenny.Editors.Layout.|*|)
instance Data.Bifoldable.Bifoldable (Graphics.UI.Threepenny.Editors.Layout.|*|)
instance Data.Biapplicative.Biapplicative (Graphics.UI.Threepenny.Editors.Layout.|*|)
instance (Graphics.UI.Threepenny.Editors.Layout.Renderable a, Graphics.UI.Threepenny.Editors.Layout.Renderable b) => Graphics.UI.Threepenny.Editors.Layout.Renderable (a Graphics.UI.Threepenny.Editors.Layout.|*| b)
instance (Data.HasEmpty.HasEmpty a, Data.HasEmpty.HasEmpty b) => Data.HasEmpty.HasEmpty (a Graphics.UI.Threepenny.Editors.Layout.|*| b)
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Editors.Layout.Columns
instance GHC.Show.Show Graphics.UI.Threepenny.Editors.Layout.Columns
instance GHC.Base.Monoid Graphics.UI.Threepenny.Editors.Layout.Columns
instance GHC.Base.Monoid Graphics.UI.Threepenny.Editors.Layout.Horizontal
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Editors.Layout.Horizontal
instance GHC.Base.Monoid Graphics.UI.Threepenny.Editors.Layout.Vertical
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Editors.Layout.Vertical
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Internal.Element
instance Graphics.UI.Threepenny.Editors.Layout.Renderable a => Graphics.UI.Threepenny.Editors.Layout.Renderable (Graphics.UI.Threepenny.Internal.UI a)
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Widgets.TextEntry
instance Graphics.UI.Threepenny.Editors.Layout.Renderable (Graphics.UI.Threepenny.Widgets.ListBox a)
instance Graphics.UI.Threepenny.Editors.Layout.Renderable GHC.Base.String
instance Graphics.UI.Threepenny.Editors.Layout.Renderable Graphics.UI.Threepenny.Editors.Layout.Layout

module Graphics.UI.Threepenny.Editors.Utils

-- | Returns a new behavior that only notifies for new values.
calmB :: Eq a => Behavior a -> UI (Behavior a)

-- | Returns a new <a>Event</a> that skips consecutive triggers with the
--   same value.
calmE :: Eq a => Event a -> UI (Event a)

module Graphics.UI.Threepenny.Editors.Types
data GenericWidget control a
GenericWidget :: Tidings a -> control -> GenericWidget control a

-- | The dynamic contents of the widget.
[widgetTidings] :: GenericWidget control a -> Tidings a

-- | The actual widget.
[widgetControl] :: GenericWidget control a -> control
edited :: GenericWidget el a -> Event a
contents :: GenericWidget el a -> Behavior a

-- | An editor for values of type <tt>inner</tt> inside a datatype
--   <tt>outer</tt> realized by a <tt>widget</tt>.
--   
--   All the three type arguments are functorial, but <tt>outer</tt> is
--   contravariant, so <tt>Editor</tt> is a <a>Biapplicative</a> functor
--   and a <a>Profunctor</a> (via <a>dimapE</a>).
--   
--   <a>Biapplicative</a> allows to compose editors on both their
--   <tt>widget</tt> and <tt>inner</tt> structure. When <tt>widget</tt> is
--   monoidal, widget composition is implicit and <a>Applicative</a>
--   suffices.
--   
--   <a>Profunctor</a> allows to apply an <tt>inner</tt> editor to an
--   <tt>outer</tt> datatype.
--   
--   Once <a>create</a>d, an <a>Editor</a> yields a tuple of an
--   <tt>widget</tt> and a <tt>Tidings inner</tt> which can be integrated
--   in a threepenny app.
newtype Editor outer widget inner
Editor :: (Behavior outer -> UI (GenericWidget widget inner)) -> Editor outer widget inner
[create] :: Editor outer widget inner -> Behavior outer -> UI (GenericWidget widget inner)

-- | Lift an HTML element into a vacuous editor.
liftElement :: UI el -> Editor a el ()
dimapE :: (a' -> a) -> (b -> b') -> Editor a el b -> Editor a' el b'
applyE :: (el1 -> el2 -> el) -> Editor in_ el1 (a -> b) -> Editor in_ el2 a -> Editor in_ el b

-- | Left-right editor composition
(|*|) :: Editor s Layout (b -> a) -> Editor s Layout b -> Editor s Layout a
infixl 4 |*|

-- | Left-right composition of an element with a editor
(|*) :: Editor s Layout a -> UI Element -> Editor s Layout a
infixl 5 |*

-- | Left-right composition of an element with a editor
(*|) :: UI Element -> Editor s Layout a -> Editor s Layout a
infixl 5 *|

-- | Left-right editor composition
(-*-) :: Editor s Layout (b -> a) -> Editor s Layout b -> Editor s Layout a
infixl 4 -*-

-- | Left-right composition of an element with a editor
(-*) :: Editor s Layout a -> UI Element -> Editor s Layout a
infixl 5 -*

-- | Left-right composition of an element with a editor
(*-) :: UI Element -> Editor s Layout a -> Editor s Layout a
infixl 5 *-

-- | A helper that arranges a label and an editor horizontally.
field :: Renderable m => String -> (out -> inn) -> Editor inn m a -> Editor out Layout a

-- | A helper that arranges a label and an editor horizontally, wrapped in
--   the given monoidal layout builder.
fieldLayout :: (Renderable m, Renderable m') => (Layout -> m') -> String -> (out -> inn) -> Editor inn m a -> Editor out m' a
editorUnit :: Editor b Element b
editorIdentity :: Editor a el a -> Editor (Identity a) el (Identity a)
editorString :: Editor String TextEntry String
editorText :: Editor Text TextEntry Text
editorCheckBox :: Editor Bool Element Bool
editorReadShow :: (Read a, Show a) => Editor (Maybe a) TextEntry (Maybe a)
editorEnumBounded :: (Bounded a, Enum a, Ord a, Show a) => Behavior (a -> UI Element) -> Editor (Maybe a) (ListBox a) (Maybe a)

-- | An editor that presents a dynamic choice of values.
editorSelection :: Ord a => Behavior [a] -> Behavior (a -> UI Element) -> Editor (Maybe a) (ListBox a) (Maybe a)

-- | An editor for union types, built from editors for its constructors.
editorSum :: (Ord tag, Show tag, Renderable el) => (Layout -> Layout -> Layout) -> [(tag, Editor a el a)] -> (a -> tag) -> Editor a Layout a

-- | Ignores <a>Nothing</a> values and only updates for <a>Just</a> values
editorJust :: Editor (Maybe b) el (Maybe b) -> Editor b el b
data EditorCollection k w
EditorCollection :: ListBox k -> Element -> w -> EditorCollection k w
[selector] :: EditorCollection k w -> ListBox k
[add, remove] :: EditorCollection k w -> Element
[selected] :: EditorCollection k w -> w

-- | A barebones editor for collections of editable items. Displays an
--   index selector, add and delete buttons, and an editor for the selected
--   item. Limitations: - Won't work with recursive data structures, due to
--   the lack of FRP switch.
editorCollection :: forall k v w. (Ord k, Renderable w) => (Behavior (Maybe k, Map k v) -> EditorCollectionConfig k v) -> Editor v w v -> Editor (Maybe k, Map k v) (EditorCollection k w) (Maybe k, Map k v)

-- | A barebones editor for collections of editable items. Displays an
--   index selector, add and delete buttons, and an editor for the selected
--   item. Limitations: - Won't work with recursive data structures, due to
--   the lack of FRP switch.
editorList :: (HasEmpty a, Renderable w) => Editor a w a -> Editor (Maybe Int, [a]) (EditorCollection Int w) (Maybe Int, [a])
data EditorCollectionConfig k v
EditorCollectionConfig :: Behavior k -> Behavior (Maybe k) -> v -> Behavior (Set k) -> Behavior (k -> UI Element) -> EditorCollectionConfig k v

-- | Current value to use for creating a new key
[eccNewKey] :: EditorCollectionConfig k v -> Behavior k

-- | Current value to use if the selected key is deleted
[eccAfterDelKey] :: EditorCollectionConfig k v -> Behavior (Maybe k)

-- | Value to use for creating new items
[eccTemplate] :: EditorCollectionConfig k v -> v

-- | Currently user select able keys
[eccOptions] :: EditorCollectionConfig k v -> Behavior (Set k)

-- | How to render a key
[eccDisplay] :: EditorCollectionConfig k v -> Behavior (k -> UI Element)
defaultEditorCollectionConfig :: (Enum k, Ord k, Show k, HasEmpty v) => Behavior (Maybe k, Map k v) -> EditorCollectionConfig k v

-- | This class defines how to represent empty values in a UI. A generic
--   derivation is available for every SOP type.
class HasEmpty a
emptyValue :: HasEmpty a => a
emptyValue :: (HasEmpty a, Generic a, HasEmptyCode (Code a), All HasEmpty (Head (Code a))) => a
instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Types.GenericWidget control)
instance Graphics.UI.Threepenny.Editors.Layout.Renderable w => Graphics.UI.Threepenny.Editors.Layout.Renderable (Graphics.UI.Threepenny.Editors.Types.EditorCollection k w)
instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Types.Editor a el)
instance Data.Bifunctor.Bifunctor (Graphics.UI.Threepenny.Editors.Types.Editor a)
instance Data.Biapplicative.Biapplicative (Graphics.UI.Threepenny.Editors.Types.Editor a)
instance GHC.Base.Monoid el => GHC.Base.Applicative (Graphics.UI.Threepenny.Editors.Types.Editor a el)
instance Data.Bifunctor.Bifunctor Graphics.UI.Threepenny.Editors.Types.GenericWidget
instance Graphics.UI.Threepenny.Core.Widget el => Graphics.UI.Threepenny.Core.Widget (Graphics.UI.Threepenny.Editors.Types.GenericWidget el a)
instance Graphics.UI.Threepenny.Editors.Layout.Renderable el => Graphics.UI.Threepenny.Editors.Layout.Renderable (Graphics.UI.Threepenny.Editors.Types.GenericWidget el a)


-- | Types and combinators to create widgets for editing algebraic
--   datatypes.
--   
--   This module builds around the idea that editors usually have the same
--   shape as the data they are editing. We can immediately take advantage
--   of this to automatically build editors from datatype definitions.
--   
--   <pre>
--   data Person = Person { first, last, email :: String, age :: Int }
--   
--   deriveGeneric ''Person
--   
--   instance Editable Person
--   </pre>
--   
--   This produces a generic editor with a fixed vertical layout. To
--   customize the layout, we can use a explicit instance and monoidal
--   layout builders:
--   
--   <pre>
--   instance Editable Person where
--     editor = Person &lt;$&gt; fieldLayout Next  "First:" first editor
--                     &lt;*&gt; fieldLayout Break "Last:"  last  editor
--                     &lt;*&gt; fieldLayout Next  "Email:" email editor
--                     &lt;*&gt; fieldLayout Next  "Age:"   age   editor
--   </pre>
--   
--   We can take this a step further by repurposing datatype definitions to
--   represent not only data, but also the collections of editors that are
--   composed to build the datatype editor. This is done via the
--   <a>Purpose</a> type and the <a>Field</a> type family.
--   
--   <pre>
--   data Person purpose =
--     Person { first, last, email :: Field purpose String
--            , age                :: Field purpose Int}
--   
--   deriveGeneric ''Person
--   
--   instance Editable (Person Data) where
--     type EditorWidget (Person Data) = Person Edit
--     editor = editorGenericBi
--   
--   instance Renderable (Person Edit) where
--     render = renderGeneric
--   </pre>
--   
--   <a>renderGeneric</a> will produce a vertical layout. A direct
--   implementation would use standard threepenny layout combinators since
--   the fields of <tt>Person Edit</tt> are instances of <a>Widget</a>:
--   
--   <pre>
--   instance Renderable (Person Edit) where
--     render Person{..} =
--       grid [[string "First:", element first, string "Email:", element email]
--            ,[string "Last:",  element last, string "Age:", element age]
--            ]
--   </pre>
module Graphics.UI.Threepenny.Editors

-- | An editor for values of type <tt>inner</tt> inside a datatype
--   <tt>outer</tt> realized by a <tt>widget</tt>.
--   
--   All the three type arguments are functorial, but <tt>outer</tt> is
--   contravariant, so <tt>Editor</tt> is a <a>Biapplicative</a> functor
--   and a <a>Profunctor</a> (via <a>dimapE</a>).
--   
--   <a>Biapplicative</a> allows to compose editors on both their
--   <tt>widget</tt> and <tt>inner</tt> structure. When <tt>widget</tt> is
--   monoidal, widget composition is implicit and <a>Applicative</a>
--   suffices.
--   
--   <a>Profunctor</a> allows to apply an <tt>inner</tt> editor to an
--   <tt>outer</tt> datatype.
--   
--   Once <a>create</a>d, an <a>Editor</a> yields a tuple of an
--   <tt>widget</tt> and a <tt>Tidings inner</tt> which can be integrated
--   in a threepenny app.
newtype Editor outer widget inner
Editor :: (Behavior outer -> UI (GenericWidget widget inner)) -> Editor outer widget inner
[create] :: Editor outer widget inner -> Behavior outer -> UI (GenericWidget widget inner)

-- | The class of <a>Editable</a> datatypes.
--   
--   There are several ways to create an instance, from easiest to most
--   advanced:
--   
--   <ul>
--   <li>Automatically (via <a>SOP</a>), producing an editor with a
--   vertical layout:</li>
--   </ul>
--   
--   <pre>
--   instance Editable MyDatatype
--   </pre>
--   
--   <ul>
--   <li>Using the applicative layout combinators:</li>
--   </ul>
--   
--   <pre>
--   instance Editable MyDatatype where
--     editor = MyDatatype &lt;$&gt; field "Name:" name editor
--                         -*- field "Age:"  age  editor
--   </pre>
--   
--   <ul>
--   <li>Using a monoidal layout builder:</li>
--   </ul>
--   
--   <pre>
--   instance Editable MyDatatype where
--     editor = MyDatatype &lt;$&gt; fieldLayout Break "Name:" name editor
--                         &lt;*&gt; fieldLayout Next  "Age:"  age  editor
--   </pre>
--   
--   <ul>
--   <li>Using a dual purpose datatype, leaving the layout details for the
--   <a>Renderable</a> instance.</li>
--   </ul>
--   
--   <pre>
--   instance Editable (MyDatatype Data) where
--     type EditorWidget (MyDatatype Data) = MyDatatype Edit
--     editor = editorGenericBi
--   </pre>
class (HasEmpty a, Renderable (EditorWidget a), Renderable (ListEditorWidget a)) => Editable a where {
    type family EditorWidget a;
    type family ListEditorWidget a;
    type EditorWidget a = Layout;
    type ListEditorWidget a = EditorCollection Int (EditorWidget a);
}
editor :: Editable a => Editor a (EditorWidget a) a
listEditor :: Editable a => Editor [a] (ListEditorWidget a) [a]
editor :: (Editable a, Generic a, HasDatatypeInfo a, (All (All Editable `And` All HasEmpty) (Code a)), EditorWidget a ~ Layout) => Editor a (EditorWidget a) a
listEditor :: (Editable a, HasEmpty a, ListEditorWidget a ~ EditorCollection Int (EditorWidget a)) => Editor [a] (ListEditorWidget a) [a]
dimapE :: (a' -> a) -> (b -> b') -> Editor a el b -> Editor a' el b'

-- | Left-right editor composition
(|*|) :: Editor s Layout (b -> a) -> Editor s Layout b -> Editor s Layout a
infixl 4 |*|

-- | Left-right composition of an element with a editor
(|*) :: Editor s Layout a -> UI Element -> Editor s Layout a
infixl 5 |*

-- | Left-right composition of an element with a editor
(*|) :: UI Element -> Editor s Layout a -> Editor s Layout a
infixl 5 *|

-- | Left-right editor composition
(-*-) :: Editor s Layout (b -> a) -> Editor s Layout b -> Editor s Layout a
infixl 4 -*-

-- | Left-right composition of an element with a editor
(-*) :: Editor s Layout a -> UI Element -> Editor s Layout a
infixl 5 -*

-- | Left-right composition of an element with a editor
(*-) :: UI Element -> Editor s Layout a -> Editor s Layout a
infixl 5 *-

-- | A helper that arranges a label and an editor horizontally.
field :: Renderable m => String -> (out -> inn) -> Editor inn m a -> Editor out Layout a

-- | A helper that arranges a label and an editor horizontally, wrapped in
--   the given monoidal layout builder.
fieldLayout :: (Renderable m, Renderable m') => (Layout -> m') -> String -> (out -> inn) -> Editor inn m a -> Editor out m' a

-- | Conceal the widget type of some <a>Editor</a>
withSomeWidget :: Renderable w => Editor a w b -> Editor a Layout b
editorUnit :: Editor b Element b
editorIdentity :: Editor a el a -> Editor (Identity a) el (Identity a)
editorReadShow :: (Read a, Show a) => Editor (Maybe a) TextEntry (Maybe a)
editorEnumBounded :: (Bounded a, Enum a, Ord a, Show a) => Behavior (a -> UI Element) -> Editor (Maybe a) (ListBox a) (Maybe a)

-- | An editor that presents a dynamic choice of values.
editorSelection :: Ord a => Behavior [a] -> Behavior (a -> UI Element) -> Editor (Maybe a) (ListBox a) (Maybe a)

-- | An editor for union types, built from editors for its constructors.
editorSum :: (Ord tag, Show tag, Renderable el) => (Layout -> Layout -> Layout) -> [(tag, Editor a el a)] -> (a -> tag) -> Editor a Layout a

-- | Ignores <a>Nothing</a> values and only updates for <a>Just</a> values
editorJust :: Editor (Maybe b) el (Maybe b) -> Editor b el b
editorString :: Editor String TextEntry String
editorText :: Editor Text TextEntry Text
editorCheckBox :: Editor Bool Element Bool

-- | A barebones editor for collections of editable items. Displays an
--   index selector, add and delete buttons, and an editor for the selected
--   item. Limitations: - Won't work with recursive data structures, due to
--   the lack of FRP switch.
editorList :: (HasEmpty a, Renderable w) => Editor a w a -> Editor (Maybe Int, [a]) (EditorCollection Int w) (Maybe Int, [a])

-- | A barebones editor for collections of editable items. Displays an
--   index selector, add and delete buttons, and an editor for the selected
--   item. Limitations: - Won't work with recursive data structures, due to
--   the lack of FRP switch.
editorCollection :: forall k v w. (Ord k, Renderable w) => (Behavior (Maybe k, Map k v) -> EditorCollectionConfig k v) -> Editor v w v -> Editor (Maybe k, Map k v) (EditorCollection k w) (Maybe k, Map k v)
data EditorCollection k w

-- | A version of <a>editor</a> with a concealed widget type.
someEditor :: Editable a => Editor a Layout a

-- | Conceal the widget type of some <a>Editor</a>
withSomeWidget :: Renderable w => Editor a w b -> Editor a Layout b

-- | Type level fields. Used to define dual purpose datatype constructors,
--   which can be instantiated to either store data or widgets. Example:
--   
--   <pre>
--   data PersonF (purpose :: Purpose) = Person
--     { education           :: Field purpose Education
--     , firstName, lastName :: Field purpose Text
--     , age                 :: Field purpose (Maybe Int)
--     }
--   </pre>
--   
--   <pre>
--   type Person = PersonF Data
--   type PersonEditor = PersonF Edit
--   </pre>

-- | List version of <a>Field</a>. Example:
--   
--   <pre>
--   data PersonF (purpose :: Purpose) = Person
--     { education           :: Field purpose Education
--     , firstName, lastName :: Field purpose Text
--     , age                 :: Field purpose (Maybe Int)
--     , addresses           :: ListField purpose String
--     }
--   </pre>
--   
--   <pre>
--   type Person = PersonF Data
--   type PersonEditor = PersonF Edit
--   </pre>

-- | <a>Purpose</a> is a kind for type level <a>Field</a>s
data Purpose
Data :: Purpose
Edit :: Purpose

-- | A generic <a>editor</a> derivation for SOP types.
--   
--   The datatype arguments are layered in vertical fashion and labelled
--   with field names if available.
editorGeneric :: forall a. (Generic a, HasDatatypeInfo a, (All (All Editable `And` All HasEmpty) (Code a))) => Editor a Layout a

-- | A generic <a>editor</a> derivation for dual purpose datatypes with a
--   single constructor.
--   
--   <i>e.g.</i> for the datatype
--   
--   <pre>
--   data Person purpose = Person { firstName, lastName :: Field purpose String }
--   </pre>
--   
--   <pre>
--   instance Editable (Person Data) where
--       type EditorWidget (Person Data) = Person Edit
--       editor = editorGenericBi
--   </pre>
--   
--   will be equivalent to
--   
--   <pre>
--   instance Editable (Person Data) where
--    type EditorWidget (Person Data) = Person Edit
--    editor = bipure DataItem DataItem
--                &lt;&lt;*&gt;&gt; edit firstName editor
--                &lt;&lt;*&gt;&gt; edit lastName editor
--   </pre>
editorGenericBi :: forall xs typ. (Generic (typ  'Data), Generic (typ  'Edit), All Editable xs, Code (typ  'Data) ~ '[xs], Code (typ  'Edit) ~ '[EditorWidgetsFor xs]) => Editor (typ  'Data) (typ  'Edit) (typ  'Data)
data GenericWidget control a
GenericWidget :: Tidings a -> control -> GenericWidget control a

-- | The dynamic contents of the widget.
[widgetTidings] :: GenericWidget control a -> Tidings a

-- | The actual widget.
[widgetControl] :: GenericWidget control a -> control
edited :: GenericWidget el a -> Event a
contents :: GenericWidget el a -> Behavior a

-- | A rathe limited, grid layout builder, probably not fit for general
--   purpose use yet.
data Layout

-- | A monoidal layout builder that places everything in a single column
newtype Vertical
Vertical :: Layout -> Vertical
[getVertical] :: Vertical -> Layout

-- | A monoidal layout builder that places everything in a single row
newtype Horizontal
Horizontal :: Layout -> Horizontal
[getHorizontal] :: Horizontal -> Layout

-- | A monoidal layout builder that lays elements in columns
data Columns

-- | Continue in the same column
Next :: Layout -> Columns

-- | Continue in the next column
Break :: Layout -> Columns

-- | Closely related to <a>Widget</a>, this class represents types that can
--   be rendered to an <a>Element</a>, either directly or via
--   <a>Layout</a>.
class Renderable w
render :: Renderable w => w -> UI Element
getLayout :: Renderable w => w -> Layout

-- | A generic <a>render</a> derivation for data types with a single
--   constructor which renders the (labelled) fields in a vertical layout.
--   For custom layouts use <a>getLayoutGeneric</a>.
--   
--   <i>e.g.</i> given the declarations
--   
--   <pre>
--   data PersonEditor = PersonEditor { firstName, lastName :: EditorWidget String }
--   deriveGeneric ''PersonEditor
--   </pre>
--   
--   using <a>renderGeneric</a> to instantiate <a>Renderable</a>
--   
--   <pre>
--   instance Renderable PersonEditor where
--     getLayout = renderGeneric
--   </pre>
--   
--   will be equivalent to writing the below by hand
--   
--   <pre>
--   instance Renderable PersonEditor where
--     getLayout PersonEditor{..} =
--         grid [ [string "First name:", element firstName]
--              , [string "Last name:",  element lastName ]
--              ]
--   </pre>
renderGeneric :: forall a xs. (Generic a, HasDatatypeInfo a, All Renderable xs, Code a ~ '[xs]) => a -> UI Element

-- | A helper to implement <a>getLayout</a> for data types with a single
--   constructor. Given a value, <a>getLayoutGeneric</a> returns a grid of
--   <a>Layout</a>s with one row per field. Rows can carry one element, for
--   unnamed fields; two elements, for named fields; or three elements, for
--   operators.
getLayoutGeneric :: forall a xs. (Generic a, HasDatatypeInfo a, All Renderable xs, Code a ~ '[xs]) => a -> [[Layout]]

-- | This class defines how to represent empty values in a UI. A generic
--   derivation is available for every SOP type.
class HasEmpty a
emptyValue :: HasEmpty a => a
emptyValue :: (HasEmpty a, Generic a, HasEmptyCode (Code a), All HasEmpty (Head (Code a))) => a
instance GHC.Classes.Ord Graphics.UI.Threepenny.Editors.Tag
instance GHC.Classes.Eq Graphics.UI.Threepenny.Editors.Tag
instance GHC.Show.Show Graphics.UI.Threepenny.Editors.Tag
instance Graphics.UI.Threepenny.Editors.Editable ()
instance Graphics.UI.Threepenny.Editors.Editable GHC.Types.Char
instance Graphics.UI.Threepenny.Editors.Editable a => Graphics.UI.Threepenny.Editors.Editable [a]
instance Graphics.UI.Threepenny.Editors.Editable Data.Text.Internal.Text
instance Graphics.UI.Threepenny.Editors.Editable GHC.Types.Bool
instance Graphics.UI.Threepenny.Editors.Editable (GHC.Base.Maybe GHC.Types.Int)
instance Graphics.UI.Threepenny.Editors.Editable (GHC.Base.Maybe GHC.Types.Double)
instance Graphics.UI.Threepenny.Editors.Editable GHC.Types.Int
instance Graphics.UI.Threepenny.Editors.Editable GHC.Types.Double
instance (Graphics.UI.Threepenny.Editors.Editable a, Graphics.UI.Threepenny.Editors.Editable b) => Graphics.UI.Threepenny.Editors.Editable (a Graphics.UI.Threepenny.Editors.Layout.|*| b)
instance (Graphics.UI.Threepenny.Editors.Editable a, Graphics.UI.Threepenny.Editors.Editable b) => Graphics.UI.Threepenny.Editors.Editable (a Graphics.UI.Threepenny.Editors.Layout.-*- b)
instance Graphics.UI.Threepenny.Editors.Editable a => Graphics.UI.Threepenny.Editors.Editable (Data.Functor.Identity.Identity a)
instance (Generics.SOP.Constraint.All Graphics.UI.Threepenny.Editors.Editable xs, Generics.SOP.Constraint.All Data.HasEmpty.HasEmpty xs) => Graphics.UI.Threepenny.Editors.Editable (Generics.SOP.NP.NP Generics.SOP.BasicFunctors.I xs)
instance Data.HasEmpty.HasEmpty a => Data.HasEmpty.HasEmpty (Generics.SOP.BasicFunctors.I a)
instance Generics.SOP.Constraint.All Data.HasEmpty.HasEmpty xs => Data.HasEmpty.HasEmpty (Generics.SOP.NP.NP Generics.SOP.BasicFunctors.I xs)


-- | Simple helpers to perform validation of user input.
--   
--   <pre>
--   -- update only if valid
--   value &lt;- accumB emptyValue updateIfValid userEdits
--   
--   -- collect validation warnings
--   warnings &lt;- stepper ok validate userEdits
--   
--   </pre>
module Graphics.UI.Threepenny.Editors.Validation
data ValidationResult

-- | All is good
ok :: ValidationResult

-- | Create a validation result from a list of warnings.
--   
--   <pre>
--   fromWarnings [] = ok
--   </pre>
fromWarnings :: [String] -> ValidationResult
getWarnings :: ValidationResult -> [String]

-- | The class of values that support validation.
class Validable a
validate :: Validable a => a -> ValidationResult
isValid :: Validable a => a -> Bool
updateIfValid :: Validable a => a -> a -> a
instance GHC.Show.Show Graphics.UI.Threepenny.Editors.Validation.ValidationResult
