From 10ad518fa540724ca3a16e32b590774a93f87ab2 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 17:45:44 -0400 Subject: [PATCH 01/51] Implement more of the Css grid spec --- src/Clay/Grid.hs | 69 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 4a24b1f..89302ab 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -1,5 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} --- | Partial implementation of . +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE TypeFamilies #-} +-- | Partial implementation of . -- -- For instance, you want to generate the following CSS: -- @@ -40,19 +42,72 @@ -- width maxContent -- @ module Clay.Grid -( gridGap -, gridTemplateColumns -) -where + ( gap + , rowGap + , columnGap + , gridTemplateRows + , gridTemplateColumns + , gridTemplateAreas + , gridArea + , GridArea(..) + , GridTemplateAreas(..) + ) + where import Clay.Property import Clay.Size import Clay.Stylesheet +import Data.String (IsString) +import Data.Text (Text) +import qualified Data.Text as Text + +import Data.Coerce (coerce) +import GHC.Exts (IsList(..)) + + -- | Property sets the gaps (gutters) between rows and columns. -gridGap :: Size a -> Css -gridGap = key "grid-gap" +gap :: Size a -> Css +gap = key "gap" <> key "grid-gap" + +-- | Property sets the size of the gap (gutter) between an element's grid rows. +rowGap :: Size a -> Css +rowGap = key "row-gap" <> key "grid-row-gap" + +-- | Property sets the size of the gap (gutter) between an element's grid columns. +columnGap :: Size a -> Css +columnGap = key "column-gap" <> key "grid-column-gap" + +-- | Property defines the line names and track sizing functions of the grid rows. +gridTemplateRows :: [Size a] -> Css +gridTemplateRows = key "grid-template-rows" . noCommas -- | Property defines the line names and track sizing functions of the grid columns. gridTemplateColumns :: [Size a] -> Css gridTemplateColumns = key "grid-template-columns" . noCommas + +-- | Property defines the template for grid layout +gridTemplateAreas :: GridTemplateAreas -> Css +gridTemplateAreas = key "grid-template-areas" + +-- | Property defines the element location inside grid template +gridArea :: GridArea -> Css +gridArea = key "grid-area" + +newtype GridArea = GridArea Text + deriving (IsString, Val) + +-- have to create a newtype to override the Val instance for lists +newtype GridTemplateAreas = GridTemplateAreas { unGridTemplateAreas :: [[GridArea]] } + +instance IsList GridTemplateAreas where + type Item GridTemplateAreas = [GridArea] + fromList = GridTemplateAreas + toList = unGridTemplateAreas + +instance Val GridTemplateAreas where + value areas = + value $ + Text.intercalate "\n" $ + fmap (Text.intercalate " ") $ + (coerce areas :: [[Text]]) From ec6e6a2d5d365228be4b4948dd20fc5fa777f319 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 17:52:41 -0400 Subject: [PATCH 02/51] Set linux style line endings --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf From cbac4f5e36a685fbd3bb09ee912d78c2eb25c873 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 18:22:31 -0400 Subject: [PATCH 03/51] Tentative changelog --- CHANGELOG | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 2c731d8..9ea1046 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,17 @@ CHANGELOG + 0.15.0: + - 'Clay.Grid': + new properties: + gap: `gap` & `grid-gap` + rowGap: `row-gap` & `grid-row-gap` + columnGap: `column-gap` & `grid-column-gap` + gridTemplateRows: `grid-template-rows` + gridTemplateColumns: `grid-template-columns` + gridTemplateAreas: `grid-template-areas` + gridArea: `grid-area` + newtype GridArea for type safe grid area templating + 0.14.0: - Drop support for GHC 8.2 - Added `text-align-last` From d70aa0259889dbedf83b635aabd72db5b509bb51 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 18:31:55 -0400 Subject: [PATCH 04/51] Wrap each row in quotes --- src/Clay/Grid.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 89302ab..fe17b9a 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -109,5 +109,7 @@ instance Val GridTemplateAreas where value areas = value $ Text.intercalate "\n" $ - fmap (Text.intercalate " ") $ + fmap (quote . Text.intercalate " ") $ (coerce areas :: [[Text]]) + where + quote text = "\"" <> text <> "\"" From 4da0bd8331f032181a945ab481ed8482a529c2a7 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 19:35:43 -0400 Subject: [PATCH 05/51] Restore gridGap, but deprecate it --- CHANGELOG | 1 + src/Clay/Grid.hs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9ea1046..8102661 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ CHANGELOG gridTemplateColumns: `grid-template-columns` gridTemplateAreas: `grid-template-areas` gridArea: `grid-area` + deprecate: 'Clay.Grid.gridGap' in favor of 'Clay.Grid.gap' newtype GridArea for type safe grid area templating 0.14.0: diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index fe17b9a..2c1fb6e 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -43,6 +43,7 @@ -- @ module Clay.Grid ( gap + , gridGap , rowGap , columnGap , gridTemplateRows @@ -67,8 +68,12 @@ import GHC.Exts (IsList(..)) -- | Property sets the gaps (gutters) between rows and columns. -gap :: Size a -> Css -gap = key "gap" <> key "grid-gap" +gap :: Size a -> Size a -> Css +gap row col = key "gap" (row, col) <> key "grid-gap" (row, col) + +gridGap :: Size a -> Css +gridGap = key "grid-gap" +{-# DEPRECATED gridGap "Use gap, rowGap, and/or columnGap instead" #-} -- | Property sets the size of the gap (gutter) between an element's grid rows. rowGap :: Size a -> Css From 56b89a87730ee3cb948f3563529e3ff71fffbb4f Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Fri, 24 Jul 2020 20:04:47 -0400 Subject: [PATCH 06/51] Test gridTemplateAreas --- clay.cabal | 5 ++- spec/Clay/GridSpec.hs | 49 +++++++++++++++++++++++ spec/Common.hs | 24 ++++++++++- src/Clay/Grid.hs | 92 +++++++++++++++++++++---------------------- 4 files changed, 119 insertions(+), 51 deletions(-) create mode 100644 spec/Clay/GridSpec.hs diff --git a/clay.cabal b/clay.cabal index a98d9cb..b363887 100644 --- a/clay.cabal +++ b/clay.cabal @@ -57,7 +57,7 @@ Library Clay.FontFace Clay.Geometry Clay.Gradient - Clay.Grid + Clay.Grid Clay.List Clay.Media Clay.Mask @@ -88,5 +88,6 @@ Test-Suite Test-Clay mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, hspec >= 2.2.0 && < 2.8, - hspec-discover >= 2.2.0 && < 2.8 + hspec-discover >= 2.2.0 && < 2.8, + deep-seq >= 1.2.0 && < 1.5 GHC-Options: -Wall -Wcompat diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs new file mode 100644 index 0000000..20e023c --- /dev/null +++ b/spec/Clay/GridSpec.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedLists #-} +module Clay.GridSpec where + +import Test.Hspec +import Common +import Clay + +spec :: Spec +spec = do + describe "grid-template-areas" $ do + describe "mozilla example" $ do + let + area_a = "a" + area_b = "b" + area_c = "c" + area_blank = "." + + "{grid-template-areas:\"a a .\"\n\"a a .\"\n\". b c\"}" + `shouldRenderFrom` + gridTemplateAreas + [ [ area_a, area_a, area_blank] + , [ area_a, area_a, area_blank] + , [ area_blank, area_b, area_c] + ] + describe "non rectangular template areas should error" $ do + let + area_a = "a" + area_b = "b" + area_c = "c" + area_blank = "." + + GridTemplateAreas_NotRectangular + `shouldErrorFromRender` + gridTemplateAreas + [ [ area_blank] -- length 1 + , [ area_a, area_blank] -- length 2 + , [ area_blank, area_b, area_c] -- length 3 + ] + + describe "empty template should error" $ do + GridTemplateAreas_Empty + `shouldErrorFromRender` + gridTemplateAreas [] + + describe "template with empty row(s) should error" $ do + GridTemplateAreas_EmptyRow + `shouldErrorFromRender` + gridTemplateAreas [[], []] diff --git a/spec/Common.hs b/spec/Common.hs index b4f30e8..99154f0 100644 --- a/spec/Common.hs +++ b/spec/Common.hs @@ -1,8 +1,18 @@ -module Common where +module Common + ( shouldRenderFrom + , shouldRenderAsFrom + , shouldRenderItFrom + , shouldErrorFromRender + ) + where import Test.Hspec import Clay import Data.Text.Lazy (Text, unpack) +import Control.Exception (evaluate) +import Control.Exception (Exception(..), evaluate) +import Control.DeepSeq (force) + shouldRenderFrom :: Text -> Css -> SpecWith () shouldRenderFrom txt css = @@ -15,5 +25,15 @@ shouldRenderAsFrom des txt css = infixr 3 `shouldRenderAsFrom` shouldRenderItFrom :: Text -> Css -> Expectation -shouldRenderItFrom = flip $ shouldBe . renderWith compact [] +shouldRenderItFrom = flip $ shouldBe . testRender infixr 0 `shouldRenderItFrom` + +testRender :: Css -> Text +testRender = renderWith compact [] + +shouldErrorFromRender :: (Exception e, Eq e) => e -> Css -> SpecWith () +shouldErrorFromRender exception css = do + let errorMsg = show exception + let rendered = evaluate $ force $ testRender css + it ("throws " <> errorMsg) $ + (rendered `shouldThrow` (== exception)) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 2c1fb6e..5751918 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -2,48 +2,8 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeFamilies #-} -- | Partial implementation of . --- --- For instance, you want to generate the following CSS: --- --- @ --- .grid1 { --- display: grid; --- width: max-content; --- } --- --- .grid3 { --- display: grid; --- width: max-content; --- } --- --- \@media (min-width: 40.0rem) { --- .grid3 { --- display: grid; --- grid-template-columns: 1fr 1fr 1fr; --- grid-gap: 1rem; --- width: max-content; --- } --- } --- @ --- --- The corresponding clay code: --- --- @ --- ".grid1" ? do --- display grid --- width maxContent --- ".grid3" ? do --- display grid --- width maxContent --- query M.screen [M.minWidth (rem 40)] $ ".grid3" ? do --- display grid --- gridTemplateColumns [fr 1, fr 1, fr 1] --- gridGap $ rem 1 --- width maxContent --- @ module Clay.Grid ( gap - , gridGap , rowGap , columnGap , gridTemplateRows @@ -52,6 +12,9 @@ module Clay.Grid , gridArea , GridArea(..) , GridTemplateAreas(..) + , InvalidGridTemplateAreas(..) + -- deprecated + , gridGap ) where @@ -65,6 +28,8 @@ import qualified Data.Text as Text import Data.Coerce (coerce) import GHC.Exts (IsList(..)) +import Control.Exception (Exception(..), throw) +import Control.Monad (when) -- | Property sets the gaps (gutters) between rows and columns. @@ -110,11 +75,44 @@ instance IsList GridTemplateAreas where fromList = GridTemplateAreas toList = unGridTemplateAreas +newtype Row = Row Int + deriving Show + +data InvalidGridTemplateAreas + = GridTemplateAreas_Empty + | GridTemplateAreas_EmptyRow -- Row + | GridTemplateAreas_NotRectangular -- [Row] + deriving (Eq, Show) + +instance Exception InvalidGridTemplateAreas + instance Val GridTemplateAreas where - value areas = - value $ - Text.intercalate "\n" $ - fmap (quote . Text.intercalate " ") $ - (coerce areas :: [[Text]]) - where - quote text = "\"" <> text <> "\"" + value areas = fromRight' $ do + let + wrapInParens text = "\"" <> text <> "\"" + nested = coerce areas :: [[Text]] + counts = fmap length nested + longest = maximum counts + + when (length nested == 0) $ + Left GridTemplateAreas_Empty + + when (any (== 0) counts) $ + Left GridTemplateAreas_EmptyRow + + when (any (/= longest) counts) $ + Left GridTemplateAreas_NotRectangular + + pure $ + value $ + Text.intercalate "\n" $ + fmap (wrapInParens . Text.intercalate " ") $ + nested + + +fromRight' :: Either InvalidGridTemplateAreas a -> a +fromRight' = fromRightOrThrow + +fromRightOrThrow :: Exception e => Either e a -> a +fromRightOrThrow (Right a) = a +fromRightOrThrow (Left e) = throw e From 414ea66ab0b4cdb26cba249f38f24b69e8ba94fa Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 08:48:17 -0400 Subject: [PATCH 07/51] Remove deepseq dependency --- clay.cabal | 3 +-- nix/clay.nix | 2 +- spec/Common.hs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clay.cabal b/clay.cabal index b363887..3acaccb 100644 --- a/clay.cabal +++ b/clay.cabal @@ -88,6 +88,5 @@ Test-Suite Test-Clay mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, hspec >= 2.2.0 && < 2.8, - hspec-discover >= 2.2.0 && < 2.8, - deep-seq >= 1.2.0 && < 1.5 + hspec-discover >= 2.2.0 && < 2.8 GHC-Options: -Wall -Wcompat diff --git a/nix/clay.nix b/nix/clay.nix index a4eeea2..be833a4 100644 --- a/nix/clay.nix +++ b/nix/clay.nix @@ -1,7 +1,7 @@ { mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text }: mkDerivation { pname = "clay"; - version = "0.14.0"; + version = "0.15.0"; src = ./..; libraryHaskellDepends = [ base mtl text ]; testHaskellDepends = [ base hspec hspec-discover mtl text ]; diff --git a/spec/Common.hs b/spec/Common.hs index 99154f0..4d306a7 100644 --- a/spec/Common.hs +++ b/spec/Common.hs @@ -11,7 +11,6 @@ import Clay import Data.Text.Lazy (Text, unpack) import Control.Exception (evaluate) import Control.Exception (Exception(..), evaluate) -import Control.DeepSeq (force) shouldRenderFrom :: Text -> Css -> SpecWith () @@ -34,6 +33,6 @@ testRender = renderWith compact [] shouldErrorFromRender :: (Exception e, Eq e) => e -> Css -> SpecWith () shouldErrorFromRender exception css = do let errorMsg = show exception - let rendered = evaluate $ force $ testRender css + let rendered = evaluate $! testRender css it ("throws " <> errorMsg) $ (rendered `shouldThrow` (== exception)) From b0dd86b250ff82a6e03341ca8386c694bea05a2a Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 08:48:45 -0400 Subject: [PATCH 08/51] Formatting --- spec/Clay/GridSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 20e023c..7059aae 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -33,7 +33,7 @@ spec = do GridTemplateAreas_NotRectangular `shouldErrorFromRender` gridTemplateAreas - [ [ area_blank] -- length 1 + [ [ area_blank] -- length 1 , [ area_a, area_blank] -- length 2 , [ area_blank, area_b, area_c] -- length 3 ] From 298835afa643b24c283ccc139d2dc2a06df18cff Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 09:04:55 -0400 Subject: [PATCH 09/51] Use smart constructor pattern --- src/Clay/Grid.hs | 53 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 5751918..201b353 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -11,7 +11,9 @@ module Clay.Grid , gridTemplateAreas , gridArea , GridArea(..) - , GridTemplateAreas(..) + , GridTemplateAreas + , mkGridTemplateAreas + , unGridTemplateAreas , InvalidGridTemplateAreas(..) -- deprecated , gridGap @@ -70,31 +72,21 @@ newtype GridArea = GridArea Text -- have to create a newtype to override the Val instance for lists newtype GridTemplateAreas = GridTemplateAreas { unGridTemplateAreas :: [[GridArea]] } +-- | toList will throw when your grid template areas are invalid instance IsList GridTemplateAreas where type Item GridTemplateAreas = [GridArea] - fromList = GridTemplateAreas toList = unGridTemplateAreas + fromList = fromRightOrThrow . mkGridTemplateAreas -newtype Row = Row Int - deriving Show -data InvalidGridTemplateAreas - = GridTemplateAreas_Empty - | GridTemplateAreas_EmptyRow -- Row - | GridTemplateAreas_NotRectangular -- [Row] - deriving (Eq, Show) - -instance Exception InvalidGridTemplateAreas - -instance Val GridTemplateAreas where - value areas = fromRight' $ do +-- | Smart constructor for GridTemplateAreas +mkGridTemplateAreas :: [[GridArea]] -> Either InvalidGridTemplateAreas GridTemplateAreas +mkGridTemplateAreas rows = do let - wrapInParens text = "\"" <> text <> "\"" - nested = coerce areas :: [[Text]] - counts = fmap length nested + counts = map length rows longest = maximum counts - when (length nested == 0) $ + when (null rows ) $ Left GridTemplateAreas_Empty when (any (== 0) counts) $ @@ -103,15 +95,28 @@ instance Val GridTemplateAreas where when (any (/= longest) counts) $ Left GridTemplateAreas_NotRectangular - pure $ + Right $ GridTemplateAreas rows + + +-- | Failure modes for the smart constructor +data InvalidGridTemplateAreas + = GridTemplateAreas_Empty + | GridTemplateAreas_EmptyRow -- Row + | GridTemplateAreas_NotRectangular -- [Row] + deriving (Eq, Show) + +instance Exception InvalidGridTemplateAreas + +instance Val GridTemplateAreas where + value areas = + let + rows = coerce areas :: [[Text]] + wrapInParens text = "\"" <> text <> "\"" + in value $ Text.intercalate "\n" $ fmap (wrapInParens . Text.intercalate " ") $ - nested - - -fromRight' :: Either InvalidGridTemplateAreas a -> a -fromRight' = fromRightOrThrow + rows fromRightOrThrow :: Exception e => Either e a -> a fromRightOrThrow (Right a) = a From f8c3e2f6dcd7985ba376efccb881ed33a2def1b5 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 09:39:08 -0400 Subject: [PATCH 10/51] Allow keyword values for gridTemplateAreas --- spec/Clay/GridSpec.hs | 27 ++++++++++--- src/Clay/Grid.hs | 93 +++++++++++++++++++++++++------------------ 2 files changed, 77 insertions(+), 43 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 7059aae..fa1a096 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -9,12 +9,29 @@ import Clay spec :: Spec spec = do describe "grid-template-areas" $ do + describe "keyword values" $ do + "{grid-template-areas:none}" + `shouldRenderFrom` + gridTemplateAreas none + + "{grid-template-areas:inherit}" + `shouldRenderFrom` + gridTemplateAreas inherit + + "{grid-template-areas:initial}" + `shouldRenderFrom` + gridTemplateAreas initial + + "{grid-template-areas:unset}" + `shouldRenderFrom` + gridTemplateAreas unset + describe "mozilla example" $ do let area_a = "a" area_b = "b" area_c = "c" - area_blank = "." + area_blank = blankGridArea "{grid-template-areas:\"a a .\"\n\"a a .\"\n\". b c\"}" `shouldRenderFrom` @@ -28,9 +45,9 @@ spec = do area_a = "a" area_b = "b" area_c = "c" - area_blank = "." + area_blank = blankGridArea - GridTemplateAreas_NotRectangular + GridTemplateNamedAreas_NotRectangular `shouldErrorFromRender` gridTemplateAreas [ [ area_blank] -- length 1 @@ -39,11 +56,11 @@ spec = do ] describe "empty template should error" $ do - GridTemplateAreas_Empty + GridTemplateNamedAreas_Empty `shouldErrorFromRender` gridTemplateAreas [] describe "template with empty row(s) should error" $ do - GridTemplateAreas_EmptyRow + GridTemplateNamedAreas_EmptyRow `shouldErrorFromRender` gridTemplateAreas [[], []] diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 201b353..d1a6f76 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -10,16 +10,18 @@ module Clay.Grid , gridTemplateColumns , gridTemplateAreas , gridArea + , blankGridArea , GridArea(..) - , GridTemplateAreas - , mkGridTemplateAreas - , unGridTemplateAreas - , InvalidGridTemplateAreas(..) + , GridTemplateNamedAreas + , mkGridTemplateNamedAreas + , unGridTemplateNamedAreas + , InvalidGridTemplateNamedAreas(..) -- deprecated , gridGap ) where +import Clay.Common import Clay.Property import Clay.Size import Clay.Stylesheet @@ -69,55 +71,70 @@ gridArea = key "grid-area" newtype GridArea = GridArea Text deriving (IsString, Val) --- have to create a newtype to override the Val instance for lists -newtype GridTemplateAreas = GridTemplateAreas { unGridTemplateAreas :: [[GridArea]] } +blankGridArea :: GridArea +blankGridArea = GridArea "." + +------------------------------------------------------------------------------- +newtype GridTemplateAreas = GridTemplateAreas Value + deriving (Val, None, Inherit, Initial, Unset) --- | toList will throw when your grid template areas are invalid instance IsList GridTemplateAreas where type Item GridTemplateAreas = [GridArea] - toList = unGridTemplateAreas - fromList = fromRightOrThrow . mkGridTemplateAreas + toList = error "toList GridTemplateAreas is not defined" + fromList = GridTemplateAreas . value . fromList' + where + fromList' :: [Item GridTemplateNamedAreas] -> GridTemplateNamedAreas + fromList' = fromList +-- have to create a newtype to override the Val instance for lists +newtype GridTemplateNamedAreas = GridTemplateNamedAreas { unGridTemplateNamedAreas :: [[GridArea]] } --- | Smart constructor for GridTemplateAreas -mkGridTemplateAreas :: [[GridArea]] -> Either InvalidGridTemplateAreas GridTemplateAreas -mkGridTemplateAreas rows = do +instance Val GridTemplateNamedAreas where + value areas = let - counts = map length rows + rows = coerce areas :: [[Text]] + wrapInParens text = "\"" <> text <> "\"" + convertRow = wrapInParens . Text.intercalate " " + in + value $ + Text.intercalate "\n" $ + map convertRow $ + rows + +-- | toList will throw when your grid template areas are invalid +instance IsList GridTemplateNamedAreas where + type Item GridTemplateNamedAreas = [GridArea] + toList = unGridTemplateNamedAreas . coerce + fromList = fromRightOrThrow . mkGridTemplateNamedAreas + where + fromRightOrThrow :: Exception e => Either e a -> a + fromRightOrThrow (Right a) = a + fromRightOrThrow (Left e) = throw e + +-- | Smart constructor for GridTemplateNamedAreas +mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplateNamedAreas GridTemplateNamedAreas +mkGridTemplateNamedAreas rows = do + let + counts = map length (coerce rows :: [[GridArea]]) longest = maximum counts when (null rows ) $ - Left GridTemplateAreas_Empty + Left GridTemplateNamedAreas_Empty when (any (== 0) counts) $ - Left GridTemplateAreas_EmptyRow + Left GridTemplateNamedAreas_EmptyRow when (any (/= longest) counts) $ - Left GridTemplateAreas_NotRectangular - - Right $ GridTemplateAreas rows + Left GridTemplateNamedAreas_NotRectangular + Right $ GridTemplateNamedAreas rows -- | Failure modes for the smart constructor -data InvalidGridTemplateAreas - = GridTemplateAreas_Empty - | GridTemplateAreas_EmptyRow -- Row - | GridTemplateAreas_NotRectangular -- [Row] +data InvalidGridTemplateNamedAreas + = GridTemplateNamedAreas_Empty + | GridTemplateNamedAreas_EmptyRow + | GridTemplateNamedAreas_NotRectangular deriving (Eq, Show) -instance Exception InvalidGridTemplateAreas - -instance Val GridTemplateAreas where - value areas = - let - rows = coerce areas :: [[Text]] - wrapInParens text = "\"" <> text <> "\"" - in - value $ - Text.intercalate "\n" $ - fmap (wrapInParens . Text.intercalate " ") $ - rows - -fromRightOrThrow :: Exception e => Either e a -> a -fromRightOrThrow (Right a) = a -fromRightOrThrow (Left e) = throw e +instance Exception InvalidGridTemplateNamedAreas +------------------------------------------------------------------------------ From 7ecce2d145f8c052df2f2b8a3352ed54a80fc789 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 10:58:46 -0400 Subject: [PATCH 11/51] Test stuff --- spec/Clay/GridSpec.hs | 39 +++++++++++++++++++++++++++++++++++++++ spec/Common.hs | 1 - src/Clay/Grid.hs | 33 ++++++++++++++++++++++++++------- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index fa1a096..866c85c 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -6,8 +6,47 @@ import Test.Hspec import Common import Clay +test = hspec spec + spec :: Spec spec = do + describe "gap" $ do + "{gap:10px;grid-gap:10px}" + `shouldRenderFrom` + gap (px 10) + + describe "rowGap" $ do + "{row-gap:5px;grid-row-gap:5px}" + `shouldRenderFrom` + rowGap (px 5) + + describe "columnGap" $ do + "{column-gap:1em;grid-column-gap:1em}" + `shouldRenderFrom` + columnGap (em 1) + + describe "gridTemplateRows" $ do + describe "keywords" $ do + "{grid-template-rows:none}" + `shouldRenderFrom` + gridTemplateRows none + + describe "list of sizes" $ do + "{grid-template-rows:1em auto min-content}" + `shouldRenderFrom` + gridTemplateRows [SomeSize $ em 1, SomeSize auto, SomeSize minContent] + + describe "gridTemplateColumns" $ do + describe "keywords" $ do + "{grid-template-rows:none}" + `shouldRenderFrom` + gridTemplateRows none + + describe "list of sizes" $ do + "{grid-template-columns:1em 20% min-content}" + `shouldRenderFrom` + gridTemplateColumns [SomeSize $ em 1, SomeSize $ pct 20, SomeSize minContent] + describe "grid-template-areas" $ do describe "keyword values" $ do "{grid-template-areas:none}" diff --git a/spec/Common.hs b/spec/Common.hs index 4d306a7..3995641 100644 --- a/spec/Common.hs +++ b/spec/Common.hs @@ -9,7 +9,6 @@ module Common import Test.Hspec import Clay import Data.Text.Lazy (Text, unpack) -import Control.Exception (evaluate) import Control.Exception (Exception(..), evaluate) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index d1a6f76..eecfdab 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -1,6 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ExistentialQuantification #-} -- | Partial implementation of . module Clay.Grid ( gap @@ -8,10 +10,13 @@ module Clay.Grid , columnGap , gridTemplateRows , gridTemplateColumns + , GridTemplateSizes + , SomeSize(..) , gridTemplateAreas , gridArea , blankGridArea , GridArea(..) + , GridTemplateAreas , GridTemplateNamedAreas , mkGridTemplateNamedAreas , unGridTemplateNamedAreas @@ -37,11 +42,11 @@ import Control.Monad (when) -- | Property sets the gaps (gutters) between rows and columns. -gap :: Size a -> Size a -> Css -gap row col = key "gap" (row, col) <> key "grid-gap" (row, col) +gap :: Size a -> Css +gap = key "gap" <> key "grid-gap" gridGap :: Size a -> Css -gridGap = key "grid-gap" +gridGap = gap {-# DEPRECATED gridGap "Use gap, rowGap, and/or columnGap instead" #-} -- | Property sets the size of the gap (gutter) between an element's grid rows. @@ -53,12 +58,12 @@ columnGap :: Size a -> Css columnGap = key "column-gap" <> key "grid-column-gap" -- | Property defines the line names and track sizing functions of the grid rows. -gridTemplateRows :: [Size a] -> Css -gridTemplateRows = key "grid-template-rows" . noCommas +gridTemplateRows :: GridTemplateSizes -> Css +gridTemplateRows = key "grid-template-rows" -- | Property defines the line names and track sizing functions of the grid columns. -gridTemplateColumns :: [Size a] -> Css -gridTemplateColumns = key "grid-template-columns" . noCommas +gridTemplateColumns :: GridTemplateSizes -> Css +gridTemplateColumns = key "grid-template-columns" -- | Property defines the template for grid layout gridTemplateAreas :: GridTemplateAreas -> Css @@ -74,6 +79,20 @@ newtype GridArea = GridArea Text blankGridArea :: GridArea blankGridArea = GridArea "." +------------------------------------------------------------------------------- +data SomeSize = forall a. SomeSize { getSize :: Size a } + +instance Val SomeSize where + value (SomeSize size) = value size + +newtype GridTemplateSizes = GridTemplateSizes Value + deriving (Val, None, Inherit, Initial, Unset) + +instance IsList GridTemplateSizes where + type Item GridTemplateSizes = SomeSize + toList = error "" + fromList = GridTemplateSizes . noCommas + ------------------------------------------------------------------------------- newtype GridTemplateAreas = GridTemplateAreas Value deriving (Val, None, Inherit, Initial, Unset) From afb5b6c7940cbe2f4ba698443bc7d7670c2ea8d5 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 17:04:10 -0400 Subject: [PATCH 12/51] Test gridArea --- spec/Clay/GridSpec.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 866c85c..e381e1b 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -47,7 +47,12 @@ spec = do `shouldRenderFrom` gridTemplateColumns [SomeSize $ em 1, SomeSize $ pct 20, SomeSize minContent] - describe "grid-template-areas" $ do + describe "gridArea" $ do + "{grid-area:header}" + `shouldRenderFrom` + gridArea "header" + + describe "gridTemplateAreas" $ do describe "keyword values" $ do "{grid-template-areas:none}" `shouldRenderFrom` From 21cf7a6532bcff210b45f2529feda6da6422b2f7 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 25 Jul 2020 22:02:43 -0400 Subject: [PATCH 13/51] Mixed units in gridTemplateRows/gridTemplateColumns --- spec/Clay/GridSpec.hs | 8 ++++---- src/Clay/Grid.hs | 16 +++++----------- src/Clay/Size.hs | 12 ++++++++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index e381e1b..00a7b86 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -32,9 +32,9 @@ spec = do gridTemplateRows none describe "list of sizes" $ do - "{grid-template-rows:1em auto min-content}" + "{grid-template-rows:50px auto 40em}" `shouldRenderFrom` - gridTemplateRows [SomeSize $ em 1, SomeSize auto, SomeSize minContent] + gridTemplateRows [px 50, auto, em 40] describe "gridTemplateColumns" $ do describe "keywords" $ do @@ -43,9 +43,9 @@ spec = do gridTemplateRows none describe "list of sizes" $ do - "{grid-template-columns:1em 20% min-content}" + "{grid-template-columns:1em 20% auto}" `shouldRenderFrom` - gridTemplateColumns [SomeSize $ em 1, SomeSize $ pct 20, SomeSize minContent] + gridTemplateColumns [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] describe "gridArea" $ do "{grid-area:header}" diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index eecfdab..bf5a9d3 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -11,7 +11,6 @@ module Clay.Grid , gridTemplateRows , gridTemplateColumns , GridTemplateSizes - , SomeSize(..) , gridTemplateAreas , gridArea , blankGridArea @@ -58,11 +57,11 @@ columnGap :: Size a -> Css columnGap = key "column-gap" <> key "grid-column-gap" -- | Property defines the line names and track sizing functions of the grid rows. -gridTemplateRows :: GridTemplateSizes -> Css +gridTemplateRows :: GridTemplateSizes a -> Css gridTemplateRows = key "grid-template-rows" -- | Property defines the line names and track sizing functions of the grid columns. -gridTemplateColumns :: GridTemplateSizes -> Css +gridTemplateColumns :: GridTemplateSizes a -> Css gridTemplateColumns = key "grid-template-columns" -- | Property defines the template for grid layout @@ -80,16 +79,11 @@ blankGridArea :: GridArea blankGridArea = GridArea "." ------------------------------------------------------------------------------- -data SomeSize = forall a. SomeSize { getSize :: Size a } - -instance Val SomeSize where - value (SomeSize size) = value size - -newtype GridTemplateSizes = GridTemplateSizes Value +newtype GridTemplateSizes a = GridTemplateSizes Value deriving (Val, None, Inherit, Initial, Unset) -instance IsList GridTemplateSizes where - type Item GridTemplateSizes = SomeSize +instance IsList (GridTemplateSizes a) where + type Item (GridTemplateSizes a) = Size a toList = error "" fromList = GridTemplateSizes . noCommas diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index 75c5cb8..9b2c3ea 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -14,6 +14,8 @@ module Clay.Size Size , LengthUnit , Percentage +, AnyUnit +, upcast , nil , unitless @@ -74,6 +76,7 @@ where import Data.Monoid import Prelude hiding (rem) import Data.Text (Text) +import Data.Coerce (coerce) import Clay.Common import Clay.Property @@ -88,7 +91,12 @@ data LengthUnit data Percentage -- | When combining percentages with units using calc, we get a combination -data Combination +-- | Any unit or combination of units +data AnyUnit + +-- | Upcast a size unit +upcast :: Size a -> Size AnyUnit +upcast = coerce data Size a = SimpleSize Text | @@ -222,7 +230,7 @@ instance Fractional (Size Percentage) where type family SizeCombination sa sb where SizeCombination Percentage Percentage = Percentage SizeCombination LengthUnit LengthUnit = LengthUnit - SizeCombination a b = Combination + SizeCombination a b = AnyUnit -- | Plus operator to combine sizes into calc function infixl 6 @+@ From 6ff48640a16e7ab5f503415dbea27eaba3ec2306 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 10:49:36 -0400 Subject: [PATCH 14/51] Integer & keyword grid coordinates --- src/Clay/Grid.hs | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index bf5a9d3..14128be 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -56,6 +56,8 @@ rowGap = key "row-gap" <> key "grid-row-gap" columnGap :: Size a -> Css columnGap = key "column-gap" <> key "grid-column-gap" +------------------------------------------------------------------------------- + -- | Property defines the line names and track sizing functions of the grid rows. gridTemplateRows :: GridTemplateSizes a -> Css gridTemplateRows = key "grid-template-rows" @@ -64,30 +66,50 @@ gridTemplateRows = key "grid-template-rows" gridTemplateColumns :: GridTemplateSizes a -> Css gridTemplateColumns = key "grid-template-columns" --- | Property defines the template for grid layout -gridTemplateAreas :: GridTemplateAreas -> Css -gridTemplateAreas = key "grid-template-areas" +newtype GridTemplateSizes a = GridTemplateSizes Value + deriving (Val, None, Inherit, Initial, Unset) +instance IsList (GridTemplateSizes a) where + type Item (GridTemplateSizes a) = Size a + toList = error "" + fromList = GridTemplateSizes . noCommas + +------------------------------------------------------------------------------- -- | Property defines the element location inside grid template gridArea :: GridArea -> Css gridArea = key "grid-area" -newtype GridArea = GridArea Text - deriving (IsString, Val) - blankGridArea :: GridArea blankGridArea = GridArea "." +newtype GridArea = GridArea Text + deriving (IsString, Val) + ------------------------------------------------------------------------------- -newtype GridTemplateSizes a = GridTemplateSizes Value - deriving (Val, None, Inherit, Initial, Unset) -instance IsList (GridTemplateSizes a) where - type Item (GridTemplateSizes a) = Size a - toList = error "" - fromList = GridTemplateSizes . noCommas +gridRowStart :: GridCoordinate -> Css +gridRowStart = key "grid-row-start" + +gridRowEnd :: GridCoordinate -> Css +gridRowEnd = key "grid-row-end" +gridColumnStart :: GridCoordinate -> Css +gridColumnStart = key "grid-column-start" + +gridColumnEnd :: GridCoordinate -> Css +gridColumnEnd = key "grid-column-end" + +newtype GridCoordinate = GridCoordinate Value + deriving (Val, Auto, Inherit, Initial, Unset) + +instance Num GridCoordinate where + fromInteger = GridCoordinate . value ------------------------------------------------------------------------------- + +-- | Property defines the template for grid layout +gridTemplateAreas :: GridTemplateAreas -> Css +gridTemplateAreas = key "grid-template-areas" + newtype GridTemplateAreas = GridTemplateAreas Value deriving (Val, None, Inherit, Initial, Unset) From c9d875add13cd706f2bfb8efec586e4dbf816813 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 12:10:37 -0400 Subject: [PATCH 15/51] Use Data.These to model GridLocation --- clay.cabal | 4 ++- nix/clay.nix | 7 +++-- spec/Clay/GridSpec.hs | 31 +++++++++++++++---- src/Clay/Grid.hs | 70 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 90 insertions(+), 22 deletions(-) diff --git a/clay.cabal b/clay.cabal index 3acaccb..6746274 100644 --- a/clay.cabal +++ b/clay.cabal @@ -75,7 +75,8 @@ Library Build-Depends: base >= 4.11 && < 5, mtl >= 1 && < 2.3, - text >= 0.11 && < 1.3 + text >= 0.11 && < 1.3, + these GHC-Options: -Wall -Wcompat Test-Suite Test-Clay @@ -87,6 +88,7 @@ Test-Suite Test-Clay base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, + these, hspec >= 2.2.0 && < 2.8, hspec-discover >= 2.2.0 && < 2.8 GHC-Options: -Wall -Wcompat diff --git a/nix/clay.nix b/nix/clay.nix index be833a4..0322cd0 100644 --- a/nix/clay.nix +++ b/nix/clay.nix @@ -1,10 +1,11 @@ -{ mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text }: +<<<<<<< HEAD +{ mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text, these }: mkDerivation { pname = "clay"; version = "0.15.0"; src = ./..; - libraryHaskellDepends = [ base mtl text ]; - testHaskellDepends = [ base hspec hspec-discover mtl text ]; + libraryHaskellDepends = [ base mtl text these ]; + testHaskellDepends = [ base hspec hspec-discover mtl text these ]; homepage = "http://fvisser.nl/clay"; description = "CSS preprocessor as embedded Haskell"; license = lib.licenses.bsd3; diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 00a7b86..029e817 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -26,7 +26,7 @@ spec = do columnGap (em 1) describe "gridTemplateRows" $ do - describe "keywords" $ do + describe "keyword" $ do "{grid-template-rows:none}" `shouldRenderFrom` gridTemplateRows none @@ -37,7 +37,7 @@ spec = do gridTemplateRows [px 50, auto, em 40] describe "gridTemplateColumns" $ do - describe "keywords" $ do + describe "keyword" $ do "{grid-template-rows:none}" `shouldRenderFrom` gridTemplateRows none @@ -47,10 +47,29 @@ spec = do `shouldRenderFrom` gridTemplateColumns [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] - describe "gridArea" $ do - "{grid-area:header}" - `shouldRenderFrom` - gridArea "header" + describe "gridArea" $ do + "{grid-area:header}" + `shouldRenderFrom` + gridArea "header" + + describe "grid coordinate properties" $ do + + "{grid-row-start:3}" + `shouldRenderFrom` + gridRowStart 3 + + "{grid-row-end:-2}" + `shouldRenderFrom` + gridRowEnd (-2) + + "{grid-column-start:span nav}" + `shouldRenderFrom` + gridColumnStart $ gridLocation Span (That "nav") + + "{grid-column-end:3 footer}" + `shouldRenderFrom` + gridColumnEnd $ gridLocation NoSpan (These 3 "footer") + describe "gridTemplateAreas" $ do describe "keyword values" $ do diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 14128be..cc96f1b 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -11,17 +11,27 @@ module Clay.Grid , gridTemplateRows , gridTemplateColumns , GridTemplateSizes - , gridTemplateAreas , gridArea , blankGridArea - , GridArea(..) + , GridArea + , gridRowStart + , gridRowEnd + , gridColumnStart + , gridColumnEnd + , GridLocation + , gridLocation + , IsSpan(..) + , gridTemplateAreas , GridTemplateAreas , GridTemplateNamedAreas , mkGridTemplateNamedAreas , unGridTemplateNamedAreas , InvalidGridTemplateNamedAreas(..) + -- re exports + , These(..) -- deprecated , gridGap + ) where @@ -29,12 +39,15 @@ import Clay.Common import Clay.Property import Clay.Size import Clay.Stylesheet +import Clay.Elements +import Prelude hiding (span) import Data.String (IsString) import Data.Text (Text) import qualified Data.Text as Text import Data.Coerce (coerce) +import Data.These import GHC.Exts (IsList(..)) import Control.Exception (Exception(..), throw) import Control.Monad (when) @@ -87,23 +100,56 @@ newtype GridArea = GridArea Text ------------------------------------------------------------------------------- -gridRowStart :: GridCoordinate -> Css +gridRowStart :: GridLocation -> Css gridRowStart = key "grid-row-start" -gridRowEnd :: GridCoordinate -> Css +gridRowEnd :: GridLocation -> Css gridRowEnd = key "grid-row-end" -gridColumnStart :: GridCoordinate -> Css +gridColumnStart :: GridLocation -> Css gridColumnStart = key "grid-column-start" -gridColumnEnd :: GridCoordinate -> Css +gridColumnEnd :: GridLocation -> Css gridColumnEnd = key "grid-column-end" -newtype GridCoordinate = GridCoordinate Value - deriving (Val, Auto, Inherit, Initial, Unset) +gridLocation :: IsSpan -> These Integer GridArea -> GridLocation +gridLocation isSpan these = GridLocation_Data $ GridLocationData isSpan these + +data IsSpan = Span | NoSpan + deriving (Show, Eq) + +data GridLocation + = GridLocation_Keyword Value + | GridLocation_Data GridLocationData + +instance Val GridLocation where + value (GridLocation_Keyword v) = v + value (GridLocation_Data d) = value d + +instance Auto GridLocation where auto = GridLocation_Keyword auto +instance Inherit GridLocation where inherit = GridLocation_Keyword inherit +instance Initial GridLocation where initial = GridLocation_Keyword initial +instance Unset GridLocation where unset = GridLocation_Keyword unset + +data GridLocationData = GridLocationData + { gridLocation_span :: IsSpan + , gridLocation_coordinateAndOrGridArea :: These Integer GridArea + } + +instance (Val a, Val b) => Val (These a b) where + value (This a) = value a + value (That b) = value b + value (These a b) = value (a, b) + +instance Val GridLocationData where + value (GridLocationData isSpan coordinateAndOrGridArea) = + if isSpan == Span + then value ("span" :: Text, coordinateAndOrGridArea) + else value coordinateAndOrGridArea + +instance Num GridLocation where + fromInteger = gridLocation NoSpan . This -instance Num GridCoordinate where - fromInteger = GridCoordinate . value ------------------------------------------------------------------------------- -- | Property defines the template for grid layout @@ -133,7 +179,7 @@ instance Val GridTemplateNamedAreas where in value $ Text.intercalate "\n" $ - map convertRow $ + fmap convertRow $ rows -- | toList will throw when your grid template areas are invalid @@ -150,7 +196,7 @@ instance IsList GridTemplateNamedAreas where mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplateNamedAreas GridTemplateNamedAreas mkGridTemplateNamedAreas rows = do let - counts = map length (coerce rows :: [[GridArea]]) + counts = fmap length (coerce rows :: [[GridArea]]) longest = maximum counts when (null rows ) $ From 1265b8832da7fdfe3ba4a7d4258bcf7c32219a2d Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 12:13:42 -0400 Subject: [PATCH 16/51] Fix a test --- src/Clay/Grid.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index cc96f1b..b1d7ca5 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -149,6 +149,8 @@ instance Val GridLocationData where instance Num GridLocation where fromInteger = gridLocation NoSpan . This + negate (GridLocation_Data (GridLocationData NoSpan (This index))) = + fromInteger $ negate index ------------------------------------------------------------------------------- From b38178472f42d74fba3a45b36c4d7067954f5899 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 12:22:48 -0400 Subject: [PATCH 17/51] Use bi-directional pattern to simplify --- src/Clay/Grid.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index b1d7ca5..fa750a2 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -3,6 +3,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE PatternSynonyms #-} -- | Partial implementation of . module Clay.Grid ( gap @@ -39,9 +40,7 @@ import Clay.Common import Clay.Property import Clay.Size import Clay.Stylesheet -import Clay.Elements -import Prelude hiding (span) import Data.String (IsString) import Data.Text (Text) import qualified Data.Text as Text @@ -147,10 +146,12 @@ instance Val GridLocationData where then value ("span" :: Text, coordinateAndOrGridArea) else value coordinateAndOrGridArea +pattern GridIndex :: Integer -> GridLocation +pattern GridIndex n = GridLocation_Data (GridLocationData NoSpan (This n)) + instance Num GridLocation where - fromInteger = gridLocation NoSpan . This - negate (GridLocation_Data (GridLocationData NoSpan (This index))) = - fromInteger $ negate index + fromInteger = GridIndex + negate (GridIndex index) = GridIndex $ negate index ------------------------------------------------------------------------------- From 21c7d4131e369dc0bac8532435cd4e38e5600084 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 12:33:50 -0400 Subject: [PATCH 18/51] Drop browser prefixes from calc --- CHANGELOG | 4 ++++ spec/Clay/GridSpec.hs | 2 +- src/Clay/Size.hs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8102661..4b438fe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,10 @@ CHANGELOG gridArea: `grid-area` deprecate: 'Clay.Grid.gridGap' in favor of 'Clay.Grid.gap' newtype GridArea for type safe grid area templating + - 'Clay.Size': + AnyUnit, a size parameter for lists of mixed units + upcast :: Size a -> Size AnyUnit + drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at 96% for unprefixed calc) 0.14.0: - Drop support for GHC 8.2 diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 029e817..046baeb 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -43,7 +43,7 @@ spec = do gridTemplateRows none describe "list of sizes" $ do - "{grid-template-columns:1em 20% auto}" + "{grid-template-columns:1em calc(20% + 1fr) auto}" `shouldRenderFrom` gridTemplateColumns [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index 9b2c3ea..3df8cd6 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -119,7 +119,7 @@ sizeToText (OtherSize a) = plain $ unValue a instance Val (Size a) where value (SimpleSize a) = value a value (OtherSize a) = a - value s = Value $ browsers <> Plain ("calc" <> sizeToText s) + value s = Value $ Plain ("calc" <> sizeToText s) instance Auto (Size a) where auto = OtherSize Clay.Common.autoValue instance Normal (Size a) where normal = OtherSize Clay.Common.normalValue From 367fc84d6cbc7d4b4e9557dd6551e33f6d950832 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 12:35:00 -0400 Subject: [PATCH 19/51] update statistic --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4b438fe..a75e4f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,7 +15,7 @@ CHANGELOG - 'Clay.Size': AnyUnit, a size parameter for lists of mixed units upcast :: Size a -> Size AnyUnit - drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at 96% for unprefixed calc) + drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) 0.14.0: - Drop support for GHC 8.2 From 7c0568db2565165996aa54812fc198513167d9eb Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 13:05:30 -0400 Subject: [PATCH 20/51] Implement minmax css function --- CHANGELOG | 1 + spec/Clay/GridSpec.hs | 4 ++-- src/Clay/Size.hs | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a75e4f5..45fc68d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ CHANGELOG - 'Clay.Size': AnyUnit, a size parameter for lists of mixed units upcast :: Size a -> Size AnyUnit + minmax :: Size a -> Size a -> Size AnyUnit, a css function for grids drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) 0.14.0: diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 046baeb..0f2af54 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -32,9 +32,9 @@ spec = do gridTemplateRows none describe "list of sizes" $ do - "{grid-template-rows:50px auto 40em}" + "{grid-template-rows:50px auto minmax(400em,50%)}" `shouldRenderFrom` - gridTemplateRows [px 50, auto, em 40] + gridTemplateRows [upcast (px 50), upcast auto, minmax (em 400) (pct 50)] describe "gridTemplateColumns" $ do describe "keyword" $ do diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index 3df8cd6..fc9ada7 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -40,6 +40,7 @@ module Clay.Size , minContent , available , fitContent +, minmax -- * Calculation operators for calc @@ -102,6 +103,7 @@ data Size a = SimpleSize Text | forall b c. SumSize (Size b) (Size c) | forall b c. DiffSize (Size b) (Size c) | + forall b c. MinMaxSize (Size b) (Size c) | MultSize Double (Size a) | DivSize Double (Size a) | OtherSize Value @@ -114,11 +116,13 @@ sizeToText (SumSize a b) = mconcat ["(", sizeToText a, " + ", sizeToText b, ")"] sizeToText (DiffSize a b) = mconcat ["(", sizeToText a, " - ", sizeToText b, ")"] sizeToText (MultSize a b) = mconcat ["(", cssDoubleText a, " * ", sizeToText b, ")"] sizeToText (DivSize a b) = mconcat ["(", sizeToText b, " / ", cssDoubleText a, ")"] +sizeToText (MinMaxSize a b) = mconcat ["minmax(", sizeToText a, ",", sizeToText b, ")"] sizeToText (OtherSize a) = plain $ unValue a instance Val (Size a) where value (SimpleSize a) = value a value (OtherSize a) = a + value s@(MinMaxSize _ _) = Value $ Plain $ sizeToText s value s = Value $ Plain ("calc" <> sizeToText s) instance Auto (Size a) where auto = OtherSize Clay.Common.autoValue @@ -197,6 +201,10 @@ available = SimpleSize "available" fitContent :: Size LengthUnit fitContent = SimpleSize "fit-content" +-- | A mixed size range; only valid within grid-template-rows, grid-template-columns, grid-auto-rows, or grid-auto-columns. +minmax :: Size a -> Size b -> Size AnyUnit +minmax = MinMaxSize + -- | SimpleSize in percents. pct :: Double -> Size Percentage pct i = SimpleSize (cssDoubleText i <> "%") From 59bc0592f1a2dc402dc6cb9b5cd5938dbc181344 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 13:19:37 -0400 Subject: [PATCH 21/51] Use formal syntax name --- src/Clay/Grid.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index fa750a2..8237e2e 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -11,7 +11,7 @@ module Clay.Grid , columnGap , gridTemplateRows , gridTemplateColumns - , GridTemplateSizes + , GridTrackList , gridArea , blankGridArea , GridArea @@ -71,20 +71,20 @@ columnGap = key "column-gap" <> key "grid-column-gap" ------------------------------------------------------------------------------- -- | Property defines the line names and track sizing functions of the grid rows. -gridTemplateRows :: GridTemplateSizes a -> Css +gridTemplateRows :: GridTrackList a -> Css gridTemplateRows = key "grid-template-rows" -- | Property defines the line names and track sizing functions of the grid columns. -gridTemplateColumns :: GridTemplateSizes a -> Css +gridTemplateColumns :: GridTrackList a -> Css gridTemplateColumns = key "grid-template-columns" -newtype GridTemplateSizes a = GridTemplateSizes Value +newtype GridTrackList a = GridTrackList Value deriving (Val, None, Inherit, Initial, Unset) -instance IsList (GridTemplateSizes a) where - type Item (GridTemplateSizes a) = Size a +instance IsList (GridTrackList a) where + type Item (GridTrackList a) = Size a toList = error "" - fromList = GridTemplateSizes . noCommas + fromList = GridTrackList . noCommas ------------------------------------------------------------------------------- -- | Property defines the element location inside grid template From ade2300ccd3da7b966f22c17decf8c70152c0649 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 13:22:24 -0400 Subject: [PATCH 22/51] grid-auto-* properties --- src/Clay/Grid.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 8237e2e..387a968 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -86,6 +86,25 @@ instance IsList (GridTrackList a) where toList = error "" fromList = GridTrackList . noCommas +------------------------------------------------------------------------------- + +-- | Property defines the line names and track sizing functions of the grid rows. +gridAutoRows :: GridAutoTrackList a -> Css +gridTemplateRows = key "grid-template-rows" + +-- | Property defines the line names and track sizing functions of the grid columns. +gridAutoColumns :: GridAutoTrackList a -> Css +gridTemplateColumns = key "grid-template-columns" + +newtype GridAutoTrackList a = GridAutoTrackList Value + deriving (Val, Auto, MinContent, MaxContent, Inherit, Initial, Unset) + +instance IsList (GridAutoTrackList a) where + type Item (GridAutoTrackList a) = Size a + toList = error "" + fromList = GridAutoTrackList . noCommas + + ------------------------------------------------------------------------------- -- | Property defines the element location inside grid template gridArea :: GridArea -> Css From fbde8a87d68dd80cd16678b878e927a28705b85a Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 13:26:02 -0400 Subject: [PATCH 23/51] fixup! Drop browser prefixes from calc --- spec/Clay/SizeSpec.hs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/Clay/SizeSpec.hs b/spec/Clay/SizeSpec.hs index c6d57ce..b132608 100644 --- a/spec/Clay/SizeSpec.hs +++ b/spec/Clay/SizeSpec.hs @@ -18,11 +18,6 @@ import Data.List sizeRepr :: Size a -> Text sizeRepr = plain . unValue . value -hasAllPrefixes :: Val a => a -> Bool -hasAllPrefixes a = checkPrefixed ((unValue . value) a) browsers - where checkPrefixed (Prefixed pa) (Prefixed pb) = sort (fmap fst pa) == sort (fmap fst pb) - checkPrefixed _ _ = False - compactRender :: Css -> Text compactRender css = toStrict $ renderWith compact [] css @@ -47,8 +42,6 @@ spec = do sizeRepr (em 2 @+@ px 1) `shouldBe` "calc(2em + 1px)" it "returns calc for nested sum" $ sizeRepr (em 2 @+@ pt 1 @+@ px 3) `shouldBe` "calc((2em + 1pt) + 3px)" - it "returns prefixed calc for simple sum" $ - (em 2 @+@ pt 2) `shouldSatisfy` hasAllPrefixes it "return calc for sum of different types" $ sizeRepr (em 2 @+@ pct 10) `shouldBe` "calc(2em + 10%)" it "returns calc for simple difference" $ From 5d68bee166d5899ab971c3efc408f2d183beeb55 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 13:34:04 -0400 Subject: [PATCH 24/51] WIP - MinContent / MaxContent --- src/Clay/Common.hs | 56 ++++++++++++++++++++++++++-------------------- src/Clay/Size.hs | 8 ------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Clay/Common.hs b/src/Clay/Common.hs index 5a1cf26..6b26c59 100644 --- a/src/Clay/Common.hs +++ b/src/Clay/Common.hs @@ -15,17 +15,19 @@ import Data.String (IsString) ------------------------------------------------------------------------------- -class All a where all :: a -class Auto a where auto :: a -class Baseline a where baseline :: a -class Center a where center :: a -class Inherit a where inherit :: a -class None a where none :: a -class Normal a where normal :: a -class Visible a where visible :: a -class Hidden a where hidden :: a -class Initial a where initial :: a -class Unset a where unset :: a +class All a where all :: a +class Auto a where auto :: a +class Baseline a where baseline :: a +class Center a where center :: a +class Inherit a where inherit :: a +class None a where none :: a +class Normal a where normal :: a +class Visible a where visible :: a +class Hidden a where hidden :: a +class Initial a where initial :: a +class Unset a where unset :: a +class MinContent a where minContent :: a +class MaxContent a where maxContent :: a -- | The other type class is used to escape from the type safety introduced by -- embedding CSS properties into the typed world of Clay. `Other` allows you to @@ -55,19 +57,25 @@ initialValue :: Value initialValue = "initial" unsetValue :: Value unsetValue = "unset" - -instance All Value where all = allValue -instance Auto Value where auto = autoValue -instance Baseline Value where baseline = baselineValue -instance Center Value where center = centerValue -instance Inherit Value where inherit = inheritValue -instance Normal Value where normal = normalValue -instance None Value where none = noneValue -instance Visible Value where visible = visibleValue -instance Hidden Value where hidden = hiddenValue -instance Other Value where other = id -instance Initial Value where initial = initialValue -instance Unset Value where unset = unsetValue +minContentValue :: Value +minContentValue = "min-content" +maxContentValue :: Value +maxContentValue = "max-content" + +instance All Value where all = allValue +instance Auto Value where auto = autoValue +instance Baseline Value where baseline = baselineValue +instance Center Value where center = centerValue +instance Inherit Value where inherit = inheritValue +instance Normal Value where normal = normalValue +instance None Value where none = noneValue +instance Visible Value where visible = visibleValue +instance Hidden Value where hidden = hiddenValue +instance Other Value where other = id +instance Initial Value where initial = initialValue +instance Unset Value where unset = unsetValue +instance MinContent Value where minContent = minContentValue +instance MaxContent Value where maxContent = maxContentValue ------------------------------------------------------------------------------- diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index fc9ada7..94dfa1c 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -185,14 +185,6 @@ vmax i = SimpleSize (cssDoubleText i <> "vmax") -- | 'SimpleSize' in fr's (a fractional unit and 1fr is for 1 part of the available space in grid areas). fr i = SimpleSize (cssDoubleText i <> "fr") --- | SimpleSize for the intrinsic preferred width. -maxContent :: Size LengthUnit -maxContent = SimpleSize "max-content" - --- | SimpleSize for the intrinsic minimum width. -minContent :: Size LengthUnit -minContent = SimpleSize "min-content" - -- | SimpleSize for the containing block width minus horizontal margin, border, and padding. available :: Size LengthUnit available = SimpleSize "available" From c4c2c1dfa67ff94e57b0401193b49f304a576d44 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 14:28:12 -0400 Subject: [PATCH 25/51] grid-auto-rows & grid-auto-columns --- CHANGELOG | 13 +++++++++---- spec/Clay/GridSpec.hs | 23 +++++++++++++++++++---- src/Clay/Grid.hs | 7 +++++-- src/Clay/Size.hs | 15 ++++++++++----- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 45fc68d..03cbc9d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,16 +6,21 @@ CHANGELOG gap: `gap` & `grid-gap` rowGap: `row-gap` & `grid-row-gap` columnGap: `column-gap` & `grid-column-gap` + gridArea: `grid-area` + gridAutoRows: `grid-auto-rows` + gridAutoColumns: `grid-auto-columns` gridTemplateRows: `grid-template-rows` - gridTemplateColumns: `grid-template-columns` + gridTemplateColumns: `grid-template-columns` (already existed, but now handles more cases) gridTemplateAreas: `grid-template-areas` - gridArea: `grid-area` deprecate: 'Clay.Grid.gridGap' in favor of 'Clay.Grid.gap' - newtype GridArea for type safe grid area templating - 'Clay.Size': AnyUnit, a size parameter for lists of mixed units upcast :: Size a -> Size AnyUnit - minmax :: Size a -> Size a -> Size AnyUnit, a css function for grids + minmax :: Size a -> Size a -> Size AnyUnit + remove `available`, it's not a valid css size + upgrade `fitContent` from value to function, it's not valid without an argument: + https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage + drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) 0.14.0: diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 0f2af54..cc6f4ef 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -32,21 +32,36 @@ spec = do gridTemplateRows none describe "list of sizes" $ do - "{grid-template-rows:50px auto minmax(400em,50%)}" + "{grid-template-rows:50px fit-content(500px) minmax(400em,50%)}" `shouldRenderFrom` - gridTemplateRows [upcast (px 50), upcast auto, minmax (em 400) (pct 50)] + gridTemplateRows [upcast (px 50), upcast $ fitContent (px 500), minmax (em 400) (pct 50)] describe "gridTemplateColumns" $ do describe "keyword" $ do - "{grid-template-rows:none}" + "{grid-template-columns:none}" `shouldRenderFrom` - gridTemplateRows none + gridTemplateColumns none describe "list of sizes" $ do "{grid-template-columns:1em calc(20% + 1fr) auto}" `shouldRenderFrom` gridTemplateColumns [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] + describe "gridAutoRows" $ do + describe "keywords" $ do + "{grid-auto-rows:min-content}" + `shouldRenderFrom` + gridAutoRows minContent + + "{grid-auto-rows:max-content}" + `shouldRenderFrom` + gridAutoRows maxContent + + describe "list of sizes" $ do + "{grid-auto-rows:1em calc(20% + 1fr) auto}" + `shouldRenderFrom` + gridAutoRows [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] + describe "gridArea" $ do "{grid-area:header}" `shouldRenderFrom` diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 387a968..eea0090 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -12,6 +12,9 @@ module Clay.Grid , gridTemplateRows , gridTemplateColumns , GridTrackList + , gridAutoRows + , gridAutoColumns + , GridAutoTrackList , gridArea , blankGridArea , GridArea @@ -90,11 +93,11 @@ instance IsList (GridTrackList a) where -- | Property defines the line names and track sizing functions of the grid rows. gridAutoRows :: GridAutoTrackList a -> Css -gridTemplateRows = key "grid-template-rows" +gridAutoRows = key "grid-auto-rows" -- | Property defines the line names and track sizing functions of the grid columns. gridAutoColumns :: GridAutoTrackList a -> Css -gridTemplateColumns = key "grid-template-columns" +gridAutoColumns = key "grid-auto-columns" newtype GridAutoTrackList a = GridAutoTrackList Value deriving (Val, Auto, MinContent, MaxContent, Inherit, Initial, Unset) diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index 94dfa1c..2954bcc 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -38,7 +38,6 @@ module Clay.Size , fr , maxContent , minContent -, available , fitContent , minmax @@ -104,6 +103,7 @@ data Size a = forall b c. SumSize (Size b) (Size c) | forall b c. DiffSize (Size b) (Size c) | forall b c. MinMaxSize (Size b) (Size c) | + forall b. FitContentSize (Size b) | MultSize Double (Size a) | DivSize Double (Size a) | OtherSize Value @@ -117,12 +117,14 @@ sizeToText (DiffSize a b) = mconcat ["(", sizeToText a, " - ", sizeToText b, ")" sizeToText (MultSize a b) = mconcat ["(", cssDoubleText a, " * ", sizeToText b, ")"] sizeToText (DivSize a b) = mconcat ["(", sizeToText b, " / ", cssDoubleText a, ")"] sizeToText (MinMaxSize a b) = mconcat ["minmax(", sizeToText a, ",", sizeToText b, ")"] +sizeToText (FitContentSize a) = mconcat ["fit-content(", sizeToText a, ")"] sizeToText (OtherSize a) = plain $ unValue a instance Val (Size a) where value (SimpleSize a) = value a value (OtherSize a) = a value s@(MinMaxSize _ _) = Value $ Plain $ sizeToText s + value s@(FitContentSize _) = Value $ Plain $ sizeToText s value s = Value $ Plain ("calc" <> sizeToText s) instance Auto (Size a) where auto = OtherSize Clay.Common.autoValue @@ -185,13 +187,16 @@ vmax i = SimpleSize (cssDoubleText i <> "vmax") -- | 'SimpleSize' in fr's (a fractional unit and 1fr is for 1 part of the available space in grid areas). fr i = SimpleSize (cssDoubleText i <> "fr") +-- | Keyword min-content size +instance MinContent (Size LengthUnit) where minContent = OtherSize minContent + +-- | Keyword max-content size +instance MaxContent (Size LengthUnit) where maxContent = OtherSize maxContent -- | SimpleSize for the containing block width minus horizontal margin, border, and padding. -available :: Size LengthUnit -available = SimpleSize "available" -- | The larger of the intrinsic minimum width or the smaller of the intrinsic preferred width and the available width. -fitContent :: Size LengthUnit -fitContent = SimpleSize "fit-content" +fitContent :: Size a -> Size a +fitContent = FitContentSize -- | A mixed size range; only valid within grid-template-rows, grid-template-columns, grid-auto-rows, or grid-auto-columns. minmax :: Size a -> Size b -> Size AnyUnit From 07d665b462b901812597daf9501cde48abe81e0c Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 14:30:21 -0400 Subject: [PATCH 26/51] Document --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 03cbc9d..f63d5d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ CHANGELOG minmax :: Size a -> Size a -> Size AnyUnit remove `available`, it's not a valid css size upgrade `fitContent` from value to function, it's not valid without an argument: + minContent & maxContent are now type class overloaded values https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) From 57cf1b70133859dccafa138bf07608e379b5c6a7 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 14:45:18 -0400 Subject: [PATCH 27/51] grid-auto-flow support --- CHANGELOG | 1 + spec/Clay/GridSpec.hs | 21 +++++++++++++++++++++ src/Clay/Common.hs | 8 ++++++++ src/Clay/Flexbox.hs | 9 +++------ src/Clay/Grid.hs | 20 ++++++++++++++++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f63d5d3..27997ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ CHANGELOG gridArea: `grid-area` gridAutoRows: `grid-auto-rows` gridAutoColumns: `grid-auto-columns` + gridAutoFlow: `grid-auto-flow` gridTemplateRows: `grid-template-rows` gridTemplateColumns: `grid-template-columns` (already existed, but now handles more cases) gridTemplateAreas: `grid-template-areas` diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index cc6f4ef..d78a60d 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -62,6 +62,27 @@ spec = do `shouldRenderFrom` gridAutoRows [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto] + describe "gridAutoFlow" $ do + "{grid-auto-flow:row}" + `shouldRenderFrom` + gridAutoFlow row + + "{grid-auto-flow:column}" + `shouldRenderFrom` + gridAutoFlow column + + "{grid-auto-flow:dense}" + `shouldRenderFrom` + gridAutoFlow dense + + "{grid-auto-flow:row dense}" + `shouldRenderFrom` + gridAutoFlow rowDense + + "{grid-auto-flow:column dense}" + `shouldRenderFrom` + gridAutoFlow columnDense + describe "gridArea" $ do "{grid-area:header}" `shouldRenderFrom` diff --git a/src/Clay/Common.hs b/src/Clay/Common.hs index 6b26c59..67ff124 100644 --- a/src/Clay/Common.hs +++ b/src/Clay/Common.hs @@ -28,6 +28,8 @@ class Initial a where initial :: a class Unset a where unset :: a class MinContent a where minContent :: a class MaxContent a where maxContent :: a +class Row a where row :: a +class Column a where column :: a -- | The other type class is used to escape from the type safety introduced by -- embedding CSS properties into the typed world of Clay. `Other` allows you to @@ -61,6 +63,10 @@ minContentValue :: Value minContentValue = "min-content" maxContentValue :: Value maxContentValue = "max-content" +rowValue :: Value +rowValue = "row" +columnValue :: Value +columnValue = "column" instance All Value where all = allValue instance Auto Value where auto = autoValue @@ -76,6 +82,8 @@ instance Initial Value where initial = initialValue instance Unset Value where unset = unsetValue instance MinContent Value where minContent = minContentValue instance MaxContent Value where maxContent = maxContentValue +instance Row Value where row = rowValue +instance Column Value where column = columnValue ------------------------------------------------------------------------------- diff --git a/src/Clay/Flexbox.hs b/src/Clay/Flexbox.hs index 510fe41..c79445e 100644 --- a/src/Clay/Flexbox.hs +++ b/src/Clay/Flexbox.hs @@ -1,7 +1,7 @@ {-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, OverloadedStrings #-} module Clay.Flexbox where -import Clay.Common (Auto, Baseline, Center, Inherit, Other) +import Clay.Common (Auto, Baseline, Center, Inherit, Other, Row, Column) import Clay.Property import Clay.Size (Size) import Clay.Stylesheet @@ -66,13 +66,10 @@ flexBasis = key "flex-basis" ------------------------------------------------------------------------------- newtype FlexDirection = FlexDirection Value - deriving (Val, Other) - -row, rowReverse, column, columnReverse :: FlexDirection + deriving (Val, Other, Row, Column) -row = FlexDirection "row" +rowReverse, columnReverse :: FlexDirection rowReverse = FlexDirection "row-reverse" -column = FlexDirection "column" columnReverse = FlexDirection "column-reverse" flexDirection :: FlexDirection -> Css diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index eea0090..78dc351 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -15,6 +15,12 @@ module Clay.Grid , gridAutoRows , gridAutoColumns , GridAutoTrackList + , gridAutoFlow + , row + , column + , dense + , rowDense + , columnDense , gridArea , blankGridArea , GridArea @@ -107,7 +113,21 @@ instance IsList (GridAutoTrackList a) where toList = error "" fromList = GridAutoTrackList . noCommas +------------------------------------------------------------------------------- +gridAutoFlow :: GridAutoFlow -> Css +gridAutoFlow = key "grid-auto-flow" + +newtype GridAutoFlow = GridAutoFlow Value + deriving (Val, Row, Column, Inherit, Initial, Unset) + +dense :: GridAutoFlow +dense = GridAutoFlow "dense" + +rowDense :: GridAutoFlow +rowDense = GridAutoFlow "row dense" +columnDense :: GridAutoFlow +columnDense = GridAutoFlow "column dense" ------------------------------------------------------------------------------- -- | Property defines the element location inside grid template gridArea :: GridArea -> Css From 2a4bdb36de44e9412437fd7bb01810a4d1b95051 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 14:50:02 -0400 Subject: [PATCH 28/51] Include package version bound for these --- clay.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clay.cabal b/clay.cabal index 6746274..47c87c4 100644 --- a/clay.cabal +++ b/clay.cabal @@ -76,7 +76,7 @@ Library base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, - these + these < 1.2 GHC-Options: -Wall -Wcompat Test-Suite Test-Clay @@ -88,7 +88,7 @@ Test-Suite Test-Clay base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, - these, + these < 1.2, hspec >= 2.2.0 && < 2.8, hspec-discover >= 2.2.0 && < 2.8 GHC-Options: -Wall -Wcompat From 0d44926173de37063940a8012ed8d69e27fb7de1 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 15:38:21 -0400 Subject: [PATCH 29/51] Add keyword size values --- CHANGELOG | 3 ++- src/Clay/Size.hs | 20 +++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 27997ef..d3c65d4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,7 +18,8 @@ CHANGELOG AnyUnit, a size parameter for lists of mixed units upcast :: Size a -> Size AnyUnit minmax :: Size a -> Size a -> Size AnyUnit - remove `available`, it's not a valid css size + remove `available`, `normal`: not valid css sizes + include `initial`, `unset` keyword values upgrade `fitContent` from value to function, it's not valid without an argument: minContent & maxContent are now type class overloaded values https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage diff --git a/src/Clay/Size.hs b/src/Clay/Size.hs index 2954bcc..77084eb 100644 --- a/src/Clay/Size.hs +++ b/src/Clay/Size.hs @@ -127,10 +127,15 @@ instance Val (Size a) where value s@(FitContentSize _) = Value $ Plain $ sizeToText s value s = Value $ Plain ("calc" <> sizeToText s) -instance Auto (Size a) where auto = OtherSize Clay.Common.autoValue -instance Normal (Size a) where normal = OtherSize Clay.Common.normalValue -instance Inherit (Size a) where inherit = OtherSize Clay.Common.inheritValue -instance None (Size a) where none = OtherSize Clay.Common.noneValue +-- Keywords +instance Auto (Size a) where auto = OtherSize auto +instance Inherit (Size a) where inherit = OtherSize inherit +instance Initial (Size a) where initial = OtherSize initial +instance Unset (Size a) where unset = OtherSize inherit +instance None (Size a) where none = OtherSize none +instance MinContent (Size a) where minContent = OtherSize minContent +instance MaxContent (Size a) where maxContent = OtherSize maxContent + instance Other (Size a) where other a = OtherSize a -- | Zero size. @@ -187,13 +192,6 @@ vmax i = SimpleSize (cssDoubleText i <> "vmax") -- | 'SimpleSize' in fr's (a fractional unit and 1fr is for 1 part of the available space in grid areas). fr i = SimpleSize (cssDoubleText i <> "fr") --- | Keyword min-content size -instance MinContent (Size LengthUnit) where minContent = OtherSize minContent - --- | Keyword max-content size -instance MaxContent (Size LengthUnit) where maxContent = OtherSize maxContent --- | SimpleSize for the containing block width minus horizontal margin, border, and padding. - -- | The larger of the intrinsic minimum width or the smaller of the intrinsic preferred width and the available width. fitContent :: Size a -> Size a fitContent = FitContentSize From ee7746bace9609bbd7e846c6980d5739ea7e958e Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 16:37:11 -0400 Subject: [PATCH 30/51] Fix failing test --- spec/Clay/SizeSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/Clay/SizeSpec.hs b/spec/Clay/SizeSpec.hs index b132608..17802d4 100644 --- a/spec/Clay/SizeSpec.hs +++ b/spec/Clay/SizeSpec.hs @@ -26,8 +26,8 @@ spec = do describe "render results" $ do it "marginLeft auto" $ (compactRender $ marginLeft auto) `shouldBe` "{margin-left:auto}" - it "marginLeft normal" $ - (compactRender $ marginLeft normal) `shouldBe` "{margin-left:normal}" + it "marginLeft initial" $ + (compactRender $ marginLeft initial) `shouldBe` "{margin-left:initial}" it "marginLeft inherit" $ (compactRender $ marginLeft inherit) `shouldBe` "{margin-left:inherit}" it "marginLeft none" $ From f1f4485d34ddab06bbcef19829b81df9fdab3bfd Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 16:47:59 -0400 Subject: [PATCH 31/51] Deal with warnings --- spec/Clay/GridSpec.hs | 2 -- src/Clay/Grid.hs | 20 ++++++++++---------- src/Clay/Property.hs | 6 ++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index d78a60d..d16effd 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -6,8 +6,6 @@ import Test.Hspec import Common import Clay -test = hspec spec - spec :: Spec spec = do describe "gap" $ do diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 78dc351..375fe2b 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -154,7 +154,7 @@ gridColumnEnd :: GridLocation -> Css gridColumnEnd = key "grid-column-end" gridLocation :: IsSpan -> These Integer GridArea -> GridLocation -gridLocation isSpan these = GridLocation_Data $ GridLocationData isSpan these +gridLocation isSpan = GridLocation_Data . GridLocationData isSpan data IsSpan = Span | NoSpan deriving (Show, Eq) @@ -172,15 +172,7 @@ instance Inherit GridLocation where inherit = GridLocation_Keyword inherit instance Initial GridLocation where initial = GridLocation_Keyword initial instance Unset GridLocation where unset = GridLocation_Keyword unset -data GridLocationData = GridLocationData - { gridLocation_span :: IsSpan - , gridLocation_coordinateAndOrGridArea :: These Integer GridArea - } - -instance (Val a, Val b) => Val (These a b) where - value (This a) = value a - value (That b) = value b - value (These a b) = value (a, b) +data GridLocationData = GridLocationData IsSpan (These Integer GridArea) instance Val GridLocationData where value (GridLocationData isSpan coordinateAndOrGridArea) = @@ -192,8 +184,16 @@ pattern GridIndex :: Integer -> GridLocation pattern GridIndex n = GridLocation_Data (GridLocationData NoSpan (This n)) instance Num GridLocation where + -- for index literals fromInteger = GridIndex + -- for negative index literals negate (GridIndex index) = GridIndex $ negate index + -- in general we don't support arithmetic on this type + negate _ = error "negate not defined for GridLocation" + abs = error "abs not defined for GridLocation" + signum = error "abs not defined for GridLocation" + (+) = error "addition not defined for GridLocation" + (*) = error "multiplication not defined for GridLocation" ------------------------------------------------------------------------------- diff --git a/src/Clay/Property.hs b/src/Clay/Property.hs index 1ed1e19..9b913de 100644 --- a/src/Clay/Property.hs +++ b/src/Clay/Property.hs @@ -8,6 +8,7 @@ import Data.List.NonEmpty (NonEmpty, toList) import Data.Maybe import Data.String import Data.Text (Text, replace) +import Data.These (These(..)) data Prefixed = Prefixed { unPrefixed :: [(Text, Text)] } | Plain { unPlain :: Text } deriving (Show, Eq) @@ -100,6 +101,11 @@ instance Val a => Val [a] where instance Val a => Val (NonEmpty a) where value = value . toList +instance (Val a, Val b) => Val (These a b) where + value (This a) = value a + value (That b) = value b + value (These a b) = value (a, b) + intercalate :: Monoid a => a -> [a] -> a intercalate _ [] = mempty intercalate s (x:xs) = foldl (\a b -> a `mappend` s `mappend` b) x xs From 2af5ae80bf59a1651a7568191d63d09b7b3b3070 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 17:06:09 -0400 Subject: [PATCH 32/51] Minor changes --- spec/Clay/GridSpec.hs | 2 ++ src/Clay/Grid.hs | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index d16effd..24bb44f 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -5,6 +5,8 @@ module Clay.GridSpec where import Test.Hspec import Common import Clay +import Data.These (These (..)) + spec :: Spec spec = do diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 375fe2b..1e9f99b 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -38,7 +38,7 @@ module Clay.Grid , unGridTemplateNamedAreas , InvalidGridTemplateNamedAreas(..) -- re exports - , These(..) + , module Data.These -- deprecated , gridGap @@ -49,11 +49,12 @@ import Clay.Common import Clay.Property import Clay.Size import Clay.Stylesheet +import Clay.Elements (span) +import Prelude hiding (span) import Data.String (IsString) import Data.Text (Text) import qualified Data.Text as Text - import Data.Coerce (coerce) import Data.These import GHC.Exts (IsList(..)) @@ -172,13 +173,16 @@ instance Inherit GridLocation where inherit = GridLocation_Keyword inherit instance Initial GridLocation where initial = GridLocation_Keyword initial instance Unset GridLocation where unset = GridLocation_Keyword unset +-- See under syntax: +-- https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start +-- either grid index and/or named grid area is required, but span is optional data GridLocationData = GridLocationData IsSpan (These Integer GridArea) instance Val GridLocationData where - value (GridLocationData isSpan coordinateAndOrGridArea) = + value (GridLocationData isSpan indexAndOrGridArea) = if isSpan == Span - then value ("span" :: Text, coordinateAndOrGridArea) - else value coordinateAndOrGridArea + then value (span :: Value, indexAndOrGridArea) + else value indexAndOrGridArea pattern GridIndex :: Integer -> GridLocation pattern GridIndex n = GridLocation_Data (GridLocationData NoSpan (This n)) From 891b6261d5dfea883122b6807bc4d9ae4256b730 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 21:04:52 -0400 Subject: [PATCH 33/51] Make language pragmas consistent --- src/Clay/Grid.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 1e9f99b..e4e0e94 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -1,10 +1,12 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ExistentialQuantification #-} -{-# LANGUAGE PatternSynonyms #-} --- | Partial implementation of . +{-# LANGUAGE + OverloadedStrings + , GeneralizedNewtypeDeriving + , TypeFamilies + , RankNTypes + , ExistentialQuantification + , PatternSynonyms + #-} +-- | Implementation of . module Clay.Grid ( gap , rowGap From 159684813424afb26aa0da900fabb543d5b5eb6d Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sun, 26 Jul 2020 21:08:25 -0400 Subject: [PATCH 34/51] Limit exports to necessary functionality --- src/Clay/Grid.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index e4e0e94..4a62136 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -36,11 +36,9 @@ module Clay.Grid , gridTemplateAreas , GridTemplateAreas , GridTemplateNamedAreas - , mkGridTemplateNamedAreas - , unGridTemplateNamedAreas , InvalidGridTemplateNamedAreas(..) -- re exports - , module Data.These + , These(..) -- deprecated , gridGap From 2737110dcda9d17a7f9417125a42283d5c2d76b7 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Tue, 28 Jul 2020 20:08:15 -0400 Subject: [PATCH 35/51] Undo version bump Just noticed that the latest version on hackage is 0.13.x, so I'm leaving the version number alone. --- CHANGELOG | 16 ++++++---------- nix/clay.nix | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d3c65d4..0821ca7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ CHANGELOG - 0.15.0: + 0.14.0: + - Drop support for GHC 8.2 + - Added `text-align-last` + - Fix typo in `stepsStart` + Thanks to Vasiliy Yorkin and Florian Grignon. - 'Clay.Grid': new properties: gap: `gap` & `grid-gap` @@ -11,12 +15,10 @@ CHANGELOG gridAutoColumns: `grid-auto-columns` gridAutoFlow: `grid-auto-flow` gridTemplateRows: `grid-template-rows` - gridTemplateColumns: `grid-template-columns` (already existed, but now handles more cases) + gridTemplateColumns: `grid-template-columns` gridTemplateAreas: `grid-template-areas` - deprecate: 'Clay.Grid.gridGap' in favor of 'Clay.Grid.gap' - 'Clay.Size': AnyUnit, a size parameter for lists of mixed units - upcast :: Size a -> Size AnyUnit minmax :: Size a -> Size a -> Size AnyUnit remove `available`, `normal`: not valid css sizes include `initial`, `unset` keyword values @@ -26,12 +28,6 @@ CHANGELOG drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) - 0.14.0: - - Drop support for GHC 8.2 - - Added `text-align-last` - - Fix typo in `stepsStart` - Thanks to Vasiliy Yorkin and Florian Grignon. - 0.13.3: - Improve README - Relax types for `sym2` and `sym3` combinators diff --git a/nix/clay.nix b/nix/clay.nix index 0322cd0..aff7bbc 100644 --- a/nix/clay.nix +++ b/nix/clay.nix @@ -2,7 +2,7 @@ { mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text, these }: mkDerivation { pname = "clay"; - version = "0.15.0"; + version = "0.14.0"; src = ./..; libraryHaskellDepends = [ base mtl text these ]; testHaskellDepends = [ base hspec hspec-discover mtl text these ]; From 8fd45d961f817011f8a2456e50881d612e2a5293 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Tue, 28 Jul 2020 20:10:20 -0400 Subject: [PATCH 36/51] Delete gridGap --- src/Clay/Grid.hs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 4a62136..d993009 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -39,9 +39,6 @@ module Clay.Grid , InvalidGridTemplateNamedAreas(..) -- re exports , These(..) - -- deprecated - , gridGap - ) where @@ -66,10 +63,6 @@ import Control.Monad (when) gap :: Size a -> Css gap = key "gap" <> key "grid-gap" -gridGap :: Size a -> Css -gridGap = gap -{-# DEPRECATED gridGap "Use gap, rowGap, and/or columnGap instead" #-} - -- | Property sets the size of the gap (gutter) between an element's grid rows. rowGap :: Size a -> Css rowGap = key "row-gap" <> key "grid-row-gap" @@ -267,4 +260,3 @@ data InvalidGridTemplateNamedAreas deriving (Eq, Show) instance Exception InvalidGridTemplateNamedAreas ------------------------------------------------------------------------------- From 33fc6c728f224149efd50e22d88fddbdb7a54546 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Tue, 28 Jul 2020 20:24:26 -0400 Subject: [PATCH 37/51] Document gap, rowGap, & columnGap --- src/Clay/Grid.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index d993009..af9d299 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -60,14 +60,23 @@ import Control.Monad (when) -- | Property sets the gaps (gutters) between rows and columns. +-- Sets both "gap" & "grid-gap" +-- to quote: https://developer.mozilla.org/en-US/docs/Web/CSS/gap +-- "CSS Grid Layout initially defined the grid-gap property. This prefixed property is being replaced by gap. However, in order to support browsers that implemented grid-gap and not gap for grid, you will need to use the prefixed property" gap :: Size a -> Css gap = key "gap" <> key "grid-gap" -- | Property sets the size of the gap (gutter) between an element's grid rows. +-- Sets both "row-gap" & "grid-row-gap" +-- to quote: https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap +-- "CSS Grid Layout initially defined the grid-row-gap property. This prefixed property is being replaced by row-gap. However, in order to support browsers that implemented grid-row-gap and not row-gap for grid, you will need to use the prefixed property." rowGap :: Size a -> Css rowGap = key "row-gap" <> key "grid-row-gap" -- | Property sets the size of the gap (gutter) between an element's grid columns. +-- Sets both "column-gap" & "grid-column-gap" +-- to quote: https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap +-- "CSS Grid Layout initially defined the grid-column-gap property. This prefixed property is being replaced by column-gap. However, in order to support bcolumnsers that implemented grid-column-gap and not column-gap for grid, you will need to use the prefixed property." columnGap :: Size a -> Css columnGap = key "column-gap" <> key "grid-column-gap" From 8844e04955858a113b3dddc20dea886f6b6c1c92 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 1 Aug 2020 09:40:19 -0400 Subject: [PATCH 38/51] Update src/Clay/Grid.hs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Bärenz --- src/Clay/Grid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index af9d299..5998d18 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -237,7 +237,7 @@ instance Val GridTemplateNamedAreas where instance IsList GridTemplateNamedAreas where type Item GridTemplateNamedAreas = [GridArea] toList = unGridTemplateNamedAreas . coerce - fromList = fromRightOrThrow . mkGridTemplateNamedAreas + fromList = either throw id . mkGridTemplateNamedAreas where fromRightOrThrow :: Exception e => Either e a -> a fromRightOrThrow (Right a) = a From b6d68dfad02ab8f510e58852e1ec207ea8fdaa11 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 1 Aug 2020 09:40:28 -0400 Subject: [PATCH 39/51] Update src/Clay/Grid.hs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Bärenz --- src/Clay/Grid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 5998d18..0e00e68 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -250,7 +250,7 @@ mkGridTemplateNamedAreas rows = do counts = fmap length (coerce rows :: [[GridArea]]) longest = maximum counts - when (null rows ) $ + when (null rows) $ Left GridTemplateNamedAreas_Empty when (any (== 0) counts) $ From 26eca85859072b097b5bfbae896c02c68d6380e8 Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 1 Aug 2020 09:45:54 -0400 Subject: [PATCH 40/51] Remove unnecessary coerce --- src/Clay/Grid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 0e00e68..097becc 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -236,7 +236,7 @@ instance Val GridTemplateNamedAreas where -- | toList will throw when your grid template areas are invalid instance IsList GridTemplateNamedAreas where type Item GridTemplateNamedAreas = [GridArea] - toList = unGridTemplateNamedAreas . coerce + toList = unGridTemplateNamedAreas fromList = either throw id . mkGridTemplateNamedAreas where fromRightOrThrow :: Exception e => Either e a -> a From 945facd1f80ad0601d21cc5d84e88b4d28af510e Mon Sep 17 00:00:00 2001 From: CharlesTaylor7 Date: Sat, 1 Aug 2020 09:57:05 -0400 Subject: [PATCH 41/51] Delete unused method --- src/Clay/Grid.hs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 097becc..9690f84 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -238,10 +238,6 @@ instance IsList GridTemplateNamedAreas where type Item GridTemplateNamedAreas = [GridArea] toList = unGridTemplateNamedAreas fromList = either throw id . mkGridTemplateNamedAreas - where - fromRightOrThrow :: Exception e => Either e a -> a - fromRightOrThrow (Right a) = a - fromRightOrThrow (Left e) = throw e -- | Smart constructor for GridTemplateNamedAreas mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplateNamedAreas GridTemplateNamedAreas From 5d934b327d0cac5b91442a32e56832aee8c0ceb5 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 12:45:55 -0500 Subject: [PATCH 42/51] Update changelog --- CHANGELOG | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0821ca7..25eb9ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,11 +23,9 @@ CHANGELOG remove `available`, `normal`: not valid css sizes include `initial`, `unset` keyword values upgrade `fitContent` from value to function, it's not valid without an argument: + https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage minContent & maxContent are now type class overloaded values - https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage - - drop browser prefixes from `calc` ((caniuse)[https://caniuse.com/#feat=calc] is at nearly 98% for unprefixed calc) - + 0.13.3: - Improve README - Relax types for `sym2` and `sym3` combinators From 37ccb8a8c17c1557352cb5bfc14763bd94bd6999 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 12:51:13 -0500 Subject: [PATCH 43/51] Merge conflict --- nix/clay.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/clay.nix b/nix/clay.nix index aff7bbc..bed4fd3 100644 --- a/nix/clay.nix +++ b/nix/clay.nix @@ -1,4 +1,3 @@ -<<<<<<< HEAD { mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text, these }: mkDerivation { pname = "clay"; From 389e0cd6fb41a09443385d6bcbe61240a7e9bae4 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 12:55:19 -0500 Subject: [PATCH 44/51] Include lower bound for these package --- clay.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clay.cabal b/clay.cabal index 47c87c4..d79e37c 100644 --- a/clay.cabal +++ b/clay.cabal @@ -76,7 +76,7 @@ Library base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, - these < 1.2 + these >= 0.2 && < 1.2, GHC-Options: -Wall -Wcompat Test-Suite Test-Clay @@ -88,7 +88,7 @@ Test-Suite Test-Clay base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, - these < 1.2, + these >= 0.2 && < 1.2, hspec >= 2.2.0 && < 2.8, hspec-discover >= 2.2.0 && < 2.8 GHC-Options: -Wall -Wcompat From 874a1f564fe7b7af67c7167e51f6c9e8e51cd351 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 13:25:20 -0500 Subject: [PATCH 45/51] Handle underscores --- clay.cabal | 2 +- src/Clay/Grid.hs | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/clay.cabal b/clay.cabal index d79e37c..ba802e5 100644 --- a/clay.cabal +++ b/clay.cabal @@ -76,7 +76,7 @@ Library base >= 4.11 && < 5, mtl >= 1 && < 2.3, text >= 0.11 && < 1.3, - these >= 0.2 && < 1.2, + these >= 0.2 && < 1.2 GHC-Options: -Wall -Wcompat Test-Suite Test-Clay diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 9690f84..8e264ff 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -157,37 +157,39 @@ gridColumnEnd :: GridLocation -> Css gridColumnEnd = key "grid-column-end" gridLocation :: IsSpan -> These Integer GridArea -> GridLocation -gridLocation isSpan = GridLocation_Data . GridLocationData isSpan +gridLocation isSpan = GridLocationData . MkGridLocationData isSpan data IsSpan = Span | NoSpan deriving (Show, Eq) data GridLocation - = GridLocation_Keyword Value - | GridLocation_Data GridLocationData + = GridLocationKeyword Value + | GridLocationData GridLocationData instance Val GridLocation where - value (GridLocation_Keyword v) = v - value (GridLocation_Data d) = value d + value (GridLocationKeyword v) = v + value (GridLocationData d) = value d -instance Auto GridLocation where auto = GridLocation_Keyword auto -instance Inherit GridLocation where inherit = GridLocation_Keyword inherit -instance Initial GridLocation where initial = GridLocation_Keyword initial -instance Unset GridLocation where unset = GridLocation_Keyword unset +instance Auto GridLocation where auto = GridLocationKeyword auto +instance Inherit GridLocation where inherit = GridLocationKeyword inherit +instance Initial GridLocation where initial = GridLocationKeyword initial +instance Unset GridLocation where unset = GridLocationKeyword unset -- See under syntax: -- https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start -- either grid index and/or named grid area is required, but span is optional -data GridLocationData = GridLocationData IsSpan (These Integer GridArea) +-- Note: constuctor is not exported, 'GridIndex, or 'gridLocationData to fill this info in +data GridLocationData = MkGridLocationData IsSpan (These Integer GridArea) + instance Val GridLocationData where - value (GridLocationData isSpan indexAndOrGridArea) = + value (MkGridLocationData isSpan indexAndOrGridArea) = if isSpan == Span then value (span :: Value, indexAndOrGridArea) else value indexAndOrGridArea pattern GridIndex :: Integer -> GridLocation -pattern GridIndex n = GridLocation_Data (GridLocationData NoSpan (This n)) +pattern GridIndex n = GridLocationData (MkGridLocationData NoSpan (This n)) instance Num GridLocation where -- for index literals From 561cdae3947ad69773ed4de5554ddecd118f5f8d Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 14:07:25 -0500 Subject: [PATCH 46/51] Rename type --- spec/Clay/GridSpec.hs | 6 +++--- src/Clay/Grid.hs | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/spec/Clay/GridSpec.hs b/spec/Clay/GridSpec.hs index 24bb44f..5ce6c29 100644 --- a/spec/Clay/GridSpec.hs +++ b/spec/Clay/GridSpec.hs @@ -146,7 +146,7 @@ spec = do area_c = "c" area_blank = blankGridArea - GridTemplateNamedAreas_NotRectangular + InvalidGridTemplateNotRectangular `shouldErrorFromRender` gridTemplateAreas [ [ area_blank] -- length 1 @@ -155,11 +155,11 @@ spec = do ] describe "empty template should error" $ do - GridTemplateNamedAreas_Empty + InvalidGridTemplateEmpty `shouldErrorFromRender` gridTemplateAreas [] describe "template with empty row(s) should error" $ do - GridTemplateNamedAreas_EmptyRow + InvalidGridTemplateEmptyRow `shouldErrorFromRender` gridTemplateAreas [[], []] diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 8e264ff..3667ccd 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -36,7 +36,7 @@ module Clay.Grid , gridTemplateAreas , GridTemplateAreas , GridTemplateNamedAreas - , InvalidGridTemplateNamedAreas(..) + , InvalidGridTemplate(..) -- re exports , These(..) ) @@ -242,28 +242,29 @@ instance IsList GridTemplateNamedAreas where fromList = either throw id . mkGridTemplateNamedAreas -- | Smart constructor for GridTemplateNamedAreas -mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplateNamedAreas GridTemplateNamedAreas +mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplate GridTemplateNamedAreas mkGridTemplateNamedAreas rows = do let counts = fmap length (coerce rows :: [[GridArea]]) - longest = maximum counts + shortestRowLength = minimum counts when (null rows) $ - Left GridTemplateNamedAreas_Empty + Left InvalidGridTemplateEmpty - when (any (== 0) counts) $ - Left GridTemplateNamedAreas_EmptyRow + when (shortestRowLength == 0) $ + Left InvalidGridTemplateEmptyRow - when (any (/= longest) counts) $ - Left GridTemplateNamedAreas_NotRectangular + when (any (/= shortestRowLength) counts) $ + Left InvalidGridTemplateNotRectangular Right $ GridTemplateNamedAreas rows --- | Failure modes for the smart constructor -data InvalidGridTemplateNamedAreas - = GridTemplateNamedAreas_Empty - | GridTemplateNamedAreas_EmptyRow - | GridTemplateNamedAreas_NotRectangular + +-- | Possible failure modes for 'mkGridTemplateNamedAreas +data InvalidGridTemplate + = InvalidGridTemplateEmpty + | InvalidGridTemplateEmptyRow + | InvalidGridTemplateNotRectangular deriving (Eq, Show) -instance Exception InvalidGridTemplateNamedAreas +instance Exception InvalidGridTemplate From da09a3e9dec09d5f16fa18dcd327b02f187a4458 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 14:16:49 -0500 Subject: [PATCH 47/51] Replace partial instance with a constructor --- src/Clay/Grid.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 3667ccd..037c325 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -93,10 +93,9 @@ gridTemplateColumns = key "grid-template-columns" newtype GridTrackList a = GridTrackList Value deriving (Val, None, Inherit, Initial, Unset) -instance IsList (GridTrackList a) where - type Item (GridTrackList a) = Size a - toList = error "" - fromList = GridTrackList . noCommas +-- | Create a GridTrackList from a list of sizes +mkGridTrackList :: [Size a] -> GridTrackList a +mkGridTrackList = GridTrackList . noCommas ------------------------------------------------------------------------------- From 53a5bb8cef3d1b88d9ccfaf1e8ac0152ffb97fa6 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 14:20:58 -0500 Subject: [PATCH 48/51] Remove more partial instances --- src/Clay/Grid.hs | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 037c325..bca9037 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -14,9 +14,11 @@ module Clay.Grid , gridTemplateRows , gridTemplateColumns , GridTrackList + , mkGridTrackList , gridAutoRows , gridAutoColumns , GridAutoTrackList + , mkGridAutoTrackList , gridAutoFlow , row , column @@ -110,10 +112,8 @@ gridAutoColumns = key "grid-auto-columns" newtype GridAutoTrackList a = GridAutoTrackList Value deriving (Val, Auto, MinContent, MaxContent, Inherit, Initial, Unset) -instance IsList (GridAutoTrackList a) where - type Item (GridAutoTrackList a) = Size a - toList = error "" - fromList = GridAutoTrackList . noCommas +mkGridAutoTrackList :: [Size a] -> GridAutoTrackList +mkGridAutoTrackList = GridAutoTrackList . noCommas ------------------------------------------------------------------------------- gridAutoFlow :: GridAutoFlow -> Css @@ -190,18 +190,6 @@ instance Val GridLocationData where pattern GridIndex :: Integer -> GridLocation pattern GridIndex n = GridLocationData (MkGridLocationData NoSpan (This n)) -instance Num GridLocation where - -- for index literals - fromInteger = GridIndex - -- for negative index literals - negate (GridIndex index) = GridIndex $ negate index - -- in general we don't support arithmetic on this type - negate _ = error "negate not defined for GridLocation" - abs = error "abs not defined for GridLocation" - signum = error "abs not defined for GridLocation" - (+) = error "addition not defined for GridLocation" - (*) = error "multiplication not defined for GridLocation" - ------------------------------------------------------------------------------- -- | Property defines the template for grid layout @@ -234,12 +222,6 @@ instance Val GridTemplateNamedAreas where fmap convertRow $ rows --- | toList will throw when your grid template areas are invalid -instance IsList GridTemplateNamedAreas where - type Item GridTemplateNamedAreas = [GridArea] - toList = unGridTemplateNamedAreas - fromList = either throw id . mkGridTemplateNamedAreas - -- | Smart constructor for GridTemplateNamedAreas mkGridTemplateNamedAreas :: [[GridArea]] -> Either InvalidGridTemplate GridTemplateNamedAreas mkGridTemplateNamedAreas rows = do From 6cf06cd0295bb43a2eb1ac5999e4c528534cef3b Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sat, 8 Jan 2022 14:22:24 -0500 Subject: [PATCH 49/51] Don't derive exception --- src/Clay/Grid.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index bca9037..a1a47ee 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -247,5 +247,3 @@ data InvalidGridTemplate | InvalidGridTemplateEmptyRow | InvalidGridTemplateNotRectangular deriving (Eq, Show) - -instance Exception InvalidGridTemplate From 5250c669a30b851dfef2180c527e214be4a800c7 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 9 Jan 2022 16:59:52 -0500 Subject: [PATCH 50/51] Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Bärenz --- src/Clay/Grid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index a1a47ee..79eccd7 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -177,7 +177,7 @@ instance Unset GridLocation where unset = GridLocationKeyword unset -- See under syntax: -- https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start -- either grid index and/or named grid area is required, but span is optional --- Note: constuctor is not exported, 'GridIndex, or 'gridLocationData to fill this info in +-- Note: constructor is not exported, 'GridIndex, or 'gridLocationData to fill this info in data GridLocationData = MkGridLocationData IsSpan (These Integer GridArea) From 148bf30cdbb411d20070cfa9935ebc8e3be5f151 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Mon, 10 Jan 2022 18:42:22 -0500 Subject: [PATCH 51/51] Remove invalid keywords from GridAutoTrackList MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Bärenz --- src/Clay/Grid.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clay/Grid.hs b/src/Clay/Grid.hs index 79eccd7..d82755d 100644 --- a/src/Clay/Grid.hs +++ b/src/Clay/Grid.hs @@ -110,7 +110,7 @@ gridAutoColumns :: GridAutoTrackList a -> Css gridAutoColumns = key "grid-auto-columns" newtype GridAutoTrackList a = GridAutoTrackList Value - deriving (Val, Auto, MinContent, MaxContent, Inherit, Initial, Unset) + deriving (Val, Auto, MinContent, MaxContent) mkGridAutoTrackList :: [Size a] -> GridAutoTrackList mkGridAutoTrackList = GridAutoTrackList . noCommas