threepenny-editors 0.2.0.14 → 0.2.0.15
raw patch · 6 files changed
+82/−30 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Graphics.UI.Threepenny.Editors.Profunctor: instance Data.Profunctor.Unsafe.Profunctor Graphics.UI.Threepenny.Editors.Profunctor.HEF
- Graphics.UI.Threepenny.Editors.Profunctor: instance Data.Profunctor.Unsafe.Profunctor Graphics.UI.Threepenny.Editors.Profunctor.VEF
- Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Applicative (Graphics.UI.Threepenny.Editors.Profunctor.HEF a)
- Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Applicative (Graphics.UI.Threepenny.Editors.Profunctor.VEF a)
- Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Profunctor.HEF a)
- Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Profunctor.VEF a)
+ Graphics.UI.Threepenny.Editors: Horizontally :: EditorFactory a b -> Horizontally a b
+ Graphics.UI.Threepenny.Editors: Vertically :: EditorFactory a b -> Vertically a b
+ Graphics.UI.Threepenny.Editors: [horizontally] :: Horizontally a b -> EditorFactory a b
+ Graphics.UI.Threepenny.Editors: [vertically] :: Vertically a b -> EditorFactory a b
+ Graphics.UI.Threepenny.Editors: newtype Horizontally a b
+ Graphics.UI.Threepenny.Editors: newtype Vertically a b
+ Graphics.UI.Threepenny.Editors.Profunctor: Horizontally :: EditorFactory a b -> Horizontally a b
+ Graphics.UI.Threepenny.Editors.Profunctor: Vertically :: EditorFactory a b -> Vertically a b
+ Graphics.UI.Threepenny.Editors.Profunctor: [horizontally] :: Horizontally a b -> EditorFactory a b
+ Graphics.UI.Threepenny.Editors.Profunctor: [vertically] :: Vertically a b -> EditorFactory a b
+ Graphics.UI.Threepenny.Editors.Profunctor: instance Data.Profunctor.Unsafe.Profunctor Graphics.UI.Threepenny.Editors.Profunctor.Horizontally
+ Graphics.UI.Threepenny.Editors.Profunctor: instance Data.Profunctor.Unsafe.Profunctor Graphics.UI.Threepenny.Editors.Profunctor.Vertically
+ Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Applicative (Graphics.UI.Threepenny.Editors.Profunctor.Horizontally a)
+ Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Applicative (Graphics.UI.Threepenny.Editors.Profunctor.Vertically a)
+ Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Profunctor.Horizontally a)
+ Graphics.UI.Threepenny.Editors.Profunctor: instance GHC.Base.Functor (Graphics.UI.Threepenny.Editors.Profunctor.Vertically a)
+ Graphics.UI.Threepenny.Editors.Profunctor: newtype Horizontally a b
+ Graphics.UI.Threepenny.Editors.Profunctor: newtype Vertically a b
Files
- CHANGELOG.md +2/−0
- examples/Person.hs +38/−13
- src/Graphics/UI/Threepenny/Editors.hs +3/−1
- src/Graphics/UI/Threepenny/Editors/Base.hs +8/−3
- src/Graphics/UI/Threepenny/Editors/Profunctor.hs +30/−12
- threepenny-editors.cabal +1/−1
CHANGELOG.md view
@@ -1,3 +1,5 @@+# 0.2.0.14 (2017-07-10)+ * Expose Vertically and Horizontally for use with ApplicativeDo # 0.2.0.14 (2017-07-01) * Improved rendering of field names in generic editors. # 0.2.0.13 (2017-06-22)
examples/Person.hs view
@@ -1,8 +1,11 @@+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE RecursiveDo #-} {-# LANGUAGE ScopedTypeVariables #-} import Control.Monad+import Data.Coerce import Data.Default import Data.Maybe import Data.Profunctor@@ -76,27 +79,49 @@ instance SOP.Generic Person instance Default Person where def = Person Basic "First" "Last" (Just 18) def def -editorPerson :: EditorFactory Person Person-editorPerson =- (\fn ln a e ls b -> Person e fn ln a b ls)- <$> field "First:" firstName editor- -*- field "Last:" lastName editor- -*- field "Age:" age editor- -*- field "Education:" education editorEducation- -*- field "Status" status (editorJust $ editorSelection (pure [minBound..]) (pure (string.show)))- -*- field "Brexiter" brexiteer editor+editorPersonRows :: EditorFactory Person Person+editorPersonRows = vertically $ do+ (firstName, lastName) <- coerce $ horizontally $ do+ firstName <- coerce $ field "First:" firstName editor+ lastName <- coerce $ field "Last:" lastName editor+ return (firstName, lastName)+ (age, education) <- coerce $ horizontally $ do+ age <- coerce $ field "Age:" age editor+ education <- coerce $ field "Education:" education editorEducation+ return (age, education)+ (status, brexiteer) <- coerce $ horizontally $ do+ status <- coerce $ field "Status" status (editorJust $ editorSelection (pure [minBound..]) (pure (string.show)))+ brexiteer <- coerce $ field "Brexiter" brexiteer editor+ return (status, brexiteer)+ return Person{..} +editorPersonColumns :: EditorFactory Person Person+editorPersonColumns = horizontally $ do+ (firstName, lastName, age) <- coerce $ vertically $ do+ firstName <- coerce $ field "First:" firstName editor+ lastName <- coerce $ field "Last:" lastName editor+ age <- coerce $ field "Age:" age editor+ return (firstName, lastName, age)+ (education, status, brexiteer) <- coerce $ vertically $ do+ education <- coerce $ field "Education:" education editorEducation+ status <- coerce $ field "Status" status (editorJust $ editorSelection (pure [minBound..]) (pure (string.show)))+ brexiteer <- coerce $ field "Brexiter" brexiteer editor+ return (education, status, brexiteer)+ return Person{..}+ setup :: Window -> UI () setup w = void $ mdo _ <- return w # set title "Threepenny editors example"- person1 <- createEditor editorPerson person1B+ person1r <- createEditor editorPersonRows person1B+ person1c <- createEditor editorPersonColumns person1B person2 <- createEditor editorGeneric person1B- person1B <- stepper def (unionWith const (edited person1) (edited person2))+ person1B <- stepper def (head <$> unions [edited person1r, edited person1c, edited person2]) getBody w #+ [grid- [ [return $ editorElement person1]+ [ [return $ editorElement person1r] , [hr]+ , [return $ editorElement person1c]+ , [hr] , [return $ editorElement person2] , [hr]- , [sink text (show <$> contents person1) p] ]]
src/Graphics/UI/Threepenny/Editors.hs view
@@ -7,10 +7,12 @@ , EditorFactory , createEditor , Editable(..)- -- ** Editor compoosition+ -- ** Editor composition , (|*|), (|*), (*|) , (-*-), (-*), (*-) , field+ , Vertically(..)+ , Horizontally(..) -- ** Editor constructors , editorUnit , editorIdentity
src/Graphics/UI/Threepenny/Editors/Base.hs view
@@ -75,16 +75,21 @@ getHorizontal (Horizontal h) = h getHorizontal other = [other] +getVertical :: Layout -> [Layout]+getVertical (Vertical h) = h+getVertical other = [other]+ getSingleOrGrid :: Layout -> UI Element getSingleOrGrid (Single e) = return e getSingleOrGrid other = runLayout other -getGridLayout :: Layout -> UI [[Element]]-getGridLayout (Vertical hh) = mapM (mapM getSingleOrGrid) $ fmap getHorizontal hh+getGridLayout :: Layout -> [[Layout]]+getGridLayout (Vertical hh) = fmap getHorizontal hh+getGridLayout (Horizontal vv) = getZipList $ sequenceA $ fmap (ZipList . getVertical) $ vv getGridLayout other = getGridLayout $ Vertical [other] runLayout :: Layout -> UI Element-runLayout = getGridLayout >=> grid . fmap (fmap return)+runLayout = mapM (mapM getSingleOrGrid) . getGridLayout >=> grid . fmap (fmap return) data EditorDef a = EditorDef { editorDefTidings :: Tidings a
src/Graphics/UI/Threepenny/Editors/Profunctor.hs view
@@ -28,6 +28,8 @@ , (|*|), (|*), (*|) , (-*-), (-*), (*-) , field+ , Vertically(..)+ , Horizontally(..) -- ** Editor constructors , editorUnit , editorIdentity@@ -239,11 +241,11 @@ f = fromMaybe def . getCompose . prj . K . hexpand (Compose Nothing) . hmap (Compose . Just) . unSOP constructorEditorFor' :: (SListI xs, All Editable xs) => NP FieldInfo xs -> EditorFactory (NP I xs) (NP I xs)-constructorEditorFor' fields = unVEF $ hsequence $ hliftA VEF $ fieldsEditor (hliftA (K . fieldName) fields)+constructorEditorFor' fields = vertically $ hsequence $ hliftA Vertically $ fieldsEditor (hliftA (K . fieldName) fields) -- | Tuple editor without fields instance All Editable xs => Editable (NP I xs) where- editor = unHEF $ hsequence $ hliftA HEF tupleEditor+ editor = horizontally $ hsequence $ hliftA Horizontally tupleEditor tupleEditor :: forall xs . All Editable xs => NP (EditorFactory (NP I xs)) xs tupleEditor = go id sList where@@ -265,17 +267,33 @@ onHead _ [] = [] toFieldLabel _ = "" --- | EditorFactory with an Applicative instance for vertical composition-newtype VEF a b = VEF {unVEF :: EditorFactory a b} deriving (Functor, Profunctor)-instance Applicative (VEF a) where- pure x = VEF $ const x <$> editorUnit- VEF a <*> VEF b = VEF (a -*- b)+-- | Applicative instance for vertical composition of editor factories.+--+-- This can be used in conjunction with ApplicativeDo as:+--+-- > editorPerson = vertically $ do+-- > firstName <- Vertically $ field "First:" firstName editor+-- > lastName <- Vertically $ field "Last:" lastName editor+-- > age <- Vertically $ field "Age:" age editor+-- > return Person{..} --- | EditorFactory with an Applicative instance for horizontal composition-newtype HEF a b = HEF {unHEF :: EditorFactory a b} deriving (Functor, Profunctor)-instance Applicative (HEF a) where- pure x = HEF $ const x <$> editorUnit- HEF a <*> HEF b = HEF (a |*| b)+newtype Vertically a b = Vertically {vertically :: EditorFactory a b} deriving (Functor, Profunctor)+instance Applicative (Vertically a) where+ pure x = Vertically $ const x <$> editorUnit+ Vertically a <*> Vertically b = Vertically (a -*- b)++-- | Applicative instance for horizontal composition of editor factories.+-- This can be used in conjunction with ApplicativeDo as:+--+-- > editorPerson = horizontally $ do+-- > firstName <- Horizontally $ field "First:" firstName editor+-- > lastName <- Horizontally $ field "Last:" lastName editor+-- > age <- Horizontally $ field "Age:" age editor+-- > return Person{..}+newtype Horizontally a b = Horizontally {horizontally :: EditorFactory a b} deriving (Functor, Profunctor)+instance Applicative (Horizontally a) where+ pure x = Horizontally $ const x <$> editorUnit+ Horizontally a <*> Horizontally b = Horizontally (a |*| b) instance (Applicative f, All Default xs) => Default (NP f xs) where def = hcpure (Proxy @ Default) (pure def)
threepenny-editors.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: threepenny-editors-version: 0.2.0.14+version: 0.2.0.15 synopsis: Composable algebraic editors description: This package provides a type class 'Editable' and combinators to easily put together form-like editors for algebraic datatypes.