packages feed

threepenny-editors 0.5.3 → 0.5.4

raw patch · 4 files changed

+95/−27 lines, 4 filesdep −template-haskellPVP ok

version bump matches the API change (PVP)

Dependencies removed: template-haskell

API changes (from Hackage documentation)

+ Graphics.UI.Threepenny.Editors: editorGenericSimpleBi :: forall xs typ. (Generic (typ Value), Generic (typ Edit), All Editable xs, Code (typ Value) ~ '[xs], Code (typ Edit) ~ '[EditorWidgetsFor xs]) => Editor (typ Value) (typ Edit) (typ Value)

Files

CHANGELOG.md view
@@ -1,3 +1,5 @@+# 0.5.4 (2017-08-28)+    * Generic derivation of `editor` for dual purpose datatypes. # 0.5.3 (2017-08-28)     * Generic derivation for `render`.     * Dropped dependency on the lens package.
examples/CRUD.hs view
@@ -1,11 +1,11 @@+{-# LANGUAGE DataKinds            #-}+{-# LANGUAGE DeriveGeneric        #-}+{-# LANGUAGE FlexibleInstances    #-}+{-# LANGUAGE KindSignatures       #-}+{-# LANGUAGE RecordWildCards      #-}+{-# LANGUAGE TemplateHaskell      #-}+{-# LANGUAGE TypeFamilies         #-} {-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE DeriveGeneric #-} {-----------------------------------------------------------------------------     Example from threepenny-gui extended with Editors: @@ -14,20 +14,19 @@     that the database is updated. This is perfectly fine for rapid prototyping.     A more sophisticated approach would use incremental updates. ------------------------------------------------------------------------------}-{-# LANGUAGE RecursiveDo #-}+{-# LANGUAGE RecursiveDo          #-} module CRUD (main) where-import Prelude hiding (lookup)-import Control.Monad  (void)-import Data.Biapplicative-import Data.List      (isPrefixOf)-import Data.Maybe-import qualified Data.Map as Map-import Generics.SOP.TH+import           Control.Monad                  (void)+import           Data.List                      (isPrefixOf)+import qualified Data.Map                       as Map+import           Data.Maybe+import           Generics.SOP.TH+import           Prelude                        hiding (lookup) -import qualified Graphics.UI.Threepenny as UI-import Graphics.UI.Threepenny.Editors hiding (create)+import qualified Graphics.UI.Threepenny         as UI+import           Graphics.UI.Threepenny.Core    hiding (delete)+import           Graphics.UI.Threepenny.Editors hiding (create) import qualified Graphics.UI.Threepenny.Editors as Editors-import Graphics.UI.Threepenny.Core hiding (delete)  {-----------------------------------------------------------------------------     Main@@ -132,18 +131,17 @@   { firstName, lastName :: Field usage String   } -showDataItem :: DataItem -> String-showDataItem DataItem{..} = lastName ++ ", " ++ firstName- type DataItem = DataItemDual Value type DataItemEditor = DataItemDual Edit +showDataItem :: DataItem -> String+showDataItem DataItem{..} = lastName ++ ", " ++ firstName+ instance Editable DataItem where   type EditorWidget DataItem = DataItemEditor-  editor = bipure DataItem DataItem-           <<*>> edit firstName editor-           <<*>> edit lastName editor+  editor = editorGenericSimpleBi -deriveGeneric ''DataItemDual instance Renderable DataItemEditor where   render = renderGeneric++deriveGeneric ''DataItemDual
src/Graphics/UI/Threepenny/Editors.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds                  #-} {-# LANGUAGE DefaultSignatures          #-}@@ -15,6 +16,7 @@ {-# OPTIONS_GHC -Wno-orphans            #-} {-# OPTIONS_GHC -Wno-name-shadowing     #-} {-# OPTIONS_GHC -Wno-duplicate-exports  #-}+{-# OPTIONS_GHC -fdefer-type-errors  #-}  module Graphics.UI.Threepenny.Editors   ( -- * Widgets@@ -56,6 +58,7 @@     -- ** Generic editors   , editorGeneric   , editorGenericSimple+  , editorGenericSimpleBi     -- * Layouts   , Layout   , above@@ -228,6 +231,72 @@  getLayoutField :: Renderable x => FieldInfo x -> x -> [Layout] getLayoutField (FieldInfo name) x =  [getLayout(toFieldLabel name), getLayout x]++{----------------------------------------------+  Generic derivations for Biapplicative editors+-----------------------------------------------}+-- | A generic implementation of 'editor' for dual purpose datatypes with a single constructor.+--+--   /e.g./ for the datatype+--+-- @+--  data Person usage = Person { firstName, lastName :: Field usage String }+-- @+--+-- @ instance Editable (Person Value) where+--     type EditorWidget (Person Value) = Person Edit+--     editor = editorGenericSimpleBi+-- @+--+--   will be equivalent to+--+-- > instance Editable (Person Value) where+-- >  type EditorWidget (Person Value) = Person Edit+-- >  editor = bipure DataItem DataItem+-- >              <<*>> edit firstName editor+-- >              <<*>> edit lastName editor+-- +editorGenericSimpleBi+  :: forall xs typ .+     ( Generic (typ 'Value)+     , Generic (typ 'Edit)+     , All Editable xs+     , Code (typ 'Value) ~ '[xs]+     , Code (typ 'Edit) ~ '[EditorWidgetsFor xs]+     )+  => Editor (typ 'Value) (typ 'Edit) (typ 'Value)+editorGenericSimpleBi = dimapE from to $ bimap to id $ constructorEditorBi++constructorEditorBi+  :: forall xs . (All Editable xs)+  => Editor (SOP I '[xs]) (SOP I '[EditorWidgetsFor xs]) (SOP I '[xs])+constructorEditorBi = dimapE (unZ . unSOP) (SOP . Z) . bimap (SOP . Z . unpackWidgets) id $ constructorEditorBi'++constructorEditorBi' :: (SListI xs, All Editable xs) => Editor (NP I xs) (NP EditorWidgetFor xs) (NP I xs)+constructorEditorBi' = sequence_NP2 fieldsEditorBi++unpackWidgets :: NP EditorWidgetFor xs -> NP I (EditorWidgetsFor xs)+unpackWidgets Nil = Nil+unpackWidgets (EditorWidgetFor e :* xs) = I e :* unpackWidgets xs++type family EditorWidgetsFor (xs :: [*]) where+  EditorWidgetsFor '[] = '[]+  EditorWidgetsFor (x ': xs) = EditorWidget x ': EditorWidgetsFor xs++fieldsEditorBi :: forall xs . All Editable xs => NP2 EditorWidgetFor (Editor (NP I xs)) xs+fieldsEditorBi = go id sList where+  go :: forall ys. All Editable ys => (forall f . NP f xs -> NP f ys) -> SList ys -> NP2 EditorWidgetFor (Editor (NP I xs)) ys+  go _ SNil = Nil2+  go f SCons = bimap EditorWidgetFor id (edit (unI . hd . f) editor) :** go (tl . f) sList+++data NP2 :: (k -> *) -> (k -> k -> *) -> [k] -> * where+  Nil2 :: NP2 w f '[]+  (:**) :: f (w x) x -> NP2 w f xs -> NP2 w f (x ': xs)++sequence_NP2 :: Biapplicative f => NP2 w f xs -> f (NP w xs) (NP I xs)+sequence_NP2 Nil2 = bipure Nil Nil+sequence_NP2 (x :** xs) = bipure (:*) (\x xx -> I x :* xx) <<*>> x <<*>> sequence_NP2 xs  {----------------------------------------------   Generic derivations for Applicative Editables
threepenny-editors.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           threepenny-editors-version:        0.5.3+version:        0.5.4 synopsis:       Composable algebraic editors description:    This package provides a type class 'Editable' and combinators to                 easily put together form-like editors for algebraic datatypes.@@ -44,7 +44,6 @@     , profunctors     , threepenny-gui > 0.7     , casing-    , template-haskell   exposed-modules:       Graphics.UI.Threepenny.Editors       Graphics.UI.Threepenny.Editors.Layout