@7span/react-list 0.0.6 → 1.0.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/dist/react-list.js +199 -198
- package/dist/react-list.umd.cjs +1 -1
- package/package.json +19 -10
- package/src/components/attributes.jsx +53 -0
- package/src/components/empty.jsx +22 -0
- package/src/components/error.jsx +27 -0
- package/src/components/go-to.jsx +58 -0
- package/src/components/initial-loader.jsx +25 -0
- package/src/components/items.jsx +50 -0
- package/src/components/list.jsx +361 -0
- package/src/components/load-more.jsx +39 -0
- package/src/components/loader.jsx +29 -0
- package/src/components/pagination.jsx +158 -0
- package/src/components/per-page.jsx +65 -0
- package/src/components/refresh.jsx +34 -0
- package/src/components/search.jsx +59 -0
- package/src/components/summary.jsx +51 -0
- package/src/components/utils.js +42 -0
- package/src/context/list-provider.jsx +55 -0
- package/src/index.js +15 -0
package/dist/react-list.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as c, jsxs as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as c, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as X, useContext as Y, useState as G, useMemo as C, memo as B, useCallback as E, useRef as U, useEffect as D } from "react";
|
|
3
|
+
const V = X(null), ee = ({ children: s, config: i }) => {
|
|
4
4
|
const { requestHandler: a, stateManager: n = {} } = i, [r, l] = G({
|
|
5
5
|
data: [],
|
|
6
6
|
response: null,
|
|
@@ -27,7 +27,7 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
27
27
|
});
|
|
28
28
|
if (!a)
|
|
29
29
|
throw new Error("ListProvider: requestHandler is required.");
|
|
30
|
-
const
|
|
30
|
+
const d = C(
|
|
31
31
|
() => ({
|
|
32
32
|
requestHandler: a,
|
|
33
33
|
stateManager: n,
|
|
@@ -36,14 +36,14 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
36
36
|
}),
|
|
37
37
|
[a, n, r]
|
|
38
38
|
);
|
|
39
|
-
return /* @__PURE__ */ c(
|
|
39
|
+
return /* @__PURE__ */ c(V.Provider, { value: d, children: s });
|
|
40
40
|
}, x = () => {
|
|
41
|
-
const s =
|
|
41
|
+
const s = Y(V);
|
|
42
42
|
if (!s)
|
|
43
43
|
throw new Error("useListContext must be used within a ListProvider");
|
|
44
44
|
return s;
|
|
45
|
-
},
|
|
46
|
-
const { listState: a } = x(), { attrs: n, attrSettings: r, updateAttr: l } = a,
|
|
45
|
+
}, te = B(({ children: s, renderAttribute: i }) => {
|
|
46
|
+
const { listState: a } = x(), { attrs: n, attrSettings: r, updateAttr: l } = a, d = E(
|
|
47
47
|
(u) => (h) => {
|
|
48
48
|
l(u, "visible", h.target.checked);
|
|
49
49
|
},
|
|
@@ -57,60 +57,60 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
57
57
|
[n, r, l]
|
|
58
58
|
);
|
|
59
59
|
return s ? s(m) : /* @__PURE__ */ c("div", { className: "react-list-attributes", children: n.map((u, h) => {
|
|
60
|
-
var
|
|
60
|
+
var f;
|
|
61
61
|
return i ? i({
|
|
62
62
|
key: `attr-${h}`,
|
|
63
63
|
attr: u,
|
|
64
64
|
updateAttr: l,
|
|
65
65
|
attrSettings: r
|
|
66
|
-
}) : /* @__PURE__ */
|
|
66
|
+
}) : /* @__PURE__ */ T("label", { children: [
|
|
67
67
|
/* @__PURE__ */ c("span", { children: u.label }),
|
|
68
68
|
/* @__PURE__ */ c(
|
|
69
69
|
"input",
|
|
70
70
|
{
|
|
71
71
|
type: "checkbox",
|
|
72
|
-
checked: ((
|
|
73
|
-
onChange:
|
|
72
|
+
checked: ((f = r == null ? void 0 : r[u.name]) == null ? void 0 : f.visible) ?? !1,
|
|
73
|
+
onChange: d(u.name)
|
|
74
74
|
}
|
|
75
75
|
)
|
|
76
76
|
] }, `attr-${h}`);
|
|
77
77
|
}) });
|
|
78
|
-
}),
|
|
79
|
-
const { listState: i } = x(), { data: a, loader: n, error: r } = i, { isLoading: l, initialLoading:
|
|
80
|
-
return (a == null ? void 0 : a.length) > 0 ||
|
|
81
|
-
}),
|
|
78
|
+
}), se = B(({ children: s }) => {
|
|
79
|
+
const { listState: i } = x(), { data: a, loader: n, error: r } = i, { isLoading: l, initialLoading: d } = n;
|
|
80
|
+
return (a == null ? void 0 : a.length) > 0 || d || l || r ? null : /* @__PURE__ */ c("div", { className: "react-list-empty", children: s || /* @__PURE__ */ c("div", { children: /* @__PURE__ */ c("p", { children: "No data found!" }) }) });
|
|
81
|
+
}), ne = B(({ children: s }) => {
|
|
82
82
|
const { listState: i } = x(), { error: a, loader: n } = i, { isLoading: r } = n;
|
|
83
|
-
return !a || r ? null : /* @__PURE__ */ c("div", { className: "react-list-error", children: typeof s == "function" ? s({ error: a }) : s || /* @__PURE__ */
|
|
83
|
+
return !a || r ? null : /* @__PURE__ */ c("div", { className: "react-list-error", children: typeof s == "function" ? s({ error: a }) : s || /* @__PURE__ */ T("div", { children: [
|
|
84
84
|
/* @__PURE__ */ c("h3", { children: "Error occurred" }),
|
|
85
|
-
/* @__PURE__ */
|
|
85
|
+
/* @__PURE__ */ T("pre", { children: [
|
|
86
86
|
a.name,
|
|
87
87
|
": ",
|
|
88
88
|
a.message
|
|
89
89
|
] })
|
|
90
90
|
] }) });
|
|
91
|
-
}),
|
|
92
|
-
const { listState: i } = x(), { data: a, count: n, pagination: r, setPage: l, loader:
|
|
93
|
-
const
|
|
94
|
-
return { pages: Array.from({ length:
|
|
95
|
-
}, [n, h]),
|
|
96
|
-
(
|
|
97
|
-
l(Number(
|
|
91
|
+
}), re = B(({ children: s }) => {
|
|
92
|
+
const { listState: i } = x(), { data: a, count: n, pagination: r, setPage: l, loader: d, error: m } = i, { page: u, perPage: h } = r, { initialLoading: f, isLoading: y } = d, { pages: L, pagesCount: v } = C(() => {
|
|
93
|
+
const R = Math.ceil(n / h);
|
|
94
|
+
return { pages: Array.from({ length: R }, (_, p) => p + 1), pagesCount: R };
|
|
95
|
+
}, [n, h]), I = E(
|
|
96
|
+
(R) => {
|
|
97
|
+
l(Number(R.target.value));
|
|
98
98
|
},
|
|
99
99
|
[l]
|
|
100
100
|
), P = C(
|
|
101
101
|
() => ({
|
|
102
102
|
setPage: l,
|
|
103
103
|
page: u,
|
|
104
|
-
pages:
|
|
105
|
-
pagesCount:
|
|
104
|
+
pages: L,
|
|
105
|
+
pagesCount: v
|
|
106
106
|
}),
|
|
107
|
-
[l, u,
|
|
107
|
+
[l, u, L, v]
|
|
108
108
|
);
|
|
109
|
-
return
|
|
109
|
+
return f || !a || a.length === 0 || m ? null : /* @__PURE__ */ c("div", { className: "react-list-go-to", children: s ? s(P) : /* @__PURE__ */ c("select", { value: u, onChange: I, children: L.map((R) => /* @__PURE__ */ T("option", { value: R, children: [
|
|
110
110
|
"Page ",
|
|
111
|
-
|
|
112
|
-
] }, `page-${
|
|
113
|
-
}),
|
|
111
|
+
R
|
|
112
|
+
] }, `page-${R}`)) }) });
|
|
113
|
+
}), ie = B(({ children: s }) => {
|
|
114
114
|
const { listState: i } = x(), { loader: a } = i, { initialLoading: n } = a;
|
|
115
115
|
return C(
|
|
116
116
|
() => ({
|
|
@@ -118,16 +118,17 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
118
118
|
}),
|
|
119
119
|
[n]
|
|
120
120
|
), n ? /* @__PURE__ */ c("div", { className: "react-list-initial-loader", children: s || /* @__PURE__ */ c("p", { children: "Initial Loading..." }) }) : null;
|
|
121
|
-
}),
|
|
122
|
-
const { listState: a } = x(), { data: n = [], loader: r, error: l, setSort:
|
|
121
|
+
}), ae = B(({ children: s, renderItem: i }) => {
|
|
122
|
+
const { listState: a } = x(), { data: n = [], loader: r, error: l, setSort: d, sort: m } = a, { initialLoading: u, isLoading: h } = r, f = C(
|
|
123
123
|
() => ({
|
|
124
124
|
items: n,
|
|
125
|
-
|
|
125
|
+
isLoading: h,
|
|
126
|
+
setSort: d,
|
|
126
127
|
sort: m
|
|
127
128
|
}),
|
|
128
|
-
[n, m,
|
|
129
|
+
[n, m, d, h]
|
|
129
130
|
);
|
|
130
|
-
return u || !n || n.length === 0 || l ? null : i ? /* @__PURE__ */ c("div", { className: "react-list-items", children: n.map((
|
|
131
|
+
return u || !n || n.length === 0 || l ? null : i ? /* @__PURE__ */ c("div", { className: "react-list-items", children: n.map((y, L) => /* @__PURE__ */ c("div", { children: i({ item: y, index: L }) }, y.id || L)) }) : typeof s == "function" ? /* @__PURE__ */ c("div", { className: "react-list-items", children: s(f) }) : /* @__PURE__ */ c("div", { className: "react-list-items", children: n.map((y, L) => /* @__PURE__ */ c("pre", { children: JSON.stringify(y, null, 2) }, y.id || L)) });
|
|
131
132
|
}), W = (s, i) => {
|
|
132
133
|
if (s === i) return !0;
|
|
133
134
|
if (s == null || i == null || typeof s != "object" || typeof i != "object")
|
|
@@ -144,44 +145,44 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
144
145
|
for (let r of a)
|
|
145
146
|
if (!n.includes(r) || !W(s[r], i[r])) return !1;
|
|
146
147
|
return !0;
|
|
147
|
-
},
|
|
148
|
+
}, Z = (s, i) => !i || Object.keys(i).length === 0 ? s && Object.keys(s).length > 0 : !s || Object.keys(s).length === 0 ? !1 : !W(s, i), oe = ({
|
|
148
149
|
initialItems: s = [],
|
|
149
150
|
children: i,
|
|
150
151
|
endpoint: a,
|
|
151
152
|
page: n = 1,
|
|
152
153
|
perPage: r = 25,
|
|
153
154
|
sortBy: l = "",
|
|
154
|
-
sortOrder:
|
|
155
|
+
sortOrder: d = "desc",
|
|
155
156
|
count: m = 0,
|
|
156
157
|
search: u = "",
|
|
157
158
|
filters: h = {},
|
|
158
|
-
attrs:
|
|
159
|
+
attrs: f,
|
|
159
160
|
version: y = 1,
|
|
160
|
-
paginationMode:
|
|
161
|
-
meta:
|
|
162
|
-
onResponse:
|
|
161
|
+
paginationMode: L = "pagination",
|
|
162
|
+
meta: v = {},
|
|
163
|
+
onResponse: I,
|
|
163
164
|
afterPageChange: P,
|
|
164
|
-
afterLoadMore:
|
|
165
|
+
afterLoadMore: R
|
|
165
166
|
}) => {
|
|
166
|
-
const { requestHandler:
|
|
167
|
+
const { requestHandler: $, setListState: _, stateManager: p } = x(), M = U(!1), k = L === "loadMore", A = E(
|
|
167
168
|
(e) => ({
|
|
168
169
|
endpoint: a,
|
|
169
170
|
version: y,
|
|
170
|
-
meta:
|
|
171
|
+
meta: v,
|
|
171
172
|
search: (e == null ? void 0 : e.search) || u,
|
|
172
173
|
page: (e == null ? void 0 : e.page) || n,
|
|
173
174
|
perPage: (e == null ? void 0 : e.perPage) || r,
|
|
174
175
|
sortBy: (e == null ? void 0 : e.sortBy) || l,
|
|
175
|
-
sortOrder: (e == null ? void 0 : e.sortOrder) ||
|
|
176
|
+
sortOrder: (e == null ? void 0 : e.sortOrder) || d,
|
|
176
177
|
filters: (e == null ? void 0 : e.filters) || h,
|
|
177
178
|
attrSettings: (e == null ? void 0 : e.attrSettings) || {},
|
|
178
179
|
isRefresh: !1
|
|
179
180
|
}),
|
|
180
|
-
[a, y,
|
|
181
|
-
),
|
|
181
|
+
[a, y, v, u, n, r, l, d, h]
|
|
182
|
+
), O = E(() => {
|
|
182
183
|
var e;
|
|
183
184
|
try {
|
|
184
|
-
const
|
|
185
|
+
const g = A(), o = (e = p == null ? void 0 : p.get) == null ? void 0 : e.call(p, g);
|
|
185
186
|
return {
|
|
186
187
|
page: o == null ? void 0 : o.page,
|
|
187
188
|
perPage: o == null ? void 0 : o.perPage,
|
|
@@ -191,17 +192,17 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
191
192
|
attrSettings: o == null ? void 0 : o.attrSettings,
|
|
192
193
|
filters: o == null ? void 0 : o.filters
|
|
193
194
|
};
|
|
194
|
-
} catch (
|
|
195
|
-
return console.error(
|
|
195
|
+
} catch (g) {
|
|
196
|
+
return console.error(g), {};
|
|
196
197
|
}
|
|
197
|
-
}, [A, p]),
|
|
198
|
-
const e =
|
|
199
|
-
let
|
|
200
|
-
return k ?
|
|
201
|
-
page:
|
|
198
|
+
}, [A, p]), N = E(() => {
|
|
199
|
+
const e = O();
|
|
200
|
+
let g = n;
|
|
201
|
+
return k ? g = 1 : e.page != null && (g = e.page), {
|
|
202
|
+
page: g,
|
|
202
203
|
perPage: e.perPage != null ? e.perPage : r,
|
|
203
204
|
sortBy: e.sortBy != null ? e.sortBy : l,
|
|
204
|
-
sortOrder: e.sortOrder != null ? e.sortOrder :
|
|
205
|
+
sortOrder: e.sortOrder != null ? e.sortOrder : d,
|
|
205
206
|
search: e.search != null ? e.search : u,
|
|
206
207
|
filters: e.filters != null ? e.filters : h,
|
|
207
208
|
attrSettings: e.attrSettings || {},
|
|
@@ -215,32 +216,32 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
215
216
|
confirmedPage: null
|
|
216
217
|
};
|
|
217
218
|
}, [
|
|
218
|
-
|
|
219
|
+
O,
|
|
219
220
|
u,
|
|
220
221
|
n,
|
|
221
222
|
r,
|
|
222
223
|
l,
|
|
223
|
-
|
|
224
|
+
d,
|
|
224
225
|
u,
|
|
225
226
|
h,
|
|
226
227
|
k
|
|
227
|
-
]), [t, b] = G(
|
|
228
|
+
]), [t, b] = G(N), q = E(
|
|
228
229
|
(e) => {
|
|
229
|
-
var
|
|
230
|
+
var g;
|
|
230
231
|
if (p) {
|
|
231
232
|
const o = A(e);
|
|
232
|
-
(
|
|
233
|
+
(g = p == null ? void 0 : p.set) == null || g.call(p, o);
|
|
233
234
|
}
|
|
234
235
|
},
|
|
235
236
|
[p, A]
|
|
236
|
-
),
|
|
237
|
-
async (e = {},
|
|
237
|
+
), z = E(
|
|
238
|
+
async (e = {}, g = null) => {
|
|
238
239
|
t.initializingState || b((o) => ({ ...o, error: null, isLoading: !0 }));
|
|
239
240
|
try {
|
|
240
|
-
const o =
|
|
241
|
+
const o = g || t, w = (g == null ? void 0 : g.items) ?? t.items, S = await $({
|
|
241
242
|
endpoint: a,
|
|
242
243
|
version: y,
|
|
243
|
-
meta:
|
|
244
|
+
meta: v,
|
|
244
245
|
page: o.page,
|
|
245
246
|
perPage: o.perPage,
|
|
246
247
|
search: o.search,
|
|
@@ -249,23 +250,23 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
249
250
|
filters: o.filters,
|
|
250
251
|
...e
|
|
251
252
|
});
|
|
252
|
-
|
|
253
|
-
let
|
|
254
|
-
k ? (
|
|
255
|
-
const
|
|
253
|
+
I && I(S);
|
|
254
|
+
let K;
|
|
255
|
+
k ? (K = o.page === 1 ? S.items : [...w, ...S.items], R && R(S)) : (K = S.items, P && P(S));
|
|
256
|
+
const Q = {
|
|
256
257
|
...o,
|
|
257
|
-
response:
|
|
258
|
+
response: S,
|
|
258
259
|
selection: [],
|
|
259
260
|
// Append items for loadMore, replace for pagination
|
|
260
|
-
items: k && o.page > 1 ? [...
|
|
261
|
-
count:
|
|
261
|
+
items: k && o.page > 1 ? [...w, ...S.items] : S.items,
|
|
262
|
+
count: S.count,
|
|
262
263
|
initializingState: !1,
|
|
263
264
|
isLoading: !1
|
|
264
265
|
};
|
|
265
|
-
|
|
266
|
+
q(Q), b(Q);
|
|
266
267
|
} catch (o) {
|
|
267
|
-
throw b((
|
|
268
|
-
...
|
|
268
|
+
throw b((w) => ({
|
|
269
|
+
...w,
|
|
269
270
|
error: o,
|
|
270
271
|
items: [],
|
|
271
272
|
count: 0,
|
|
@@ -274,55 +275,55 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
274
275
|
})), o;
|
|
275
276
|
}
|
|
276
277
|
},
|
|
277
|
-
[a, y, k,
|
|
278
|
-
),
|
|
278
|
+
[a, y, k, v, $, t]
|
|
279
|
+
), H = C(
|
|
279
280
|
() => ({
|
|
280
|
-
setPage: (e,
|
|
281
|
+
setPage: (e, g) => {
|
|
281
282
|
let o = e;
|
|
282
283
|
e === 0 && (o = "");
|
|
283
|
-
const
|
|
284
|
-
b(
|
|
284
|
+
const w = { ...t, page: o };
|
|
285
|
+
b(w), o && z(g, w);
|
|
285
286
|
},
|
|
286
287
|
setPerPage: (e) => {
|
|
287
|
-
const
|
|
288
|
-
b(
|
|
288
|
+
const g = { ...t, perPage: e, page: 1 };
|
|
289
|
+
b(g), z({}, g);
|
|
289
290
|
},
|
|
290
291
|
setSearch: (e) => {
|
|
291
292
|
if (e !== t.search) {
|
|
292
|
-
const
|
|
293
|
-
b(
|
|
293
|
+
const g = { ...t, search: e, page: 1 };
|
|
294
|
+
b(g), z({}, g);
|
|
294
295
|
}
|
|
295
296
|
},
|
|
296
|
-
setSort: ({ by: e, order:
|
|
297
|
-
const o = { ...t, sortBy: e, sortOrder:
|
|
298
|
-
b(o),
|
|
297
|
+
setSort: ({ by: e, order: g }) => {
|
|
298
|
+
const o = { ...t, sortBy: e, sortOrder: g, page: 1 };
|
|
299
|
+
b(o), z({}, o);
|
|
299
300
|
},
|
|
300
301
|
loadMore: () => {
|
|
301
302
|
const e = { ...t, page: t.page + 1 };
|
|
302
|
-
b(e),
|
|
303
|
+
b(e), z({}, e);
|
|
303
304
|
},
|
|
304
305
|
clearFilters: () => {
|
|
305
306
|
const e = { ...t, filters: h, page: 1 };
|
|
306
|
-
b(e),
|
|
307
|
+
b(e), z({}, e);
|
|
307
308
|
},
|
|
308
309
|
refresh: (e = { isRefresh: !0 }) => {
|
|
309
310
|
if (k) {
|
|
310
|
-
const
|
|
311
|
-
b(
|
|
311
|
+
const g = { ...t, page: 1, items: [] };
|
|
312
|
+
b(g), z(e, g);
|
|
312
313
|
} else
|
|
313
|
-
|
|
314
|
+
z(e);
|
|
314
315
|
},
|
|
315
316
|
setFilters: (e) => {
|
|
316
|
-
const
|
|
317
|
-
b(
|
|
317
|
+
const g = { ...t, filters: e, page: 1 };
|
|
318
|
+
b(g), z({}, g);
|
|
318
319
|
},
|
|
319
|
-
updateItemById: (e,
|
|
320
|
-
const o = t.items.map((
|
|
321
|
-
b((
|
|
320
|
+
updateItemById: (e, g) => {
|
|
321
|
+
const o = t.items.map((w) => w.id === g ? { ...w, ...e } : w);
|
|
322
|
+
b((w) => ({ ...w, items: o }));
|
|
322
323
|
},
|
|
323
|
-
setSelection: (e) => b((
|
|
324
|
+
setSelection: (e) => b((g) => ({ ...g, selection: e }))
|
|
324
325
|
}),
|
|
325
|
-
[
|
|
326
|
+
[z, k, t]
|
|
326
327
|
), J = C(
|
|
327
328
|
() => ({
|
|
328
329
|
data: t.items,
|
|
@@ -340,12 +341,12 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
340
341
|
initialLoading: t.initializingState
|
|
341
342
|
},
|
|
342
343
|
sort: { sortBy: t.sortBy, sortOrder: t.sortOrder },
|
|
343
|
-
hasActiveFilters:
|
|
344
|
+
hasActiveFilters: Z(t.filters, h),
|
|
344
345
|
search: t.search,
|
|
345
346
|
filters: t.filters,
|
|
346
|
-
attrs:
|
|
347
|
+
attrs: f || Object.keys(t.items[0] || {}),
|
|
347
348
|
isEmpty: t.items.length === 0,
|
|
348
|
-
...
|
|
349
|
+
...H
|
|
349
350
|
}),
|
|
350
351
|
[
|
|
351
352
|
t.items,
|
|
@@ -361,22 +362,22 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
361
362
|
t.sortOrder,
|
|
362
363
|
t.search,
|
|
363
364
|
t.filters,
|
|
364
|
-
|
|
365
|
-
|
|
365
|
+
H,
|
|
366
|
+
f
|
|
366
367
|
]
|
|
367
368
|
);
|
|
368
|
-
return
|
|
369
|
-
if (t.initializingState && !
|
|
370
|
-
if (
|
|
369
|
+
return D(() => {
|
|
370
|
+
if (t.initializingState && !M.current) {
|
|
371
|
+
if (M.current = !0, p != null && p.init) {
|
|
371
372
|
const e = A(t);
|
|
372
373
|
p.init(e);
|
|
373
374
|
}
|
|
374
|
-
s.length ||
|
|
375
|
+
s.length || H.setPage(t.page);
|
|
375
376
|
}
|
|
376
|
-
}, []),
|
|
377
|
-
|
|
377
|
+
}, []), D(() => {
|
|
378
|
+
_(J);
|
|
378
379
|
}, [
|
|
379
|
-
|
|
380
|
+
_,
|
|
380
381
|
t.items,
|
|
381
382
|
t.count,
|
|
382
383
|
t.error,
|
|
@@ -387,22 +388,22 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
387
388
|
t.sortBy,
|
|
388
389
|
t.sortOrder
|
|
389
390
|
]), typeof i == "function" ? i(J) : i;
|
|
390
|
-
},
|
|
391
|
-
const { listState: i } = x(), { data: a, count: n, pagination: r, setPage: l, loader:
|
|
391
|
+
}, le = B(({ children: s }) => {
|
|
392
|
+
const { listState: i } = x(), { data: a, count: n, pagination: r, setPage: l, loader: d, error: m } = i, { page: u, perPage: h } = r, { isLoading: f } = d, y = C(
|
|
392
393
|
() => u * h < n,
|
|
393
394
|
[u, h, n]
|
|
394
|
-
),
|
|
395
|
-
y && !
|
|
396
|
-
}, [y,
|
|
395
|
+
), L = E(() => {
|
|
396
|
+
y && !f && l(u + 1);
|
|
397
|
+
}, [y, f, l, u]), v = C(
|
|
397
398
|
() => ({
|
|
398
|
-
isLoading:
|
|
399
|
-
loadMore:
|
|
399
|
+
isLoading: f,
|
|
400
|
+
loadMore: L,
|
|
400
401
|
hasMoreItems: y
|
|
401
402
|
}),
|
|
402
|
-
[
|
|
403
|
+
[f, L, y]
|
|
403
404
|
);
|
|
404
|
-
return !a || a.length === 0 || m ? null : s(
|
|
405
|
-
}),
|
|
405
|
+
return !a || a.length === 0 || m ? null : s(v);
|
|
406
|
+
}), ce = B(({ children: s, position: i = "overlay" }) => {
|
|
406
407
|
const { listState: a } = x(), { loader: n } = a, { isLoading: r, initializingState: l } = n;
|
|
407
408
|
return C(
|
|
408
409
|
() => ({
|
|
@@ -410,7 +411,7 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
410
411
|
}),
|
|
411
412
|
[r]
|
|
412
413
|
), !l && !r ? null : /* @__PURE__ */ c("div", { children: s || /* @__PURE__ */ c("div", { children: /* @__PURE__ */ c("p", { children: "Loading..." }) }) });
|
|
413
|
-
}),
|
|
414
|
+
}), ue = B(
|
|
414
415
|
({
|
|
415
416
|
children: s,
|
|
416
417
|
pageLinks: i = 5,
|
|
@@ -418,36 +419,36 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
418
419
|
renderPrev: n,
|
|
419
420
|
renderPages: r,
|
|
420
421
|
renderPage: l,
|
|
421
|
-
renderNext:
|
|
422
|
+
renderNext: d,
|
|
422
423
|
renderLast: m
|
|
423
424
|
}) => {
|
|
424
|
-
const { listState: u } = x(), { data: h, count:
|
|
425
|
-
const
|
|
426
|
-
return { pagesCount:
|
|
427
|
-
}, [
|
|
428
|
-
const { pagesCount:
|
|
429
|
-
return P <=
|
|
425
|
+
const { listState: u } = x(), { data: h, count: f, pagination: y, setPage: L, loader: v, error: I } = u, { page: P, perPage: R } = y, { initialLoading: $, isLoading: _ } = v, p = C(() => {
|
|
426
|
+
const O = Math.ceil(f / R), N = Math.floor(i / 2), t = P * R < f;
|
|
427
|
+
return { pagesCount: O, halfWay: N, hasNext: t, hasPrev: P !== 1 };
|
|
428
|
+
}, [f, R, P, i]), M = C(() => {
|
|
429
|
+
const { pagesCount: O, halfWay: N } = p, t = Array.from({ length: Math.min(i, O) });
|
|
430
|
+
return P <= N ? t.map((b, q) => q + 1) : O - P < N ? t.map((b, q) => O - q).reverse() : t.map((b, q) => P - N + q);
|
|
430
431
|
}, [P, i, p]), k = C(
|
|
431
432
|
() => ({
|
|
432
|
-
prev: () =>
|
|
433
|
-
next: () =>
|
|
434
|
-
first: () =>
|
|
435
|
-
last: () =>
|
|
436
|
-
setPage: (
|
|
433
|
+
prev: () => L(P - 1),
|
|
434
|
+
next: () => L(P + 1),
|
|
435
|
+
first: () => L(1),
|
|
436
|
+
last: () => L(p.pagesCount),
|
|
437
|
+
setPage: (O) => L(O)
|
|
437
438
|
}),
|
|
438
|
-
[
|
|
439
|
+
[L, P, p.pagesCount]
|
|
439
440
|
), A = C(
|
|
440
441
|
() => ({
|
|
441
442
|
page: P,
|
|
442
|
-
perPage:
|
|
443
|
-
count:
|
|
443
|
+
perPage: R,
|
|
444
|
+
count: f,
|
|
444
445
|
...p,
|
|
445
|
-
pagesToDisplay:
|
|
446
|
+
pagesToDisplay: M,
|
|
446
447
|
...k
|
|
447
448
|
}),
|
|
448
|
-
[P,
|
|
449
|
+
[P, R, f, p, M, k]
|
|
449
450
|
);
|
|
450
|
-
return
|
|
451
|
+
return $ || !h || h.length === 0 || I ? null : s ? s(A) : /* @__PURE__ */ T("div", { className: "react-list-pagination", children: [
|
|
451
452
|
a ? a(A) : /* @__PURE__ */ c(
|
|
452
453
|
"button",
|
|
453
454
|
{
|
|
@@ -466,18 +467,18 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
466
467
|
children: "Prev"
|
|
467
468
|
}
|
|
468
469
|
),
|
|
469
|
-
r ? r(A) : /* @__PURE__ */ c("div", { children:
|
|
470
|
-
const
|
|
471
|
-
return l ? l(t) : /* @__PURE__ */ c("div", { children:
|
|
470
|
+
r ? r(A) : /* @__PURE__ */ c("div", { children: M.map((O) => {
|
|
471
|
+
const N = O === P, t = { ...A, page: O, isActive: N };
|
|
472
|
+
return l ? l(t) : /* @__PURE__ */ c("div", { children: N ? /* @__PURE__ */ c("span", { children: O }) : /* @__PURE__ */ c(
|
|
472
473
|
"button",
|
|
473
474
|
{
|
|
474
475
|
type: "button",
|
|
475
|
-
onClick: () => k.setPage(
|
|
476
|
-
children:
|
|
476
|
+
onClick: () => k.setPage(O),
|
|
477
|
+
children: O
|
|
477
478
|
}
|
|
478
|
-
) }, `page-${
|
|
479
|
+
) }, `page-${O}`);
|
|
479
480
|
}) }),
|
|
480
|
-
|
|
481
|
+
d ? d(A) : /* @__PURE__ */ c(
|
|
481
482
|
"button",
|
|
482
483
|
{
|
|
483
484
|
type: "button",
|
|
@@ -497,51 +498,51 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
497
498
|
)
|
|
498
499
|
] });
|
|
499
500
|
}
|
|
500
|
-
),
|
|
501
|
+
), ge = B(
|
|
501
502
|
({ children: s, options: i = [10, 25, 50, 100] }) => {
|
|
502
|
-
const { listState: a } = x(), { data: n, pagination: r, setPerPage: l, loader:
|
|
503
|
-
value:
|
|
504
|
-
label:
|
|
505
|
-
} :
|
|
506
|
-
(
|
|
507
|
-
l(Number(
|
|
503
|
+
const { listState: a } = x(), { data: n, pagination: r, setPerPage: l, loader: d, error: m } = a, { perPage: u } = r, { initialLoading: h } = d, f = C(() => i.map((v) => typeof v != "object" ? {
|
|
504
|
+
value: v,
|
|
505
|
+
label: v
|
|
506
|
+
} : v), [i]), y = E(
|
|
507
|
+
(v) => {
|
|
508
|
+
l(Number(v.target.value));
|
|
508
509
|
},
|
|
509
510
|
[l]
|
|
510
|
-
),
|
|
511
|
+
), L = C(
|
|
511
512
|
() => ({
|
|
512
513
|
perPage: u,
|
|
513
514
|
setPerPage: l,
|
|
514
|
-
options:
|
|
515
|
+
options: f
|
|
515
516
|
}),
|
|
516
|
-
[u, l,
|
|
517
|
+
[u, l, f]
|
|
517
518
|
);
|
|
518
|
-
return h || !n || n.length === 0 || m ? null : /* @__PURE__ */ c("div", { className: "react-list-per-page", children: s ? s(
|
|
519
|
-
|
|
519
|
+
return h || !n || n.length === 0 || m ? null : /* @__PURE__ */ c("div", { className: "react-list-per-page", children: s ? s(L) : /* @__PURE__ */ c("select", { value: u, onChange: y, children: f.map((v) => /* @__PURE__ */ T("option", { value: v.value, children: [
|
|
520
|
+
v.label,
|
|
520
521
|
" items per page"
|
|
521
|
-
] }, `option-${
|
|
522
|
+
] }, `option-${v.value}`)) }) });
|
|
522
523
|
}
|
|
523
|
-
),
|
|
524
|
-
const { listState: i } = x(), { loader: a, refresh: n } = i, { isLoading: r, initialLoading: l } = a,
|
|
524
|
+
), de = B(({ children: s }) => {
|
|
525
|
+
const { listState: i } = x(), { loader: a, refresh: n } = i, { isLoading: r, initialLoading: l } = a, d = E(() => {
|
|
525
526
|
n({ isRefresh: !0 });
|
|
526
527
|
}, [n]), m = C(
|
|
527
528
|
() => ({
|
|
528
529
|
isLoading: r,
|
|
529
|
-
refresh:
|
|
530
|
+
refresh: d
|
|
530
531
|
}),
|
|
531
|
-
[r,
|
|
532
|
+
[r, d]
|
|
532
533
|
);
|
|
533
|
-
return l ? null : s ? s(m) : /* @__PURE__ */ c("div", { className: "react-list-refresh", children: /* @__PURE__ */ c("button", { onClick:
|
|
534
|
-
}),
|
|
535
|
-
const { listState: a } = x(), { search: n, setSearch: r } = a, [l,
|
|
536
|
-
|
|
537
|
-
n !== l &&
|
|
534
|
+
return l ? null : s ? s(m) : /* @__PURE__ */ c("div", { className: "react-list-refresh", children: /* @__PURE__ */ c("button", { onClick: d, disabled: r, children: r ? "Loading..." : "Refresh" }) });
|
|
535
|
+
}), fe = B(({ children: s, debounceTime: i = 500 }) => {
|
|
536
|
+
const { listState: a } = x(), { search: n, setSearch: r } = a, [l, d] = G(n ?? ""), m = U(null);
|
|
537
|
+
D(() => {
|
|
538
|
+
n !== l && d(n ?? "");
|
|
538
539
|
}, [n]);
|
|
539
|
-
const u = (
|
|
540
|
-
f
|
|
541
|
-
r(
|
|
540
|
+
const u = (f) => {
|
|
541
|
+
d(f), m.current && clearTimeout(m.current), m.current = setTimeout(() => {
|
|
542
|
+
r(f);
|
|
542
543
|
}, i);
|
|
543
544
|
};
|
|
544
|
-
return
|
|
545
|
+
return D(() => () => {
|
|
545
546
|
m.current && clearTimeout(m.current);
|
|
546
547
|
}, []), /* @__PURE__ */ c("div", { className: "react-list-search", children: s ? s({
|
|
547
548
|
search: l,
|
|
@@ -551,26 +552,26 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
551
552
|
{
|
|
552
553
|
type: "text",
|
|
553
554
|
value: l,
|
|
554
|
-
onChange: (
|
|
555
|
+
onChange: (f) => u(f.target.value),
|
|
555
556
|
placeholder: "Search..."
|
|
556
557
|
}
|
|
557
558
|
) });
|
|
558
|
-
}),
|
|
559
|
-
const { listState: i } = x(), { data: a, count: n, pagination: r, loader: l, error:
|
|
560
|
-
const
|
|
561
|
-
return { from:
|
|
562
|
-
}, [m, u, n, a]),
|
|
559
|
+
}), pe = B(({ children: s }) => {
|
|
560
|
+
const { listState: i } = x(), { data: a, count: n, pagination: r, loader: l, error: d } = i, { page: m, perPage: u } = r, { initialLoading: h, isLoading: f } = l, y = C(() => {
|
|
561
|
+
const v = m * u - u + 1, I = Math.min(m * u, n), P = (a == null ? void 0 : a.length) || 0;
|
|
562
|
+
return { from: v, to: I, visibleCount: P };
|
|
563
|
+
}, [m, u, n, a]), L = C(
|
|
563
564
|
() => ({
|
|
564
565
|
...y,
|
|
565
566
|
count: n
|
|
566
567
|
}),
|
|
567
568
|
[y, n]
|
|
568
569
|
);
|
|
569
|
-
return h || !a || a.length === 0 ||
|
|
570
|
+
return h || !a || a.length === 0 || d ? null : /* @__PURE__ */ c("div", { className: "react-list-summary", children: s ? s(L) : /* @__PURE__ */ T("span", { children: [
|
|
570
571
|
"Showing ",
|
|
571
572
|
/* @__PURE__ */ c("span", { children: y.visibleCount }),
|
|
572
573
|
" items (",
|
|
573
|
-
/* @__PURE__ */
|
|
574
|
+
/* @__PURE__ */ T("span", { children: [
|
|
574
575
|
y.from,
|
|
575
576
|
" - ",
|
|
576
577
|
y.to
|
|
@@ -580,19 +581,19 @@ const U = V(null), j = ({ children: s, config: i }) => {
|
|
|
580
581
|
] }) });
|
|
581
582
|
});
|
|
582
583
|
export {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
584
|
+
te as ReactListAttributes,
|
|
585
|
+
se as ReactListEmpty,
|
|
586
|
+
ne as ReactListError,
|
|
587
|
+
re as ReactListGoTo,
|
|
588
|
+
ie as ReactListInitialLoader,
|
|
589
|
+
ae as ReactListItems,
|
|
590
|
+
le as ReactListLoadMore,
|
|
591
|
+
ce as ReactListLoader,
|
|
592
|
+
ue as ReactListPagination,
|
|
593
|
+
ge as ReactListPerPage,
|
|
594
|
+
ee as ReactListProvider,
|
|
595
|
+
de as ReactListRefresh,
|
|
596
|
+
fe as ReactListSearch,
|
|
597
|
+
pe as ReactListSummary,
|
|
598
|
+
oe as default
|
|
598
599
|
};
|