@colisweb/rescript-toolkit 2.48.1 → 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/.gitlab-ci.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
include:
|
|
2
|
-
- "https://colisweb-idl.gitlab.io/colisweb-open-source/ci-common/
|
|
2
|
+
- "https://colisweb-idl.gitlab.io/colisweb-open-source/ci-common/v14.3.2/templates/colisweb.yml"
|
|
3
3
|
|
|
4
4
|
# -----------------------------------------------
|
|
5
5
|
# Test
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.50.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rescript clean",
|
|
6
6
|
"build": "rescript build -with-deps",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"reason-promise": "1.1.5",
|
|
75
75
|
"res-react-intl": "3.1.2",
|
|
76
76
|
"reschema": "1.3.1",
|
|
77
|
-
"rescript": "
|
|
77
|
+
"rescript": "10.0.0",
|
|
78
78
|
"rescript-classnames": "6.0.0",
|
|
79
79
|
"rescript-react-update": "5.0.0",
|
|
80
80
|
"sanitize-html": "1.27.4",
|
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
let ignoredTerms = ["timeout", "network"]
|
|
2
|
+
|
|
1
3
|
@react.component
|
|
2
4
|
let make = (
|
|
3
5
|
~fallbackRender: ReactErrorBoundary.fallbackProps => React.element,
|
|
@@ -21,7 +23,6 @@ let make = (
|
|
|
21
23
|
| #default(axiosError) =>
|
|
22
24
|
Js.Exn.message(axiosError)->Option.forEach(message => {
|
|
23
25
|
let message = message->Js.String2.toLowerCase
|
|
24
|
-
let ignoredTerms = ["timeout", "network"]
|
|
25
26
|
|
|
26
27
|
if ignoredTerms->Array.some(Js.String2.includes(message)) {
|
|
27
28
|
()
|
|
@@ -36,7 +37,12 @@ let make = (
|
|
|
36
37
|
| err =>
|
|
37
38
|
switch Js.Exn.message(Obj.magic(err)) {
|
|
38
39
|
| None => Toolkit__BrowserLogger.error2("Unhandled error", err)
|
|
39
|
-
| Some(message) =>
|
|
40
|
+
| Some(message) =>
|
|
41
|
+
if ignoredTerms->Array.some(Js.String2.includes(message->Js.String2.toLowerCase)) {
|
|
42
|
+
()
|
|
43
|
+
} else {
|
|
44
|
+
Toolkit__BrowserLogger.error2(Obj.magic(message), err)
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
}}>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let transformUrl = text =>
|
|
2
|
-
text
|
|
3
|
-
|
|
2
|
+
text->Js.String2.unsafeReplaceBy0(%re("/(https?:\/\/[^\s]+)/g"), (url, _, _) =>
|
|
3
|
+
`<a target='_blank' class='text-info-500 underline' href="${url}">${url}</a>`
|
|
4
4
|
)
|
|
5
5
|
|
|
6
6
|
@module("sanitize-html")
|
|
@@ -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
|
+
}
|