@colisweb/rescript-toolkit 2.68.1 → 2.69.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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "2.68.1",
3
+ "version": "2.69.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -81,7 +81,8 @@
81
81
  "rescript-react-update": "5.0.0",
82
82
  "sanitize-html": "1.27.4",
83
83
  "swr": "2.0.0",
84
- "tailwindcss": "3.2.4"
84
+ "tailwindcss": "3.2.4",
85
+ "use-local-storage-state": "^18.1.2"
85
86
  },
86
87
  "devDependencies": {
87
88
  "@babel/core": "7.20.5",
@@ -286,3 +286,11 @@ let useQueryParams = (~decoder, ~defaultParams) => {
286
286
  [queryString],
287
287
  )
288
288
  }
289
+
290
+ type localstorageStateOptions<'state> = {defaultValue?: 'state, storageSync?: bool}
291
+
292
+ @module("use-local-storage-state")
293
+ external useLocalStorageState: (
294
+ string,
295
+ localstorageStateOptions<'state>,
296
+ ) => ('state, ('state => 'state) => unit) = "default"
@@ -2,18 +2,22 @@ let localStorageKey = "@colisweb/mock"
2
2
 
3
3
  @react.component
4
4
  let make = (~worker: Msw.worker, ~children) => {
5
- let (mockEnabled, setMock) = React.useState(() =>
6
- Browser.LocalStorage.getItem(localStorageKey)
7
- ->Js.Nullable.toOption
8
- ->Option.mapWithDefault(false, bool_of_string)
5
+ let (mockEnabled, setMock) = Toolkit__Hooks.useLocalStorageState(
6
+ localStorageKey,
7
+ {
8
+ defaultValue: false,
9
+ },
9
10
  )
11
+ let (workerStarted, setWorkerStarted) = React.useState(() => false)
10
12
 
11
13
  React.useLayoutEffect1(() => {
12
14
  if mockEnabled {
13
15
  worker->Msw.start
16
+ setWorkerStarted(_ => true)
14
17
  Browser.LocalStorage.setItem(localStorageKey, Js.Nullable.return("true"))
15
18
  } else {
16
19
  worker->Msw.stop
20
+ setWorkerStarted(_ => false)
17
21
  Browser.LocalStorage.removeItem(localStorageKey)
18
22
  }
19
23
 
@@ -36,7 +40,11 @@ let make = (~worker: Msw.worker, ~children) => {
36
40
  }}
37
41
  />
38
42
  </label>
39
- {children}
43
+ {switch (mockEnabled, workerStarted) {
44
+ | (false, _) => children
45
+ | (true, false) => React.null
46
+ | (true, true) => children
47
+ }}
40
48
  </React.Suspense>
41
49
  }
42
50
 
@@ -50,7 +50,7 @@ module Core = {
50
50
  <div className={cx([className, "flex flex-auto w-full overflow-x-auto relative"])}>
51
51
  <Toolkit__Ui_Spread props={table.getTableProps()}>
52
52
  <table className="border-b border-gray-300 w-full h-full">
53
- <thead className="block h-20">
53
+ <thead className="block xl:h-20">
54
54
  <tr className="flex">
55
55
  {table.headers
56
56
  ->Array.mapWithIndex((index, column) => {
@@ -58,7 +58,7 @@ module Core = {
58
58
  ? <Toolkit__Ui_Spread
59
59
  key={"thead-th" ++ index->Int.toString} props={column.getHeaderProps()}>
60
60
  <td
61
- className="px-2 pt-2 border-b border-r border-gray-300 h-20"
61
+ className="px-2 pt-2 border-b border-r border-gray-300 xl:h-20"
62
62
  key={"thead-thd" ++ index->Int.toString}>
63
63
  <Toolkit__Ui_Spread props={column.getSortByToggleProps()}>
64
64
  <div
@@ -0,0 +1,19 @@
1
+ @val
2
+ external cmd2: (string, string) => unit = "window.zE"
3
+ @val
4
+ external cmd3: (string, string, 'a) => unit = "window.zE"
5
+
6
+ type onLoadCallback = unit => unit
7
+ type key = string
8
+
9
+ let load: (key, onLoadCallback) => unit = %raw(`
10
+ function (key, cb) {
11
+ var d = document;
12
+ var s = d.createElement('script');
13
+ s.id = 'ze-snippet';
14
+ s.src = 'https://static.zdassets.com/ekr/snippet.js?key='+ key;
15
+ s.async = 1;
16
+ s.addEventListener("load", cb);
17
+ d.getElementsByTagName('head')[0].appendChild(s);
18
+ }
19
+ `)