@7span/react-list 0.0.1 → 0.0.4

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 z } from "react/jsx-runtime";
2
+ import { createContext as $, useContext as j, useState as T, useMemo as P, memo as w, useCallback as k, useEffect as E, useRef as q } from "react";
3
+ const A = $(null), H = ({ children: r, config: o }) => {
4
+ const { requestHandler: n, stateManager: e = {} } = o, [s, a] = T({
5
5
  data: [],
6
6
  response: null,
7
7
  error: null,
@@ -25,835 +25,484 @@ const E = D(null), F = ({ children: i, config: c }) => {
25
25
  isEmpty: !0,
26
26
  isInitializing: !0
27
27
  });
28
- if (!r)
28
+ if (!n)
29
29
  throw new Error("ListProvider: requestHandler is required.");
30
- const s = g(
30
+ const p = P(
31
31
  () => ({
32
- requestHandler: r,
33
- stateManager: t,
34
- listState: o,
35
- setListState: n
32
+ requestHandler: n,
33
+ stateManager: e,
34
+ listState: s,
35
+ setListState: a
36
36
  }),
37
- [r, t, o]
37
+ [n, 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: r });
40
+ }, R = () => {
41
+ const r = j(A);
42
+ if (!r)
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"
52
- },
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);
44
+ return r;
45
+ }, W = w(({ children: r, renderAttribute: o }) => {
46
+ const { listState: n } = R(), { attrs: e, attrSettings: s, updateAttr: a } = n, p = k(
47
+ (u) => (m) => {
48
+ a(u, "visible", m.target.checked);
68
49
  },
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 r ? r(h) : /* @__PURE__ */ i("div", { className: "react-list-attributes", children: e.map((u, m) => {
60
+ var l;
61
+ return o ? o({
62
+ key: `attr-${m}`,
63
+ attr: u,
64
+ updateAttr: a,
65
+ attrSettings: s
66
+ }) : /* @__PURE__ */ z("label", { children: [
67
+ /* @__PURE__ */ i("span", { children: u.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[u.name]) == null ? void 0 : l.visible) ?? !1,
73
+ onChange: p(u.name)
96
74
  }
97
75
  )
98
- ] }, `attr-${u}`);
76
+ ] }, `attr-${m}`);
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: [
147
- r.name,
78
+ }), F = w(({ children: r }) => {
79
+ const { listState: o } = R(), { 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 = w(({ children: r }) => {
82
+ const { listState: o } = R(), { 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,
148
87
  ": ",
149
- r.message
88
+ n.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 = w(({ children: r }) => {
92
+ const { listState: o } = R(), { data: n, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: u, perPage: m } = s, { initialLoading: l, isLoading: L } = p, { pages: y, pagesCount: S } = P(() => {
93
+ const t = Math.ceil(e / m);
94
+ return { pages: Array.from({ length: t }, (M, b) => b + 1), pagesCount: t };
95
+ }, [e, m]), N = k(
96
+ (t) => {
97
+ a(Number(t.target.value));
177
98
  },
178
- [n]
179
- ), e = g(
99
+ [a]
100
+ ), v = P(
180
101
  () => ({
181
- setPage: n,
182
- page: a,
183
- pages: P,
184
- pagesCount: w,
185
- styles: y
102
+ setPage: a,
103
+ page: u,
104
+ pages: y,
105
+ pagesCount: S
186
106
  }),
187
- [n, a, P, w, y]
107
+ [a, u, y, S]
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 || !n || n.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-go-to", children: r ? r(v) : /* @__PURE__ */ i("select", { value: u, onChange: N, children: y.map((t) => /* @__PURE__ */ z("option", { value: t, 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
+ t
112
+ ] }, `page-${t}`)) }) });
113
+ }), K = w(({ children: r }) => {
114
+ const { listState: o } = R(), { loader: n } = o, { initialLoading: e } = n;
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: r || /* @__PURE__ */ i("p", { children: "Initial Loading..." }) }) : null;
121
+ }), Q = w(({ children: r, renderItem: o }) => {
122
+ const { listState: n } = R(), { data: e = [], loader: s, error: a, setSort: p, sort: h } = n, { initialLoading: u } = s, m = 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,
256
- 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",
130
+ return u || !e || e.length === 0 || a ? null : o ? /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, L) => /* @__PURE__ */ i("div", { children: o({ item: l, index: L }) }, l.id || L)) }) : typeof r == "function" ? /* @__PURE__ */ i("div", { className: "react-list-items", children: r(m) }) : /* @__PURE__ */ i("div", { className: "react-list-items", children: e.map((l, L) => /* @__PURE__ */ i("pre", { children: JSON.stringify(l, null, 2) }, l.id || L)) });
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
+ search: h = "",
140
+ filters: u = {},
141
+ attrs: m,
142
+ version: l = 1,
143
+ paginationMode: L = "pagination",
266
144
  meta: y = {}
267
145
  }) => {
268
- const { requestHandler: P, setListState: w } = k(), p = d === "loadMore", [e, L] = O({
269
- page: r,
270
- perPage: t,
271
- sortBy: o,
272
- sortOrder: n,
273
- search: s,
274
- filters: f,
146
+ const { requestHandler: S, setListState: N } = R(), v = L === "loadMore", [t, C] = T({
147
+ page: e,
148
+ perPage: s,
149
+ sortBy: a,
150
+ sortOrder: p,
151
+ search: h,
152
+ filters: u,
275
153
  attrSettings: {},
276
- items: [],
154
+ items: r,
277
155
  selection: [],
278
156
  error: null,
279
157
  response: null,
280
158
  count: 0,
281
159
  isLoading: !1,
282
160
  initializingState: !0
283
- }), z = T(
284
- async (b = {}, x = null) => {
285
- e.initializingState || L((m) => ({ ...m, error: null, isLoading: !0 }));
161
+ }), M = k(
162
+ async (d = {}, g = null) => {
163
+ t.initializingState || C((c) => ({ ...c, error: null, isLoading: !0 }));
286
164
  try {
287
- const m = x || e, S = await P({
288
- endpoint: c,
289
- version: h,
165
+ const c = g || t, f = await S({
166
+ endpoint: n,
167
+ version: l,
290
168
  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
169
+ page: c.page,
170
+ perPage: c.perPage,
171
+ search: c.search,
172
+ sortBy: c.sortBy,
173
+ sortOrder: c.sortOrder,
174
+ filters: c.filters,
175
+ ...d
298
176
  });
299
- L((B) => ({
300
- ...B,
301
- response: S,
177
+ C((x) => ({
178
+ ...x,
179
+ response: f,
302
180
  selection: [],
303
181
  // Append items for loadMore, replace for pagination
304
- items: p ? [...B.items, ...S.items] : S.items,
305
- count: S.count,
182
+ items: v && c.page > 1 ? [...x.items, ...f.items] : f.items,
183
+ count: f.count,
306
184
  initializingState: !1,
307
185
  isLoading: !1
308
186
  }));
309
- } catch (m) {
310
- throw L((S) => ({
311
- ...S,
312
- error: m,
187
+ } catch (c) {
188
+ throw C((f) => ({
189
+ ...f,
190
+ error: c,
313
191
  items: [],
314
192
  count: 0,
315
193
  initializingState: !1,
316
194
  isLoading: !1
317
- })), m;
195
+ })), c;
318
196
  }
319
197
  },
320
- [c, h, p, y, P, e]
321
- ), v = g(
198
+ [n, l, v, y, S, t]
199
+ ), b = P(
322
200
  () => ({
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);
201
+ setPage: (d, g) => {
202
+ let c = d;
203
+ d === 0 && (c = "");
204
+ const f = { ...t, page: c };
205
+ C(f), c && M(g, f);
328
206
  },
329
- setPerPage: (b) => {
330
- const x = { ...e, perPage: b, page: 1 };
331
- L(x), z({}, x);
207
+ setPerPage: (d) => {
208
+ const g = { ...t, perPage: d, page: 1 };
209
+ C(g), M({}, g);
332
210
  },
333
- setSearch: (b) => {
334
- if (b !== e.search) {
335
- const x = { ...e, search: b, page: 1 };
336
- L(x), z({}, x);
211
+ setSearch: (d) => {
212
+ if (d !== t.search) {
213
+ const g = { ...t, search: d, page: 1 };
214
+ C(g), M({}, g);
337
215
  }
338
216
  },
339
- setSort: ({ by: b, order: x }) => {
340
- const m = { ...e, sortBy: b, sortOrder: x, page: 1 };
341
- L(m), z({}, m);
217
+ setSort: ({ by: d, order: g }) => {
218
+ const c = { ...t, sortBy: d, sortOrder: g, page: 1 };
219
+ C(c), M({}, c);
342
220
  },
343
221
  loadMore: () => {
344
- const b = { ...e, page: e.page + 1 };
345
- L(b), z({}, b);
222
+ const d = { ...t, page: t.page + 1 };
223
+ C(d), M({}, d);
346
224
  },
347
- refresh: (b = { isRefresh: !0 }) => {
348
- if (p) {
349
- const x = { ...e, page: 1, items: [] };
350
- L(x), z(b, x);
225
+ refresh: (d = { isRefresh: !0 }) => {
226
+ if (v) {
227
+ const g = { ...t, page: 1, items: [] };
228
+ C(g), M(d, g);
351
229
  } else
352
- z(b);
230
+ M(d);
231
+ },
232
+ setFilters: (d) => {
233
+ const g = { ...t, filters: d, page: 1 };
234
+ C(g), M({}, g);
353
235
  },
354
- setFilters: (b) => {
355
- const x = { ...e, filters: b, page: 1 };
356
- L(x), z({}, x);
236
+ updateItemById: (d, g) => {
237
+ const c = t.items.map((f) => f.id === g ? { ...f, ...d } : f);
238
+ C((f) => ({ ...f, items: c }));
357
239
  },
358
- setSelection: (b) => L((x) => ({ ...x, selection: b }))
240
+ setSelection: (d) => C((g) => ({ ...g, selection: d }))
359
241
  }),
360
- [z, p, e]
361
- ), C = g(
242
+ [M, v, t]
243
+ ), O = P(
362
244
  () => ({
363
- data: e.items,
364
- response: e.response,
365
- error: e.error,
366
- count: e.count,
367
- selection: e.selection,
245
+ data: t.items,
246
+ response: t.response,
247
+ error: t.error,
248
+ count: t.count,
249
+ selection: t.selection,
368
250
  pagination: {
369
- page: e.page,
370
- perPage: e.perPage,
371
- hasMore: e.items.length < e.count
251
+ page: t.page,
252
+ perPage: t.perPage,
253
+ hasMore: t.items.length < t.count
372
254
  },
373
255
  loader: {
374
- isLoading: e.isLoading,
375
- initialLoading: e.initializingState
256
+ isLoading: t.isLoading,
257
+ initialLoading: t.initializingState
376
258
  },
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
259
+ sort: { sortBy: t.sortBy, sortOrder: t.sortOrder },
260
+ search: t.search,
261
+ filters: t.filters,
262
+ attrs: m || Object.keys(t.items[0] || {}),
263
+ isEmpty: t.items.length === 0,
264
+ ...b
383
265
  }),
384
266
  [
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
267
+ t.items,
268
+ t.response,
269
+ t.error,
270
+ t.count,
271
+ t.selection,
272
+ t.page,
273
+ t.perPage,
274
+ t.isLoading,
275
+ t.initializingState,
276
+ t.sortBy,
277
+ t.sortOrder,
278
+ t.search,
279
+ t.filters,
280
+ b,
281
+ m
400
282
  ]
401
283
  );
402
- return I(() => {
403
- e.initializingState && v.setPage(e.page);
404
- }, []), I(() => {
405
- w(C);
284
+ return E(() => {
285
+ t.initializingState && b.setPage(t.page);
286
+ }, []), E(() => {
287
+ N(O);
406
288
  }, [
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(
289
+ N,
290
+ t.items,
291
+ t.count,
292
+ t.error,
293
+ t.isLoading,
294
+ t.selection,
295
+ t.page,
296
+ t.perPage,
297
+ t.sortBy,
298
+ t.sortOrder
299
+ ]), typeof o == "function" ? o(O) : o;
300
+ }, V = w(({ children: r }) => {
301
+ const { listState: o } = R(), { data: n, count: e, pagination: s, setPage: a, loader: p, error: h } = o, { page: u, perPage: m } = s, { isLoading: l } = p, L = P(
302
+ () => u * m < e,
303
+ [u, m, e]
304
+ ), y = k(() => {
305
+ L && !l && a(u + 1);
306
+ }, [L, l, a, u]), S = P(
423
307
  () => ({
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,
308
+ isLoading: l,
439
309
  loadMore: y,
440
- hasMoreItems: d,
441
- styles: P
310
+ hasMoreItems: L
442
311
  }),
443
- [u, y, d, P]
312
+ [l, y, L]
444
313
  );
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(
314
+ return !n || n.length === 0 || h ? null : r(S);
315
+ }), X = w(({ children: r, position: o = "overlay" }) => {
316
+ const { listState: n } = R(), { loader: e } = n, { isLoading: s, initializingState: a } = e;
317
+ return P(
477
318
  () => ({
478
- overlay: s.overlay,
479
- before: s.before,
480
- after: s.after
319
+ isLoading: s
481
320
  }),
482
321
  [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(
322
+ ), !a && !s ? null : /* @__PURE__ */ i("div", { children: r || /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i("p", { children: "Loading..." }) }) });
323
+ }), Y = w(
492
324
  ({
493
- children: i,
494
- pageLinks: c = 5,
495
- renderFirst: r,
496
- renderPrev: t,
497
- renderPages: o,
498
- renderPage: n,
499
- renderNext: s,
500
- renderLast: f
325
+ children: r,
326
+ pageLinks: o = 5,
327
+ renderFirst: n,
328
+ renderPrev: e,
329
+ renderPages: s,
330
+ renderPage: a,
331
+ renderNext: p,
332
+ renderLast: h
501
333
  }) => {
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(
334
+ const { listState: u } = R(), { data: m, count: l, pagination: L, setPage: y, loader: S, error: N } = u, { page: v, perPage: t } = L, { initialLoading: C, isLoading: M } = S, b = P(() => {
335
+ const c = Math.ceil(l / t), f = Math.floor(o / 2), x = v * t < l;
336
+ return { pagesCount: c, halfWay: f, hasNext: x, hasPrev: v !== 1 };
337
+ }, [l, t, v, o]), O = P(() => {
338
+ const { pagesCount: c, halfWay: f } = b, x = Array.from({ length: Math.min(o, c) });
339
+ return v <= f ? x.map((I, B) => B + 1) : c - v < f ? x.map((I, B) => c - B).reverse() : x.map((I, B) => v - f + B);
340
+ }, [v, o, b]), d = P(
503
341
  () => ({
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(
556
- () => ({
557
- prev: () => y(p - 1),
558
- next: () => y(p + 1),
342
+ prev: () => y(v - 1),
343
+ next: () => y(v + 1),
559
344
  first: () => y(1),
560
- last: () => y(C.pagesCount),
561
- setPage: (S) => y(S)
345
+ last: () => y(b.pagesCount),
346
+ setPage: (c) => y(c)
562
347
  }),
563
- [y, p, C.pagesCount]
564
- ), m = g(
348
+ [y, v, b.pagesCount]
349
+ ), g = P(
565
350
  () => ({
566
- page: p,
567
- perPage: e,
568
- count: u,
569
- ...C,
570
- pagesToDisplay: b,
571
- ...x,
572
- styles: v
351
+ page: v,
352
+ perPage: t,
353
+ count: l,
354
+ ...b,
355
+ pagesToDisplay: O,
356
+ ...d
573
357
  }),
574
- [
575
- p,
576
- e,
577
- u,
578
- C,
579
- b,
580
- x,
581
- v
582
- ]
358
+ [v, t, l, b, O, d]
583
359
  );
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(
360
+ return C || !m || m.length === 0 || N ? null : r ? r(g) : /* @__PURE__ */ z("div", { className: "react-list-pagination", children: [
361
+ n ? n(g) : /* @__PURE__ */ i(
586
362
  "button",
587
363
  {
588
364
  type: "button",
589
- disabled: !C.hasPrev,
590
- onClick: x.first,
591
- style: {
592
- ...v.button,
593
- ...!C.hasPrev && v.disabledButton
594
- },
365
+ disabled: !b.hasPrev,
366
+ onClick: d.first,
595
367
  children: "First"
596
368
  }
597
369
  ),
598
- t ? t(m) : /* @__PURE__ */ l(
370
+ e ? e(g) : /* @__PURE__ */ i(
599
371
  "button",
600
372
  {
601
373
  type: "button",
602
- disabled: !C.hasPrev,
603
- onClick: x.prev,
604
- style: {
605
- ...v.button,
606
- ...!C.hasPrev && v.disabledButton
607
- },
374
+ disabled: !b.hasPrev,
375
+ onClick: d.prev,
608
376
  children: "Prev"
609
377
  }
610
378
  ),
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(
379
+ s ? s(g) : /* @__PURE__ */ i("div", { children: O.map((c) => {
380
+ const f = c === v, x = { ...g, page: c, isActive: f };
381
+ return a ? a(x) : /* @__PURE__ */ i("div", { children: f ? /* @__PURE__ */ i("span", { children: c }) : /* @__PURE__ */ i(
614
382
  "button",
615
383
  {
616
384
  type: "button",
617
- onClick: () => x.setPage(S),
618
- style: v.pageButton,
619
- children: S
385
+ onClick: () => d.setPage(c),
386
+ children: c
620
387
  }
621
- ) }, `page-${S}`);
388
+ ) }, `page-${c}`);
622
389
  }) }),
623
- s ? s(m) : /* @__PURE__ */ l(
390
+ p ? p(g) : /* @__PURE__ */ i(
624
391
  "button",
625
392
  {
626
393
  type: "button",
627
- disabled: !C.hasNext,
628
- onClick: x.next,
629
- style: {
630
- ...v.button,
631
- ...!C.hasNext && v.disabledButton
632
- },
394
+ disabled: !b.hasNext,
395
+ onClick: d.next,
633
396
  children: "Next"
634
397
  }
635
398
  ),
636
- f ? f(m) : /* @__PURE__ */ l(
399
+ h ? h(g) : /* @__PURE__ */ i(
637
400
  "button",
638
401
  {
639
402
  type: "button",
640
- disabled: !C.hasNext,
641
- onClick: x.last,
642
- style: {
643
- ...v.button,
644
- ...!C.hasNext && v.disabledButton
645
- },
403
+ disabled: !b.hasNext,
404
+ onClick: d.last,
646
405
  children: "Last"
647
406
  }
648
407
  )
649
408
  ] });
650
409
  }
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));
410
+ ), Z = w(
411
+ ({ children: r, options: o = [10, 25, 50, 100] }) => {
412
+ const { listState: n } = R(), { data: e, pagination: s, setPerPage: a, loader: p, error: h } = n, { perPage: u } = s, { initialLoading: m } = p, l = P(() => o.map((S) => typeof S != "object" ? {
413
+ value: S,
414
+ label: S
415
+ } : S), [o]), L = k(
416
+ (S) => {
417
+ a(Number(S.target.value));
677
418
  },
678
- [n]
679
- ), w = g(
419
+ [a]
420
+ ), y = P(
680
421
  () => ({
681
- perPage: a,
682
- setPerPage: n,
683
- options: y,
684
- styles: d
422
+ perPage: u,
423
+ setPerPage: a,
424
+ options: l
685
425
  }),
686
- [a, n, y, d]
426
+ [u, a, l]
687
427
  );
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
- ) });
428
+ return m || !e || e.length === 0 || h ? null : /* @__PURE__ */ i("div", { className: "react-list-per-page", children: r ? r(y) : /* @__PURE__ */ i("select", { value: u, onChange: L, children: l.map((S) => /* @__PURE__ */ z("option", { value: S.value, children: [
429
+ S.label,
430
+ " items per page"
431
+ ] }, `option-${S.value}`)) }) });
700
432
  }
701
- ), ne = R(({ children: i }) => {
702
- const { listState: c } = k(), { loader: r, refresh: t } = c, { isLoading: o, initialLoading: n } = r, s = g(
433
+ ), tt = w(({ children: r }) => {
434
+ const { listState: o } = R(), { loader: n, refresh: e } = o, { isLoading: s, initialLoading: a } = n, p = k(() => {
435
+ e({ isRefresh: !0 });
436
+ }, [e]), h = P(
703
437
  () => ({
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(
728
- () => ({
729
- isLoading: o,
730
- refresh: f
438
+ isLoading: s,
439
+ refresh: p
731
440
  }),
732
- [o, f, s]
441
+ [s, p]
733
442
  );
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);
443
+ 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" }) });
444
+ }), et = w(({ children: r, debounceTime: o = 500 }) => {
445
+ const { listState: n } = R(), { search: e, setSearch: s } = n, [a, p] = T(e ?? ""), h = q(null);
446
+ E(() => {
447
+ e !== a && p(e ?? "");
448
+ }, [e]);
449
+ const u = (l) => {
450
+ p(l), h.current && clearTimeout(h.current), h.current = setTimeout(() => {
451
+ s(l);
452
+ }, o);
758
453
  };
759
- I(() => () => {
454
+ return E(() => () => {
760
455
  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"
456
+ }, []), /* @__PURE__ */ i("div", { className: "react-list-search", children: r ? r({
457
+ search: a,
458
+ setSearch: u
459
+ }) : /* @__PURE__ */ i(
460
+ "input",
461
+ {
462
+ type: "text",
463
+ value: a,
464
+ onChange: (l) => u(l.target.value),
465
+ placeholder: "Search..."
775
466
  }
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(
467
+ ) });
468
+ }), nt = w(({ children: r }) => {
469
+ const { listState: o } = R(), { data: n, count: e, pagination: s, loader: a, error: p } = o, { page: h, perPage: u } = s, { initialLoading: m, isLoading: l } = a, L = P(() => {
470
+ const S = h * u - u + 1, N = Math.min(h * u, e), v = (n == null ? void 0 : n.length) || 0;
471
+ return { from: S, to: N, visibleCount: v };
472
+ }, [h, u, e, n]), y = P(
822
473
  () => ({
823
- ...y,
824
- count: t,
825
- styles: d
474
+ ...L,
475
+ count: e
826
476
  }),
827
- [y, t, d]
477
+ [L, e]
828
478
  );
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: [
479
+ return m || !n || n.length === 0 || p ? null : /* @__PURE__ */ i("div", { className: "react-list-summary", children: r ? r(y) : /* @__PURE__ */ z("span", { children: [
830
480
  "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,
481
+ /* @__PURE__ */ i("span", { children: L.visibleCount }),
482
+ " items (",
483
+ /* @__PURE__ */ z("span", { children: [
484
+ L.from,
836
485
  " - ",
837
- y.to
486
+ L.to
838
487
  ] }),
839
488
  ") out of ",
840
- /* @__PURE__ */ l("span", { style: d.highlight, children: t })
489
+ /* @__PURE__ */ i("span", { children: e })
841
490
  ] }) });
842
491
  });
843
492
  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
493
+ W as ReactListAttributes,
494
+ F as ReactListEmpty,
495
+ G as ReactListError,
496
+ J as ReactListGoTo,
497
+ K as ReactListInitialLoader,
498
+ Q as ReactListItems,
499
+ V as ReactListLoadMore,
500
+ X as ReactListLoader,
501
+ Y as ReactListPagination,
502
+ Z as ReactListPerPage,
503
+ H as ReactListProvider,
504
+ tt as ReactListRefresh,
505
+ et as ReactListSearch,
506
+ nt as ReactListSummary,
507
+ U as default
859
508
  };
@@ -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(S,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):(S=typeof globalThis<"u"?globalThis:S||self,s(S.ReactList={},S.jsxRuntime,S.react))})(this,function(S,s,n){"use strict";const B=n.createContext(null),I=({children:o,config:l})=>{const{requestHandler:a,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(!a)throw new Error("ListProvider: requestHandler is required.");const f=n.useMemo(()=>({requestHandler:a,stateManager:t,listState:r,setListState:i}),[a,t,r]);return s.jsx(B.Provider,{value:f,children:o})},w=()=>{const o=n.useContext(B);if(!o)throw new Error("useListContext must be used within a ListProvider");return o},j=n.memo(({children:o,renderAttribute:l})=>{const{listState:a}=w(),{attrs:t,attrSettings:r,updateAttr:i}=a,f=n.useCallback(d=>m=>{i(d,"visible",m.target.checked)},[i]),p=n.useMemo(()=>({attrs:t,attrSettings:r,updateAttr:i}),[t,r,i]);return o?o(p):s.jsx("div",{className:"react-list-attributes",children:t.map((d,m)=>{var u;return l?l({key:`attr-${m}`,attr:d,updateAttr:i,attrSettings:r}):s.jsxs("label",{children:[s.jsx("span",{children:d.label}),s.jsx("input",{type:"checkbox",checked:((u=r==null?void 0:r[d.name])==null?void 0:u.visible)??!1,onChange:f(d.name)})]},`attr-${m}`)})})}),q=n.memo(({children:o})=>{const{listState:l}=w(),{data:a,loader:t,error:r}=l,{isLoading:i,initialLoading:f}=t;return(a==null?void 0:a.length)>0||f||i||r?null:s.jsx("div",{className:"react-list-empty",children:o||s.jsx("div",{children:s.jsx("p",{children:"No data found!"})})})}),A=n.memo(({children:o})=>{const{listState:l}=w(),{error:a,loader:t}=l,{isLoading:r}=t;return!a||r?null:s.jsx("div",{className:"react-list-error",children:typeof o=="function"?o({error:a}):o||s.jsxs("div",{children:[s.jsx("h3",{children:"Error occurred"}),s.jsxs("pre",{children:[a.name,": ",a.message]})]})})}),_=n.memo(({children:o})=>{const{listState:l}=w(),{data:a,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:d,perPage:m}=r,{initialLoading:u,isLoading:v}=f,{pages:b,pagesCount:y}=n.useMemo(()=>{const e=Math.ceil(t/m);return{pages:Array.from({length:e},(k,M)=>M+1),pagesCount:e}},[t,m]),N=n.useCallback(e=>{i(Number(e.target.value))},[i]),P=n.useMemo(()=>({setPage:i,page:d,pages:b,pagesCount:y}),[i,d,b,y]);return u||!a||a.length===0||p?null:s.jsx("div",{className:"react-list-go-to",children:o?o(P):s.jsx("select",{value:d,onChange:N,children:b.map(e=>s.jsxs("option",{value:e,children:["Page ",e]},`page-${e}`))})})}),$=n.memo(({children:o})=>{const{listState:l}=w(),{loader:a}=l,{initialLoading:t}=a;return n.useMemo(()=>({loading:t}),[t]),t?s.jsx("div",{className:"react-list-initial-loader",children:o||s.jsx("p",{children:"Initial Loading..."})}):null}),D=n.memo(({children:o,renderItem:l})=>{const{listState:a}=w(),{data:t=[],loader:r,error:i,setSort:f,sort:p}=a,{initialLoading:d}=r,m=n.useMemo(()=>({items:t,setSort:f,sort:p}),[t,p,f]);return d||!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 o=="function"?s.jsx("div",{className:"react-list-items",children:o(m)}):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=({initialItems:o=[],children:l,endpoint:a,page:t=1,perPage:r=25,sortBy:i="",sortOrder:f="desc",search:p="",filters:d={},attrs:m,version:u=1,paginationMode:v="pagination",meta:b={}})=>{const{requestHandler:y,setListState:N}=w(),P=v==="loadMore",[e,C]=n.useState({page:t,perPage:r,sortBy:i,sortOrder:f,search:p,filters:d,attrSettings:{},items:o,selection:[],error:null,response:null,count:0,isLoading:!1,initializingState:!0}),k=n.useCallback(async(g={},h=null)=>{e.initializingState||C(c=>({...c,error:null,isLoading:!0}));try{const c=h||e,L=await y({endpoint:a,version:u,meta:b,page:c.page,perPage:c.perPage,search:c.search,sortBy:c.sortBy,sortOrder:c.sortOrder,filters:c.filters,...g});C(E=>({...E,response:L,selection:[],items:P&&c.page>1?[...E.items,...L.items]:L.items,count:L.count,initializingState:!1,isLoading:!1}))}catch(c){throw C(L=>({...L,error:c,items:[],count:0,initializingState:!1,isLoading:!1})),c}},[a,u,P,b,y,e]),M=n.useMemo(()=>({setPage:(g,h)=>{let c=g;g===0&&(c="");const L={...e,page:c};C(L),c&&k(h,L)},setPerPage:g=>{const h={...e,perPage:g,page:1};C(h),k({},h)},setSearch:g=>{if(g!==e.search){const h={...e,search:g,page:1};C(h),k({},h)}},setSort:({by:g,order:h})=>{const c={...e,sortBy:g,sortOrder:h,page:1};C(c),k({},c)},loadMore:()=>{const g={...e,page:e.page+1};C(g),k({},g)},refresh:(g={isRefresh:!0})=>{if(P){const h={...e,page:1,items:[]};C(h),k(g,h)}else k(g)},setFilters:g=>{const h={...e,filters:g,page:1};C(h),k({},h)},updateItemById:(g,h)=>{const c=e.items.map(L=>L.id===h?{...L,...g}:L);C(L=>({...L,items:c}))},setSelection:g=>C(h=>({...h,selection:g}))}),[k,P,e]),O=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:m||Object.keys(e.items[0]||{}),isEmpty:e.items.length===0,...M}),[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,M,m]);return n.useEffect(()=>{e.initializingState&&M.setPage(e.page)},[]),n.useEffect(()=>{N(O)},[N,e.items,e.count,e.error,e.isLoading,e.selection,e.page,e.perPage,e.sortBy,e.sortOrder]),typeof l=="function"?l(O):l},x=n.memo(({children:o})=>{const{listState:l}=w(),{data:a,count:t,pagination:r,setPage:i,loader:f,error:p}=l,{page:d,perPage:m}=r,{isLoading:u}=f,v=n.useMemo(()=>d*m<t,[d,m,t]),b=n.useCallback(()=>{v&&!u&&i(d+1)},[v,u,i,d]),y=n.useMemo(()=>({isLoading:u,loadMore:b,hasMoreItems:v}),[u,b,v]);return!a||a.length===0||p?null:o(y)}),G=n.memo(({children:o,position:l="overlay"})=>{const{listState:a}=w(),{loader:t}=a,{isLoading:r,initializingState:i}=t;return n.useMemo(()=>({isLoading:r}),[r]),!i&&!r?null:s.jsx("div",{children:o||s.jsx("div",{children:s.jsx("p",{children:"Loading..."})})})}),W=n.memo(({children:o,pageLinks:l=5,renderFirst:a,renderPrev:t,renderPages:r,renderPage:i,renderNext:f,renderLast:p})=>{const{listState:d}=w(),{data:m,count:u,pagination:v,setPage:b,loader:y,error:N}=d,{page:P,perPage:e}=v,{initialLoading:C,isLoading:k}=y,M=n.useMemo(()=>{const c=Math.ceil(u/e),L=Math.floor(l/2),E=P*e<u;return{pagesCount:c,halfWay:L,hasNext:E,hasPrev:P!==1}},[u,e,P,l]),O=n.useMemo(()=>{const{pagesCount:c,halfWay:L}=M,E=Array.from({length:Math.min(l,c)});return P<=L?E.map((T,z)=>z+1):c-P<L?E.map((T,z)=>c-z).reverse():E.map((T,z)=>P-L+z)},[P,l,M]),g=n.useMemo(()=>({prev:()=>b(P-1),next:()=>b(P+1),first:()=>b(1),last:()=>b(M.pagesCount),setPage:c=>b(c)}),[b,P,M.pagesCount]),h=n.useMemo(()=>({page:P,perPage:e,count:u,...M,pagesToDisplay:O,...g}),[P,e,u,M,O,g]);return C||!m||m.length===0||N?null:o?o(h):s.jsxs("div",{className:"react-list-pagination",children:[a?a(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:O.map(c=>{const L=c===P,E={...h,page:c,isActive:L};return i?i(E):s.jsx("div",{children:L?s.jsx("span",{children:c}):s.jsx("button",{type:"button",onClick:()=>g.setPage(c),children:c})},`page-${c}`)})}),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:o,options:l=[10,25,50,100]})=>{const{listState:a}=w(),{data:t,pagination:r,setPerPage:i,loader:f,error:p}=a,{perPage:d}=r,{initialLoading:m}=f,u=n.useMemo(()=>l.map(y=>typeof y!="object"?{value:y,label:y}:y),[l]),v=n.useCallback(y=>{i(Number(y.target.value))},[i]),b=n.useMemo(()=>({perPage:d,setPerPage:i,options:u}),[d,i,u]);return m||!t||t.length===0||p?null:s.jsx("div",{className:"react-list-per-page",children:o?o(b):s.jsx("select",{value:d,onChange:v,children:u.map(y=>s.jsxs("option",{value:y.value,children:[y.label," items per page"]},`option-${y.value}`))})})}),J=n.memo(({children:o})=>{const{listState:l}=w(),{loader:a,refresh:t}=l,{isLoading:r,initialLoading:i}=a,f=n.useCallback(()=>{t({isRefresh:!0})},[t]),p=n.useMemo(()=>({isLoading:r,refresh:f}),[r,f]);return i?null:o?o(p):s.jsx("div",{className:"react-list-refresh",children:s.jsx("button",{onClick:f,disabled:r,children:r?"Loading...":"Refresh"})})}),K=n.memo(({children:o,debounceTime:l=500})=>{const{listState:a}=w(),{search:t,setSearch:r}=a,[i,f]=n.useState(t??""),p=n.useRef(null);n.useEffect(()=>{t!==i&&f(t??"")},[t]);const d=u=>{f(u),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{r(u)},l)};n.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const m={search:i,setSearch:d};return s.jsx("div",{className:"react-list-search",children:o?o(m):s.jsx("input",{type:"text",value:i,onChange:u=>d(u.target.value),placeholder:"Search..."})})}),Q=n.memo(({children:o})=>{const{listState:l}=w(),{data:a,count:t,pagination:r,loader:i,error:f}=l,{page:p,perPage:d}=r,{initialLoading:m,isLoading:u}=i,v=n.useMemo(()=>{const y=p*d-d+1,N=Math.min(p*d,t),P=(a==null?void 0:a.length)||0;return{from:y,to:N,visibleCount:P}},[p,d,t,a]),b=n.useMemo(()=>({...v,count:t}),[v,t]);return m||!a||a.length===0||f?null:s.jsx("div",{className:"react-list-summary",children:o?o(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})]})})});S.ReactListAttributes=j,S.ReactListEmpty=q,S.ReactListError=A,S.ReactListGoTo=_,S.ReactListInitialLoader=$,S.ReactListItems=D,S.ReactListLoadMore=x,S.ReactListLoader=G,S.ReactListPagination=W,S.ReactListPerPage=F,S.ReactListProvider=I,S.ReactListRefresh=J,S.ReactListSearch=K,S.ReactListSummary=Q,S.default=H,Object.defineProperties(S,{__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.4",
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",