@colisweb/rescript-toolkit 2.51.1 → 2.52.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.51.1",
3
+ "version": "2.52.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -66,24 +66,21 @@ let make = (
66
66
  let {left, top, width, height} =
67
67
  buttonRef->Browser.DomElement.getBoundingClientRect
68
68
  let dropdown = ref->Browser.DomElement.getBoundingClientRect
69
-
70
69
  let left = left +. width /. 2. -. dropdown.width /. 2.
71
70
 
72
- let left = switch left {
73
- | left if left < 0. => "0px"
71
+ let adjustmentStyle = ReactDOM.Style.make(
72
+ ~top=`${(top +. height)->Js.Float.toString}px`,
73
+ ~opacity="1",
74
+ )
75
+
76
+ let adjustmentStyle = switch left {
77
+ | left if left < 0. => adjustmentStyle(~left="8px", ())
74
78
  | left if left +. dropdown.width > Browser.innerWidth->Int.toFloat =>
75
- `${(Browser.innerWidth->Int.toFloat -. dropdown.width)->Js.Float.toString}px`
76
- | left => `${left->Js.Float.toString}px`
79
+ adjustmentStyle(~right="8px", ())
80
+ | left => adjustmentStyle(~left=`${left->Js.Float.toString}px`, ())
77
81
  }
78
82
 
79
- setAdjustmentStyle(_ => Some(
80
- ReactDOM.Style.make(
81
- ~left,
82
- ~top=`${(top +. height)->Js.Float.toString}px`,
83
- ~opacity="1",
84
- (),
85
- ),
86
- ))
83
+ setAdjustmentStyle(_ => Some(adjustmentStyle))
87
84
  }
88
85
 
89
86
  | _ => ()
@@ -97,6 +97,70 @@ external delete: (string, ~config: config=?, unit) => Promise.Js.t<response<'dat
97
97
  external options: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
98
98
  "options"
99
99
 
100
+ module Instance = {
101
+ type t
102
+
103
+ @module("axios")
104
+ external create: config => t = "create"
105
+
106
+ @send
107
+ external get: (t, string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> = "get"
108
+
109
+ @send
110
+ external post: (
111
+ t,
112
+ string,
113
+ ~data: 'a,
114
+ ~config: config=?,
115
+ unit,
116
+ ) => Promise.Js.t<response<'data>, 'err> = "post"
117
+
118
+ @send
119
+ external put: (
120
+ t,
121
+ string,
122
+ ~data: 'a,
123
+ ~config: config=?,
124
+ unit,
125
+ ) => Promise.Js.t<response<'data>, 'err> = "put"
126
+
127
+ @send
128
+ external patch: (
129
+ t,
130
+ string,
131
+ ~data: 'a,
132
+ ~config: config=?,
133
+ unit,
134
+ ) => Promise.Js.t<response<'data>, 'err> = "patch"
135
+
136
+ @send
137
+ external delete: (t, string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
138
+ "delete"
139
+
140
+ @send
141
+ external options: (t, string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
142
+ "options"
143
+
144
+ module Interceptors = {
145
+ type interceptor
146
+ module Request = {
147
+ @send @scope(("interceptors", "request"))
148
+ external use: (t, 'config => Promise.Js.t<'updatedConfig, 'error>) => interceptor = "use"
149
+
150
+ @send @scope(("interceptors", "request"))
151
+ external eject: (t, interceptor) => unit = "eject"
152
+ }
153
+
154
+ module Response = {
155
+ @send @scope(("interceptors", "response"))
156
+ external use: (t, 'res => 'res, error<'z> => 'a) => unit = "use"
157
+
158
+ @send @scope(("interceptors", "response"))
159
+ external eject: (t, interceptor) => unit = "eject"
160
+ }
161
+ }
162
+ }
163
+
100
164
  module Interceptors = {
101
165
  type t
102
166
  module Request = {
@@ -106,6 +170,14 @@ module Interceptors = {
106
170
  @module("axios") @scope(("default", "interceptors", "request"))
107
171
  external eject: t => unit = "eject"
108
172
  }
173
+
174
+ module Response = {
175
+ @module("axios") @scope(("default", "interceptors", "response"))
176
+ external use: ('res => 'res, error<'z> => 'a) => unit = "use"
177
+
178
+ @module("axios") @scope(("default", "interceptors", "response"))
179
+ external eject: t => unit = "eject"
180
+ }
109
181
  }
110
182
 
111
183
  module WithResult = {
@@ -133,47 +205,83 @@ module WithResult = {
133
205
  })
134
206
 
135
207
  let get = (
208
+ ~instance=?,
136
209
  ~config=?,
137
210
  ~decodeData: decodeData<'newData>,
138
211
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
139
212
  string,
140
- ) => get(string, ~config?, ())->toResult(~decodeData, ~mapError)
213
+ ) =>
214
+ switch instance {
215
+ | None => get(string, ~config?, ())->toResult(~decodeData, ~mapError)
216
+ | Some(instance) =>
217
+ instance->Instance.get(string, ~config?, ())->toResult(~decodeData, ~mapError)
218
+ }
141
219
 
142
220
  let post = (
221
+ ~instance=?,
143
222
  ~data,
144
223
  ~config=?,
145
224
  ~decodeData: decodeData<'newData>,
146
225
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
147
226
  string,
148
- ) => post(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
227
+ ) =>
228
+ switch instance {
229
+ | None => post(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
230
+ | Some(instance) =>
231
+ instance->Instance.post(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
232
+ }
149
233
 
150
234
  let put = (
235
+ ~instance=?,
151
236
  ~data,
152
237
  ~config=?,
153
238
  ~decodeData: decodeData<'newData>,
154
239
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
155
240
  string,
156
- ) => put(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
241
+ ) =>
242
+ switch instance {
243
+ | None => put(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
244
+ | Some(instance) =>
245
+ instance->Instance.put(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
246
+ }
157
247
 
158
248
  let patch = (
249
+ ~instance=?,
159
250
  ~data,
160
251
  ~config=?,
161
252
  ~decodeData: decodeData<'newData>,
162
253
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
163
254
  string,
164
- ) => patch(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
255
+ ) =>
256
+ switch instance {
257
+ | None => patch(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
258
+ | Some(instance) =>
259
+ instance->Instance.patch(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
260
+ }
165
261
 
166
262
  let delete = (
263
+ ~instance=?,
167
264
  ~config=?,
168
265
  ~decodeData: decodeData<'newData>,
169
266
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
170
267
  string,
171
- ) => delete(string, ~config?, ())->toResult(~decodeData, ~mapError)
268
+ ) =>
269
+ switch instance {
270
+ | None => delete(string, ~config?, ())->toResult(~decodeData, ~mapError)
271
+ | Some(instance) =>
272
+ instance->Instance.delete(string, ~config?, ())->toResult(~decodeData, ~mapError)
273
+ }
172
274
 
173
275
  let options = (
276
+ ~instance=?,
174
277
  ~config=?,
175
278
  ~decodeData: decodeData<'newData>,
176
279
  ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
177
280
  string,
178
- ) => options(string, ~config?, ())->toResult(~decodeData, ~mapError)
281
+ ) =>
282
+ switch instance {
283
+ | None => options(string, ~config?, ())->toResult(~decodeData, ~mapError)
284
+ | Some(instance) =>
285
+ instance->Instance.options(string, ~config?, ())->toResult(~decodeData, ~mapError)
286
+ }
179
287
  }