@colisweb/rescript-toolkit 2.59.2 → 2.61.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.
|
|
3
|
+
"version": "2.61.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rescript clean",
|
|
6
6
|
"build": "rescript build -with-deps",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"rescript-classnames": "6.0.0",
|
|
79
79
|
"rescript-react-update": "5.0.0",
|
|
80
80
|
"sanitize-html": "1.27.4",
|
|
81
|
-
"swr": "
|
|
81
|
+
"swr": "2.0.0",
|
|
82
82
|
"tailwindcss": "3.2.4"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
@@ -4,19 +4,16 @@ module type Config = {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
module Make = (Config: Config) => {
|
|
7
|
-
let key: Config.Request.argument => Swr.SwrKey.t =
|
|
7
|
+
let key: Config.Request.argument => Swr.SwrKey.t = arr =>
|
|
8
|
+
Config.key(arr)->Js.Array2.joinWith("--")->Swr.SwrKey.make
|
|
8
9
|
|
|
9
10
|
let use = (
|
|
10
11
|
~options: option<Swr.fetcherOptions>=?,
|
|
11
12
|
argument: option<Config.Request.argument>,
|
|
12
13
|
): Toolkit__Hooks.fetcher<Config.Request.response> =>
|
|
13
|
-
Toolkit__Hooks.useFetcher(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
() => {
|
|
17
|
-
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
18
|
-
},
|
|
19
|
-
)
|
|
14
|
+
Toolkit__Hooks.useFetcher(~options?, argument->Option.map(key), () => {
|
|
15
|
+
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
16
|
+
})
|
|
20
17
|
|
|
21
18
|
let useOptional = (
|
|
22
19
|
~options: option<Swr.fetcherOptions>=?,
|
|
@@ -26,3 +23,28 @@ module Make = (Config: Config) => {
|
|
|
26
23
|
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
27
24
|
})
|
|
28
25
|
}
|
|
26
|
+
|
|
27
|
+
module type MutationConfig = {
|
|
28
|
+
module Request: Toolkit__Request.Config
|
|
29
|
+
let key: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module MakeMutation = (Config: MutationConfig) => {
|
|
33
|
+
let key = Config.key->Swr.SwrKey.make
|
|
34
|
+
|
|
35
|
+
let useMutation = (
|
|
36
|
+
~options: option<Swr.mutationFetcherOptions<Config.Request.response>>=?,
|
|
37
|
+
key: string,
|
|
38
|
+
) => {
|
|
39
|
+
Swr.useSwrMutation(
|
|
40
|
+
Swr.SwrKey.make(key),
|
|
41
|
+
(_url, {arg}) => {
|
|
42
|
+
Config.Request.exec(arg)->Promise.Js.fromResult
|
|
43
|
+
},
|
|
44
|
+
switch options {
|
|
45
|
+
| Some(options) => options->Obj.magic
|
|
46
|
+
| None => {revalidate: true}
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -4,7 +4,7 @@ type status = [#success | #error | #warning | #info]
|
|
|
4
4
|
let make = (~title, ~description=?, ~status, ~className=?) =>
|
|
5
5
|
<div
|
|
6
6
|
className={cx([
|
|
7
|
-
"
|
|
7
|
+
"p-4 flex items-center border rounded-lg",
|
|
8
8
|
switch status {
|
|
9
9
|
| #success => "bg-success-50 border-success-500"
|
|
10
10
|
| #error => "bg-danger-50 border-danger-500"
|
|
@@ -16,18 +16,19 @@ let make = (~title, ~description=?, ~status, ~className=?) =>
|
|
|
16
16
|
{switch status {
|
|
17
17
|
| #success => <BsReactIcons.MdCheckCircle size=28 className="text-success-600 flex-shrink-0" />
|
|
18
18
|
| #error => <BsReactIcons.MdWarning size=28 className="text-danger-600 flex-shrink-0" />
|
|
19
|
-
| #warning =>
|
|
19
|
+
| #warning =>
|
|
20
|
+
<BsReactIcons.FaExclamationTriangle size=28 className="text-warning-600 flex-shrink-0" />
|
|
20
21
|
| #info => <BsReactIcons.FaExclamationCircle size=28 className="text-info-600 flex-shrink-0" />
|
|
21
22
|
}}
|
|
22
23
|
<div className="mx-3">
|
|
23
24
|
<div
|
|
24
25
|
className={cx([
|
|
25
|
-
description->Option.isSome ? "font-
|
|
26
|
+
description->Option.isSome ? "font-semibold" : "",
|
|
26
27
|
{
|
|
27
28
|
switch status {
|
|
28
29
|
| #success => "text-success-600"
|
|
29
30
|
| #error => "text-danger-600"
|
|
30
|
-
| #warning => "text-warning-
|
|
31
|
+
| #warning => "text-warning-700"
|
|
31
32
|
| #info => "text-info-600"
|
|
32
33
|
}
|
|
33
34
|
},
|
|
@@ -5980,3 +5980,8 @@ module FaCog = {
|
|
|
5980
5980
|
@module("react-icons/fa") @react.component
|
|
5981
5981
|
external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element = "FaCog"
|
|
5982
5982
|
}
|
|
5983
|
+
module FaExclamationTriangle = {
|
|
5984
|
+
@module("react-icons/fa") @react.component
|
|
5985
|
+
external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
|
|
5986
|
+
"FaExclamationTriangle"
|
|
5987
|
+
}
|
package/src/vendors/Swr.res
CHANGED
|
@@ -12,6 +12,7 @@ type fetcherOptions
|
|
|
12
12
|
@obj
|
|
13
13
|
external makeFetcherOptions: (
|
|
14
14
|
~suspense: bool=?,
|
|
15
|
+
~keepPreviousData: bool=?,
|
|
15
16
|
~fetcher: 'fetcher=?,
|
|
16
17
|
~fallbackData: 'data=?,
|
|
17
18
|
~revalidateOnFocus: bool=?,
|
|
@@ -43,16 +44,39 @@ type fetcher<'data> = {
|
|
|
43
44
|
data: option<'data>,
|
|
44
45
|
error: option<Js.Exn.t>,
|
|
45
46
|
isValidating: bool,
|
|
47
|
+
isLoading: bool,
|
|
46
48
|
mutate: (. unit) => Js.Promise.t<bool>,
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
type mutationFetcherOptions<'optimisticData> = {
|
|
52
|
+
optimisticData?: 'optimisticData => 'optimisticData,
|
|
53
|
+
revalidate?: bool,
|
|
54
|
+
populateCache?: bool,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type mutationFetcher<'params, 'data, 'error> = {
|
|
58
|
+
data: option<'data>,
|
|
59
|
+
error: option<Js.Exn.t>,
|
|
60
|
+
isMutating: bool,
|
|
61
|
+
trigger: 'params => Promise.Js.t<'data, 'error>,
|
|
62
|
+
}
|
|
63
|
+
|
|
49
64
|
module SwrKey = Toolkit__Identifier.MakeString()
|
|
50
65
|
|
|
51
66
|
@module("swr")
|
|
52
67
|
external useSwr: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<'data> = "default"
|
|
53
68
|
|
|
69
|
+
type mutationParams<'params> = {arg: 'params}
|
|
70
|
+
@module("swr/mutation")
|
|
71
|
+
external useSwrMutation: (
|
|
72
|
+
SwrKey.t,
|
|
73
|
+
(string, mutationParams<'params>) => 'response,
|
|
74
|
+
mutationFetcherOptions<'optimisticData>,
|
|
75
|
+
) => mutationFetcher<'params, 'data, 'error> = "default"
|
|
76
|
+
|
|
54
77
|
@module("swr")
|
|
55
|
-
external useSwrOptional: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<option<'data>> =
|
|
78
|
+
external useSwrOptional: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<option<'data>> =
|
|
79
|
+
"default"
|
|
56
80
|
|
|
57
81
|
type cache
|
|
58
82
|
@module("swr") external cache: cache = "cache"
|