@colisweb/rescript-toolkit 2.49.0 → 2.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "2.49.0",
3
+ "version": "2.50.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -415,3 +415,26 @@ module SortOrder = Enum({
415
415
  @deriving(jsConverter)
416
416
  type enum = [#asc | #desc]
417
417
  })
418
+
419
+ module Coordinates = {
420
+ @decco
421
+ type t = {
422
+ latitude: float,
423
+ longitude: float,
424
+ }
425
+ let make = (~lat: float, ~lng: float): t => {latitude: lat, longitude: lng}
426
+ let areEquals = (a: t, b: t): bool => a.latitude === b.latitude && a.longitude === b.longitude
427
+ let fromJs = value => {
428
+ latitude: (value->Obj.magic)["lat"](),
429
+ longitude: (value->Obj.magic)["lng"](),
430
+ }
431
+ type gmaps = {
432
+ lat: float,
433
+ lng: float,
434
+ }
435
+ let toGmaps = (t: t): gmaps => {lat: t.latitude, lng: t.longitude}
436
+ let fromGmaps = (gmaps: gmaps) => {
437
+ latitude: gmaps.lat,
438
+ longitude: gmaps.lng,
439
+ }
440
+ }
@@ -0,0 +1,180 @@
1
+ // See https://react-google-maps-api-docs.netlify.com/
2
+ type gmapInstance
3
+
4
+ module LatLngBounds = {
5
+ type t
6
+ type paddingClass = {
7
+ left: int,
8
+ right: int,
9
+ top: int,
10
+ bottom: int,
11
+ }
12
+
13
+ @new external makeBounds: unit => t = "google.maps.LatLngBounds"
14
+
15
+ @send external extend: (t, Toolkit__Decoders.Coordinates.gmaps) => unit = "extend"
16
+
17
+ @send
18
+ external fitBounds: (gmapInstance, t, paddingClass) => unit = "fitBounds"
19
+ }
20
+
21
+ module LoadScript = {
22
+ type t
23
+
24
+ @obj
25
+ external options: (~googleMapsApiKey: string, ~libraries: array<string>=?) => t = ""
26
+
27
+ let commonOptions = options(~libraries=["places"])
28
+
29
+ type useLoadScriptReturn = {
30
+ isLoaded: bool,
31
+ loadError: bool,
32
+ }
33
+
34
+ @module("@react-google-maps/api")
35
+ external useLoadScript: t => useLoadScriptReturn = "useLoadScript"
36
+ }
37
+
38
+ module GoogleMap = {
39
+ type options
40
+ @obj
41
+ external makeOptions: (
42
+ ~backgroundColor: string=?,
43
+ ~disableDefaultUI: bool=?,
44
+ ~keyboardShortcuts: bool=?,
45
+ ~mapTypeControl: bool=?,
46
+ unit,
47
+ ) => options = ""
48
+
49
+ @module("@react-google-maps/api") @react.component
50
+ external make: (
51
+ ~id: string=?,
52
+ ~center: Toolkit__Decoders.Coordinates.gmaps=?,
53
+ ~zoom: int=?,
54
+ ~mapContainerClassName: string=?,
55
+ ~mapContainerStyle: ReactDOMStyle.t=?,
56
+ ~clickableIcons: bool=?,
57
+ ~options: options=?,
58
+ ~onLoad: gmapInstance => unit=?,
59
+ ~onTilesLoaded: unit => unit=?,
60
+ ~children: React.element=?,
61
+ ) => React.element = "GoogleMap"
62
+ }
63
+
64
+ module Marker = {
65
+ @module("@react-google-maps/api") @react.component
66
+ external make: (
67
+ ~position: Toolkit__Decoders.Coordinates.gmaps=?,
68
+ ~clickable: bool=?,
69
+ ~draggable: bool=?,
70
+ ~icon: string=?,
71
+ ~label: string=?,
72
+ ~options: string=?,
73
+ ~children: React.element=?,
74
+ ) => React.element = "Marker"
75
+ }
76
+
77
+ module InfoWindow = {
78
+ type options
79
+ @obj external options: (~pixelOffset: int=?) => options = ""
80
+
81
+ @module("@react-google-maps/api") @react.component
82
+ external make: (
83
+ ~position: Toolkit__Decoders.Coordinates.gmaps=?,
84
+ ~children: React.element=?,
85
+ ~options: options=?,
86
+ ) => React.element = "InfoWindow"
87
+ }
88
+
89
+ module Waypoint = {
90
+ type t = {
91
+ location: Toolkit__Decoders.Coordinates.gmaps,
92
+ stopover: bool,
93
+ }
94
+ let make = (~lat: float, ~lng: float, ~stopover=true, ()): t => {
95
+ location: Toolkit__Decoders.Coordinates.make(~lat, ~lng)->Toolkit__Decoders.Coordinates.toGmaps,
96
+ stopover,
97
+ }
98
+ let areEquals = (a: t, b: t): bool =>
99
+ a.location.lat === b.location.lat && a.location.lng === b.location.lng
100
+ }
101
+
102
+ module DirectionsService = {
103
+ module Options = {
104
+ type t
105
+
106
+ type travelMode = [#DRIVING | #BICYCLING | #TRANSIT | #WALKING]
107
+
108
+ @obj
109
+ external make: (
110
+ ~destination: Toolkit__Decoders.Coordinates.gmaps,
111
+ ~origin: Toolkit__Decoders.Coordinates.gmaps,
112
+ ~travelMode: travelMode,
113
+ ~waypoints: array<Waypoint.t>=?,
114
+ unit,
115
+ ) => t = ""
116
+ }
117
+
118
+ module Response = {
119
+ type t
120
+
121
+ @get external status: t => string = "status"
122
+
123
+ @get @scope(("request", "origin"))
124
+ external _origin: t => 'dest = "location"
125
+ let origin = (r: t): Toolkit__Decoders.Coordinates.gmaps => {
126
+ lat: (r->_origin)["lat"](),
127
+ lng: (r->_origin)["lng"](),
128
+ }
129
+
130
+ @get @scope(("request", "destination"))
131
+ external _destination: t => 'dest = "location"
132
+ let destination = (r: t): Toolkit__Decoders.Coordinates.gmaps => {
133
+ lat: (r->_destination)["lat"](),
134
+ lng: (r->_destination)["lng"](),
135
+ }
136
+
137
+ type rec routes = array<route>
138
+ and route = {legs: array<leg>}
139
+ and leg = {distance: distance}
140
+ and distance = {value: float}
141
+ @get external _routes: t => routes = "routes"
142
+ let route0totalDistance = (r: t) =>
143
+ r
144
+ ->_routes
145
+ ->Array.get(0)
146
+ ->Option.flatMap(route =>
147
+ route.legs
148
+ ->Array.reduce(None, (red, leg) =>
149
+ red->Option.mapWithDefault(
150
+ Some(leg.distance.value),
151
+ red => Some(red +. leg.distance.value),
152
+ )
153
+ )
154
+ ->Option.map(totalDist => #m(totalDist))
155
+ )
156
+ }
157
+
158
+ @module("@react-google-maps/api") @react.component
159
+ external make: (
160
+ ~options: Options.t=?,
161
+ ~callback: Js.Nullable.t<Response.t> => unit,
162
+ ) => React.element = "DirectionsService"
163
+ }
164
+
165
+ module DirectionsRenderer = {
166
+ module Options = {
167
+ type t
168
+
169
+ @obj
170
+ external make: (
171
+ ~directions: DirectionsService.Response.t,
172
+ ~suppressMarkers: bool=?,
173
+ ~preserveViewport: bool=?,
174
+ unit,
175
+ ) => t = ""
176
+ }
177
+
178
+ @module("@react-google-maps/api") @react.component
179
+ external make: (~options: Options.t) => React.element = "DirectionsRenderer"
180
+ }