datastar-hs 1.1.0.2 → 1.1.1.0
raw patch · 5 files changed
+79/−2 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Hypermedia.Datastar: [peViewTransitionSelector] :: PatchElements -> Maybe Text
+ Hypermedia.Datastar.PatchElements: [peViewTransitionSelector] :: PatchElements -> Maybe Text
- Hypermedia.Datastar: PatchElements :: Maybe Text -> Maybe Text -> ElementPatchMode -> Bool -> ElementNamespace -> Maybe Text -> Int -> PatchElements
+ Hypermedia.Datastar: PatchElements :: Maybe Text -> Maybe Text -> ElementPatchMode -> Bool -> Maybe Text -> ElementNamespace -> Maybe Text -> Int -> PatchElements
- Hypermedia.Datastar.PatchElements: PatchElements :: Maybe Text -> Maybe Text -> ElementPatchMode -> Bool -> ElementNamespace -> Maybe Text -> Int -> PatchElements
+ Hypermedia.Datastar.PatchElements: PatchElements :: Maybe Text -> Maybe Text -> ElementPatchMode -> Bool -> Maybe Text -> ElementNamespace -> Maybe Text -> Int -> PatchElements
Files
- CHANGELOG.md +10/−0
- datastar-hs.cabal +1/−1
- e2e-server/Main.hs +1/−1
- src/Hypermedia/Datastar/PatchElements.hs +25/−0
- test/Hypermedia/Datastar/PatchElementsSpec.hs +42/−0
CHANGELOG.md view
@@ -1,5 +1,15 @@ # Changelog +## 1.1.1.0++* Add `peViewTransitionSelector` to `PatchElements`: a CSS selector for the+ element to scope a view transition to, sent as the `viewTransitionSelector`+ data line. It is only sent when `peUseViewTransition` is `True`, and needs+ Datastar 1.0.2 or later in the browser. Code that builds events with+ `patchElements` or `removeElements` is unaffected; code that uses the+ `PatchElements` constructor directly needs the new field.+* Bump the examples and the e2e test page to Datastar 1.0.3+ ## 1.1.0.2 * Doc-only release: the package description now links to
datastar-hs.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: datastar-hs-version: 1.1.0.2+version: 1.1.1.0 synopsis: Haskell bindings for Datastar description: Server-side SDK for building real-time hypermedia applications with
e2e-server/Main.hs view
@@ -48,7 +48,7 @@ testPage = renderBS $ doctypehtml_ $ do head_ $ do title_ "datastar-hs e2e tests"- script_ [type_ "module", src_ "https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0/bundles/datastar.js"] ("" :: T.Text)+ script_ [type_ "module", src_ "https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.3/bundles/datastar.js"] ("" :: T.Text) body_ [makeAttributes "data-signals" "{}"] $ do h1_ "datastar-hs E2E Test Page"
src/Hypermedia/Datastar/PatchElements.hs view
@@ -25,6 +25,17 @@ } @ +To animate the update with a view transition, optionally scoped to a single+element:++@+sendPatchElements gen+ (patchElements "\<div id=\\\"feed\\\"\>...\<\/div\>")+ { peUseViewTransition = True+ , peViewTransitionSelector = Just \"#main\"+ }+@+ To remove elements from the DOM, use 'removeElements' with a CSS selector: @@@ -61,6 +72,13 @@ <https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API View Transition>. Default: 'False'. -}+ , peViewTransitionSelector :: Maybe Text+ {- ^ CSS selector for the element to scope the view transition to (an+ <https://developer.chrome.com/blog/element-scoped-view-transitions element-scoped view transition>).+ Only sent when 'peUseViewTransition' is 'True'. When 'Nothing' (the+ default), or when nothing matches the selector, the transition applies+ to the whole document. Needs Datastar 1.0.2 or later in the browser.+ -} , peNamespace :: ElementNamespace {- ^ XML namespace for the patched elements. Default: 'HtmlNs'. Use 'SvgNs' or 'MathmlNs' when patching inline SVG or MathML.@@ -91,6 +109,7 @@ , peSelector = Nothing , peMode = defaultPatchMode , peUseViewTransition = defaultUseViewTransition+ , peViewTransitionSelector = Nothing , peNamespace = defaultNamespace , peEventId = Nothing , peRetryDuration = defaultRetryDuration@@ -110,6 +129,7 @@ , peSelector = Just sel , peMode = Remove , peUseViewTransition = defaultUseViewTransition+ , peViewTransitionSelector = Nothing , peNamespace = defaultNamespace , peEventId = Nothing , peRetryDuration = defaultRetryDuration@@ -129,6 +149,11 @@ ] , [ "useViewTransition true" | peUseViewTransition pe+ ]+ , [ "viewTransitionSelector " <> s+ | peUseViewTransition pe+ , Just s <- [peViewTransitionSelector pe]+ , not (T.null s) ] , [ "namespace " <> namespaceToText (peNamespace pe) | peNamespace pe /= defaultNamespace
test/Hypermedia/Datastar/PatchElementsSpec.hs view
@@ -26,6 +26,7 @@ { peSelector = Just "#feed" , peMode = Inner , peUseViewTransition = True+ , peViewTransitionSelector = Just "#main" , peNamespace = HtmlNs , peEventId = Just "123" , peRetryDuration = 2000@@ -38,6 +39,7 @@ `shouldBe` [ "selector #feed" , "mode inner" , "useViewTransition true"+ , "viewTransitionSelector #main" , "elements <div id=\"feed\">" , "elements <span>1</span>" , "elements </div>"@@ -94,6 +96,46 @@ event = toDatastarEvent pe lines' = dataLines event any (T.isPrefixOf "mode") lines' `shouldBe` False++ it "view transition without a selector" $ do+ let pe = (patchElements "<p>hello</p>"){peUseViewTransition = True}+ event = toDatastarEvent pe+ dataLines event+ `shouldBe` [ "useViewTransition true"+ , "elements <p>hello</p>"+ ]++ it "viewTransitionSelector sits between useViewTransition and namespace" $ do+ let pe =+ (patchElements "<circle id=\"c1\" r=\"5\"/>")+ { peUseViewTransition = True+ , peViewTransitionSelector = Just "#vis"+ , peNamespace = SvgNs+ }+ event = toDatastarEvent pe+ dataLines event+ `shouldBe` [ "useViewTransition true"+ , "viewTransitionSelector #vis"+ , "namespace svg"+ , "elements <circle id=\"c1\" r=\"5\"/>"+ ]++ it "omits viewTransitionSelector when useViewTransition is False" $ do+ let pe = (patchElements "<p>hello</p>"){peViewTransitionSelector = Just "#main"}+ event = toDatastarEvent pe+ dataLines event `shouldBe` ["elements <p>hello</p>"]++ it "omits viewTransitionSelector when empty" $ do+ let pe =+ (patchElements "<p>hello</p>")+ { peUseViewTransition = True+ , peViewTransitionSelector = Just ""+ }+ event = toDatastarEvent pe+ dataLines event+ `shouldBe` [ "useViewTransition true"+ , "elements <p>hello</p>"+ ] it "politely ignores empty element strings" $ do let lines' =