@colisweb/rescript-toolkit 4.29.3 → 5.0.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 +25 -23
- package/{bsconfig.json → rescript.json} +10 -5
- package/src/decoders/Decoders__UnitMeasure.res +251 -0
- package/src/decoders/Toolkit__Decoders.res +118 -412
- package/src/decoders/index.md +5 -5
- package/src/form/Reform.res +18 -18
- package/src/form/Toolkit__Form.res +53 -50
- package/src/hooks/Toolkit__Hooks.res +40 -42
- package/src/hooks/index.md +2 -2
- package/src/identifier/Toolkit__Identifier.res +27 -70
- package/src/identifier/index.md +3 -3
- package/src/intl/Toolkit__Intl.res +1 -1
- package/src/mock/MockOverlay.res +1 -1
- package/src/request/index.md +11 -11
- package/src/router/Toolkit__Router.res +11 -11
- package/src/ui/Toolkit__Ui_Autocomplete.res +2 -2
- package/src/ui/Toolkit__Ui_Button.res +1 -1
- package/src/ui/Toolkit__Ui_ButtonGroup2.res +1 -1
- package/src/ui/Toolkit__Ui_Checkbox.res +1 -1
- package/src/ui/Toolkit__Ui_Coordinates.res +4 -4
- package/src/ui/Toolkit__Ui_DatetimeInput.res +3 -4
- package/src/ui/Toolkit__Ui_Dropdown.res +1 -1
- package/src/ui/Toolkit__Ui_DropdownList.res +1 -1
- package/src/ui/Toolkit__Ui_IconButton.res +5 -5
- package/src/ui/Toolkit__Ui_Layout.res +6 -6
- package/src/ui/Toolkit__Ui_Listbox.res +17 -21
- package/src/ui/Toolkit__Ui_MultiSelect.res +1 -1
- package/src/ui/Toolkit__Ui_MultiSelectWithValidation.res +1 -1
- package/src/ui/Toolkit__Ui_Notice.res +37 -26
- package/src/ui/Toolkit__Ui_Portal.res +1 -1
- package/src/ui/Toolkit__Ui_PortalDropdown.res +8 -6
- package/src/ui/Toolkit__Ui_RadioGroup.res +1 -1
- package/src/ui/Toolkit__Ui_SearchListbox.res +4 -5
- package/src/ui/Toolkit__Ui_SelectWithValidation.res +1 -1
- package/src/ui/Toolkit__Ui_Snackbar.res +2 -2
- package/src/ui/Toolkit__Ui_Switch.res +1 -1
- package/src/ui/Toolkit__Ui_TextInput.res +3 -4
- package/src/ui/Toolkit__Ui_TextareaInput.res +2 -23
- package/src/ui/Toolkit__Ui_Tooltip.res +1 -1
- package/src/ui/Toolkit__Ui_WeekDateFilter.res +1 -1
- package/src/unleash/Toolkit__Unleash.res +6 -6
- package/src/unleash/index.md +1 -1
- package/src/utils/Toolkit__Utils.res +20 -0
- package/src/utils/Toolkit__Utils_UnitMeasure.res +72 -110
- package/src/vendors/Axios.res +2 -2
- package/src/vendors/DatadogRum.res +3 -3
- package/src/vendors/ReactDayPicker.res +4 -4
- package/src/vendors/ReactUse.res +1 -1
- package/src/vendors/Zendesk.res +1 -1
|
@@ -1,46 +1,18 @@
|
|
|
1
|
-
module type UnitConfig = {
|
|
2
|
-
type unitEnum
|
|
3
|
-
let unitEnumToJs: unitEnum => string
|
|
4
|
-
let unitEnumFromJs: string => option<unitEnum>
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module Unit = (Config: UnitConfig) => {
|
|
8
|
-
%%private(
|
|
9
|
-
let encoder = value => value->Config.unitEnumToJs->Decco.stringToJson
|
|
10
|
-
|
|
11
|
-
let decoder = json =>
|
|
12
|
-
switch Decco.stringFromJson(json) {
|
|
13
|
-
| Ok(value) =>
|
|
14
|
-
switch Config.unitEnumFromJs(value) {
|
|
15
|
-
| None => Decco.error(~path="", "Invalid unitEnum " ++ value, json)
|
|
16
|
-
| Some(value) => Ok(value)
|
|
17
|
-
}
|
|
18
|
-
| Error(_) as error => error
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let codec = (encoder, decoder)
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
@decco
|
|
25
|
-
type unitEnum = @decco.codec(codec) Config.unitEnum
|
|
26
|
-
|
|
27
|
-
let unitEnumToString = Config.unitEnumToJs
|
|
28
|
-
let unitEnumFromString = Config.unitEnumFromJs
|
|
29
|
-
}
|
|
30
|
-
|
|
31
1
|
module Weight = {
|
|
32
|
-
|
|
33
|
-
@
|
|
34
|
-
type
|
|
35
|
-
|
|
2
|
+
module Unit = {
|
|
3
|
+
@spice
|
|
4
|
+
type t =
|
|
5
|
+
| @spice.as("g") Gram
|
|
6
|
+
| @spice.as("kg") Kg
|
|
7
|
+
}
|
|
36
8
|
|
|
37
|
-
@
|
|
9
|
+
@spice
|
|
38
10
|
type t = [#g(float) | #kg(float)]
|
|
39
11
|
|
|
40
|
-
let wrapValue = (unit, value) => {
|
|
12
|
+
let wrapValue = (unit: Unit.t, value) => {
|
|
41
13
|
switch unit {
|
|
42
|
-
|
|
|
43
|
-
|
|
|
14
|
+
| Gram => #g(value)
|
|
15
|
+
| Kg => #kg(value)
|
|
44
16
|
}
|
|
45
17
|
}
|
|
46
18
|
|
|
@@ -66,18 +38,21 @@ module Weight = {
|
|
|
66
38
|
}
|
|
67
39
|
|
|
68
40
|
module Time = {
|
|
69
|
-
|
|
70
|
-
@
|
|
71
|
-
type
|
|
72
|
-
|
|
41
|
+
module Unit = {
|
|
42
|
+
@spice
|
|
43
|
+
type t =
|
|
44
|
+
| @spice.as("min") Min
|
|
45
|
+
| @spice.as("h") Hour
|
|
46
|
+
| @spice.as("s") Second
|
|
47
|
+
}
|
|
73
48
|
|
|
74
49
|
type t = [#min(float) | #h(float) | #s(float)]
|
|
75
50
|
|
|
76
|
-
let wrapValue = (unit, value) => {
|
|
51
|
+
let wrapValue = (unit: Unit.t, value) => {
|
|
77
52
|
switch unit {
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
53
|
+
| Min => #min(value)
|
|
54
|
+
| Hour => #h(value)
|
|
55
|
+
| Second => #s(value)
|
|
81
56
|
}
|
|
82
57
|
}
|
|
83
58
|
|
|
@@ -144,16 +119,15 @@ module Time = {
|
|
|
144
119
|
}
|
|
145
120
|
|
|
146
121
|
module Dimension = {
|
|
147
|
-
|
|
148
|
-
@
|
|
149
|
-
type
|
|
150
|
-
|
|
|
151
|
-
|
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
155
|
-
|
|
156
|
-
})
|
|
122
|
+
module Unit = {
|
|
123
|
+
@spice
|
|
124
|
+
type t =
|
|
125
|
+
| @spice.as("mm") Mm
|
|
126
|
+
| @spice.as("cm") Cm
|
|
127
|
+
| @spice.as("dm") Dm
|
|
128
|
+
| @spice.as("m") M
|
|
129
|
+
| @spice.as("km") Km
|
|
130
|
+
}
|
|
157
131
|
|
|
158
132
|
type t = [
|
|
159
133
|
| #mm(float)
|
|
@@ -163,13 +137,13 @@ module Dimension = {
|
|
|
163
137
|
| #km(float)
|
|
164
138
|
]
|
|
165
139
|
|
|
166
|
-
let wrapValue = (unit:
|
|
140
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
167
141
|
switch unit {
|
|
168
|
-
|
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
142
|
+
| Mm => #mm(value)
|
|
143
|
+
| Cm => #cm(value)
|
|
144
|
+
| Dm => #dm(value)
|
|
145
|
+
| M => #m(value)
|
|
146
|
+
| Km => #km(value)
|
|
173
147
|
}
|
|
174
148
|
|
|
175
149
|
let toValue = value =>
|
|
@@ -204,20 +178,18 @@ module Dimension = {
|
|
|
204
178
|
}
|
|
205
179
|
|
|
206
180
|
module Speed = {
|
|
207
|
-
|
|
208
|
-
@
|
|
209
|
-
type
|
|
210
|
-
|
|
211
|
-
]
|
|
212
|
-
})
|
|
181
|
+
module Unit = {
|
|
182
|
+
@spice
|
|
183
|
+
type t = | @spice.as("km/h") Km_h
|
|
184
|
+
}
|
|
213
185
|
|
|
214
186
|
type t = [
|
|
215
187
|
| #km_h(float)
|
|
216
188
|
]
|
|
217
189
|
|
|
218
|
-
let wrapValue = (unit:
|
|
190
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
219
191
|
switch unit {
|
|
220
|
-
|
|
|
192
|
+
| Km_h => #km_h(value)
|
|
221
193
|
}
|
|
222
194
|
|
|
223
195
|
let toValue = value =>
|
|
@@ -240,20 +212,18 @@ module Speed = {
|
|
|
240
212
|
}
|
|
241
213
|
|
|
242
214
|
module Volume = {
|
|
243
|
-
|
|
244
|
-
@
|
|
245
|
-
type
|
|
246
|
-
|
|
247
|
-
]
|
|
248
|
-
})
|
|
215
|
+
module Unit = {
|
|
216
|
+
@spice
|
|
217
|
+
type t = | @spice.as("m³") M3
|
|
218
|
+
}
|
|
249
219
|
|
|
250
220
|
type t = [
|
|
251
221
|
| #m3(float)
|
|
252
222
|
]
|
|
253
223
|
|
|
254
|
-
let wrapValue = (unit:
|
|
224
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
255
225
|
switch unit {
|
|
256
|
-
|
|
|
226
|
+
| M3 => #m3(value)
|
|
257
227
|
}
|
|
258
228
|
|
|
259
229
|
let toValue = value =>
|
|
@@ -276,20 +246,18 @@ module Volume = {
|
|
|
276
246
|
}
|
|
277
247
|
|
|
278
248
|
module EnergyCapacity = {
|
|
279
|
-
|
|
280
|
-
@
|
|
281
|
-
type
|
|
282
|
-
|
|
283
|
-
]
|
|
284
|
-
})
|
|
249
|
+
module Unit = {
|
|
250
|
+
@spice
|
|
251
|
+
type t = | @spice.as("kWh") Kwh
|
|
252
|
+
}
|
|
285
253
|
|
|
286
254
|
type t = [
|
|
287
255
|
| #kWh(float)
|
|
288
256
|
]
|
|
289
257
|
|
|
290
|
-
let wrapValue = (unit:
|
|
258
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
291
259
|
switch unit {
|
|
292
|
-
|
|
|
260
|
+
| Kwh => #kWh(value)
|
|
293
261
|
}
|
|
294
262
|
|
|
295
263
|
let toValue = value =>
|
|
@@ -312,20 +280,18 @@ module EnergyCapacity = {
|
|
|
312
280
|
}
|
|
313
281
|
|
|
314
282
|
module Currency = {
|
|
315
|
-
|
|
316
|
-
@
|
|
317
|
-
type
|
|
318
|
-
|
|
319
|
-
]
|
|
320
|
-
})
|
|
283
|
+
module Unit = {
|
|
284
|
+
@spice
|
|
285
|
+
type t = | @spice.as("EUR") EUR
|
|
286
|
+
}
|
|
321
287
|
|
|
322
288
|
type t = [
|
|
323
289
|
| #EUR(float)
|
|
324
290
|
]
|
|
325
291
|
|
|
326
|
-
let wrapValue = (unit:
|
|
292
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
327
293
|
switch unit {
|
|
328
|
-
|
|
|
294
|
+
| EUR => #EUR(value)
|
|
329
295
|
}
|
|
330
296
|
|
|
331
297
|
let toValue = value =>
|
|
@@ -348,20 +314,18 @@ module Currency = {
|
|
|
348
314
|
|
|
349
315
|
module CompositeUnits = {
|
|
350
316
|
module CurrencyPerDistance = {
|
|
351
|
-
|
|
352
|
-
@
|
|
353
|
-
type
|
|
354
|
-
|
|
355
|
-
]
|
|
356
|
-
})
|
|
317
|
+
module Unit = {
|
|
318
|
+
@spice
|
|
319
|
+
type t = | @spice.as("EUR/km") EUR_km
|
|
320
|
+
}
|
|
357
321
|
|
|
358
322
|
type t = [
|
|
359
323
|
| #EUR_km(float)
|
|
360
324
|
]
|
|
361
325
|
|
|
362
|
-
let wrapValue = (unit:
|
|
326
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
363
327
|
switch unit {
|
|
364
|
-
|
|
|
328
|
+
| EUR_km => #EUR_km(value)
|
|
365
329
|
}
|
|
366
330
|
|
|
367
331
|
let toValue = value =>
|
|
@@ -383,20 +347,18 @@ module CompositeUnits = {
|
|
|
383
347
|
}
|
|
384
348
|
|
|
385
349
|
module CurrencyPerTime = {
|
|
386
|
-
|
|
387
|
-
@
|
|
388
|
-
type
|
|
389
|
-
|
|
390
|
-
]
|
|
391
|
-
})
|
|
350
|
+
module Unit = {
|
|
351
|
+
@spice
|
|
352
|
+
type t = | @spice.as("EUR/h") EUR_h
|
|
353
|
+
}
|
|
392
354
|
|
|
393
355
|
type t = [
|
|
394
356
|
| #EUR_h(float)
|
|
395
357
|
]
|
|
396
358
|
|
|
397
|
-
let wrapValue = (unit:
|
|
359
|
+
let wrapValue = (unit: Unit.t, value: float): t =>
|
|
398
360
|
switch unit {
|
|
399
|
-
|
|
|
361
|
+
| EUR_h => #EUR_h(value)
|
|
400
362
|
}
|
|
401
363
|
|
|
402
364
|
let toValue = value =>
|
package/src/vendors/Axios.res
CHANGED
|
@@ -178,11 +178,11 @@ module Interceptors = {
|
|
|
178
178
|
module WithResult = {
|
|
179
179
|
type customError<'apiError, 'response> = [
|
|
180
180
|
| #default(error<'response>)
|
|
181
|
-
| #decodeError(config,
|
|
181
|
+
| #decodeError(config, Spice.decodeError)
|
|
182
182
|
| #custom('apiError)
|
|
183
183
|
]
|
|
184
184
|
|
|
185
|
-
type decodeData<'newData> = Js.Json.t => result<'newData,
|
|
185
|
+
type decodeData<'newData> = Js.Json.t => result<'newData, Spice.decodeError>
|
|
186
186
|
|
|
187
187
|
type mapError<'a, 'response, 'headers, 'request> = error<'response> => customError<'a, 'response>
|
|
188
188
|
|
|
@@ -41,7 +41,7 @@ module Browser = {
|
|
|
41
41
|
external addErrorWithContext: (Js.Exn.t, 'context) => unit = "addError"
|
|
42
42
|
|
|
43
43
|
let use = (~options: initOptions, ~sessionData, ~contextCallback=?, ()) => {
|
|
44
|
-
React.
|
|
44
|
+
React.useLayoutEffect(() => {
|
|
45
45
|
if options.env !== "local" {
|
|
46
46
|
datadogRumInit({
|
|
47
47
|
...options,
|
|
@@ -61,9 +61,9 @@ module Browser = {
|
|
|
61
61
|
startSessionReplayRecording()
|
|
62
62
|
}
|
|
63
63
|
None
|
|
64
|
-
})
|
|
64
|
+
}, [])
|
|
65
65
|
|
|
66
|
-
React.
|
|
66
|
+
React.useLayoutEffect(() => {
|
|
67
67
|
if options.env !== "local" {
|
|
68
68
|
setUser(sessionData)
|
|
69
69
|
|
|
@@ -232,7 +232,7 @@ module SingleDayPickerInput = {
|
|
|
232
232
|
let (validatedValue, setValidatedValue) = React.useState(() => value)
|
|
233
233
|
let (localValue, setLocalValue) = React.useState(() => validatedValue)
|
|
234
234
|
|
|
235
|
-
React.
|
|
235
|
+
React.useEffect(() => {
|
|
236
236
|
setLocalValue(_ => value)
|
|
237
237
|
setValidatedValue(_ => value)
|
|
238
238
|
None
|
|
@@ -253,7 +253,7 @@ module SingleDayPickerInput = {
|
|
|
253
253
|
)}
|
|
254
254
|
</p>}>
|
|
255
255
|
{disclosure => {
|
|
256
|
-
|
|
256
|
+
<React.Fragment>
|
|
257
257
|
<SingleDayPicker
|
|
258
258
|
?modifiers
|
|
259
259
|
?modifiersClassNames
|
|
@@ -292,7 +292,7 @@ module SingleDayPickerInput = {
|
|
|
292
292
|
<ReactIntl.FormattedMessage defaultMessage="Valider" />
|
|
293
293
|
</Toolkit__Ui_Button>
|
|
294
294
|
</div>
|
|
295
|
-
|
|
295
|
+
</React.Fragment>
|
|
296
296
|
}}
|
|
297
297
|
</Toolkit__Ui_PortalDropdown>
|
|
298
298
|
}
|
|
@@ -419,7 +419,7 @@ module RangeDayPickerInput = {
|
|
|
419
419
|
},
|
|
420
420
|
)
|
|
421
421
|
|
|
422
|
-
React.
|
|
422
|
+
React.useEffect(() => {
|
|
423
423
|
dispatch(UpdateRange(value))
|
|
424
424
|
None
|
|
425
425
|
}, [value])
|
package/src/vendors/ReactUse.res
CHANGED
|
@@ -26,7 +26,7 @@ external useTimeoutFn: (unit => unit, int) => (Js.Nullable.t<bool>, unit => unit
|
|
|
26
26
|
external useFirstMountState: unit => bool = "useFirstMountState"
|
|
27
27
|
|
|
28
28
|
@module("react-use")
|
|
29
|
-
external useMountedState:
|
|
29
|
+
external useMountedState: unit => unit => bool = "useMountedState"
|
|
30
30
|
|
|
31
31
|
@module("react-use")
|
|
32
32
|
external useUpdateEffect: (unit => option<unit => unit>, array<'a>) => unit = "useUpdateEffect"
|
package/src/vendors/Zendesk.res
CHANGED