@7span/react-list 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-list.js +859 -0
- package/dist/react-list.umd.cjs +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,859 @@
|
|
|
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({
|
|
5
|
+
data: [],
|
|
6
|
+
response: null,
|
|
7
|
+
error: null,
|
|
8
|
+
count: 0,
|
|
9
|
+
selection: [],
|
|
10
|
+
pagination: {
|
|
11
|
+
page: 1,
|
|
12
|
+
perPage: 25
|
|
13
|
+
},
|
|
14
|
+
loader: {
|
|
15
|
+
isLoading: !1,
|
|
16
|
+
initialLoading: !0
|
|
17
|
+
},
|
|
18
|
+
sort: {
|
|
19
|
+
sortBy: null,
|
|
20
|
+
sortOrder: "desc"
|
|
21
|
+
},
|
|
22
|
+
search: "",
|
|
23
|
+
filters: {},
|
|
24
|
+
attrs: [],
|
|
25
|
+
isEmpty: !0,
|
|
26
|
+
isInitializing: !0
|
|
27
|
+
});
|
|
28
|
+
if (!r)
|
|
29
|
+
throw new Error("ListProvider: requestHandler is required.");
|
|
30
|
+
const s = g(
|
|
31
|
+
() => ({
|
|
32
|
+
requestHandler: r,
|
|
33
|
+
stateManager: t,
|
|
34
|
+
listState: o,
|
|
35
|
+
setListState: n
|
|
36
|
+
}),
|
|
37
|
+
[r, t, o]
|
|
38
|
+
);
|
|
39
|
+
return /* @__PURE__ */ l(E.Provider, { value: s, children: i });
|
|
40
|
+
}, k = () => {
|
|
41
|
+
const i = j(E);
|
|
42
|
+
if (!i)
|
|
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);
|
|
68
|
+
},
|
|
69
|
+
[n]
|
|
70
|
+
), a = g(
|
|
71
|
+
() => ({
|
|
72
|
+
attrs: t,
|
|
73
|
+
attrSettings: o,
|
|
74
|
+
updateAttr: n,
|
|
75
|
+
styles: s
|
|
76
|
+
}),
|
|
77
|
+
[t, o, n]
|
|
78
|
+
);
|
|
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(
|
|
90
|
+
"input",
|
|
91
|
+
{
|
|
92
|
+
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
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
] }, `attr-${u}`);
|
|
99
|
+
}) });
|
|
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,
|
|
148
|
+
": ",
|
|
149
|
+
r.message
|
|
150
|
+
] })
|
|
151
|
+
] }) });
|
|
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));
|
|
177
|
+
},
|
|
178
|
+
[n]
|
|
179
|
+
), e = g(
|
|
180
|
+
() => ({
|
|
181
|
+
setPage: n,
|
|
182
|
+
page: a,
|
|
183
|
+
pages: P,
|
|
184
|
+
pagesCount: w,
|
|
185
|
+
styles: y
|
|
186
|
+
}),
|
|
187
|
+
[n, a, P, w, y]
|
|
188
|
+
);
|
|
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: [
|
|
190
|
+
"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(
|
|
223
|
+
() => ({
|
|
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
|
+
}
|
|
243
|
+
}),
|
|
244
|
+
[]
|
|
245
|
+
), h = g(
|
|
246
|
+
() => ({
|
|
247
|
+
items: t,
|
|
248
|
+
styles: a
|
|
249
|
+
}),
|
|
250
|
+
[t, a]
|
|
251
|
+
);
|
|
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",
|
|
266
|
+
meta: y = {}
|
|
267
|
+
}) => {
|
|
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,
|
|
275
|
+
attrSettings: {},
|
|
276
|
+
items: [],
|
|
277
|
+
selection: [],
|
|
278
|
+
error: null,
|
|
279
|
+
response: null,
|
|
280
|
+
count: 0,
|
|
281
|
+
isLoading: !1,
|
|
282
|
+
initializingState: !0
|
|
283
|
+
}), z = T(
|
|
284
|
+
async (b = {}, x = null) => {
|
|
285
|
+
e.initializingState || L((m) => ({ ...m, error: null, isLoading: !0 }));
|
|
286
|
+
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
|
|
298
|
+
});
|
|
299
|
+
L((B) => ({
|
|
300
|
+
...B,
|
|
301
|
+
response: S,
|
|
302
|
+
selection: [],
|
|
303
|
+
// Append items for loadMore, replace for pagination
|
|
304
|
+
items: p ? [...B.items, ...S.items] : S.items,
|
|
305
|
+
count: S.count,
|
|
306
|
+
initializingState: !1,
|
|
307
|
+
isLoading: !1
|
|
308
|
+
}));
|
|
309
|
+
} catch (m) {
|
|
310
|
+
throw L((S) => ({
|
|
311
|
+
...S,
|
|
312
|
+
error: m,
|
|
313
|
+
items: [],
|
|
314
|
+
count: 0,
|
|
315
|
+
initializingState: !1,
|
|
316
|
+
isLoading: !1
|
|
317
|
+
})), m;
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
[c, h, p, y, P, e]
|
|
321
|
+
), v = g(
|
|
322
|
+
() => ({
|
|
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);
|
|
328
|
+
},
|
|
329
|
+
setPerPage: (b) => {
|
|
330
|
+
const x = { ...e, perPage: b, page: 1 };
|
|
331
|
+
L(x), z({}, x);
|
|
332
|
+
},
|
|
333
|
+
setSearch: (b) => {
|
|
334
|
+
if (b !== e.search) {
|
|
335
|
+
const x = { ...e, search: b, page: 1 };
|
|
336
|
+
L(x), z({}, x);
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
setSort: ({ by: b, order: x }) => {
|
|
340
|
+
const m = { ...e, sortBy: b, sortOrder: x, page: 1 };
|
|
341
|
+
L(m), z({}, m);
|
|
342
|
+
},
|
|
343
|
+
loadMore: () => {
|
|
344
|
+
const b = { ...e, page: e.page + 1 };
|
|
345
|
+
L(b), z({}, b);
|
|
346
|
+
},
|
|
347
|
+
refresh: (b = { isRefresh: !0 }) => {
|
|
348
|
+
if (p) {
|
|
349
|
+
const x = { ...e, page: 1, items: [] };
|
|
350
|
+
L(x), z(b, x);
|
|
351
|
+
} else
|
|
352
|
+
z(b);
|
|
353
|
+
},
|
|
354
|
+
setFilters: (b) => {
|
|
355
|
+
const x = { ...e, filters: b, page: 1 };
|
|
356
|
+
L(x), z({}, x);
|
|
357
|
+
},
|
|
358
|
+
setSelection: (b) => L((x) => ({ ...x, selection: b }))
|
|
359
|
+
}),
|
|
360
|
+
[z, p, e]
|
|
361
|
+
), C = g(
|
|
362
|
+
() => ({
|
|
363
|
+
data: e.items,
|
|
364
|
+
response: e.response,
|
|
365
|
+
error: e.error,
|
|
366
|
+
count: e.count,
|
|
367
|
+
selection: e.selection,
|
|
368
|
+
pagination: {
|
|
369
|
+
page: e.page,
|
|
370
|
+
perPage: e.perPage,
|
|
371
|
+
hasMore: e.items.length < e.count
|
|
372
|
+
},
|
|
373
|
+
loader: {
|
|
374
|
+
isLoading: e.isLoading,
|
|
375
|
+
initialLoading: e.initializingState
|
|
376
|
+
},
|
|
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
|
|
383
|
+
}),
|
|
384
|
+
[
|
|
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
|
|
400
|
+
]
|
|
401
|
+
);
|
|
402
|
+
return I(() => {
|
|
403
|
+
e.initializingState && v.setPage(e.page);
|
|
404
|
+
}, []), I(() => {
|
|
405
|
+
w(C);
|
|
406
|
+
}, [
|
|
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(
|
|
423
|
+
() => ({
|
|
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,
|
|
439
|
+
loadMore: y,
|
|
440
|
+
hasMoreItems: d,
|
|
441
|
+
styles: P
|
|
442
|
+
}),
|
|
443
|
+
[u, y, d, P]
|
|
444
|
+
);
|
|
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(
|
|
477
|
+
() => ({
|
|
478
|
+
overlay: s.overlay,
|
|
479
|
+
before: s.before,
|
|
480
|
+
after: s.after
|
|
481
|
+
}),
|
|
482
|
+
[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(
|
|
492
|
+
({
|
|
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
|
|
501
|
+
}) => {
|
|
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(
|
|
556
|
+
() => ({
|
|
557
|
+
prev: () => y(p - 1),
|
|
558
|
+
next: () => y(p + 1),
|
|
559
|
+
first: () => y(1),
|
|
560
|
+
last: () => y(C.pagesCount),
|
|
561
|
+
setPage: (S) => y(S)
|
|
562
|
+
}),
|
|
563
|
+
[y, p, C.pagesCount]
|
|
564
|
+
), m = g(
|
|
565
|
+
() => ({
|
|
566
|
+
page: p,
|
|
567
|
+
perPage: e,
|
|
568
|
+
count: u,
|
|
569
|
+
...C,
|
|
570
|
+
pagesToDisplay: b,
|
|
571
|
+
...x,
|
|
572
|
+
styles: v
|
|
573
|
+
}),
|
|
574
|
+
[
|
|
575
|
+
p,
|
|
576
|
+
e,
|
|
577
|
+
u,
|
|
578
|
+
C,
|
|
579
|
+
b,
|
|
580
|
+
x,
|
|
581
|
+
v
|
|
582
|
+
]
|
|
583
|
+
);
|
|
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(
|
|
586
|
+
"button",
|
|
587
|
+
{
|
|
588
|
+
type: "button",
|
|
589
|
+
disabled: !C.hasPrev,
|
|
590
|
+
onClick: x.first,
|
|
591
|
+
style: {
|
|
592
|
+
...v.button,
|
|
593
|
+
...!C.hasPrev && v.disabledButton
|
|
594
|
+
},
|
|
595
|
+
children: "First"
|
|
596
|
+
}
|
|
597
|
+
),
|
|
598
|
+
t ? t(m) : /* @__PURE__ */ l(
|
|
599
|
+
"button",
|
|
600
|
+
{
|
|
601
|
+
type: "button",
|
|
602
|
+
disabled: !C.hasPrev,
|
|
603
|
+
onClick: x.prev,
|
|
604
|
+
style: {
|
|
605
|
+
...v.button,
|
|
606
|
+
...!C.hasPrev && v.disabledButton
|
|
607
|
+
},
|
|
608
|
+
children: "Prev"
|
|
609
|
+
}
|
|
610
|
+
),
|
|
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(
|
|
614
|
+
"button",
|
|
615
|
+
{
|
|
616
|
+
type: "button",
|
|
617
|
+
onClick: () => x.setPage(S),
|
|
618
|
+
style: v.pageButton,
|
|
619
|
+
children: S
|
|
620
|
+
}
|
|
621
|
+
) }, `page-${S}`);
|
|
622
|
+
}) }),
|
|
623
|
+
s ? s(m) : /* @__PURE__ */ l(
|
|
624
|
+
"button",
|
|
625
|
+
{
|
|
626
|
+
type: "button",
|
|
627
|
+
disabled: !C.hasNext,
|
|
628
|
+
onClick: x.next,
|
|
629
|
+
style: {
|
|
630
|
+
...v.button,
|
|
631
|
+
...!C.hasNext && v.disabledButton
|
|
632
|
+
},
|
|
633
|
+
children: "Next"
|
|
634
|
+
}
|
|
635
|
+
),
|
|
636
|
+
f ? f(m) : /* @__PURE__ */ l(
|
|
637
|
+
"button",
|
|
638
|
+
{
|
|
639
|
+
type: "button",
|
|
640
|
+
disabled: !C.hasNext,
|
|
641
|
+
onClick: x.last,
|
|
642
|
+
style: {
|
|
643
|
+
...v.button,
|
|
644
|
+
...!C.hasNext && v.disabledButton
|
|
645
|
+
},
|
|
646
|
+
children: "Last"
|
|
647
|
+
}
|
|
648
|
+
)
|
|
649
|
+
] });
|
|
650
|
+
}
|
|
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));
|
|
677
|
+
},
|
|
678
|
+
[n]
|
|
679
|
+
), w = g(
|
|
680
|
+
() => ({
|
|
681
|
+
perPage: a,
|
|
682
|
+
setPerPage: n,
|
|
683
|
+
options: y,
|
|
684
|
+
styles: d
|
|
685
|
+
}),
|
|
686
|
+
[a, n, y, d]
|
|
687
|
+
);
|
|
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
|
+
) });
|
|
700
|
+
}
|
|
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(
|
|
728
|
+
() => ({
|
|
729
|
+
isLoading: o,
|
|
730
|
+
refresh: f
|
|
731
|
+
}),
|
|
732
|
+
[o, f, s]
|
|
733
|
+
);
|
|
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);
|
|
758
|
+
};
|
|
759
|
+
I(() => () => {
|
|
760
|
+
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"
|
|
775
|
+
}
|
|
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(
|
|
822
|
+
() => ({
|
|
823
|
+
...y,
|
|
824
|
+
count: t,
|
|
825
|
+
styles: d
|
|
826
|
+
}),
|
|
827
|
+
[y, t, d]
|
|
828
|
+
);
|
|
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: [
|
|
830
|
+
"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,
|
|
836
|
+
" - ",
|
|
837
|
+
y.to
|
|
838
|
+
] }),
|
|
839
|
+
") out of ",
|
|
840
|
+
/* @__PURE__ */ l("span", { style: d.highlight, children: t })
|
|
841
|
+
] }) });
|
|
842
|
+
});
|
|
843
|
+
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
|
|
859
|
+
};
|
|
@@ -0,0 +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"}})});
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@7span/react-list",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A simple and reusable list component for React",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.jsx"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite",
|
|
11
|
+
"build": "vite build",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"preview": "vite preview",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/react-list.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
25
|
+
"vite": "^6.3.1"
|
|
26
|
+
}
|
|
27
|
+
}
|