@7span/react-list 0.0.6 → 1.0.0

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