@7span/react-list 0.0.5 → 1.0.0

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