@iyulab/flex-table 0.59.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,223 +0,0 @@
1
- import { n as e } from "./locale-Cfm-vJji.js";
2
- import { i as t, t as n } from "./query-Dw4iO0ir.js";
3
- //#region src/core/source-error.ts
4
- async function r(t) {
5
- let n = await t.text().catch(() => ""), r = {
6
- message: e("requestFailed", { status: t.status }),
7
- status: t.status
8
- };
9
- if (!n) return r;
10
- let a = n;
11
- try {
12
- a = JSON.parse(n);
13
- } catch {}
14
- if (r.body = a, !a || typeof a != "object") return r;
15
- let o = a, s = o.error && typeof o.error == "object" ? o.error : o;
16
- typeof s.message == "string" && s.message ? r.message = s.message : typeof o.message == "string" && o.message && (r.message = o.message), typeof s.code == "string" && s.code && (r.code = s.code);
17
- let c = i(s.details);
18
- return c && (r.details = c), r;
19
- }
20
- function i(e) {
21
- if (!Array.isArray(e)) return;
22
- let t = e.filter((e) => {
23
- if (!e || typeof e != "object") return !1;
24
- let t = e;
25
- return typeof t.code == "string" && typeof t.message == "string";
26
- });
27
- return t.length > 0 ? t : void 0;
28
- }
29
- var a = class extends Error {
30
- constructor(e) {
31
- super(e.message), this.name = "SourceRequestError", this.failure = e;
32
- }
33
- };
34
- function o(t) {
35
- return new a({
36
- message: e("networkFailed"),
37
- cause: t
38
- });
39
- }
40
- function s(e) {
41
- return e instanceof a ? e.failure : e instanceof Error ? { message: e.message } : { message: String(e) };
42
- }
43
- //#endregion
44
- //#region src/odata/source.ts
45
- function c(e, i = {}) {
46
- let c = e, u = i, d = l(i.fixedFilter), f = t({
47
- defaultOrderBy: i.defaultOrderBy,
48
- initialPage: i.initialPage ?? 0,
49
- initialSearch: i.initialSearch ?? "",
50
- initialSort: i.initialSort
51
- }), p = {
52
- data: [],
53
- totalCount: 0,
54
- loading: !0,
55
- error: null,
56
- page: f.page,
57
- pageSize: i.pageSize ?? 20,
58
- sortCriteria: f.sortCriteria,
59
- search: f.search
60
- }, m = x(), h = /* @__PURE__ */ new Set(), g = null, _ = !1, v = null;
61
- function y() {
62
- return u.enabled ?? !0;
63
- }
64
- function b() {
65
- return p.pageSize;
66
- }
67
- function x() {
68
- return {
69
- ...p,
70
- loading: p.loading || !y()
71
- };
72
- }
73
- function S(e) {
74
- p = {
75
- ...p,
76
- ...e
77
- }, C();
78
- }
79
- function C() {
80
- let e = x();
81
- if (!Object.keys(e).every((t) => e[t] === m[t])) {
82
- m = e;
83
- for (let e of [...h]) e();
84
- }
85
- }
86
- function w() {
87
- return JSON.stringify([
88
- c,
89
- u.baseUrl,
90
- b(),
91
- u.defaultOrderBy,
92
- d,
93
- p.page,
94
- p.sortCriteria,
95
- p.search
96
- ]);
97
- }
98
- function T() {
99
- _ || (_ = !0, queueMicrotask(() => {
100
- _ = !1, E();
101
- }));
102
- }
103
- function E() {
104
- if (h.size === 0) return;
105
- if (!y()) {
106
- g?.abort(), g = null, v = null, C();
107
- return;
108
- }
109
- let e = w();
110
- e !== v && (v = e, D());
111
- }
112
- function D() {
113
- g?.abort();
114
- let e = new AbortController();
115
- g = e;
116
- let { page: t, sortCriteria: i, search: l } = p, d = b(), f = u.fetcher ?? fetch, m = u.onUnauthorized;
117
- S({
118
- loading: !0,
119
- error: null
120
- });
121
- let h = n({
122
- page: t,
123
- pageSize: d,
124
- sortCriteria: i,
125
- defaultOrderBy: u.defaultOrderBy,
126
- search: l,
127
- fixedFilter: u.fixedFilter
128
- }), _ = `${u.baseUrl ?? window.location.origin}${c}${h}`, v = async (t) => {
129
- let n;
130
- try {
131
- n = await f(t, { signal: e.signal });
132
- } catch (e) {
133
- throw e?.name === "AbortError" ? e : o(e);
134
- }
135
- if (!n.ok) throw n.status === 401 && m && m(n), new a(await r(n));
136
- return n.json();
137
- };
138
- (async () => {
139
- let e = await v(_), t = [...e.value ?? e], n = new URL(_).origin, r = /* @__PURE__ */ new Set([_]), i = _, a = e["@odata.nextLink"];
140
- for (; typeof a == "string" && a && t.length < d;) {
141
- let e = new URL(a, i);
142
- if (e.origin !== n) throw Error(`OData nextLink points outside the source origin (${e.origin})`);
143
- if (i = e.toString(), r.has(i)) throw Error(`OData nextLink repeats an already-read page (${i})`);
144
- r.add(i);
145
- let o = await v(i);
146
- t.push(...o.value ?? []), a = o["@odata.nextLink"];
147
- }
148
- return {
149
- count: e["@odata.count"],
150
- rows: t
151
- };
152
- })().then(({ count: n, rows: r }) => {
153
- if (e.signal.aborted) return;
154
- let i = n ?? 0, a = i === 0 ? 0 : Math.ceil(i / d) - 1;
155
- t > a ? (S({
156
- data: r,
157
- totalCount: i,
158
- error: null,
159
- page: a
160
- }), T()) : S({
161
- data: r,
162
- totalCount: i,
163
- error: null
164
- });
165
- }).catch((t) => {
166
- e.signal.aborted || t?.name !== "AbortError" && S({
167
- error: s(t),
168
- data: [],
169
- totalCount: 0
170
- });
171
- }).finally(() => {
172
- e.signal.aborted || S({ loading: !1 });
173
- });
174
- }
175
- return {
176
- getState: () => m,
177
- subscribe(e) {
178
- return h.add(e), h.size === 1 && T(), () => {
179
- !h.delete(e) || h.size > 0 || (g?.abort(), g = null, v = null);
180
- };
181
- },
182
- setPage(e) {
183
- S({ page: e }), T();
184
- },
185
- setPageSize(e) {
186
- e !== p.pageSize && (S({
187
- pageSize: e,
188
- page: 0
189
- }), T());
190
- },
191
- setSort(e) {
192
- S({
193
- sortCriteria: e,
194
- page: 0
195
- }), T();
196
- },
197
- setSearch(e) {
198
- S({
199
- search: e,
200
- page: 0
201
- }), T();
202
- },
203
- refresh() {
204
- y() && (v = null, T());
205
- },
206
- update(e, t = {}) {
207
- let n = l(t.fixedFilter), r = n !== d, i = t.pageSize !== void 0 && t.pageSize !== u.pageSize;
208
- c = e, u = t, d = n, r && (p = {
209
- ...p,
210
- page: 0
211
- }), i && t.pageSize !== p.pageSize && (p = {
212
- ...p,
213
- pageSize: t.pageSize,
214
- page: 0
215
- }), C(), T();
216
- }
217
- };
218
- }
219
- function l(e) {
220
- return e ? JSON.stringify(e) : "";
221
- }
222
- //#endregion
223
- export { c as t };