@7span/react-list 0.0.1 → 0.0.3

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 l, jsxs as M } from "react/jsx-runtime";
2
- import { createContext as D, useContext as j, useState as O, useMemo as g, memo as R, useCallback as T, useEffect as I, useTransition as $, useRef as q } from "react";
3
- const E = D(null), F = ({ children: i, config: c }) => {
4
- const { requestHandler: r, stateManager: t = {} } = c, [o, n] = O({
1
+ import { jsx as i, jsxs as N } from "react/jsx-runtime";
2
+ import { createContext as $, useContext as j, useState as T, useMemo as P, memo as R, useCallback as O, useEffect as E, useRef as q } from "react";
3
+ const A = $(null), H = ({ children: n, config: o }) => {
4
+ const { requestHandler: r, stateManager: e = {} } = o, [s, a] = T({
5
5
  data: [],
6
6
  response: null,
7
7
  error: null,
@@ -27,251 +27,128 @@ const E = D(null), F = ({ children: i, config: c }) => {
27
27
  });
28
28
  if (!r)
29
29
  throw new Error("ListProvider: requestHandler is required.");
30
- const s = g(
30
+ const p = P(
31
31
  () => ({
32
32
  requestHandler: r,
33
- stateManager: t,
34
- listState: o,
35
- setListState: n
33
+ stateManager: e,
34
+ listState: s,
35
+ setListState: a
36
36
  }),
37
- [r, t, o]
37
+ [r, e, s]
38
38
  );
39
- return /* @__PURE__ */ l(E.Provider, { value: s, children: i });
40
- }, k = () => {
41
- const i = j(E);
42
- if (!i)
39
+ return /* @__PURE__ */ i(A.Provider, { value: p, children: n });
40
+ }, C = () => {
41
+ const n = j(A);
42
+ if (!n)
43
43
  throw new Error("useListContext must be used within a ListProvider");
44
- return i;
45
- }, G = R(({ children: i, renderAttribute: c }) => {
46
- const { listState: r } = k(), { attrs: t, attrSettings: o, updateAttr: n } = r, s = {
47
- container: {
48
- display: "flex",
49
- flexDirection: "column",
50
- gap: "12px",
51
- padding: "12px"
44
+ return n;
45
+ }, W = R(({ children: n, renderAttribute: o }) => {
46
+ const { listState: r } = C(), { attrs: e, attrSettings: s, updateAttr: a } = r, p = O(
47
+ (c) => (L) => {
48
+ a(c, "visible", L.target.checked);
52
49
  },
53
- label: {
54
- display: "flex",
55
- alignItems: "center",
56
- gap: "8px",
57
- cursor: "pointer",
58
- fontSize: "14px"
59
- },
60
- checkbox: {
61
- width: "16px",
62
- height: "16px",
63
- cursor: "pointer"
64
- }
65
- }, f = T(
66
- (h) => (u) => {
67
- n(h, "visible", u.target.checked);
68
- },
69
- [n]
70
- ), a = g(
50
+ [a]
51
+ ), h = P(
71
52
  () => ({
72
- attrs: t,
73
- attrSettings: o,
74
- updateAttr: n,
75
- styles: s
53
+ attrs: e,
54
+ attrSettings: s,
55
+ updateAttr: a
76
56
  }),
77
- [t, o, n]
57
+ [e, s, a]
78
58
  );
79
- return i ? i(a) : /* @__PURE__ */ l("div", { className: "react-list-attributes", style: s.container, children: t.map((h, u) => {
80
- var d;
81
- return c ? c({
82
- key: `attr-${u}`,
83
- attr: h,
84
- updateAttr: n,
85
- attrSettings: o,
86
- styles: s
87
- }) : /* @__PURE__ */ M("label", { style: s.label, children: [
88
- /* @__PURE__ */ l("span", { children: h.label }),
89
- /* @__PURE__ */ l(
59
+ return n ? n(h) : /* @__PURE__ */ i("div", { className: "react-list-attributes", children: e.map((c, L) => {
60
+ var l;
61
+ return o ? o({
62
+ key: `attr-${L}`,
63
+ attr: c,
64
+ updateAttr: a,
65
+ attrSettings: s
66
+ }) : /* @__PURE__ */ N("label", { children: [
67
+ /* @__PURE__ */ i("span", { children: c.label }),
68
+ /* @__PURE__ */ i(
90
69
  "input",
91
70
  {
92
71
  type: "checkbox",
93
- checked: ((d = o == null ? void 0 : o[h.name]) == null ? void 0 : d.visible) ?? !1,
94
- onChange: f(h.name),
95
- style: s.checkbox
72
+ checked: ((l = s == null ? void 0 : s[c.name]) == null ? void 0 : l.visible) ?? !1,
73
+ onChange: p(c.name)
96
74
  }
97
75
  )
98
- ] }, `attr-${u}`);
76
+ ] }, `attr-${L}`);
99
77
  }) });
100
- }), J = R(({ children: i }) => {
101
- const { listState: c } = k(), { data: r, loader: t, error: o } = c, { isLoading: n, initialLoading: s } = t, f = g(
102
- () => ({
103
- container: {
104
- width: "100%",
105
- padding: "32px 16px"
106
- },
107
- defaultMessage: {
108
- textAlign: "center",
109
- color: "#6B7280",
110
- fontSize: "16px",
111
- fontWeight: "400"
112
- }
113
- }),
114
- []
115
- );
116
- return (r == null ? void 0 : r.length) > 0 || s || n || o ? null : /* @__PURE__ */ l("div", { className: "react-list-empty", style: f.container, children: i || /* @__PURE__ */ l("div", { style: f.defaultMessage, children: /* @__PURE__ */ l("p", { children: "No data found!" }) }) });
117
- }), K = R(({ children: i }) => {
118
- const { listState: c } = k(), { error: r, loader: t } = c, { isLoading: o } = t, n = g(
119
- () => ({
120
- container: {
121
- width: "100%",
122
- padding: "32px 16px"
123
- },
124
- errorContent: {
125
- textAlign: "center",
126
- color: "#DC2626",
127
- padding: "32px 0"
128
- },
129
- heading: {
130
- fontSize: "16px",
131
- fontWeight: "500",
132
- marginBottom: "8px"
133
- },
134
- message: {
135
- fontSize: "14px",
136
- fontFamily: "monospace",
137
- marginTop: "8px",
138
- whiteSpace: "pre-wrap",
139
- wordBreak: "break-word"
140
- }
141
- }),
142
- []
143
- );
144
- return !r || o ? null : i ? i({ error: r }) : /* @__PURE__ */ l("div", { className: "react-list-error", style: n.container, children: /* @__PURE__ */ M("div", { style: n.errorContent, children: [
145
- /* @__PURE__ */ l("h3", { style: n.heading, children: "Error occurred" }),
146
- /* @__PURE__ */ M("pre", { style: n.message, children: [
78
+ }), F = R(({ children: n }) => {
79
+ const { listState: o } = C(), { data: r, loader: e, error: s } = o, { isLoading: a, initialLoading: p } = e;
80
+ return (r == null ? void 0 : r.length) > 0 || p || a || s ? null : /* @__PURE__ */ i("div", { className: "react-list-empty", children: n || /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("p", { children: "No data found!" }) }) });
81
+ }), G = R(({ children: n }) => {
82
+ const { listState: o } = C(), { error: r, loader: e } = o, { isLoading: s } = e;
83
+ return !r || s ? null : /* @__PURE__ */ i("div", { className: "react-list-error", children: typeof n == "function" ? n({ error: r }) : n || /* @__PURE__ */ N("div", { children: [
84
+ /* @__PURE__ */ i("h3", { children: "Error occurred" }),
85
+ /* @__PURE__ */ N("pre", { children: [
147
86
  r.name,
148
87
  ": ",
149
88
  r.message
150
89
  ] })
151
90
  ] }) });
152
- }), Q = R(({ children: i }) => {
153
- const { listState: c } = k(), { data: r, count: t, pagination: o, setPage: n, loader: s, error: f } = c, { page: a, perPage: h } = o, { initialLoading: u, isLoading: d } = s, y = g(
154
- () => ({
155
- container: {
156
- display: "inline-block",
157
- minWidth: "120px"
158
- },
159
- select: {
160
- width: "100%",
161
- padding: "8px 12px",
162
- border: "1px solid #ccc",
163
- borderRadius: "4px",
164
- fontSize: "14px",
165
- backgroundColor: "#fff",
166
- cursor: "pointer",
167
- outline: "none"
168
- }
169
- }),
170
- []
171
- ), { pages: P, pagesCount: w } = g(() => {
172
- const L = Math.ceil(t / h);
173
- return { pages: Array.from({ length: L }, (v, C) => C + 1), pagesCount: L };
174
- }, [t, h]), p = T(
175
- (L) => {
176
- n(Number(L.target.value));
91
+ }), J = R(({ children: n }) => {
92
+ const { listState: o } = C(), { data: r, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: c, perPage: L } = s, { initialLoading: l, isLoading: S } = p, { pages: y, pagesCount: v } = P(() => {
93
+ const f = Math.ceil(e / L);
94
+ return { pages: Array.from({ length: f }, (k, b) => b + 1), pagesCount: f };
95
+ }, [e, L]), x = O(
96
+ (f) => {
97
+ a(Number(f.target.value));
177
98
  },
178
- [n]
179
- ), e = g(
99
+ [a]
100
+ ), t = P(
180
101
  () => ({
181
- setPage: n,
182
- page: a,
183
- pages: P,
184
- pagesCount: w,
185
- styles: y
102
+ setPage: a,
103
+ page: c,
104
+ pages: y,
105
+ pagesCount: v
186
106
  }),
187
- [n, a, P, w, y]
107
+ [a, c, y, v]
188
108
  );
189
- return u || !r || r.length === 0 || f ? null : i ? i(e) : /* @__PURE__ */ l("div", { className: "react-list-go-to", style: y.container, children: /* @__PURE__ */ l("select", { value: a, onChange: p, style: y.select, children: P.map((L) => /* @__PURE__ */ M("option", { value: L, children: [
109
+ return l || !r || r.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-go-to", children: n ? n(t) : /* @__PURE__ */ i("select", { value: c, onChange: x, children: y.map((f) => /* @__PURE__ */ N("option", { value: f, children: [
190
110
  "Page ",
191
- L
192
- ] }, `page-${L}`)) }) });
193
- }), U = R(({ children: i }) => {
194
- const { listState: c } = k(), { loader: r } = c, { initialLoading: t } = r, o = g(
195
- () => ({
196
- container: {
197
- padding: "20px",
198
- textAlign: "center"
199
- },
200
- defaultLoader: {
201
- fontSize: "16px",
202
- color: "#4B5563",
203
- margin: 0,
204
- animation: "pulse 1.5s infinite ease-in-out"
205
- },
206
- "@keyframes pulse": {
207
- "0%": { opacity: 0.6 },
208
- "50%": { opacity: 1 },
209
- "100%": { opacity: 0.6 }
210
- }
211
- }),
212
- []
213
- ), n = g(
214
- () => ({
215
- loading: t,
216
- styles: o
217
- }),
218
- [t]
219
- );
220
- return t ? /* @__PURE__ */ l("div", { className: "react-list-initial-loader", style: o.container, children: i ? i(n) : /* @__PURE__ */ l("p", { style: o.defaultLoader, children: "Initial Loading..." }) }) : null;
221
- }), V = R(({ children: i, renderItem: c }) => {
222
- const { listState: r } = k(), { data: t = [], loader: o, error: n } = r, { initialLoading: s, isLoading: f } = o, a = g(
111
+ f
112
+ ] }, `page-${f}`)) }) });
113
+ }), K = R(({ children: n }) => {
114
+ const { listState: o } = C(), { loader: r } = o, { initialLoading: e } = r;
115
+ return P(
223
116
  () => ({
224
- container: {
225
- display: "flex",
226
- flexDirection: "column",
227
- gap: "12px",
228
- width: "100%"
229
- },
230
- itemWrapper: {
231
- width: "100%"
232
- },
233
- defaultItem: {
234
- padding: "12px",
235
- backgroundColor: "#f9fafb",
236
- borderRadius: "4px",
237
- fontFamily: "monospace",
238
- fontSize: "14px",
239
- whiteSpace: "pre-wrap",
240
- wordBreak: "break-word",
241
- overflow: "auto"
242
- }
117
+ loading: e
243
118
  }),
244
- []
245
- ), h = g(
119
+ [e]
120
+ ), e ? /* @__PURE__ */ i("div", { className: "react-list-initial-loader", children: n || /* @__PURE__ */ i("p", { children: "Initial Loading..." }) }) : null;
121
+ }), Q = R(({ children: n, renderItem: o }) => {
122
+ const { listState: r } = C(), { data: e = [], loader: s, error: a, setSort: p, sort: h } = r, { initialLoading: c } = s, L = P(
246
123
  () => ({
247
- items: t,
248
- styles: a
124
+ items: e,
125
+ setSort: p,
126
+ sort: h
249
127
  }),
250
- [t, a]
128
+ [e, h, p]
251
129
  );
252
- return s || !t || t.length === 0 || n ? null : c ? /* @__PURE__ */ l("div", { className: "react-list-items", style: a.container, children: t.map((u, d) => /* @__PURE__ */ l("div", { style: a.itemWrapper, children: c({ item: u, index: d, styles: a }) }, u.id || d)) }) : typeof i == "function" ? /* @__PURE__ */ l("div", { className: "react-list-items", style: a.container, children: i(h) }) : /* @__PURE__ */ l("div", { className: "react-list-items", style: a.container, children: t.map((u, d) => /* @__PURE__ */ l("pre", { style: a.defaultItem, children: JSON.stringify(u, null, 2) }, u.id || d)) });
253
- }), X = ({
254
- children: i,
255
- endpoint: c,
130
+ return c || !e || e.length === 0 || a ? null : o ? /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, S) => /* @__PURE__ */ i("div", { children: o({ item: l, index: S }) }, l.id || S)) }) : typeof n == "function" ? /* @__PURE__ */ i("div", { className: "react-list-items", children: n(L) }) : /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, S) => /* @__PURE__ */ i("pre", { children: JSON.stringify(l, null, 2) }, l.id || S)) });
131
+ }), U = ({
132
+ children: n,
133
+ endpoint: o,
256
134
  page: r = 1,
257
- perPage: t = 25,
258
- sortBy: o,
259
- sortOrder: n = "desc",
260
- search: s = "",
261
- filters: f = {},
262
- attrs: a,
263
- version: h = 1,
264
- hasPaginationHistory: u = !0,
265
- paginationMode: d = "pagination",
266
- meta: y = {}
135
+ perPage: e = 25,
136
+ sortBy: s,
137
+ sortOrder: a = "desc",
138
+ search: p = "",
139
+ filters: h = {},
140
+ attrs: c,
141
+ version: L = 1,
142
+ paginationMode: l = "pagination",
143
+ meta: S = {}
267
144
  }) => {
268
- const { requestHandler: P, setListState: w } = k(), p = d === "loadMore", [e, L] = O({
145
+ const { requestHandler: y, setListState: v } = C(), x = l === "loadMore", [t, f] = T({
269
146
  page: r,
270
- perPage: t,
271
- sortBy: o,
272
- sortOrder: n,
273
- search: s,
274
- filters: f,
147
+ perPage: e,
148
+ sortBy: s,
149
+ sortOrder: a,
150
+ search: p,
151
+ filters: h,
275
152
  attrSettings: {},
276
153
  items: [],
277
154
  selection: [],
@@ -280,580 +157,351 @@ const E = D(null), F = ({ children: i, config: c }) => {
280
157
  count: 0,
281
158
  isLoading: !1,
282
159
  initializingState: !0
283
- }), z = T(
284
- async (b = {}, x = null) => {
285
- e.initializingState || L((m) => ({ ...m, error: null, isLoading: !0 }));
160
+ }), w = O(
161
+ async (m = {}, d = null) => {
162
+ t.initializingState || f((g) => ({ ...g, error: null, isLoading: !0 }));
286
163
  try {
287
- const m = x || e, S = await P({
288
- endpoint: c,
289
- version: h,
290
- meta: y,
291
- page: m.page,
292
- perPage: m.perPage,
293
- search: m.search,
294
- sortBy: m.sortBy,
295
- sortOrder: m.sortOrder,
296
- filters: m.filters,
297
- ...b
164
+ const g = d || t, u = await y({
165
+ endpoint: o,
166
+ version: L,
167
+ meta: S,
168
+ page: g.page,
169
+ perPage: g.perPage,
170
+ search: g.search,
171
+ sortBy: g.sortBy,
172
+ sortOrder: g.sortOrder,
173
+ filters: g.filters,
174
+ ...m
298
175
  });
299
- L((B) => ({
300
- ...B,
301
- response: S,
176
+ f((M) => ({
177
+ ...M,
178
+ response: u,
302
179
  selection: [],
303
180
  // Append items for loadMore, replace for pagination
304
- items: p ? [...B.items, ...S.items] : S.items,
305
- count: S.count,
181
+ items: x && g.page > 1 ? [...M.items, ...u.items] : u.items,
182
+ count: u.count,
306
183
  initializingState: !1,
307
184
  isLoading: !1
308
185
  }));
309
- } catch (m) {
310
- throw L((S) => ({
311
- ...S,
312
- error: m,
186
+ } catch (g) {
187
+ throw f((u) => ({
188
+ ...u,
189
+ error: g,
313
190
  items: [],
314
191
  count: 0,
315
192
  initializingState: !1,
316
193
  isLoading: !1
317
- })), m;
194
+ })), g;
318
195
  }
319
196
  },
320
- [c, h, p, y, P, e]
321
- ), v = g(
197
+ [o, L, x, S, y, t]
198
+ ), k = P(
322
199
  () => ({
323
- setPage: (b, x) => {
324
- let m = b;
325
- b === 0 && (m = "");
326
- const S = { ...e, page: m };
327
- L(S), m && z(x, S);
200
+ setPage: (m, d) => {
201
+ let g = m;
202
+ m === 0 && (g = "");
203
+ const u = { ...t, page: g };
204
+ f(u), g && w(d, u);
328
205
  },
329
- setPerPage: (b) => {
330
- const x = { ...e, perPage: b, page: 1 };
331
- L(x), z({}, x);
206
+ setPerPage: (m) => {
207
+ const d = { ...t, perPage: m, page: 1 };
208
+ f(d), w({}, d);
332
209
  },
333
- setSearch: (b) => {
334
- if (b !== e.search) {
335
- const x = { ...e, search: b, page: 1 };
336
- L(x), z({}, x);
210
+ setSearch: (m) => {
211
+ if (m !== t.search) {
212
+ const d = { ...t, search: m, page: 1 };
213
+ f(d), w({}, d);
337
214
  }
338
215
  },
339
- setSort: ({ by: b, order: x }) => {
340
- const m = { ...e, sortBy: b, sortOrder: x, page: 1 };
341
- L(m), z({}, m);
216
+ setSort: ({ by: m, order: d }) => {
217
+ const g = { ...t, sortBy: m, sortOrder: d, page: 1 };
218
+ f(g), w({}, g);
342
219
  },
343
220
  loadMore: () => {
344
- const b = { ...e, page: e.page + 1 };
345
- L(b), z({}, b);
221
+ const m = { ...t, page: t.page + 1 };
222
+ f(m), w({}, m);
346
223
  },
347
- refresh: (b = { isRefresh: !0 }) => {
348
- if (p) {
349
- const x = { ...e, page: 1, items: [] };
350
- L(x), z(b, x);
224
+ refresh: (m = { isRefresh: !0 }) => {
225
+ if (x) {
226
+ const d = { ...t, page: 1, items: [] };
227
+ f(d), w(m, d);
351
228
  } else
352
- z(b);
229
+ w(m);
353
230
  },
354
- setFilters: (b) => {
355
- const x = { ...e, filters: b, page: 1 };
356
- L(x), z({}, x);
231
+ setFilters: (m) => {
232
+ const d = { ...t, filters: m, page: 1 };
233
+ f(d), w({}, d);
357
234
  },
358
- setSelection: (b) => L((x) => ({ ...x, selection: b }))
235
+ updateItemById: (m, d) => {
236
+ const g = t.items.map((u) => u.id === d ? { ...u, ...m } : u);
237
+ f((u) => ({ ...u, items: g }));
238
+ },
239
+ setSelection: (m) => f((d) => ({ ...d, selection: m }))
359
240
  }),
360
- [z, p, e]
361
- ), C = g(
241
+ [w, x, t]
242
+ ), b = P(
362
243
  () => ({
363
- data: e.items,
364
- response: e.response,
365
- error: e.error,
366
- count: e.count,
367
- selection: e.selection,
244
+ data: t.items,
245
+ response: t.response,
246
+ error: t.error,
247
+ count: t.count,
248
+ selection: t.selection,
368
249
  pagination: {
369
- page: e.page,
370
- perPage: e.perPage,
371
- hasMore: e.items.length < e.count
250
+ page: t.page,
251
+ perPage: t.perPage,
252
+ hasMore: t.items.length < t.count
372
253
  },
373
254
  loader: {
374
- isLoading: e.isLoading,
375
- initialLoading: e.initializingState
255
+ isLoading: t.isLoading,
256
+ initialLoading: t.initializingState
376
257
  },
377
- sort: { sortBy: e.sortBy, sortOrder: e.sortOrder },
378
- search: e.search,
379
- filters: e.filters,
380
- attrs: a || Object.keys(e.items[0] || {}),
381
- isEmpty: e.items.length === 0,
382
- ...v
258
+ sort: { sortBy: t.sortBy, sortOrder: t.sortOrder },
259
+ search: t.search,
260
+ filters: t.filters,
261
+ attrs: c || Object.keys(t.items[0] || {}),
262
+ isEmpty: t.items.length === 0,
263
+ ...k
383
264
  }),
384
265
  [
385
- e.items,
386
- e.response,
387
- e.error,
388
- e.count,
389
- e.selection,
390
- e.page,
391
- e.perPage,
392
- e.isLoading,
393
- e.initializingState,
394
- e.sortBy,
395
- e.sortOrder,
396
- e.search,
397
- e.filters,
398
- v,
399
- a
266
+ t.items,
267
+ t.response,
268
+ t.error,
269
+ t.count,
270
+ t.selection,
271
+ t.page,
272
+ t.perPage,
273
+ t.isLoading,
274
+ t.initializingState,
275
+ t.sortBy,
276
+ t.sortOrder,
277
+ t.search,
278
+ t.filters,
279
+ k,
280
+ c
400
281
  ]
401
282
  );
402
- return I(() => {
403
- e.initializingState && v.setPage(e.page);
404
- }, []), I(() => {
405
- w(C);
283
+ return E(() => {
284
+ t.initializingState && k.setPage(t.page);
285
+ }, []), E(() => {
286
+ v(b);
406
287
  }, [
407
- w,
408
- e.items,
409
- e.count,
410
- e.error,
411
- e.isLoading,
412
- e.selection,
413
- e.page,
414
- e.perPage
415
- ]), i({ ...C });
416
- }, Y = R(({ children: i }) => {
417
- const { listState: c } = k(), { data: r, count: t, pagination: o, setPage: n, loader: s, error: f } = c, { page: a, perPage: h } = o, { isLoading: u } = s, d = g(
418
- () => a * h < t,
419
- [a, h, t]
420
- ), y = T(() => {
421
- d && !u && n(a + 1);
422
- }, [d, u, n, a]), P = g(
288
+ v,
289
+ t.items,
290
+ t.count,
291
+ t.error,
292
+ t.isLoading,
293
+ t.selection,
294
+ t.page,
295
+ t.perPage,
296
+ t.sortBy,
297
+ t.sortOrder
298
+ ]), typeof n == "function" ? n(b) : n;
299
+ }, V = R(({ children: n }) => {
300
+ const { listState: o } = C(), { data: r, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: c, perPage: L } = s, { isLoading: l } = p, S = P(
301
+ () => c * L < e,
302
+ [c, L, e]
303
+ ), y = O(() => {
304
+ S && !l && a(c + 1);
305
+ }, [S, l, a, c]), v = P(
423
306
  () => ({
424
- button: {
425
- padding: "8px 16px",
426
- backgroundColor: "#4B5563",
427
- color: "#ffffff",
428
- border: "none",
429
- borderRadius: "4px",
430
- cursor: "pointer",
431
- opacity: u || !d ? 0.5 : 1,
432
- pointerEvents: u || !d ? "none" : "auto"
433
- }
434
- }),
435
- [u, d]
436
- ), w = g(
437
- () => ({
438
- isLoading: u,
307
+ isLoading: l,
439
308
  loadMore: y,
440
- hasMoreItems: d,
441
- styles: P
309
+ hasMoreItems: S
442
310
  }),
443
- [u, y, d, P]
311
+ [l, y, S]
444
312
  );
445
- return !r || r.length === 0 || f ? null : i(w);
446
- }), Z = R(({ children: i, position: c = "overlay" }) => {
447
- const { listState: r } = k(), { loader: t } = r, { isLoading: o, initializingState: n } = t, s = g(
448
- () => ({
449
- overlay: {
450
- position: "absolute",
451
- top: 0,
452
- left: 0,
453
- right: 0,
454
- bottom: 0,
455
- backgroundColor: "rgba(255, 255, 255, 0.5)",
456
- zIndex: 10
457
- },
458
- before: {
459
- marginBottom: "16px"
460
- },
461
- after: {
462
- marginTop: "16px"
463
- },
464
- defaultLoader: {
465
- display: "flex",
466
- alignItems: "center",
467
- justifyContent: "center",
468
- height: "100%"
469
- },
470
- loadingText: {
471
- color: "#4B5563",
472
- fontSize: "14px"
473
- }
474
- }),
475
- []
476
- ), f = g(
313
+ return !r || r.length === 0 || h ? null : n(v);
314
+ }), X = R(({ children: n, position: o = "overlay" }) => {
315
+ const { listState: r } = C(), { loader: e } = r, { isLoading: s, initializingState: a } = e;
316
+ return P(
477
317
  () => ({
478
- overlay: s.overlay,
479
- before: s.before,
480
- after: s.after
318
+ isLoading: s
481
319
  }),
482
320
  [s]
483
- ), a = g(
484
- () => ({
485
- isLoading: o,
486
- styles: s
487
- }),
488
- [o, s]
489
- );
490
- return !n && !o ? null : /* @__PURE__ */ l("div", { style: f[c] || {}, children: i ? i(a) : /* @__PURE__ */ l("div", { style: s.defaultLoader, children: /* @__PURE__ */ l("p", { style: s.loadingText, children: "Loading..." }) }) });
491
- }), ee = R(
321
+ ), !a && !s ? null : /* @__PURE__ */ i("div", { children: n || /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("p", { children: "Loading..." }) }) });
322
+ }), Y = R(
492
323
  ({
493
- children: i,
494
- pageLinks: c = 5,
324
+ children: n,
325
+ pageLinks: o = 5,
495
326
  renderFirst: r,
496
- renderPrev: t,
497
- renderPages: o,
498
- renderPage: n,
499
- renderNext: s,
500
- renderLast: f
327
+ renderPrev: e,
328
+ renderPages: s,
329
+ renderPage: a,
330
+ renderNext: p,
331
+ renderLast: h
501
332
  }) => {
502
- const { listState: a } = k(), { data: h, count: u, pagination: d, setPage: y, loader: P, error: w } = a, { page: p, perPage: e } = d, { initialLoading: L, isLoading: z } = P, v = g(
503
- () => ({
504
- container: {
505
- display: "flex",
506
- alignItems: "center",
507
- gap: "8px"
508
- },
509
- button: {
510
- padding: "4px 8px",
511
- border: "1px solid #e5e7eb",
512
- borderRadius: "4px",
513
- cursor: "pointer",
514
- backgroundColor: "#ffffff",
515
- minWidth: "60px",
516
- fontSize: "14px"
517
- },
518
- disabledButton: {
519
- opacity: 0.5,
520
- cursor: "not-allowed"
521
- },
522
- pagesContainer: {
523
- display: "flex",
524
- alignItems: "center",
525
- gap: "4px"
526
- },
527
- activePageSpan: {
528
- padding: "4px 8px",
529
- backgroundColor: "#2563eb",
530
- color: "#ffffff",
531
- borderRadius: "4px",
532
- minWidth: "32px",
533
- textAlign: "center"
534
- },
535
- pageButton: {
536
- padding: "4px 8px",
537
- border: "1px solid #e5e7eb",
538
- borderRadius: "4px",
539
- minWidth: "32px",
540
- textAlign: "center",
541
- cursor: "pointer",
542
- backgroundColor: "#ffffff",
543
- ":hover": {
544
- backgroundColor: "#f3f4f6"
545
- }
546
- }
547
- }),
548
- []
549
- ), C = g(() => {
550
- const S = Math.ceil(u / e), B = Math.floor(c / 2), N = p * e < u;
551
- return { pagesCount: S, halfWay: B, hasNext: N, hasPrev: p !== 1 };
552
- }, [u, e, p, c]), b = g(() => {
553
- const { pagesCount: S, halfWay: B } = C, N = Array.from({ length: Math.min(c, S) });
554
- return p <= B ? N.map((A, W) => W + 1) : S - p < B ? N.map((A, W) => S - W).reverse() : N.map((A, W) => p - B + W);
555
- }, [p, c, C]), x = g(
333
+ const { listState: c } = C(), { data: L, count: l, pagination: S, setPage: y, loader: v, error: x } = c, { page: t, perPage: f } = S, { initialLoading: w, isLoading: k } = v, b = P(() => {
334
+ const u = Math.ceil(l / f), M = Math.floor(o / 2), z = t * f < l;
335
+ return { pagesCount: u, halfWay: M, hasNext: z, hasPrev: t !== 1 };
336
+ }, [l, f, t, o]), m = P(() => {
337
+ const { pagesCount: u, halfWay: M } = b, z = Array.from({ length: Math.min(o, u) });
338
+ return t <= M ? z.map((I, B) => B + 1) : u - t < M ? z.map((I, B) => u - B).reverse() : z.map((I, B) => t - M + B);
339
+ }, [t, o, b]), d = P(
556
340
  () => ({
557
- prev: () => y(p - 1),
558
- next: () => y(p + 1),
341
+ prev: () => y(t - 1),
342
+ next: () => y(t + 1),
559
343
  first: () => y(1),
560
- last: () => y(C.pagesCount),
561
- setPage: (S) => y(S)
344
+ last: () => y(b.pagesCount),
345
+ setPage: (u) => y(u)
562
346
  }),
563
- [y, p, C.pagesCount]
564
- ), m = g(
347
+ [y, t, b.pagesCount]
348
+ ), g = P(
565
349
  () => ({
566
- page: p,
567
- perPage: e,
568
- count: u,
569
- ...C,
570
- pagesToDisplay: b,
571
- ...x,
572
- styles: v
350
+ page: t,
351
+ perPage: f,
352
+ count: l,
353
+ ...b,
354
+ pagesToDisplay: m,
355
+ ...d
573
356
  }),
574
- [
575
- p,
576
- e,
577
- u,
578
- C,
579
- b,
580
- x,
581
- v
582
- ]
357
+ [t, f, l, b, m, d]
583
358
  );
584
- return L || !h || h.length === 0 || w ? null : i ? i(m) : /* @__PURE__ */ M("div", { style: v.container, children: [
585
- r ? r(m) : /* @__PURE__ */ l(
359
+ return w || !L || L.length === 0 || x ? null : n ? n(g) : /* @__PURE__ */ N("div", { className: "react-list-pagination", children: [
360
+ r ? r(g) : /* @__PURE__ */ i(
586
361
  "button",
587
362
  {
588
363
  type: "button",
589
- disabled: !C.hasPrev,
590
- onClick: x.first,
591
- style: {
592
- ...v.button,
593
- ...!C.hasPrev && v.disabledButton
594
- },
364
+ disabled: !b.hasPrev,
365
+ onClick: d.first,
595
366
  children: "First"
596
367
  }
597
368
  ),
598
- t ? t(m) : /* @__PURE__ */ l(
369
+ e ? e(g) : /* @__PURE__ */ i(
599
370
  "button",
600
371
  {
601
372
  type: "button",
602
- disabled: !C.hasPrev,
603
- onClick: x.prev,
604
- style: {
605
- ...v.button,
606
- ...!C.hasPrev && v.disabledButton
607
- },
373
+ disabled: !b.hasPrev,
374
+ onClick: d.prev,
608
375
  children: "Prev"
609
376
  }
610
377
  ),
611
- o ? o(m) : /* @__PURE__ */ l("div", { style: v.pagesContainer, children: b.map((S) => {
612
- const B = S === p, N = { ...m, page: S, isActive: B };
613
- return n ? n(N) : /* @__PURE__ */ l("div", { children: B ? /* @__PURE__ */ l("span", { style: v.activePageSpan, children: S }) : /* @__PURE__ */ l(
378
+ s ? s(g) : /* @__PURE__ */ i("div", { children: m.map((u) => {
379
+ const M = u === t, z = { ...g, page: u, isActive: M };
380
+ return a ? a(z) : /* @__PURE__ */ i("div", { children: M ? /* @__PURE__ */ i("span", { children: u }) : /* @__PURE__ */ i(
614
381
  "button",
615
382
  {
616
383
  type: "button",
617
- onClick: () => x.setPage(S),
618
- style: v.pageButton,
619
- children: S
384
+ onClick: () => d.setPage(u),
385
+ children: u
620
386
  }
621
- ) }, `page-${S}`);
387
+ ) }, `page-${u}`);
622
388
  }) }),
623
- s ? s(m) : /* @__PURE__ */ l(
389
+ p ? p(g) : /* @__PURE__ */ i(
624
390
  "button",
625
391
  {
626
392
  type: "button",
627
- disabled: !C.hasNext,
628
- onClick: x.next,
629
- style: {
630
- ...v.button,
631
- ...!C.hasNext && v.disabledButton
632
- },
393
+ disabled: !b.hasNext,
394
+ onClick: d.next,
633
395
  children: "Next"
634
396
  }
635
397
  ),
636
- f ? f(m) : /* @__PURE__ */ l(
398
+ h ? h(g) : /* @__PURE__ */ i(
637
399
  "button",
638
400
  {
639
401
  type: "button",
640
- disabled: !C.hasNext,
641
- onClick: x.last,
642
- style: {
643
- ...v.button,
644
- ...!C.hasNext && v.disabledButton
645
- },
402
+ disabled: !b.hasNext,
403
+ onClick: d.last,
646
404
  children: "Last"
647
405
  }
648
406
  )
649
407
  ] });
650
408
  }
651
- ), te = R(
652
- ({ children: i, options: c = [10, 25, 50, 100] }) => {
653
- const { listState: r } = k(), { data: t, pagination: o, setPerPage: n, loader: s, error: f } = r, { perPage: a } = o, { initialLoading: h, isLoading: u } = s, d = g(
654
- () => ({
655
- container: {
656
- display: "inline-block",
657
- minWidth: "150px"
658
- },
659
- select: {
660
- width: "100%",
661
- padding: "8px 12px",
662
- border: "1px solid #e5e7eb",
663
- borderRadius: "4px",
664
- fontSize: "14px",
665
- backgroundColor: "#ffffff",
666
- cursor: "pointer",
667
- outline: "none"
668
- }
669
- }),
670
- []
671
- ), y = g(() => c.map((p) => typeof p != "object" ? {
672
- value: p,
673
- label: p
674
- } : p), [c]), P = T(
675
- (p) => {
676
- n(Number(p.target.value));
409
+ ), Z = R(
410
+ ({ children: n, options: o = [10, 25, 50, 100] }) => {
411
+ const { listState: r } = C(), { data: e, pagination: s, setPerPage: a, loader: p, error: h } = r, { perPage: c } = s, { initialLoading: L } = p, l = P(() => o.map((v) => typeof v != "object" ? {
412
+ value: v,
413
+ label: v
414
+ } : v), [o]), S = O(
415
+ (v) => {
416
+ a(Number(v.target.value));
677
417
  },
678
- [n]
679
- ), w = g(
418
+ [a]
419
+ ), y = P(
680
420
  () => ({
681
- perPage: a,
682
- setPerPage: n,
683
- options: y,
684
- styles: d
421
+ perPage: c,
422
+ setPerPage: a,
423
+ options: l
685
424
  }),
686
- [a, n, y, d]
425
+ [c, a, l]
687
426
  );
688
- return h || !t || t.length === 0 || f ? null : i ? i(w) : /* @__PURE__ */ l("div", { className: "react-list-per-page", style: d.container, children: /* @__PURE__ */ l(
689
- "select",
690
- {
691
- value: a,
692
- onChange: P,
693
- style: d.select,
694
- children: y.map((p) => /* @__PURE__ */ M("option", { value: p.value, children: [
695
- p.label,
696
- " items per page"
697
- ] }, `option-${p.value}`))
698
- }
699
- ) });
427
+ return L || !e || e.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-per-page", children: n ? n(y) : /* @__PURE__ */ i("select", { value: c, onChange: S, children: l.map((v) => /* @__PURE__ */ N("option", { value: v.value, children: [
428
+ v.label,
429
+ " items per page"
430
+ ] }, `option-${v.value}`)) }) });
700
431
  }
701
- ), ne = R(({ children: i }) => {
702
- const { listState: c } = k(), { loader: r, refresh: t } = c, { isLoading: o, initialLoading: n } = r, s = g(
703
- () => ({
704
- container: {
705
- display: "inline-block"
706
- },
707
- button: {
708
- padding: "8px 16px",
709
- border: "1px solid #e5e7eb",
710
- borderRadius: "6px",
711
- backgroundColor: "#ffffff",
712
- cursor: "pointer",
713
- fontSize: "14px",
714
- transition: "all 0.2s ease",
715
- ":hover": {
716
- backgroundColor: "#f3f4f6"
717
- },
718
- ":disabled": {
719
- opacity: 0.6,
720
- cursor: "not-allowed"
721
- }
722
- }
723
- }),
724
- []
725
- ), f = T(() => {
726
- t({ isRefresh: !0 });
727
- }, [t]), a = g(
432
+ ), tt = R(({ children: n }) => {
433
+ const { listState: o } = C(), { loader: r, refresh: e } = o, { isLoading: s, initialLoading: a } = r, p = O(() => {
434
+ e({ isRefresh: !0 });
435
+ }, [e]), h = P(
728
436
  () => ({
729
- isLoading: o,
730
- refresh: f
437
+ isLoading: s,
438
+ refresh: p
731
439
  }),
732
- [o, f, s]
440
+ [s, p]
733
441
  );
734
- return n ? null : i ? i(a) : /* @__PURE__ */ l("div", { className: "react-list-refresh", style: s.container, children: /* @__PURE__ */ l(
735
- "button",
736
- {
737
- onClick: f,
738
- disabled: o,
739
- style: {
740
- ...s.button,
741
- ...o && s.button[":disabled"]
742
- },
743
- children: o ? "Loading..." : "Refresh"
744
- }
745
- ) });
746
- }), re = R(({ children: i, debounceTime: c = 500 }) => {
747
- const { listState: r } = k(), { search: t, setSearch: o } = r, [n, s] = $(), [f, a] = O(t ?? ""), h = q(null);
748
- I(() => {
749
- t !== f && a(t ?? "");
750
- }, [t]);
751
- const u = (P) => {
752
- const w = P.target.value;
753
- a(w), h.current && clearTimeout(h.current), h.current = setTimeout(() => {
754
- s(() => {
755
- o(w);
756
- });
757
- }, c);
442
+ return a ? null : n ? n(h) : /* @__PURE__ */ i("div", { className: "react-list-refresh", children: /* @__PURE__ */ i("button", { onClick: p, disabled: s, children: s ? "Loading..." : "Refresh" }) });
443
+ }), et = R(({ children: n, debounceTime: o = 500 }) => {
444
+ const { listState: r } = C(), { search: e, setSearch: s } = r, [a, p] = T(e ?? ""), h = q(null);
445
+ E(() => {
446
+ e !== a && p(e ?? "");
447
+ }, [e]);
448
+ const c = (l) => {
449
+ p(l), h.current && clearTimeout(h.current), h.current = setTimeout(() => {
450
+ s(l);
451
+ }, o);
758
452
  };
759
- I(() => () => {
453
+ return E(() => () => {
760
454
  h.current && clearTimeout(h.current);
761
- }, []);
762
- const d = {
763
- container: {
764
- margin: "10px 0",
765
- width: "100%",
766
- maxWidth: "300px"
767
- },
768
- input: {
769
- width: "100%",
770
- padding: "8px 12px",
771
- border: "1px solid #ccc",
772
- borderRadius: "4px",
773
- fontSize: "14px",
774
- outline: "none"
455
+ }, []), /* @__PURE__ */ i("div", { className: "react-list-search", children: n ? n({
456
+ search: a,
457
+ setSearch: c
458
+ }) : /* @__PURE__ */ i(
459
+ "input",
460
+ {
461
+ type: "text",
462
+ value: a,
463
+ onChange: (l) => c(l.target.value),
464
+ placeholder: "Search..."
775
465
  }
776
- }, y = {
777
- search: f,
778
- setSearch: u,
779
- isPending: n
780
- };
781
- return i ? i(y) : /* @__PURE__ */ M("div", { className: "react-list-search", style: d.container, children: [
782
- /* @__PURE__ */ l(
783
- "input",
784
- {
785
- type: "text",
786
- value: f,
787
- onChange: u,
788
- placeholder: "Search...",
789
- style: d.input
790
- }
791
- ),
792
- n && /* @__PURE__ */ l(
793
- "div",
794
- {
795
- className: "search-indicator",
796
- style: { fontSize: "12px", color: "#888", marginTop: "4px" },
797
- children: "Searching..."
798
- }
799
- )
800
- ] });
801
- }), oe = R(({ children: i }) => {
802
- const { listState: c } = k(), { data: r, count: t, pagination: o, loader: n, error: s } = c, { page: f, perPage: a } = o, { initialLoading: h, isLoading: u } = n, d = g(
803
- () => ({
804
- container: {
805
- padding: "8px 0",
806
- fontSize: "14px",
807
- color: "#4B5563"
808
- },
809
- text: {
810
- display: "inline-block"
811
- },
812
- highlight: {
813
- fontWeight: "500",
814
- color: "#111827"
815
- }
816
- }),
817
- []
818
- ), y = g(() => {
819
- const w = f * a - a + 1, p = Math.min(f * a, t), e = (r == null ? void 0 : r.length) || 0;
820
- return { from: w, to: p, visibleCount: e };
821
- }, [f, a, t, r]), P = g(
466
+ ) });
467
+ }), nt = R(({ children: n }) => {
468
+ const { listState: o } = C(), { data: r, count: e, pagination: s, loader: a, error: p } = o, { page: h, perPage: c } = s, { initialLoading: L, isLoading: l } = a, S = P(() => {
469
+ const v = h * c - c + 1, x = Math.min(h * c, e), t = (r == null ? void 0 : r.length) || 0;
470
+ return { from: v, to: x, visibleCount: t };
471
+ }, [h, c, e, r]), y = P(
822
472
  () => ({
823
- ...y,
824
- count: t,
825
- styles: d
473
+ ...S,
474
+ count: e
826
475
  }),
827
- [y, t, d]
476
+ [S, e]
828
477
  );
829
- return h || !r || r.length === 0 || s ? null : i ? i(P) : /* @__PURE__ */ l("div", { className: "react-list-summary", style: d.container, children: /* @__PURE__ */ M("span", { style: d.text, children: [
478
+ return L || !r || r.length === 0 || p ? null : /* @__PURE__ */ i("div", { className: "react-list-summary", children: n ? n(y) : /* @__PURE__ */ N("span", { children: [
830
479
  "Showing ",
831
- /* @__PURE__ */ l("span", { style: d.highlight, children: y.visibleCount }),
832
- " ",
833
- "items (",
834
- /* @__PURE__ */ M("span", { style: d.highlight, children: [
835
- y.from,
480
+ /* @__PURE__ */ i("span", { children: S.visibleCount }),
481
+ " items (",
482
+ /* @__PURE__ */ N("span", { children: [
483
+ S.from,
836
484
  " - ",
837
- y.to
485
+ S.to
838
486
  ] }),
839
487
  ") out of ",
840
- /* @__PURE__ */ l("span", { style: d.highlight, children: t })
488
+ /* @__PURE__ */ i("span", { children: e })
841
489
  ] }) });
842
490
  });
843
491
  export {
844
- G as ReactListAttributes,
845
- J as ReactListEmpty,
846
- K as ReactListError,
847
- Q as ReactListGoTo,
848
- U as ReactListInitialLoader,
849
- V as ReactListItems,
850
- Y as ReactListLoadMore,
851
- Z as ReactListLoader,
852
- ee as ReactListPagination,
853
- te as ReactListPerPage,
854
- F as ReactListProvider,
855
- ne as ReactListRefresh,
856
- re as ReactListSearch,
857
- oe as ReactListSummary,
858
- X as default
492
+ W as ReactListAttributes,
493
+ F as ReactListEmpty,
494
+ G as ReactListError,
495
+ J as ReactListGoTo,
496
+ K as ReactListInitialLoader,
497
+ Q as ReactListItems,
498
+ V as ReactListLoadMore,
499
+ X as ReactListLoader,
500
+ Y as ReactListPagination,
501
+ Z as ReactListPerPage,
502
+ H as ReactListProvider,
503
+ tt as ReactListRefresh,
504
+ et as ReactListSearch,
505
+ nt as ReactListSummary,
506
+ U as default
859
507
  };
@@ -1 +1 @@
1
- (function(S,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(S=typeof globalThis<"u"?globalThis:S||self,n(S.ReactList={},S.jsxRuntime,S.react))})(this,function(S,n,e){"use strict";const I=e.createContext(null),W=({children:a,config:d})=>{const{requestHandler:i,stateManager:s={}}=d,[r,o]=e.useState({data:[],response:null,error:null,count:0,selection:[],pagination:{page:1,perPage:25},loader:{isLoading:!1,initialLoading:!0},sort:{sortBy:null,sortOrder:"desc"},search:"",filters:{},attrs:[],isEmpty:!0,isInitializing:!0});if(!i)throw new Error("ListProvider: requestHandler is required.");const l=e.useMemo(()=>({requestHandler:i,stateManager:s,listState:r,setListState:o}),[i,s,r]);return n.jsx(I.Provider,{value:l,children:a})},w=()=>{const a=e.useContext(I);if(!a)throw new Error("useListContext must be used within a ListProvider");return a},A=e.memo(({children:a,renderAttribute:d})=>{const{listState:i}=w(),{attrs:s,attrSettings:r,updateAttr:o}=i,l={container:{display:"flex",flexDirection:"column",gap:"12px",padding:"12px"},label:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"14px"},checkbox:{width:"16px",height:"16px",cursor:"pointer"}},f=e.useCallback(h=>g=>{o(h,"visible",g.target.checked)},[o]),c=e.useMemo(()=>({attrs:s,attrSettings:r,updateAttr:o,styles:l}),[s,r,o]);return a?a(c):n.jsx("div",{className:"react-list-attributes",style:l.container,children:s.map((h,g)=>{var u;return d?d({key:`attr-${g}`,attr:h,updateAttr:o,attrSettings:r,styles:l}):n.jsxs("label",{style:l.label,children:[n.jsx("span",{children:h.label}),n.jsx("input",{type:"checkbox",checked:((u=r==null?void 0:r[h.name])==null?void 0:u.visible)??!1,onChange:f(h.name),style:l.checkbox})]},`attr-${g}`)})})}),O=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,loader:s,error:r}=d,{isLoading:o,initialLoading:l}=s,f=e.useMemo(()=>({container:{width:"100%",padding:"32px 16px"},defaultMessage:{textAlign:"center",color:"#6B7280",fontSize:"16px",fontWeight:"400"}}),[]);return(i==null?void 0:i.length)>0||l||o||r?null:n.jsx("div",{className:"react-list-empty",style:f.container,children:a||n.jsx("div",{style:f.defaultMessage,children:n.jsx("p",{children:"No data found!"})})})}),j=e.memo(({children:a})=>{const{listState:d}=w(),{error:i,loader:s}=d,{isLoading:r}=s,o=e.useMemo(()=>({container:{width:"100%",padding:"32px 16px"},errorContent:{textAlign:"center",color:"#DC2626",padding:"32px 0"},heading:{fontSize:"16px",fontWeight:"500",marginBottom:"8px"},message:{fontSize:"14px",fontFamily:"monospace",marginTop:"8px",whiteSpace:"pre-wrap",wordBreak:"break-word"}}),[]);return!i||r?null:a?a({error:i}):n.jsx("div",{className:"react-list-error",style:o.container,children:n.jsxs("div",{style:o.errorContent,children:[n.jsx("h3",{style:o.heading,children:"Error occurred"}),n.jsxs("pre",{style:o.message,children:[i.name,": ",i.message]})]})})}),q=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,setPage:o,loader:l,error:f}=d,{page:c,perPage:h}=r,{initialLoading:g,isLoading:u}=l,y=e.useMemo(()=>({container:{display:"inline-block",minWidth:"120px"},select:{width:"100%",padding:"8px 12px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"14px",backgroundColor:"#fff",cursor:"pointer",outline:"none"}}),[]),{pages:P,pagesCount:k}=e.useMemo(()=>{const v=Math.ceil(s/h);return{pages:Array.from({length:v},(C,M)=>M+1),pagesCount:v}},[s,h]),p=e.useCallback(v=>{o(Number(v.target.value))},[o]),t=e.useMemo(()=>({setPage:o,page:c,pages:P,pagesCount:k,styles:y}),[o,c,P,k,y]);return g||!i||i.length===0||f?null:a?a(t):n.jsx("div",{className:"react-list-go-to",style:y.container,children:n.jsx("select",{value:c,onChange:p,style:y.select,children:P.map(v=>n.jsxs("option",{value:v,children:["Page ",v]},`page-${v}`))})})}),D=e.memo(({children:a})=>{const{listState:d}=w(),{loader:i}=d,{initialLoading:s}=i,r=e.useMemo(()=>({container:{padding:"20px",textAlign:"center"},defaultLoader:{fontSize:"16px",color:"#4B5563",margin:0,animation:"pulse 1.5s infinite ease-in-out"},"@keyframes pulse":{"0%":{opacity:.6},"50%":{opacity:1},"100%":{opacity:.6}}}),[]),o=e.useMemo(()=>({loading:s,styles:r}),[s]);return s?n.jsx("div",{className:"react-list-initial-loader",style:r.container,children:a?a(o):n.jsx("p",{style:r.defaultLoader,children:"Initial Loading..."})}):null}),_=e.memo(({children:a,renderItem:d})=>{const{listState:i}=w(),{data:s=[],loader:r,error:o}=i,{initialLoading:l,isLoading:f}=r,c=e.useMemo(()=>({container:{display:"flex",flexDirection:"column",gap:"12px",width:"100%"},itemWrapper:{width:"100%"},defaultItem:{padding:"12px",backgroundColor:"#f9fafb",borderRadius:"4px",fontFamily:"monospace",fontSize:"14px",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"}}),[]),h=e.useMemo(()=>({items:s,styles:c}),[s,c]);return l||!s||s.length===0||o?null:d?n.jsx("div",{className:"react-list-items",style:c.container,children:s.map((g,u)=>n.jsx("div",{style:c.itemWrapper,children:d({item:g,index:u,styles:c})},g.id||u))}):typeof a=="function"?n.jsx("div",{className:"react-list-items",style:c.container,children:a(h)}):n.jsx("div",{className:"react-list-items",style:c.container,children:s.map((g,u)=>n.jsx("pre",{style:c.defaultItem,children:JSON.stringify(g,null,2)},g.id||u))})}),$=({children:a,endpoint:d,page:i=1,perPage:s=25,sortBy:r,sortOrder:o="desc",search:l="",filters:f={},attrs:c,version:h=1,hasPaginationHistory:g=!0,paginationMode:u="pagination",meta:y={}})=>{const{requestHandler:P,setListState:k}=w(),p=u==="loadMore",[t,v]=e.useState({page:i,perPage:s,sortBy:r,sortOrder:o,search:l,filters:f,attrSettings:{},items:[],selection:[],error:null,response:null,count:0,isLoading:!1,initializingState:!0}),z=e.useCallback(async(x={},m=null)=>{t.initializingState||v(b=>({...b,error:null,isLoading:!0}));try{const b=m||t,L=await P({endpoint:d,version:h,meta:y,page:b.page,perPage:b.perPage,search:b.search,sortBy:b.sortBy,sortOrder:b.sortOrder,filters:b.filters,...x});v(B=>({...B,response:L,selection:[],items:p?[...B.items,...L.items]:L.items,count:L.count,initializingState:!1,isLoading:!1}))}catch(b){throw v(L=>({...L,error:b,items:[],count:0,initializingState:!1,isLoading:!1})),b}},[d,h,p,y,P,t]),C=e.useMemo(()=>({setPage:(x,m)=>{let b=x;x===0&&(b="");const L={...t,page:b};v(L),b&&z(m,L)},setPerPage:x=>{const m={...t,perPage:x,page:1};v(m),z({},m)},setSearch:x=>{if(x!==t.search){const m={...t,search:x,page:1};v(m),z({},m)}},setSort:({by:x,order:m})=>{const b={...t,sortBy:x,sortOrder:m,page:1};v(b),z({},b)},loadMore:()=>{const x={...t,page:t.page+1};v(x),z({},x)},refresh:(x={isRefresh:!0})=>{if(p){const m={...t,page:1,items:[]};v(m),z(x,m)}else z(x)},setFilters:x=>{const m={...t,filters:x,page:1};v(m),z({},m)},setSelection:x=>v(m=>({...m,selection:x}))}),[z,p,t]),M=e.useMemo(()=>({data:t.items,response:t.response,error:t.error,count:t.count,selection:t.selection,pagination:{page:t.page,perPage:t.perPage,hasMore:t.items.length<t.count},loader:{isLoading:t.isLoading,initialLoading:t.initializingState},sort:{sortBy:t.sortBy,sortOrder:t.sortOrder},search:t.search,filters:t.filters,attrs:c||Object.keys(t.items[0]||{}),isEmpty:t.items.length===0,...C}),[t.items,t.response,t.error,t.count,t.selection,t.page,t.perPage,t.isLoading,t.initializingState,t.sortBy,t.sortOrder,t.search,t.filters,C,c]);return e.useEffect(()=>{t.initializingState&&C.setPage(t.page)},[]),e.useEffect(()=>{k(M)},[k,t.items,t.count,t.error,t.isLoading,t.selection,t.page,t.perPage]),a({...M})},H=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,setPage:o,loader:l,error:f}=d,{page:c,perPage:h}=r,{isLoading:g}=l,u=e.useMemo(()=>c*h<s,[c,h,s]),y=e.useCallback(()=>{u&&!g&&o(c+1)},[u,g,o,c]),P=e.useMemo(()=>({button:{padding:"8px 16px",backgroundColor:"#4B5563",color:"#ffffff",border:"none",borderRadius:"4px",cursor:"pointer",opacity:g||!u?.5:1,pointerEvents:g||!u?"none":"auto"}}),[g,u]),k=e.useMemo(()=>({isLoading:g,loadMore:y,hasMoreItems:u,styles:P}),[g,y,u,P]);return!i||i.length===0||f?null:a(k)}),F=e.memo(({children:a,position:d="overlay"})=>{const{listState:i}=w(),{loader:s}=i,{isLoading:r,initializingState:o}=s,l=e.useMemo(()=>({overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.5)",zIndex:10},before:{marginBottom:"16px"},after:{marginTop:"16px"},defaultLoader:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%"},loadingText:{color:"#4B5563",fontSize:"14px"}}),[]),f=e.useMemo(()=>({overlay:l.overlay,before:l.before,after:l.after}),[l]),c=e.useMemo(()=>({isLoading:r,styles:l}),[r,l]);return!o&&!r?null:n.jsx("div",{style:f[d]||{},children:a?a(c):n.jsx("div",{style:l.defaultLoader,children:n.jsx("p",{style:l.loadingText,children:"Loading..."})})})}),G=e.memo(({children:a,pageLinks:d=5,renderFirst:i,renderPrev:s,renderPages:r,renderPage:o,renderNext:l,renderLast:f})=>{const{listState:c}=w(),{data:h,count:g,pagination:u,setPage:y,loader:P,error:k}=c,{page:p,perPage:t}=u,{initialLoading:v,isLoading:z}=P,C=e.useMemo(()=>({container:{display:"flex",alignItems:"center",gap:"8px"},button:{padding:"4px 8px",border:"1px solid #e5e7eb",borderRadius:"4px",cursor:"pointer",backgroundColor:"#ffffff",minWidth:"60px",fontSize:"14px"},disabledButton:{opacity:.5,cursor:"not-allowed"},pagesContainer:{display:"flex",alignItems:"center",gap:"4px"},activePageSpan:{padding:"4px 8px",backgroundColor:"#2563eb",color:"#ffffff",borderRadius:"4px",minWidth:"32px",textAlign:"center"},pageButton:{padding:"4px 8px",border:"1px solid #e5e7eb",borderRadius:"4px",minWidth:"32px",textAlign:"center",cursor:"pointer",backgroundColor:"#ffffff",":hover":{backgroundColor:"#f3f4f6"}}}),[]),M=e.useMemo(()=>{const L=Math.ceil(g/t),B=Math.floor(d/2),T=p*t<g;return{pagesCount:L,halfWay:B,hasNext:T,hasPrev:p!==1}},[g,t,p,d]),x=e.useMemo(()=>{const{pagesCount:L,halfWay:B}=M,T=Array.from({length:Math.min(d,L)});return p<=B?T.map((E,N)=>N+1):L-p<B?T.map((E,N)=>L-N).reverse():T.map((E,N)=>p-B+N)},[p,d,M]),m=e.useMemo(()=>({prev:()=>y(p-1),next:()=>y(p+1),first:()=>y(1),last:()=>y(M.pagesCount),setPage:L=>y(L)}),[y,p,M.pagesCount]),b=e.useMemo(()=>({page:p,perPage:t,count:g,...M,pagesToDisplay:x,...m,styles:C}),[p,t,g,M,x,m,C]);return v||!h||h.length===0||k?null:a?a(b):n.jsxs("div",{style:C.container,children:[i?i(b):n.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:m.first,style:{...C.button,...!M.hasPrev&&C.disabledButton},children:"First"}),s?s(b):n.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:m.prev,style:{...C.button,...!M.hasPrev&&C.disabledButton},children:"Prev"}),r?r(b):n.jsx("div",{style:C.pagesContainer,children:x.map(L=>{const B=L===p,T={...b,page:L,isActive:B};return o?o(T):n.jsx("div",{children:B?n.jsx("span",{style:C.activePageSpan,children:L}):n.jsx("button",{type:"button",onClick:()=>m.setPage(L),style:C.pageButton,children:L})},`page-${L}`)})}),l?l(b):n.jsx("button",{type:"button",disabled:!M.hasNext,onClick:m.next,style:{...C.button,...!M.hasNext&&C.disabledButton},children:"Next"}),f?f(b):n.jsx("button",{type:"button",disabled:!M.hasNext,onClick:m.last,style:{...C.button,...!M.hasNext&&C.disabledButton},children:"Last"})]})}),R=e.memo(({children:a,options:d=[10,25,50,100]})=>{const{listState:i}=w(),{data:s,pagination:r,setPerPage:o,loader:l,error:f}=i,{perPage:c}=r,{initialLoading:h,isLoading:g}=l,u=e.useMemo(()=>({container:{display:"inline-block",minWidth:"150px"},select:{width:"100%",padding:"8px 12px",border:"1px solid #e5e7eb",borderRadius:"4px",fontSize:"14px",backgroundColor:"#ffffff",cursor:"pointer",outline:"none"}}),[]),y=e.useMemo(()=>d.map(p=>typeof p!="object"?{value:p,label:p}:p),[d]),P=e.useCallback(p=>{o(Number(p.target.value))},[o]),k=e.useMemo(()=>({perPage:c,setPerPage:o,options:y,styles:u}),[c,o,y,u]);return h||!s||s.length===0||f?null:a?a(k):n.jsx("div",{className:"react-list-per-page",style:u.container,children:n.jsx("select",{value:c,onChange:P,style:u.select,children:y.map(p=>n.jsxs("option",{value:p.value,children:[p.label," items per page"]},`option-${p.value}`))})})}),J=e.memo(({children:a})=>{const{listState:d}=w(),{loader:i,refresh:s}=d,{isLoading:r,initialLoading:o}=i,l=e.useMemo(()=>({container:{display:"inline-block"},button:{padding:"8px 16px",border:"1px solid #e5e7eb",borderRadius:"6px",backgroundColor:"#ffffff",cursor:"pointer",fontSize:"14px",transition:"all 0.2s ease",":hover":{backgroundColor:"#f3f4f6"},":disabled":{opacity:.6,cursor:"not-allowed"}}}),[]),f=e.useCallback(()=>{s({isRefresh:!0})},[s]),c=e.useMemo(()=>({isLoading:r,refresh:f}),[r,f,l]);return o?null:a?a(c):n.jsx("div",{className:"react-list-refresh",style:l.container,children:n.jsx("button",{onClick:f,disabled:r,style:{...l.button,...r&&l.button[":disabled"]},children:r?"Loading...":"Refresh"})})}),K=e.memo(({children:a,debounceTime:d=500})=>{const{listState:i}=w(),{search:s,setSearch:r}=i,[o,l]=e.useTransition(),[f,c]=e.useState(s??""),h=e.useRef(null);e.useEffect(()=>{s!==f&&c(s??"")},[s]);const g=P=>{const k=P.target.value;c(k),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{l(()=>{r(k)})},d)};e.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const u={container:{margin:"10px 0",width:"100%",maxWidth:"300px"},input:{width:"100%",padding:"8px 12px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"14px",outline:"none"}},y={search:f,setSearch:g,isPending:o};return a?a(y):n.jsxs("div",{className:"react-list-search",style:u.container,children:[n.jsx("input",{type:"text",value:f,onChange:g,placeholder:"Search...",style:u.input}),o&&n.jsx("div",{className:"search-indicator",style:{fontSize:"12px",color:"#888",marginTop:"4px"},children:"Searching..."})]})}),Q=e.memo(({children:a})=>{const{listState:d}=w(),{data:i,count:s,pagination:r,loader:o,error:l}=d,{page:f,perPage:c}=r,{initialLoading:h,isLoading:g}=o,u=e.useMemo(()=>({container:{padding:"8px 0",fontSize:"14px",color:"#4B5563"},text:{display:"inline-block"},highlight:{fontWeight:"500",color:"#111827"}}),[]),y=e.useMemo(()=>{const k=f*c-c+1,p=Math.min(f*c,s),t=(i==null?void 0:i.length)||0;return{from:k,to:p,visibleCount:t}},[f,c,s,i]),P=e.useMemo(()=>({...y,count:s,styles:u}),[y,s,u]);return h||!i||i.length===0||l?null:a?a(P):n.jsx("div",{className:"react-list-summary",style:u.container,children:n.jsxs("span",{style:u.text,children:["Showing ",n.jsx("span",{style:u.highlight,children:y.visibleCount})," ","items (",n.jsxs("span",{style:u.highlight,children:[y.from," - ",y.to]}),") out of ",n.jsx("span",{style:u.highlight,children:s})]})})});S.ReactListAttributes=A,S.ReactListEmpty=O,S.ReactListError=j,S.ReactListGoTo=q,S.ReactListInitialLoader=D,S.ReactListItems=_,S.ReactListLoadMore=H,S.ReactListLoader=F,S.ReactListPagination=G,S.ReactListPerPage=R,S.ReactListProvider=W,S.ReactListRefresh=J,S.ReactListSearch=K,S.ReactListSummary=Q,S.default=$,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(y,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],s):(y=typeof globalThis<"u"?globalThis:y||self,s(y.ReactList={},y.jsxRuntime,y.react))})(this,function(y,s,n){"use strict";const B=n.createContext(null),I=({children:a,config:l})=>{const{requestHandler:o,stateManager:t={}}=l,[r,i]=n.useState({data:[],response:null,error:null,count:0,selection:[],pagination:{page:1,perPage:25},loader:{isLoading:!1,initialLoading:!0},sort:{sortBy:null,sortOrder:"desc"},search:"",filters:{},attrs:[],isEmpty:!0,isInitializing:!0});if(!o)throw new Error("ListProvider: requestHandler is required.");const f=n.useMemo(()=>({requestHandler:o,stateManager:t,listState:r,setListState:i}),[o,t,r]);return s.jsx(B.Provider,{value:f,children:a})},C=()=>{const a=n.useContext(B);if(!a)throw new Error("useListContext must be used within a ListProvider");return a},j=n.memo(({children:a,renderAttribute:l})=>{const{listState:o}=C(),{attrs:t,attrSettings:r,updateAttr:i}=o,f=n.useCallback(c=>S=>{i(c,"visible",S.target.checked)},[i]),p=n.useMemo(()=>({attrs:t,attrSettings:r,updateAttr:i}),[t,r,i]);return a?a(p):s.jsx("div",{className:"react-list-attributes",children:t.map((c,S)=>{var u;return l?l({key:`attr-${S}`,attr:c,updateAttr:i,attrSettings:r}):s.jsxs("label",{children:[s.jsx("span",{children:c.label}),s.jsx("input",{type:"checkbox",checked:((u=r==null?void 0:r[c.name])==null?void 0:u.visible)??!1,onChange:f(c.name)})]},`attr-${S}`)})})}),q=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,loader:t,error:r}=l,{isLoading:i,initialLoading:f}=t;return(o==null?void 0:o.length)>0||f||i||r?null:s.jsx("div",{className:"react-list-empty",children:a||s.jsx("div",{children:s.jsx("p",{children:"No data found!"})})})}),A=n.memo(({children:a})=>{const{listState:l}=C(),{error:o,loader:t}=l,{isLoading:r}=t;return!o||r?null:s.jsx("div",{className:"react-list-error",children:typeof a=="function"?a({error:o}):a||s.jsxs("div",{children:[s.jsx("h3",{children:"Error occurred"}),s.jsxs("pre",{children:[o.name,": ",o.message]})]})})}),_=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:c,perPage:S}=r,{initialLoading:u,isLoading:v}=f,{pages:b,pagesCount:P}=n.useMemo(()=>{const m=Math.ceil(t/S);return{pages:Array.from({length:m},(O,M)=>M+1),pagesCount:m}},[t,S]),E=n.useCallback(m=>{i(Number(m.target.value))},[i]),e=n.useMemo(()=>({setPage:i,page:c,pages:b,pagesCount:P}),[i,c,b,P]);return u||!o||o.length===0||p?null:s.jsx("div",{className:"react-list-go-to",children:a?a(e):s.jsx("select",{value:c,onChange:E,children:b.map(m=>s.jsxs("option",{value:m,children:["Page ",m]},`page-${m}`))})})}),$=n.memo(({children:a})=>{const{listState:l}=C(),{loader:o}=l,{initialLoading:t}=o;return n.useMemo(()=>({loading:t}),[t]),t?s.jsx("div",{className:"react-list-initial-loader",children:a||s.jsx("p",{children:"Initial Loading..."})}):null}),D=n.memo(({children:a,renderItem:l})=>{const{listState:o}=C(),{data:t=[],loader:r,error:i,setSort:f,sort:p}=o,{initialLoading:c}=r,S=n.useMemo(()=>({items:t,setSort:f,sort:p}),[t,p,f]);return c||!t||t.length===0||i?null:l?s.jsx("div",{className:"react-list-items",children:t.map((u,v)=>s.jsx("div",{children:l({item:u,index:v})},u.id||v))}):typeof a=="function"?s.jsx("div",{className:"react-list-items",children:a(S)}):s.jsx("div",{className:"react-list-items",children:t.map((u,v)=>s.jsx("pre",{children:JSON.stringify(u,null,2)},u.id||v))})}),H=({children:a,endpoint:l,page:o=1,perPage:t=25,sortBy:r,sortOrder:i="desc",search:f="",filters:p={},attrs:c,version:S=1,paginationMode:u="pagination",meta:v={}})=>{const{requestHandler:b,setListState:P}=C(),E=u==="loadMore",[e,m]=n.useState({page:o,perPage:t,sortBy:r,sortOrder:i,search:f,filters:p,attrSettings:{},items:[],selection:[],error:null,response:null,count:0,isLoading:!1,initializingState:!0}),w=n.useCallback(async(L={},g=null)=>{e.initializingState||m(h=>({...h,error:null,isLoading:!0}));try{const h=g||e,d=await b({endpoint:l,version:S,meta:v,page:h.page,perPage:h.perPage,search:h.search,sortBy:h.sortBy,sortOrder:h.sortOrder,filters:h.filters,...L});m(k=>({...k,response:d,selection:[],items:E&&h.page>1?[...k.items,...d.items]:d.items,count:d.count,initializingState:!1,isLoading:!1}))}catch(h){throw m(d=>({...d,error:h,items:[],count:0,initializingState:!1,isLoading:!1})),h}},[l,S,E,v,b,e]),O=n.useMemo(()=>({setPage:(L,g)=>{let h=L;L===0&&(h="");const d={...e,page:h};m(d),h&&w(g,d)},setPerPage:L=>{const g={...e,perPage:L,page:1};m(g),w({},g)},setSearch:L=>{if(L!==e.search){const g={...e,search:L,page:1};m(g),w({},g)}},setSort:({by:L,order:g})=>{const h={...e,sortBy:L,sortOrder:g,page:1};m(h),w({},h)},loadMore:()=>{const L={...e,page:e.page+1};m(L),w({},L)},refresh:(L={isRefresh:!0})=>{if(E){const g={...e,page:1,items:[]};m(g),w(L,g)}else w(L)},setFilters:L=>{const g={...e,filters:L,page:1};m(g),w({},g)},updateItemById:(L,g)=>{const h=e.items.map(d=>d.id===g?{...d,...L}:d);m(d=>({...d,items:h}))},setSelection:L=>m(g=>({...g,selection:L}))}),[w,E,e]),M=n.useMemo(()=>({data:e.items,response:e.response,error:e.error,count:e.count,selection:e.selection,pagination:{page:e.page,perPage:e.perPage,hasMore:e.items.length<e.count},loader:{isLoading:e.isLoading,initialLoading:e.initializingState},sort:{sortBy:e.sortBy,sortOrder:e.sortOrder},search:e.search,filters:e.filters,attrs:c||Object.keys(e.items[0]||{}),isEmpty:e.items.length===0,...O}),[e.items,e.response,e.error,e.count,e.selection,e.page,e.perPage,e.isLoading,e.initializingState,e.sortBy,e.sortOrder,e.search,e.filters,O,c]);return n.useEffect(()=>{e.initializingState&&O.setPage(e.page)},[]),n.useEffect(()=>{P(M)},[P,e.items,e.count,e.error,e.isLoading,e.selection,e.page,e.perPage,e.sortBy,e.sortOrder]),typeof a=="function"?a(M):a},x=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:c,perPage:S}=r,{isLoading:u}=f,v=n.useMemo(()=>c*S<t,[c,S,t]),b=n.useCallback(()=>{v&&!u&&i(c+1)},[v,u,i,c]),P=n.useMemo(()=>({isLoading:u,loadMore:b,hasMoreItems:v}),[u,b,v]);return!o||o.length===0||p?null:a(P)}),G=n.memo(({children:a,position:l="overlay"})=>{const{listState:o}=C(),{loader:t}=o,{isLoading:r,initializingState:i}=t;return n.useMemo(()=>({isLoading:r}),[r]),!i&&!r?null:s.jsx("div",{children:a||s.jsx("div",{children:s.jsx("p",{children:"Loading..."})})})}),W=n.memo(({children:a,pageLinks:l=5,renderFirst:o,renderPrev:t,renderPages:r,renderPage:i,renderNext:f,renderLast:p})=>{const{listState:c}=C(),{data:S,count:u,pagination:v,setPage:b,loader:P,error:E}=c,{page:e,perPage:m}=v,{initialLoading:w,isLoading:O}=P,M=n.useMemo(()=>{const d=Math.ceil(u/m),k=Math.floor(l/2),N=e*m<u;return{pagesCount:d,halfWay:k,hasNext:N,hasPrev:e!==1}},[u,m,e,l]),L=n.useMemo(()=>{const{pagesCount:d,halfWay:k}=M,N=Array.from({length:Math.min(l,d)});return e<=k?N.map((T,z)=>z+1):d-e<k?N.map((T,z)=>d-z).reverse():N.map((T,z)=>e-k+z)},[e,l,M]),g=n.useMemo(()=>({prev:()=>b(e-1),next:()=>b(e+1),first:()=>b(1),last:()=>b(M.pagesCount),setPage:d=>b(d)}),[b,e,M.pagesCount]),h=n.useMemo(()=>({page:e,perPage:m,count:u,...M,pagesToDisplay:L,...g}),[e,m,u,M,L,g]);return w||!S||S.length===0||E?null:a?a(h):s.jsxs("div",{className:"react-list-pagination",children:[o?o(h):s.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:g.first,children:"First"}),t?t(h):s.jsx("button",{type:"button",disabled:!M.hasPrev,onClick:g.prev,children:"Prev"}),r?r(h):s.jsx("div",{children:L.map(d=>{const k=d===e,N={...h,page:d,isActive:k};return i?i(N):s.jsx("div",{children:k?s.jsx("span",{children:d}):s.jsx("button",{type:"button",onClick:()=>g.setPage(d),children:d})},`page-${d}`)})}),f?f(h):s.jsx("button",{type:"button",disabled:!M.hasNext,onClick:g.next,children:"Next"}),p?p(h):s.jsx("button",{type:"button",disabled:!M.hasNext,onClick:g.last,children:"Last"})]})}),F=n.memo(({children:a,options:l=[10,25,50,100]})=>{const{listState:o}=C(),{data:t,pagination:r,setPerPage:i,loader:f,error:p}=o,{perPage:c}=r,{initialLoading:S}=f,u=n.useMemo(()=>l.map(P=>typeof P!="object"?{value:P,label:P}:P),[l]),v=n.useCallback(P=>{i(Number(P.target.value))},[i]),b=n.useMemo(()=>({perPage:c,setPerPage:i,options:u}),[c,i,u]);return S||!t||t.length===0||p?null:s.jsx("div",{className:"react-list-per-page",children:a?a(b):s.jsx("select",{value:c,onChange:v,children:u.map(P=>s.jsxs("option",{value:P.value,children:[P.label," items per page"]},`option-${P.value}`))})})}),J=n.memo(({children:a})=>{const{listState:l}=C(),{loader:o,refresh:t}=l,{isLoading:r,initialLoading:i}=o,f=n.useCallback(()=>{t({isRefresh:!0})},[t]),p=n.useMemo(()=>({isLoading:r,refresh:f}),[r,f]);return i?null:a?a(p):s.jsx("div",{className:"react-list-refresh",children:s.jsx("button",{onClick:f,disabled:r,children:r?"Loading...":"Refresh"})})}),K=n.memo(({children:a,debounceTime:l=500})=>{const{listState:o}=C(),{search:t,setSearch:r}=o,[i,f]=n.useState(t??""),p=n.useRef(null);n.useEffect(()=>{t!==i&&f(t??"")},[t]);const c=u=>{f(u),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{r(u)},l)};n.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const S={search:i,setSearch:c};return s.jsx("div",{className:"react-list-search",children:a?a(S):s.jsx("input",{type:"text",value:i,onChange:u=>c(u.target.value),placeholder:"Search..."})})}),Q=n.memo(({children:a})=>{const{listState:l}=C(),{data:o,count:t,pagination:r,loader:i,error:f}=l,{page:p,perPage:c}=r,{initialLoading:S,isLoading:u}=i,v=n.useMemo(()=>{const P=p*c-c+1,E=Math.min(p*c,t),e=(o==null?void 0:o.length)||0;return{from:P,to:E,visibleCount:e}},[p,c,t,o]),b=n.useMemo(()=>({...v,count:t}),[v,t]);return S||!o||o.length===0||f?null:s.jsx("div",{className:"react-list-summary",children:a?a(b):s.jsxs("span",{children:["Showing ",s.jsx("span",{children:v.visibleCount})," items (",s.jsxs("span",{children:[v.from," - ",v.to]}),") out of ",s.jsx("span",{children:t})]})})});y.ReactListAttributes=j,y.ReactListEmpty=q,y.ReactListError=A,y.ReactListGoTo=_,y.ReactListInitialLoader=$,y.ReactListItems=D,y.ReactListLoadMore=x,y.ReactListLoader=G,y.ReactListPagination=W,y.ReactListPerPage=F,y.ReactListProvider=I,y.ReactListRefresh=J,y.ReactListSearch=K,y.ReactListSummary=Q,y.default=H,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@7span/react-list",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A simple and reusable list component for React",
5
5
  "type": "module",
6
- "exports": {
7
- ".": "./src/index.jsx"
8
- },
9
6
  "scripts": {
10
7
  "dev": "vite",
11
8
  "build": "vite build",