@7span/react-list 0.0.5 → 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 +400 -310
- package/dist/react-list.umd.cjs +1 -1
- package/package.json +11 -3
- 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,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
const { requestHandler:
|
|
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
|
+
const { requestHandler: a, stateManager: n = {} } = i, [r, l] = G({
|
|
5
5
|
data: [],
|
|
6
6
|
response: null,
|
|
7
7
|
error: null,
|
|
@@ -25,223 +25,306 @@ const I = $(null), H = ({ children: r, config: o }) => {
|
|
|
25
25
|
isEmpty: !0,
|
|
26
26
|
isInitializing: !0
|
|
27
27
|
});
|
|
28
|
-
if (!
|
|
28
|
+
if (!a)
|
|
29
29
|
throw new Error("ListProvider: requestHandler is required.");
|
|
30
|
-
const
|
|
30
|
+
const d = C(
|
|
31
31
|
() => ({
|
|
32
|
-
requestHandler:
|
|
33
|
-
stateManager:
|
|
34
|
-
listState:
|
|
35
|
-
setListState:
|
|
32
|
+
requestHandler: a,
|
|
33
|
+
stateManager: n,
|
|
34
|
+
listState: r,
|
|
35
|
+
setListState: l
|
|
36
36
|
}),
|
|
37
|
-
[
|
|
37
|
+
[a, n, r]
|
|
38
38
|
);
|
|
39
|
-
return /* @__PURE__ */
|
|
40
|
-
},
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
39
|
+
return /* @__PURE__ */ c(V.Provider, { value: d, children: s });
|
|
40
|
+
}, x = () => {
|
|
41
|
+
const s = Y(V);
|
|
42
|
+
if (!s)
|
|
43
43
|
throw new Error("useListContext must be used within a ListProvider");
|
|
44
|
-
return
|
|
45
|
-
},
|
|
46
|
-
const { listState:
|
|
47
|
-
(u) => (
|
|
48
|
-
|
|
44
|
+
return s;
|
|
45
|
+
}, te = B(({ children: s, renderAttribute: i }) => {
|
|
46
|
+
const { listState: a } = x(), { attrs: n, attrSettings: r, updateAttr: l } = a, d = E(
|
|
47
|
+
(u) => (h) => {
|
|
48
|
+
l(u, "visible", h.target.checked);
|
|
49
49
|
},
|
|
50
|
-
[
|
|
51
|
-
),
|
|
50
|
+
[l]
|
|
51
|
+
), m = C(
|
|
52
52
|
() => ({
|
|
53
|
-
attrs:
|
|
54
|
-
attrSettings:
|
|
55
|
-
updateAttr:
|
|
53
|
+
attrs: n,
|
|
54
|
+
attrSettings: r,
|
|
55
|
+
updateAttr: l
|
|
56
56
|
}),
|
|
57
|
-
[
|
|
57
|
+
[n, r, l]
|
|
58
58
|
);
|
|
59
|
-
return
|
|
60
|
-
var
|
|
61
|
-
return
|
|
62
|
-
key: `attr-${
|
|
59
|
+
return s ? s(m) : /* @__PURE__ */ c("div", { className: "react-list-attributes", children: n.map((u, h) => {
|
|
60
|
+
var f;
|
|
61
|
+
return i ? i({
|
|
62
|
+
key: `attr-${h}`,
|
|
63
63
|
attr: u,
|
|
64
|
-
updateAttr:
|
|
65
|
-
attrSettings:
|
|
66
|
-
}) : /* @__PURE__ */
|
|
67
|
-
/* @__PURE__ */
|
|
68
|
-
/* @__PURE__ */
|
|
64
|
+
updateAttr: l,
|
|
65
|
+
attrSettings: r
|
|
66
|
+
}) : /* @__PURE__ */ T("label", { children: [
|
|
67
|
+
/* @__PURE__ */ c("span", { children: u.label }),
|
|
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
|
-
] }, `attr-${
|
|
76
|
+
] }, `attr-${h}`);
|
|
77
77
|
}) });
|
|
78
|
-
}),
|
|
79
|
-
const { listState:
|
|
80
|
-
return (
|
|
81
|
-
}),
|
|
82
|
-
const { listState:
|
|
83
|
-
return !
|
|
84
|
-
/* @__PURE__ */
|
|
85
|
-
/* @__PURE__ */
|
|
86
|
-
|
|
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
|
+
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__ */ T("div", { children: [
|
|
84
|
+
/* @__PURE__ */ c("h3", { children: "Error occurred" }),
|
|
85
|
+
/* @__PURE__ */ T("pre", { children: [
|
|
86
|
+
a.name,
|
|
87
87
|
": ",
|
|
88
|
-
|
|
88
|
+
a.message
|
|
89
89
|
] })
|
|
90
90
|
] }) });
|
|
91
|
-
}),
|
|
92
|
-
const { listState:
|
|
93
|
-
const
|
|
94
|
-
return { pages: Array.from({ length:
|
|
95
|
-
}, [
|
|
96
|
-
(
|
|
97
|
-
|
|
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
|
-
[
|
|
100
|
-
),
|
|
99
|
+
[l]
|
|
100
|
+
), P = C(
|
|
101
101
|
() => ({
|
|
102
|
-
setPage:
|
|
102
|
+
setPage: l,
|
|
103
103
|
page: u,
|
|
104
|
-
pages:
|
|
105
|
-
pagesCount:
|
|
104
|
+
pages: L,
|
|
105
|
+
pagesCount: v
|
|
106
106
|
}),
|
|
107
|
-
[
|
|
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
|
-
}),
|
|
114
|
-
const { listState:
|
|
115
|
-
return
|
|
111
|
+
R
|
|
112
|
+
] }, `page-${R}`)) }) });
|
|
113
|
+
}), ie = B(({ children: s }) => {
|
|
114
|
+
const { listState: i } = x(), { loader: a } = i, { initialLoading: n } = a;
|
|
115
|
+
return C(
|
|
116
116
|
() => ({
|
|
117
|
-
loading:
|
|
117
|
+
loading: n
|
|
118
118
|
}),
|
|
119
|
-
[
|
|
120
|
-
),
|
|
121
|
-
}),
|
|
122
|
-
const { listState:
|
|
119
|
+
[n]
|
|
120
|
+
), n ? /* @__PURE__ */ c("div", { className: "react-list-initial-loader", children: s || /* @__PURE__ */ c("p", { children: "Initial Loading..." }) }) : null;
|
|
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
|
-
items:
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
items: n,
|
|
125
|
+
isLoading: h,
|
|
126
|
+
setSort: d,
|
|
127
|
+
sort: m
|
|
127
128
|
}),
|
|
128
|
-
[
|
|
129
|
+
[n, m, d, h]
|
|
129
130
|
);
|
|
130
|
-
return u || !
|
|
131
|
-
}),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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)) });
|
|
132
|
+
}), W = (s, i) => {
|
|
133
|
+
if (s === i) return !0;
|
|
134
|
+
if (s == null || i == null || typeof s != "object" || typeof i != "object")
|
|
135
|
+
return s === i;
|
|
136
|
+
if (Array.isArray(s) && Array.isArray(i)) {
|
|
137
|
+
if (s.length !== i.length) return !1;
|
|
138
|
+
for (let r = 0; r < s.length; r++)
|
|
139
|
+
if (!W(s[r], i[r])) return !1;
|
|
140
|
+
return !0;
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(s) || Array.isArray(i)) return !1;
|
|
143
|
+
const a = Object.keys(s).filter((r) => s[r] !== void 0), n = Object.keys(i).filter((r) => i[r] !== void 0);
|
|
144
|
+
if (a.length !== n.length) return !1;
|
|
145
|
+
for (let r of a)
|
|
146
|
+
if (!n.includes(r) || !W(s[r], i[r])) return !1;
|
|
147
|
+
return !0;
|
|
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 = ({
|
|
149
|
+
initialItems: s = [],
|
|
150
|
+
children: i,
|
|
151
|
+
endpoint: a,
|
|
152
|
+
page: n = 1,
|
|
153
|
+
perPage: r = 25,
|
|
154
|
+
sortBy: l = "",
|
|
155
|
+
sortOrder: d = "desc",
|
|
156
|
+
count: m = 0,
|
|
140
157
|
search: u = "",
|
|
141
|
-
filters:
|
|
142
|
-
attrs:
|
|
143
|
-
version:
|
|
144
|
-
paginationMode:
|
|
145
|
-
meta:
|
|
158
|
+
filters: h = {},
|
|
159
|
+
attrs: f,
|
|
160
|
+
version: y = 1,
|
|
161
|
+
paginationMode: L = "pagination",
|
|
162
|
+
meta: v = {},
|
|
163
|
+
onResponse: I,
|
|
164
|
+
afterPageChange: P,
|
|
165
|
+
afterLoadMore: R
|
|
146
166
|
}) => {
|
|
147
|
-
const { requestHandler:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
const { requestHandler: $, setListState: _, stateManager: p } = x(), M = U(!1), k = L === "loadMore", A = E(
|
|
168
|
+
(e) => ({
|
|
169
|
+
endpoint: a,
|
|
170
|
+
version: y,
|
|
171
|
+
meta: v,
|
|
172
|
+
search: (e == null ? void 0 : e.search) || u,
|
|
173
|
+
page: (e == null ? void 0 : e.page) || n,
|
|
174
|
+
perPage: (e == null ? void 0 : e.perPage) || r,
|
|
175
|
+
sortBy: (e == null ? void 0 : e.sortBy) || l,
|
|
176
|
+
sortOrder: (e == null ? void 0 : e.sortOrder) || d,
|
|
177
|
+
filters: (e == null ? void 0 : e.filters) || h,
|
|
178
|
+
attrSettings: (e == null ? void 0 : e.attrSettings) || {},
|
|
179
|
+
isRefresh: !1
|
|
180
|
+
}),
|
|
181
|
+
[a, y, v, u, n, r, l, d, h]
|
|
182
|
+
), O = E(() => {
|
|
183
|
+
var e;
|
|
184
|
+
try {
|
|
185
|
+
const g = A(), o = (e = p == null ? void 0 : p.get) == null ? void 0 : e.call(p, g);
|
|
186
|
+
return {
|
|
187
|
+
page: o == null ? void 0 : o.page,
|
|
188
|
+
perPage: o == null ? void 0 : o.perPage,
|
|
189
|
+
sortBy: o == null ? void 0 : o.sortBy,
|
|
190
|
+
sortOrder: o == null ? void 0 : o.sortOrder,
|
|
191
|
+
search: o == null ? void 0 : o.search,
|
|
192
|
+
attrSettings: o == null ? void 0 : o.attrSettings,
|
|
193
|
+
filters: o == null ? void 0 : o.filters
|
|
194
|
+
};
|
|
195
|
+
} catch (g) {
|
|
196
|
+
return console.error(g), {};
|
|
197
|
+
}
|
|
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,
|
|
203
|
+
perPage: e.perPage != null ? e.perPage : r,
|
|
204
|
+
sortBy: e.sortBy != null ? e.sortBy : l,
|
|
205
|
+
sortOrder: e.sortOrder != null ? e.sortOrder : d,
|
|
206
|
+
search: e.search != null ? e.search : u,
|
|
207
|
+
filters: e.filters != null ? e.filters : h,
|
|
208
|
+
attrSettings: e.attrSettings || {},
|
|
209
|
+
items: s,
|
|
210
|
+
selection: [],
|
|
211
|
+
error: null,
|
|
212
|
+
response: null,
|
|
213
|
+
count: 0,
|
|
214
|
+
isLoading: !1,
|
|
215
|
+
initializingState: !s.length,
|
|
216
|
+
confirmedPage: null
|
|
217
|
+
};
|
|
218
|
+
}, [
|
|
219
|
+
O,
|
|
220
|
+
u,
|
|
221
|
+
n,
|
|
222
|
+
r,
|
|
223
|
+
l,
|
|
224
|
+
d,
|
|
225
|
+
u,
|
|
226
|
+
h,
|
|
227
|
+
k
|
|
228
|
+
]), [t, b] = G(N), q = E(
|
|
229
|
+
(e) => {
|
|
230
|
+
var g;
|
|
231
|
+
if (p) {
|
|
232
|
+
const o = A(e);
|
|
233
|
+
(g = p == null ? void 0 : p.set) == null || g.call(p, o);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
[p, A]
|
|
237
|
+
), z = E(
|
|
238
|
+
async (e = {}, g = null) => {
|
|
239
|
+
t.initializingState || b((o) => ({ ...o, error: null, isLoading: !0 }));
|
|
165
240
|
try {
|
|
166
|
-
const
|
|
167
|
-
endpoint:
|
|
168
|
-
version:
|
|
169
|
-
meta:
|
|
170
|
-
page:
|
|
171
|
-
perPage:
|
|
172
|
-
search:
|
|
173
|
-
sortBy:
|
|
174
|
-
sortOrder:
|
|
175
|
-
filters:
|
|
176
|
-
...
|
|
241
|
+
const o = g || t, w = (g == null ? void 0 : g.items) ?? t.items, S = await $({
|
|
242
|
+
endpoint: a,
|
|
243
|
+
version: y,
|
|
244
|
+
meta: v,
|
|
245
|
+
page: o.page,
|
|
246
|
+
perPage: o.perPage,
|
|
247
|
+
search: o.search,
|
|
248
|
+
sortBy: o.sortBy,
|
|
249
|
+
sortOrder: o.sortOrder,
|
|
250
|
+
filters: o.filters,
|
|
251
|
+
...e
|
|
177
252
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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 = {
|
|
257
|
+
...o,
|
|
258
|
+
response: S,
|
|
181
259
|
selection: [],
|
|
182
260
|
// Append items for loadMore, replace for pagination
|
|
183
|
-
items:
|
|
184
|
-
count:
|
|
261
|
+
items: k && o.page > 1 ? [...w, ...S.items] : S.items,
|
|
262
|
+
count: S.count,
|
|
185
263
|
initializingState: !1,
|
|
186
264
|
isLoading: !1
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
265
|
+
};
|
|
266
|
+
q(Q), b(Q);
|
|
267
|
+
} catch (o) {
|
|
268
|
+
throw b((w) => ({
|
|
269
|
+
...w,
|
|
270
|
+
error: o,
|
|
192
271
|
items: [],
|
|
193
272
|
count: 0,
|
|
194
273
|
initializingState: !1,
|
|
195
274
|
isLoading: !1
|
|
196
|
-
})),
|
|
275
|
+
})), o;
|
|
197
276
|
}
|
|
198
277
|
},
|
|
199
|
-
[
|
|
200
|
-
),
|
|
278
|
+
[a, y, k, v, $, t]
|
|
279
|
+
), H = C(
|
|
201
280
|
() => ({
|
|
202
|
-
setPage: (
|
|
203
|
-
let
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
281
|
+
setPage: (e, g) => {
|
|
282
|
+
let o = e;
|
|
283
|
+
e === 0 && (o = "");
|
|
284
|
+
const w = { ...t, page: o };
|
|
285
|
+
b(w), o && z(g, w);
|
|
207
286
|
},
|
|
208
|
-
setPerPage: (
|
|
209
|
-
const
|
|
210
|
-
|
|
287
|
+
setPerPage: (e) => {
|
|
288
|
+
const g = { ...t, perPage: e, page: 1 };
|
|
289
|
+
b(g), z({}, g);
|
|
211
290
|
},
|
|
212
|
-
setSearch: (
|
|
213
|
-
if (
|
|
214
|
-
const
|
|
215
|
-
|
|
291
|
+
setSearch: (e) => {
|
|
292
|
+
if (e !== t.search) {
|
|
293
|
+
const g = { ...t, search: e, page: 1 };
|
|
294
|
+
b(g), z({}, g);
|
|
216
295
|
}
|
|
217
296
|
},
|
|
218
|
-
setSort: ({ by:
|
|
219
|
-
const
|
|
220
|
-
|
|
297
|
+
setSort: ({ by: e, order: g }) => {
|
|
298
|
+
const o = { ...t, sortBy: e, sortOrder: g, page: 1 };
|
|
299
|
+
b(o), z({}, o);
|
|
221
300
|
},
|
|
222
301
|
loadMore: () => {
|
|
223
|
-
const
|
|
224
|
-
|
|
302
|
+
const e = { ...t, page: t.page + 1 };
|
|
303
|
+
b(e), z({}, e);
|
|
225
304
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
305
|
+
clearFilters: () => {
|
|
306
|
+
const e = { ...t, filters: h, page: 1 };
|
|
307
|
+
b(e), z({}, e);
|
|
308
|
+
},
|
|
309
|
+
refresh: (e = { isRefresh: !0 }) => {
|
|
310
|
+
if (k) {
|
|
311
|
+
const g = { ...t, page: 1, items: [] };
|
|
312
|
+
b(g), z(e, g);
|
|
230
313
|
} else
|
|
231
|
-
|
|
314
|
+
z(e);
|
|
232
315
|
},
|
|
233
|
-
setFilters: (
|
|
234
|
-
const
|
|
235
|
-
|
|
316
|
+
setFilters: (e) => {
|
|
317
|
+
const g = { ...t, filters: e, page: 1 };
|
|
318
|
+
b(g), z({}, g);
|
|
236
319
|
},
|
|
237
|
-
updateItemById: (
|
|
238
|
-
const
|
|
239
|
-
|
|
320
|
+
updateItemById: (e, g) => {
|
|
321
|
+
const o = t.items.map((w) => w.id === g ? { ...w, ...e } : w);
|
|
322
|
+
b((w) => ({ ...w, items: o }));
|
|
240
323
|
},
|
|
241
|
-
setSelection: (
|
|
324
|
+
setSelection: (e) => b((g) => ({ ...g, selection: e }))
|
|
242
325
|
}),
|
|
243
|
-
[
|
|
244
|
-
),
|
|
326
|
+
[z, k, t]
|
|
327
|
+
), J = C(
|
|
245
328
|
() => ({
|
|
246
329
|
data: t.items,
|
|
247
330
|
response: t.response,
|
|
@@ -258,11 +341,12 @@ const I = $(null), H = ({ children: r, config: o }) => {
|
|
|
258
341
|
initialLoading: t.initializingState
|
|
259
342
|
},
|
|
260
343
|
sort: { sortBy: t.sortBy, sortOrder: t.sortOrder },
|
|
344
|
+
hasActiveFilters: Z(t.filters, h),
|
|
261
345
|
search: t.search,
|
|
262
346
|
filters: t.filters,
|
|
263
|
-
attrs:
|
|
347
|
+
attrs: f || Object.keys(t.items[0] || {}),
|
|
264
348
|
isEmpty: t.items.length === 0,
|
|
265
|
-
...
|
|
349
|
+
...H
|
|
266
350
|
}),
|
|
267
351
|
[
|
|
268
352
|
t.items,
|
|
@@ -278,16 +362,22 @@ const I = $(null), H = ({ children: r, config: o }) => {
|
|
|
278
362
|
t.sortOrder,
|
|
279
363
|
t.search,
|
|
280
364
|
t.filters,
|
|
281
|
-
|
|
282
|
-
|
|
365
|
+
H,
|
|
366
|
+
f
|
|
283
367
|
]
|
|
284
368
|
);
|
|
285
|
-
return
|
|
286
|
-
t.initializingState &&
|
|
287
|
-
|
|
288
|
-
|
|
369
|
+
return D(() => {
|
|
370
|
+
if (t.initializingState && !M.current) {
|
|
371
|
+
if (M.current = !0, p != null && p.init) {
|
|
372
|
+
const e = A(t);
|
|
373
|
+
p.init(e);
|
|
374
|
+
}
|
|
375
|
+
s.length || H.setPage(t.page);
|
|
376
|
+
}
|
|
377
|
+
}, []), D(() => {
|
|
378
|
+
_(J);
|
|
289
379
|
}, [
|
|
290
|
-
|
|
380
|
+
_,
|
|
291
381
|
t.items,
|
|
292
382
|
t.count,
|
|
293
383
|
t.error,
|
|
@@ -297,213 +387,213 @@ const I = $(null), H = ({ children: r, config: o }) => {
|
|
|
297
387
|
t.perPage,
|
|
298
388
|
t.sortBy,
|
|
299
389
|
t.sortOrder
|
|
300
|
-
]), typeof
|
|
301
|
-
},
|
|
302
|
-
const { listState:
|
|
303
|
-
() => u *
|
|
304
|
-
[u,
|
|
305
|
-
),
|
|
306
|
-
|
|
307
|
-
}, [f, l,
|
|
390
|
+
]), typeof i == "function" ? i(J) : i;
|
|
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(
|
|
393
|
+
() => u * h < n,
|
|
394
|
+
[u, h, n]
|
|
395
|
+
), L = E(() => {
|
|
396
|
+
y && !f && l(u + 1);
|
|
397
|
+
}, [y, f, l, u]), v = C(
|
|
308
398
|
() => ({
|
|
309
|
-
isLoading:
|
|
310
|
-
loadMore:
|
|
311
|
-
hasMoreItems:
|
|
399
|
+
isLoading: f,
|
|
400
|
+
loadMore: L,
|
|
401
|
+
hasMoreItems: y
|
|
312
402
|
}),
|
|
313
|
-
[
|
|
403
|
+
[f, L, y]
|
|
314
404
|
);
|
|
315
|
-
return !
|
|
316
|
-
}),
|
|
317
|
-
const { listState:
|
|
318
|
-
return
|
|
405
|
+
return !a || a.length === 0 || m ? null : s(v);
|
|
406
|
+
}), ce = B(({ children: s, position: i = "overlay" }) => {
|
|
407
|
+
const { listState: a } = x(), { loader: n } = a, { isLoading: r, initializingState: l } = n;
|
|
408
|
+
return C(
|
|
319
409
|
() => ({
|
|
320
|
-
isLoading:
|
|
410
|
+
isLoading: r
|
|
321
411
|
}),
|
|
322
|
-
[
|
|
323
|
-
), !
|
|
324
|
-
}),
|
|
412
|
+
[r]
|
|
413
|
+
), !l && !r ? null : /* @__PURE__ */ c("div", { children: s || /* @__PURE__ */ c("div", { children: /* @__PURE__ */ c("p", { children: "Loading..." }) }) });
|
|
414
|
+
}), ue = B(
|
|
325
415
|
({
|
|
326
|
-
children:
|
|
327
|
-
pageLinks:
|
|
328
|
-
renderFirst:
|
|
329
|
-
renderPrev:
|
|
330
|
-
renderPages:
|
|
331
|
-
renderPage:
|
|
332
|
-
renderNext:
|
|
333
|
-
renderLast:
|
|
416
|
+
children: s,
|
|
417
|
+
pageLinks: i = 5,
|
|
418
|
+
renderFirst: a,
|
|
419
|
+
renderPrev: n,
|
|
420
|
+
renderPages: r,
|
|
421
|
+
renderPage: l,
|
|
422
|
+
renderNext: d,
|
|
423
|
+
renderLast: m
|
|
334
424
|
}) => {
|
|
335
|
-
const { listState: u } =
|
|
336
|
-
const
|
|
337
|
-
return { pagesCount:
|
|
338
|
-
}, [
|
|
339
|
-
const { pagesCount:
|
|
340
|
-
return
|
|
341
|
-
}, [
|
|
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);
|
|
431
|
+
}, [P, i, p]), k = C(
|
|
342
432
|
() => ({
|
|
343
|
-
prev: () =>
|
|
344
|
-
next: () =>
|
|
345
|
-
first: () =>
|
|
346
|
-
last: () =>
|
|
347
|
-
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)
|
|
348
438
|
}),
|
|
349
|
-
[
|
|
350
|
-
),
|
|
439
|
+
[L, P, p.pagesCount]
|
|
440
|
+
), A = C(
|
|
351
441
|
() => ({
|
|
352
|
-
page:
|
|
353
|
-
perPage:
|
|
354
|
-
count:
|
|
355
|
-
...
|
|
356
|
-
pagesToDisplay:
|
|
357
|
-
...
|
|
442
|
+
page: P,
|
|
443
|
+
perPage: R,
|
|
444
|
+
count: f,
|
|
445
|
+
...p,
|
|
446
|
+
pagesToDisplay: M,
|
|
447
|
+
...k
|
|
358
448
|
}),
|
|
359
|
-
[
|
|
449
|
+
[P, R, f, p, M, k]
|
|
360
450
|
);
|
|
361
|
-
return
|
|
362
|
-
|
|
451
|
+
return $ || !h || h.length === 0 || I ? null : s ? s(A) : /* @__PURE__ */ T("div", { className: "react-list-pagination", children: [
|
|
452
|
+
a ? a(A) : /* @__PURE__ */ c(
|
|
363
453
|
"button",
|
|
364
454
|
{
|
|
365
455
|
type: "button",
|
|
366
|
-
disabled: !
|
|
367
|
-
onClick:
|
|
456
|
+
disabled: !p.hasPrev,
|
|
457
|
+
onClick: k.first,
|
|
368
458
|
children: "First"
|
|
369
459
|
}
|
|
370
460
|
),
|
|
371
|
-
|
|
461
|
+
n ? n(A) : /* @__PURE__ */ c(
|
|
372
462
|
"button",
|
|
373
463
|
{
|
|
374
464
|
type: "button",
|
|
375
|
-
disabled: !
|
|
376
|
-
onClick:
|
|
465
|
+
disabled: !p.hasPrev,
|
|
466
|
+
onClick: k.prev,
|
|
377
467
|
children: "Prev"
|
|
378
468
|
}
|
|
379
469
|
),
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
return
|
|
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(
|
|
383
473
|
"button",
|
|
384
474
|
{
|
|
385
475
|
type: "button",
|
|
386
|
-
onClick: () =>
|
|
387
|
-
children:
|
|
476
|
+
onClick: () => k.setPage(O),
|
|
477
|
+
children: O
|
|
388
478
|
}
|
|
389
|
-
) }, `page-${
|
|
479
|
+
) }, `page-${O}`);
|
|
390
480
|
}) }),
|
|
391
|
-
|
|
481
|
+
d ? d(A) : /* @__PURE__ */ c(
|
|
392
482
|
"button",
|
|
393
483
|
{
|
|
394
484
|
type: "button",
|
|
395
|
-
disabled: !
|
|
396
|
-
onClick:
|
|
485
|
+
disabled: !p.hasNext,
|
|
486
|
+
onClick: k.next,
|
|
397
487
|
children: "Next"
|
|
398
488
|
}
|
|
399
489
|
),
|
|
400
|
-
|
|
490
|
+
m ? m(A) : /* @__PURE__ */ c(
|
|
401
491
|
"button",
|
|
402
492
|
{
|
|
403
493
|
type: "button",
|
|
404
|
-
disabled: !
|
|
405
|
-
onClick:
|
|
494
|
+
disabled: !p.hasNext,
|
|
495
|
+
onClick: k.last,
|
|
406
496
|
children: "Last"
|
|
407
497
|
}
|
|
408
498
|
)
|
|
409
499
|
] });
|
|
410
500
|
}
|
|
411
|
-
),
|
|
412
|
-
({ children:
|
|
413
|
-
const { listState:
|
|
414
|
-
value:
|
|
415
|
-
label:
|
|
416
|
-
} :
|
|
417
|
-
(
|
|
418
|
-
|
|
501
|
+
), ge = B(
|
|
502
|
+
({ children: s, options: i = [10, 25, 50, 100] }) => {
|
|
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));
|
|
419
509
|
},
|
|
420
|
-
[
|
|
421
|
-
),
|
|
510
|
+
[l]
|
|
511
|
+
), L = C(
|
|
422
512
|
() => ({
|
|
423
513
|
perPage: u,
|
|
424
|
-
setPerPage:
|
|
425
|
-
options:
|
|
514
|
+
setPerPage: l,
|
|
515
|
+
options: f
|
|
426
516
|
}),
|
|
427
|
-
[u,
|
|
517
|
+
[u, l, f]
|
|
428
518
|
);
|
|
429
|
-
return
|
|
430
|
-
|
|
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,
|
|
431
521
|
" items per page"
|
|
432
|
-
] }, `option-${
|
|
522
|
+
] }, `option-${v.value}`)) }) });
|
|
433
523
|
}
|
|
434
|
-
),
|
|
435
|
-
const { listState:
|
|
436
|
-
|
|
437
|
-
}, [
|
|
524
|
+
), de = B(({ children: s }) => {
|
|
525
|
+
const { listState: i } = x(), { loader: a, refresh: n } = i, { isLoading: r, initialLoading: l } = a, d = E(() => {
|
|
526
|
+
n({ isRefresh: !0 });
|
|
527
|
+
}, [n]), m = C(
|
|
438
528
|
() => ({
|
|
439
|
-
isLoading:
|
|
440
|
-
refresh:
|
|
529
|
+
isLoading: r,
|
|
530
|
+
refresh: d
|
|
441
531
|
}),
|
|
442
|
-
[
|
|
532
|
+
[r, d]
|
|
443
533
|
);
|
|
444
|
-
return
|
|
445
|
-
}),
|
|
446
|
-
const { listState:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}, [
|
|
450
|
-
const u = (
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
},
|
|
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 ?? "");
|
|
539
|
+
}, [n]);
|
|
540
|
+
const u = (f) => {
|
|
541
|
+
d(f), m.current && clearTimeout(m.current), m.current = setTimeout(() => {
|
|
542
|
+
r(f);
|
|
543
|
+
}, i);
|
|
454
544
|
};
|
|
455
|
-
return
|
|
456
|
-
|
|
457
|
-
}, []), /* @__PURE__ */
|
|
458
|
-
search:
|
|
545
|
+
return D(() => () => {
|
|
546
|
+
m.current && clearTimeout(m.current);
|
|
547
|
+
}, []), /* @__PURE__ */ c("div", { className: "react-list-search", children: s ? s({
|
|
548
|
+
search: l,
|
|
459
549
|
setSearch: u
|
|
460
|
-
}) : /* @__PURE__ */
|
|
550
|
+
}) : /* @__PURE__ */ c(
|
|
461
551
|
"input",
|
|
462
552
|
{
|
|
463
553
|
type: "text",
|
|
464
|
-
value:
|
|
465
|
-
onChange: (
|
|
554
|
+
value: l,
|
|
555
|
+
onChange: (f) => u(f.target.value),
|
|
466
556
|
placeholder: "Search..."
|
|
467
557
|
}
|
|
468
558
|
) });
|
|
469
|
-
}),
|
|
470
|
-
const { listState:
|
|
471
|
-
const
|
|
472
|
-
return { from:
|
|
473
|
-
}, [
|
|
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(
|
|
474
564
|
() => ({
|
|
475
|
-
...
|
|
476
|
-
count:
|
|
565
|
+
...y,
|
|
566
|
+
count: n
|
|
477
567
|
}),
|
|
478
|
-
[
|
|
568
|
+
[y, n]
|
|
479
569
|
);
|
|
480
|
-
return
|
|
570
|
+
return h || !a || a.length === 0 || d ? null : /* @__PURE__ */ c("div", { className: "react-list-summary", children: s ? s(L) : /* @__PURE__ */ T("span", { children: [
|
|
481
571
|
"Showing ",
|
|
482
|
-
/* @__PURE__ */
|
|
572
|
+
/* @__PURE__ */ c("span", { children: y.visibleCount }),
|
|
483
573
|
" items (",
|
|
484
|
-
/* @__PURE__ */
|
|
485
|
-
|
|
574
|
+
/* @__PURE__ */ T("span", { children: [
|
|
575
|
+
y.from,
|
|
486
576
|
" - ",
|
|
487
|
-
|
|
577
|
+
y.to
|
|
488
578
|
] }),
|
|
489
579
|
") out of ",
|
|
490
|
-
/* @__PURE__ */
|
|
580
|
+
/* @__PURE__ */ c("span", { children: n })
|
|
491
581
|
] }) });
|
|
492
582
|
});
|
|
493
583
|
export {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
|
509
599
|
};
|