@nice2dev/erp-adapter 1.0.5 → 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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as O, useRef as ae, useCallback as m, useEffect as W, useMemo as de } from "react";
2
- class Ve {
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 s = await this.cfg.tokenFactory();
13
- a.Authorization = `Bearer ${s}`;
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 Ce(i) {
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 = (u) => {
64
- t = u, n.forEach((f) => f(u));
65
- }, s = new e.HubConnectionBuilder().withUrl(i.hubUrl, {
66
- accessTokenFactory: i.accessTokenFactory ? () => i.accessTokenFactory() : void 0
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 s.onreconnecting(() => a("reconnecting")), s.onreconnected(() => a("connected")), s.onclose(() => a("disconnected")), {
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 s.start(), a("connected");
73
+ a("connecting"), await o.start(), a("connected");
74
74
  },
75
75
  async stop() {
76
- await s.stop(), a("disconnected");
76
+ await o.stop(), a("disconnected");
77
77
  },
78
- on(u, f) {
79
- s.on(u, f);
78
+ on(c, g) {
79
+ o.on(c, g);
80
80
  },
81
- off(u, f) {
82
- s.off(u, f);
81
+ off(c, g) {
82
+ o.off(c, g);
83
83
  },
84
- invoke(u, ...f) {
85
- return s.invoke(u, ...f);
84
+ invoke(c, ...g) {
85
+ return o.invoke(c, ...g);
86
86
  },
87
- onStatusChange(u) {
88
- return n.add(u), () => n.delete(u);
87
+ onStatusChange(c) {
88
+ return n.add(c), () => n.delete(c);
89
89
  }
90
90
  };
91
91
  }
92
- function he(i) {
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: s,
100
- onConflict: o,
101
- subscribeMethod: u = "SubscribeToEntity",
102
- unsubscribeMethod: f = "UnsubscribeFromEntity",
103
- changeEventName: b = "EntityChanged",
104
- flashChanges: y = !0,
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: C = !0
107
- } = i, [q, L] = O(a), [Q, G] = O(e.status), [X, U] = O(/* @__PURE__ */ new Set()), [H, R] = O(/* @__PURE__ */ new Set()), [_, Z] = O(null), J = ae(/* @__PURE__ */ new Map()), I = ae(/* @__PURE__ */ new Map()), Y = m(
108
- (d, v) => {
109
- const { operation: E, key: S, data: g, changes: N } = v;
110
- switch (E) {
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 !g || d.some((A) => A[n] === S) ? d : [...d, g];
112
+ return !S || y.some((R) => R[n] === C) ? y : [...y, S];
113
113
  case "update":
114
- return d.map((A) => {
115
- if (A[n] !== S) return A;
116
- const K = J.current.get(S);
117
- if (K && o) {
118
- const te = o(
119
- { ...A, ...K.changes },
120
- g ?? { ...A, ...N },
121
- v
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 te === "local" ? { ...A, ...K.changes } : te === "remote" ? (J.current.delete(S), g ?? { ...A, ...N }) : te === "merge" ? { ...A, ...N, ...K.changes } : te;
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 g || { ...A, ...N };
125
+ return S || { ...R, ...I };
126
126
  });
127
127
  case "delete":
128
- return d.filter((A) => A[n] !== S);
128
+ return y.filter((R) => R[n] !== C);
129
129
  default:
130
- return d;
130
+ return y;
131
131
  }
132
132
  },
133
- [n, o]
134
- ), $ = m(
135
- (d) => {
136
- if (!y) return;
137
- const v = I.current.get(d);
138
- v && clearTimeout(v), U((S) => /* @__PURE__ */ new Set([...S, d]));
139
- const E = setTimeout(() => {
140
- U((S) => {
141
- const g = new Set(S);
142
- return g.delete(d), g;
143
- }), I.current.delete(d);
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
- I.current.set(d, E);
145
+ B.current.set(y, P);
146
146
  },
147
- [y, V]
148
- ), B = m(
149
- async (d) => {
150
- d.entityName === t && (r && !await r(d) || (L((v) => {
151
- const E = Y(v, d);
152
- return s == null || s(d, E), E;
153
- }), $(d.key)));
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, Y, s, $]
156
- ), P = m(
157
- (d) => {
158
- B(d);
155
+ [t, r, _, o, L]
156
+ ), p = h(
157
+ (y) => {
158
+ z(y);
159
159
  },
160
- [B]
161
- ), oe = m(
162
- (d, v) => {
163
- if (!C) return;
164
- const E = q.find((S) => S[n] === d);
165
- E && (J.current.set(d, { original: E, changes: v }), R((S) => /* @__PURE__ */ new Set([...S, d])));
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
- [q, n, C]
168
- ), j = m((d) => {
169
- J.current.delete(d), R((v) => {
170
- const E = new Set(v);
171
- return E.delete(d), E;
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 = m((d) => {
174
- const v = J.current.get(d);
175
- v && (L(
176
- (E) => E.map(
177
- (S) => S[n] === d ? v.original : S
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
- ), J.current.delete(d), R((E) => {
180
- const S = new Set(E);
181
- return S.delete(d), S;
179
+ ), j.current.delete(y), x((P) => {
180
+ const C = new Set(P);
181
+ return C.delete(y), C;
182
182
  }));
183
- }, [n]), ee = m(async () => {
183
+ }, [n]), ne = h(async () => {
184
184
  if (e.status === "connected")
185
185
  try {
186
- await e.invoke(u, t), Z(null);
187
- } catch (d) {
188
- Z(d instanceof Error ? d : new Error(String(d)));
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, u, t]), ne = m(async () => {
190
+ }, [e, c, t]), re = h(async () => {
191
191
  if (e.status === "connected")
192
192
  try {
193
- await e.invoke(f, t);
193
+ await e.invoke(g, t);
194
194
  } catch {
195
195
  }
196
- }, [e, f, t]);
197
- return W(() => {
198
- const d = e.onStatusChange((v) => {
199
- G(v), v === "connected" && ee();
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(b, B), e.status === "connected" && ee(), () => {
202
- d(), e.off(b, B), ne(), I.current.forEach((v) => clearTimeout(v)), I.current.clear();
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, b, B, ee, ne]), W(() => {
205
- L(a);
204
+ }, [e, v, z, ne, re]), te(() => {
205
+ N(a);
206
206
  }, [a]), {
207
- data: q,
208
- status: Q,
209
- flashedKeys: X,
210
- pendingKeys: H,
211
- error: _,
212
- applyRemoteUpdate: P,
213
- registerPendingChange: oe,
214
- confirmPendingChange: j,
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: ee
216
+ resubscribe: ne
217
217
  };
218
218
  }
219
- function Pe(i) {
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: s = "UpdateEntity",
227
- deleteMethod: o = "DeleteEntity"
228
- } = i;
226
+ updateMethod: o = "UpdateEntity",
227
+ deleteMethod: l = "DeleteEntity"
228
+ } = u;
229
229
  return {
230
230
  /** Fetch all entities from the hub. */
231
- async fetchAll(u) {
232
- return e.invoke(a, t, u);
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(u) {
236
- return e.invoke(r, t, u);
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(u, f) {
240
- return e.invoke(s, t, u, f);
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(u) {
244
- return e.invoke(o, t, u);
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 Te(i, e, t) {
253
- const n = new Map(i.map((a) => [a[t], a]));
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(i) {
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: s = 3e4,
282
- idleTimeout: o = 6e4,
283
- awayTimeout: u = 3e5,
284
- joinMethod: f = "JoinEntityView",
285
- leaveMethod: b = "LeaveEntityView",
286
- updateMethod: y = "UpdateEntityPresence",
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: C = "EntityUserJoined",
289
- leftEventName: q = "EntityUserLeft",
290
- onPresenceChange: L,
291
- onEditConflict: Q
292
- } = i, [G, X] = O([]), [U, H] = O(r), [R, _] = O(), [Z, J] = O(e.status), I = ae(Date.now()), Y = ae(null), $ = ae(null), B = ae(null), P = Array.isArray(n) ? n : [n], oe = `${t}:${P.sort().join(",")}`, j = m(
293
- async (c, k, w) => {
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(y, {
296
+ await e.invoke(w, {
297
297
  entityType: t,
298
- entityIds: P,
298
+ entityIds: p,
299
299
  userId: a.id,
300
- status: c,
301
- editingField: k,
302
- selection: w,
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, y, t, P, a.id]
309
- ), F = m(
310
- (c, k) => {
311
- H(c), _(k), j(c, k), I.current = Date.now();
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
- [j]
314
- ), ee = m(
315
- (c) => {
316
- const k = G.find(
317
- (w) => w.user.id !== a.id && w.status === "editing" && w.editingField === c
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
- k && (Q == null || Q(k.user, c)), F("editing", c);
319
+ T && (X == null || X(T.user, m)), F("editing", m);
320
320
  },
321
- [G, a.id, Q, F]
322
- ), ne = m(() => {
321
+ [q, a.id, X, F]
322
+ ), re = h(() => {
323
323
  F("viewing", void 0);
324
- }, [F]), d = m(
325
- (c) => {
326
- j(U, R, c), I.current = Date.now();
324
+ }, [F]), y = h(
325
+ (m) => {
326
+ J(U, x, m), B.current = Date.now();
327
327
  },
328
- [j, U, R]
329
- ), v = m(
330
- (c) => {
331
- const k = G.find(
332
- (w) => w.user.id !== a.id && w.status === "editing" && w.editingField === c
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 (k == null ? void 0 : k.user) ?? null;
334
+ return (T == null ? void 0 : T.user) ?? null;
335
335
  },
336
- [G, a.id]
337
- ), E = m(
338
- (c) => {
339
- const k = G.find((w) => w.status === "editing" && w.editingField === c);
340
- return (k == null ? void 0 : k.user) ?? null;
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
- [G]
343
- ), S = m(async () => {
342
+ [q]
343
+ ), C = h(async () => {
344
344
  if (e.status === "connected")
345
345
  try {
346
- const c = await e.invoke("GetEntityPresence", t, P);
347
- Array.isArray(c) && (X(c), L == null || L(c));
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, P, L]), g = m(() => {
351
- I.current = Date.now(), $.current && clearTimeout($.current), B.current && clearTimeout(B.current), (U === "idle" || U === "away") && F(R ? "editing" : "viewing", R), $.current = setTimeout(() => {
352
- F("idle", R);
353
- }, o), B.current = setTimeout(() => {
354
- F("away", R);
355
- }, u);
356
- }, [U, R, o, u, F]), N = m(
357
- (c) => {
358
- c.entityType !== t || !c.entityIds.some((w) => P.includes(w)) || (X(c.presence.filter((w) => w.user.id !== a.id)), L == null || L(c.presence));
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, P, a.id, L]
361
- ), A = m(
362
- (c) => {
363
- c.entityType !== t || !c.entityIds.some((w) => P.includes(w)) || c.presence.user.id === a.id || X((w) => {
364
- const se = w.findIndex((re) => re.user.id === c.presence.user.id);
365
- if (se >= 0) {
366
- const re = [...w];
367
- return re[se] = c.presence, re;
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 [...w, c.presence];
369
+ return [...s, m.presence];
370
370
  });
371
371
  },
372
- [t, P, a.id]
373
- ), K = m(
374
- (c) => {
375
- c.entityType !== t || !c.entityIds.some((w) => P.includes(w)) || X((w) => w.filter((se) => se.user.id !== c.userId));
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, P]
377
+ [t, p]
378
378
  );
379
- W(() => {
380
- const c = e.onStatusChange(J);
381
- e.on(V, N), e.on(C, A), e.on(q, K);
382
- const k = async () => {
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(f, {
385
+ await e.invoke(g, {
386
386
  entityType: t,
387
- entityIds: P,
387
+ entityIds: p,
388
388
  user: a,
389
389
  status: U
390
- }), await S();
390
+ }), await C();
391
391
  } catch {
392
392
  }
393
393
  };
394
- return e.status === "connected" && k(), () => {
395
- c(), e.off(V, N), e.off(C, A), e.off(q, K), e.status === "connected" && e.invoke(b, {
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: P,
397
+ entityIds: p,
398
398
  userId: a.id
399
399
  }).catch(() => {
400
400
  });
401
401
  };
402
402
  }, [
403
403
  e,
404
- oe,
405
- f,
406
- b,
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
- P
418
- ]), W(() => (Y.current = setInterval(() => {
419
- j(U, R);
420
- }, s), () => {
421
- Y.current && clearInterval(Y.current);
422
- }), [s, j, U, R]), W(() => {
423
- const c = ["mousemove", "keydown", "mousedown", "touchstart", "scroll"];
424
- return c.forEach((k) => window.addEventListener(k, g, { passive: !0 })), $.current = setTimeout(() => {
425
- F("idle", R);
426
- }, o), B.current = setTimeout(() => {
427
- F("away", R);
428
- }, u), () => {
429
- c.forEach((k) => window.removeEventListener(k, g)), $.current && clearTimeout($.current), B.current && clearTimeout(B.current);
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
- }, [g, o, u, R, F]);
432
- const te = G.filter((c) => c.status === "viewing" || c.status === "idle").map((c) => c.user), le = G.filter((c) => c.status === "editing").map((c) => c.user), ue = le.length > 0;
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: G,
435
- viewers: te,
436
- editors: le,
434
+ presence: q,
435
+ viewers: se,
436
+ editors: ie,
437
437
  myStatus: U,
438
438
  setMyStatus: F,
439
- startEditing: ee,
440
- stopEditing: ne,
441
- updateSelection: d,
442
- connectionStatus: Z,
443
- isFieldLocked: v,
439
+ startEditing: ne,
440
+ stopEditing: re,
441
+ updateSelection: y,
442
+ connectionStatus: ae,
443
+ isFieldLocked: k,
444
444
  hasActiveEditors: ue,
445
- getFieldEditor: E,
446
- refresh: S
445
+ getFieldEditor: P,
446
+ refresh: C
447
447
  };
448
448
  }
449
- function fe(i) {
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 < i.length; n++)
474
- t = i.charCodeAt(n) + ((t << 5) - 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 xe(i) {
478
- switch (i) {
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 Re(i) {
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
- } = i, [r, s] = O(/* @__PURE__ */ new Map()), o = m(
498
- (y) => {
499
- y.entityType === t && s(new Map(Object.entries(y.presenceByEntity)));
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
- W(() => (e.on(a, o), () => {
504
- e.off(a, o);
505
- }), [e, a, o]);
506
- const u = m(
507
- (y) => r.get(y) ?? [],
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
- ), f = m(
510
- (y) => {
511
- const V = r.get(y);
512
- return (V == null ? void 0 : V.some((C) => C.status === "editing" && C.user.id !== n.id)) ?? !1;
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
- ), b = m(
516
- (y) => {
517
- const V = r.get(y);
518
- return (V == null ? void 0 : V.filter((C) => C.status === "editing").map((C) => C.user)) ?? [];
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: u,
525
- isEntityBeingEdited: f,
526
- getEntityEditors: b
524
+ getPresence: c,
525
+ isEntityBeingEdited: g,
526
+ getEntityEditors: v
527
527
  };
528
528
  }
529
- function M(i) {
530
- return `${String(i.rowKey)}:${i.field}`;
529
+ function G(u) {
530
+ return `${String(u.rowKey)}:${u.field}`;
531
531
  }
532
- function me(i) {
533
- return i ? typeof i == "number" ? i : new Date(i).getTime() : Date.now();
532
+ function fe(u) {
533
+ return u ? typeof u == "number" ? u : new Date(u).getTime() : Date.now();
534
534
  }
535
- function De(i) {
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: s = "last-write-wins",
543
- mergeFunction: o,
544
- onConflict: u,
545
- onBeforeCommit: f,
546
- onAfterCommit: b,
547
- enableCellLocking: y = !0,
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: C = !0,
550
- cursorDebounce: q = 50,
551
- optimisticUpdates: L = !0,
552
- flashChanges: Q = !0,
553
- flashDuration: G = 500,
554
- liveDataOptions: X = {}
555
- } = i, [U, H] = O(/* @__PURE__ */ new Map()), [R, _] = O(/* @__PURE__ */ new Map()), [Z, J] = O([]), [I, Y] = O(null), [$, B] = O([]), [P, oe] = O([]), [j, F] = O(null), [ee, ne] = O([]), d = ae(null), v = ae(/* @__PURE__ */ new Map()), E = m((l) => (v.current.has(l) || v.current.set(l, fe(l)), v.current.get(l)), []), S = m(
556
- (l, h, p) => {
557
- if (!p.changes) return h;
558
- const T = R.get(M({ rowKey: p.key, field: Object.keys(p.changes)[0] }));
559
- if (!T) return h;
560
- const D = T.timestamp, x = me(p.timestamp);
561
- switch (s) {
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 D > x ? "local" : "remote";
563
+ return M > D ? "local" : "remote";
564
564
  case "first-write-wins":
565
- return D < x ? "local" : "remote";
565
+ return M < D ? "local" : "remote";
566
566
  case "merge":
567
- return o ? o(l, h, Object.keys(p.changes)[0]) : "merge";
567
+ return l ? l(i, f, Object.keys(d.changes)[0]) : "merge";
568
568
  case "ask-user":
569
- const z = {
570
- cell: { rowKey: p.key, field: Object.keys(p.changes)[0] },
571
- localValue: T.newValue,
572
- remoteValue: p.changes[Object.keys(p.changes)[0]],
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: p.changedBy ? { id: p.changedBy, name: p.changedBy } : { id: "unknown", name: "Unknown" },
575
- localTimestamp: D,
576
- remoteTimestamp: x
574
+ remoteUser: d.changedBy ? { id: d.changedBy, name: d.changedBy } : { id: "unknown", name: "Unknown" },
575
+ localTimestamp: M,
576
+ remoteTimestamp: D
577
577
  };
578
- return J((ie) => [...ie, z]), "local";
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
- [R, s, o, a]
587
- ), g = he({
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: Q,
593
- flashDuration: G,
594
- optimisticUpdates: L,
595
- onConflict: S,
596
- ...X
597
- }), N = pe({
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
- }), A = m(() => {
605
- !C || e.status !== "connected" || e.invoke("UpdateGridSelection", {
604
+ }), R = h(() => {
605
+ !O || e.status !== "connected" || e.invoke("UpdateGridSelection", {
606
606
  entityType: t,
607
607
  userId: a.id,
608
- focusedCell: I,
609
- selectedCells: $,
610
- selectedRows: P,
611
- editingCell: j
608
+ focusedCell: B,
609
+ selectedCells: L,
610
+ selectedRows: p,
611
+ editingCell: J
612
612
  }).catch(() => {
613
613
  });
614
- }, [e, C, t, a.id, I, $, P, j]);
615
- W(() => {
616
- if (C)
617
- return d.current && clearTimeout(d.current), d.current = setTimeout(A, q), () => {
618
- d.current && clearTimeout(d.current);
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
- }, [C, A, q, I, $, P, j]), W(() => {
621
- if (!C) return;
622
- const l = (h) => {
623
- h.entityType !== t || h.userId === a.id || ne((p) => {
624
- const T = p.findIndex((x) => x.user.id === h.userId), D = {
625
- user: { id: h.userId, name: h.userName, avatarUrl: h.avatarUrl },
626
- focusedCell: h.focusedCell,
627
- selectedCells: h.selectedCells,
628
- selectedRows: h.selectedRows,
629
- editingCell: h.editingCell,
630
- color: E(h.userId)
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 (T >= 0) {
633
- const x = [...p];
634
- return x[T] = D, x;
632
+ if (A >= 0) {
633
+ const D = [...d];
634
+ return D[A] = M, D;
635
635
  }
636
- return [...p, D];
636
+ return [...d, M];
637
637
  });
638
638
  };
639
- return e.on("GridSelectionUpdated", l), () => {
640
- e.off("GridSelectionUpdated", l);
639
+ return e.on("GridSelectionUpdated", i), () => {
640
+ e.off("GridSelectionUpdated", i);
641
641
  };
642
- }, [e, C, t, a.id, E]), W(() => {
643
- if (!y) return;
644
- const l = (p) => {
645
- p.entityType === t && H((T) => {
646
- const D = new Map(T);
647
- return D.set(M(p.cell), { user: p.user, timestamp: p.timestamp }), D;
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
- }, h = (p) => {
650
- p.entityType === t && H((T) => {
651
- const D = new Map(T);
652
- return D.delete(M(p.cell)), D;
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", l), e.on("CellUnlocked", h), () => {
656
- e.off("CellLocked", l), e.off("CellUnlocked", h);
655
+ return e.on("CellLocked", i), e.on("CellUnlocked", f), () => {
656
+ e.off("CellLocked", i), e.off("CellUnlocked", f);
657
657
  };
658
- }, [e, y, t]), W(() => {
659
- if (!y) return;
660
- const l = setInterval(() => {
661
- const h = Date.now();
662
- H((p) => {
663
- const T = new Map(p);
664
- let D = !1;
665
- for (const [x, z] of T)
666
- h - z.timestamp > V && (T.delete(x), D = !0);
667
- return D ? T : p;
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(l);
671
- }, [y, V]);
672
- const K = m(
673
- (l) => {
674
- if (!y) return !1;
675
- const h = U.get(M(l));
676
- return h ? h.user.id !== a.id && Date.now() - h.timestamp < V : !1;
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
- [y, U, a.id, V]
679
- ), te = m(
680
- (l) => {
681
- const h = U.get(M(l));
682
- return !h || Date.now() - h.timestamp > V ? null : h.user;
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
- ), le = m(
686
- (l) => K(l) ? !1 : (F(l), N.startEditing(`${l.rowKey}:${l.field}`), y && e.status === "connected" && (e.invoke("AcquireCellLock", {
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: l,
688
+ cell: i,
689
689
  user: a,
690
690
  timestamp: Date.now()
691
691
  }).catch(() => {
692
- }), H((h) => {
693
- const p = new Map(h);
694
- return p.set(M(l), { user: a, timestamp: Date.now() }), p;
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
- [K, N, y, e, t, a]
697
- ), ue = m(
698
- async (l, h) => {
699
- const p = g.data.find((x) => x[n] === l.rowKey);
700
- if (!p) return !1;
701
- const T = p[l.field];
702
- if (f && !await f(l, T, h))
703
- return c(l), !1;
704
- const D = {
705
- cell: l,
706
- originalValue: T,
707
- newValue: h,
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
- _((x) => {
711
- const z = new Map(x);
712
- return z.set(M(l), D), z;
713
- }), L && g.registerPendingChange(l.rowKey, { [l.field]: h });
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: l.rowKey,
718
- field: l.field,
719
- value: h,
717
+ entityId: i.rowKey,
718
+ field: i.field,
719
+ value: f,
720
720
  userId: a.id,
721
- timestamp: D.timestamp
722
- }), g.confirmPendingChange(l.rowKey), _((x) => {
723
- const z = new Map(x);
724
- return z.delete(M(l)), z;
725
- }), b == null || b(l, h), y && (e.invoke("ReleaseCellLock", { entityType: t, cell: l }).catch(() => {
726
- }), H((x) => {
727
- const z = new Map(x);
728
- return z.delete(M(l)), z;
729
- })), F(null), N.stopEditing(), !0;
730
- } catch (x) {
731
- throw g.rollbackPendingChange(l.rowKey), _((z) => {
732
- const ie = new Map(z);
733
- return ie.delete(M(l)), ie;
734
- }), x;
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
- g,
738
+ S,
739
739
  n,
740
- f,
741
- L,
740
+ g,
741
+ N,
742
742
  e,
743
743
  t,
744
744
  a.id,
745
- b,
746
- y,
747
- N
745
+ v,
746
+ w,
747
+ I
748
748
  ]
749
- ), c = m(
750
- (l) => {
751
- F(null), N.stopEditing(), y && e.status === "connected" && (e.invoke("ReleaseCellLock", { entityType: t, cell: l }).catch(() => {
752
- }), H((h) => {
753
- const p = new Map(h);
754
- return p.delete(M(l)), p;
755
- })), _((h) => {
756
- const p = new Map(h);
757
- return p.delete(M(l)), p;
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
- [N, y, e, t]
761
- ), k = m(
762
- (l, h) => {
763
- const p = Z.find((T) => M(T.cell) === M(l));
764
- p && (h === "remote" && g.applyRemoteUpdate({
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: l.rowKey,
768
- changes: { [l.field]: p.remoteValue }
769
- }), J((T) => T.filter((D) => M(D.cell) !== M(l))));
767
+ key: i.rowKey,
768
+ changes: { [i.field]: d.remoteValue }
769
+ }), j((A) => A.filter((M) => G(M.cell) !== G(i))));
770
770
  },
771
- [Z, g, t]
772
- ), w = m(
773
- async (l) => {
774
- await e.invoke("InsertEntity", t, l);
771
+ [ae, S, t]
772
+ ), s = h(
773
+ async (i) => {
774
+ await e.invoke("InsertEntity", t, i);
775
775
  },
776
776
  [e, t]
777
- ), se = m(
778
- async (l, h) => {
779
- L && g.registerPendingChange(l, h);
777
+ ), b = h(
778
+ async (i, f) => {
779
+ N && S.registerPendingChange(i, f);
780
780
  try {
781
- await e.invoke("UpdateEntity", t, l, h), g.confirmPendingChange(l);
782
- } catch (p) {
783
- throw g.rollbackPendingChange(l), p;
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, L, g]
787
- ), re = m(
788
- async (l) => {
789
- await e.invoke("DeleteEntity", t, l);
786
+ [e, t, N, S]
787
+ ), $ = h(
788
+ async (i) => {
789
+ await e.invoke("DeleteEntity", t, i);
790
790
  },
791
791
  [e, t]
792
- ), ce = de(
792
+ ), ee = de(
793
793
  () => ({
794
794
  user: a,
795
- focusedCell: I,
796
- selectedCells: $,
797
- selectedRows: P,
798
- editingCell: j,
799
- color: E(a.id)
795
+ focusedCell: B,
796
+ selectedCells: L,
797
+ selectedRows: p,
798
+ editingCell: J,
799
+ color: P(a.id)
800
800
  }),
801
- [a, I, $, P, j, E]
801
+ [a, B, L, p, J, P]
802
802
  );
803
803
  return {
804
- data: g.data,
805
- presence: N.presence,
806
- userSelections: ee,
807
- mySelection: ce,
808
- flashedKeys: g.flashedKeys,
809
- pendingEdits: R,
810
- connectionStatus: g.status,
811
- myPresenceStatus: N.myStatus,
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: Y,
814
- setSelectedCells: B,
815
- setSelectedRows: oe,
813
+ setFocusedCell: _,
814
+ setSelectedCells: z,
815
+ setSelectedRows: le,
816
816
  // Edit methods
817
- startCellEdit: le,
817
+ startCellEdit: ie,
818
818
  commitCellEdit: ue,
819
- cancelCellEdit: c,
820
- isCellLocked: K,
821
- getCellEditor: te,
822
- getUserColor: E,
819
+ cancelCellEdit: m,
820
+ isCellLocked: H,
821
+ getCellEditor: se,
822
+ getUserColor: P,
823
823
  // Row methods
824
- insertRow: w,
825
- updateRow: se,
826
- deleteRow: re,
824
+ insertRow: s,
825
+ updateRow: b,
826
+ deleteRow: $,
827
827
  // Conflict handling
828
- resolveConflict: k,
829
- conflicts: Z
828
+ resolveConflict: T,
829
+ conflicts: ae
830
830
  };
831
831
  }
832
- class Ae {
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 Le {
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((s) => a.append("files", s)), t && a.append("folder", t);
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, s) => {
949
- const o = new XMLHttpRequest(), u = new FormData();
950
- if (u.append("file", e), n && u.append("folder", n), a) {
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
- s(new DOMException("Aborted", "AbortError"));
952
+ o(new DOMException("Aborted", "AbortError"));
953
953
  return;
954
954
  }
955
955
  a.addEventListener("abort", () => {
956
- o.abort(), s(new DOMException("Aborted", "AbortError"));
956
+ l.abort(), o(new DOMException("Aborted", "AbortError"));
957
957
  });
958
958
  }
959
- o.upload.addEventListener("progress", (b) => {
959
+ l.upload.addEventListener("progress", (v) => {
960
960
  t({
961
- loaded: b.loaded,
962
- total: b.total,
963
- percent: b.lengthComputable ? b.loaded / b.total : NaN
961
+ loaded: v.loaded,
962
+ total: v.total,
963
+ percent: v.lengthComputable ? v.loaded / v.total : NaN
964
964
  });
965
- }), o.addEventListener("load", () => {
966
- if (o.status >= 200 && o.status < 300)
965
+ }), l.addEventListener("load", () => {
966
+ if (l.status >= 200 && l.status < 300)
967
967
  try {
968
- r(JSON.parse(o.responseText));
968
+ r(JSON.parse(l.responseText));
969
969
  } catch {
970
- s(new Error("Invalid JSON response"));
970
+ o(new Error("Invalid JSON response"));
971
971
  }
972
972
  else
973
- s(new Error(`File upload failed: ${o.status}`));
974
- }), o.addEventListener("error", () => s(new Error("Network error during upload"))), o.addEventListener("abort", () => s(new DOMException("Aborted", "AbortError"))), o.open("POST", this.cfg.baseUrl);
975
- const f = await this.headers();
976
- Object.entries(f).forEach(([b, y]) => o.setRequestHeader(b, y)), o.send(u);
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 s = 0; s < e.length; s++) {
985
+ for (let o = 0; o < e.length; o++) {
986
986
  if (a != null && a.aborted) throw new DOMException("Aborted", "AbortError");
987
- const o = await this.uploadWithProgress(
988
- e[s],
989
- (u) => t(s, u),
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(o);
993
+ r.push(l);
994
994
  }
995
995
  return r;
996
996
  }
997
997
  }
998
- class Ue {
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 o;
1026
+ var l;
1027
1027
  const n = await this.requestExport(e);
1028
- if (!((o = n.data) != null && o.downloadUrl)) throw new Error("No download URL returned");
1029
- const a = await this.download(n.data.downloadUrl), r = URL.createObjectURL(a), s = document.createElement("a");
1030
- s.href = r, s.download = t ?? `export.${e.format}`, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(r);
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 Fe(i) {
1033
+ function Ue(u) {
1034
1034
  return (e) => {
1035
1035
  const t = e ?? globalThis.fetch;
1036
1036
  return (a, r) => {
1037
- const u = { url: typeof a == "string" ? a : a instanceof URL ? a.toString() : a.url, init: r ?? {}, meta: {} };
1038
- let f = (b) => t(b.url, b.init);
1039
- for (let b = i.length - 1; b >= 0; b--) {
1040
- const y = i[b], V = f;
1041
- f = (C) => y(C, V);
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 f(u);
1043
+ return g(c);
1044
1044
  };
1045
1045
  };
1046
1046
  }
1047
- function Oe() {
1048
- return async (i, e) => {
1049
- const t = performance.now(), n = (i.init.method ?? "GET").toUpperCase();
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(i), r = (performance.now() - t).toFixed(1);
1052
- return console.debug(`[ERP] ${n} ${i.url} → ${a.status} (${r}ms)`), a;
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} ${i.url} FAILED (${r}ms)`, a), a;
1055
+ throw console.error(`[ERP] ${n} ${u.url} FAILED (${r}ms)`, a), a;
1056
1056
  }
1057
1057
  };
1058
1058
  }
1059
- function Ne(i) {
1060
- const e = (i == null ? void 0 : i.maxRetries) ?? 3, t = (i == null ? void 0 : i.baseDelay) ?? 500, n = new Set((i == null ? void 0 : i.retryOn) ?? [408, 429, 500, 502, 503, 504]);
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 s;
1063
- for (let o = 0; o <= e; o++) {
1062
+ let o;
1063
+ for (let l = 0; l <= e; l++) {
1064
1064
  try {
1065
- const f = await r(a);
1066
- if (f.ok || !n.has(f.status) || o === e)
1067
- return f;
1068
- s = new Error(`HTTP ${f.status}`);
1069
- } catch (f) {
1070
- if (s = f, o === e) throw f;
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 u = t * Math.pow(2, o) * (0.5 + Math.random() * 0.5);
1073
- await new Promise((f) => setTimeout(f, u));
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 s;
1075
+ throw o;
1076
1076
  };
1077
1077
  }
1078
- function Me(i) {
1078
+ function Ie(u) {
1079
1079
  return async (e, t) => {
1080
- const n = typeof i == "function" ? await i() : i;
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 Ie {
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 $e {
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 s = await this.adapter.create(e);
1179
- return s.success ? (this.items = this.items.map(
1180
- (o) => o[this.keyField] === t ? s.data : o
1181
- ), r.status = "confirmed", r.entityId = s.data[this.keyField]) : (this.items = this.items.filter(
1182
- (o) => o[this.keyField] !== t
1183
- ), r.status = "failed", r.error = s.error), this.notify(), s;
1184
- } catch (s) {
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
- (o) => o[this.keyField] !== t
1187
- ), r.status = "failed", r.error = s instanceof Error ? s.message : String(s), this.notify(), s;
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
- (o) => o[this.keyField] === e
1194
- ), a = n >= 0 ? { ...this.items[n] } : void 0, s = {
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
- (o, u) => u === n ? { ...o, ...t } : o
1204
- )), this.mutations.push(s), this.notify();
1203
+ (l, c) => c === n ? { ...l, ...t } : l
1204
+ )), this.mutations.push(o), this.notify();
1205
1205
  try {
1206
- const o = await this.adapter.update(e, t);
1207
- return o.success ? (this.items = this.items.map(
1208
- (u) => u[this.keyField] === e ? o.data : u
1209
- ), s.status = "confirmed") : (a && n >= 0 && (this.items = this.items.map(
1210
- (u) => u[this.keyField] === e ? a : u
1211
- )), s.status = "failed", s.error = o.error), this.notify(), o;
1212
- } catch (o) {
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
- (u) => u[this.keyField] === e ? a : u
1215
- )), s.status = "failed", s.error = o instanceof Error ? o.message : String(o), this.notify(), o;
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
- (s) => s[this.keyField] === e
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
- (s) => s[this.keyField] !== e
1231
+ (o) => o[this.keyField] !== e
1232
1232
  ), this.mutations.push(r), this.notify();
1233
1233
  try {
1234
- const s = await this.adapter.remove(e);
1235
- return s.success ? r.status = "confirmed" : (n && this.items.splice(t, 0, n), r.status = "failed", r.error = s.error), this.notify(), s;
1236
- } catch (s) {
1237
- throw n && this.items.splice(t, 0, n), r.status = "failed", r.error = s instanceof Error ? s.message : String(s), this.notify(), s;
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 Be {
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 s, o;
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(), (o = (s = this.config).onQueued) == null || o.call(s, r), Promise.resolve(new Response(
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
- ], ke = [
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
- ], Se = [
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
- ...ke,
1817
- ...Se
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
- Ae as ErpAuthAdapter,
1821
- Ve as ErpDataAdapter,
1822
- Ue as ErpExportAdapter,
1823
- Le as ErpFileAdapter,
1824
- Be as ErpOfflineQueue,
1825
- $e as ErpOptimisticStore,
1826
- Ie as ErpRateLimiter,
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
- Te as applyBatchChanges,
2175
+ Ae as applyBatchChanges,
1829
2176
  ye as audioControlRegistry,
1830
- ke as authControlRegistry,
2177
+ Se as authControlRegistry,
1831
2178
  ve as businessControlRegistry,
1832
- Fe as createMiddlewarePipeline,
1833
- Ce as createSignalRAdapter,
2179
+ Ue as createMiddlewarePipeline,
2180
+ Ve as createSignalRAdapter,
1834
2181
  Pe as createSignalRDataOperations,
1835
- xe as formatPresenceStatus,
2182
+ Oe as formatPresenceStatus,
1836
2183
  we as gamificationControlRegistry,
1837
- fe as generateUserColor,
2184
+ me as generateUserColor,
1838
2185
  be as graphicControlRegistry,
1839
- Me as headerMiddleware,
1840
- Oe as loggingMiddleware,
1841
- Ne as retryMiddleware,
1842
- Se as socialControlRegistry,
2186
+ Ie as headerMiddleware,
2187
+ Fe as loggingMiddleware,
2188
+ Me as retryMiddleware,
2189
+ ke as socialControlRegistry,
1843
2190
  ge as threeControlRegistry,
1844
- De as useCollaborativeDataGrid,
2191
+ Le as useCollaborativeDataGrid,
1845
2192
  pe as useEntityPresence,
1846
- Re as useMultiEntityPresence,
2193
+ Je as useLoanApi,
2194
+ xe as useMultiEntityPresence,
1847
2195
  he as useSignalRLiveData
1848
2196
  };
1849
2197
  //# sourceMappingURL=index.mjs.map