@nice2dev/erp-adapter 1.0.4 → 1.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/finance/useLoanApi.d.ts +185 -0
- package/dist/finance/useLoanApi.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +934 -586
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
class
|
|
1
|
+
import { useState as E, useRef as oe, useCallback as h, useEffect as te, useMemo as de } from "react";
|
|
2
|
+
class Ce {
|
|
3
3
|
constructor(e) {
|
|
4
4
|
this.cfg = typeof e == "string" ? { baseUrl: e } : e;
|
|
5
5
|
}
|
|
@@ -9,8 +9,8 @@ class Ve {
|
|
|
9
9
|
...this.cfg.headers
|
|
10
10
|
};
|
|
11
11
|
if (this.cfg.tokenFactory) {
|
|
12
|
-
const
|
|
13
|
-
a.Authorization = `Bearer ${
|
|
12
|
+
const o = await this.cfg.tokenFactory();
|
|
13
|
+
a.Authorization = `Bearer ${o}`;
|
|
14
14
|
}
|
|
15
15
|
const r = await n(`${this.cfg.baseUrl}${e}`, { ...t, headers: { ...a, ...t == null ? void 0 : t.headers } });
|
|
16
16
|
if (!r.ok) throw new Error(`ERP request failed: ${r.status} ${r.statusText}`);
|
|
@@ -57,191 +57,191 @@ class Ve {
|
|
|
57
57
|
return this.request(`/${e}`, { method: "PATCH", body: JSON.stringify(t) });
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
async function
|
|
60
|
+
async function Ve(u) {
|
|
61
61
|
const e = await import("@microsoft/signalr");
|
|
62
62
|
let t = "disconnected";
|
|
63
|
-
const n = /* @__PURE__ */ new Set(), a = (
|
|
64
|
-
t =
|
|
65
|
-
},
|
|
66
|
-
accessTokenFactory:
|
|
63
|
+
const n = /* @__PURE__ */ new Set(), a = (c) => {
|
|
64
|
+
t = c, n.forEach((g) => g(c));
|
|
65
|
+
}, o = new e.HubConnectionBuilder().withUrl(u.hubUrl, {
|
|
66
|
+
accessTokenFactory: u.accessTokenFactory ? () => u.accessTokenFactory() : void 0
|
|
67
67
|
}).withAutomaticReconnect().build();
|
|
68
|
-
return
|
|
68
|
+
return o.onreconnecting(() => a("reconnecting")), o.onreconnected(() => a("connected")), o.onclose(() => a("disconnected")), {
|
|
69
69
|
get status() {
|
|
70
70
|
return t;
|
|
71
71
|
},
|
|
72
72
|
async start() {
|
|
73
|
-
a("connecting"), await
|
|
73
|
+
a("connecting"), await o.start(), a("connected");
|
|
74
74
|
},
|
|
75
75
|
async stop() {
|
|
76
|
-
await
|
|
76
|
+
await o.stop(), a("disconnected");
|
|
77
77
|
},
|
|
78
|
-
on(
|
|
79
|
-
|
|
78
|
+
on(c, g) {
|
|
79
|
+
o.on(c, g);
|
|
80
80
|
},
|
|
81
|
-
off(
|
|
82
|
-
|
|
81
|
+
off(c, g) {
|
|
82
|
+
o.off(c, g);
|
|
83
83
|
},
|
|
84
|
-
invoke(
|
|
85
|
-
return
|
|
84
|
+
invoke(c, ...g) {
|
|
85
|
+
return o.invoke(c, ...g);
|
|
86
86
|
},
|
|
87
|
-
onStatusChange(
|
|
88
|
-
return n.add(
|
|
87
|
+
onStatusChange(c) {
|
|
88
|
+
return n.add(c), () => n.delete(c);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
function he(
|
|
92
|
+
function he(u) {
|
|
93
93
|
const {
|
|
94
94
|
adapter: e,
|
|
95
95
|
entityName: t,
|
|
96
96
|
keyField: n,
|
|
97
97
|
initialData: a = [],
|
|
98
98
|
onBeforeChange: r,
|
|
99
|
-
onAfterChange:
|
|
100
|
-
onConflict:
|
|
101
|
-
subscribeMethod:
|
|
102
|
-
unsubscribeMethod:
|
|
103
|
-
changeEventName:
|
|
104
|
-
flashChanges:
|
|
99
|
+
onAfterChange: o,
|
|
100
|
+
onConflict: l,
|
|
101
|
+
subscribeMethod: c = "SubscribeToEntity",
|
|
102
|
+
unsubscribeMethod: g = "UnsubscribeFromEntity",
|
|
103
|
+
changeEventName: v = "EntityChanged",
|
|
104
|
+
flashChanges: w = !0,
|
|
105
105
|
flashDuration: V = 500,
|
|
106
|
-
optimisticUpdates:
|
|
107
|
-
} =
|
|
108
|
-
(
|
|
109
|
-
const { operation:
|
|
110
|
-
switch (
|
|
106
|
+
optimisticUpdates: O = !0
|
|
107
|
+
} = u, [Q, N] = E(a), [X, q] = E(e.status), [Z, U] = E(/* @__PURE__ */ new Set()), [K, x] = E(/* @__PURE__ */ new Set()), [Y, ae] = E(null), j = oe(/* @__PURE__ */ new Map()), B = oe(/* @__PURE__ */ new Map()), _ = h(
|
|
108
|
+
(y, k) => {
|
|
109
|
+
const { operation: P, key: C, data: S, changes: I } = k;
|
|
110
|
+
switch (P) {
|
|
111
111
|
case "insert":
|
|
112
|
-
return !
|
|
112
|
+
return !S || y.some((R) => R[n] === C) ? y : [...y, S];
|
|
113
113
|
case "update":
|
|
114
|
-
return
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
119
|
-
{ ...
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
return y.map((R) => {
|
|
115
|
+
if (R[n] !== C) return R;
|
|
116
|
+
const H = j.current.get(C);
|
|
117
|
+
if (H && l) {
|
|
118
|
+
const se = l(
|
|
119
|
+
{ ...R, ...H.changes },
|
|
120
|
+
S ?? { ...R, ...I },
|
|
121
|
+
k
|
|
122
122
|
);
|
|
123
|
-
return
|
|
123
|
+
return se === "local" ? { ...R, ...H.changes } : se === "remote" ? (j.current.delete(C), S ?? { ...R, ...I }) : se === "merge" ? { ...R, ...I, ...H.changes } : se;
|
|
124
124
|
}
|
|
125
|
-
return
|
|
125
|
+
return S || { ...R, ...I };
|
|
126
126
|
});
|
|
127
127
|
case "delete":
|
|
128
|
-
return
|
|
128
|
+
return y.filter((R) => R[n] !== C);
|
|
129
129
|
default:
|
|
130
|
-
return
|
|
130
|
+
return y;
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
|
-
[n,
|
|
134
|
-
),
|
|
135
|
-
(
|
|
136
|
-
if (!
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
U((
|
|
141
|
-
const
|
|
142
|
-
return
|
|
143
|
-
}),
|
|
133
|
+
[n, l]
|
|
134
|
+
), L = h(
|
|
135
|
+
(y) => {
|
|
136
|
+
if (!w) return;
|
|
137
|
+
const k = B.current.get(y);
|
|
138
|
+
k && clearTimeout(k), U((C) => /* @__PURE__ */ new Set([...C, y]));
|
|
139
|
+
const P = setTimeout(() => {
|
|
140
|
+
U((C) => {
|
|
141
|
+
const S = new Set(C);
|
|
142
|
+
return S.delete(y), S;
|
|
143
|
+
}), B.current.delete(y);
|
|
144
144
|
}, V);
|
|
145
|
-
|
|
145
|
+
B.current.set(y, P);
|
|
146
146
|
},
|
|
147
|
-
[
|
|
148
|
-
),
|
|
149
|
-
async (
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
return
|
|
153
|
-
}),
|
|
147
|
+
[w, V]
|
|
148
|
+
), z = h(
|
|
149
|
+
async (y) => {
|
|
150
|
+
y.entityName === t && (r && !await r(y) || (N((k) => {
|
|
151
|
+
const P = _(k, y);
|
|
152
|
+
return o == null || o(y, P), P;
|
|
153
|
+
}), L(y.key)));
|
|
154
154
|
},
|
|
155
|
-
[t, r,
|
|
156
|
-
),
|
|
157
|
-
(
|
|
158
|
-
|
|
155
|
+
[t, r, _, o, L]
|
|
156
|
+
), p = h(
|
|
157
|
+
(y) => {
|
|
158
|
+
z(y);
|
|
159
159
|
},
|
|
160
|
-
[
|
|
161
|
-
),
|
|
162
|
-
(
|
|
163
|
-
if (!
|
|
164
|
-
const
|
|
165
|
-
|
|
160
|
+
[z]
|
|
161
|
+
), le = h(
|
|
162
|
+
(y, k) => {
|
|
163
|
+
if (!O) return;
|
|
164
|
+
const P = Q.find((C) => C[n] === y);
|
|
165
|
+
P && (j.current.set(y, { original: P, changes: k }), x((C) => /* @__PURE__ */ new Set([...C, y])));
|
|
166
166
|
},
|
|
167
|
-
[
|
|
168
|
-
),
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
return
|
|
167
|
+
[Q, n, O]
|
|
168
|
+
), J = h((y) => {
|
|
169
|
+
j.current.delete(y), x((k) => {
|
|
170
|
+
const P = new Set(k);
|
|
171
|
+
return P.delete(y), P;
|
|
172
172
|
});
|
|
173
|
-
}, []), F =
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
(
|
|
177
|
-
(
|
|
173
|
+
}, []), F = h((y) => {
|
|
174
|
+
const k = j.current.get(y);
|
|
175
|
+
k && (N(
|
|
176
|
+
(P) => P.map(
|
|
177
|
+
(C) => C[n] === y ? k.original : C
|
|
178
178
|
)
|
|
179
|
-
),
|
|
180
|
-
const
|
|
181
|
-
return
|
|
179
|
+
), j.current.delete(y), x((P) => {
|
|
180
|
+
const C = new Set(P);
|
|
181
|
+
return C.delete(y), C;
|
|
182
182
|
}));
|
|
183
|
-
}, [n]),
|
|
183
|
+
}, [n]), ne = h(async () => {
|
|
184
184
|
if (e.status === "connected")
|
|
185
185
|
try {
|
|
186
|
-
await e.invoke(
|
|
187
|
-
} catch (
|
|
188
|
-
|
|
186
|
+
await e.invoke(c, t), ae(null);
|
|
187
|
+
} catch (y) {
|
|
188
|
+
ae(y instanceof Error ? y : new Error(String(y)));
|
|
189
189
|
}
|
|
190
|
-
}, [e,
|
|
190
|
+
}, [e, c, t]), re = h(async () => {
|
|
191
191
|
if (e.status === "connected")
|
|
192
192
|
try {
|
|
193
|
-
await e.invoke(
|
|
193
|
+
await e.invoke(g, t);
|
|
194
194
|
} catch {
|
|
195
195
|
}
|
|
196
|
-
}, [e,
|
|
197
|
-
return
|
|
198
|
-
const
|
|
199
|
-
|
|
196
|
+
}, [e, g, t]);
|
|
197
|
+
return te(() => {
|
|
198
|
+
const y = e.onStatusChange((k) => {
|
|
199
|
+
q(k), k === "connected" && ne();
|
|
200
200
|
});
|
|
201
|
-
return e.on(
|
|
202
|
-
|
|
201
|
+
return e.on(v, z), e.status === "connected" && ne(), () => {
|
|
202
|
+
y(), e.off(v, z), re(), B.current.forEach((k) => clearTimeout(k)), B.current.clear();
|
|
203
203
|
};
|
|
204
|
-
}, [e,
|
|
205
|
-
|
|
204
|
+
}, [e, v, z, ne, re]), te(() => {
|
|
205
|
+
N(a);
|
|
206
206
|
}, [a]), {
|
|
207
|
-
data:
|
|
208
|
-
status:
|
|
209
|
-
flashedKeys:
|
|
210
|
-
pendingKeys:
|
|
211
|
-
error:
|
|
212
|
-
applyRemoteUpdate:
|
|
213
|
-
registerPendingChange:
|
|
214
|
-
confirmPendingChange:
|
|
207
|
+
data: Q,
|
|
208
|
+
status: X,
|
|
209
|
+
flashedKeys: Z,
|
|
210
|
+
pendingKeys: K,
|
|
211
|
+
error: Y,
|
|
212
|
+
applyRemoteUpdate: p,
|
|
213
|
+
registerPendingChange: le,
|
|
214
|
+
confirmPendingChange: J,
|
|
215
215
|
rollbackPendingChange: F,
|
|
216
|
-
resubscribe:
|
|
216
|
+
resubscribe: ne
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
function Pe(
|
|
219
|
+
function Pe(u) {
|
|
220
220
|
const {
|
|
221
221
|
adapter: e,
|
|
222
222
|
entityName: t,
|
|
223
223
|
keyField: n,
|
|
224
224
|
fetchMethod: a = "GetEntities",
|
|
225
225
|
insertMethod: r = "InsertEntity",
|
|
226
|
-
updateMethod:
|
|
227
|
-
deleteMethod:
|
|
228
|
-
} =
|
|
226
|
+
updateMethod: o = "UpdateEntity",
|
|
227
|
+
deleteMethod: l = "DeleteEntity"
|
|
228
|
+
} = u;
|
|
229
229
|
return {
|
|
230
230
|
/** Fetch all entities from the hub. */
|
|
231
|
-
async fetchAll(
|
|
232
|
-
return e.invoke(a, t,
|
|
231
|
+
async fetchAll(c) {
|
|
232
|
+
return e.invoke(a, t, c);
|
|
233
233
|
},
|
|
234
234
|
/** Insert a new entity via the hub. */
|
|
235
|
-
async insert(
|
|
236
|
-
return e.invoke(r, t,
|
|
235
|
+
async insert(c) {
|
|
236
|
+
return e.invoke(r, t, c);
|
|
237
237
|
},
|
|
238
238
|
/** Update an existing entity via the hub. */
|
|
239
|
-
async update(
|
|
240
|
-
return e.invoke(
|
|
239
|
+
async update(c, g) {
|
|
240
|
+
return e.invoke(o, t, c, g);
|
|
241
241
|
},
|
|
242
242
|
/** Delete an entity via the hub. */
|
|
243
|
-
async remove(
|
|
244
|
-
return e.invoke(
|
|
243
|
+
async remove(c) {
|
|
244
|
+
return e.invoke(l, t, c);
|
|
245
245
|
},
|
|
246
246
|
/** Get the key field name. */
|
|
247
247
|
getKeyField() {
|
|
@@ -249,8 +249,8 @@ function Pe(i) {
|
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
function
|
|
253
|
-
const n = new Map(
|
|
252
|
+
function Ae(u, e, t) {
|
|
253
|
+
const n = new Map(u.map((a) => [a[t], a]));
|
|
254
254
|
for (const a of e)
|
|
255
255
|
switch (a.operation) {
|
|
256
256
|
case "insert":
|
|
@@ -271,182 +271,182 @@ function Te(i, e, t) {
|
|
|
271
271
|
}
|
|
272
272
|
return Array.from(n.values());
|
|
273
273
|
}
|
|
274
|
-
function pe(
|
|
274
|
+
function pe(u) {
|
|
275
275
|
const {
|
|
276
276
|
adapter: e,
|
|
277
277
|
entityType: t,
|
|
278
278
|
entityId: n,
|
|
279
279
|
currentUser: a,
|
|
280
280
|
initialStatus: r = "viewing",
|
|
281
|
-
heartbeatInterval:
|
|
282
|
-
idleTimeout:
|
|
283
|
-
awayTimeout:
|
|
284
|
-
joinMethod:
|
|
285
|
-
leaveMethod:
|
|
286
|
-
updateMethod:
|
|
281
|
+
heartbeatInterval: o = 3e4,
|
|
282
|
+
idleTimeout: l = 6e4,
|
|
283
|
+
awayTimeout: c = 3e5,
|
|
284
|
+
joinMethod: g = "JoinEntityView",
|
|
285
|
+
leaveMethod: v = "LeaveEntityView",
|
|
286
|
+
updateMethod: w = "UpdateEntityPresence",
|
|
287
287
|
presenceEventName: V = "EntityPresenceChanged",
|
|
288
|
-
joinedEventName:
|
|
289
|
-
leftEventName:
|
|
290
|
-
onPresenceChange:
|
|
291
|
-
onEditConflict:
|
|
292
|
-
} =
|
|
293
|
-
async (
|
|
288
|
+
joinedEventName: O = "EntityUserJoined",
|
|
289
|
+
leftEventName: Q = "EntityUserLeft",
|
|
290
|
+
onPresenceChange: N,
|
|
291
|
+
onEditConflict: X
|
|
292
|
+
} = u, [q, Z] = E([]), [U, K] = E(r), [x, Y] = E(), [ae, j] = E(e.status), B = oe(Date.now()), _ = oe(null), L = oe(null), z = oe(null), p = Array.isArray(n) ? n : [n], le = `${t}:${p.sort().join(",")}`, J = h(
|
|
293
|
+
async (m, T, s) => {
|
|
294
294
|
if (e.status === "connected")
|
|
295
295
|
try {
|
|
296
|
-
await e.invoke(
|
|
296
|
+
await e.invoke(w, {
|
|
297
297
|
entityType: t,
|
|
298
|
-
entityIds:
|
|
298
|
+
entityIds: p,
|
|
299
299
|
userId: a.id,
|
|
300
|
-
status:
|
|
301
|
-
editingField:
|
|
302
|
-
selection:
|
|
300
|
+
status: m,
|
|
301
|
+
editingField: T,
|
|
302
|
+
selection: s,
|
|
303
303
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
304
304
|
});
|
|
305
305
|
} catch {
|
|
306
306
|
}
|
|
307
307
|
},
|
|
308
|
-
[e,
|
|
309
|
-
), F =
|
|
310
|
-
(
|
|
311
|
-
|
|
308
|
+
[e, w, t, p, a.id]
|
|
309
|
+
), F = h(
|
|
310
|
+
(m, T) => {
|
|
311
|
+
K(m), Y(T), J(m, T), B.current = Date.now();
|
|
312
312
|
},
|
|
313
|
-
[
|
|
314
|
-
),
|
|
315
|
-
(
|
|
316
|
-
const
|
|
317
|
-
(
|
|
313
|
+
[J]
|
|
314
|
+
), ne = h(
|
|
315
|
+
(m) => {
|
|
316
|
+
const T = q.find(
|
|
317
|
+
(s) => s.user.id !== a.id && s.status === "editing" && s.editingField === m
|
|
318
318
|
);
|
|
319
|
-
|
|
319
|
+
T && (X == null || X(T.user, m)), F("editing", m);
|
|
320
320
|
},
|
|
321
|
-
[
|
|
322
|
-
),
|
|
321
|
+
[q, a.id, X, F]
|
|
322
|
+
), re = h(() => {
|
|
323
323
|
F("viewing", void 0);
|
|
324
|
-
}, [F]),
|
|
325
|
-
(
|
|
326
|
-
|
|
324
|
+
}, [F]), y = h(
|
|
325
|
+
(m) => {
|
|
326
|
+
J(U, x, m), B.current = Date.now();
|
|
327
327
|
},
|
|
328
|
-
[
|
|
329
|
-
),
|
|
330
|
-
(
|
|
331
|
-
const
|
|
332
|
-
(
|
|
328
|
+
[J, U, x]
|
|
329
|
+
), k = h(
|
|
330
|
+
(m) => {
|
|
331
|
+
const T = q.find(
|
|
332
|
+
(s) => s.user.id !== a.id && s.status === "editing" && s.editingField === m
|
|
333
333
|
);
|
|
334
|
-
return (
|
|
334
|
+
return (T == null ? void 0 : T.user) ?? null;
|
|
335
335
|
},
|
|
336
|
-
[
|
|
337
|
-
),
|
|
338
|
-
(
|
|
339
|
-
const
|
|
340
|
-
return (
|
|
336
|
+
[q, a.id]
|
|
337
|
+
), P = h(
|
|
338
|
+
(m) => {
|
|
339
|
+
const T = q.find((s) => s.status === "editing" && s.editingField === m);
|
|
340
|
+
return (T == null ? void 0 : T.user) ?? null;
|
|
341
341
|
},
|
|
342
|
-
[
|
|
343
|
-
),
|
|
342
|
+
[q]
|
|
343
|
+
), C = h(async () => {
|
|
344
344
|
if (e.status === "connected")
|
|
345
345
|
try {
|
|
346
|
-
const
|
|
347
|
-
Array.isArray(
|
|
346
|
+
const m = await e.invoke("GetEntityPresence", t, p);
|
|
347
|
+
Array.isArray(m) && (Z(m), N == null || N(m));
|
|
348
348
|
} catch {
|
|
349
349
|
}
|
|
350
|
-
}, [e, t,
|
|
351
|
-
|
|
352
|
-
F("idle",
|
|
353
|
-
},
|
|
354
|
-
F("away",
|
|
355
|
-
},
|
|
356
|
-
}, [U,
|
|
357
|
-
(
|
|
358
|
-
|
|
350
|
+
}, [e, t, p, N]), S = h(() => {
|
|
351
|
+
B.current = Date.now(), L.current && clearTimeout(L.current), z.current && clearTimeout(z.current), (U === "idle" || U === "away") && F(x ? "editing" : "viewing", x), L.current = setTimeout(() => {
|
|
352
|
+
F("idle", x);
|
|
353
|
+
}, l), z.current = setTimeout(() => {
|
|
354
|
+
F("away", x);
|
|
355
|
+
}, c);
|
|
356
|
+
}, [U, x, l, c, F]), I = h(
|
|
357
|
+
(m) => {
|
|
358
|
+
m.entityType !== t || !m.entityIds.some((s) => p.includes(s)) || (Z(m.presence.filter((s) => s.user.id !== a.id)), N == null || N(m.presence));
|
|
359
359
|
},
|
|
360
|
-
[t,
|
|
361
|
-
),
|
|
362
|
-
(
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
if (
|
|
366
|
-
const
|
|
367
|
-
return
|
|
360
|
+
[t, p, a.id, N]
|
|
361
|
+
), R = h(
|
|
362
|
+
(m) => {
|
|
363
|
+
m.entityType !== t || !m.entityIds.some((s) => p.includes(s)) || m.presence.user.id === a.id || Z((s) => {
|
|
364
|
+
const b = s.findIndex(($) => $.user.id === m.presence.user.id);
|
|
365
|
+
if (b >= 0) {
|
|
366
|
+
const $ = [...s];
|
|
367
|
+
return $[b] = m.presence, $;
|
|
368
368
|
}
|
|
369
|
-
return [...
|
|
369
|
+
return [...s, m.presence];
|
|
370
370
|
});
|
|
371
371
|
},
|
|
372
|
-
[t,
|
|
373
|
-
),
|
|
374
|
-
(
|
|
375
|
-
|
|
372
|
+
[t, p, a.id]
|
|
373
|
+
), H = h(
|
|
374
|
+
(m) => {
|
|
375
|
+
m.entityType !== t || !m.entityIds.some((s) => p.includes(s)) || Z((s) => s.filter((b) => b.user.id !== m.userId));
|
|
376
376
|
},
|
|
377
|
-
[t,
|
|
377
|
+
[t, p]
|
|
378
378
|
);
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
e.on(V,
|
|
382
|
-
const
|
|
379
|
+
te(() => {
|
|
380
|
+
const m = e.onStatusChange(j);
|
|
381
|
+
e.on(V, I), e.on(O, R), e.on(Q, H);
|
|
382
|
+
const T = async () => {
|
|
383
383
|
if (e.status === "connected")
|
|
384
384
|
try {
|
|
385
|
-
await e.invoke(
|
|
385
|
+
await e.invoke(g, {
|
|
386
386
|
entityType: t,
|
|
387
|
-
entityIds:
|
|
387
|
+
entityIds: p,
|
|
388
388
|
user: a,
|
|
389
389
|
status: U
|
|
390
|
-
}), await
|
|
390
|
+
}), await C();
|
|
391
391
|
} catch {
|
|
392
392
|
}
|
|
393
393
|
};
|
|
394
|
-
return e.status === "connected" &&
|
|
395
|
-
|
|
394
|
+
return e.status === "connected" && T(), () => {
|
|
395
|
+
m(), e.off(V, I), e.off(O, R), e.off(Q, H), e.status === "connected" && e.invoke(v, {
|
|
396
396
|
entityType: t,
|
|
397
|
-
entityIds:
|
|
397
|
+
entityIds: p,
|
|
398
398
|
userId: a.id
|
|
399
399
|
}).catch(() => {
|
|
400
400
|
});
|
|
401
401
|
};
|
|
402
402
|
}, [
|
|
403
403
|
e,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
404
|
+
le,
|
|
405
|
+
g,
|
|
406
|
+
v,
|
|
407
407
|
V,
|
|
408
|
+
O,
|
|
409
|
+
Q,
|
|
410
|
+
I,
|
|
411
|
+
R,
|
|
412
|
+
H,
|
|
408
413
|
C,
|
|
409
|
-
q,
|
|
410
|
-
N,
|
|
411
|
-
A,
|
|
412
|
-
K,
|
|
413
|
-
S,
|
|
414
414
|
a,
|
|
415
415
|
U,
|
|
416
416
|
t,
|
|
417
|
-
|
|
418
|
-
]),
|
|
419
|
-
|
|
420
|
-
},
|
|
421
|
-
|
|
422
|
-
}), [
|
|
423
|
-
const
|
|
424
|
-
return
|
|
425
|
-
F("idle",
|
|
426
|
-
},
|
|
427
|
-
F("away",
|
|
428
|
-
},
|
|
429
|
-
|
|
417
|
+
p
|
|
418
|
+
]), te(() => (_.current = setInterval(() => {
|
|
419
|
+
J(U, x);
|
|
420
|
+
}, o), () => {
|
|
421
|
+
_.current && clearInterval(_.current);
|
|
422
|
+
}), [o, J, U, x]), te(() => {
|
|
423
|
+
const m = ["mousemove", "keydown", "mousedown", "touchstart", "scroll"];
|
|
424
|
+
return m.forEach((T) => window.addEventListener(T, S, { passive: !0 })), L.current = setTimeout(() => {
|
|
425
|
+
F("idle", x);
|
|
426
|
+
}, l), z.current = setTimeout(() => {
|
|
427
|
+
F("away", x);
|
|
428
|
+
}, c), () => {
|
|
429
|
+
m.forEach((T) => window.removeEventListener(T, S)), L.current && clearTimeout(L.current), z.current && clearTimeout(z.current);
|
|
430
430
|
};
|
|
431
|
-
}, [
|
|
432
|
-
const
|
|
431
|
+
}, [S, l, c, x, F]);
|
|
432
|
+
const se = q.filter((m) => m.status === "viewing" || m.status === "idle").map((m) => m.user), ie = q.filter((m) => m.status === "editing").map((m) => m.user), ue = ie.length > 0;
|
|
433
433
|
return {
|
|
434
|
-
presence:
|
|
435
|
-
viewers:
|
|
436
|
-
editors:
|
|
434
|
+
presence: q,
|
|
435
|
+
viewers: se,
|
|
436
|
+
editors: ie,
|
|
437
437
|
myStatus: U,
|
|
438
438
|
setMyStatus: F,
|
|
439
|
-
startEditing:
|
|
440
|
-
stopEditing:
|
|
441
|
-
updateSelection:
|
|
442
|
-
connectionStatus:
|
|
443
|
-
isFieldLocked:
|
|
439
|
+
startEditing: ne,
|
|
440
|
+
stopEditing: re,
|
|
441
|
+
updateSelection: y,
|
|
442
|
+
connectionStatus: ae,
|
|
443
|
+
isFieldLocked: k,
|
|
444
444
|
hasActiveEditors: ue,
|
|
445
|
-
getFieldEditor:
|
|
446
|
-
refresh:
|
|
445
|
+
getFieldEditor: P,
|
|
446
|
+
refresh: C
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
|
-
function
|
|
449
|
+
function me(u) {
|
|
450
450
|
const e = [
|
|
451
451
|
"#3b82f6",
|
|
452
452
|
// blue
|
|
@@ -470,12 +470,12 @@ function fe(i) {
|
|
|
470
470
|
// teal
|
|
471
471
|
];
|
|
472
472
|
let t = 0;
|
|
473
|
-
for (let n = 0; n <
|
|
474
|
-
t =
|
|
473
|
+
for (let n = 0; n < u.length; n++)
|
|
474
|
+
t = u.charCodeAt(n) + ((t << 5) - t);
|
|
475
475
|
return e[Math.abs(t) % e.length];
|
|
476
476
|
}
|
|
477
|
-
function
|
|
478
|
-
switch (
|
|
477
|
+
function Oe(u) {
|
|
478
|
+
switch (u) {
|
|
479
479
|
case "viewing":
|
|
480
480
|
return "Viewing";
|
|
481
481
|
case "editing":
|
|
@@ -488,94 +488,94 @@ function xe(i) {
|
|
|
488
488
|
return "Unknown";
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
function
|
|
491
|
+
function xe(u) {
|
|
492
492
|
const {
|
|
493
493
|
adapter: e,
|
|
494
494
|
entityType: t,
|
|
495
495
|
currentUser: n,
|
|
496
496
|
batchEventName: a = "BatchPresenceUpdate"
|
|
497
|
-
} =
|
|
498
|
-
(
|
|
499
|
-
|
|
497
|
+
} = u, [r, o] = E(/* @__PURE__ */ new Map()), l = h(
|
|
498
|
+
(w) => {
|
|
499
|
+
w.entityType === t && o(new Map(Object.entries(w.presenceByEntity)));
|
|
500
500
|
},
|
|
501
501
|
[t]
|
|
502
502
|
);
|
|
503
|
-
|
|
504
|
-
e.off(a,
|
|
505
|
-
}), [e, a,
|
|
506
|
-
const
|
|
507
|
-
(
|
|
503
|
+
te(() => (e.on(a, l), () => {
|
|
504
|
+
e.off(a, l);
|
|
505
|
+
}), [e, a, l]);
|
|
506
|
+
const c = h(
|
|
507
|
+
(w) => r.get(w) ?? [],
|
|
508
508
|
[r]
|
|
509
|
-
),
|
|
510
|
-
(
|
|
511
|
-
const V = r.get(
|
|
512
|
-
return (V == null ? void 0 : V.some((
|
|
509
|
+
), g = h(
|
|
510
|
+
(w) => {
|
|
511
|
+
const V = r.get(w);
|
|
512
|
+
return (V == null ? void 0 : V.some((O) => O.status === "editing" && O.user.id !== n.id)) ?? !1;
|
|
513
513
|
},
|
|
514
514
|
[r, n.id]
|
|
515
|
-
),
|
|
516
|
-
(
|
|
517
|
-
const V = r.get(
|
|
518
|
-
return (V == null ? void 0 : V.filter((
|
|
515
|
+
), v = h(
|
|
516
|
+
(w) => {
|
|
517
|
+
const V = r.get(w);
|
|
518
|
+
return (V == null ? void 0 : V.filter((O) => O.status === "editing").map((O) => O.user)) ?? [];
|
|
519
519
|
},
|
|
520
520
|
[r]
|
|
521
521
|
);
|
|
522
522
|
return {
|
|
523
523
|
presenceByEntity: r,
|
|
524
|
-
getPresence:
|
|
525
|
-
isEntityBeingEdited:
|
|
526
|
-
getEntityEditors:
|
|
524
|
+
getPresence: c,
|
|
525
|
+
isEntityBeingEdited: g,
|
|
526
|
+
getEntityEditors: v
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
|
-
function
|
|
530
|
-
return `${String(
|
|
529
|
+
function G(u) {
|
|
530
|
+
return `${String(u.rowKey)}:${u.field}`;
|
|
531
531
|
}
|
|
532
|
-
function
|
|
533
|
-
return
|
|
532
|
+
function fe(u) {
|
|
533
|
+
return u ? typeof u == "number" ? u : new Date(u).getTime() : Date.now();
|
|
534
534
|
}
|
|
535
|
-
function
|
|
535
|
+
function Le(u) {
|
|
536
536
|
const {
|
|
537
537
|
adapter: e,
|
|
538
538
|
entityType: t,
|
|
539
539
|
keyField: n,
|
|
540
540
|
currentUser: a,
|
|
541
541
|
initialData: r = [],
|
|
542
|
-
conflictStrategy:
|
|
543
|
-
mergeFunction:
|
|
544
|
-
onConflict:
|
|
545
|
-
onBeforeCommit:
|
|
546
|
-
onAfterCommit:
|
|
547
|
-
enableCellLocking:
|
|
542
|
+
conflictStrategy: o = "last-write-wins",
|
|
543
|
+
mergeFunction: l,
|
|
544
|
+
onConflict: c,
|
|
545
|
+
onBeforeCommit: g,
|
|
546
|
+
onAfterCommit: v,
|
|
547
|
+
enableCellLocking: w = !0,
|
|
548
548
|
lockTimeout: V = 6e4,
|
|
549
|
-
enableCursorSharing:
|
|
550
|
-
cursorDebounce:
|
|
551
|
-
optimisticUpdates:
|
|
552
|
-
flashChanges:
|
|
553
|
-
flashDuration:
|
|
554
|
-
liveDataOptions:
|
|
555
|
-
} =
|
|
556
|
-
(
|
|
557
|
-
if (!
|
|
558
|
-
const
|
|
559
|
-
if (!
|
|
560
|
-
const
|
|
561
|
-
switch (
|
|
549
|
+
enableCursorSharing: O = !0,
|
|
550
|
+
cursorDebounce: Q = 50,
|
|
551
|
+
optimisticUpdates: N = !0,
|
|
552
|
+
flashChanges: X = !0,
|
|
553
|
+
flashDuration: q = 500,
|
|
554
|
+
liveDataOptions: Z = {}
|
|
555
|
+
} = u, [U, K] = E(/* @__PURE__ */ new Map()), [x, Y] = E(/* @__PURE__ */ new Map()), [ae, j] = E([]), [B, _] = E(null), [L, z] = E([]), [p, le] = E([]), [J, F] = E(null), [ne, re] = E([]), y = oe(null), k = oe(/* @__PURE__ */ new Map()), P = h((i) => (k.current.has(i) || k.current.set(i, me(i)), k.current.get(i)), []), C = h(
|
|
556
|
+
(i, f, d) => {
|
|
557
|
+
if (!d.changes) return f;
|
|
558
|
+
const A = x.get(G({ rowKey: d.key, field: Object.keys(d.changes)[0] }));
|
|
559
|
+
if (!A) return f;
|
|
560
|
+
const M = A.timestamp, D = fe(d.timestamp);
|
|
561
|
+
switch (o) {
|
|
562
562
|
case "last-write-wins":
|
|
563
|
-
return
|
|
563
|
+
return M > D ? "local" : "remote";
|
|
564
564
|
case "first-write-wins":
|
|
565
|
-
return
|
|
565
|
+
return M < D ? "local" : "remote";
|
|
566
566
|
case "merge":
|
|
567
|
-
return
|
|
567
|
+
return l ? l(i, f, Object.keys(d.changes)[0]) : "merge";
|
|
568
568
|
case "ask-user":
|
|
569
|
-
const
|
|
570
|
-
cell: { rowKey:
|
|
571
|
-
localValue:
|
|
572
|
-
remoteValue:
|
|
569
|
+
const W = {
|
|
570
|
+
cell: { rowKey: d.key, field: Object.keys(d.changes)[0] },
|
|
571
|
+
localValue: A.newValue,
|
|
572
|
+
remoteValue: d.changes[Object.keys(d.changes)[0]],
|
|
573
573
|
localUser: a,
|
|
574
|
-
remoteUser:
|
|
575
|
-
localTimestamp:
|
|
576
|
-
remoteTimestamp:
|
|
574
|
+
remoteUser: d.changedBy ? { id: d.changedBy, name: d.changedBy } : { id: "unknown", name: "Unknown" },
|
|
575
|
+
localTimestamp: M,
|
|
576
|
+
remoteTimestamp: D
|
|
577
577
|
};
|
|
578
|
-
return
|
|
578
|
+
return j((ce) => [...ce, W]), "local";
|
|
579
579
|
// Keep local until resolved
|
|
580
580
|
case "reject":
|
|
581
581
|
return "remote";
|
|
@@ -583,253 +583,253 @@ function De(i) {
|
|
|
583
583
|
return "remote";
|
|
584
584
|
}
|
|
585
585
|
},
|
|
586
|
-
[
|
|
587
|
-
),
|
|
586
|
+
[x, o, l, a]
|
|
587
|
+
), S = he({
|
|
588
588
|
adapter: e,
|
|
589
589
|
entityName: t,
|
|
590
590
|
keyField: n,
|
|
591
591
|
initialData: r,
|
|
592
|
-
flashChanges:
|
|
593
|
-
flashDuration:
|
|
594
|
-
optimisticUpdates:
|
|
595
|
-
onConflict:
|
|
596
|
-
...
|
|
597
|
-
}),
|
|
592
|
+
flashChanges: X,
|
|
593
|
+
flashDuration: q,
|
|
594
|
+
optimisticUpdates: N,
|
|
595
|
+
onConflict: C,
|
|
596
|
+
...Z
|
|
597
|
+
}), I = pe({
|
|
598
598
|
adapter: e,
|
|
599
599
|
entityType: t,
|
|
600
600
|
entityId: "grid",
|
|
601
601
|
// Special ID for grid-level presence
|
|
602
602
|
currentUser: a,
|
|
603
603
|
initialStatus: "viewing"
|
|
604
|
-
}),
|
|
605
|
-
!
|
|
604
|
+
}), R = h(() => {
|
|
605
|
+
!O || e.status !== "connected" || e.invoke("UpdateGridSelection", {
|
|
606
606
|
entityType: t,
|
|
607
607
|
userId: a.id,
|
|
608
|
-
focusedCell:
|
|
609
|
-
selectedCells:
|
|
610
|
-
selectedRows:
|
|
611
|
-
editingCell:
|
|
608
|
+
focusedCell: B,
|
|
609
|
+
selectedCells: L,
|
|
610
|
+
selectedRows: p,
|
|
611
|
+
editingCell: J
|
|
612
612
|
}).catch(() => {
|
|
613
613
|
});
|
|
614
|
-
}, [e,
|
|
615
|
-
|
|
616
|
-
if (
|
|
617
|
-
return
|
|
618
|
-
|
|
614
|
+
}, [e, O, t, a.id, B, L, p, J]);
|
|
615
|
+
te(() => {
|
|
616
|
+
if (O)
|
|
617
|
+
return y.current && clearTimeout(y.current), y.current = setTimeout(R, Q), () => {
|
|
618
|
+
y.current && clearTimeout(y.current);
|
|
619
619
|
};
|
|
620
|
-
}, [
|
|
621
|
-
if (!
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
user: { id:
|
|
626
|
-
focusedCell:
|
|
627
|
-
selectedCells:
|
|
628
|
-
selectedRows:
|
|
629
|
-
editingCell:
|
|
630
|
-
color:
|
|
620
|
+
}, [O, R, Q, B, L, p, J]), te(() => {
|
|
621
|
+
if (!O) return;
|
|
622
|
+
const i = (f) => {
|
|
623
|
+
f.entityType !== t || f.userId === a.id || re((d) => {
|
|
624
|
+
const A = d.findIndex((D) => D.user.id === f.userId), M = {
|
|
625
|
+
user: { id: f.userId, name: f.userName, avatarUrl: f.avatarUrl },
|
|
626
|
+
focusedCell: f.focusedCell,
|
|
627
|
+
selectedCells: f.selectedCells,
|
|
628
|
+
selectedRows: f.selectedRows,
|
|
629
|
+
editingCell: f.editingCell,
|
|
630
|
+
color: P(f.userId)
|
|
631
631
|
};
|
|
632
|
-
if (
|
|
633
|
-
const
|
|
634
|
-
return
|
|
632
|
+
if (A >= 0) {
|
|
633
|
+
const D = [...d];
|
|
634
|
+
return D[A] = M, D;
|
|
635
635
|
}
|
|
636
|
-
return [...
|
|
636
|
+
return [...d, M];
|
|
637
637
|
});
|
|
638
638
|
};
|
|
639
|
-
return e.on("GridSelectionUpdated",
|
|
640
|
-
e.off("GridSelectionUpdated",
|
|
639
|
+
return e.on("GridSelectionUpdated", i), () => {
|
|
640
|
+
e.off("GridSelectionUpdated", i);
|
|
641
641
|
};
|
|
642
|
-
}, [e,
|
|
643
|
-
if (!
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
return
|
|
642
|
+
}, [e, O, t, a.id, P]), te(() => {
|
|
643
|
+
if (!w) return;
|
|
644
|
+
const i = (d) => {
|
|
645
|
+
d.entityType === t && K((A) => {
|
|
646
|
+
const M = new Map(A);
|
|
647
|
+
return M.set(G(d.cell), { user: d.user, timestamp: d.timestamp }), M;
|
|
648
648
|
});
|
|
649
|
-
},
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
return
|
|
649
|
+
}, f = (d) => {
|
|
650
|
+
d.entityType === t && K((A) => {
|
|
651
|
+
const M = new Map(A);
|
|
652
|
+
return M.delete(G(d.cell)), M;
|
|
653
653
|
});
|
|
654
654
|
};
|
|
655
|
-
return e.on("CellLocked",
|
|
656
|
-
e.off("CellLocked",
|
|
655
|
+
return e.on("CellLocked", i), e.on("CellUnlocked", f), () => {
|
|
656
|
+
e.off("CellLocked", i), e.off("CellUnlocked", f);
|
|
657
657
|
};
|
|
658
|
-
}, [e,
|
|
659
|
-
if (!
|
|
660
|
-
const
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
const
|
|
664
|
-
let
|
|
665
|
-
for (const [
|
|
666
|
-
|
|
667
|
-
return
|
|
658
|
+
}, [e, w, t]), te(() => {
|
|
659
|
+
if (!w) return;
|
|
660
|
+
const i = setInterval(() => {
|
|
661
|
+
const f = Date.now();
|
|
662
|
+
K((d) => {
|
|
663
|
+
const A = new Map(d);
|
|
664
|
+
let M = !1;
|
|
665
|
+
for (const [D, W] of A)
|
|
666
|
+
f - W.timestamp > V && (A.delete(D), M = !0);
|
|
667
|
+
return M ? A : d;
|
|
668
668
|
});
|
|
669
669
|
}, 1e4);
|
|
670
|
-
return () => clearInterval(
|
|
671
|
-
}, [
|
|
672
|
-
const
|
|
673
|
-
(
|
|
674
|
-
if (!
|
|
675
|
-
const
|
|
676
|
-
return
|
|
670
|
+
return () => clearInterval(i);
|
|
671
|
+
}, [w, V]);
|
|
672
|
+
const H = h(
|
|
673
|
+
(i) => {
|
|
674
|
+
if (!w) return !1;
|
|
675
|
+
const f = U.get(G(i));
|
|
676
|
+
return f ? f.user.id !== a.id && Date.now() - f.timestamp < V : !1;
|
|
677
677
|
},
|
|
678
|
-
[
|
|
679
|
-
),
|
|
680
|
-
(
|
|
681
|
-
const
|
|
682
|
-
return !
|
|
678
|
+
[w, U, a.id, V]
|
|
679
|
+
), se = h(
|
|
680
|
+
(i) => {
|
|
681
|
+
const f = U.get(G(i));
|
|
682
|
+
return !f || Date.now() - f.timestamp > V ? null : f.user;
|
|
683
683
|
},
|
|
684
684
|
[U, V]
|
|
685
|
-
),
|
|
686
|
-
(
|
|
685
|
+
), ie = h(
|
|
686
|
+
(i) => H(i) ? !1 : (F(i), I.startEditing(`${i.rowKey}:${i.field}`), w && e.status === "connected" && (e.invoke("AcquireCellLock", {
|
|
687
687
|
entityType: t,
|
|
688
|
-
cell:
|
|
688
|
+
cell: i,
|
|
689
689
|
user: a,
|
|
690
690
|
timestamp: Date.now()
|
|
691
691
|
}).catch(() => {
|
|
692
|
-
}),
|
|
693
|
-
const
|
|
694
|
-
return
|
|
692
|
+
}), K((f) => {
|
|
693
|
+
const d = new Map(f);
|
|
694
|
+
return d.set(G(i), { user: a, timestamp: Date.now() }), d;
|
|
695
695
|
})), !0),
|
|
696
|
-
[
|
|
697
|
-
), ue =
|
|
698
|
-
async (
|
|
699
|
-
const
|
|
700
|
-
if (!
|
|
701
|
-
const
|
|
702
|
-
if (
|
|
703
|
-
return
|
|
704
|
-
const
|
|
705
|
-
cell:
|
|
706
|
-
originalValue:
|
|
707
|
-
newValue:
|
|
696
|
+
[H, I, w, e, t, a]
|
|
697
|
+
), ue = h(
|
|
698
|
+
async (i, f) => {
|
|
699
|
+
const d = S.data.find((D) => D[n] === i.rowKey);
|
|
700
|
+
if (!d) return !1;
|
|
701
|
+
const A = d[i.field];
|
|
702
|
+
if (g && !await g(i, A, f))
|
|
703
|
+
return m(i), !1;
|
|
704
|
+
const M = {
|
|
705
|
+
cell: i,
|
|
706
|
+
originalValue: A,
|
|
707
|
+
newValue: f,
|
|
708
708
|
timestamp: Date.now()
|
|
709
709
|
};
|
|
710
|
-
|
|
711
|
-
const
|
|
712
|
-
return
|
|
713
|
-
}),
|
|
710
|
+
Y((D) => {
|
|
711
|
+
const W = new Map(D);
|
|
712
|
+
return W.set(G(i), M), W;
|
|
713
|
+
}), N && S.registerPendingChange(i.rowKey, { [i.field]: f });
|
|
714
714
|
try {
|
|
715
715
|
return await e.invoke("UpdateEntityField", {
|
|
716
716
|
entityType: t,
|
|
717
|
-
entityId:
|
|
718
|
-
field:
|
|
719
|
-
value:
|
|
717
|
+
entityId: i.rowKey,
|
|
718
|
+
field: i.field,
|
|
719
|
+
value: f,
|
|
720
720
|
userId: a.id,
|
|
721
|
-
timestamp:
|
|
722
|
-
}),
|
|
723
|
-
const
|
|
724
|
-
return
|
|
725
|
-
}),
|
|
726
|
-
}),
|
|
727
|
-
const
|
|
728
|
-
return
|
|
729
|
-
})), F(null),
|
|
730
|
-
} catch (
|
|
731
|
-
throw
|
|
732
|
-
const
|
|
733
|
-
return
|
|
734
|
-
}),
|
|
721
|
+
timestamp: M.timestamp
|
|
722
|
+
}), S.confirmPendingChange(i.rowKey), Y((D) => {
|
|
723
|
+
const W = new Map(D);
|
|
724
|
+
return W.delete(G(i)), W;
|
|
725
|
+
}), v == null || v(i, f), w && (e.invoke("ReleaseCellLock", { entityType: t, cell: i }).catch(() => {
|
|
726
|
+
}), K((D) => {
|
|
727
|
+
const W = new Map(D);
|
|
728
|
+
return W.delete(G(i)), W;
|
|
729
|
+
})), F(null), I.stopEditing(), !0;
|
|
730
|
+
} catch (D) {
|
|
731
|
+
throw S.rollbackPendingChange(i.rowKey), Y((W) => {
|
|
732
|
+
const ce = new Map(W);
|
|
733
|
+
return ce.delete(G(i)), ce;
|
|
734
|
+
}), D;
|
|
735
735
|
}
|
|
736
736
|
},
|
|
737
737
|
[
|
|
738
|
-
|
|
738
|
+
S,
|
|
739
739
|
n,
|
|
740
|
-
|
|
741
|
-
|
|
740
|
+
g,
|
|
741
|
+
N,
|
|
742
742
|
e,
|
|
743
743
|
t,
|
|
744
744
|
a.id,
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
745
|
+
v,
|
|
746
|
+
w,
|
|
747
|
+
I
|
|
748
748
|
]
|
|
749
|
-
),
|
|
750
|
-
(
|
|
751
|
-
F(null),
|
|
752
|
-
}),
|
|
753
|
-
const
|
|
754
|
-
return
|
|
755
|
-
})),
|
|
756
|
-
const
|
|
757
|
-
return
|
|
749
|
+
), m = h(
|
|
750
|
+
(i) => {
|
|
751
|
+
F(null), I.stopEditing(), w && e.status === "connected" && (e.invoke("ReleaseCellLock", { entityType: t, cell: i }).catch(() => {
|
|
752
|
+
}), K((f) => {
|
|
753
|
+
const d = new Map(f);
|
|
754
|
+
return d.delete(G(i)), d;
|
|
755
|
+
})), Y((f) => {
|
|
756
|
+
const d = new Map(f);
|
|
757
|
+
return d.delete(G(i)), d;
|
|
758
758
|
});
|
|
759
759
|
},
|
|
760
|
-
[
|
|
761
|
-
),
|
|
762
|
-
(
|
|
763
|
-
const
|
|
764
|
-
|
|
760
|
+
[I, w, e, t]
|
|
761
|
+
), T = h(
|
|
762
|
+
(i, f) => {
|
|
763
|
+
const d = ae.find((A) => G(A.cell) === G(i));
|
|
764
|
+
d && (f === "remote" && S.applyRemoteUpdate({
|
|
765
765
|
operation: "update",
|
|
766
766
|
entityName: t,
|
|
767
|
-
key:
|
|
768
|
-
changes: { [
|
|
769
|
-
}),
|
|
767
|
+
key: i.rowKey,
|
|
768
|
+
changes: { [i.field]: d.remoteValue }
|
|
769
|
+
}), j((A) => A.filter((M) => G(M.cell) !== G(i))));
|
|
770
770
|
},
|
|
771
|
-
[
|
|
772
|
-
),
|
|
773
|
-
async (
|
|
774
|
-
await e.invoke("InsertEntity", t,
|
|
771
|
+
[ae, S, t]
|
|
772
|
+
), s = h(
|
|
773
|
+
async (i) => {
|
|
774
|
+
await e.invoke("InsertEntity", t, i);
|
|
775
775
|
},
|
|
776
776
|
[e, t]
|
|
777
|
-
),
|
|
778
|
-
async (
|
|
779
|
-
|
|
777
|
+
), b = h(
|
|
778
|
+
async (i, f) => {
|
|
779
|
+
N && S.registerPendingChange(i, f);
|
|
780
780
|
try {
|
|
781
|
-
await e.invoke("UpdateEntity", t,
|
|
782
|
-
} catch (
|
|
783
|
-
throw
|
|
781
|
+
await e.invoke("UpdateEntity", t, i, f), S.confirmPendingChange(i);
|
|
782
|
+
} catch (d) {
|
|
783
|
+
throw S.rollbackPendingChange(i), d;
|
|
784
784
|
}
|
|
785
785
|
},
|
|
786
|
-
[e, t,
|
|
787
|
-
),
|
|
788
|
-
async (
|
|
789
|
-
await e.invoke("DeleteEntity", t,
|
|
786
|
+
[e, t, N, S]
|
|
787
|
+
), $ = h(
|
|
788
|
+
async (i) => {
|
|
789
|
+
await e.invoke("DeleteEntity", t, i);
|
|
790
790
|
},
|
|
791
791
|
[e, t]
|
|
792
|
-
),
|
|
792
|
+
), ee = de(
|
|
793
793
|
() => ({
|
|
794
794
|
user: a,
|
|
795
|
-
focusedCell:
|
|
796
|
-
selectedCells:
|
|
797
|
-
selectedRows:
|
|
798
|
-
editingCell:
|
|
799
|
-
color:
|
|
795
|
+
focusedCell: B,
|
|
796
|
+
selectedCells: L,
|
|
797
|
+
selectedRows: p,
|
|
798
|
+
editingCell: J,
|
|
799
|
+
color: P(a.id)
|
|
800
800
|
}),
|
|
801
|
-
[a,
|
|
801
|
+
[a, B, L, p, J, P]
|
|
802
802
|
);
|
|
803
803
|
return {
|
|
804
|
-
data:
|
|
805
|
-
presence:
|
|
806
|
-
userSelections:
|
|
807
|
-
mySelection:
|
|
808
|
-
flashedKeys:
|
|
809
|
-
pendingEdits:
|
|
810
|
-
connectionStatus:
|
|
811
|
-
myPresenceStatus:
|
|
804
|
+
data: S.data,
|
|
805
|
+
presence: I.presence,
|
|
806
|
+
userSelections: ne,
|
|
807
|
+
mySelection: ee,
|
|
808
|
+
flashedKeys: S.flashedKeys,
|
|
809
|
+
pendingEdits: x,
|
|
810
|
+
connectionStatus: S.status,
|
|
811
|
+
myPresenceStatus: I.myStatus,
|
|
812
812
|
// Selection methods
|
|
813
|
-
setFocusedCell:
|
|
814
|
-
setSelectedCells:
|
|
815
|
-
setSelectedRows:
|
|
813
|
+
setFocusedCell: _,
|
|
814
|
+
setSelectedCells: z,
|
|
815
|
+
setSelectedRows: le,
|
|
816
816
|
// Edit methods
|
|
817
|
-
startCellEdit:
|
|
817
|
+
startCellEdit: ie,
|
|
818
818
|
commitCellEdit: ue,
|
|
819
|
-
cancelCellEdit:
|
|
820
|
-
isCellLocked:
|
|
821
|
-
getCellEditor:
|
|
822
|
-
getUserColor:
|
|
819
|
+
cancelCellEdit: m,
|
|
820
|
+
isCellLocked: H,
|
|
821
|
+
getCellEditor: se,
|
|
822
|
+
getUserColor: P,
|
|
823
823
|
// Row methods
|
|
824
|
-
insertRow:
|
|
825
|
-
updateRow:
|
|
826
|
-
deleteRow:
|
|
824
|
+
insertRow: s,
|
|
825
|
+
updateRow: b,
|
|
826
|
+
deleteRow: $,
|
|
827
827
|
// Conflict handling
|
|
828
|
-
resolveConflict:
|
|
829
|
-
conflicts:
|
|
828
|
+
resolveConflict: T,
|
|
829
|
+
conflicts: ae
|
|
830
830
|
};
|
|
831
831
|
}
|
|
832
|
-
class
|
|
832
|
+
class Re {
|
|
833
833
|
constructor(e) {
|
|
834
834
|
this.accessToken = null, this.refreshToken = null, this.tokenFactory = async () => {
|
|
835
835
|
if (!this.accessToken) throw new Error("Not authenticated");
|
|
@@ -882,7 +882,7 @@ class Ae {
|
|
|
882
882
|
}
|
|
883
883
|
}
|
|
884
884
|
}
|
|
885
|
-
class
|
|
885
|
+
class De {
|
|
886
886
|
constructor(e) {
|
|
887
887
|
this.cfg = e;
|
|
888
888
|
}
|
|
@@ -905,7 +905,7 @@ class Le {
|
|
|
905
905
|
/** Upload multiple files. */
|
|
906
906
|
async uploadMultiple(e, t) {
|
|
907
907
|
const n = this.cfg.fetch ?? globalThis.fetch, a = new FormData();
|
|
908
|
-
e.forEach((
|
|
908
|
+
e.forEach((o) => a.append("files", o)), t && a.append("folder", t);
|
|
909
909
|
const r = await n(`${this.cfg.baseUrl}/batch`, {
|
|
910
910
|
method: "POST",
|
|
911
911
|
headers: await this.headers(),
|
|
@@ -945,35 +945,35 @@ class Le {
|
|
|
945
945
|
* Falls back to standard fetch-based upload if XHR is unavailable.
|
|
946
946
|
*/
|
|
947
947
|
uploadWithProgress(e, t, n, a) {
|
|
948
|
-
return typeof XMLHttpRequest > "u" ? this.upload(e, n) : new Promise(async (r,
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
948
|
+
return typeof XMLHttpRequest > "u" ? this.upload(e, n) : new Promise(async (r, o) => {
|
|
949
|
+
const l = new XMLHttpRequest(), c = new FormData();
|
|
950
|
+
if (c.append("file", e), n && c.append("folder", n), a) {
|
|
951
951
|
if (a.aborted) {
|
|
952
|
-
|
|
952
|
+
o(new DOMException("Aborted", "AbortError"));
|
|
953
953
|
return;
|
|
954
954
|
}
|
|
955
955
|
a.addEventListener("abort", () => {
|
|
956
|
-
|
|
956
|
+
l.abort(), o(new DOMException("Aborted", "AbortError"));
|
|
957
957
|
});
|
|
958
958
|
}
|
|
959
|
-
|
|
959
|
+
l.upload.addEventListener("progress", (v) => {
|
|
960
960
|
t({
|
|
961
|
-
loaded:
|
|
962
|
-
total:
|
|
963
|
-
percent:
|
|
961
|
+
loaded: v.loaded,
|
|
962
|
+
total: v.total,
|
|
963
|
+
percent: v.lengthComputable ? v.loaded / v.total : NaN
|
|
964
964
|
});
|
|
965
|
-
}),
|
|
966
|
-
if (
|
|
965
|
+
}), l.addEventListener("load", () => {
|
|
966
|
+
if (l.status >= 200 && l.status < 300)
|
|
967
967
|
try {
|
|
968
|
-
r(JSON.parse(
|
|
968
|
+
r(JSON.parse(l.responseText));
|
|
969
969
|
} catch {
|
|
970
|
-
|
|
970
|
+
o(new Error("Invalid JSON response"));
|
|
971
971
|
}
|
|
972
972
|
else
|
|
973
|
-
|
|
974
|
-
}),
|
|
975
|
-
const
|
|
976
|
-
Object.entries(
|
|
973
|
+
o(new Error(`File upload failed: ${l.status}`));
|
|
974
|
+
}), l.addEventListener("error", () => o(new Error("Network error during upload"))), l.addEventListener("abort", () => o(new DOMException("Aborted", "AbortError"))), l.open("POST", this.cfg.baseUrl);
|
|
975
|
+
const g = await this.headers();
|
|
976
|
+
Object.entries(g).forEach(([v, w]) => l.setRequestHeader(v, w)), l.send(c);
|
|
977
977
|
});
|
|
978
978
|
}
|
|
979
979
|
/**
|
|
@@ -982,20 +982,20 @@ class Le {
|
|
|
982
982
|
*/
|
|
983
983
|
async uploadMultipleWithProgress(e, t, n, a) {
|
|
984
984
|
const r = [];
|
|
985
|
-
for (let
|
|
985
|
+
for (let o = 0; o < e.length; o++) {
|
|
986
986
|
if (a != null && a.aborted) throw new DOMException("Aborted", "AbortError");
|
|
987
|
-
const
|
|
988
|
-
e[
|
|
989
|
-
(
|
|
987
|
+
const l = await this.uploadWithProgress(
|
|
988
|
+
e[o],
|
|
989
|
+
(c) => t(o, c),
|
|
990
990
|
n,
|
|
991
991
|
a
|
|
992
992
|
);
|
|
993
|
-
r.push(
|
|
993
|
+
r.push(l);
|
|
994
994
|
}
|
|
995
995
|
return r;
|
|
996
996
|
}
|
|
997
997
|
}
|
|
998
|
-
class
|
|
998
|
+
class Ne {
|
|
999
999
|
constructor(e) {
|
|
1000
1000
|
this.cfg = e;
|
|
1001
1001
|
}
|
|
@@ -1023,65 +1023,65 @@ class Ue {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
/** Trigger browser download for an export. */
|
|
1025
1025
|
async downloadToFile(e, t) {
|
|
1026
|
-
var
|
|
1026
|
+
var l;
|
|
1027
1027
|
const n = await this.requestExport(e);
|
|
1028
|
-
if (!((
|
|
1029
|
-
const a = await this.download(n.data.downloadUrl), r = URL.createObjectURL(a),
|
|
1030
|
-
|
|
1028
|
+
if (!((l = n.data) != null && l.downloadUrl)) throw new Error("No download URL returned");
|
|
1029
|
+
const a = await this.download(n.data.downloadUrl), r = URL.createObjectURL(a), o = document.createElement("a");
|
|
1030
|
+
o.href = r, o.download = t ?? `export.${e.format}`, document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(r);
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
|
1033
|
-
function
|
|
1033
|
+
function Ue(u) {
|
|
1034
1034
|
return (e) => {
|
|
1035
1035
|
const t = e ?? globalThis.fetch;
|
|
1036
1036
|
return (a, r) => {
|
|
1037
|
-
const
|
|
1038
|
-
let
|
|
1039
|
-
for (let
|
|
1040
|
-
const
|
|
1041
|
-
|
|
1037
|
+
const c = { url: typeof a == "string" ? a : a instanceof URL ? a.toString() : a.url, init: r ?? {}, meta: {} };
|
|
1038
|
+
let g = (v) => t(v.url, v.init);
|
|
1039
|
+
for (let v = u.length - 1; v >= 0; v--) {
|
|
1040
|
+
const w = u[v], V = g;
|
|
1041
|
+
g = (O) => w(O, V);
|
|
1042
1042
|
}
|
|
1043
|
-
return
|
|
1043
|
+
return g(c);
|
|
1044
1044
|
};
|
|
1045
1045
|
};
|
|
1046
1046
|
}
|
|
1047
|
-
function
|
|
1048
|
-
return async (
|
|
1049
|
-
const t = performance.now(), n = (
|
|
1047
|
+
function Fe() {
|
|
1048
|
+
return async (u, e) => {
|
|
1049
|
+
const t = performance.now(), n = (u.init.method ?? "GET").toUpperCase();
|
|
1050
1050
|
try {
|
|
1051
|
-
const a = await e(
|
|
1052
|
-
return console.debug(`[ERP] ${n} ${
|
|
1051
|
+
const a = await e(u), r = (performance.now() - t).toFixed(1);
|
|
1052
|
+
return console.debug(`[ERP] ${n} ${u.url} → ${a.status} (${r}ms)`), a;
|
|
1053
1053
|
} catch (a) {
|
|
1054
1054
|
const r = (performance.now() - t).toFixed(1);
|
|
1055
|
-
throw console.error(`[ERP] ${n} ${
|
|
1055
|
+
throw console.error(`[ERP] ${n} ${u.url} FAILED (${r}ms)`, a), a;
|
|
1056
1056
|
}
|
|
1057
1057
|
};
|
|
1058
1058
|
}
|
|
1059
|
-
function
|
|
1060
|
-
const e = (
|
|
1059
|
+
function Me(u) {
|
|
1060
|
+
const e = (u == null ? void 0 : u.maxRetries) ?? 3, t = (u == null ? void 0 : u.baseDelay) ?? 500, n = new Set((u == null ? void 0 : u.retryOn) ?? [408, 429, 500, 502, 503, 504]);
|
|
1061
1061
|
return async (a, r) => {
|
|
1062
|
-
let
|
|
1063
|
-
for (let
|
|
1062
|
+
let o;
|
|
1063
|
+
for (let l = 0; l <= e; l++) {
|
|
1064
1064
|
try {
|
|
1065
|
-
const
|
|
1066
|
-
if (
|
|
1067
|
-
return
|
|
1068
|
-
|
|
1069
|
-
} catch (
|
|
1070
|
-
if (
|
|
1065
|
+
const g = await r(a);
|
|
1066
|
+
if (g.ok || !n.has(g.status) || l === e)
|
|
1067
|
+
return g;
|
|
1068
|
+
o = new Error(`HTTP ${g.status}`);
|
|
1069
|
+
} catch (g) {
|
|
1070
|
+
if (o = g, l === e) throw g;
|
|
1071
1071
|
}
|
|
1072
|
-
const
|
|
1073
|
-
await new Promise((
|
|
1072
|
+
const c = t * Math.pow(2, l) * (0.5 + Math.random() * 0.5);
|
|
1073
|
+
await new Promise((g) => setTimeout(g, c));
|
|
1074
1074
|
}
|
|
1075
|
-
throw
|
|
1075
|
+
throw o;
|
|
1076
1076
|
};
|
|
1077
1077
|
}
|
|
1078
|
-
function
|
|
1078
|
+
function Ie(u) {
|
|
1079
1079
|
return async (e, t) => {
|
|
1080
|
-
const n = typeof
|
|
1080
|
+
const n = typeof u == "function" ? await u() : u;
|
|
1081
1081
|
return e.init.headers = { ...e.init.headers, ...n }, t(e);
|
|
1082
1082
|
};
|
|
1083
1083
|
}
|
|
1084
|
-
class
|
|
1084
|
+
class $e {
|
|
1085
1085
|
constructor(e) {
|
|
1086
1086
|
this.inFlight = 0, this.timestamps = [], this.queue = [], this.processing = !1, this.backingOff = !1, this.maxConcurrent = (e == null ? void 0 : e.maxConcurrent) ?? 6, this.maxPerSecond = (e == null ? void 0 : e.maxPerSecond) ?? 20, this.backoffDelay = (e == null ? void 0 : e.backoffDelay) ?? 2e3, this.baseFetch = (e == null ? void 0 : e.baseFetch) ?? globalThis.fetch.bind(globalThis), this.fetch = this.fetch.bind(this);
|
|
1087
1087
|
}
|
|
@@ -1135,7 +1135,7 @@ class Ie {
|
|
|
1135
1135
|
e();
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
|
-
class
|
|
1138
|
+
class Be {
|
|
1139
1139
|
constructor(e, t = "id") {
|
|
1140
1140
|
this.items = [], this.mutations = [], this.listeners = /* @__PURE__ */ new Set(), this.nextMutationId = 1, this.adapter = e, this.keyField = t;
|
|
1141
1141
|
}
|
|
@@ -1175,23 +1175,23 @@ class $e {
|
|
|
1175
1175
|
};
|
|
1176
1176
|
this.items = [...this.items, n], this.mutations.push(r), this.notify();
|
|
1177
1177
|
try {
|
|
1178
|
-
const
|
|
1179
|
-
return
|
|
1180
|
-
(
|
|
1181
|
-
), r.status = "confirmed", r.entityId =
|
|
1182
|
-
(
|
|
1183
|
-
), r.status = "failed", r.error =
|
|
1184
|
-
} catch (
|
|
1178
|
+
const o = await this.adapter.create(e);
|
|
1179
|
+
return o.success ? (this.items = this.items.map(
|
|
1180
|
+
(l) => l[this.keyField] === t ? o.data : l
|
|
1181
|
+
), r.status = "confirmed", r.entityId = o.data[this.keyField]) : (this.items = this.items.filter(
|
|
1182
|
+
(l) => l[this.keyField] !== t
|
|
1183
|
+
), r.status = "failed", r.error = o.error), this.notify(), o;
|
|
1184
|
+
} catch (o) {
|
|
1185
1185
|
throw this.items = this.items.filter(
|
|
1186
|
-
(
|
|
1187
|
-
), r.status = "failed", r.error =
|
|
1186
|
+
(l) => l[this.keyField] !== t
|
|
1187
|
+
), r.status = "failed", r.error = o instanceof Error ? o.message : String(o), this.notify(), o;
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
1190
|
/** Optimistically update an item. */
|
|
1191
1191
|
async update(e, t) {
|
|
1192
1192
|
const n = this.items.findIndex(
|
|
1193
|
-
(
|
|
1194
|
-
), a = n >= 0 ? { ...this.items[n] } : void 0,
|
|
1193
|
+
(l) => l[this.keyField] === e
|
|
1194
|
+
), a = n >= 0 ? { ...this.items[n] } : void 0, o = {
|
|
1195
1195
|
id: String(this.nextMutationId++),
|
|
1196
1196
|
type: "update",
|
|
1197
1197
|
entityId: e,
|
|
@@ -1200,25 +1200,25 @@ class $e {
|
|
|
1200
1200
|
status: "pending"
|
|
1201
1201
|
};
|
|
1202
1202
|
n >= 0 && (this.items = this.items.map(
|
|
1203
|
-
(
|
|
1204
|
-
)), this.mutations.push(
|
|
1203
|
+
(l, c) => c === n ? { ...l, ...t } : l
|
|
1204
|
+
)), this.mutations.push(o), this.notify();
|
|
1205
1205
|
try {
|
|
1206
|
-
const
|
|
1207
|
-
return
|
|
1208
|
-
(
|
|
1209
|
-
),
|
|
1210
|
-
(
|
|
1211
|
-
)),
|
|
1212
|
-
} catch (
|
|
1206
|
+
const l = await this.adapter.update(e, t);
|
|
1207
|
+
return l.success ? (this.items = this.items.map(
|
|
1208
|
+
(c) => c[this.keyField] === e ? l.data : c
|
|
1209
|
+
), o.status = "confirmed") : (a && n >= 0 && (this.items = this.items.map(
|
|
1210
|
+
(c) => c[this.keyField] === e ? a : c
|
|
1211
|
+
)), o.status = "failed", o.error = l.error), this.notify(), l;
|
|
1212
|
+
} catch (l) {
|
|
1213
1213
|
throw a && n >= 0 && (this.items = this.items.map(
|
|
1214
|
-
(
|
|
1215
|
-
)),
|
|
1214
|
+
(c) => c[this.keyField] === e ? a : c
|
|
1215
|
+
)), o.status = "failed", o.error = l instanceof Error ? l.message : String(l), this.notify(), l;
|
|
1216
1216
|
}
|
|
1217
1217
|
}
|
|
1218
1218
|
/** Optimistically delete an item. */
|
|
1219
1219
|
async remove(e) {
|
|
1220
1220
|
const t = this.items.findIndex(
|
|
1221
|
-
(
|
|
1221
|
+
(o) => o[this.keyField] === e
|
|
1222
1222
|
), n = t >= 0 ? { ...this.items[t] } : void 0, r = {
|
|
1223
1223
|
id: String(this.nextMutationId++),
|
|
1224
1224
|
type: "delete",
|
|
@@ -1228,17 +1228,17 @@ class $e {
|
|
|
1228
1228
|
status: "pending"
|
|
1229
1229
|
};
|
|
1230
1230
|
this.items = this.items.filter(
|
|
1231
|
-
(
|
|
1231
|
+
(o) => o[this.keyField] !== e
|
|
1232
1232
|
), this.mutations.push(r), this.notify();
|
|
1233
1233
|
try {
|
|
1234
|
-
const
|
|
1235
|
-
return
|
|
1236
|
-
} catch (
|
|
1237
|
-
throw n && this.items.splice(t, 0, n), r.status = "failed", r.error =
|
|
1234
|
+
const o = await this.adapter.remove(e);
|
|
1235
|
+
return o.success ? r.status = "confirmed" : (n && this.items.splice(t, 0, n), r.status = "failed", r.error = o.error), this.notify(), o;
|
|
1236
|
+
} catch (o) {
|
|
1237
|
+
throw n && this.items.splice(t, 0, n), r.status = "failed", r.error = o instanceof Error ? o.message : String(o), this.notify(), o;
|
|
1238
1238
|
}
|
|
1239
1239
|
}
|
|
1240
1240
|
}
|
|
1241
|
-
class
|
|
1241
|
+
class ze {
|
|
1242
1242
|
constructor(e) {
|
|
1243
1243
|
this.queue = [], this.syncing = !1, this.nextId = 1, this.config = e ?? {}, this.baseFetch = (e == null ? void 0 : e.baseFetch) ?? globalThis.fetch.bind(globalThis), this.storageKey = (e == null ? void 0 : e.storageKey) ?? "erp_offline_", this.fetch = this.fetch.bind(this), this.restoreQueue(), this.boundOnline = () => {
|
|
1244
1244
|
var t, n;
|
|
@@ -1250,7 +1250,7 @@ class Be {
|
|
|
1250
1250
|
}
|
|
1251
1251
|
/** A fetch-compatible function that queues mutations when offline. */
|
|
1252
1252
|
fetch(e, t) {
|
|
1253
|
-
var
|
|
1253
|
+
var o, l;
|
|
1254
1254
|
const n = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, a = ((t == null ? void 0 : t.method) ?? "GET").toUpperCase();
|
|
1255
1255
|
if (this.isOnline())
|
|
1256
1256
|
return this.baseFetch(e, t);
|
|
@@ -1264,7 +1264,7 @@ class Be {
|
|
|
1264
1264
|
body: typeof (t == null ? void 0 : t.body) == "string" ? t.body : void 0,
|
|
1265
1265
|
timestamp: Date.now()
|
|
1266
1266
|
};
|
|
1267
|
-
return this.queue.push(r), this.persistQueue(), (
|
|
1267
|
+
return this.queue.push(r), this.persistQueue(), (l = (o = this.config).onQueued) == null || l.call(o, r), Promise.resolve(new Response(
|
|
1268
1268
|
JSON.stringify({ queued: !0, queueId: r.id }),
|
|
1269
1269
|
{ status: 202, headers: { "Content-Type": "application/json" } }
|
|
1270
1270
|
));
|
|
@@ -1688,7 +1688,7 @@ const ye = [
|
|
|
1688
1688
|
{ name: "readOnly", type: "boolean", label: "Read only", defaultValue: !1 }
|
|
1689
1689
|
]
|
|
1690
1690
|
}
|
|
1691
|
-
],
|
|
1691
|
+
], Se = [
|
|
1692
1692
|
{
|
|
1693
1693
|
type: "NiceLoginForm",
|
|
1694
1694
|
label: "Login Form",
|
|
@@ -1749,7 +1749,7 @@ const ye = [
|
|
|
1749
1749
|
{ name: "codeLength", type: "number", label: "Code length", min: 4, max: 8, defaultValue: 6 }
|
|
1750
1750
|
]
|
|
1751
1751
|
}
|
|
1752
|
-
],
|
|
1752
|
+
], ke = [
|
|
1753
1753
|
{
|
|
1754
1754
|
type: "NiceComments",
|
|
1755
1755
|
label: "Comments",
|
|
@@ -1813,37 +1813,385 @@ const ye = [
|
|
|
1813
1813
|
...ge,
|
|
1814
1814
|
...we,
|
|
1815
1815
|
...ve,
|
|
1816
|
-
...
|
|
1817
|
-
...
|
|
1816
|
+
...Se,
|
|
1817
|
+
...ke
|
|
1818
1818
|
];
|
|
1819
|
+
async function Te(u, e) {
|
|
1820
|
+
const t = await fetch(u, {
|
|
1821
|
+
...e,
|
|
1822
|
+
headers: {
|
|
1823
|
+
"Content-Type": "application/json",
|
|
1824
|
+
...e == null ? void 0 : e.headers
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
if (!t.ok) {
|
|
1828
|
+
const n = await t.text();
|
|
1829
|
+
let a = {};
|
|
1830
|
+
try {
|
|
1831
|
+
a = JSON.parse(n);
|
|
1832
|
+
} catch {
|
|
1833
|
+
}
|
|
1834
|
+
throw {
|
|
1835
|
+
code: a.code || `HTTP_${t.status}`,
|
|
1836
|
+
message: a.message || t.statusText,
|
|
1837
|
+
statusCode: t.status
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
return t.json();
|
|
1841
|
+
}
|
|
1842
|
+
function Je(u) {
|
|
1843
|
+
const {
|
|
1844
|
+
baseUrl: e,
|
|
1845
|
+
currency: t = "PLN",
|
|
1846
|
+
timeout: n = 3e4,
|
|
1847
|
+
fetcher: a = Te,
|
|
1848
|
+
getAuthToken: r,
|
|
1849
|
+
onError: o
|
|
1850
|
+
} = u, [l, c] = E([]), [g, v] = E(null), [w, V] = E(null), [O, Q] = E(null), [N, X] = E(null), [q, Z] = E(null), [U, K] = E([]), [x, Y] = E([]), [ae, j] = E(null), [B, _] = E({
|
|
1851
|
+
offers: !1,
|
|
1852
|
+
calculate: !1,
|
|
1853
|
+
compare: !1,
|
|
1854
|
+
apply: !1,
|
|
1855
|
+
creditCheck: !1,
|
|
1856
|
+
refinancing: !1,
|
|
1857
|
+
consolidation: !1,
|
|
1858
|
+
savedCalculations: !1
|
|
1859
|
+
}), L = oe(/* @__PURE__ */ new Map()), z = h(() => {
|
|
1860
|
+
const s = {
|
|
1861
|
+
"Content-Type": "application/json"
|
|
1862
|
+
}, b = r == null ? void 0 : r();
|
|
1863
|
+
return b && (s.Authorization = `Bearer ${b}`), s;
|
|
1864
|
+
}, [r]), p = h(
|
|
1865
|
+
async (s, b = {}, $) => {
|
|
1866
|
+
const ee = L.current.get(s);
|
|
1867
|
+
ee && ee.abort();
|
|
1868
|
+
const i = new AbortController();
|
|
1869
|
+
L.current.set(s, i);
|
|
1870
|
+
const f = setTimeout(() => i.abort(), n);
|
|
1871
|
+
_((d) => ({ ...d, [$]: !0 })), j(null);
|
|
1872
|
+
try {
|
|
1873
|
+
const d = `${e}${s}`;
|
|
1874
|
+
return await a(d, {
|
|
1875
|
+
...b,
|
|
1876
|
+
headers: {
|
|
1877
|
+
...z(),
|
|
1878
|
+
...b.headers
|
|
1879
|
+
},
|
|
1880
|
+
signal: i.signal
|
|
1881
|
+
});
|
|
1882
|
+
} catch (d) {
|
|
1883
|
+
const A = {
|
|
1884
|
+
code: d.code || "UNKNOWN_ERROR",
|
|
1885
|
+
message: d.message || "An unknown error occurred",
|
|
1886
|
+
details: d.details,
|
|
1887
|
+
endpoint: s,
|
|
1888
|
+
statusCode: d.statusCode
|
|
1889
|
+
};
|
|
1890
|
+
throw d.name !== "AbortError" && (j(A), o == null || o(A)), A;
|
|
1891
|
+
} finally {
|
|
1892
|
+
clearTimeout(f), L.current.delete(s), _((d) => ({ ...d, [$]: !1 }));
|
|
1893
|
+
}
|
|
1894
|
+
},
|
|
1895
|
+
[e, n, a, z, o]
|
|
1896
|
+
), le = h(
|
|
1897
|
+
async (s) => {
|
|
1898
|
+
var f, d;
|
|
1899
|
+
const b = new URLSearchParams();
|
|
1900
|
+
s != null && s.loanType && b.set("loanType", s.loanType), s != null && s.minAmount && b.set("minAmount", String(s.minAmount)), s != null && s.maxAmount && b.set("maxAmount", String(s.maxAmount)), s != null && s.minTerm && b.set("minTerm", String(s.minTerm)), s != null && s.maxTerm && b.set("maxTerm", String(s.maxTerm)), s != null && s.maxApr && b.set("maxApr", String(s.maxApr)), (f = s == null ? void 0 : s.banks) != null && f.length && b.set("banks", s.banks.join(",")), (d = s == null ? void 0 : s.features) != null && d.length && b.set("features", s.features.join(",")), b.set("currency", (s == null ? void 0 : s.currency) || t);
|
|
1901
|
+
const $ = b.toString(), ee = `/offers${$ ? `?${$}` : ""}`, i = await p(ee, { method: "GET" }, "offers");
|
|
1902
|
+
return c(i), i;
|
|
1903
|
+
},
|
|
1904
|
+
[p, t]
|
|
1905
|
+
), J = h((s) => {
|
|
1906
|
+
v(s);
|
|
1907
|
+
}, []), F = h(
|
|
1908
|
+
async (s) => p(`/offers/${s}`, { method: "GET" }, "offers"),
|
|
1909
|
+
[p]
|
|
1910
|
+
), ne = h(
|
|
1911
|
+
async (s) => {
|
|
1912
|
+
const b = await p(
|
|
1913
|
+
"/calculate/amortization",
|
|
1914
|
+
{
|
|
1915
|
+
method: "POST",
|
|
1916
|
+
body: JSON.stringify({
|
|
1917
|
+
...s,
|
|
1918
|
+
currency: s.currency || t
|
|
1919
|
+
})
|
|
1920
|
+
},
|
|
1921
|
+
"calculate"
|
|
1922
|
+
);
|
|
1923
|
+
return V(b), b;
|
|
1924
|
+
},
|
|
1925
|
+
[p, t]
|
|
1926
|
+
), re = h(
|
|
1927
|
+
async (s) => {
|
|
1928
|
+
const b = await p(
|
|
1929
|
+
"/calculate/compare",
|
|
1930
|
+
{
|
|
1931
|
+
method: "POST",
|
|
1932
|
+
body: JSON.stringify({ scenarios: s, currency: t })
|
|
1933
|
+
},
|
|
1934
|
+
"compare"
|
|
1935
|
+
);
|
|
1936
|
+
return Q(b), b;
|
|
1937
|
+
},
|
|
1938
|
+
[p, t]
|
|
1939
|
+
), y = h(
|
|
1940
|
+
async (s, b, $) => {
|
|
1941
|
+
const ee = await p(
|
|
1942
|
+
"/credit/analyze",
|
|
1943
|
+
{
|
|
1944
|
+
method: "POST",
|
|
1945
|
+
body: JSON.stringify({
|
|
1946
|
+
monthlyIncome: s,
|
|
1947
|
+
monthlyDebts: b,
|
|
1948
|
+
requestedAmount: $,
|
|
1949
|
+
currency: t
|
|
1950
|
+
})
|
|
1951
|
+
},
|
|
1952
|
+
"creditCheck"
|
|
1953
|
+
);
|
|
1954
|
+
return Z(ee), ee;
|
|
1955
|
+
},
|
|
1956
|
+
[p, t]
|
|
1957
|
+
), k = h(
|
|
1958
|
+
async (s) => {
|
|
1959
|
+
const b = await p(
|
|
1960
|
+
"/applications",
|
|
1961
|
+
{
|
|
1962
|
+
method: "POST",
|
|
1963
|
+
body: JSON.stringify(s)
|
|
1964
|
+
},
|
|
1965
|
+
"apply"
|
|
1966
|
+
);
|
|
1967
|
+
return X(b), b;
|
|
1968
|
+
},
|
|
1969
|
+
[p]
|
|
1970
|
+
), P = h(
|
|
1971
|
+
async (s) => {
|
|
1972
|
+
const b = await p(
|
|
1973
|
+
`/applications/${s}`,
|
|
1974
|
+
{ method: "GET" },
|
|
1975
|
+
"apply"
|
|
1976
|
+
);
|
|
1977
|
+
return X(b), b;
|
|
1978
|
+
},
|
|
1979
|
+
[p]
|
|
1980
|
+
), C = h(
|
|
1981
|
+
async (s) => {
|
|
1982
|
+
await p(`/applications/${s}/cancel`, { method: "POST" }, "apply"), X(null);
|
|
1983
|
+
},
|
|
1984
|
+
[p]
|
|
1985
|
+
), S = h(
|
|
1986
|
+
async (s, b, $, ee) => {
|
|
1987
|
+
const i = await p(
|
|
1988
|
+
"/calculations",
|
|
1989
|
+
{
|
|
1990
|
+
method: "POST",
|
|
1991
|
+
body: JSON.stringify({ name: s, config: b, result: $, notes: ee })
|
|
1992
|
+
},
|
|
1993
|
+
"savedCalculations"
|
|
1994
|
+
);
|
|
1995
|
+
return K((f) => [...f, i]), i;
|
|
1996
|
+
},
|
|
1997
|
+
[p]
|
|
1998
|
+
), I = h(
|
|
1999
|
+
async (s) => p(
|
|
2000
|
+
`/calculations/${s}`,
|
|
2001
|
+
{ method: "GET" },
|
|
2002
|
+
"savedCalculations"
|
|
2003
|
+
),
|
|
2004
|
+
[p]
|
|
2005
|
+
), R = h(
|
|
2006
|
+
async (s) => {
|
|
2007
|
+
await p(`/calculations/${s}`, { method: "DELETE" }, "savedCalculations"), K((b) => b.filter(($) => $.id !== s));
|
|
2008
|
+
},
|
|
2009
|
+
[p]
|
|
2010
|
+
), H = h(async () => {
|
|
2011
|
+
const s = await p(
|
|
2012
|
+
"/calculations",
|
|
2013
|
+
{ method: "GET" },
|
|
2014
|
+
"savedCalculations"
|
|
2015
|
+
);
|
|
2016
|
+
return K(s), s;
|
|
2017
|
+
}, [p]), se = h(
|
|
2018
|
+
async (s, b) => p(
|
|
2019
|
+
"/refinancing/analyze",
|
|
2020
|
+
{
|
|
2021
|
+
method: "POST",
|
|
2022
|
+
body: JSON.stringify({ currentLoanId: s, newOfferIds: b })
|
|
2023
|
+
},
|
|
2024
|
+
"refinancing"
|
|
2025
|
+
),
|
|
2026
|
+
[p]
|
|
2027
|
+
), ie = h(
|
|
2028
|
+
async (s, b) => p(
|
|
2029
|
+
"/consolidation/simulate",
|
|
2030
|
+
{
|
|
2031
|
+
method: "POST",
|
|
2032
|
+
body: JSON.stringify({ debts: s, targetRate: b, currency: t })
|
|
2033
|
+
},
|
|
2034
|
+
"consolidation"
|
|
2035
|
+
),
|
|
2036
|
+
[p, t]
|
|
2037
|
+
), ue = h(async () => {
|
|
2038
|
+
const s = await p("/active", { method: "GET" }, "offers");
|
|
2039
|
+
return Y(s), s;
|
|
2040
|
+
}, [p]), m = h(() => {
|
|
2041
|
+
j(null);
|
|
2042
|
+
}, []), T = h(() => {
|
|
2043
|
+
c([]), v(null), V(null), Q(null), X(null), Z(null), K([]), Y([]), j(null), _({
|
|
2044
|
+
offers: !1,
|
|
2045
|
+
calculate: !1,
|
|
2046
|
+
compare: !1,
|
|
2047
|
+
apply: !1,
|
|
2048
|
+
creditCheck: !1,
|
|
2049
|
+
refinancing: !1,
|
|
2050
|
+
consolidation: !1,
|
|
2051
|
+
savedCalculations: !1
|
|
2052
|
+
});
|
|
2053
|
+
}, []);
|
|
2054
|
+
return te(() => () => {
|
|
2055
|
+
L.current.forEach((s) => s.abort()), L.current.clear();
|
|
2056
|
+
}, []), {
|
|
2057
|
+
// State
|
|
2058
|
+
offers: l,
|
|
2059
|
+
selectedOffer: g,
|
|
2060
|
+
latestCalculation: w,
|
|
2061
|
+
latestComparison: O,
|
|
2062
|
+
applicationState: N,
|
|
2063
|
+
creditAnalysis: q,
|
|
2064
|
+
savedCalculations: U,
|
|
2065
|
+
activeLoans: x,
|
|
2066
|
+
loading: B,
|
|
2067
|
+
error: ae,
|
|
2068
|
+
// Offer operations
|
|
2069
|
+
fetchOffers: le,
|
|
2070
|
+
selectOffer: J,
|
|
2071
|
+
getOfferDetails: F,
|
|
2072
|
+
// Calculation operations
|
|
2073
|
+
calculateAmortization: ne,
|
|
2074
|
+
compareLoanScenarios: re,
|
|
2075
|
+
// Credit analysis
|
|
2076
|
+
runCreditAnalysis: y,
|
|
2077
|
+
// Application operations
|
|
2078
|
+
submitApplication: k,
|
|
2079
|
+
getApplicationStatus: P,
|
|
2080
|
+
cancelApplication: C,
|
|
2081
|
+
// Saved calculations
|
|
2082
|
+
saveCalculation: S,
|
|
2083
|
+
loadCalculation: I,
|
|
2084
|
+
deleteSavedCalculation: R,
|
|
2085
|
+
fetchSavedCalculations: H,
|
|
2086
|
+
// Refinancing & Consolidation
|
|
2087
|
+
analyzeRefinancing: se,
|
|
2088
|
+
simulateConsolidation: ie,
|
|
2089
|
+
// Active loans
|
|
2090
|
+
fetchActiveLoans: ue,
|
|
2091
|
+
// Utilities
|
|
2092
|
+
clearError: m,
|
|
2093
|
+
reset: T
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
class Ge {
|
|
2097
|
+
constructor(e) {
|
|
2098
|
+
this.baseUrl = e.baseUrl, this.currency = e.currency || "PLN", this.timeout = e.timeout || 3e4, this.getAuthToken = e.getAuthToken;
|
|
2099
|
+
}
|
|
2100
|
+
async request(e, t = {}) {
|
|
2101
|
+
var l;
|
|
2102
|
+
const n = new AbortController(), a = setTimeout(() => n.abort(), this.timeout), r = {
|
|
2103
|
+
"Content-Type": "application/json"
|
|
2104
|
+
}, o = (l = this.getAuthToken) == null ? void 0 : l.call(this);
|
|
2105
|
+
o && (r.Authorization = `Bearer ${o}`);
|
|
2106
|
+
try {
|
|
2107
|
+
const c = await fetch(`${this.baseUrl}${e}`, {
|
|
2108
|
+
...t,
|
|
2109
|
+
headers: { ...r, ...t.headers },
|
|
2110
|
+
signal: n.signal
|
|
2111
|
+
});
|
|
2112
|
+
if (!c.ok)
|
|
2113
|
+
throw new Error(`HTTP ${c.status}: ${c.statusText}`);
|
|
2114
|
+
return c.json();
|
|
2115
|
+
} finally {
|
|
2116
|
+
clearTimeout(a);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
async getOffers(e) {
|
|
2120
|
+
const t = new URLSearchParams();
|
|
2121
|
+
e != null && e.loanType && t.set("loanType", e.loanType), e != null && e.minAmount && t.set("minAmount", String(e.minAmount)), e != null && e.maxAmount && t.set("maxAmount", String(e.maxAmount)), t.set("currency", (e == null ? void 0 : e.currency) || this.currency);
|
|
2122
|
+
const n = t.toString();
|
|
2123
|
+
return this.request(`/offers${n ? `?${n}` : ""}`);
|
|
2124
|
+
}
|
|
2125
|
+
async getOfferById(e) {
|
|
2126
|
+
return this.request(`/offers/${e}`);
|
|
2127
|
+
}
|
|
2128
|
+
async calculateAmortization(e) {
|
|
2129
|
+
return this.request("/calculate/amortization", {
|
|
2130
|
+
method: "POST",
|
|
2131
|
+
body: JSON.stringify({ ...e, currency: e.currency || this.currency })
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
async compareScenarios(e) {
|
|
2135
|
+
return this.request("/calculate/compare", {
|
|
2136
|
+
method: "POST",
|
|
2137
|
+
body: JSON.stringify({ scenarios: e, currency: this.currency })
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
async submitApplication(e) {
|
|
2141
|
+
return this.request("/applications", {
|
|
2142
|
+
method: "POST",
|
|
2143
|
+
body: JSON.stringify(e)
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
async getApplicationStatus(e) {
|
|
2147
|
+
return this.request(`/applications/${e}`);
|
|
2148
|
+
}
|
|
2149
|
+
async analyzeRefinancing(e, t) {
|
|
2150
|
+
return this.request("/refinancing/analyze", {
|
|
2151
|
+
method: "POST",
|
|
2152
|
+
body: JSON.stringify({ currentLoanId: e, newOfferIds: t })
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
async simulateConsolidation(e, t) {
|
|
2156
|
+
return this.request("/consolidation/simulate", {
|
|
2157
|
+
method: "POST",
|
|
2158
|
+
body: JSON.stringify({ debts: e, targetRate: t, currency: this.currency })
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
async getActiveLoans() {
|
|
2162
|
+
return this.request("/active");
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
1819
2165
|
export {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
2166
|
+
Re as ErpAuthAdapter,
|
|
2167
|
+
Ce as ErpDataAdapter,
|
|
2168
|
+
Ne as ErpExportAdapter,
|
|
2169
|
+
De as ErpFileAdapter,
|
|
2170
|
+
ze as ErpOfflineQueue,
|
|
2171
|
+
Be as ErpOptimisticStore,
|
|
2172
|
+
$e as ErpRateLimiter,
|
|
2173
|
+
Ge as LoanService,
|
|
1827
2174
|
je as allControlRegistries,
|
|
1828
|
-
|
|
2175
|
+
Ae as applyBatchChanges,
|
|
1829
2176
|
ye as audioControlRegistry,
|
|
1830
|
-
|
|
2177
|
+
Se as authControlRegistry,
|
|
1831
2178
|
ve as businessControlRegistry,
|
|
1832
|
-
|
|
1833
|
-
|
|
2179
|
+
Ue as createMiddlewarePipeline,
|
|
2180
|
+
Ve as createSignalRAdapter,
|
|
1834
2181
|
Pe as createSignalRDataOperations,
|
|
1835
|
-
|
|
2182
|
+
Oe as formatPresenceStatus,
|
|
1836
2183
|
we as gamificationControlRegistry,
|
|
1837
|
-
|
|
2184
|
+
me as generateUserColor,
|
|
1838
2185
|
be as graphicControlRegistry,
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
2186
|
+
Ie as headerMiddleware,
|
|
2187
|
+
Fe as loggingMiddleware,
|
|
2188
|
+
Me as retryMiddleware,
|
|
2189
|
+
ke as socialControlRegistry,
|
|
1843
2190
|
ge as threeControlRegistry,
|
|
1844
|
-
|
|
2191
|
+
Le as useCollaborativeDataGrid,
|
|
1845
2192
|
pe as useEntityPresence,
|
|
1846
|
-
|
|
2193
|
+
Je as useLoanApi,
|
|
2194
|
+
xe as useMultiEntityPresence,
|
|
1847
2195
|
he as useSignalRLiveData
|
|
1848
2196
|
};
|
|
1849
2197
|
//# sourceMappingURL=index.mjs.map
|