@colisweb/rescript-toolkit 2.48.2 → 2.50.1

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/v13.18.1/templates/colisweb.yml"
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.48.2",
3
+ "version": "2.50.1",
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": "9.1.4",
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
+ }
@@ -131,12 +131,12 @@ module Make = (Config: Config) => {
131
131
  }
132
132
 
133
133
  module Provider = {
134
- let makeProps = (~value, ~children, ()) =>
135
- {
136
- "value": Some(value),
137
- "children": children,
138
- }
139
- let make = React.Context.provider(formContext)
134
+ let provider = React.Context.provider(formContext)
135
+
136
+ @react.component
137
+ let make = (~value: api, ~children) => {
138
+ React.createElement(provider, {"value": Some(value), "children": children})
139
+ }
140
140
  }
141
141
 
142
142
  module Field = {
@@ -203,7 +203,7 @@ module Make = (Config: Config) => {
203
203
  None
204
204
  },
205
205
  )
206
- | SetFieldsState(fieldsState) => Update({...state, fieldsState: fieldsState})
206
+ | SetFieldsState(fieldsState) => Update({...state, fieldsState})
207
207
  | ValidateField(field) =>
208
208
  SideEffects(
209
209
  self => {
@@ -320,7 +320,7 @@ module Make = (Config: Config) => {
320
320
  values: initialState,
321
321
  formState: Pristine,
322
322
  })
323
- | SetValues(values) => Update({...state, values: values})
323
+ | SetValues(values) => Update({...state, values})
324
324
  | SetFieldValue(field, value) =>
325
325
  Update({...state, values: Config.set(state.values, field, value)})
326
326
  | RaiseSubmitFailed(err) => Update({...state, formState: SubmitFailed(err)})
@@ -405,14 +405,14 @@ module Make = (Config: Config) => {
405
405
  let raiseSubmitFailed = error => send(RaiseSubmitFailed(error))
406
406
 
407
407
  let interface: api = {
408
- state: state,
408
+ state,
409
409
  submit: () => send(TrySubmit),
410
410
  resetForm: () => send(ResetForm),
411
411
  setValues: values => send(SetValues(values)),
412
412
  setFieldValue: (field, value, ~shouldValidate=true, ()) =>
413
413
  shouldValidate ? send(FieldChangeValue(field, value)) : send(SetFieldValue(field, value)),
414
- getFieldState: getFieldState,
415
- getFieldError: getFieldError,
414
+ getFieldState,
415
+ getFieldError,
416
416
  handleChange: (field, value) => send(FieldChangeValue(field, value)),
417
417
  arrayPush: (field, value) => send(FieldArrayAdd(field, value)),
418
418
  arrayUpdateByIndex: (~field, ~index, value) =>
@@ -421,8 +421,8 @@ module Make = (Config: Config) => {
421
421
  arrayRemoveByIndex: (field, index) => send(FieldArrayRemove(field, index)),
422
422
  validateField: field => send(ValidateField(field)),
423
423
  validateForm: () => send(ValidateForm(false)),
424
- validateFields: validateFields,
425
- raiseSubmitFailed: raiseSubmitFailed,
424
+ validateFields,
425
+ raiseSubmitFailed,
426
426
  isSubmitting: state.formState == Submitting,
427
427
  isErrored: state.formState == Errored,
428
428
  isDirty: state.formState == Dirty,
@@ -1,6 +1,6 @@
1
1
  let transformUrl = text =>
2
- text |> Js.String.unsafeReplaceBy0(%re("/(https?:\\/\\/[^\\s]+)/g"), (url, _, _) =>
3
- j`<a target='_blank' class='text-info-500 underline' href="$url">$url</a>`
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
+ }