@colisweb/rescript-toolkit 5.40.4 → 5.41.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": "5.40.4",
3
+ "version": "5.41.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
package/rescript.json CHANGED
@@ -32,7 +32,9 @@
32
32
  "@dck/rescript-ky"
33
33
  ],
34
34
  "ppx-flags": [
35
- ["@greenlabs/ppx-spice/ppx"],
35
+ [
36
+ "@greenlabs/ppx-spice/ppx"
37
+ ],
36
38
  "lenses-ppx/ppx",
37
39
  "res-react-intl/ppx"
38
40
  ],
@@ -44,7 +46,6 @@
44
46
  "-bs-super-errors",
45
47
  "-bs-no-version-header",
46
48
  "-open Belt",
47
- "-open Toolkit__Primitives_Result"
49
+ "-open Toolkit__Primitives"
48
50
  ]
49
- }
50
-
51
+ }
@@ -1,4 +1,5 @@
1
1
  module String = {
2
+ include String
2
3
  let joinNonEmty = (~separator=", ", parts: array<string>): string =>
3
4
  parts->Array.keep(str => str !== "")->Js.Array2.joinWith(separator)
4
5
 
@@ -21,7 +22,27 @@ module String = {
21
22
  }
22
23
  }
23
24
 
25
+ module Result = {
26
+ include Belt.Result
27
+
28
+ let get = result =>
29
+ switch result {
30
+ | Ok(v) => Some(v)
31
+ | Error(_) => None
32
+ }
33
+
34
+ let mapError = (result: t<'a, 'b>, fn: 'b => 'c) => {
35
+ switch result {
36
+ | Ok(_) as ok => ok
37
+ | Error(err) => Error(fn(err))
38
+ }
39
+ }
40
+
41
+ let mapOk = map
42
+ }
43
+
24
44
  module Option = {
45
+ include Belt.Option
25
46
  let fromString = v => v === "" ? None : Some(v)
26
47
 
27
48
  let fromBool = v => v === true ? Some(true) : None
@@ -54,6 +75,8 @@ module Option = {
54
75
  }
55
76
 
56
77
  module Array = {
78
+ include Belt.Array
79
+
57
80
  let joinNonEmpty = (~separator=", ", parts: array<string>): string =>
58
81
  parts->Array.keep(str => str !== "")->Js.Array2.joinWith(separator)
59
82
 
@@ -62,4 +85,63 @@ module Array = {
62
85
  let isLastIndex = (array, index) => array->Array.length - 1 == index
63
86
 
64
87
  let flatten = array => array->Array.reduce([], (acc, value) => acc->Array.concat(value))
88
+
89
+ let findMap: (array<'a>, 'a => option<'b>) => option<'b> = (array, findMapper) => {
90
+ let result = ref(None)
91
+ let index = ref(0)
92
+
93
+ while result.contents->Belt.Option.isNone && index.contents < array->Array.length {
94
+ result := findMapper(array[index.contents]->Belt.Option.getExn)
95
+ index := index.contents + 1
96
+ }
97
+
98
+ result.contents
99
+ }
100
+
101
+ let findMapWithIndex: (array<'a>, (int, 'a) => option<'b>) => option<'b> = (
102
+ array,
103
+ findMapper,
104
+ ) => {
105
+ let result = ref(None)
106
+ let index = ref(0)
107
+
108
+ while result.contents->Belt.Option.isNone && index.contents < array->Array.length {
109
+ result := findMapper(index.contents, array[index.contents]->Belt.Option.getExn)
110
+ index := index.contents + 1
111
+ }
112
+
113
+ result.contents
114
+ }
115
+ }
116
+
117
+ let cx = arr => {
118
+ let result = ref("")
119
+ for i in 0 to arr->Array.length - 1 {
120
+ switch arr->Array.getUnsafe(i) {
121
+ | "" => ()
122
+ | name => result := (result.contents == "" ? name : result.contents ++ " " ++ name)
123
+ }
124
+ }
125
+ result.contents
126
+ }
127
+
128
+ module NonEmptyArray: {
129
+ type t<'a>
130
+ let t_encode: ('a => Js.Json.t, t<'a>) => Js.Json.t
131
+ let t_decode: (
132
+ Js.Json.t => result<'a, Spice.decodeError>,
133
+ Js.Json.t,
134
+ ) => result<t<'a>, Spice.decodeError>
135
+ let make: array<'a> => option<t<'a>>
136
+ let makeExn: array<'a> => t<'a>
137
+ let toArray: t<'a> => array<'a>
138
+ } = {
139
+ @spice
140
+ type t<'a> = array<'a>
141
+
142
+ let make = arr => arr->Array.length === 0 ? None : Some(arr->Obj.magic)
143
+
144
+ let makeExn = arr => arr->make->Belt.Option.getExn
145
+
146
+ external toArray: t<'a> => array<'a> = "%identity"
65
147
  }
@@ -57,7 +57,7 @@ let make = (
57
57
  if !isDefaultValue {
58
58
  switch search {
59
59
  | "" => ()
60
- | search if search->String.length < minSearchLength =>
60
+ | search if search->Js.String.length < minSearchLength =>
61
61
  setSuggestions(_ => Some(Error("QUERY_TOO_SMALL")))
62
62
  | search =>
63
63
  setSearching(_ => true)
@@ -6264,3 +6264,9 @@ module FaLinkedin = {
6264
6264
  external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
6265
6265
  "FaLinkedin"
6266
6266
  }
6267
+
6268
+ module FaClipboardUser = {
6269
+ @module("react-icons/fa6") @react.component
6270
+ external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
6271
+ "FaClipboardUser"
6272
+ }
@@ -0,0 +1,174 @@
1
+ type coreRowModel
2
+ type filteredRowModel
3
+ type paginationRowModel
4
+
5
+ @module("@tanstack/react-table")
6
+ external getCoreRowModel: unit => coreRowModel = "getCoreRowModel"
7
+ @module("@tanstack/react-table")
8
+ external getFilteredRowModel: unit => filteredRowModel = "getFilteredRowModel"
9
+ @module("@tanstack/react-table")
10
+ external getPaginationRowModel: unit => paginationRowModel = "getPaginationRowModel"
11
+
12
+ type paginationState = {
13
+ pageIndex: int,
14
+ pageSize: int,
15
+ }
16
+
17
+ type rowSelectionState = Js.Dict.t<bool>
18
+ type filterState = {id: string, value: unknown}
19
+ type sortingState = {id: string, desc: bool}
20
+
21
+ type tableState = {
22
+ pagination: paginationState,
23
+ rowSelection: rowSelectionState,
24
+ columnFilters?: array<filterState>,
25
+ sorting?: array<sortingState>,
26
+ }
27
+ type tableInitialState = {
28
+ pagination?: paginationState,
29
+ rowSelection?: rowSelectionState,
30
+ columnFilters?: array<filterState>,
31
+ sorting?: array<sortingState>,
32
+ }
33
+
34
+ module TableAPI = {
35
+ type t = {initialState: tableInitialState}
36
+ }
37
+
38
+ module ColumnDef = {
39
+ type tableContext = {
40
+ getIsAllRowsSelected: unit => bool,
41
+ getIsSomeRowsSelected: unit => bool,
42
+ getToggleAllRowsSelectedHandler: (unit, ReactEvent.Form.t) => unit,
43
+ }
44
+
45
+ type rowOptions = {
46
+ getIsSelected: unit => bool,
47
+ getCanSelect: unit => bool,
48
+ getIsSomeSelected: unit => bool,
49
+ getToggleSelectedHandler: (unit, ReactEvent.Form.t) => unit,
50
+ }
51
+
52
+ type cellOptions<'columnData> = {
53
+ getValue: unit => 'columnData,
54
+ row: rowOptions,
55
+ }
56
+
57
+ type columnMeta<'filterVariant> = {filterVariant?: 'filterVariant}
58
+ type filterFnVariant = | @as("equals") Equals
59
+ type t<'tableData, 'filterVariant>
60
+ @obj
61
+ external make: (
62
+ ~id: string=?,
63
+ ~accessorFn: 'tableData => 'columnData,
64
+ ~header: 'columnData => React.element=?,
65
+ ~footer: unit => React.element=?,
66
+ ~cell: cellOptions<'columnData> => React.element,
67
+ ~meta: columnMeta<'filterVariant>=?,
68
+ ~enableResizing: int=?,
69
+ ~maxSize: int=?,
70
+ ~minSize: int=?,
71
+ ~size: int=?,
72
+ ~enableSorting: bool=?,
73
+ ~filterFn: filterFnVariant=?,
74
+ unit,
75
+ ) => t<'tableData, 'filterVariant> = ""
76
+ }
77
+
78
+ module Header = {
79
+ type t
80
+ type tableContext = {setColumnFilters: (array<filterState> => array<filterState>) => unit}
81
+ type context = {table: tableContext}
82
+
83
+ @module("@tanstack/react-table")
84
+ external flexRender: (t, context) => React.element = "flexRender"
85
+ }
86
+
87
+ module Cell = {
88
+ type t
89
+ type context
90
+
91
+ @module("@tanstack/react-table")
92
+ external flexRender: (t, context) => React.element = "flexRender"
93
+ }
94
+
95
+ type rec rowModel<'filterVariant> = {rows: array<row<'filterVariant>>}
96
+ and row<'filterVariant> = {
97
+ getVisibleCells: unit => array<rowModelCell<'filterVariant>>,
98
+ id: string,
99
+ }
100
+ and rowModelCell<'filterVariant> = {
101
+ id: string,
102
+ isPlaceholder: bool,
103
+ column: 'filterValue. parentColumn<'filterValue, 'filterVariant>,
104
+ getContext: unit => Cell.context,
105
+ }
106
+
107
+ and parentColumn<'filterValue, 'filterVariant> = {
108
+ columnDef: parentColumnDef<'filterVariant>,
109
+ getFilterValue: unit => 'filterValue,
110
+ setFilterValue: 'filterValue => unit,
111
+ }
112
+ and parentColumnDef<'filterVariant> = {
113
+ header: Header.t,
114
+ cell: Cell.t,
115
+ meta?: ColumnDef.columnMeta<'filterVariant>,
116
+ }
117
+
118
+ type rec headerGroup<'filterVariant> = {headers: array<header<'filterVariant>>, id: string}
119
+ and header<'filterVariant> = {
120
+ isPlaceholder: bool,
121
+ column: 'a. parentColumn<'a, 'filterVariant>,
122
+ colSpan: int,
123
+ getSize: unit => int,
124
+ getContext: unit => Header.context,
125
+ getIsSorted: unit => bool,
126
+ getCanFilter: unit => bool,
127
+ getCanSort: unit => bool,
128
+ getToggleSortingHandler: unit => unit,
129
+ id: string,
130
+ }
131
+
132
+ type rec tableInstance<'tableData, 'filterVariant> = {
133
+ getHeaderGroups: unit => array<headerGroup<'filterVariant>>,
134
+ getRowModel: unit => rowModel<'filterVariant>,
135
+ getFooterGroups: unit => array<headerGroup<'filterVariant>>,
136
+ getPageCount: unit => int,
137
+ getCanPreviousPage: unit => bool,
138
+ getCanNextPage: unit => bool,
139
+ getIsAllRowsSelected: unit => bool,
140
+ getIsSomeRowsSelected: unit => bool,
141
+ getToggleAllRowsSelectedHandler: (unit, ReactEvent.Form.t) => unit,
142
+ setPageIndex: (int => int) => unit,
143
+ setPageSize: int => unit,
144
+ previousPage: unit => unit,
145
+ nextPage: unit => unit,
146
+ getState: unit => tableState,
147
+ setOptions: (
148
+ tableOptions<'tableData, 'filterVariant> => tableOptions<'tableData, 'filterVariant>
149
+ ) => unit,
150
+ setColumnFilters: (array<filterState> => array<filterState>) => unit,
151
+ }
152
+ and tableOptions<'tableData, 'filterVariant> = {
153
+ data: array<'tableData>,
154
+ columns: array<ColumnDef.t<'tableData, 'filterVariant>>,
155
+ getCoreRowModel: coreRowModel,
156
+ getFilteredRowModel?: filteredRowModel,
157
+ getPaginationRowModel?: paginationRowModel,
158
+ onPaginationChange?: (paginationState => paginationState) => paginationState,
159
+ onRowSelectionChange?: (rowSelectionState => rowSelectionState) => unit,
160
+ pageCount?: int,
161
+ initialState?: tableInitialState,
162
+ manualPagination?: bool,
163
+ manualSorting?: bool,
164
+ manualFiltering?: bool,
165
+ enableRowSelection?: bool,
166
+ enableMultiRowSelection?: bool,
167
+ debugTable?: bool,
168
+ }
169
+
170
+ @module("@tanstack/react-table")
171
+ external useReactTable: tableOptions<'tableData, 'filterVariant> => tableInstance<
172
+ 'tableData,
173
+ 'filterVariant,
174
+ > = "useReactTable"
@@ -1,30 +0,0 @@
1
- module Array = {
2
- include Belt.Array
3
-
4
- let findMap: (array<'a>, 'a => option<'b>) => option<'b> = (array, findMapper) => {
5
- let result = ref(None)
6
- let index = ref(0)
7
-
8
- while result.contents->Option.isNone && index.contents < array->Array.length {
9
- result := findMapper(array[index.contents]->Option.getExn)
10
- index := index.contents + 1
11
- }
12
-
13
- result.contents
14
- }
15
-
16
- let findMapWithIndex: (array<'a>, (int, 'a) => option<'b>) => option<'b> = (
17
- array,
18
- findMapper,
19
- ) => {
20
- let result = ref(None)
21
- let index = ref(0)
22
-
23
- while result.contents->Option.isNone && index.contents < array->Array.length {
24
- result := findMapper(index.contents, array[index.contents]->Option.getExn)
25
- index := index.contents + 1
26
- }
27
-
28
- result.contents
29
- }
30
- }
@@ -1,29 +0,0 @@
1
- module Result = {
2
- include Belt.Result
3
-
4
- let get = result =>
5
- switch result {
6
- | Ok(v) => Some(v)
7
- | Error(_) => None
8
- }
9
-
10
- let mapError = (result: t<'a, 'b>, fn: 'b => 'c) => {
11
- switch result {
12
- | Ok(_) as ok => ok
13
- | Error(err) => Error(fn(err))
14
- }
15
- }
16
-
17
- let mapOk = map
18
- }
19
-
20
- let cx = arr => {
21
- let result = ref("")
22
- for i in 0 to arr->Array.length - 1 {
23
- switch arr->Array.getUnsafe(i) {
24
- | "" => ()
25
- | name => result := (result.contents == "" ? name : result.contents ++ " " ++ name)
26
- }
27
- }
28
- result.contents
29
- }