@7span/react-list 0.0.1 → 0.0.3
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/dist/react-list.js +337 -689
- package/dist/react-list.umd.cjs +1 -1
- package/package.json +1 -4
package/dist/react-list.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
const { requestHandler: r, stateManager:
|
|
1
|
+
import { jsx as i, jsxs as N } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as $, useContext as j, useState as T, useMemo as P, memo as R, useCallback as O, useEffect as E, useRef as q } from "react";
|
|
3
|
+
const A = $(null), H = ({ children: n, config: o }) => {
|
|
4
|
+
const { requestHandler: r, stateManager: e = {} } = o, [s, a] = T({
|
|
5
5
|
data: [],
|
|
6
6
|
response: null,
|
|
7
7
|
error: null,
|
|
@@ -27,251 +27,128 @@ const E = D(null), F = ({ children: i, config: c }) => {
|
|
|
27
27
|
});
|
|
28
28
|
if (!r)
|
|
29
29
|
throw new Error("ListProvider: requestHandler is required.");
|
|
30
|
-
const
|
|
30
|
+
const p = P(
|
|
31
31
|
() => ({
|
|
32
32
|
requestHandler: r,
|
|
33
|
-
stateManager:
|
|
34
|
-
listState:
|
|
35
|
-
setListState:
|
|
33
|
+
stateManager: e,
|
|
34
|
+
listState: s,
|
|
35
|
+
setListState: a
|
|
36
36
|
}),
|
|
37
|
-
[r,
|
|
37
|
+
[r, e, s]
|
|
38
38
|
);
|
|
39
|
-
return /* @__PURE__ */
|
|
40
|
-
},
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
39
|
+
return /* @__PURE__ */ i(A.Provider, { value: p, children: n });
|
|
40
|
+
}, C = () => {
|
|
41
|
+
const n = j(A);
|
|
42
|
+
if (!n)
|
|
43
43
|
throw new Error("useListContext must be used within a ListProvider");
|
|
44
|
-
return
|
|
45
|
-
},
|
|
46
|
-
const { listState: r } =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
flexDirection: "column",
|
|
50
|
-
gap: "12px",
|
|
51
|
-
padding: "12px"
|
|
44
|
+
return n;
|
|
45
|
+
}, W = R(({ children: n, renderAttribute: o }) => {
|
|
46
|
+
const { listState: r } = C(), { attrs: e, attrSettings: s, updateAttr: a } = r, p = O(
|
|
47
|
+
(c) => (L) => {
|
|
48
|
+
a(c, "visible", L.target.checked);
|
|
52
49
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
alignItems: "center",
|
|
56
|
-
gap: "8px",
|
|
57
|
-
cursor: "pointer",
|
|
58
|
-
fontSize: "14px"
|
|
59
|
-
},
|
|
60
|
-
checkbox: {
|
|
61
|
-
width: "16px",
|
|
62
|
-
height: "16px",
|
|
63
|
-
cursor: "pointer"
|
|
64
|
-
}
|
|
65
|
-
}, f = T(
|
|
66
|
-
(h) => (u) => {
|
|
67
|
-
n(h, "visible", u.target.checked);
|
|
68
|
-
},
|
|
69
|
-
[n]
|
|
70
|
-
), a = g(
|
|
50
|
+
[a]
|
|
51
|
+
), h = P(
|
|
71
52
|
() => ({
|
|
72
|
-
attrs:
|
|
73
|
-
attrSettings:
|
|
74
|
-
updateAttr:
|
|
75
|
-
styles: s
|
|
53
|
+
attrs: e,
|
|
54
|
+
attrSettings: s,
|
|
55
|
+
updateAttr: a
|
|
76
56
|
}),
|
|
77
|
-
[
|
|
57
|
+
[e, s, a]
|
|
78
58
|
);
|
|
79
|
-
return
|
|
80
|
-
var
|
|
81
|
-
return
|
|
82
|
-
key: `attr-${
|
|
83
|
-
attr:
|
|
84
|
-
updateAttr:
|
|
85
|
-
attrSettings:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
/* @__PURE__ */ l(
|
|
59
|
+
return n ? n(h) : /* @__PURE__ */ i("div", { className: "react-list-attributes", children: e.map((c, L) => {
|
|
60
|
+
var l;
|
|
61
|
+
return o ? o({
|
|
62
|
+
key: `attr-${L}`,
|
|
63
|
+
attr: c,
|
|
64
|
+
updateAttr: a,
|
|
65
|
+
attrSettings: s
|
|
66
|
+
}) : /* @__PURE__ */ N("label", { children: [
|
|
67
|
+
/* @__PURE__ */ i("span", { children: c.label }),
|
|
68
|
+
/* @__PURE__ */ i(
|
|
90
69
|
"input",
|
|
91
70
|
{
|
|
92
71
|
type: "checkbox",
|
|
93
|
-
checked: ((
|
|
94
|
-
onChange:
|
|
95
|
-
style: s.checkbox
|
|
72
|
+
checked: ((l = s == null ? void 0 : s[c.name]) == null ? void 0 : l.visible) ?? !1,
|
|
73
|
+
onChange: p(c.name)
|
|
96
74
|
}
|
|
97
75
|
)
|
|
98
|
-
] }, `attr-${
|
|
76
|
+
] }, `attr-${L}`);
|
|
99
77
|
}) });
|
|
100
|
-
}),
|
|
101
|
-
const { listState:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
textAlign: "center",
|
|
109
|
-
color: "#6B7280",
|
|
110
|
-
fontSize: "16px",
|
|
111
|
-
fontWeight: "400"
|
|
112
|
-
}
|
|
113
|
-
}),
|
|
114
|
-
[]
|
|
115
|
-
);
|
|
116
|
-
return (r == null ? void 0 : r.length) > 0 || s || n || o ? null : /* @__PURE__ */ l("div", { className: "react-list-empty", style: f.container, children: i || /* @__PURE__ */ l("div", { style: f.defaultMessage, children: /* @__PURE__ */ l("p", { children: "No data found!" }) }) });
|
|
117
|
-
}), K = R(({ children: i }) => {
|
|
118
|
-
const { listState: c } = k(), { error: r, loader: t } = c, { isLoading: o } = t, n = g(
|
|
119
|
-
() => ({
|
|
120
|
-
container: {
|
|
121
|
-
width: "100%",
|
|
122
|
-
padding: "32px 16px"
|
|
123
|
-
},
|
|
124
|
-
errorContent: {
|
|
125
|
-
textAlign: "center",
|
|
126
|
-
color: "#DC2626",
|
|
127
|
-
padding: "32px 0"
|
|
128
|
-
},
|
|
129
|
-
heading: {
|
|
130
|
-
fontSize: "16px",
|
|
131
|
-
fontWeight: "500",
|
|
132
|
-
marginBottom: "8px"
|
|
133
|
-
},
|
|
134
|
-
message: {
|
|
135
|
-
fontSize: "14px",
|
|
136
|
-
fontFamily: "monospace",
|
|
137
|
-
marginTop: "8px",
|
|
138
|
-
whiteSpace: "pre-wrap",
|
|
139
|
-
wordBreak: "break-word"
|
|
140
|
-
}
|
|
141
|
-
}),
|
|
142
|
-
[]
|
|
143
|
-
);
|
|
144
|
-
return !r || o ? null : i ? i({ error: r }) : /* @__PURE__ */ l("div", { className: "react-list-error", style: n.container, children: /* @__PURE__ */ M("div", { style: n.errorContent, children: [
|
|
145
|
-
/* @__PURE__ */ l("h3", { style: n.heading, children: "Error occurred" }),
|
|
146
|
-
/* @__PURE__ */ M("pre", { style: n.message, children: [
|
|
78
|
+
}), F = R(({ children: n }) => {
|
|
79
|
+
const { listState: o } = C(), { data: r, loader: e, error: s } = o, { isLoading: a, initialLoading: p } = e;
|
|
80
|
+
return (r == null ? void 0 : r.length) > 0 || p || a || s ? null : /* @__PURE__ */ i("div", { className: "react-list-empty", children: n || /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("p", { children: "No data found!" }) }) });
|
|
81
|
+
}), G = R(({ children: n }) => {
|
|
82
|
+
const { listState: o } = C(), { error: r, loader: e } = o, { isLoading: s } = e;
|
|
83
|
+
return !r || s ? null : /* @__PURE__ */ i("div", { className: "react-list-error", children: typeof n == "function" ? n({ error: r }) : n || /* @__PURE__ */ N("div", { children: [
|
|
84
|
+
/* @__PURE__ */ i("h3", { children: "Error occurred" }),
|
|
85
|
+
/* @__PURE__ */ N("pre", { children: [
|
|
147
86
|
r.name,
|
|
148
87
|
": ",
|
|
149
88
|
r.message
|
|
150
89
|
] })
|
|
151
90
|
] }) });
|
|
152
|
-
}),
|
|
153
|
-
const { listState:
|
|
154
|
-
(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
select: {
|
|
160
|
-
width: "100%",
|
|
161
|
-
padding: "8px 12px",
|
|
162
|
-
border: "1px solid #ccc",
|
|
163
|
-
borderRadius: "4px",
|
|
164
|
-
fontSize: "14px",
|
|
165
|
-
backgroundColor: "#fff",
|
|
166
|
-
cursor: "pointer",
|
|
167
|
-
outline: "none"
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
[]
|
|
171
|
-
), { pages: P, pagesCount: w } = g(() => {
|
|
172
|
-
const L = Math.ceil(t / h);
|
|
173
|
-
return { pages: Array.from({ length: L }, (v, C) => C + 1), pagesCount: L };
|
|
174
|
-
}, [t, h]), p = T(
|
|
175
|
-
(L) => {
|
|
176
|
-
n(Number(L.target.value));
|
|
91
|
+
}), J = R(({ children: n }) => {
|
|
92
|
+
const { listState: o } = C(), { data: r, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: c, perPage: L } = s, { initialLoading: l, isLoading: S } = p, { pages: y, pagesCount: v } = P(() => {
|
|
93
|
+
const f = Math.ceil(e / L);
|
|
94
|
+
return { pages: Array.from({ length: f }, (k, b) => b + 1), pagesCount: f };
|
|
95
|
+
}, [e, L]), x = O(
|
|
96
|
+
(f) => {
|
|
97
|
+
a(Number(f.target.value));
|
|
177
98
|
},
|
|
178
|
-
[
|
|
179
|
-
),
|
|
99
|
+
[a]
|
|
100
|
+
), t = P(
|
|
180
101
|
() => ({
|
|
181
|
-
setPage:
|
|
182
|
-
page:
|
|
183
|
-
pages:
|
|
184
|
-
pagesCount:
|
|
185
|
-
styles: y
|
|
102
|
+
setPage: a,
|
|
103
|
+
page: c,
|
|
104
|
+
pages: y,
|
|
105
|
+
pagesCount: v
|
|
186
106
|
}),
|
|
187
|
-
[
|
|
107
|
+
[a, c, y, v]
|
|
188
108
|
);
|
|
189
|
-
return
|
|
109
|
+
return l || !r || r.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-go-to", children: n ? n(t) : /* @__PURE__ */ i("select", { value: c, onChange: x, children: y.map((f) => /* @__PURE__ */ N("option", { value: f, children: [
|
|
190
110
|
"Page ",
|
|
191
|
-
|
|
192
|
-
] }, `page-${
|
|
193
|
-
}),
|
|
194
|
-
const { listState:
|
|
195
|
-
|
|
196
|
-
container: {
|
|
197
|
-
padding: "20px",
|
|
198
|
-
textAlign: "center"
|
|
199
|
-
},
|
|
200
|
-
defaultLoader: {
|
|
201
|
-
fontSize: "16px",
|
|
202
|
-
color: "#4B5563",
|
|
203
|
-
margin: 0,
|
|
204
|
-
animation: "pulse 1.5s infinite ease-in-out"
|
|
205
|
-
},
|
|
206
|
-
"@keyframes pulse": {
|
|
207
|
-
"0%": { opacity: 0.6 },
|
|
208
|
-
"50%": { opacity: 1 },
|
|
209
|
-
"100%": { opacity: 0.6 }
|
|
210
|
-
}
|
|
211
|
-
}),
|
|
212
|
-
[]
|
|
213
|
-
), n = g(
|
|
214
|
-
() => ({
|
|
215
|
-
loading: t,
|
|
216
|
-
styles: o
|
|
217
|
-
}),
|
|
218
|
-
[t]
|
|
219
|
-
);
|
|
220
|
-
return t ? /* @__PURE__ */ l("div", { className: "react-list-initial-loader", style: o.container, children: i ? i(n) : /* @__PURE__ */ l("p", { style: o.defaultLoader, children: "Initial Loading..." }) }) : null;
|
|
221
|
-
}), V = R(({ children: i, renderItem: c }) => {
|
|
222
|
-
const { listState: r } = k(), { data: t = [], loader: o, error: n } = r, { initialLoading: s, isLoading: f } = o, a = g(
|
|
111
|
+
f
|
|
112
|
+
] }, `page-${f}`)) }) });
|
|
113
|
+
}), K = R(({ children: n }) => {
|
|
114
|
+
const { listState: o } = C(), { loader: r } = o, { initialLoading: e } = r;
|
|
115
|
+
return P(
|
|
223
116
|
() => ({
|
|
224
|
-
|
|
225
|
-
display: "flex",
|
|
226
|
-
flexDirection: "column",
|
|
227
|
-
gap: "12px",
|
|
228
|
-
width: "100%"
|
|
229
|
-
},
|
|
230
|
-
itemWrapper: {
|
|
231
|
-
width: "100%"
|
|
232
|
-
},
|
|
233
|
-
defaultItem: {
|
|
234
|
-
padding: "12px",
|
|
235
|
-
backgroundColor: "#f9fafb",
|
|
236
|
-
borderRadius: "4px",
|
|
237
|
-
fontFamily: "monospace",
|
|
238
|
-
fontSize: "14px",
|
|
239
|
-
whiteSpace: "pre-wrap",
|
|
240
|
-
wordBreak: "break-word",
|
|
241
|
-
overflow: "auto"
|
|
242
|
-
}
|
|
117
|
+
loading: e
|
|
243
118
|
}),
|
|
244
|
-
[]
|
|
245
|
-
),
|
|
119
|
+
[e]
|
|
120
|
+
), e ? /* @__PURE__ */ i("div", { className: "react-list-initial-loader", children: n || /* @__PURE__ */ i("p", { children: "Initial Loading..." }) }) : null;
|
|
121
|
+
}), Q = R(({ children: n, renderItem: o }) => {
|
|
122
|
+
const { listState: r } = C(), { data: e = [], loader: s, error: a, setSort: p, sort: h } = r, { initialLoading: c } = s, L = P(
|
|
246
123
|
() => ({
|
|
247
|
-
items:
|
|
248
|
-
|
|
124
|
+
items: e,
|
|
125
|
+
setSort: p,
|
|
126
|
+
sort: h
|
|
249
127
|
}),
|
|
250
|
-
[
|
|
128
|
+
[e, h, p]
|
|
251
129
|
);
|
|
252
|
-
return
|
|
253
|
-
}),
|
|
254
|
-
children:
|
|
255
|
-
endpoint:
|
|
130
|
+
return c || !e || e.length === 0 || a ? null : o ? /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, S) => /* @__PURE__ */ i("div", { children: o({ item: l, index: S }) }, l.id || S)) }) : typeof n == "function" ? /* @__PURE__ */ i("div", { className: "react-list-items", children: n(L) }) : /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, S) => /* @__PURE__ */ i("pre", { children: JSON.stringify(l, null, 2) }, l.id || S)) });
|
|
131
|
+
}), U = ({
|
|
132
|
+
children: n,
|
|
133
|
+
endpoint: o,
|
|
256
134
|
page: r = 1,
|
|
257
|
-
perPage:
|
|
258
|
-
sortBy:
|
|
259
|
-
sortOrder:
|
|
260
|
-
search:
|
|
261
|
-
filters:
|
|
262
|
-
attrs:
|
|
263
|
-
version:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
meta: y = {}
|
|
135
|
+
perPage: e = 25,
|
|
136
|
+
sortBy: s,
|
|
137
|
+
sortOrder: a = "desc",
|
|
138
|
+
search: p = "",
|
|
139
|
+
filters: h = {},
|
|
140
|
+
attrs: c,
|
|
141
|
+
version: L = 1,
|
|
142
|
+
paginationMode: l = "pagination",
|
|
143
|
+
meta: S = {}
|
|
267
144
|
}) => {
|
|
268
|
-
const { requestHandler:
|
|
145
|
+
const { requestHandler: y, setListState: v } = C(), x = l === "loadMore", [t, f] = T({
|
|
269
146
|
page: r,
|
|
270
|
-
perPage:
|
|
271
|
-
sortBy:
|
|
272
|
-
sortOrder:
|
|
273
|
-
search:
|
|
274
|
-
filters:
|
|
147
|
+
perPage: e,
|
|
148
|
+
sortBy: s,
|
|
149
|
+
sortOrder: a,
|
|
150
|
+
search: p,
|
|
151
|
+
filters: h,
|
|
275
152
|
attrSettings: {},
|
|
276
153
|
items: [],
|
|
277
154
|
selection: [],
|
|
@@ -280,580 +157,351 @@ const E = D(null), F = ({ children: i, config: c }) => {
|
|
|
280
157
|
count: 0,
|
|
281
158
|
isLoading: !1,
|
|
282
159
|
initializingState: !0
|
|
283
|
-
}),
|
|
284
|
-
async (
|
|
285
|
-
|
|
160
|
+
}), w = O(
|
|
161
|
+
async (m = {}, d = null) => {
|
|
162
|
+
t.initializingState || f((g) => ({ ...g, error: null, isLoading: !0 }));
|
|
286
163
|
try {
|
|
287
|
-
const
|
|
288
|
-
endpoint:
|
|
289
|
-
version:
|
|
290
|
-
meta:
|
|
291
|
-
page:
|
|
292
|
-
perPage:
|
|
293
|
-
search:
|
|
294
|
-
sortBy:
|
|
295
|
-
sortOrder:
|
|
296
|
-
filters:
|
|
297
|
-
...
|
|
164
|
+
const g = d || t, u = await y({
|
|
165
|
+
endpoint: o,
|
|
166
|
+
version: L,
|
|
167
|
+
meta: S,
|
|
168
|
+
page: g.page,
|
|
169
|
+
perPage: g.perPage,
|
|
170
|
+
search: g.search,
|
|
171
|
+
sortBy: g.sortBy,
|
|
172
|
+
sortOrder: g.sortOrder,
|
|
173
|
+
filters: g.filters,
|
|
174
|
+
...m
|
|
298
175
|
});
|
|
299
|
-
|
|
300
|
-
...
|
|
301
|
-
response:
|
|
176
|
+
f((M) => ({
|
|
177
|
+
...M,
|
|
178
|
+
response: u,
|
|
302
179
|
selection: [],
|
|
303
180
|
// Append items for loadMore, replace for pagination
|
|
304
|
-
items:
|
|
305
|
-
count:
|
|
181
|
+
items: x && g.page > 1 ? [...M.items, ...u.items] : u.items,
|
|
182
|
+
count: u.count,
|
|
306
183
|
initializingState: !1,
|
|
307
184
|
isLoading: !1
|
|
308
185
|
}));
|
|
309
|
-
} catch (
|
|
310
|
-
throw
|
|
311
|
-
...
|
|
312
|
-
error:
|
|
186
|
+
} catch (g) {
|
|
187
|
+
throw f((u) => ({
|
|
188
|
+
...u,
|
|
189
|
+
error: g,
|
|
313
190
|
items: [],
|
|
314
191
|
count: 0,
|
|
315
192
|
initializingState: !1,
|
|
316
193
|
isLoading: !1
|
|
317
|
-
})),
|
|
194
|
+
})), g;
|
|
318
195
|
}
|
|
319
196
|
},
|
|
320
|
-
[
|
|
321
|
-
),
|
|
197
|
+
[o, L, x, S, y, t]
|
|
198
|
+
), k = P(
|
|
322
199
|
() => ({
|
|
323
|
-
setPage: (
|
|
324
|
-
let
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
200
|
+
setPage: (m, d) => {
|
|
201
|
+
let g = m;
|
|
202
|
+
m === 0 && (g = "");
|
|
203
|
+
const u = { ...t, page: g };
|
|
204
|
+
f(u), g && w(d, u);
|
|
328
205
|
},
|
|
329
|
-
setPerPage: (
|
|
330
|
-
const
|
|
331
|
-
|
|
206
|
+
setPerPage: (m) => {
|
|
207
|
+
const d = { ...t, perPage: m, page: 1 };
|
|
208
|
+
f(d), w({}, d);
|
|
332
209
|
},
|
|
333
|
-
setSearch: (
|
|
334
|
-
if (
|
|
335
|
-
const
|
|
336
|
-
|
|
210
|
+
setSearch: (m) => {
|
|
211
|
+
if (m !== t.search) {
|
|
212
|
+
const d = { ...t, search: m, page: 1 };
|
|
213
|
+
f(d), w({}, d);
|
|
337
214
|
}
|
|
338
215
|
},
|
|
339
|
-
setSort: ({ by:
|
|
340
|
-
const
|
|
341
|
-
|
|
216
|
+
setSort: ({ by: m, order: d }) => {
|
|
217
|
+
const g = { ...t, sortBy: m, sortOrder: d, page: 1 };
|
|
218
|
+
f(g), w({}, g);
|
|
342
219
|
},
|
|
343
220
|
loadMore: () => {
|
|
344
|
-
const
|
|
345
|
-
|
|
221
|
+
const m = { ...t, page: t.page + 1 };
|
|
222
|
+
f(m), w({}, m);
|
|
346
223
|
},
|
|
347
|
-
refresh: (
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
|
|
224
|
+
refresh: (m = { isRefresh: !0 }) => {
|
|
225
|
+
if (x) {
|
|
226
|
+
const d = { ...t, page: 1, items: [] };
|
|
227
|
+
f(d), w(m, d);
|
|
351
228
|
} else
|
|
352
|
-
|
|
229
|
+
w(m);
|
|
353
230
|
},
|
|
354
|
-
setFilters: (
|
|
355
|
-
const
|
|
356
|
-
|
|
231
|
+
setFilters: (m) => {
|
|
232
|
+
const d = { ...t, filters: m, page: 1 };
|
|
233
|
+
f(d), w({}, d);
|
|
357
234
|
},
|
|
358
|
-
|
|
235
|
+
updateItemById: (m, d) => {
|
|
236
|
+
const g = t.items.map((u) => u.id === d ? { ...u, ...m } : u);
|
|
237
|
+
f((u) => ({ ...u, items: g }));
|
|
238
|
+
},
|
|
239
|
+
setSelection: (m) => f((d) => ({ ...d, selection: m }))
|
|
359
240
|
}),
|
|
360
|
-
[
|
|
361
|
-
),
|
|
241
|
+
[w, x, t]
|
|
242
|
+
), b = P(
|
|
362
243
|
() => ({
|
|
363
|
-
data:
|
|
364
|
-
response:
|
|
365
|
-
error:
|
|
366
|
-
count:
|
|
367
|
-
selection:
|
|
244
|
+
data: t.items,
|
|
245
|
+
response: t.response,
|
|
246
|
+
error: t.error,
|
|
247
|
+
count: t.count,
|
|
248
|
+
selection: t.selection,
|
|
368
249
|
pagination: {
|
|
369
|
-
page:
|
|
370
|
-
perPage:
|
|
371
|
-
hasMore:
|
|
250
|
+
page: t.page,
|
|
251
|
+
perPage: t.perPage,
|
|
252
|
+
hasMore: t.items.length < t.count
|
|
372
253
|
},
|
|
373
254
|
loader: {
|
|
374
|
-
isLoading:
|
|
375
|
-
initialLoading:
|
|
255
|
+
isLoading: t.isLoading,
|
|
256
|
+
initialLoading: t.initializingState
|
|
376
257
|
},
|
|
377
|
-
sort: { sortBy:
|
|
378
|
-
search:
|
|
379
|
-
filters:
|
|
380
|
-
attrs:
|
|
381
|
-
isEmpty:
|
|
382
|
-
...
|
|
258
|
+
sort: { sortBy: t.sortBy, sortOrder: t.sortOrder },
|
|
259
|
+
search: t.search,
|
|
260
|
+
filters: t.filters,
|
|
261
|
+
attrs: c || Object.keys(t.items[0] || {}),
|
|
262
|
+
isEmpty: t.items.length === 0,
|
|
263
|
+
...k
|
|
383
264
|
}),
|
|
384
265
|
[
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
266
|
+
t.items,
|
|
267
|
+
t.response,
|
|
268
|
+
t.error,
|
|
269
|
+
t.count,
|
|
270
|
+
t.selection,
|
|
271
|
+
t.page,
|
|
272
|
+
t.perPage,
|
|
273
|
+
t.isLoading,
|
|
274
|
+
t.initializingState,
|
|
275
|
+
t.sortBy,
|
|
276
|
+
t.sortOrder,
|
|
277
|
+
t.search,
|
|
278
|
+
t.filters,
|
|
279
|
+
k,
|
|
280
|
+
c
|
|
400
281
|
]
|
|
401
282
|
);
|
|
402
|
-
return
|
|
403
|
-
|
|
404
|
-
}, []),
|
|
405
|
-
|
|
283
|
+
return E(() => {
|
|
284
|
+
t.initializingState && k.setPage(t.page);
|
|
285
|
+
}, []), E(() => {
|
|
286
|
+
v(b);
|
|
406
287
|
}, [
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
288
|
+
v,
|
|
289
|
+
t.items,
|
|
290
|
+
t.count,
|
|
291
|
+
t.error,
|
|
292
|
+
t.isLoading,
|
|
293
|
+
t.selection,
|
|
294
|
+
t.page,
|
|
295
|
+
t.perPage,
|
|
296
|
+
t.sortBy,
|
|
297
|
+
t.sortOrder
|
|
298
|
+
]), typeof n == "function" ? n(b) : n;
|
|
299
|
+
}, V = R(({ children: n }) => {
|
|
300
|
+
const { listState: o } = C(), { data: r, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: c, perPage: L } = s, { isLoading: l } = p, S = P(
|
|
301
|
+
() => c * L < e,
|
|
302
|
+
[c, L, e]
|
|
303
|
+
), y = O(() => {
|
|
304
|
+
S && !l && a(c + 1);
|
|
305
|
+
}, [S, l, a, c]), v = P(
|
|
423
306
|
() => ({
|
|
424
|
-
|
|
425
|
-
padding: "8px 16px",
|
|
426
|
-
backgroundColor: "#4B5563",
|
|
427
|
-
color: "#ffffff",
|
|
428
|
-
border: "none",
|
|
429
|
-
borderRadius: "4px",
|
|
430
|
-
cursor: "pointer",
|
|
431
|
-
opacity: u || !d ? 0.5 : 1,
|
|
432
|
-
pointerEvents: u || !d ? "none" : "auto"
|
|
433
|
-
}
|
|
434
|
-
}),
|
|
435
|
-
[u, d]
|
|
436
|
-
), w = g(
|
|
437
|
-
() => ({
|
|
438
|
-
isLoading: u,
|
|
307
|
+
isLoading: l,
|
|
439
308
|
loadMore: y,
|
|
440
|
-
hasMoreItems:
|
|
441
|
-
styles: P
|
|
309
|
+
hasMoreItems: S
|
|
442
310
|
}),
|
|
443
|
-
[
|
|
311
|
+
[l, y, S]
|
|
444
312
|
);
|
|
445
|
-
return !r || r.length === 0 ||
|
|
446
|
-
}),
|
|
447
|
-
const { listState: r } =
|
|
448
|
-
|
|
449
|
-
overlay: {
|
|
450
|
-
position: "absolute",
|
|
451
|
-
top: 0,
|
|
452
|
-
left: 0,
|
|
453
|
-
right: 0,
|
|
454
|
-
bottom: 0,
|
|
455
|
-
backgroundColor: "rgba(255, 255, 255, 0.5)",
|
|
456
|
-
zIndex: 10
|
|
457
|
-
},
|
|
458
|
-
before: {
|
|
459
|
-
marginBottom: "16px"
|
|
460
|
-
},
|
|
461
|
-
after: {
|
|
462
|
-
marginTop: "16px"
|
|
463
|
-
},
|
|
464
|
-
defaultLoader: {
|
|
465
|
-
display: "flex",
|
|
466
|
-
alignItems: "center",
|
|
467
|
-
justifyContent: "center",
|
|
468
|
-
height: "100%"
|
|
469
|
-
},
|
|
470
|
-
loadingText: {
|
|
471
|
-
color: "#4B5563",
|
|
472
|
-
fontSize: "14px"
|
|
473
|
-
}
|
|
474
|
-
}),
|
|
475
|
-
[]
|
|
476
|
-
), f = g(
|
|
313
|
+
return !r || r.length === 0 || h ? null : n(v);
|
|
314
|
+
}), X = R(({ children: n, position: o = "overlay" }) => {
|
|
315
|
+
const { listState: r } = C(), { loader: e } = r, { isLoading: s, initializingState: a } = e;
|
|
316
|
+
return P(
|
|
477
317
|
() => ({
|
|
478
|
-
|
|
479
|
-
before: s.before,
|
|
480
|
-
after: s.after
|
|
318
|
+
isLoading: s
|
|
481
319
|
}),
|
|
482
320
|
[s]
|
|
483
|
-
), a
|
|
484
|
-
|
|
485
|
-
isLoading: o,
|
|
486
|
-
styles: s
|
|
487
|
-
}),
|
|
488
|
-
[o, s]
|
|
489
|
-
);
|
|
490
|
-
return !n && !o ? null : /* @__PURE__ */ l("div", { style: f[c] || {}, children: i ? i(a) : /* @__PURE__ */ l("div", { style: s.defaultLoader, children: /* @__PURE__ */ l("p", { style: s.loadingText, children: "Loading..." }) }) });
|
|
491
|
-
}), ee = R(
|
|
321
|
+
), !a && !s ? null : /* @__PURE__ */ i("div", { children: n || /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("p", { children: "Loading..." }) }) });
|
|
322
|
+
}), Y = R(
|
|
492
323
|
({
|
|
493
|
-
children:
|
|
494
|
-
pageLinks:
|
|
324
|
+
children: n,
|
|
325
|
+
pageLinks: o = 5,
|
|
495
326
|
renderFirst: r,
|
|
496
|
-
renderPrev:
|
|
497
|
-
renderPages:
|
|
498
|
-
renderPage:
|
|
499
|
-
renderNext:
|
|
500
|
-
renderLast:
|
|
327
|
+
renderPrev: e,
|
|
328
|
+
renderPages: s,
|
|
329
|
+
renderPage: a,
|
|
330
|
+
renderNext: p,
|
|
331
|
+
renderLast: h
|
|
501
332
|
}) => {
|
|
502
|
-
const { listState:
|
|
503
|
-
()
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
button: {
|
|
510
|
-
padding: "4px 8px",
|
|
511
|
-
border: "1px solid #e5e7eb",
|
|
512
|
-
borderRadius: "4px",
|
|
513
|
-
cursor: "pointer",
|
|
514
|
-
backgroundColor: "#ffffff",
|
|
515
|
-
minWidth: "60px",
|
|
516
|
-
fontSize: "14px"
|
|
517
|
-
},
|
|
518
|
-
disabledButton: {
|
|
519
|
-
opacity: 0.5,
|
|
520
|
-
cursor: "not-allowed"
|
|
521
|
-
},
|
|
522
|
-
pagesContainer: {
|
|
523
|
-
display: "flex",
|
|
524
|
-
alignItems: "center",
|
|
525
|
-
gap: "4px"
|
|
526
|
-
},
|
|
527
|
-
activePageSpan: {
|
|
528
|
-
padding: "4px 8px",
|
|
529
|
-
backgroundColor: "#2563eb",
|
|
530
|
-
color: "#ffffff",
|
|
531
|
-
borderRadius: "4px",
|
|
532
|
-
minWidth: "32px",
|
|
533
|
-
textAlign: "center"
|
|
534
|
-
},
|
|
535
|
-
pageButton: {
|
|
536
|
-
padding: "4px 8px",
|
|
537
|
-
border: "1px solid #e5e7eb",
|
|
538
|
-
borderRadius: "4px",
|
|
539
|
-
minWidth: "32px",
|
|
540
|
-
textAlign: "center",
|
|
541
|
-
cursor: "pointer",
|
|
542
|
-
backgroundColor: "#ffffff",
|
|
543
|
-
":hover": {
|
|
544
|
-
backgroundColor: "#f3f4f6"
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}),
|
|
548
|
-
[]
|
|
549
|
-
), C = g(() => {
|
|
550
|
-
const S = Math.ceil(u / e), B = Math.floor(c / 2), N = p * e < u;
|
|
551
|
-
return { pagesCount: S, halfWay: B, hasNext: N, hasPrev: p !== 1 };
|
|
552
|
-
}, [u, e, p, c]), b = g(() => {
|
|
553
|
-
const { pagesCount: S, halfWay: B } = C, N = Array.from({ length: Math.min(c, S) });
|
|
554
|
-
return p <= B ? N.map((A, W) => W + 1) : S - p < B ? N.map((A, W) => S - W).reverse() : N.map((A, W) => p - B + W);
|
|
555
|
-
}, [p, c, C]), x = g(
|
|
333
|
+
const { listState: c } = C(), { data: L, count: l, pagination: S, setPage: y, loader: v, error: x } = c, { page: t, perPage: f } = S, { initialLoading: w, isLoading: k } = v, b = P(() => {
|
|
334
|
+
const u = Math.ceil(l / f), M = Math.floor(o / 2), z = t * f < l;
|
|
335
|
+
return { pagesCount: u, halfWay: M, hasNext: z, hasPrev: t !== 1 };
|
|
336
|
+
}, [l, f, t, o]), m = P(() => {
|
|
337
|
+
const { pagesCount: u, halfWay: M } = b, z = Array.from({ length: Math.min(o, u) });
|
|
338
|
+
return t <= M ? z.map((I, B) => B + 1) : u - t < M ? z.map((I, B) => u - B).reverse() : z.map((I, B) => t - M + B);
|
|
339
|
+
}, [t, o, b]), d = P(
|
|
556
340
|
() => ({
|
|
557
|
-
prev: () => y(
|
|
558
|
-
next: () => y(
|
|
341
|
+
prev: () => y(t - 1),
|
|
342
|
+
next: () => y(t + 1),
|
|
559
343
|
first: () => y(1),
|
|
560
|
-
last: () => y(
|
|
561
|
-
setPage: (
|
|
344
|
+
last: () => y(b.pagesCount),
|
|
345
|
+
setPage: (u) => y(u)
|
|
562
346
|
}),
|
|
563
|
-
[y,
|
|
564
|
-
),
|
|
347
|
+
[y, t, b.pagesCount]
|
|
348
|
+
), g = P(
|
|
565
349
|
() => ({
|
|
566
|
-
page:
|
|
567
|
-
perPage:
|
|
568
|
-
count:
|
|
569
|
-
...
|
|
570
|
-
pagesToDisplay:
|
|
571
|
-
...
|
|
572
|
-
styles: v
|
|
350
|
+
page: t,
|
|
351
|
+
perPage: f,
|
|
352
|
+
count: l,
|
|
353
|
+
...b,
|
|
354
|
+
pagesToDisplay: m,
|
|
355
|
+
...d
|
|
573
356
|
}),
|
|
574
|
-
[
|
|
575
|
-
p,
|
|
576
|
-
e,
|
|
577
|
-
u,
|
|
578
|
-
C,
|
|
579
|
-
b,
|
|
580
|
-
x,
|
|
581
|
-
v
|
|
582
|
-
]
|
|
357
|
+
[t, f, l, b, m, d]
|
|
583
358
|
);
|
|
584
|
-
return
|
|
585
|
-
r ? r(
|
|
359
|
+
return w || !L || L.length === 0 || x ? null : n ? n(g) : /* @__PURE__ */ N("div", { className: "react-list-pagination", children: [
|
|
360
|
+
r ? r(g) : /* @__PURE__ */ i(
|
|
586
361
|
"button",
|
|
587
362
|
{
|
|
588
363
|
type: "button",
|
|
589
|
-
disabled: !
|
|
590
|
-
onClick:
|
|
591
|
-
style: {
|
|
592
|
-
...v.button,
|
|
593
|
-
...!C.hasPrev && v.disabledButton
|
|
594
|
-
},
|
|
364
|
+
disabled: !b.hasPrev,
|
|
365
|
+
onClick: d.first,
|
|
595
366
|
children: "First"
|
|
596
367
|
}
|
|
597
368
|
),
|
|
598
|
-
|
|
369
|
+
e ? e(g) : /* @__PURE__ */ i(
|
|
599
370
|
"button",
|
|
600
371
|
{
|
|
601
372
|
type: "button",
|
|
602
|
-
disabled: !
|
|
603
|
-
onClick:
|
|
604
|
-
style: {
|
|
605
|
-
...v.button,
|
|
606
|
-
...!C.hasPrev && v.disabledButton
|
|
607
|
-
},
|
|
373
|
+
disabled: !b.hasPrev,
|
|
374
|
+
onClick: d.prev,
|
|
608
375
|
children: "Prev"
|
|
609
376
|
}
|
|
610
377
|
),
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
return
|
|
378
|
+
s ? s(g) : /* @__PURE__ */ i("div", { children: m.map((u) => {
|
|
379
|
+
const M = u === t, z = { ...g, page: u, isActive: M };
|
|
380
|
+
return a ? a(z) : /* @__PURE__ */ i("div", { children: M ? /* @__PURE__ */ i("span", { children: u }) : /* @__PURE__ */ i(
|
|
614
381
|
"button",
|
|
615
382
|
{
|
|
616
383
|
type: "button",
|
|
617
|
-
onClick: () =>
|
|
618
|
-
|
|
619
|
-
children: S
|
|
384
|
+
onClick: () => d.setPage(u),
|
|
385
|
+
children: u
|
|
620
386
|
}
|
|
621
|
-
) }, `page-${
|
|
387
|
+
) }, `page-${u}`);
|
|
622
388
|
}) }),
|
|
623
|
-
|
|
389
|
+
p ? p(g) : /* @__PURE__ */ i(
|
|
624
390
|
"button",
|
|
625
391
|
{
|
|
626
392
|
type: "button",
|
|
627
|
-
disabled: !
|
|
628
|
-
onClick:
|
|
629
|
-
style: {
|
|
630
|
-
...v.button,
|
|
631
|
-
...!C.hasNext && v.disabledButton
|
|
632
|
-
},
|
|
393
|
+
disabled: !b.hasNext,
|
|
394
|
+
onClick: d.next,
|
|
633
395
|
children: "Next"
|
|
634
396
|
}
|
|
635
397
|
),
|
|
636
|
-
|
|
398
|
+
h ? h(g) : /* @__PURE__ */ i(
|
|
637
399
|
"button",
|
|
638
400
|
{
|
|
639
401
|
type: "button",
|
|
640
|
-
disabled: !
|
|
641
|
-
onClick:
|
|
642
|
-
style: {
|
|
643
|
-
...v.button,
|
|
644
|
-
...!C.hasNext && v.disabledButton
|
|
645
|
-
},
|
|
402
|
+
disabled: !b.hasNext,
|
|
403
|
+
onClick: d.last,
|
|
646
404
|
children: "Last"
|
|
647
405
|
}
|
|
648
406
|
)
|
|
649
407
|
] });
|
|
650
408
|
}
|
|
651
|
-
),
|
|
652
|
-
({ children:
|
|
653
|
-
const { listState: r } =
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
select: {
|
|
660
|
-
width: "100%",
|
|
661
|
-
padding: "8px 12px",
|
|
662
|
-
border: "1px solid #e5e7eb",
|
|
663
|
-
borderRadius: "4px",
|
|
664
|
-
fontSize: "14px",
|
|
665
|
-
backgroundColor: "#ffffff",
|
|
666
|
-
cursor: "pointer",
|
|
667
|
-
outline: "none"
|
|
668
|
-
}
|
|
669
|
-
}),
|
|
670
|
-
[]
|
|
671
|
-
), y = g(() => c.map((p) => typeof p != "object" ? {
|
|
672
|
-
value: p,
|
|
673
|
-
label: p
|
|
674
|
-
} : p), [c]), P = T(
|
|
675
|
-
(p) => {
|
|
676
|
-
n(Number(p.target.value));
|
|
409
|
+
), Z = R(
|
|
410
|
+
({ children: n, options: o = [10, 25, 50, 100] }) => {
|
|
411
|
+
const { listState: r } = C(), { data: e, pagination: s, setPerPage: a, loader: p, error: h } = r, { perPage: c } = s, { initialLoading: L } = p, l = P(() => o.map((v) => typeof v != "object" ? {
|
|
412
|
+
value: v,
|
|
413
|
+
label: v
|
|
414
|
+
} : v), [o]), S = O(
|
|
415
|
+
(v) => {
|
|
416
|
+
a(Number(v.target.value));
|
|
677
417
|
},
|
|
678
|
-
[
|
|
679
|
-
),
|
|
418
|
+
[a]
|
|
419
|
+
), y = P(
|
|
680
420
|
() => ({
|
|
681
|
-
perPage:
|
|
682
|
-
setPerPage:
|
|
683
|
-
options:
|
|
684
|
-
styles: d
|
|
421
|
+
perPage: c,
|
|
422
|
+
setPerPage: a,
|
|
423
|
+
options: l
|
|
685
424
|
}),
|
|
686
|
-
[
|
|
425
|
+
[c, a, l]
|
|
687
426
|
);
|
|
688
|
-
return
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
onChange: P,
|
|
693
|
-
style: d.select,
|
|
694
|
-
children: y.map((p) => /* @__PURE__ */ M("option", { value: p.value, children: [
|
|
695
|
-
p.label,
|
|
696
|
-
" items per page"
|
|
697
|
-
] }, `option-${p.value}`))
|
|
698
|
-
}
|
|
699
|
-
) });
|
|
427
|
+
return L || !e || e.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-per-page", children: n ? n(y) : /* @__PURE__ */ i("select", { value: c, onChange: S, children: l.map((v) => /* @__PURE__ */ N("option", { value: v.value, children: [
|
|
428
|
+
v.label,
|
|
429
|
+
" items per page"
|
|
430
|
+
] }, `option-${v.value}`)) }) });
|
|
700
431
|
}
|
|
701
|
-
),
|
|
702
|
-
const { listState:
|
|
703
|
-
(
|
|
704
|
-
|
|
705
|
-
display: "inline-block"
|
|
706
|
-
},
|
|
707
|
-
button: {
|
|
708
|
-
padding: "8px 16px",
|
|
709
|
-
border: "1px solid #e5e7eb",
|
|
710
|
-
borderRadius: "6px",
|
|
711
|
-
backgroundColor: "#ffffff",
|
|
712
|
-
cursor: "pointer",
|
|
713
|
-
fontSize: "14px",
|
|
714
|
-
transition: "all 0.2s ease",
|
|
715
|
-
":hover": {
|
|
716
|
-
backgroundColor: "#f3f4f6"
|
|
717
|
-
},
|
|
718
|
-
":disabled": {
|
|
719
|
-
opacity: 0.6,
|
|
720
|
-
cursor: "not-allowed"
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}),
|
|
724
|
-
[]
|
|
725
|
-
), f = T(() => {
|
|
726
|
-
t({ isRefresh: !0 });
|
|
727
|
-
}, [t]), a = g(
|
|
432
|
+
), tt = R(({ children: n }) => {
|
|
433
|
+
const { listState: o } = C(), { loader: r, refresh: e } = o, { isLoading: s, initialLoading: a } = r, p = O(() => {
|
|
434
|
+
e({ isRefresh: !0 });
|
|
435
|
+
}, [e]), h = P(
|
|
728
436
|
() => ({
|
|
729
|
-
isLoading:
|
|
730
|
-
refresh:
|
|
437
|
+
isLoading: s,
|
|
438
|
+
refresh: p
|
|
731
439
|
}),
|
|
732
|
-
[
|
|
440
|
+
[s, p]
|
|
733
441
|
);
|
|
734
|
-
return
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
) });
|
|
746
|
-
}), re = R(({ children: i, debounceTime: c = 500 }) => {
|
|
747
|
-
const { listState: r } = k(), { search: t, setSearch: o } = r, [n, s] = $(), [f, a] = O(t ?? ""), h = q(null);
|
|
748
|
-
I(() => {
|
|
749
|
-
t !== f && a(t ?? "");
|
|
750
|
-
}, [t]);
|
|
751
|
-
const u = (P) => {
|
|
752
|
-
const w = P.target.value;
|
|
753
|
-
a(w), h.current && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
754
|
-
s(() => {
|
|
755
|
-
o(w);
|
|
756
|
-
});
|
|
757
|
-
}, c);
|
|
442
|
+
return a ? null : n ? n(h) : /* @__PURE__ */ i("div", { className: "react-list-refresh", children: /* @__PURE__ */ i("button", { onClick: p, disabled: s, children: s ? "Loading..." : "Refresh" }) });
|
|
443
|
+
}), et = R(({ children: n, debounceTime: o = 500 }) => {
|
|
444
|
+
const { listState: r } = C(), { search: e, setSearch: s } = r, [a, p] = T(e ?? ""), h = q(null);
|
|
445
|
+
E(() => {
|
|
446
|
+
e !== a && p(e ?? "");
|
|
447
|
+
}, [e]);
|
|
448
|
+
const c = (l) => {
|
|
449
|
+
p(l), h.current && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
450
|
+
s(l);
|
|
451
|
+
}, o);
|
|
758
452
|
};
|
|
759
|
-
|
|
453
|
+
return E(() => () => {
|
|
760
454
|
h.current && clearTimeout(h.current);
|
|
761
|
-
}, [])
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
border: "1px solid #ccc",
|
|
772
|
-
borderRadius: "4px",
|
|
773
|
-
fontSize: "14px",
|
|
774
|
-
outline: "none"
|
|
455
|
+
}, []), /* @__PURE__ */ i("div", { className: "react-list-search", children: n ? n({
|
|
456
|
+
search: a,
|
|
457
|
+
setSearch: c
|
|
458
|
+
}) : /* @__PURE__ */ i(
|
|
459
|
+
"input",
|
|
460
|
+
{
|
|
461
|
+
type: "text",
|
|
462
|
+
value: a,
|
|
463
|
+
onChange: (l) => c(l.target.value),
|
|
464
|
+
placeholder: "Search..."
|
|
775
465
|
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
/* @__PURE__ */ l(
|
|
783
|
-
"input",
|
|
784
|
-
{
|
|
785
|
-
type: "text",
|
|
786
|
-
value: f,
|
|
787
|
-
onChange: u,
|
|
788
|
-
placeholder: "Search...",
|
|
789
|
-
style: d.input
|
|
790
|
-
}
|
|
791
|
-
),
|
|
792
|
-
n && /* @__PURE__ */ l(
|
|
793
|
-
"div",
|
|
794
|
-
{
|
|
795
|
-
className: "search-indicator",
|
|
796
|
-
style: { fontSize: "12px", color: "#888", marginTop: "4px" },
|
|
797
|
-
children: "Searching..."
|
|
798
|
-
}
|
|
799
|
-
)
|
|
800
|
-
] });
|
|
801
|
-
}), oe = R(({ children: i }) => {
|
|
802
|
-
const { listState: c } = k(), { data: r, count: t, pagination: o, loader: n, error: s } = c, { page: f, perPage: a } = o, { initialLoading: h, isLoading: u } = n, d = g(
|
|
803
|
-
() => ({
|
|
804
|
-
container: {
|
|
805
|
-
padding: "8px 0",
|
|
806
|
-
fontSize: "14px",
|
|
807
|
-
color: "#4B5563"
|
|
808
|
-
},
|
|
809
|
-
text: {
|
|
810
|
-
display: "inline-block"
|
|
811
|
-
},
|
|
812
|
-
highlight: {
|
|
813
|
-
fontWeight: "500",
|
|
814
|
-
color: "#111827"
|
|
815
|
-
}
|
|
816
|
-
}),
|
|
817
|
-
[]
|
|
818
|
-
), y = g(() => {
|
|
819
|
-
const w = f * a - a + 1, p = Math.min(f * a, t), e = (r == null ? void 0 : r.length) || 0;
|
|
820
|
-
return { from: w, to: p, visibleCount: e };
|
|
821
|
-
}, [f, a, t, r]), P = g(
|
|
466
|
+
) });
|
|
467
|
+
}), nt = R(({ children: n }) => {
|
|
468
|
+
const { listState: o } = C(), { data: r, count: e, pagination: s, loader: a, error: p } = o, { page: h, perPage: c } = s, { initialLoading: L, isLoading: l } = a, S = P(() => {
|
|
469
|
+
const v = h * c - c + 1, x = Math.min(h * c, e), t = (r == null ? void 0 : r.length) || 0;
|
|
470
|
+
return { from: v, to: x, visibleCount: t };
|
|
471
|
+
}, [h, c, e, r]), y = P(
|
|
822
472
|
() => ({
|
|
823
|
-
...
|
|
824
|
-
count:
|
|
825
|
-
styles: d
|
|
473
|
+
...S,
|
|
474
|
+
count: e
|
|
826
475
|
}),
|
|
827
|
-
[
|
|
476
|
+
[S, e]
|
|
828
477
|
);
|
|
829
|
-
return
|
|
478
|
+
return L || !r || r.length === 0 || p ? null : /* @__PURE__ */ i("div", { className: "react-list-summary", children: n ? n(y) : /* @__PURE__ */ N("span", { children: [
|
|
830
479
|
"Showing ",
|
|
831
|
-
/* @__PURE__ */
|
|
832
|
-
" ",
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
y.from,
|
|
480
|
+
/* @__PURE__ */ i("span", { children: S.visibleCount }),
|
|
481
|
+
" items (",
|
|
482
|
+
/* @__PURE__ */ N("span", { children: [
|
|
483
|
+
S.from,
|
|
836
484
|
" - ",
|
|
837
|
-
|
|
485
|
+
S.to
|
|
838
486
|
] }),
|
|
839
487
|
") out of ",
|
|
840
|
-
/* @__PURE__ */
|
|
488
|
+
/* @__PURE__ */ i("span", { children: e })
|
|
841
489
|
] }) });
|
|
842
490
|
});
|
|
843
491
|
export {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
492
|
+
W as ReactListAttributes,
|
|
493
|
+
F as ReactListEmpty,
|
|
494
|
+
G as ReactListError,
|
|
495
|
+
J as ReactListGoTo,
|
|
496
|
+
K as ReactListInitialLoader,
|
|
497
|
+
Q as ReactListItems,
|
|
498
|
+
V as ReactListLoadMore,
|
|
499
|
+
X as ReactListLoader,
|
|
500
|
+
Y as ReactListPagination,
|
|
501
|
+
Z as ReactListPerPage,
|
|
502
|
+
H as ReactListProvider,
|
|
503
|
+
tt as ReactListRefresh,
|
|
504
|
+
et as ReactListSearch,
|
|
505
|
+
nt as ReactListSummary,
|
|
506
|
+
U as default
|
|
859
507
|
};
|
package/dist/react-list.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(S,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(S=typeof globalThis<"u"?globalThis:S||self,n(S.ReactList={},S.jsxRuntime,S.react))})(this,function(S,n,e){"use strict";const I=e.createContext(null),W=({children:a,config:d})=>{const{requestHandler:i,stateManager:s={}}=d,[r,o]=e.useState({data:[],response:null,error:null,count:0,selection:[],pagination:{page:1,perPage:25},loader:{isLoading:!1,initialLoading:!0},sort:{sortBy:null,sortOrder:"desc"},search:"",filters:{},attrs:[],isEmpty:!0,isInitializing:!0});if(!i)throw new Error("ListProvider: requestHandler is required.");const l=e.useMemo(()=>({requestHandler:i,stateManager:s,listState:r,setListState:o}),[i,s,r]);return n.jsx(I.Provider,{value:l,children:a})},w=()=>{const a=e.useContext(I);if(!a)throw new Error("useListContext must be used within a ListProvider");return a},A=e.memo(({children:a,renderAttribute:d})=>{const{listState:i}=w(),{attrs:s,attrSettings:r,updateAttr:o}=i,l={container:{display:"flex",flexDirection:"column",gap:"12px",padding:"12px"},label:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"14px"},checkbox:{width:"16px",height:"16px",cursor:"pointer"}},f=e.useCallback(h=>g=>{o(h,"visible",g.target.checked)},[o]),c=e.useMemo(()=>({attrs:s,attrSettings:r,updateAttr:o,styles:l}),[s,r,o]);return a?a(c):n.jsx("div",{className:"react-list-attributes",style:l.container,children:s.map((h,g)=>{var u;return d?d({key:`attr-${g}`,attr:h,updateAttr:o,attrSettings:r,styles:l}):n.jsxs("label",{style:l.label,children:[n.jsx("span",{children:h.label}),n.jsx("input",{type:"checkbox",checked:((u=r==null?void 0:r[h.name])==null?void 0:u.visible)??!1,onChange:f(h.name),style:l.checkbox})]},`attr-${g}`)})})}),O=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,loader:s,error:r}=d,{isLoading:o,initialLoading:l}=s,f=e.useMemo(()=>({container:{width:"100%",padding:"32px 16px"},defaultMessage:{textAlign:"center",color:"#6B7280",fontSize:"16px",fontWeight:"400"}}),[]);return(i==null?void 0:i.length)>0||l||o||r?null:n.jsx("div",{className:"react-list-empty",style:f.container,children:a||n.jsx("div",{style:f.defaultMessage,children:n.jsx("p",{children:"No data found!"})})})}),j=e.memo(({children:a})=>{const{listState:d}=w(),{error:i,loader:s}=d,{isLoading:r}=s,o=e.useMemo(()=>({container:{width:"100%",padding:"32px 16px"},errorContent:{textAlign:"center",color:"#DC2626",padding:"32px 0"},heading:{fontSize:"16px",fontWeight:"500",marginBottom:"8px"},message:{fontSize:"14px",fontFamily:"monospace",marginTop:"8px",whiteSpace:"pre-wrap",wordBreak:"break-word"}}),[]);return!i||r?null:a?a({error:i}):n.jsx("div",{className:"react-list-error",style:o.container,children:n.jsxs("div",{style:o.errorContent,children:[n.jsx("h3",{style:o.heading,children:"Error occurred"}),n.jsxs("pre",{style:o.message,children:[i.name,": ",i.message]})]})})}),q=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,setPage:o,loader:l,error:f}=d,{page:c,perPage:h}=r,{initialLoading:g,isLoading:u}=l,y=e.useMemo(()=>({container:{display:"inline-block",minWidth:"120px"},select:{width:"100%",padding:"8px 12px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"14px",backgroundColor:"#fff",cursor:"pointer",outline:"none"}}),[]),{pages:P,pagesCount:k}=e.useMemo(()=>{const v=Math.ceil(s/h);return{pages:Array.from({length:v},(C,M)=>M+1),pagesCount:v}},[s,h]),p=e.useCallback(v=>{o(Number(v.target.value))},[o]),t=e.useMemo(()=>({setPage:o,page:c,pages:P,pagesCount:k,styles:y}),[o,c,P,k,y]);return g||!i||i.length===0||f?null:a?a(t):n.jsx("div",{className:"react-list-go-to",style:y.container,children:n.jsx("select",{value:c,onChange:p,style:y.select,children:P.map(v=>n.jsxs("option",{value:v,children:["Page ",v]},`page-${v}`))})})}),D=e.memo(({children:a})=>{const{listState:d}=w(),{loader:i}=d,{initialLoading:s}=i,r=e.useMemo(()=>({container:{padding:"20px",textAlign:"center"},defaultLoader:{fontSize:"16px",color:"#4B5563",margin:0,animation:"pulse 1.5s infinite ease-in-out"},"@keyframes pulse":{"0%":{opacity:.6},"50%":{opacity:1},"100%":{opacity:.6}}}),[]),o=e.useMemo(()=>({loading:s,styles:r}),[s]);return s?n.jsx("div",{className:"react-list-initial-loader",style:r.container,children:a?a(o):n.jsx("p",{style:r.defaultLoader,children:"Initial Loading..."})}):null}),_=e.memo(({children:a,renderItem:d})=>{const{listState:i}=w(),{data:s=[],loader:r,error:o}=i,{initialLoading:l,isLoading:f}=r,c=e.useMemo(()=>({container:{display:"flex",flexDirection:"column",gap:"12px",width:"100%"},itemWrapper:{width:"100%"},defaultItem:{padding:"12px",backgroundColor:"#f9fafb",borderRadius:"4px",fontFamily:"monospace",fontSize:"14px",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"}}),[]),h=e.useMemo(()=>({items:s,styles:c}),[s,c]);return l||!s||s.length===0||o?null:d?n.jsx("div",{className:"react-list-items",style:c.container,children:s.map((g,u)=>n.jsx("div",{style:c.itemWrapper,children:d({item:g,index:u,styles:c})},g.id||u))}):typeof a=="function"?n.jsx("div",{className:"react-list-items",style:c.container,children:a(h)}):n.jsx("div",{className:"react-list-items",style:c.container,children:s.map((g,u)=>n.jsx("pre",{style:c.defaultItem,children:JSON.stringify(g,null,2)},g.id||u))})}),$=({children:a,endpoint:d,page:i=1,perPage:s=25,sortBy:r,sortOrder:o="desc",search:l="",filters:f={},attrs:c,version:h=1,hasPaginationHistory:g=!0,paginationMode:u="pagination",meta:y={}})=>{const{requestHandler:P,setListState:k}=w(),p=u==="loadMore",[t,v]=e.useState({page:i,perPage:s,sortBy:r,sortOrder:o,search:l,filters:f,attrSettings:{},items:[],selection:[],error:null,response:null,count:0,isLoading:!1,initializingState:!0}),z=e.useCallback(async(x={},m=null)=>{t.initializingState||v(b=>({...b,error:null,isLoading:!0}));try{const b=m||t,L=await P({endpoint:d,version:h,meta:y,page:b.page,perPage:b.perPage,search:b.search,sortBy:b.sortBy,sortOrder:b.sortOrder,filters:b.filters,...x});v(B=>({...B,response:L,selection:[],items:p?[...B.items,...L.items]:L.items,count:L.count,initializingState:!1,isLoading:!1}))}catch(b){throw v(L=>({...L,error:b,items:[],count:0,initializingState:!1,isLoading:!1})),b}},[d,h,p,y,P,t]),C=e.useMemo(()=>({setPage:(x,m)=>{let b=x;x===0&&(b="");const L={...t,page:b};v(L),b&&z(m,L)},setPerPage:x=>{const m={...t,perPage:x,page:1};v(m),z({},m)},setSearch:x=>{if(x!==t.search){const m={...t,search:x,page:1};v(m),z({},m)}},setSort:({by:x,order:m})=>{const b={...t,sortBy:x,sortOrder:m,page:1};v(b),z({},b)},loadMore:()=>{const x={...t,page:t.page+1};v(x),z({},x)},refresh:(x={isRefresh:!0})=>{if(p){const m={...t,page:1,items:[]};v(m),z(x,m)}else z(x)},setFilters:x=>{const m={...t,filters:x,page:1};v(m),z({},m)},setSelection:x=>v(m=>({...m,selection:x}))}),[z,p,t]),M=e.useMemo(()=>({data:t.items,response:t.response,error:t.error,count:t.count,selection:t.selection,pagination:{page:t.page,perPage:t.perPage,hasMore:t.items.length<t.count},loader:{isLoading:t.isLoading,initialLoading:t.initializingState},sort:{sortBy:t.sortBy,sortOrder:t.sortOrder},search:t.search,filters:t.filters,attrs:c||Object.keys(t.items[0]||{}),isEmpty:t.items.length===0,...C}),[t.items,t.response,t.error,t.count,t.selection,t.page,t.perPage,t.isLoading,t.initializingState,t.sortBy,t.sortOrder,t.search,t.filters,C,c]);return e.useEffect(()=>{t.initializingState&&C.setPage(t.page)},[]),e.useEffect(()=>{k(M)},[k,t.items,t.count,t.error,t.isLoading,t.selection,t.page,t.perPage]),a({...M})},H=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,setPage:o,loader:l,error:f}=d,{page:c,perPage:h}=r,{isLoading:g}=l,u=e.useMemo(()=>c*h<s,[c,h,s]),y=e.useCallback(()=>{u&&!g&&o(c+1)},[u,g,o,c]),P=e.useMemo(()=>({button:{padding:"8px 16px",backgroundColor:"#4B5563",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",opacity:g||!u?.5:1,pointerEvents:g||!u?"none":"auto"}}),[g,u]),k=e.useMemo(()=>({isLoading:g,loadMore:y,hasMoreItems:u,styles:P}),[g,y,u,P]);return!i||i.length===0||f?null:a(k)}),F=e.memo(({children:a,position:d="overlay"})=>{const{listState:i}=w(),{loader:s}=i,{isLoading:r,initializingState:o}=s,l=e.useMemo(()=>({overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.5)",zIndex:10},before:{marginBottom:"16px"},after:{marginTop:"16px"},defaultLoader:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%"},loadingText:{color:"#4B5563",fontSize:"14px"}}),[]),f=e.useMemo(()=>({overlay:l.overlay,before:l.before,after:l.after}),[l]),c=e.useMemo(()=>({isLoading:r,styles:l}),[r,l]);return!o&&!r?null:n.jsx("div",{style:f[d]||{},children:a?a(c):n.jsx("div",{style:l.defaultLoader,children:n.jsx("p",{style:l.loadingText,children:"Loading..."})})})}),G=e.memo(({children:a,pageLinks:d=5,renderFirst:i,renderPrev:s,renderPages:r,renderPage:o,renderNext:l,renderLast:f})=>{const{listState:c}=w(),{data:h,count:g,pagination:u,setPage:y,loader:P,error:k}=c,{page:p,perPage:t}=u,{initialLoading:v,isLoading:z}=P,C=e.useMemo(()=>({container:{display:"flex",alignItems:"center",gap:"8px"},button:{padding:"4px 8px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer",backgroundColor:"#ffffff",minWidth:"60px",fontSize:"14px"},disabledButton:{opacity:.5,cursor:"not-allowed"},pagesContainer:{display:"flex",alignItems:"center",gap:"4px"},activePageSpan:{padding:"4px 8px",backgroundColor:"#2563eb",color:"#ffffff",borderRadius:"4px",minWidth:"32px",textAlign:"center"},pageButton:{padding:"4px 8px",border:"1px solid #e5e7eb",borderRadius:"4px",minWidth:"32px",textAlign:"center",cursor:"pointer",backgroundColor:"#ffffff",":hover":{backgroundColor:"#f3f4f6"}}}),[]),M=e.useMemo(()=>{const L=Math.ceil(g/t),B=Math.floor(d/2),T=p*t<g;return{pagesCount:L,halfWay:B,hasNext:T,hasPrev:p!==1}},[g,t,p,d]),x=e.useMemo(()=>{const{pagesCount:L,halfWay:B}=M,T=Array.from({length:Math.min(d,L)});return p<=B?T.map((E,N)=>N+1):L-p<B?T.map((E,N)=>L-N).reverse():T.map((E,N)=>p-B+N)},[p,d,M]),m=e.useMemo(()=>({prev:()=>y(p-1),next:()=>y(p+1),first:()=>y(1),last:()=>y(M.pagesCount),setPage:L=>y(L)}),[y,p,M.pagesCount]),b=e.useMemo(()=>({page:p,perPage:t,count:g,...M,pagesToDisplay:x,...m,styles:C}),[p,t,g,M,x,m,C]);return v||!h||h.length===0||k?null:a?a(b):n.jsxs("div",{style:C.container,children:[i?i(b):n.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:m.first,style:{...C.button,...!M.hasPrev&&C.disabledButton},children:"First"}),s?s(b):n.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:m.prev,style:{...C.button,...!M.hasPrev&&C.disabledButton},children:"Prev"}),r?r(b):n.jsx("div",{style:C.pagesContainer,children:x.map(L=>{const B=L===p,T={...b,page:L,isActive:B};return o?o(T):n.jsx("div",{children:B?n.jsx("span",{style:C.activePageSpan,children:L}):n.jsx("button",{type:"button",onClick:()=>m.setPage(L),style:C.pageButton,children:L})},`page-${L}`)})}),l?l(b):n.jsx("button",{type:"button",disabled:!M.hasNext,onClick:m.next,style:{...C.button,...!M.hasNext&&C.disabledButton},children:"Next"}),f?f(b):n.jsx("button",{type:"button",disabled:!M.hasNext,onClick:m.last,style:{...C.button,...!M.hasNext&&C.disabledButton},children:"Last"})]})}),R=e.memo(({children:a,options:d=[10,25,50,100]})=>{const{listState:i}=w(),{data:s,pagination:r,setPerPage:o,loader:l,error:f}=i,{perPage:c}=r,{initialLoading:h,isLoading:g}=l,u=e.useMemo(()=>({container:{display:"inline-block",minWidth:"150px"},select:{width:"100%",padding:"8px 12px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",backgroundColor:"#ffffff",cursor:"pointer",outline:"none"}}),[]),y=e.useMemo(()=>d.map(p=>typeof p!="object"?{value:p,label:p}:p),[d]),P=e.useCallback(p=>{o(Number(p.target.value))},[o]),k=e.useMemo(()=>({perPage:c,setPerPage:o,options:y,styles:u}),[c,o,y,u]);return h||!s||s.length===0||f?null:a?a(k):n.jsx("div",{className:"react-list-per-page",style:u.container,children:n.jsx("select",{value:c,onChange:P,style:u.select,children:y.map(p=>n.jsxs("option",{value:p.value,children:[p.label," items per page"]},`option-${p.value}`))})})}),J=e.memo(({children:a})=>{const{listState:d}=w(),{loader:i,refresh:s}=d,{isLoading:r,initialLoading:o}=i,l=e.useMemo(()=>({container:{display:"inline-block"},button:{padding:"8px 16px",border:"1px solid #e5e7eb",borderRadius:"6px",backgroundColor:"#ffffff",cursor:"pointer",fontSize:"14px",transition:"all 0.2s ease",":hover":{backgroundColor:"#f3f4f6"},":disabled":{opacity:.6,cursor:"not-allowed"}}}),[]),f=e.useCallback(()=>{s({isRefresh:!0})},[s]),c=e.useMemo(()=>({isLoading:r,refresh:f}),[r,f,l]);return o?null:a?a(c):n.jsx("div",{className:"react-list-refresh",style:l.container,children:n.jsx("button",{onClick:f,disabled:r,style:{...l.button,...r&&l.button[":disabled"]},children:r?"Loading...":"Refresh"})})}),K=e.memo(({children:a,debounceTime:d=500})=>{const{listState:i}=w(),{search:s,setSearch:r}=i,[o,l]=e.useTransition(),[f,c]=e.useState(s??""),h=e.useRef(null);e.useEffect(()=>{s!==f&&c(s??"")},[s]);const g=P=>{const k=P.target.value;c(k),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{l(()=>{r(k)})},d)};e.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const u={container:{margin:"10px 0",width:"100%",maxWidth:"300px"},input:{width:"100%",padding:"8px 12px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"14px",outline:"none"}},y={search:f,setSearch:g,isPending:o};return a?a(y):n.jsxs("div",{className:"react-list-search",style:u.container,children:[n.jsx("input",{type:"text",value:f,onChange:g,placeholder:"Search...",style:u.input}),o&&n.jsx("div",{className:"search-indicator",style:{fontSize:"12px",color:"#888",marginTop:"4px"},children:"Searching..."})]})}),Q=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,loader:o,error:l}=d,{page:f,perPage:c}=r,{initialLoading:h,isLoading:g}=o,u=e.useMemo(()=>({container:{padding:"8px 0",fontSize:"14px",color:"#4B5563"},text:{display:"inline-block"},highlight:{fontWeight:"500",color:"#111827"}}),[]),y=e.useMemo(()=>{const k=f*c-c+1,p=Math.min(f*c,s),t=(i==null?void 0:i.length)||0;return{from:k,to:p,visibleCount:t}},[f,c,s,i]),P=e.useMemo(()=>({...y,count:s,styles:u}),[y,s,u]);return h||!i||i.length===0||l?null:a?a(P):n.jsx("div",{className:"react-list-summary",style:u.container,children:n.jsxs("span",{style:u.text,children:["Showing ",n.jsx("span",{style:u.highlight,children:y.visibleCount})," ","items (",n.jsxs("span",{style:u.highlight,children:[y.from," - ",y.to]}),") out of ",n.jsx("span",{style:u.highlight,children:s})]})})});S.ReactListAttributes=A,S.ReactListEmpty=O,S.ReactListError=j,S.ReactListGoTo=q,S.ReactListInitialLoader=D,S.ReactListItems=_,S.ReactListLoadMore=H,S.ReactListLoader=F,S.ReactListPagination=G,S.ReactListPerPage=R,S.ReactListProvider=W,S.ReactListRefresh=J,S.ReactListSearch=K,S.ReactListSummary=Q,S.default=$,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(y,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],s):(y=typeof globalThis<"u"?globalThis:y||self,s(y.ReactList={},y.jsxRuntime,y.react))})(this,function(y,s,n){"use strict";const B=n.createContext(null),I=({children:a,config:l})=>{const{requestHandler:o,stateManager:t={}}=l,[r,i]=n.useState({data:[],response:null,error:null,count:0,selection:[],pagination:{page:1,perPage:25},loader:{isLoading:!1,initialLoading:!0},sort:{sortBy:null,sortOrder:"desc"},search:"",filters:{},attrs:[],isEmpty:!0,isInitializing:!0});if(!o)throw new Error("ListProvider: requestHandler is required.");const f=n.useMemo(()=>({requestHandler:o,stateManager:t,listState:r,setListState:i}),[o,t,r]);return s.jsx(B.Provider,{value:f,children:a})},C=()=>{const a=n.useContext(B);if(!a)throw new Error("useListContext must be used within a ListProvider");return a},j=n.memo(({children:a,renderAttribute:l})=>{const{listState:o}=C(),{attrs:t,attrSettings:r,updateAttr:i}=o,f=n.useCallback(c=>S=>{i(c,"visible",S.target.checked)},[i]),p=n.useMemo(()=>({attrs:t,attrSettings:r,updateAttr:i}),[t,r,i]);return a?a(p):s.jsx("div",{className:"react-list-attributes",children:t.map((c,S)=>{var u;return l?l({key:`attr-${S}`,attr:c,updateAttr:i,attrSettings:r}):s.jsxs("label",{children:[s.jsx("span",{children:c.label}),s.jsx("input",{type:"checkbox",checked:((u=r==null?void 0:r[c.name])==null?void 0:u.visible)??!1,onChange:f(c.name)})]},`attr-${S}`)})})}),q=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,loader:t,error:r}=l,{isLoading:i,initialLoading:f}=t;return(o==null?void 0:o.length)>0||f||i||r?null:s.jsx("div",{className:"react-list-empty",children:a||s.jsx("div",{children:s.jsx("p",{children:"No data found!"})})})}),A=n.memo(({children:a})=>{const{listState:l}=C(),{error:o,loader:t}=l,{isLoading:r}=t;return!o||r?null:s.jsx("div",{className:"react-list-error",children:typeof a=="function"?a({error:o}):a||s.jsxs("div",{children:[s.jsx("h3",{children:"Error occurred"}),s.jsxs("pre",{children:[o.name,": ",o.message]})]})})}),_=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:c,perPage:S}=r,{initialLoading:u,isLoading:v}=f,{pages:b,pagesCount:P}=n.useMemo(()=>{const m=Math.ceil(t/S);return{pages:Array.from({length:m},(O,M)=>M+1),pagesCount:m}},[t,S]),E=n.useCallback(m=>{i(Number(m.target.value))},[i]),e=n.useMemo(()=>({setPage:i,page:c,pages:b,pagesCount:P}),[i,c,b,P]);return u||!o||o.length===0||p?null:s.jsx("div",{className:"react-list-go-to",children:a?a(e):s.jsx("select",{value:c,onChange:E,children:b.map(m=>s.jsxs("option",{value:m,children:["Page ",m]},`page-${m}`))})})}),$=n.memo(({children:a})=>{const{listState:l}=C(),{loader:o}=l,{initialLoading:t}=o;return n.useMemo(()=>({loading:t}),[t]),t?s.jsx("div",{className:"react-list-initial-loader",children:a||s.jsx("p",{children:"Initial Loading..."})}):null}),D=n.memo(({children:a,renderItem:l})=>{const{listState:o}=C(),{data:t=[],loader:r,error:i,setSort:f,sort:p}=o,{initialLoading:c}=r,S=n.useMemo(()=>({items:t,setSort:f,sort:p}),[t,p,f]);return c||!t||t.length===0||i?null:l?s.jsx("div",{className:"react-list-items",children:t.map((u,v)=>s.jsx("div",{children:l({item:u,index:v})},u.id||v))}):typeof a=="function"?s.jsx("div",{className:"react-list-items",children:a(S)}):s.jsx("div",{className:"react-list-items",children:t.map((u,v)=>s.jsx("pre",{children:JSON.stringify(u,null,2)},u.id||v))})}),H=({children:a,endpoint:l,page:o=1,perPage:t=25,sortBy:r,sortOrder:i="desc",search:f="",filters:p={},attrs:c,version:S=1,paginationMode:u="pagination",meta:v={}})=>{const{requestHandler:b,setListState:P}=C(),E=u==="loadMore",[e,m]=n.useState({page:o,perPage:t,sortBy:r,sortOrder:i,search:f,filters:p,attrSettings:{},items:[],selection:[],error:null,response:null,count:0,isLoading:!1,initializingState:!0}),w=n.useCallback(async(L={},g=null)=>{e.initializingState||m(h=>({...h,error:null,isLoading:!0}));try{const h=g||e,d=await b({endpoint:l,version:S,meta:v,page:h.page,perPage:h.perPage,search:h.search,sortBy:h.sortBy,sortOrder:h.sortOrder,filters:h.filters,...L});m(k=>({...k,response:d,selection:[],items:E&&h.page>1?[...k.items,...d.items]:d.items,count:d.count,initializingState:!1,isLoading:!1}))}catch(h){throw m(d=>({...d,error:h,items:[],count:0,initializingState:!1,isLoading:!1})),h}},[l,S,E,v,b,e]),O=n.useMemo(()=>({setPage:(L,g)=>{let h=L;L===0&&(h="");const d={...e,page:h};m(d),h&&w(g,d)},setPerPage:L=>{const g={...e,perPage:L,page:1};m(g),w({},g)},setSearch:L=>{if(L!==e.search){const g={...e,search:L,page:1};m(g),w({},g)}},setSort:({by:L,order:g})=>{const h={...e,sortBy:L,sortOrder:g,page:1};m(h),w({},h)},loadMore:()=>{const L={...e,page:e.page+1};m(L),w({},L)},refresh:(L={isRefresh:!0})=>{if(E){const g={...e,page:1,items:[]};m(g),w(L,g)}else w(L)},setFilters:L=>{const g={...e,filters:L,page:1};m(g),w({},g)},updateItemById:(L,g)=>{const h=e.items.map(d=>d.id===g?{...d,...L}:d);m(d=>({...d,items:h}))},setSelection:L=>m(g=>({...g,selection:L}))}),[w,E,e]),M=n.useMemo(()=>({data:e.items,response:e.response,error:e.error,count:e.count,selection:e.selection,pagination:{page:e.page,perPage:e.perPage,hasMore:e.items.length<e.count},loader:{isLoading:e.isLoading,initialLoading:e.initializingState},sort:{sortBy:e.sortBy,sortOrder:e.sortOrder},search:e.search,filters:e.filters,attrs:c||Object.keys(e.items[0]||{}),isEmpty:e.items.length===0,...O}),[e.items,e.response,e.error,e.count,e.selection,e.page,e.perPage,e.isLoading,e.initializingState,e.sortBy,e.sortOrder,e.search,e.filters,O,c]);return n.useEffect(()=>{e.initializingState&&O.setPage(e.page)},[]),n.useEffect(()=>{P(M)},[P,e.items,e.count,e.error,e.isLoading,e.selection,e.page,e.perPage,e.sortBy,e.sortOrder]),typeof a=="function"?a(M):a},x=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:c,perPage:S}=r,{isLoading:u}=f,v=n.useMemo(()=>c*S<t,[c,S,t]),b=n.useCallback(()=>{v&&!u&&i(c+1)},[v,u,i,c]),P=n.useMemo(()=>({isLoading:u,loadMore:b,hasMoreItems:v}),[u,b,v]);return!o||o.length===0||p?null:a(P)}),G=n.memo(({children:a,position:l="overlay"})=>{const{listState:o}=C(),{loader:t}=o,{isLoading:r,initializingState:i}=t;return n.useMemo(()=>({isLoading:r}),[r]),!i&&!r?null:s.jsx("div",{children:a||s.jsx("div",{children:s.jsx("p",{children:"Loading..."})})})}),W=n.memo(({children:a,pageLinks:l=5,renderFirst:o,renderPrev:t,renderPages:r,renderPage:i,renderNext:f,renderLast:p})=>{const{listState:c}=C(),{data:S,count:u,pagination:v,setPage:b,loader:P,error:E}=c,{page:e,perPage:m}=v,{initialLoading:w,isLoading:O}=P,M=n.useMemo(()=>{const d=Math.ceil(u/m),k=Math.floor(l/2),N=e*m<u;return{pagesCount:d,halfWay:k,hasNext:N,hasPrev:e!==1}},[u,m,e,l]),L=n.useMemo(()=>{const{pagesCount:d,halfWay:k}=M,N=Array.from({length:Math.min(l,d)});return e<=k?N.map((T,z)=>z+1):d-e<k?N.map((T,z)=>d-z).reverse():N.map((T,z)=>e-k+z)},[e,l,M]),g=n.useMemo(()=>({prev:()=>b(e-1),next:()=>b(e+1),first:()=>b(1),last:()=>b(M.pagesCount),setPage:d=>b(d)}),[b,e,M.pagesCount]),h=n.useMemo(()=>({page:e,perPage:m,count:u,...M,pagesToDisplay:L,...g}),[e,m,u,M,L,g]);return w||!S||S.length===0||E?null:a?a(h):s.jsxs("div",{className:"react-list-pagination",children:[o?o(h):s.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:g.first,children:"First"}),t?t(h):s.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:g.prev,children:"Prev"}),r?r(h):s.jsx("div",{children:L.map(d=>{const k=d===e,N={...h,page:d,isActive:k};return i?i(N):s.jsx("div",{children:k?s.jsx("span",{children:d}):s.jsx("button",{type:"button",onClick:()=>g.setPage(d),children:d})},`page-${d}`)})}),f?f(h):s.jsx("button",{type:"button",disabled:!M.hasNext,onClick:g.next,children:"Next"}),p?p(h):s.jsx("button",{type:"button",disabled:!M.hasNext,onClick:g.last,children:"Last"})]})}),F=n.memo(({children:a,options:l=[10,25,50,100]})=>{const{listState:o}=C(),{data:t,pagination:r,setPerPage:i,loader:f,error:p}=o,{perPage:c}=r,{initialLoading:S}=f,u=n.useMemo(()=>l.map(P=>typeof P!="object"?{value:P,label:P}:P),[l]),v=n.useCallback(P=>{i(Number(P.target.value))},[i]),b=n.useMemo(()=>({perPage:c,setPerPage:i,options:u}),[c,i,u]);return S||!t||t.length===0||p?null:s.jsx("div",{className:"react-list-per-page",children:a?a(b):s.jsx("select",{value:c,onChange:v,children:u.map(P=>s.jsxs("option",{value:P.value,children:[P.label," items per page"]},`option-${P.value}`))})})}),J=n.memo(({children:a})=>{const{listState:l}=C(),{loader:o,refresh:t}=l,{isLoading:r,initialLoading:i}=o,f=n.useCallback(()=>{t({isRefresh:!0})},[t]),p=n.useMemo(()=>({isLoading:r,refresh:f}),[r,f]);return i?null:a?a(p):s.jsx("div",{className:"react-list-refresh",children:s.jsx("button",{onClick:f,disabled:r,children:r?"Loading...":"Refresh"})})}),K=n.memo(({children:a,debounceTime:l=500})=>{const{listState:o}=C(),{search:t,setSearch:r}=o,[i,f]=n.useState(t??""),p=n.useRef(null);n.useEffect(()=>{t!==i&&f(t??"")},[t]);const c=u=>{f(u),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{r(u)},l)};n.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const S={search:i,setSearch:c};return s.jsx("div",{className:"react-list-search",children:a?a(S):s.jsx("input",{type:"text",value:i,onChange:u=>c(u.target.value),placeholder:"Search..."})})}),Q=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,loader:i,error:f}=l,{page:p,perPage:c}=r,{initialLoading:S,isLoading:u}=i,v=n.useMemo(()=>{const P=p*c-c+1,E=Math.min(p*c,t),e=(o==null?void 0:o.length)||0;return{from:P,to:E,visibleCount:e}},[p,c,t,o]),b=n.useMemo(()=>({...v,count:t}),[v,t]);return S||!o||o.length===0||f?null:s.jsx("div",{className:"react-list-summary",children:a?a(b):s.jsxs("span",{children:["Showing ",s.jsx("span",{children:v.visibleCount})," items (",s.jsxs("span",{children:[v.from," - ",v.to]}),") out of ",s.jsx("span",{children:t})]})})});y.ReactListAttributes=j,y.ReactListEmpty=q,y.ReactListError=A,y.ReactListGoTo=_,y.ReactListInitialLoader=$,y.ReactListItems=D,y.ReactListLoadMore=x,y.ReactListLoader=G,y.ReactListPagination=W,y.ReactListPerPage=F,y.ReactListProvider=I,y.ReactListRefresh=J,y.ReactListSearch=K,y.ReactListSummary=Q,y.default=H,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7span/react-list",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A simple and reusable list component for React",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./src/index.jsx"
|
|
8
|
-
},
|
|
9
6
|
"scripts": {
|
|
10
7
|
"dev": "vite",
|
|
11
8
|
"build": "vite build",
|