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