Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 89a369d

Browse files
authored
Merge pull request #11 from safareli/update
Update URI
2 parents 0c76236 + 778b520 commit 89a369d

File tree

5 files changed

+99
-46
lines changed

5 files changed

+99
-46
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"purescript-dom-classy": "^2.1.0",
1414
"purescript-transformers": "^3.2.0",
1515
"purescript-control": "^3.0.0",
16-
"purescript-uri": "^4.0.0",
16+
"purescript-uri": "^5.0.0",
1717
"purescript-colors": "^4.0.0",
1818
"purescript-symbols": "^3.0.0",
1919
"purescript-canvas": "^3.0.0",

example/src/Main.purs

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,62 @@ module Main where
33
import Prelude
44

55
import Color as Color
6-
76
import Control.Monad.Eff (Eff)
8-
import Control.Monad.Eff.Ref (REF)
9-
import Control.Monad.Eff.Random (RANDOM, random)
107
import Control.Monad.Eff.Class (liftEff)
8+
import Control.Monad.Eff.Random (RANDOM, random)
9+
import Control.Monad.Eff.Ref (REF)
1110
import Control.Monad.Maybe.Trans (MaybeT(..), runMaybeT)
12-
11+
import DOM (DOM)
12+
import DOM.Classy.ParentNode (class IsParentNode, querySelector)
13+
import DOM.HTML (window)
14+
import DOM.HTML.Window (document)
1315
import Data.Array as A
1416
import Data.Either (Either(..))
15-
import Data.Traversable as F
1617
import Data.Maybe (Maybe(..))
1718
import Data.Newtype (wrap)
18-
import Data.Path.Pathy (file, dir, (</>), rootDir, currentDir)
19-
import Data.URI (URIRef)
20-
import Data.URI as URI
21-
22-
import DOM (DOM)
23-
import DOM.HTML (window)
24-
import DOM.Classy.ParentNode (class IsParentNode, querySelector)
25-
import DOM.HTML.Window (document)
26-
19+
import Data.String.NonEmpty as NES
20+
import Data.These (These(..))
21+
import Data.Traversable as F
22+
import Data.Tuple (Tuple(..))
2723
import Graphics.Canvas (CANVAS)
28-
24+
import HeatmapLayerData (heatmapLayerData)
25+
import Leaflet.Core (mkLeafURIRef)
2926
import Leaflet.Core as LC
27+
import Leaflet.Core.Types (LeafURIRef)
3028
import Leaflet.Plugin.Heatmap as LH
3129
import Leaflet.Util ((×))
32-
33-
import HeatmapLayerData (heatmapLayerData)
30+
import Partial.Unsafe (unsafePartial)
31+
import URI (Authority(..), Fragment, HierPath, HierarchicalPart(..), Host(..), Path(..), PathAbsolute(..), Port, Query, RelPath, RelativePart(..), RelativeRef(..), URI(..), URIRef, UserInfo)
32+
import URI.Host.RegName as RegName
33+
import URI.HostPortPair (HostPortPair)
34+
import URI.HostPortPair as HostPortPair
35+
import URI.Path.Segment (segmentNZFromString)
36+
import URI.Path.Segment as PathSegment
37+
import URI.Scheme as Scheme
38+
import URI.URIRef (URIRefOptions)
3439

3540
foreign import onload e a. Eff e a Eff e a
3641

42+
type MainURIRef = URIRef UserInfo (HostPortPair Host Port) Path HierPath RelPath Query Fragment
43+
44+
mainURIRefOptions Record (URIRefOptions UserInfo (HostPortPair Host Port) Path HierPath RelPath Query Fragment)
45+
mainURIRefOptions =
46+
{ parseUserInfo: pure
47+
, printUserInfo: id
48+
, parseHosts: HostPortPair.parser pure pure
49+
, printHosts: HostPortPair.print id id
50+
, parsePath: pure
51+
, printPath: id
52+
, parseHierPath: pure
53+
, printHierPath: id
54+
, parseRelPath: pure
55+
, printRelPath: id
56+
, parseQuery: pure
57+
, printQuery: id
58+
, parseFragment: pure
59+
, printFragment: id
60+
}
61+
3762
mkLatLngs e. MaybeT (Eff (dom DOM, random RANDOM|e)) (Array LC.LatLng)
3863
mkLatLngs = do
3964
let inp = A.range 0 5
@@ -47,22 +72,27 @@ mkLatLngs = do
4772
pure $ A.zipWith (\lat lng → {lat, lng}) lats lngs
4873

4974

50-
testURI URIRef
51-
testURI =
52-
Left $ URI.URI
53-
(Just $ URI.Scheme "http")
54-
(URI.HierarchicalPart
55-
(Just $ URI.Authority Nothing [(URI.NameAddress "{s}.tile.osm.org") × Nothing])
56-
(Just $ Right $ rootDir </> dir "{z}" </> dir "{x}" </> file "{y}.png"))
57-
Nothing
58-
Nothing
59-
60-
iconConf { iconUrl URIRef, iconSize LC.Point }
61-
iconConf =
62-
{ iconUrl: Right $ URI.RelativeRef
63-
(URI.RelativePart Nothing $ Just $ Right $ currentDir </> file "marker.svg")
75+
testURI LeafURIRef
76+
testURI = mkLeafURIRef
77+
{ uri: Left $ URI
78+
(Scheme.unsafeFromString "http")
79+
(HierarchicalPartAuth
80+
(Authority Nothing (Just $ This $ NameAddress $ RegName.fromString $ unsafePartial $ NES.unsafeFromString "{s}.tile.osm.org"))
81+
(Path $ map PathSegment.segmentFromString ["{z}", "{x}", "{y}.png"]))
6482
Nothing
6583
Nothing
84+
, opts: mainURIRefOptions
85+
}
86+
87+
iconConf { iconUrl LeafURIRef, iconSize LC.Point }
88+
iconConf =
89+
{ iconUrl: mkLeafURIRef
90+
{ uri: Right $ RelativeRef
91+
(RelativePartNoAuth $ Just $ Left $ PathAbsolute $ Just $ Tuple (segmentNZFromString $ unsafePartial $ NES.unsafeFromString "marker.svg") [])
92+
Nothing
93+
Nothing
94+
, opts: mainURIRefOptions
95+
}
6696
, iconSize: 40 × 40
6797
}
6898
core

src/Leaflet/Core/Converter.purs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ module Leaflet.Core.Converter where
33
import Prelude
44

55
import Color (Color, toHexString)
6-
76
import Data.Foldable (intercalate)
87
import Data.String.Regex as RX
98
import Data.String.Regex.Flags as RXF
109
import Data.String.Regex.Unsafe as URX
11-
import Data.URI (URIRef)
12-
import Data.URI.URIRef as URIRef
10+
import Leaflet.Core.Types (LeafURIRef)
1311
import Leaflet.Core.Types as T
1412
import Leaflet.Util ((×), (∘))
13+
import URI.URIRef as URIRef
1514

1615
type ConvertDict =
17-
{ printURI URIRef String
16+
{ printURI LeafURIRef String
1817
, mkPoint T.Point Array Int
1918
, printColor Color String
2019
, convertLatLng T.LatLng Array T.Degrees
@@ -33,7 +32,7 @@ converter =
3332
let
3433
oRx = URX.unsafeRegex "%7B" RXF.global
3534
cRx = URX.unsafeRegex "%7D" RXF.global
36-
encodedString = URIRef.print uri
35+
encodedString = T.runLeafURIRef (\r -> URIRef.print r.opts r.uri) uri
3736
replaced = RX.replace oRx "{" $ RX.replace cRx "}" encodedString
3837
in replaced
3938
, mkPoint: \(a × b) → [a, b]

src/Leaflet/Core/Layer.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Data.Array as A
3333
import Data.Foldable (class Foldable, foldMap)
3434
import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3)
3535
import Data.Maybe (Maybe(..))
36-
import Data.URI (URIRef)
36+
import Leaflet.Core.Types (LeafURIRef)
3737

3838
import DOM (DOM)
3939

@@ -129,7 +129,7 @@ layer = liftEff layer_
129129
tileLayer
130130
e m
131131
. MonadEff (dom DOM|e) m
132-
URIRef
132+
LeafURIRef
133133
m T.TileLayer
134134
tileLayer =
135135
liftEff ∘ tileLayer_ ∘ converter.printURI
@@ -163,7 +163,7 @@ popup r =
163163
setURI
164164
e m
165165
. MonadEff (dom DOM|e) m
166-
URIRef
166+
LeafURIRef
167167
T.TileLayer
168168
m T.TileLayer
169169
setURI uri tl =

src/Leaflet/Core/Types.purs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ module Leaflet.Core.Types where
22

33
import Color (Color)
44
import Data.Tuple (Tuple)
5-
import Data.URI (URIRef)
6-
5+
import Type.Data.Boolean (kind Boolean)
6+
import URI (URIRef)
7+
import URI.URIRef (URIRefOptions)
78
import Unsafe.Coerce (unsafeCoerce)
89
--------------------------------------------------------------------------------
910
-- Abstract imported types
@@ -28,6 +29,27 @@ data Zoom
2829
data Degrees
2930
data LayerGroup
3031
data Control
32+
data LeafURIRef
33+
34+
type LeafURIRefR userInfo hosts path hierPath relPath query fragment =
35+
{ uri :: URIRef userInfo hosts path hierPath relPath query fragment
36+
, opts :: Record (URIRefOptions userInfo hosts path hierPath relPath query fragment)
37+
}
38+
39+
mkLeafURIRef
40+
:: forall userInfo hosts path hierPath relPath query fragment
41+
. LeafURIRefR userInfo hosts path hierPath relPath query fragment
42+
-> LeafURIRef
43+
mkLeafURIRef = unsafeCoerce
44+
45+
runLeafURIRef
46+
:: forall r
47+
. (forall userInfo hosts path hierPath relPath query fragment
48+
. LeafURIRefR userInfo hosts path hierPath relPath query fragment
49+
-> r)
50+
-> LeafURIRef
51+
-> r
52+
runLeafURIRef = unsafeCoerce
3153

3254
-- layer converters
3355
tileToLayer TileLayer Layer
@@ -132,13 +154,13 @@ type PopupConf =
132154

133155
type IconConf =
134156
InteractiveLayerConf
135-
( iconUrl URIRef
136-
, iconRetinaUrl URIRef
157+
( iconUrl LeafURIRef
158+
, iconRetinaUrl LeafURIRef
137159
, iconSize Point
138160
, iconAnchor Point
139161
, popupAnchor Point
140-
, shadowUrl URIRef
141-
, shadowRetinaUrl URIRef
162+
, shadowUrl LeafURIRef
163+
, shadowRetinaUrl LeafURIRef
142164
, shadowSize Point
143165
, shadowAnchor Point
144166
, className String
@@ -189,3 +211,5 @@ type LayerControlConf r =
189211
, hideSingleBase Boolean
190212
, sortLayers Boolean
191213
| r )
214+
215+

0 commit comments

Comments
 (0)