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