@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
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rescript clean",
|
|
7
|
-
"dev:res": "node_modules/.bin/rescript build -
|
|
7
|
+
"dev:res": "node_modules/.bin/rescript build -w",
|
|
8
8
|
"dev": "NINJA_ANSI_FORCED=1 vite",
|
|
9
9
|
"build": "NINJA_ANSI_FORCED=1 vite build",
|
|
10
10
|
"preview": "NINJA_ANSI_FORCED=1 vite preview",
|
|
@@ -28,59 +28,58 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@colisweb/bs-react-intl-extractor-bin": "0.12.2",
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
31
|
+
"@datadog/browser-rum": "5.8.0",
|
|
32
|
+
"@dck/rescript-promise": "1.1.0",
|
|
33
|
+
"@dck/restorative": "1.1.0",
|
|
34
|
+
"@greenlabs/ppx-spice": "0.2.1",
|
|
35
|
+
"@headlessui/react": "1.7.18",
|
|
34
36
|
"@headlessui/tailwindcss": "0.2.0",
|
|
35
37
|
"@reach/auto-id": "0.18.0",
|
|
36
|
-
"@rescript/react": "0.
|
|
37
|
-
"autoprefixer": "10.4.
|
|
38
|
+
"@rescript/react": "0.12.0",
|
|
39
|
+
"autoprefixer": "10.4.17",
|
|
38
40
|
"axios": "0.24.0",
|
|
39
|
-
"bs-axios": "0.0.43",
|
|
40
41
|
"case": "1.6.3",
|
|
41
42
|
"click-outside-hook": "1.1.0",
|
|
42
43
|
"copy-to-clipboard": "3.3.3",
|
|
43
44
|
"date-fns": "3.2.0",
|
|
44
|
-
"decco": "1.6.0",
|
|
45
45
|
"dedent": "0.7.0",
|
|
46
46
|
"lenses-ppx": "6.1.10",
|
|
47
47
|
"list-selectors": "2.0.1",
|
|
48
48
|
"lodash": "4.17.21",
|
|
49
|
-
"msw": "2.
|
|
50
|
-
"postcss": "8.4.
|
|
49
|
+
"msw": "2.1.2",
|
|
50
|
+
"postcss": "8.4.33",
|
|
51
51
|
"postcss-preset-env": "8.0.1",
|
|
52
52
|
"prismjs": "1.29.0",
|
|
53
53
|
"react": "18.2.0",
|
|
54
54
|
"react-big-calendar": "1.5.2",
|
|
55
55
|
"react-datepicker": "3.8.0",
|
|
56
|
-
"react-day-picker": "8.
|
|
56
|
+
"react-day-picker": "8.10.0",
|
|
57
57
|
"react-dom": "18.2.0",
|
|
58
|
-
"react-error-boundary": "4.0.
|
|
58
|
+
"react-error-boundary": "4.0.12",
|
|
59
59
|
"react-helmet": "6.1.0",
|
|
60
|
-
"react-icons": "
|
|
61
|
-
"react-intl": "6.
|
|
60
|
+
"react-icons": "5.0.1",
|
|
61
|
+
"react-intl": "6.6.1",
|
|
62
62
|
"react-portal": "4.2.2",
|
|
63
63
|
"react-select": "5.8.0",
|
|
64
64
|
"react-table": "7.8.0",
|
|
65
|
-
"react-use": "17.4.
|
|
66
|
-
"reason-promise": "1.1.5",
|
|
65
|
+
"react-use": "17.4.3",
|
|
67
66
|
"res-react-intl": "3.1.2",
|
|
68
|
-
"rescript": "
|
|
67
|
+
"rescript": "11.0.0",
|
|
69
68
|
"rescript-classnames": "6.0.0",
|
|
70
69
|
"rescript-react-update": "5.0.2",
|
|
71
70
|
"sanitize-html": "1.27.4",
|
|
72
71
|
"swr": "2.2.2",
|
|
73
|
-
"tailwindcss": "3.
|
|
72
|
+
"tailwindcss": "3.4.1",
|
|
74
73
|
"use-local-storage-state": "19.1.0"
|
|
75
74
|
},
|
|
76
75
|
"devDependencies": {
|
|
77
|
-
"@babel/core": "7.23.
|
|
76
|
+
"@babel/core": "7.23.7",
|
|
78
77
|
"@jihchi/vite-plugin-rescript": "5.5.0",
|
|
79
78
|
"@mdx-js/mdx": "2.3.0",
|
|
80
79
|
"@mdx-js/react": "2.3.0",
|
|
81
80
|
"@mdx-js/rollup": "2.3.0",
|
|
82
81
|
"@originjs/vite-plugin-commonjs": "1.0.3",
|
|
83
|
-
"@vitejs/plugin-react": "4.1
|
|
82
|
+
"@vitejs/plugin-react": "4.2.1",
|
|
84
83
|
"babel-loader": "8.2.5",
|
|
85
84
|
"highlight.js": "11.9.0",
|
|
86
85
|
"husky": "8.0.3",
|
|
@@ -91,11 +90,14 @@
|
|
|
91
90
|
"rehype-autolink-headings": "^6.1.1",
|
|
92
91
|
"rehype-highlight": "^6.0.0",
|
|
93
92
|
"rehype-slug": "^5.1.0",
|
|
94
|
-
"sass": "1.69.
|
|
95
|
-
"vite": "5.0.
|
|
93
|
+
"sass": "1.69.7",
|
|
94
|
+
"vite": "5.0.11"
|
|
96
95
|
},
|
|
97
96
|
"packageManager": "yarn@3.3.1",
|
|
98
97
|
"msw": {
|
|
99
98
|
"workerDirectory": "public"
|
|
99
|
+
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">=18"
|
|
100
102
|
}
|
|
101
103
|
}
|
|
@@ -23,18 +23,23 @@
|
|
|
23
23
|
],
|
|
24
24
|
"suffix": ".bs.js",
|
|
25
25
|
"namespace": false,
|
|
26
|
+
"uncurried": false,
|
|
26
27
|
"bs-dependencies": [
|
|
27
28
|
"@rescript/react",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"@dck/rescript-promise",
|
|
30
|
+
"@greenlabs/ppx-spice",
|
|
30
31
|
"rescript-classnames",
|
|
31
32
|
"rescript-react-update",
|
|
32
|
-
"@
|
|
33
|
+
"@dck/restorative"
|
|
34
|
+
],
|
|
35
|
+
"ppx-flags": [
|
|
36
|
+
["@greenlabs/ppx-spice/ppx"],
|
|
37
|
+
"lenses-ppx/ppx",
|
|
38
|
+
"res-react-intl/ppx"
|
|
33
39
|
],
|
|
34
|
-
"ppx-flags": ["decco/ppx", "lenses-ppx/ppx", "res-react-intl/ppx"],
|
|
35
40
|
"warnings": {
|
|
36
41
|
"number": "-44-30-32",
|
|
37
|
-
"error": "+5"
|
|
42
|
+
"error": "+5+4+6+8"
|
|
38
43
|
},
|
|
39
44
|
"bsc-flags": [
|
|
40
45
|
"-bs-super-errors",
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
module type MakeConfig = {
|
|
2
|
+
type t
|
|
3
|
+
let toString: t => string
|
|
4
|
+
let toValue: t => float
|
|
5
|
+
let display: (t, ~digits: int=?, unit) => string
|
|
6
|
+
|
|
7
|
+
let wrapValue: float => t
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module Make = (C: MakeConfig) => {
|
|
11
|
+
type dimension = C.t
|
|
12
|
+
|
|
13
|
+
let encoder: Spice.encoder<C.t> = value => value->C.toString->Spice.stringToJson
|
|
14
|
+
|
|
15
|
+
let decoder: Spice.decoder<C.t> = json =>
|
|
16
|
+
switch Spice.floatFromJson(json) {
|
|
17
|
+
| Ok(v) => v->C.wrapValue->Ok
|
|
18
|
+
| Error(_) as err => err
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let codec: Spice.codec<dimension> = (encoder, decoder)
|
|
22
|
+
|
|
23
|
+
let toValue = C.toValue
|
|
24
|
+
let display = C.display
|
|
25
|
+
let toString = C.toString
|
|
26
|
+
|
|
27
|
+
@spice
|
|
28
|
+
type t = @spice.codec(codec) C.t
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module type MakeWithUnitConfig = {
|
|
32
|
+
type t
|
|
33
|
+
let toString: t => string
|
|
34
|
+
let toValue: t => float
|
|
35
|
+
let display: (t, ~digits: int=?, unit) => string
|
|
36
|
+
|
|
37
|
+
module Unit: {
|
|
38
|
+
type t
|
|
39
|
+
let t_decode: Js.Json.t => result<t, Spice.decodeError>
|
|
40
|
+
let t_encode: t => Js.Json.t
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let wrapValue: (Unit.t, float) => t
|
|
44
|
+
|
|
45
|
+
let errorPrefix: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module MakeWithUnit = (Config: MakeWithUnitConfig) => {
|
|
49
|
+
let decodeFromString = (string: string) => {
|
|
50
|
+
// match a positive int or float followed by it's unit (capturing int/float in group1 and unit in group2)
|
|
51
|
+
let regexp = %re("/^(\d+(?:\.\d*)?)\s*(\D*)$/")
|
|
52
|
+
|
|
53
|
+
// regexpCaptures: [match , captureGroup1, captureGroup2]
|
|
54
|
+
let regexpCaptures =
|
|
55
|
+
Js.Re.exec_(regexp, string)->Belt.Option.map(r =>
|
|
56
|
+
r->Js.Re.captures->Array.map(Js.Nullable.toOption)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
let jsonString = string->Js.Json.string
|
|
60
|
+
|
|
61
|
+
let errorPrefix = Config.errorPrefix
|
|
62
|
+
|
|
63
|
+
switch regexpCaptures {
|
|
64
|
+
| None => Spice.error(`${errorPrefix} unhandled format`, jsonString)
|
|
65
|
+
| Some([None, _value, _unit]) => Spice.error(`${errorPrefix} unhandled format`, jsonString)
|
|
66
|
+
| Some([_match, _value, None]) => Spice.error(`${errorPrefix} unhandled no unit`, jsonString)
|
|
67
|
+
| Some([_match, None, _unit]) => Spice.error(`${errorPrefix} unhandled no value`, jsonString)
|
|
68
|
+
| Some([Some(_match), Some(value), Some(unit)]) => {
|
|
69
|
+
let value = value->Js.Float.fromString
|
|
70
|
+
switch unit
|
|
71
|
+
// regex captures adjacent to spaces to slashes and deletes them (for composite units)
|
|
72
|
+
->Js.String2.replaceByRe(%re("/ *\/ */"), "/")
|
|
73
|
+
->Js.Json.string
|
|
74
|
+
->Config.Unit.t_decode {
|
|
75
|
+
| Ok(unit) => Config.wrapValue(unit, value)->Ok
|
|
76
|
+
| Error(_) => Spice.error(`${errorPrefix} unhandled unit '${unit}'`, jsonString)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
| Some(_) => Spice.error(`${errorPrefix} regex capture group error`, jsonString)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
%%private(
|
|
85
|
+
let encoder: Spice.encoder<Config.t> = value => value->Config.toString->Spice.stringToJson
|
|
86
|
+
let decoder: Spice.decoder<Config.t> = json =>
|
|
87
|
+
switch Spice.stringFromJson(json) {
|
|
88
|
+
| Ok(v) => v->decodeFromString
|
|
89
|
+
| Error(_) as err => err
|
|
90
|
+
}
|
|
91
|
+
let codec: Spice.codec<Config.t> = (encoder, decoder)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
let toValue = Config.toValue
|
|
95
|
+
let toString = Config.toString
|
|
96
|
+
let display = Config.display
|
|
97
|
+
|
|
98
|
+
@spice
|
|
99
|
+
type t = @spice.codec(codec) Config.t
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module Dimension = {
|
|
103
|
+
module Config = Toolkit__Utils_UnitMeasure.Dimension
|
|
104
|
+
|
|
105
|
+
module WithUnit = MakeWithUnit({
|
|
106
|
+
include Config
|
|
107
|
+
let errorPrefix = "Dimension with unit"
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
module Mm = Make({
|
|
111
|
+
include Config
|
|
112
|
+
let wrapValue = Config.wrapValue(Mm, ...)
|
|
113
|
+
})
|
|
114
|
+
module Cm = Make({
|
|
115
|
+
include Config
|
|
116
|
+
let wrapValue = Config.wrapValue(Cm, ...)
|
|
117
|
+
})
|
|
118
|
+
module Dm = Make({
|
|
119
|
+
include Config
|
|
120
|
+
let wrapValue = Config.wrapValue(Dm, ...)
|
|
121
|
+
})
|
|
122
|
+
module M = Make({
|
|
123
|
+
include Config
|
|
124
|
+
let wrapValue = Config.wrapValue(M, ...)
|
|
125
|
+
})
|
|
126
|
+
module Km = Make({
|
|
127
|
+
include Config
|
|
128
|
+
let wrapValue = Config.wrapValue(Km, ...)
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module Speed = {
|
|
133
|
+
module Config = Toolkit__Utils_UnitMeasure.Speed
|
|
134
|
+
|
|
135
|
+
module WithUnit = MakeWithUnit({
|
|
136
|
+
include Config
|
|
137
|
+
let errorPrefix = "Speed with unit"
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
module Km_h = Make({
|
|
141
|
+
include Config
|
|
142
|
+
let wrapValue = Config.wrapValue(Km_h, ...)
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module Volume = {
|
|
147
|
+
module Config = Toolkit__Utils_UnitMeasure.Volume
|
|
148
|
+
|
|
149
|
+
module WithUnit = MakeWithUnit({
|
|
150
|
+
include Config
|
|
151
|
+
let errorPrefix = "Volume with unit"
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
module M3 = Make({
|
|
155
|
+
include Config
|
|
156
|
+
let wrapValue = Config.wrapValue(M3, ...)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module EnergyCapacity = {
|
|
161
|
+
module Config = Toolkit__Utils_UnitMeasure.EnergyCapacity
|
|
162
|
+
|
|
163
|
+
module WithUnit = MakeWithUnit({
|
|
164
|
+
include Config
|
|
165
|
+
let errorPrefix = "EnergyCapacity with unit"
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
module KWh = Make({
|
|
169
|
+
include Config
|
|
170
|
+
let wrapValue = Config.wrapValue(Kwh, ...)
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module Weight = {
|
|
175
|
+
module Config = Toolkit__Utils_UnitMeasure.Weight
|
|
176
|
+
|
|
177
|
+
module WithUnit = MakeWithUnit({
|
|
178
|
+
include Config
|
|
179
|
+
let errorPrefix = "Weight with unit"
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
module G = Make({
|
|
183
|
+
include Config
|
|
184
|
+
let wrapValue = Config.wrapValue(Gram, ...)
|
|
185
|
+
})
|
|
186
|
+
module Kg = Make({
|
|
187
|
+
include Config
|
|
188
|
+
let wrapValue = Config.wrapValue(Kg, ...)
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module Time = {
|
|
193
|
+
module Config = Toolkit__Utils_UnitMeasure.Time
|
|
194
|
+
|
|
195
|
+
module WithUnit = MakeWithUnit({
|
|
196
|
+
include Config
|
|
197
|
+
let errorPrefix = "Time with unit"
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
module Min = Make({
|
|
201
|
+
include Config
|
|
202
|
+
let wrapValue = Config.wrapValue(Min, ...)
|
|
203
|
+
})
|
|
204
|
+
module H = Make({
|
|
205
|
+
include Config
|
|
206
|
+
let wrapValue = Config.wrapValue(Hour, ...)
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module Currency = {
|
|
211
|
+
module Config = Toolkit__Utils_UnitMeasure.Currency
|
|
212
|
+
|
|
213
|
+
module WithUnit = MakeWithUnit({
|
|
214
|
+
include Config
|
|
215
|
+
let errorPrefix = "Curency with unit"
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
module EUR = Make({
|
|
219
|
+
include Config
|
|
220
|
+
let wrapValue = Config.wrapValue(EUR, ...)
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
module CompositeUnits = {
|
|
225
|
+
module CurrencyPerDistance = {
|
|
226
|
+
module Config = Toolkit__Utils_UnitMeasure.CompositeUnits.CurrencyPerDistance
|
|
227
|
+
|
|
228
|
+
module WithUnit = MakeWithUnit({
|
|
229
|
+
include Config
|
|
230
|
+
let errorPrefix = "Curency per distance with unit"
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
module EUR_km = Make({
|
|
234
|
+
include Config
|
|
235
|
+
let wrapValue = Config.wrapValue(EUR_km, ...)
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
module CurrencyPerTime = {
|
|
239
|
+
module Config = Toolkit__Utils_UnitMeasure.CompositeUnits.CurrencyPerTime
|
|
240
|
+
|
|
241
|
+
module WithUnit = MakeWithUnit({
|
|
242
|
+
include Config
|
|
243
|
+
let errorPrefix = "Curency per time with unit"
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
module EUR_h = Make({
|
|
247
|
+
include Config
|
|
248
|
+
let wrapValue = Config.wrapValue(EUR_h, ...)
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
}
|