@floegence/floe-webapp-core 0.35.8 → 0.35.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,79 +1,94 @@
1
- import { createComponent as X } from "solid-js/web";
2
- import { createMemo as b, createEffect as Y, on as Z, createSignal as C, useContext as $, createContext as ee, batch as E } from "solid-js";
3
- import { createStore as te, reconcile as v, produce as M } from "solid-js/store";
4
- import { deferNonBlocking as p } from "../../utils/defer.js";
1
+ import { createComponent as Y } from "solid-js/web";
2
+ import { createMemo as p, createEffect as Z, on as $, createSignal as b, useContext as ee, createContext as te, batch as F } from "solid-js";
3
+ import { createStore as oe, reconcile as T, produce as M } from "solid-js/store";
4
+ import { deferNonBlocking as k } from "../../utils/defer.js";
5
5
  import { DEFAULT_VIRTUAL_LIST_CONFIG as se } from "./types.js";
6
- const F = ee();
6
+ const z = te();
7
7
  function Ce() {
8
- const o = $(F);
9
- if (!o)
8
+ const n = ee(z);
9
+ if (!n)
10
10
  throw new Error("useChatContext must be used within a ChatProvider");
11
- return o;
11
+ return n;
12
12
  }
13
- const Me = (o) => {
14
- const S = b(() => ({
13
+ const xe = (n) => {
14
+ const C = p(() => ({
15
15
  placeholder: "Type a message...",
16
16
  allowAttachments: !0,
17
17
  maxAttachments: 10,
18
18
  maxAttachmentSize: 10485760,
19
19
  // 10MB
20
- ...o.config
21
- })), d = b(() => ({
20
+ ...n.config
21
+ })), u = p(() => ({
22
22
  ...se,
23
- ...o.config?.virtualList
24
- })), [c, u] = te(o.initialMessages || []), z = /* @__PURE__ */ new Map();
25
- Y(Z(() => o.initialMessages, (e) => {
26
- e && e.length > 0 && u(v(e));
23
+ ...n.config?.virtualList
24
+ })), [a, l] = oe(n.initialMessages || []), B = /* @__PURE__ */ new Map(), R = p(() => {
25
+ const e = /* @__PURE__ */ new Map();
26
+ for (let t = 0; t < a.length; t += 1) {
27
+ const o = a[t]?.id;
28
+ o && e.set(o, t);
29
+ }
30
+ return e;
31
+ }), x = (e) => {
32
+ const t = R().get(e);
33
+ if (t !== void 0) return t;
34
+ const o = a.findIndex((s) => s.id === e);
35
+ return o >= 0 ? o : void 0;
36
+ };
37
+ Z($(() => n.initialMessages, (e) => {
38
+ e && e.length > 0 && l(T(e));
27
39
  }, {
28
40
  defer: !0
29
41
  }));
30
- const [A, H] = C(!1), [P, R] = C(!0), [L, x] = C(null), [B, I] = C(0);
31
- let D = 0;
32
- const g = /* @__PURE__ */ new Set(), h = [], f = /* @__PURE__ */ new Map(), O = (e) => {
42
+ const [A, H] = b(!1), [P, D] = b(!0), [L, S] = b(null), [O, I] = b(0);
43
+ let j = 0;
44
+ const g = /* @__PURE__ */ new Set(), f = [], h = /* @__PURE__ */ new Map(), q = (e) => {
33
45
  if (!g.delete(e)) return;
34
- const t = h.indexOf(e);
35
- t >= 0 && h.splice(t, 1), I(g.size);
36
- }, j = () => {
37
- const e = ++D;
38
- return g.add(e), h.push(e), I(g.size), e;
39
- }, q = () => {
40
- for (; h.length > 0; ) {
41
- const e = h.shift();
46
+ const t = f.indexOf(e);
47
+ t >= 0 && f.splice(t, 1), I(g.size);
48
+ }, N = () => {
49
+ const e = ++j;
50
+ return g.add(e), f.push(e), I(g.size), e;
51
+ }, W = () => {
52
+ for (; f.length > 0; ) {
53
+ const e = f.shift();
42
54
  if (e === void 0) return;
43
55
  if (g.has(e)) {
44
56
  g.delete(e), I(g.size);
45
57
  return;
46
58
  }
47
59
  }
48
- }, U = b(() => B() > 0), N = b(() => U() || L() !== null), k = (e) => {
49
- u(M((t) => {
60
+ }, U = p(() => O() > 0), _ = p(() => U() || L() !== null), y = (e) => {
61
+ l(M((t) => {
50
62
  t.push(e);
51
63
  }));
52
- }, l = (e, t) => {
53
- u(M((s) => {
54
- const n = s.findIndex((a) => a.id === e);
55
- n !== -1 && (s[n] = t(s[n]));
56
- }));
57
- }, W = (e) => {
58
- u(M((t) => {
59
- const s = t.findIndex((n) => n.id === e);
60
- s !== -1 && t.splice(s, 1);
61
- })), f.delete(e);
62
- }, _ = () => {
63
- u(v([])), f.clear();
64
+ }, E = (e, t) => {
65
+ const o = x(e);
66
+ o !== void 0 && l(o, (s) => t(s));
64
67
  }, V = (e) => {
65
- u(v(e));
68
+ const t = x(e);
69
+ t !== void 0 && (l(M((o) => {
70
+ o.splice(t, 1);
71
+ })), h.delete(e));
72
+ }, G = () => {
73
+ l(T([])), h.clear();
74
+ }, Q = (e) => {
75
+ l(T(e));
76
+ }, i = (e, t) => {
77
+ const o = x(e);
78
+ o !== void 0 && l(o, M((s) => {
79
+ t(s);
80
+ }));
66
81
  };
67
- let T = [], w = null;
68
- const G = () => {
69
- const e = T;
70
- T = [], w = null, E(() => {
71
- e.forEach(Q);
82
+ let v = [], w = null;
83
+ const J = () => {
84
+ const e = v;
85
+ v = [], w = null, F(() => {
86
+ e.forEach(K);
72
87
  });
73
- }, Q = (e) => {
88
+ }, K = (e) => {
74
89
  switch (e.type) {
75
90
  case "message-start": {
76
- q();
91
+ W();
77
92
  const t = {
78
93
  id: e.messageId,
79
94
  role: "assistant",
@@ -81,105 +96,94 @@ const Me = (o) => {
81
96
  status: "streaming",
82
97
  timestamp: Date.now()
83
98
  };
84
- k(t), x(e.messageId);
99
+ y(t), S(e.messageId);
85
100
  break;
86
101
  }
87
102
  case "block-start": {
88
- l(e.messageId, (t) => ({
89
- ...t,
90
- blocks: [...t.blocks, ne(e.blockType)]
91
- }));
103
+ i(e.messageId, (t) => {
104
+ t.blocks.push(ne(e.blockType));
105
+ });
92
106
  break;
93
107
  }
94
108
  case "block-delta": {
95
- l(e.messageId, (t) => {
96
- const s = [...t.blocks], n = s[e.blockIndex];
97
- return n && "content" in n && typeof n.content == "string" && (n.content += e.delta), {
98
- ...t,
99
- blocks: s
100
- };
109
+ i(e.messageId, (t) => {
110
+ const o = t.blocks[e.blockIndex];
111
+ o && "content" in o && typeof o.content == "string" && (o.content += e.delta);
101
112
  });
102
113
  break;
103
114
  }
104
115
  case "block-set": {
105
- l(e.messageId, (t) => {
106
- const s = [...t.blocks];
107
- return e.blockIndex === s.length ? s.push(e.block) : e.blockIndex >= 0 && e.blockIndex < s.length && (s[e.blockIndex] = e.block), {
108
- ...t,
109
- blocks: s
110
- };
116
+ i(e.messageId, (t) => {
117
+ e.blockIndex === t.blocks.length ? t.blocks.push(e.block) : e.blockIndex >= 0 && e.blockIndex < t.blocks.length && (t.blocks[e.blockIndex] = e.block);
111
118
  });
112
119
  break;
113
120
  }
114
121
  case "block-end":
115
122
  break;
116
123
  case "message-end": {
117
- l(e.messageId, (t) => ({
118
- ...t,
119
- status: "complete"
120
- })), x(null);
124
+ i(e.messageId, (t) => {
125
+ t.status = "complete";
126
+ }), S(null);
121
127
  break;
122
128
  }
123
129
  case "error": {
124
- l(e.messageId, (t) => ({
125
- ...t,
126
- status: "error",
127
- error: e.error
128
- })), x(null);
130
+ i(e.messageId, (t) => {
131
+ t.status = "error", t.error = e.error;
132
+ }), S(null);
129
133
  break;
130
134
  }
131
135
  }
132
- }, J = {
133
- messages: () => c,
134
- coldMessages: z,
136
+ }, X = {
137
+ messages: () => a,
138
+ coldMessages: B,
135
139
  isLoadingHistory: A,
136
140
  hasMoreHistory: P,
137
141
  streamingMessageId: L,
138
142
  isPreparing: U,
139
- isWorking: N,
140
- config: S,
141
- virtualListConfig: d,
143
+ isWorking: _,
144
+ config: C,
145
+ virtualListConfig: u,
142
146
  sendMessage: async (e, t = []) => {
143
- const s = {
147
+ const o = {
144
148
  id: crypto.randomUUID(),
145
149
  role: "user",
146
- blocks: oe(e, t),
150
+ blocks: re(e, t),
147
151
  status: "sending",
148
152
  timestamp: Date.now()
149
153
  };
150
- E(() => {
151
- k(s), l(s.id, (i) => ({
152
- ...i,
154
+ F(() => {
155
+ y(o), E(o.id, (c) => ({
156
+ ...c,
153
157
  status: "complete"
154
158
  }));
155
159
  });
156
160
  try {
157
- o.callbacks?.onWillSend?.(e, t);
158
- } catch (i) {
159
- console.error("onWillSend error:", i);
161
+ n.callbacks?.onWillSend?.(e, t);
162
+ } catch (c) {
163
+ console.error("onWillSend error:", c);
160
164
  }
161
- const n = o.callbacks?.onSendMessage;
162
- if (!n) return;
163
- const a = j(), r = e, m = [...t];
164
- p(() => {
165
- Promise.resolve().then(() => n(r, m, k)).catch((i) => {
166
- console.error("Failed to send message:", i);
165
+ const s = n.callbacks?.onSendMessage;
166
+ if (!s) return;
167
+ const d = N(), r = e, m = [...t];
168
+ k(() => {
169
+ Promise.resolve().then(() => s(r, m, y)).catch((c) => {
170
+ console.error("Failed to send message:", c);
167
171
  }).finally(() => {
168
- O(a);
172
+ q(d);
169
173
  });
170
174
  });
171
175
  },
172
176
  loadMoreHistory: async () => {
173
177
  if (A() || !P()) return;
174
- const e = o.callbacks?.onLoadMore;
175
- e && (H(!0), p(() => {
178
+ const e = n.callbacks?.onLoadMore;
179
+ e && (H(!0), k(() => {
176
180
  Promise.resolve(e()).then((t) => {
177
181
  if (t.length === 0) {
178
- R(!1);
182
+ D(!1);
179
183
  return;
180
184
  }
181
- u(M((s) => {
182
- s.unshift(...t);
185
+ l(M((o) => {
186
+ o.unshift(...t);
183
187
  }));
184
188
  }).catch((t) => {
185
189
  console.error("Failed to load history:", t);
@@ -189,106 +193,87 @@ const Me = (o) => {
189
193
  }));
190
194
  },
191
195
  retryMessage: (e) => {
192
- const t = o.callbacks?.onRetry;
193
- t && p(() => {
196
+ const t = n.callbacks?.onRetry;
197
+ t && k(() => {
194
198
  try {
195
199
  t(e);
196
- } catch (s) {
197
- console.error("Failed to retry message:", s);
200
+ } catch (o) {
201
+ console.error("Failed to retry message:", o);
198
202
  }
199
203
  });
200
204
  },
201
- addMessage: k,
202
- updateMessage: l,
203
- deleteMessage: W,
204
- clearMessages: _,
205
- setMessages: V,
205
+ addMessage: y,
206
+ updateMessage: E,
207
+ deleteMessage: V,
208
+ clearMessages: G,
209
+ setMessages: Q,
206
210
  handleStreamEvent: (e) => {
207
- T.push(e), w || (w = requestAnimationFrame(G));
211
+ v.push(e), w || (w = requestAnimationFrame(J));
208
212
  },
209
213
  uploadAttachment: async (e) => {
210
- const t = o.callbacks?.onUploadAttachment;
214
+ const t = n.callbacks?.onUploadAttachment;
211
215
  return t ? await t(e) : URL.createObjectURL(e);
212
216
  },
213
217
  toggleToolCollapse: (e, t) => {
214
- l(e, (s) => ({
215
- ...s,
216
- blocks: s.blocks.map((n) => {
217
- if (n.type === "tool-call" && n.toolId === t) {
218
- const a = n.collapsed === void 0 ? !1 : !n.collapsed;
219
- return {
220
- ...n,
221
- collapsed: a
222
- };
218
+ i(e, (o) => {
219
+ for (const s of o.blocks)
220
+ if (s.type === "tool-call" && s.toolId === t) {
221
+ s.collapsed = s.collapsed === void 0 ? !1 : !s.collapsed;
222
+ break;
223
223
  }
224
- return n;
225
- })
226
- }));
224
+ });
227
225
  },
228
- approveToolCall: (e, t, s) => {
229
- l(e, (a) => ({
230
- ...a,
231
- blocks: a.blocks.map((r) => r.type !== "tool-call" || r.toolId !== t || r.requiresApproval !== !0 || r.approvalState !== "required" ? r : s ? {
232
- ...r,
233
- approvalState: "approved",
234
- status: "running"
235
- } : {
236
- ...r,
237
- approvalState: "rejected",
238
- status: "error",
239
- error: r.error || "Rejected by user"
240
- })
241
- }));
242
- const n = o.callbacks?.onToolApproval;
243
- n && p(() => {
244
- Promise.resolve(n(e, t, s)).catch((a) => {
245
- console.error("Failed to approve tool call:", a);
226
+ approveToolCall: (e, t, o) => {
227
+ i(e, (d) => {
228
+ for (const r of d.blocks)
229
+ if (!(r.type !== "tool-call" || r.toolId !== t) && !(r.requiresApproval !== !0 || r.approvalState !== "required")) {
230
+ o ? (r.approvalState = "approved", r.status = "running") : (r.approvalState = "rejected", r.status = "error", r.error = r.error || "Rejected by user");
231
+ break;
232
+ }
233
+ });
234
+ const s = n.callbacks?.onToolApproval;
235
+ s && k(() => {
236
+ Promise.resolve(s(e, t, o)).catch((d) => {
237
+ console.error("Failed to approve tool call:", d);
246
238
  });
247
239
  });
248
240
  },
249
- heightCache: f,
241
+ heightCache: h,
250
242
  setMessageHeight: (e, t) => {
251
- f.set(e, t);
243
+ h.set(e, t);
252
244
  },
253
- getMessageHeight: (e) => f.get(e) || d().defaultItemHeight,
254
- toggleChecklistItem: (e, t, s) => {
255
- let n = null;
256
- l(e, (r) => {
257
- const m = [...r.blocks], i = m[t];
258
- if (i && i.type === "checklist") {
259
- const K = i.items.map((y) => y.id === s ? (n = !y.checked, {
260
- ...y,
261
- checked: n
262
- }) : y);
263
- m[t] = {
264
- ...i,
265
- items: K
266
- };
245
+ getMessageHeight: (e) => h.get(e) || u().defaultItemHeight,
246
+ toggleChecklistItem: (e, t, o) => {
247
+ let s = null;
248
+ i(e, (r) => {
249
+ const m = r.blocks[t];
250
+ if (m && m.type === "checklist") {
251
+ for (const c of m.items)
252
+ if (c.id === o) {
253
+ s = !c.checked, c.checked = s;
254
+ break;
255
+ }
267
256
  }
268
- return {
269
- ...r,
270
- blocks: m
271
- };
272
257
  });
273
- const a = o.callbacks?.onChecklistChange;
274
- !a || n === null || p(() => {
258
+ const d = n.callbacks?.onChecklistChange;
259
+ !d || s === null || k(() => {
275
260
  try {
276
- a(e, t, s, n);
261
+ d(e, t, o, s);
277
262
  } catch (r) {
278
263
  console.error("Failed to handle checklist change:", r);
279
264
  }
280
265
  });
281
266
  }
282
267
  };
283
- return X(F.Provider, {
284
- value: J,
268
+ return Y(z.Provider, {
269
+ value: X,
285
270
  get children() {
286
- return o.children;
271
+ return n.children;
287
272
  }
288
273
  });
289
274
  };
290
- function ne(o) {
291
- switch (o) {
275
+ function ne(n) {
276
+ switch (n) {
292
277
  case "text":
293
278
  return {
294
279
  type: "text",
@@ -364,26 +349,26 @@ function ne(o) {
364
349
  };
365
350
  }
366
351
  }
367
- function oe(o, S) {
368
- const d = [];
369
- for (const c of S)
370
- c.type === "image" ? d.push({
352
+ function re(n, C) {
353
+ const u = [];
354
+ for (const a of C)
355
+ a.type === "image" ? u.push({
371
356
  type: "image",
372
- src: c.url || c.preview || "",
373
- alt: c.file.name
374
- }) : d.push({
357
+ src: a.url || a.preview || "",
358
+ alt: a.file.name
359
+ }) : u.push({
375
360
  type: "file",
376
- name: c.file.name,
377
- size: c.file.size,
378
- mimeType: c.file.type,
379
- url: c.url
361
+ name: a.file.name,
362
+ size: a.file.size,
363
+ mimeType: a.file.type,
364
+ url: a.url
380
365
  });
381
- return o.trim() && d.push({
366
+ return n.trim() && u.push({
382
367
  type: "text",
383
- content: o.trim()
384
- }), d;
368
+ content: n.trim()
369
+ }), u;
385
370
  }
386
371
  export {
387
- Me as ChatProvider,
372
+ xe as ChatProvider,
388
373
  Ce as useChatContext
389
374
  };
@@ -1,379 +1,411 @@
1
- import { createComponent as ot } from "solid-js/web";
2
- import { createSignal as p, createEffect as I, createMemo as z, useContext as it, createContext as st, untrack as rt } from "solid-js";
3
- import { useResolvedFloeConfig as ct } from "../../context/FloeConfigContext.js";
4
- import { deferAfterPaint as at, deferNonBlocking as y } from "../../utils/defer.js";
5
- const ue = st(), b = {
1
+ import { createComponent as pt } from "solid-js/web";
2
+ import { createSignal as p, createEffect as I, createMemo as z, useContext as St, createContext as gt, untrack as It } from "solid-js";
3
+ import { createStore as ae, produce as le } from "solid-js/store";
4
+ import { useResolvedFloeConfig as wt } from "../../context/FloeConfigContext.js";
5
+ import { deferAfterPaint as yt, deferNonBlocking as y } from "../../utils/defer.js";
6
+ const ye = gt(), E = {
6
7
  name: 0.65,
7
8
  modifiedAt: 0.2,
8
9
  size: 0.15
9
- }, oe = "fileBrowser:listColumnRatios", ie = 220, lt = "fileBrowser:sidebarWidth", dt = 160, ft = 520, se = "fileBrowser:viewMode", re = "fileBrowser:sortConfig", ce = "fileBrowser:expandedFolders", ae = "fileBrowser:sidebarCollapsed";
10
- function le(n, r) {
11
- const s = typeof n == "number" && Number.isFinite(n) ? n : r;
12
- return Math.max(dt, Math.min(ft, Math.round(s)));
10
+ }, de = "fileBrowser:listColumnRatios", fe = 220, xt = "fileBrowser:sidebarWidth", Ct = 160, Pt = 520, ue = "fileBrowser:viewMode", me = "fileBrowser:sortConfig", he = "fileBrowser:expandedFolders", pe = "fileBrowser:sidebarCollapsed";
11
+ function Se(n, i) {
12
+ const o = typeof n == "number" && Number.isFinite(n) ? n : i;
13
+ return Math.max(Ct, Math.min(Pt, Math.round(o)));
13
14
  }
14
- function ut(n, r) {
15
- return n === "list" || n === "grid" ? n : r;
15
+ function At(n, i) {
16
+ return n === "list" || n === "grid" ? n : i;
16
17
  }
17
- function mt(n, r) {
18
- if (!n || typeof n != "object") return r;
19
- const s = n, f = s.field, l = s.direction;
20
- return !(f === "name" || f === "size" || f === "modifiedAt" || f === "type") || !(l === "asc" || l === "desc") ? r : {
21
- field: f,
18
+ function Et(n, i) {
19
+ if (!n || typeof n != "object") return i;
20
+ const o = n, d = o.field, l = o.direction;
21
+ return !(d === "name" || d === "size" || d === "modifiedAt" || d === "type") || !(l === "asc" || l === "desc") ? i : {
22
+ field: d,
22
23
  direction: l
23
24
  };
24
25
  }
25
- function ht(n) {
26
+ function bt(n) {
26
27
  if (!Array.isArray(n)) return ["/"];
27
- const r = [], s = /* @__PURE__ */ new Set();
28
- for (const f of n) {
29
- if (typeof f != "string") continue;
30
- const l = f.trim();
31
- !l || s.has(l) || (s.add(l), r.push(l));
28
+ const i = [], o = /* @__PURE__ */ new Set();
29
+ for (const d of n) {
30
+ if (typeof d != "string") continue;
31
+ const l = d.trim();
32
+ !l || o.has(l) || (o.add(l), i.push(l));
32
33
  }
33
- return s.has("/") || r.unshift("/"), r;
34
+ return o.has("/") || i.unshift("/"), i;
34
35
  }
35
- function de(n) {
36
- const r = Number.isFinite(n.name) ? n.name : b.name, s = Number.isFinite(n.modifiedAt) ? n.modifiedAt : b.modifiedAt, f = Number.isFinite(n.size) ? n.size : b.size, l = Math.max(0, r), m = Math.max(0, s), C = Math.max(0, f), w = l + m + C;
37
- return w <= 0 ? b : {
38
- name: l / w,
39
- modifiedAt: m / w,
40
- size: C / w
36
+ function Mt(n) {
37
+ const i = [], o = /* @__PURE__ */ new Set();
38
+ for (const d of n) {
39
+ if (typeof d != "string") continue;
40
+ const l = d.trim();
41
+ !l || o.has(l) || (o.add(l), i.push(l));
42
+ }
43
+ return i;
44
+ }
45
+ function ge(n) {
46
+ const i = {};
47
+ for (const o of n)
48
+ i[o] = !0;
49
+ return i;
50
+ }
51
+ function Ft(n, i) {
52
+ if (n.length !== i.length) return !1;
53
+ for (let o = 0; o < n.length; o += 1)
54
+ if (n[o] !== i[o]) return !1;
55
+ return !0;
56
+ }
57
+ function Ie(n) {
58
+ const i = Number.isFinite(n.name) ? n.name : E.name, o = Number.isFinite(n.modifiedAt) ? n.modifiedAt : E.modifiedAt, d = Number.isFinite(n.size) ? n.size : E.size, l = Math.max(0, i), u = Math.max(0, o), x = Math.max(0, d), g = l + u + x;
59
+ return g <= 0 ? E : {
60
+ name: l / g,
61
+ modifiedAt: u / g,
62
+ size: x / g
41
63
  };
42
64
  }
43
- function fe(n, r) {
44
- if (!r) return [];
45
- const s = [];
46
- let f = 0;
47
- for (const l of r) {
48
- const m = n.indexOf(l, f);
49
- if (m === -1) return null;
50
- s.push(m), f = m + 1;
65
+ function we(n, i) {
66
+ if (!i) return [];
67
+ const o = [];
68
+ let d = 0;
69
+ for (const l of i) {
70
+ const u = n.indexOf(l, d);
71
+ if (u === -1) return null;
72
+ o.push(u), d = u + 1;
51
73
  }
52
- return s;
74
+ return o;
53
75
  }
54
- function Ct(n) {
55
- const r = ct(), s = (e) => {
76
+ function zt(n) {
77
+ const i = wt(), o = (e) => {
56
78
  const t = (e ?? "").trim();
57
79
  return t === "" ? "/" : t;
58
- }, f = (n.persistenceKey ?? "").trim(), l = !!f, m = (e) => f ? `${f}:${e}` : e, C = l ? ut(r.persist.load(m(se), n.initialViewMode ?? "list"), n.initialViewMode ?? "list") : n.initialViewMode ?? "list", w = {
80
+ }, d = (n.persistenceKey ?? "").trim(), l = !!d, u = (e) => d ? `${d}:${e}` : e, x = l ? At(i.persist.load(u(ue), n.initialViewMode ?? "list"), n.initialViewMode ?? "list") : n.initialViewMode ?? "list", g = {
59
81
  field: "name",
60
82
  direction: "asc"
61
- }, me = l ? mt(r.persist.load(m(re), w), w) : w, he = l ? ht(r.persist.load(m(ce), ["/"])) : ["/"], pe = l ? r.persist.load(m(ae), !1) === !0 : !1, Se = () => typeof n.path == "string" ? s(n.path) : s(n.initialPath ?? "/"), [x, D] = p(Se()), [E, M] = p(/* @__PURE__ */ new Set()), [N, we] = p(C), [F, Ie] = p(me), ge = de(r.persist.load(oe, n.initialListColumnRatios ?? b)), [W, ye] = p(ge), K = (n.sidebarWidthStorageKey ?? "").trim() || lt, Ce = le(r.persist.load(K, n.initialSidebarWidth ?? ie), n.initialSidebarWidth ?? ie), [U, xe] = p(Ce), [v, k] = p(new Set(he)), [V, Ae] = p(pe), [Pe, G] = p(null), [X, Y] = p(""), [_, R] = p(""), [be, q] = p(!1);
62
- let L = 0;
83
+ }, xe = l ? Et(i.persist.load(u(me), g), g) : g, D = l ? bt(i.persist.load(u(he), ["/"])) : ["/"], Ce = l ? i.persist.load(u(pe), !1) === !0 : !1, Pe = () => typeof n.path == "string" ? o(n.path) : o(n.initialPath ?? "/"), [C, N] = p(Pe()), [W, Ae] = ae({}), [b, Ee] = p([]), [k, be] = p(x), [F, Me] = p(xe), Fe = Ie(i.persist.load(de, n.initialListColumnRatios ?? E)), [K, Le] = p(Fe), U = (n.sidebarWidthStorageKey ?? "").trim() || xt, _e = Se(i.persist.load(U, n.initialSidebarWidth ?? fe), n.initialSidebarWidth ?? fe), [V, ve] = p(_e), [L, G] = ae(ge(D)), [q, X] = p(D), [Y, Be] = p(Ce), [Re, j] = p(null), [Q, H] = p(""), [_, v] = p(""), [Oe, $] = p(!1);
84
+ let B = 0;
63
85
  I(() => {
64
- const e = X().trim();
65
- L += 1;
66
- const t = L;
86
+ const e = Q().trim();
87
+ B += 1;
88
+ const t = B;
67
89
  if (!e) {
68
- R("");
90
+ v("");
69
91
  return;
70
92
  }
71
- at(() => {
72
- t === L && R(e);
93
+ yt(() => {
94
+ t === B && v(e);
73
95
  });
74
96
  }), I(() => {
75
- r.persist.debouncedSave(oe, W());
97
+ i.persist.debouncedSave(de, K());
76
98
  }), I(() => {
77
- r.persist.debouncedSave(K, U());
99
+ i.persist.debouncedSave(U, V());
78
100
  }), I(() => {
79
- l && r.persist.debouncedSave(m(se), N());
101
+ l && i.persist.debouncedSave(u(ue), k());
80
102
  }), I(() => {
81
- l && r.persist.debouncedSave(m(re), F());
103
+ l && i.persist.debouncedSave(u(me), F());
82
104
  }), I(() => {
83
105
  if (!l) return;
84
- const e = [...v()].sort((t, o) => t.localeCompare(o));
85
- r.persist.debouncedSave(m(ce), e);
106
+ const e = [...q()].sort((t, r) => t.localeCompare(r));
107
+ i.persist.debouncedSave(u(he), e);
86
108
  }), I(() => {
87
- l && r.persist.debouncedSave(m(ae), V());
109
+ l && i.persist.debouncedSave(u(pe), Y());
88
110
  });
89
- const Ee = (e) => we(e), Me = (e) => Ie(e), Fe = () => n.homeLabel ?? "Root", [Q, A] = p([]);
90
- let g = null, B = {
111
+ const Te = (e) => be(e), ze = (e) => Me(e), De = () => n.homeLabel ?? "Root", Ne = () => new Set(b()), We = () => new Set(q()), M = (e) => {
112
+ const t = Mt(e), r = ge(t);
113
+ Ae(le((s) => {
114
+ for (const c of Object.keys(s))
115
+ c in r || delete s[c];
116
+ for (const c of t)
117
+ s[c] = !0;
118
+ })), Ee((s) => Ft(s, t) ? s : t);
119
+ }, J = (e) => {
120
+ L[e] !== !0 && (G(e, !0), X((t) => t.includes(e) ? t : [...t, e]));
121
+ }, ke = (e) => {
122
+ if (L[e] === !0) {
123
+ G(le((t) => {
124
+ delete t[e];
125
+ })), X((t) => t.filter((r) => r !== e));
126
+ return;
127
+ }
128
+ J(e);
129
+ }, [Z, P] = p([]);
130
+ let w = null, R = {
91
131
  top: 0,
92
132
  left: 0
93
133
  };
94
- const j = () => n.files, H = (e) => {
95
- const t = s(e);
134
+ const ee = () => n.files, te = (e) => {
135
+ const t = o(e);
96
136
  if (t === "/") return "/";
97
- const o = t.split("/").filter(Boolean);
98
- return o.pop(), o.length ? "/" + o.join("/") : "/";
99
- }, ve = (e, t) => {
100
- const o = Q();
101
- if (o.length === 0) return e;
102
- let i = [...e];
103
- const a = s(t);
104
- for (const c of o)
105
- switch (c.type) {
137
+ const r = t.split("/").filter(Boolean);
138
+ return r.pop(), r.length ? "/" + r.join("/") : "/";
139
+ }, Ke = (e, t) => {
140
+ const r = Z();
141
+ if (r.length === 0) return e;
142
+ let s = [...e];
143
+ const c = o(t);
144
+ for (const a of r)
145
+ switch (a.type) {
106
146
  case "remove": {
107
- const u = new Set(c.paths.map(s));
108
- i = i.filter((d) => !u.has(s(d.path)));
147
+ const m = new Set(a.paths.map(o));
148
+ s = s.filter((f) => !m.has(o(f.path)));
109
149
  break;
110
150
  }
111
151
  case "update": {
112
- const u = s(c.oldPath), d = i.findIndex((S) => s(S.path) === u);
113
- if (d !== -1) {
114
- const S = c.updates.path ?? i[d].path;
115
- H(S) === a ? i[d] = {
116
- ...i[d],
117
- ...c.updates
118
- } : i.splice(d, 1);
152
+ const m = o(a.oldPath), f = s.findIndex((S) => o(S.path) === m);
153
+ if (f !== -1) {
154
+ const S = a.updates.path ?? s[f].path;
155
+ te(S) === c ? s[f] = {
156
+ ...s[f],
157
+ ...a.updates
158
+ } : s.splice(f, 1);
119
159
  } else {
120
- const S = c.updates.path;
121
- S && H(S);
160
+ const S = a.updates.path;
161
+ S && te(S);
122
162
  }
123
163
  break;
124
164
  }
125
165
  case "insert": {
126
- s(c.parentPath) === a && (i.some((d) => s(d.path) === s(c.item.path)) || i.push(c.item));
166
+ o(a.parentPath) === c && (s.some((f) => o(f.path) === o(a.item.path)) || s.push(a.item));
127
167
  break;
128
168
  }
129
169
  }
130
- return i;
131
- }, _e = z(() => {
132
- const e = /* @__PURE__ */ new Map(), t = (i) => {
133
- for (const a of i)
134
- a.type === "folder" && (e.set(s(a.path), a.children ?? []), a.children?.length && t(a.children));
135
- }, o = j();
136
- return e.set("/", o), t(o), e;
137
- }), Re = z(() => {
138
- const e = s(x());
139
- let t = _e().get(e) ?? [];
140
- t = ve(t, e);
141
- const o = F(), i = [...t].sort((c, u) => {
142
- if (c.type !== u.type) return c.type === "folder" ? -1 : 1;
143
- let d = 0;
144
- switch (o.field) {
170
+ return s;
171
+ }, Ue = z(() => {
172
+ const e = /* @__PURE__ */ new Map(), t = (s) => {
173
+ for (const c of s)
174
+ c.type === "folder" && (e.set(o(c.path), c.children ?? []), c.children?.length && t(c.children));
175
+ }, r = ee();
176
+ return e.set("/", r), t(r), e;
177
+ }), Ve = z(() => {
178
+ const e = o(C());
179
+ let t = Ue().get(e) ?? [];
180
+ t = Ke(t, e);
181
+ const r = F(), s = [...t].sort((a, m) => {
182
+ if (a.type !== m.type) return a.type === "folder" ? -1 : 1;
183
+ let f = 0;
184
+ switch (r.field) {
145
185
  case "name":
146
- d = c.name.localeCompare(u.name);
186
+ f = a.name.localeCompare(m.name);
147
187
  break;
148
188
  case "size":
149
- d = (c.size ?? 0) - (u.size ?? 0);
189
+ f = (a.size ?? 0) - (m.size ?? 0);
150
190
  break;
151
191
  case "modifiedAt":
152
- d = (c.modifiedAt?.getTime() ?? 0) - (u.modifiedAt?.getTime() ?? 0);
192
+ f = (a.modifiedAt?.getTime() ?? 0) - (m.modifiedAt?.getTime() ?? 0);
153
193
  break;
154
194
  case "type":
155
- d = (c.extension ?? "").localeCompare(u.extension ?? "");
195
+ f = (a.extension ?? "").localeCompare(m.extension ?? "");
156
196
  break;
157
197
  }
158
- return o.direction === "asc" ? d : -d;
159
- }), a = /* @__PURE__ */ new Map();
160
- for (const c of i)
161
- a.set(c.id, c.name.toLowerCase());
198
+ return r.direction === "asc" ? f : -f;
199
+ }), c = /* @__PURE__ */ new Map();
200
+ for (const a of s)
201
+ c.set(a.id, a.name.toLowerCase());
162
202
  return {
163
- items: i,
164
- nameLowerById: a
203
+ items: s,
204
+ nameLowerById: c
165
205
  };
166
206
  }), O = z(() => {
167
207
  const {
168
208
  items: e,
169
209
  nameLowerById: t
170
- } = Re(), i = _().trim().toLowerCase(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
171
- if (!i) {
210
+ } = Ve(), s = _().trim().toLowerCase(), c = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
211
+ if (!s) {
172
212
  for (let h = 0; h < e.length; h++) {
173
- const P = e[h];
174
- c.set(P.id, P), u.set(P.id, h);
213
+ const A = e[h];
214
+ a.set(A.id, A), m.set(A.id, h);
175
215
  }
176
216
  return {
177
217
  items: e,
178
- matchById: a,
179
- fileById: c,
180
- indexById: u
218
+ matchById: c,
219
+ fileById: a,
220
+ indexById: m
181
221
  };
182
222
  }
183
- const d = [];
223
+ const f = [];
184
224
  let S = 0;
185
225
  for (const h of e) {
186
- const P = t.get(h.id) ?? h.name.toLowerCase(), ne = fe(P, i);
187
- ne && (d.push(h), a.set(h.id, {
188
- matchedIndices: ne
189
- }), c.set(h.id, h), u.set(h.id, S), S += 1);
226
+ const A = t.get(h.id) ?? h.name.toLowerCase(), ce = we(A, s);
227
+ ce && (f.push(h), c.set(h.id, {
228
+ matchedIndices: ce
229
+ }), a.set(h.id, h), m.set(h.id, S), S += 1);
190
230
  }
191
231
  return {
192
- items: d,
193
- matchById: a,
194
- fileById: c,
195
- indexById: u
232
+ items: f,
233
+ matchById: c,
234
+ fileById: a,
235
+ indexById: m
196
236
  };
197
- }), Le = () => O().items, $ = (e) => {
198
- const t = O(), o = [];
199
- for (const i of e) {
200
- const a = t.fileById.get(i);
201
- if (!a) continue;
202
- const c = t.indexById.get(i);
203
- o.push({
204
- index: c ?? Number.MAX_SAFE_INTEGER,
205
- item: a
237
+ }), Ge = () => O().items, ne = (e) => {
238
+ const t = O(), r = [];
239
+ for (const s of e) {
240
+ const c = t.fileById.get(s);
241
+ if (!c) continue;
242
+ const a = t.indexById.get(s);
243
+ r.push({
244
+ index: a ?? Number.MAX_SAFE_INTEGER,
245
+ item: c
206
246
  });
207
247
  }
208
- return o.sort((i, a) => i.index - a.index), o.map((i) => i.item);
209
- }, J = () => {
210
- M(/* @__PURE__ */ new Set()), Y(""), R(""), q(!1);
248
+ return r.sort((s, c) => s.index - c.index), r.map((s) => s.item);
249
+ }, oe = () => {
250
+ M([]), H(""), v(""), $(!1);
211
251
  const e = n.onSelect;
212
252
  y(() => e?.([]));
213
253
  };
214
254
  I(() => {
215
255
  if (typeof n.path != "string") return;
216
- const e = s(n.path);
217
- e !== x() && (D(e), J());
256
+ const e = o(n.path);
257
+ e !== C() && (N(e), oe());
218
258
  });
219
259
  const T = (e) => {
220
- const t = s(e);
221
- if (t === x()) return;
222
- D(t), J();
223
- const o = n.onNavigate;
224
- y(() => o?.(t));
225
- const i = n.onPathChange;
226
- y(() => i?.(t, "user"));
227
- }, Be = (e) => {
228
- ye(de(e));
229
- }, Oe = () => {
230
- const e = x();
260
+ const t = o(e);
261
+ if (t === C()) return;
262
+ N(t), oe();
263
+ const r = n.onNavigate;
264
+ y(() => r?.(t));
265
+ const s = n.onPathChange;
266
+ y(() => s?.(t, "user"));
267
+ }, qe = (e) => {
268
+ Le(Ie(e));
269
+ }, Xe = () => {
270
+ const e = C();
231
271
  if (e === "/" || e === "") return;
232
272
  const t = e.split("/").filter(Boolean);
233
273
  t.pop(), T(t.length ? "/" + t.join("/") : "/");
234
- }, Z = (e) => {
235
- e.type === "folder" && (T(e.path), k((t) => {
236
- const o = new Set(t);
237
- return o.add(e.path), o;
238
- }));
239
- }, Te = (e, t = !1) => {
240
- const o = E(), i = t ? new Set(o) : /* @__PURE__ */ new Set();
241
- t ? i.has(e) ? i.delete(e) : i.add(e) : (i.clear(), i.add(e)), M(i);
242
- const a = n.onSelect;
243
- if (a) {
244
- const c = new Set(i);
274
+ }, ie = (e) => {
275
+ e.type === "folder" && (T(e.path), J(e.path));
276
+ }, Ye = (e, t = !1) => {
277
+ const r = t ? W[e] === !0 ? b().filter((c) => c !== e) : [...b(), e] : [e];
278
+ M(r);
279
+ const s = n.onSelect;
280
+ if (s) {
281
+ const c = [...r];
245
282
  y(() => {
246
- const u = rt(() => $(c));
247
- a(u);
283
+ const a = It(() => ne(c));
284
+ s(a);
248
285
  });
249
286
  }
250
- }, ze = () => {
251
- M(/* @__PURE__ */ new Set());
287
+ }, je = () => {
288
+ M([]);
252
289
  const e = n.onSelect;
253
290
  y(() => e?.([]));
254
- }, De = (e) => E().has(e), Ne = (e) => {
255
- k((t) => {
256
- const o = new Set(t);
257
- return o.has(e) ? o.delete(e) : o.add(e), o;
258
- });
259
- }, We = (e) => v().has(e), Ke = () => Ae((e) => !e), Ue = (e) => {
260
- xe((t) => le(e, t));
261
- }, ke = (e) => G(e), Ve = () => G(null), Ge = (e) => {
262
- Y(e);
263
- }, Xe = (e) => {
291
+ }, Qe = (e) => W[e] === !0, He = (e) => ke(e), $e = (e) => L[e] === !0, Je = () => Be((e) => !e), Ze = (e) => {
292
+ ve((t) => Se(e, t));
293
+ }, et = (e) => j(e), tt = () => j(null), nt = (e) => {
294
+ H(e);
295
+ }, ot = (e) => {
264
296
  const t = _().trim();
265
297
  if (!t) return null;
266
- const o = fe(e.toLowerCase(), t.toLowerCase());
267
- return o ? {
268
- matchedIndices: o
298
+ const r = we(e.toLowerCase(), t.toLowerCase());
299
+ return r ? {
300
+ matchedIndices: r
269
301
  } : null;
270
- }, Ye = (e) => O().matchById.get(e) ?? null, qe = () => $(E()), Qe = (e) => {
302
+ }, it = (e) => O().matchById.get(e) ?? null, st = () => ne(b()), rt = (e) => {
271
303
  if (e.type === "folder")
272
- Z(e);
304
+ ie(e);
273
305
  else {
274
306
  const t = n.onOpen;
275
307
  y(() => t?.(e));
276
308
  }
277
- }, je = (e) => {
278
- e.length !== 0 && A((t) => [...t, {
309
+ }, ct = (e) => {
310
+ e.length !== 0 && P((t) => [...t, {
279
311
  type: "remove",
280
312
  paths: e
281
313
  }]);
282
- }, He = (e, t) => {
283
- A((o) => [...o, {
314
+ }, at = (e, t) => {
315
+ P((r) => [...r, {
284
316
  type: "update",
285
317
  oldPath: e,
286
318
  updates: t
287
319
  }]);
288
- }, $e = (e, t) => {
289
- A((o) => [...o, {
320
+ }, lt = (e, t) => {
321
+ P((r) => [...r, {
290
322
  type: "insert",
291
323
  parentPath: e,
292
324
  item: t
293
325
  }]);
294
- }, Je = () => {
295
- A([]);
296
- }, Ze = () => {
297
- A([]);
298
- }, et = () => Q().length > 0, tt = (e) => {
299
- g = e;
300
- }, ee = () => g ? {
301
- top: g.scrollTop,
302
- left: g.scrollLeft
326
+ }, dt = () => {
327
+ P([]);
328
+ }, ft = () => {
329
+ P([]);
330
+ }, ut = () => Z().length > 0, mt = (e) => {
331
+ w = e;
332
+ }, se = () => w ? {
333
+ top: w.scrollTop,
334
+ left: w.scrollLeft
303
335
  } : {
304
336
  top: 0,
305
337
  left: 0
306
- }, te = (e) => {
307
- g && (g.scrollTop = e.top, g.scrollLeft = e.left);
308
- }, nt = {
309
- currentPath: x,
338
+ }, re = (e) => {
339
+ w && (w.scrollTop = e.top, w.scrollLeft = e.left);
340
+ }, ht = {
341
+ currentPath: C,
310
342
  setCurrentPath: T,
311
- navigateUp: Oe,
312
- navigateTo: Z,
313
- homeLabel: Fe,
314
- selectedItems: () => E(),
315
- selectItem: Te,
316
- clearSelection: ze,
317
- isSelected: De,
318
- getSelectedItemsList: qe,
319
- viewMode: N,
320
- setViewMode: Ee,
343
+ navigateUp: Xe,
344
+ navigateTo: ie,
345
+ homeLabel: De,
346
+ selectedItems: Ne,
347
+ selectItem: Ye,
348
+ clearSelection: je,
349
+ isSelected: Qe,
350
+ getSelectedItemsList: st,
351
+ viewMode: k,
352
+ setViewMode: Te,
321
353
  sortConfig: F,
322
- setSortConfig: Me,
323
- listColumnRatios: W,
324
- setListColumnRatios: Be,
325
- expandedFolders: v,
326
- toggleFolder: Ne,
327
- isExpanded: We,
328
- files: j,
329
- currentFiles: Le,
330
- filterQuery: X,
331
- setFilterQuery: Ge,
354
+ setSortConfig: ze,
355
+ listColumnRatios: K,
356
+ setListColumnRatios: qe,
357
+ expandedFolders: We,
358
+ toggleFolder: He,
359
+ isExpanded: $e,
360
+ files: ee,
361
+ currentFiles: Ge,
362
+ filterQuery: Q,
363
+ setFilterQuery: nt,
332
364
  filterQueryApplied: _,
333
- isFilterActive: be,
334
- setFilterActive: q,
335
- getFilterMatch: Xe,
336
- getFilterMatchForId: Ye,
337
- sidebarCollapsed: V,
338
- toggleSidebar: Ke,
339
- sidebarWidth: U,
340
- setSidebarWidth: Ue,
341
- contextMenu: Pe,
342
- showContextMenu: ke,
343
- hideContextMenu: Ve,
344
- openItem: Qe,
365
+ isFilterActive: Oe,
366
+ setFilterActive: $,
367
+ getFilterMatch: ot,
368
+ getFilterMatchForId: it,
369
+ sidebarCollapsed: Y,
370
+ toggleSidebar: Je,
371
+ sidebarWidth: V,
372
+ setSidebarWidth: Ze,
373
+ contextMenu: Re,
374
+ showContextMenu: et,
375
+ hideContextMenu: tt,
376
+ openItem: rt,
345
377
  // Optimistic updates
346
- optimisticRemove: je,
347
- optimisticUpdate: He,
348
- optimisticInsert: $e,
349
- clearOptimisticUpdates: Je,
350
- rollbackOptimisticUpdates: Ze,
351
- hasOptimisticUpdates: et,
378
+ optimisticRemove: ct,
379
+ optimisticUpdate: at,
380
+ optimisticInsert: lt,
381
+ clearOptimisticUpdates: dt,
382
+ rollbackOptimisticUpdates: ft,
383
+ hasOptimisticUpdates: ut,
352
384
  // Scroll position management
353
- setScrollContainer: tt,
354
- getScrollPosition: ee,
355
- setScrollPosition: te,
356
- saveScrollPosition: () => (B = ee(), B),
385
+ setScrollContainer: mt,
386
+ getScrollPosition: se,
387
+ setScrollPosition: re,
388
+ saveScrollPosition: () => (R = se(), R),
357
389
  restoreScrollPosition: () => {
358
390
  requestAnimationFrame(() => {
359
- te(B);
391
+ re(R);
360
392
  });
361
393
  }
362
394
  };
363
- return ot(ue.Provider, {
364
- value: nt,
395
+ return pt(ye.Provider, {
396
+ value: ht,
365
397
  get children() {
366
398
  return n.children;
367
399
  }
368
400
  });
369
401
  }
370
- function xt() {
371
- const n = it(ue);
402
+ function Dt() {
403
+ const n = St(ye);
372
404
  if (!n)
373
405
  throw new Error("useFileBrowser must be used within a FileBrowserProvider");
374
406
  return n;
375
407
  }
376
408
  export {
377
- Ct as FileBrowserProvider,
378
- xt as useFileBrowser
409
+ zt as FileBrowserProvider,
410
+ Dt as useFileBrowser
379
411
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.35.8",
3
+ "version": "0.35.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",