@bfrs/agentic-components 0.7.6 → 0.7.8

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.
Files changed (30) hide show
  1. package/BFRS_AGENTIC_COMPONENTS.md +4 -2
  2. package/dist/components/data-display/DataTable/DataTable.js +6 -0
  3. package/dist/components/data-display/DataTable/DataTable.js.map +1 -1
  4. package/dist/components/data-display/DataTable/DataTable.types.d.ts +7 -0
  5. package/dist/components/data-display/DataTable/TableSaveView.js +158 -138
  6. package/dist/components/data-display/DataTable/TableSaveView.js.map +1 -1
  7. package/dist/components/data-display/DataTable/TableSkeleton.js +3 -1
  8. package/dist/components/data-display/DataTable/TableSkeleton.js.map +1 -1
  9. package/dist/components/data-display/DataTable/TableViewSelector.d.ts +1 -2
  10. package/dist/components/data-display/DataTable/TableViewSelector.js +290 -264
  11. package/dist/components/data-display/DataTable/TableViewSelector.js.map +1 -1
  12. package/dist/components/data-display/DataTable/saveViewApi.d.ts +13 -4
  13. package/dist/components/data-display/DataTable/saveViewApi.js +161 -146
  14. package/dist/components/data-display/DataTable/saveViewApi.js.map +1 -1
  15. package/dist/components/data-display/DataTable/useSavedViews.d.ts +8 -8
  16. package/dist/components/data-display/DataTable/useSavedViews.js +33 -51
  17. package/dist/components/data-display/DataTable/useSavedViews.js.map +1 -1
  18. package/dist/components/data-display/DataTable/viewCache.d.ts +75 -0
  19. package/dist/components/data-display/DataTable/viewCache.js +83 -0
  20. package/dist/components/data-display/DataTable/viewCache.js.map +1 -0
  21. package/dist/components/data-display/DataTable/viewStore.d.ts +14 -4
  22. package/dist/components/data-display/DataTable/viewStore.js +191 -188
  23. package/dist/components/data-display/DataTable/viewStore.js.map +1 -1
  24. package/dist/custom-elements.js +11080 -10972
  25. package/dist/custom-elements.js.map +1 -1
  26. package/package.json +1 -1
  27. package/dist/node_modules/@phosphor-icons/react/dist/csr/ArrowCounterClockwise.es.js +0 -11
  28. package/dist/node_modules/@phosphor-icons/react/dist/csr/ArrowCounterClockwise.es.js.map +0 -1
  29. package/dist/node_modules/@phosphor-icons/react/dist/defs/ArrowCounterClockwise.es.js +0 -31
  30. package/dist/node_modules/@phosphor-icons/react/dist/defs/ArrowCounterClockwise.es.js.map +0 -1
@@ -1,5 +1,6 @@
1
- import { createSaveView as F, deleteView as k, updateView as q, getView as G, listViews as H } from "./saveViewApi.js";
2
- const K = "bfrs.savedViews.", $ = 1, L = (t) => `${K}${encodeURIComponent(t)}`;
1
+ import { createSaveView as H, DEFAULT_SAVE_ENDPOINT as Q, deleteView as Y, updateView as Z, isUnauthorizedViewApiError as N, resolveApiToken as tt, listViews as et } from "./saveViewApi.js";
2
+ import { viewCacheKey as it, invalidateViewCache as A, readViewCache as z, evictViewCacheMemory as rt, writeViewCache as nt, fingerprintToken as st } from "./viewCache.js";
3
+ const ot = "bfrs.savedViews.", C = 1, P = (t) => `${ot}${encodeURIComponent(t)}`;
3
4
  function O() {
4
5
  try {
5
6
  return typeof window < "u" && !!window.localStorage;
@@ -7,27 +8,27 @@ function O() {
7
8
  return !1;
8
9
  }
9
10
  }
10
- function y(t) {
11
- const s = { version: $, views: [] };
11
+ function J(t) {
12
+ const s = { version: C, views: [] };
12
13
  if (!O()) return s;
13
14
  try {
14
- const f = window.localStorage.getItem(L(t));
15
- if (!f) return s;
16
- const l = JSON.parse(f);
17
- return !l || !Array.isArray(l.views) ? s : { version: $, views: l.views };
15
+ const d = window.localStorage.getItem(P(t));
16
+ if (!d) return s;
17
+ const f = JSON.parse(d);
18
+ return !f || !Array.isArray(f.views) ? s : { version: C, views: f.views, fingerprint: f.fingerprint };
18
19
  } catch {
19
20
  return s;
20
21
  }
21
22
  }
22
- function W(t, s) {
23
+ function L(t, s, d) {
23
24
  if (O())
24
25
  try {
25
- const f = { version: $, views: s };
26
- window.localStorage.setItem(L(t), JSON.stringify(f));
26
+ const f = { version: C, views: s, ...d ? { fingerprint: d } : {} };
27
+ window.localStorage.setItem(P(t), JSON.stringify(f));
27
28
  } catch {
28
29
  }
29
30
  }
30
- function V() {
31
+ function K() {
31
32
  try {
32
33
  const t = globalThis.crypto;
33
34
  if (t && typeof t.randomUUID == "function")
@@ -36,7 +37,7 @@ function V() {
36
37
  }
37
38
  return `view_${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`;
38
39
  }
39
- function g(t, s) {
40
+ function x(t, s) {
40
41
  return {
41
42
  ...s,
42
43
  ...t,
@@ -49,230 +50,232 @@ function g(t, s) {
49
50
  is_system_defined: (t == null ? void 0 : t.is_system_defined) ?? s.is_system_defined
50
51
  };
51
52
  }
52
- function P(t, s) {
53
+ function at(t, s) {
53
54
  return JSON.stringify(t) === JSON.stringify(s);
54
55
  }
55
- function U(t) {
56
- return t.length === 0 || t.some((s) => s.is_default) ? t : t.map((s, f) => f === 0 ? { ...s, is_default: !0 } : s);
56
+ const ct = /* @__PURE__ */ new Set(["default"]);
57
+ function dt(t) {
58
+ return ct.has(t.trim().toLowerCase());
57
59
  }
58
- const X = /* @__PURE__ */ new Set(["default"]);
59
- function j(t) {
60
- return X.has(t.trim().toLowerCase());
61
- }
62
- function M(t) {
63
- if (j(t))
60
+ function D(t) {
61
+ if (dt(t))
64
62
  throw new Error(`"${t.trim()}" is a reserved view name. Choose a different name.`);
65
63
  }
66
- function Q(t) {
64
+ function ft(t) {
67
65
  return !!(t.saveEndpoint || t.endpoint);
68
66
  }
69
- function Y(t) {
67
+ function k(t) {
70
68
  return !!(t != null && t.viewType && t.tab);
71
69
  }
72
- const h = /* @__PURE__ */ new Map();
73
- let T = !1;
74
- function Z(t) {
70
+ const m = /* @__PURE__ */ new Map();
71
+ let q = !1;
72
+ const $ = /* @__PURE__ */ new Map();
73
+ function ut(t) {
75
74
  var s;
76
- if (t.key === null) {
77
- h.forEach((f) => f.forEach((l) => l()));
75
+ if (rt(t.key), t.key === null) {
76
+ m.forEach((d) => d.forEach((f) => f()));
78
77
  return;
79
78
  }
80
- (s = h.get(t.key)) == null || s.forEach((f) => f());
79
+ (s = m.get(t.key)) == null || s.forEach((d) => d());
81
80
  }
82
- function A() {
83
- T || typeof window > "u" || (window.addEventListener("storage", Z), T = !0);
81
+ function lt() {
82
+ q || typeof window > "u" || (window.addEventListener("storage", ut), q = !0);
84
83
  }
85
- function D(t) {
84
+ function W(t) {
86
85
  var s;
87
- (s = h.get(t)) == null || s.forEach((f) => f());
86
+ (s = m.get(t)) == null || s.forEach((d) => d());
88
87
  }
89
- function N(t, s = {}) {
90
- return I(t, s, !1);
88
+ function wt(t, s = {}) {
89
+ return R(t, s, !1);
91
90
  }
92
- function et(t, s = {}) {
93
- return I(t, s, !0);
91
+ function pt(t, s = {}) {
92
+ return R(t, s, !0);
94
93
  }
95
- function I(t, s = {}, f) {
96
- const l = L(t), w = s.saveApi, c = f && Y(w) ? w : void 0, R = s.remoteSave ?? (f && w && Q(w) ? F(w) : void 0), x = c ? () => H(c) : void 0, v = c ? (e) => G({ ...c, viewId: e }) : void 0, B = c ? (e) => q({ ...c, payload: e }) : void 0, E = c ? (e) => k({ ...c, viewId: e }) : void 0;
97
- let b = null;
98
- const p = (e, n = !0) => {
99
- W(t, e), n && D(l);
100
- }, J = (e) => U(
101
- e.map(
102
- (n, i) => g(n, {
103
- view_id: n.view_id || V(),
104
- name: n.name || `View ${i + 1}`,
94
+ function R(t, s = {}, d) {
95
+ const f = P(t), l = s.saveApi, o = d && k(l) ? l : void 0, U = s.remoteSave ?? (d && l && (ft(l) || k(l)) ? H({ ...l, saveEndpoint: l.saveEndpoint ?? l.endpoint ?? Q }) : void 0), T = o ? () => et(o) : void 0, S = o ? (i) => Z({ ...o, payload: i }) : void 0, b = o ? (i) => Y({ ...o, viewId: i }) : void 0, p = o ? { viewType: o.viewType, tab: o.tab } : void 0, u = p ? it(p) : void 0, h = () => st(o ? tt(o) : ""), _ = () => {
96
+ const i = J(t);
97
+ return !o || i.fingerprint === void 0 || i.fingerprint === h() ? i.views : (L(t, [], h()), []);
98
+ }, X = () => {
99
+ if (!o) return;
100
+ const i = J(t);
101
+ i.fingerprint !== void 0 && i.fingerprint !== h() && L(t, [], h());
102
+ }, v = (i, r = !0) => {
103
+ L(t, i, o ? h() : void 0), r && W(f);
104
+ }, j = (i) => (
105
+ // No forced primary here: absence of a backend-marked default is a valid,
106
+ // stable state (the selector's "Default"/no-view state), not something to
107
+ // paper over by promoting whichever view happens to come first.
108
+ i.map(
109
+ (r, e) => x(r, {
110
+ view_id: r.view_id || K(),
111
+ name: r.name || `View ${e + 1}`,
105
112
  view_type: t,
106
- tab: c == null ? void 0 : c.tab,
107
- columns: n.columns ?? [],
108
- filters: n.filters ?? [],
109
- priority: n.priority ?? i,
110
- is_default: !!n.is_default,
111
- is_system_defined: !!n.is_system_defined
113
+ tab: o == null ? void 0 : o.tab,
114
+ columns: r.columns ?? [],
115
+ filters: r.filters ?? [],
116
+ priority: r.priority ?? e,
117
+ is_default: !!r.is_default,
118
+ is_system_defined: !!r.is_system_defined
112
119
  })
113
120
  )
114
- ), z = (e, n = !1) => {
115
- const i = y(t).views, o = new Map(i.map((a) => [a.view_id, a])), r = J(e).map((a) => {
116
- const S = o.get(a.view_id);
117
- return S ? { ...a, is_default: S.is_default } : a;
118
- }), u = r.some((a) => a.is_default), d = i.filter(
119
- (a) => !r.some((S) => S.view_id === a.view_id || S.name.trim() === a.name.trim())
120
- ).map((a) => u ? { ...a, is_default: !1 } : a), _ = [...r, ...d], m = i.length === 0 ? U(_) : _;
121
- return P(i, m) || p(m, n), m;
122
- }, C = (e) => {
123
- const n = y(t).views, i = {
124
- view_id: e.view_id || V(),
125
- name: e.name || "Primary view",
126
- view_type: t,
127
- tab: c == null ? void 0 : c.tab,
128
- columns: e.columns ?? [],
129
- filters: e.filters ?? [],
130
- priority: e.priority ?? 0,
131
- is_default: !0,
132
- is_system_defined: !!e.is_system_defined
133
- }, o = g({ ...e, is_default: !0 }, i), r = n.findIndex((d) => d.view_id === o.view_id || d.name.trim() === o.name.trim()), u = r >= 0 ? n.map((d, _) => _ === r ? o : { ...d, is_default: !1 }) : [{ ...o, is_default: !0 }, ...n.map((d) => ({ ...d, is_default: !1 }))];
134
- return P(n, u) || p(u, !0), o;
121
+ ), F = (i, r = !1) => {
122
+ const e = _(), n = j(i);
123
+ return at(e, n) || v(n, r), n;
124
+ }, B = () => {
125
+ if (!T || !u || !p) return Promise.resolve(_());
126
+ const i = $.get(u);
127
+ if (i) return i;
128
+ const r = h(), e = T().then((n) => {
129
+ const a = F(n, !0);
130
+ return nt(u, { scope: p, fingerprint: r, views: a }), a;
131
+ }).catch((n) => {
132
+ if (N(n))
133
+ throw A(u), n;
134
+ const a = z(u, p, r);
135
+ return a.status === "miss" ? _() : a.views;
136
+ }).finally(() => {
137
+ $.get(u) === e && $.delete(u);
138
+ });
139
+ return $.set(u, e), e;
140
+ }, I = () => {
141
+ if (X(), !T || !u || !p) return Promise.resolve(_());
142
+ const i = z(u, p, h());
143
+ return i.status === "hit" ? Promise.resolve(F(i.views, !1)) : B();
144
+ }, g = () => {
145
+ u && A(u);
146
+ }, M = async (i, r) => {
147
+ const e = (await I()).find((c) => c.view_id === i);
148
+ if (!e) throw new Error(`View "${i}" not found for screen "${t}"`);
149
+ if (S) {
150
+ await S({
151
+ view_id: e.view_id,
152
+ view_type: t,
153
+ tab: o == null ? void 0 : o.tab,
154
+ name: e.name,
155
+ columns: e.columns,
156
+ filters: e.filters,
157
+ priority: e.priority,
158
+ is_default: r
159
+ }), g();
160
+ const w = (await B()).find((y) => y.view_id === i);
161
+ if (!w || w.is_default !== r)
162
+ throw new Error(
163
+ `The backend did not persist is_default=${r} for view "${e.name}". Saved views still show it as ${w ? `is_default=${w.is_default}` : "missing"}.`
164
+ );
165
+ return w;
166
+ }
167
+ const n = _(), a = r ? n.map((c) => ({ ...c, is_default: c.view_id === i })) : n.map((c) => c.view_id === i ? { ...c, is_default: !1 } : c);
168
+ return v(a), { ...e, is_default: r };
135
169
  };
136
170
  return {
137
171
  async list() {
138
- return x ? (b || (b = x().then((e) => z(e, !0)).catch(() => y(t).views).finally(() => {
139
- b = null;
140
- })), b) : y(t).views;
172
+ return I();
141
173
  },
142
- async get(e) {
143
- const n = y(t).views, i = n.find((r) => r.view_id === e) ?? null;
144
- if (v) {
145
- try {
146
- const r = await v(e);
147
- if (r) {
148
- const u = i ?? {
149
- view_id: r.view_id || e,
150
- name: r.name || "",
151
- view_type: t,
152
- tab: c == null ? void 0 : c.tab,
153
- columns: [],
154
- filters: [],
155
- priority: 0,
156
- is_default: !1,
157
- is_system_defined: !1
158
- };
159
- return g(r, u);
160
- }
161
- } catch {
162
- }
163
- return i;
164
- }
165
- return (x ? await this.list() : n).find((r) => r.view_id === e) ?? null;
174
+ async get(i) {
175
+ return (await this.list()).find((e) => e.view_id === i) ?? null;
166
176
  },
167
177
  async getActive() {
168
- if (v)
169
- try {
170
- const e = await v();
171
- return e ? C(e) : null;
172
- } catch {
173
- }
174
- return y(t).views.find((e) => e.is_default) ?? null;
178
+ return (await this.list()).find((r) => r.is_default) ?? null;
175
179
  },
176
- async save(e) {
177
- M(e.name);
178
- const n = {
179
- ...e,
180
+ async save(i) {
181
+ D(i.name);
182
+ const r = {
183
+ ...i,
180
184
  view_type: t,
181
- tab: (f ? w == null ? void 0 : w.tab : void 0) ?? e.tab,
182
- filters: e.filters ?? []
183
- }, i = R ? await R(n) : void 0, o = y(t).views, r = o.findIndex((_) => _.name.trim() === n.name.trim());
184
- if (r >= 0) {
185
- const _ = {
186
- ...o[r],
187
- name: n.name,
185
+ tab: (d ? l == null ? void 0 : l.tab : void 0) ?? i.tab,
186
+ filters: i.filters ?? []
187
+ }, e = U ? await U(r) : void 0, n = _(), a = n.findIndex(
188
+ (y) => y.name.trim() === r.name.trim() || (e == null ? void 0 : e.view.view_id) && y.view_id === e.view.view_id
189
+ );
190
+ if (a >= 0) {
191
+ const y = {
192
+ ...n[a],
193
+ name: r.name,
188
194
  view_type: t,
189
- tab: n.tab,
190
- columns: n.columns,
191
- filters: n.filters ?? [],
192
- priority: n.priority ?? o[r].priority
193
- }, m = g(i == null ? void 0 : i.view, _), a = o.slice();
194
- return a[r] = m, p(a), { view: m, alreadyExists: (i == null ? void 0 : i.alreadyExists) ?? !0 };
195
+ tab: r.tab,
196
+ columns: r.columns,
197
+ filters: r.filters ?? [],
198
+ priority: r.priority ?? n[a].priority
199
+ }, E = x(e == null ? void 0 : e.view, y), V = n.slice();
200
+ return V[a] = E, g(), v(V), { view: E, alreadyExists: (e == null ? void 0 : e.alreadyExists) ?? !0, message: e == null ? void 0 : e.message };
195
201
  }
196
- const u = {
197
- view_id: V(),
198
- name: n.name,
202
+ const c = {
203
+ view_id: K(),
204
+ name: r.name,
199
205
  view_type: t,
200
- tab: n.tab,
201
- columns: n.columns,
202
- filters: n.filters ?? [],
203
- priority: n.priority ?? 0,
206
+ tab: r.tab,
207
+ columns: r.columns,
208
+ filters: r.filters ?? [],
209
+ priority: r.priority ?? 0,
204
210
  // First view for a screen becomes primary so there is always an active view.
205
- is_default: o.length === 0,
211
+ is_default: n.length === 0,
206
212
  is_system_defined: !1
207
- }, d = g(i == null ? void 0 : i.view, u);
208
- return p([...o, d]), { view: d, alreadyExists: (i == null ? void 0 : i.alreadyExists) ?? !1 };
213
+ }, w = x(e == null ? void 0 : e.view, c);
214
+ return g(), v([...n, w]), { view: w, alreadyExists: (e == null ? void 0 : e.alreadyExists) ?? !1, message: e == null ? void 0 : e.message };
209
215
  },
210
- async rename(e, n) {
211
- M(n);
212
- const i = y(t).views, o = i.findIndex((m) => m.view_id === e);
213
- if (o < 0) throw new Error(`View "${e}" not found for screen "${t}"`);
214
- const r = { ...i[o], name: n };
215
- let u = null;
216
- if (B) {
217
- const a = (v ? await v(e).catch(() => null) : null) ?? i[o];
218
- u = await B({
219
- view_id: a.view_id || e,
220
- view_type: t,
221
- tab: c == null ? void 0 : c.tab,
222
- name: n,
223
- columns: a.columns,
224
- filters: a.filters,
225
- priority: a.priority
226
- });
227
- }
228
- const d = g(u ?? void 0, r), _ = i.slice();
229
- return _[o] = d, p(_), d;
216
+ async rename(i, r) {
217
+ D(r);
218
+ const e = S ? await this.get(i) : null, n = _(), a = n.findIndex((G) => G.view_id === i);
219
+ if (a < 0 && !e) throw new Error(`View "${i}" not found for screen "${t}"`);
220
+ const c = e ?? n[a], w = { ...c, name: r };
221
+ let y = null;
222
+ S && (y = await S({
223
+ view_id: c.view_id || i,
224
+ view_type: t,
225
+ tab: o == null ? void 0 : o.tab,
226
+ name: r,
227
+ columns: c.columns,
228
+ filters: c.filters,
229
+ priority: c.priority,
230
+ is_default: c.is_default
231
+ }));
232
+ const E = x(y ?? void 0, w), V = a >= 0 ? n.slice() : [...n, E];
233
+ return a >= 0 && (V[a] = E), g(), v(V), E;
230
234
  },
231
- async remove(e) {
232
- const n = y(t).views, i = n.find((r) => r.view_id === e);
233
- if (!i) return;
234
- E && await E(i.view_id);
235
- let o = n.filter((r) => r.view_id !== e);
236
- i.is_default && o.length > 0 && !o.some((r) => r.is_default) && (o = o.map((r, u) => u === 0 ? { ...r, is_default: !0 } : r)), p(o);
235
+ async remove(i) {
236
+ const r = _(), e = r.find((a) => a.view_id === i);
237
+ if (!e) return;
238
+ b && await b(e.view_id);
239
+ const n = r.filter((a) => a.view_id !== i);
240
+ g(), v(n);
237
241
  },
238
- async setPrimary(e) {
239
- const n = y(t).views, i = n.find((r) => r.view_id === e);
240
- if (!i) throw new Error(`View "${e}" not found for screen "${t}"`);
241
- const o = n.map((r) => ({ ...r, is_default: r.view_id === e }));
242
- return p(o), { ...i, is_default: !0 };
242
+ async setPrimary(i) {
243
+ return M(i, !0);
243
244
  },
244
- async unsetPrimary(e) {
245
- const n = y(t).views, i = n.find((r) => r.view_id === e);
246
- if (!i) throw new Error(`View "${e}" not found for screen "${t}"`);
247
- const o = n.map((r) => r.view_id === e ? { ...r, is_default: !1 } : r);
248
- return p(o), { ...i, is_default: !1 };
245
+ async unsetPrimary(i) {
246
+ return M(i, !1);
249
247
  },
250
248
  async reset() {
251
- if (E && await E(), O())
249
+ if (b && await b(), g(), O())
252
250
  try {
253
- window.localStorage.removeItem(l);
251
+ window.localStorage.removeItem(f);
254
252
  } catch {
255
253
  }
256
- D(l);
254
+ W(f);
257
255
  },
258
- subscribe(e) {
259
- A();
260
- let n = h.get(l);
261
- return n || (n = /* @__PURE__ */ new Set(), h.set(l, n)), n.add(e), () => {
262
- const i = h.get(l);
263
- i && (i.delete(e), i.size === 0 && h.delete(l));
256
+ subscribe(i) {
257
+ lt();
258
+ const r = u ? [f, u] : [f];
259
+ return r.forEach((e) => {
260
+ let n = m.get(e);
261
+ n || (n = /* @__PURE__ */ new Set(), m.set(e, n)), n.add(i);
262
+ }), () => {
263
+ r.forEach((e) => {
264
+ const n = m.get(e);
265
+ n && (n.delete(i), n.size === 0 && m.delete(e));
266
+ });
264
267
  };
265
268
  }
266
269
  };
267
270
  }
268
- function nt(t, s) {
269
- const f = N(t, s);
270
- return (l) => f.save(l);
271
+ function ht(t, s) {
272
+ const d = wt(t, s);
273
+ return (f) => d.save(f);
271
274
  }
272
275
  export {
273
- nt as createLocalSaveView,
274
- N as createLocalViewStore,
275
- et as createTableViewSelectorStore,
276
- j as isReservedViewName
276
+ ht as createLocalSaveView,
277
+ wt as createLocalViewStore,
278
+ pt as createTableViewSelectorStore,
279
+ dt as isReservedViewName
277
280
  };
278
281
  //# sourceMappingURL=viewStore.js.map