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