react-semaphor 0.1.314 → 0.1.316

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 (46) hide show
  1. package/dist/brand-studio/index.js +65 -65
  2. package/dist/briefings/index.cjs +1 -0
  3. package/dist/briefings/index.js +848 -0
  4. package/dist/chunks/{braces-CWi8x9ww.js → braces-CDPz6CF2.js} +1 -1
  5. package/dist/chunks/{calendar-preferences-dialog-D70CuT-1.js → calendar-preferences-dialog-9NlFzHX8.js} +3 -3
  6. package/dist/chunks/{calendar-preferences-dialog-BzpQ5u4h.js → calendar-preferences-dialog-BDdxi7Xm.js} +1 -1
  7. package/dist/chunks/{chevrons-up-down-B2viXO2I.js → chevrons-up-down-BsdQRmJL.js} +1 -1
  8. package/dist/chunks/dashboard-briefing-launcher-5fM_KJoT.js +7321 -0
  9. package/dist/chunks/dashboard-briefing-launcher-CVxLt10p.js +96 -0
  10. package/dist/chunks/dashboard-controls-9YV-D1tD.js +2009 -0
  11. package/dist/chunks/dashboard-controls-UR_m0wD1.js +57 -0
  12. package/dist/chunks/{dashboard-json-CJCAen1R.js → dashboard-json-CKPID8Am.js} +2 -2
  13. package/dist/chunks/{dashboard-json-v2C6Tmqf.js → dashboard-json-ws4tortP.js} +1 -1
  14. package/dist/chunks/edit-dashboard-visual-CmxnZI8I.js +178 -0
  15. package/dist/chunks/{edit-dashboard-visual-DljWvnMy.js → edit-dashboard-visual-ifKJLMTS.js} +807 -822
  16. package/dist/chunks/index-Xdag_85e.js +1298 -0
  17. package/dist/chunks/{index-P5hPTTzm.js → index-gcA9Rs35.js} +41178 -46390
  18. package/dist/chunks/{palette-CIuwlEiG.js → palette-BlxLchHy.js} +1 -1
  19. package/dist/chunks/{resource-management-panel-CAxXzMdi.js → resource-management-panel-BduJanWW.js} +1 -1
  20. package/dist/chunks/{resource-management-panel-Dk0DzgVm.js → resource-management-panel-paSAzVj2.js} +81 -81
  21. package/dist/chunks/{save-_ALpoMy6.js → save-DVRQBMeb.js} +1 -1
  22. package/dist/chunks/{switch-B6fh8nb-.js → switch-sauemjyY.js} +199 -199
  23. package/dist/chunks/{use-create-flow-overlay-state-Cqf7GaFm.js → use-create-flow-overlay-state-DKV6tIc5.js} +254 -225
  24. package/dist/chunks/use-create-flow-overlay-state-DWnzVVlP.js +26 -0
  25. package/dist/chunks/{use-visual-utils-CQQ3jvDn.js → use-visual-utils-C8PDxg2w.js} +1 -1
  26. package/dist/chunks/{use-visual-utils-CPMQLBYR.js → use-visual-utils-Cs0-baCK.js} +48 -48
  27. package/dist/dashboard/index.cjs +1 -1
  28. package/dist/dashboard/index.js +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.js +232 -485
  31. package/dist/style.css +1 -1
  32. package/dist/surfboard/index.cjs +1 -1
  33. package/dist/surfboard/index.js +2 -2
  34. package/dist/types/briefings.d.ts +240 -0
  35. package/dist/types/dashboard.d.ts +1 -0
  36. package/dist/types/main.d.ts +619 -1017
  37. package/dist/types/surfboard.d.ts +1 -0
  38. package/dist/types/types.d.ts +411 -261
  39. package/package.json +7 -2
  40. package/dist/chunks/dashboard-controls-BS_aZcxs.js +0 -57
  41. package/dist/chunks/dashboard-controls-DbKtbw1V.js +0 -2021
  42. package/dist/chunks/dashboard-filter-controls-launcher-C8Wm2Smj.js +0 -1540
  43. package/dist/chunks/dashboard-filter-controls-launcher-CMXpudFJ.js +0 -11
  44. package/dist/chunks/edit-dashboard-visual-lRn3FeaP.js +0 -183
  45. package/dist/chunks/index-XYIIY48z.js +0 -1330
  46. package/dist/chunks/use-create-flow-overlay-state-DMZTflFt.js +0 -16
@@ -1,1540 +0,0 @@
1
- import { jsx as t, jsxs as n, Fragment as _ } from "react/jsx-runtime";
2
- import { c as be, L as J, x as Fe, B as P, f as ee, i as j, u as E, h as G, az as ce, a9 as xe, G as Ce, e as Te, g as we, a as $, S as te, X as Le, P as q, b as Y, d as K, aA as ke, aB as Pe, aC as Oe } from "./switch-B6fh8nb-.js";
3
- import { b as ae, c as se, d as oe, e as re, f as ne, bV as Ve, n as Me, s as Ue, t as Be, b8 as ye, bW as ze, o as M, b9 as Z, V as Re, bq as _e, br as $e, bt as He, bu as W, by as je, bl as Ge, bX as We, bY as Xe, bF as qe, bG as Ye, bH as Ke, bI as Qe, bJ as Je, bK as Ze, bL as et, u as ie, ad as R, aY as le, aU as De, aV as de, ae as Ne, aT as tt, a_ as at, bZ as st, b_ as ot, bn as rt, aW as ue, J as nt, ag as it, b$ as lt, c0 as dt, c1 as ct, c2 as ut, c3 as mt, c4 as ht, c5 as pt, c6 as ft, c7 as Se, c8 as gt, c9 as vt, ca as bt, cb as xt, cc as Ct, cd as wt, ce as yt, cf as Dt, ba as Nt, cg as St } from "./index-P5hPTTzm.js";
4
- import { V as Et, E as me, a as he, b as It, c as At, L as Ft, d as Tt, C as Lt, u as Ee, e as Ie, f as kt } from "./use-create-flow-overlay-state-Cqf7GaFm.js";
5
- import Pt, { useState as k, useContext as Ot, useRef as X, useCallback as L, useEffect as z, useMemo as H } from "react";
6
- import { u as Ae } from "./use-visual-utils-CPMQLBYR.js";
7
- import { k as pe } from "./date-formatter-DyIOb6uC.js";
8
- import "./index-CJdxSyQq.js";
9
- import "react-dom";
10
- /**
11
- * @license lucide-react v0.453.0 - ISC
12
- *
13
- * This source code is licensed under the ISC license.
14
- * See the LICENSE file in the root directory of this source tree.
15
- */
16
- const fe = be("FileDown", [
17
- ["path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z", key: "1rqfz7" }],
18
- ["path", { d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" }],
19
- ["path", { d: "M12 18v-6", key: "17g6i2" }],
20
- ["path", { d: "m9 15 3 3 3-3", key: "1npd3o" }]
21
- ]);
22
- /**
23
- * @license lucide-react v0.453.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */
28
- const Vt = be("FilterX", [
29
- ["path", { d: "M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055", key: "1fi1da" }],
30
- ["path", { d: "m22 3-5 5", key: "12jva0" }],
31
- ["path", { d: "m17 3 5 5", key: "k36vhe" }]
32
- ]);
33
- function Mt({
34
- open: e,
35
- onOpenChange: a,
36
- isLibraryVisual: m,
37
- currentVisualName: d,
38
- isSaving: o = !1,
39
- destinationMode: h = "both",
40
- onConfirm: l
41
- }) {
42
- const [c, i] = k(
43
- m && d ? `Copy of ${d}` : d || ""
44
- ), [s, f] = k("");
45
- Pt.useEffect(() => {
46
- e && (i(
47
- m && d ? `Copy of ${d}` : d || ""
48
- ), f(""));
49
- }, [e, m, d]);
50
- const b = !!c.trim(), r = h === "local" ? {
51
- saveToLibrary: !1,
52
- saveToCurrentDashboard: !0,
53
- badgeType: "local",
54
- description: "Creates a local copy on the current dashboard.",
55
- actionLabel: "Add to Dashboard (Local)"
56
- } : h === "library" ? {
57
- saveToLibrary: !0,
58
- saveToCurrentDashboard: !1,
59
- badgeType: "library",
60
- description: "Creates a reusable visual in Visual Library.",
61
- actionLabel: "Save as Library Visual"
62
- } : {
63
- saveToLibrary: !0,
64
- saveToCurrentDashboard: !0,
65
- badgeType: "linked",
66
- description: "Creates a new library visual and adds a linked copy to this dashboard.",
67
- actionLabel: "Save Copy as Linked Visual"
68
- }, u = () => {
69
- !b || o || l({
70
- name: c.trim(),
71
- description: s.trim() || void 0,
72
- saveToLibrary: r.saveToLibrary,
73
- saveToCurrentDashboard: r.saveToCurrentDashboard
74
- });
75
- };
76
- return /* @__PURE__ */ t(ae, { open: e, onOpenChange: a, children: /* @__PURE__ */ n(se, { className: "sm:max-w-[500px]", children: [
77
- /* @__PURE__ */ n(oe, { children: [
78
- /* @__PURE__ */ n(re, { className: "flex items-center gap-2", children: [
79
- /* @__PURE__ */ t("span", { children: "Save Visual As" }),
80
- r.badgeType !== "local" && /* @__PURE__ */ t(
81
- Et,
82
- {
83
- type: r.badgeType,
84
- showLabel: !0,
85
- className: "px-2 py-0.5"
86
- }
87
- )
88
- ] }),
89
- /* @__PURE__ */ t(ne, { children: r.description })
90
- ] }),
91
- /* @__PURE__ */ n("div", { className: "grid gap-4 py-4", children: [
92
- /* @__PURE__ */ n("div", { className: "grid gap-2", children: [
93
- /* @__PURE__ */ t(J, { htmlFor: "name", children: "Name" }),
94
- /* @__PURE__ */ t(
95
- Fe,
96
- {
97
- id: "name",
98
- value: c,
99
- onChange: (w) => i(w.target.value),
100
- placeholder: "Enter visual name",
101
- disabled: o
102
- }
103
- )
104
- ] }),
105
- /* @__PURE__ */ n("div", { className: "grid gap-2", children: [
106
- /* @__PURE__ */ t(J, { htmlFor: "description", children: "Description (optional)" }),
107
- /* @__PURE__ */ t(
108
- Ve,
109
- {
110
- id: "description",
111
- value: s,
112
- onChange: (w) => f(w.target.value),
113
- placeholder: "Enter visual description",
114
- rows: 3,
115
- disabled: o
116
- }
117
- )
118
- ] })
119
- ] }),
120
- /* @__PURE__ */ n(Me, { children: [
121
- /* @__PURE__ */ t(
122
- P,
123
- {
124
- variant: "outline",
125
- onClick: () => a(!1),
126
- disabled: o,
127
- children: "Cancel"
128
- }
129
- ),
130
- /* @__PURE__ */ n(P, { onClick: u, disabled: !b || o, children: [
131
- o && /* @__PURE__ */ t(ee, { className: "mr-2 h-4 w-4 animate-spin" }),
132
- r.actionLabel
133
- ] })
134
- ] })
135
- ] }) });
136
- }
137
- function Ut() {
138
- const [e, a] = k(!1), [m, d] = k(!1), [o, h] = k(null), [l, c] = k(null), i = j((g) => g.frame), s = j((g) => g.card), f = Ue(), b = E((g) => g.selectedSheetId), r = E((g) => g.dashboard), u = E(
139
- (g) => g.actions.setIsDashboardPanelOpen
140
- ), { getUpdatedFrame: w } = Ae(), { selectVisual: v } = Be(), { addFrame: C, setSelectedFrameId: S, setIsVisualEditing: N } = G(), p = ye(), D = !!(i != null && i.visualId), I = (() => {
141
- var g, y;
142
- return ((g = i == null ? void 0 : i.cards) == null ? void 0 : g.length) === 1 && ((y = i.cards[0]) != null && y.title) ? i.cards[0].title : f != null && f.title ? f.title : (s == null ? void 0 : s.title) || "Untitled Visual";
143
- })(), T = ze((g) => {
144
- g != null && g.id && (v(g), m && o && l && b && (async () => {
145
- try {
146
- const y = {
147
- ...o,
148
- id: ce(),
149
- visualId: g.id
150
- // Link to the newly created library visual
151
- };
152
- C(b, y, {
153
- position: "end",
154
- semanticExecutionPayload: l
155
- }), S(y.id), d(!1), h(null), c(null), N(!1);
156
- } catch (y) {
157
- console.error(
158
- "Failed to promote semantic metadata for saved visual:",
159
- y
160
- ), M.error(
161
- y instanceof Error ? y.message : "Failed to prepare semantic metadata for the saved visual"
162
- );
163
- }
164
- })(), u(!0), a(!1));
165
- });
166
- return {
167
- saveAsDialogOpen: e,
168
- setSaveAsDialogOpen: a,
169
- handleSaveAs: async (g) => {
170
- if (!b) {
171
- M.error("No sheet selected");
172
- return;
173
- }
174
- const y = w(), F = xe(y);
175
- if (F) {
176
- M.error(F);
177
- return;
178
- }
179
- const V = y.cards.length === 1 ? {
180
- ...y,
181
- cards: y.cards.map((O) => ({
182
- ...O,
183
- title: g.name
184
- // Use visual name as card title
185
- }))
186
- } : y;
187
- if (g.saveToLibrary) {
188
- let O = null;
189
- if (g.saveToCurrentDashboard)
190
- try {
191
- O = await p(V, {
192
- previousFrame: Z(r, V.id)
193
- });
194
- } catch (B) {
195
- console.error(
196
- "Failed to prepare semantic metadata before saving visual:",
197
- B
198
- ), M.error(
199
- B instanceof Error ? B.message : "Failed to prepare semantic metadata for the saved visual"
200
- );
201
- return;
202
- }
203
- d(g.saveToCurrentDashboard), h(V), c(O);
204
- const U = {
205
- title: g.name,
206
- description: g.description,
207
- frameObject: V,
208
- // Card title synced for single-card frames
209
- isPrivate: !1
210
- };
211
- T.mutate(U);
212
- } else if (g.saveToCurrentDashboard) {
213
- const O = {
214
- ...V,
215
- // Card title already synced
216
- id: ce(),
217
- visualId: void 0
218
- // Explicitly no visualId for local visuals
219
- };
220
- try {
221
- const U = await p(V, {
222
- previousFrame: Z(r, V.id)
223
- });
224
- C(b, O, {
225
- position: "end",
226
- semanticExecutionPayload: U
227
- }), S(O.id), M.success("Visual saved to dashboard"), a(!1), N(!1);
228
- } catch (U) {
229
- console.error("Failed to save visual to dashboard:", U), M.error(
230
- U instanceof Error ? U.message : "Failed to prepare semantic metadata for the visual"
231
- );
232
- }
233
- }
234
- },
235
- isLibraryVisual: D,
236
- currentVisualName: I,
237
- isSaving: T.isPending
238
- };
239
- }
240
- function fa(e = {}) {
241
- const a = j((A) => A.frame), m = j((A) => A.editorContext), d = Re((A) => A.selectedVisual), o = E((A) => A.selectedFrameId), h = E((A) => A.selectedSheetId), l = E((A) => A.dashboard), { setIsVisualEditing: c, updateFrame: i } = G(), [s, f] = k(!1), [b, r] = k("both"), u = ye(), w = (m == null ? void 0 : m.type) === "documentSection", v = !!(a != null && a.visualId || d != null && d.id), C = !!(a != null && a.visualId && o), S = v && !C, {
242
- saveAsDialogOpen: N,
243
- setSaveAsDialogOpen: p,
244
- handleSaveAs: D,
245
- isLibraryVisual: I,
246
- currentVisualName: T,
247
- isSaving: x
248
- } = Ut(), { getUpdatedFrame: g } = Ae();
249
- if (w)
250
- return /* @__PURE__ */ n(_, { children: [
251
- /* @__PURE__ */ t(me, { className: "rounded-control", variant: "default" }),
252
- /* @__PURE__ */ t(he, {})
253
- ] });
254
- const y = async () => {
255
- if (!h) {
256
- M.error("No sheet selected");
257
- return;
258
- }
259
- if (s) return;
260
- f(!0);
261
- const A = g(), V = xe(A);
262
- if (V) {
263
- f(!1), M.error(V);
264
- return;
265
- }
266
- const O = {
267
- ...A,
268
- visualId: void 0
269
- }, U = Z(l, O.id);
270
- try {
271
- const B = await u(O, {
272
- previousFrame: U
273
- });
274
- i(h, O, {
275
- semanticExecutionPayload: B
276
- });
277
- } catch (B) {
278
- console.error("Failed to apply local semantic metadata:", B), f(!1), M.error(
279
- B instanceof Error ? B.message : "Failed to prepare semantic metadata for this visual"
280
- );
281
- return;
282
- }
283
- setTimeout(() => {
284
- f(!1), M.success("Changes applied. Visual is now local to this dashboard"), c(!1);
285
- }, 300);
286
- }, F = (A) => {
287
- r(A), p(!0);
288
- };
289
- return /* @__PURE__ */ n(_, { children: [
290
- /* @__PURE__ */ n("div", { className: "inline-flex items-center overflow-hidden rounded-control", children: [
291
- !v && /* @__PURE__ */ t(me, { className: "!rounded-none", variant: "default" }),
292
- v && S && /* @__PURE__ */ t(It, { className: "!rounded-none", variant: "default" }),
293
- v && C && /* @__PURE__ */ t(At, { className: "!rounded-none" }),
294
- /* @__PURE__ */ n(_e, { modal: !1, children: [
295
- /* @__PURE__ */ t($e, { asChild: !0, children: /* @__PURE__ */ t(
296
- P,
297
- {
298
- variant: "default",
299
- size: "xs",
300
- className: "w-7 !rounded-none border-l border-primary-foreground/20 px-0",
301
- "aria-label": "Open visual save options",
302
- disabled: x || s,
303
- children: /* @__PURE__ */ t(Ce, { className: "h-3.5 w-3.5" })
304
- }
305
- ) }),
306
- /* @__PURE__ */ n(
307
- He,
308
- {
309
- align: "end",
310
- className: "min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",
311
- children: [
312
- C && /* @__PURE__ */ n(_, { children: [
313
- /* @__PURE__ */ n(
314
- W,
315
- {
316
- onClick: y,
317
- disabled: s,
318
- children: [
319
- /* @__PURE__ */ t(Te, { className: "h-3.5 w-3.5" }),
320
- s ? "Applying..." : "Apply Locally"
321
- ]
322
- }
323
- ),
324
- /* @__PURE__ */ t(je, {})
325
- ] }),
326
- /* @__PURE__ */ n(
327
- W,
328
- {
329
- onClick: () => F("local"),
330
- disabled: x,
331
- children: [
332
- /* @__PURE__ */ t(Ge, { className: "h-3.5 w-3.5" }),
333
- "Add to Dashboard (Local)"
334
- ]
335
- }
336
- ),
337
- /* @__PURE__ */ n(
338
- W,
339
- {
340
- onClick: () => F("library"),
341
- disabled: x,
342
- children: [
343
- /* @__PURE__ */ t(Ft, { className: "h-3.5 w-3.5" }),
344
- "Save as Library Visual"
345
- ]
346
- }
347
- ),
348
- /* @__PURE__ */ n(
349
- W,
350
- {
351
- onClick: () => F("both"),
352
- disabled: x,
353
- children: [
354
- /* @__PURE__ */ t(Tt, { className: "h-3.5 w-3.5" }),
355
- "Save Copy as Linked Visual"
356
- ]
357
- }
358
- )
359
- ]
360
- }
361
- )
362
- ] })
363
- ] }),
364
- /* @__PURE__ */ t(he, {}),
365
- /* @__PURE__ */ t(
366
- Mt,
367
- {
368
- open: N,
369
- onOpenChange: (A) => {
370
- x || p(A);
371
- },
372
- isLibraryVisual: I,
373
- currentVisualName: T,
374
- isSaving: x,
375
- destinationMode: b,
376
- onConfirm: D
377
- }
378
- )
379
- ] });
380
- }
381
- function ga({ className: e }) {
382
- const a = j((s) => s.isDevMode), m = E((s) => s.isVisualEditing), { setIsDevMode: d } = we(), { config: o } = Ot(We).tokenProps, h = (o == null ? void 0 : o.showAdvancedMode) !== !1;
383
- if (!m || !h)
384
- return null;
385
- const l = a ? te : Xe, c = a ? "Drag & drop" : "SQL", i = a ? "Switch to drag-and-drop mode" : "Switch to SQL mode";
386
- return /* @__PURE__ */ n(
387
- "button",
388
- {
389
- type: "button",
390
- "aria-label": i,
391
- title: i,
392
- onClick: () => d(!a),
393
- className: $(
394
- "inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",
395
- e
396
- ),
397
- children: [
398
- /* @__PURE__ */ t(l, { className: "h-3 w-3 text-muted-foreground" }),
399
- c
400
- ]
401
- }
402
- );
403
- }
404
- function va({
405
- open: e,
406
- onOpenChange: a,
407
- onSave: m,
408
- onDiscard: d,
409
- isSaving: o,
410
- title: h = "Unsaved changes",
411
- description: l = "You have unsaved changes to this dashboard. What would you like to do?",
412
- cancelLabel: c = "Cancel",
413
- discardLabel: i = "Discard",
414
- saveLabel: s = "Save"
415
- }) {
416
- return /* @__PURE__ */ t(qe, { open: e, onOpenChange: (b) => {
417
- !b && o || a(b);
418
- }, children: /* @__PURE__ */ n(Ye, { children: [
419
- /* @__PURE__ */ n(Ke, { children: [
420
- /* @__PURE__ */ t(Qe, { children: h }),
421
- /* @__PURE__ */ t(Je, { children: l })
422
- ] }),
423
- /* @__PURE__ */ n(Ze, { children: [
424
- /* @__PURE__ */ t(
425
- P,
426
- {
427
- type: "button",
428
- size: "xs",
429
- onClick: d,
430
- disabled: o,
431
- variant: "ghost",
432
- className: "mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",
433
- children: i
434
- }
435
- ),
436
- /* @__PURE__ */ t(et, { disabled: o, children: c }),
437
- /* @__PURE__ */ t(P, { type: "button", size: "xs", onClick: m, disabled: o, children: o ? /* @__PURE__ */ n(_, { children: [
438
- /* @__PURE__ */ t(ee, { className: "mr-2 h-3.5 w-3.5 animate-spin" }),
439
- "Saving..."
440
- ] }) : s })
441
- ] })
442
- ] }) });
443
- }
444
- const Bt = 1e4, zt = 15e3, Rt = 3e4, _t = 3e4, $t = 12e4, ge = 2 * 60 * 60 * 1e3;
445
- function Ht(e) {
446
- const a = Date.now() - e.getTime();
447
- return a < _t ? Bt : a < $t ? zt : Rt;
448
- }
449
- function ba() {
450
- const { authToken: e, tokenProps: a } = ie(), m = R((r) => r.activeExports), [d, o] = k(
451
- typeof document < "u" ? !document.hidden : !0
452
- ), h = X(null), l = X(!1), c = X(void 0), i = a == null ? void 0 : a.apiServiceUrl, s = e == null ? void 0 : e.accessToken, f = L(() => {
453
- const r = R.getState().activeExports;
454
- return Array.from(r.values()).filter(
455
- (u) => le(u.status)
456
- );
457
- }, []);
458
- z(() => {
459
- if (typeof document > "u") return;
460
- const r = () => {
461
- o(!document.hidden);
462
- };
463
- return document.addEventListener("visibilitychange", r), () => {
464
- document.removeEventListener("visibilitychange", r);
465
- };
466
- }, []);
467
- const b = L(async () => {
468
- if (!i || !s) {
469
- l.current = !1;
470
- return;
471
- }
472
- const r = f();
473
- if (r.length === 0) {
474
- l.current = !1;
475
- return;
476
- }
477
- const u = Date.now(), w = r.filter(
478
- (p) => u - p.startedAt.getTime() > ge
479
- );
480
- if (w.length > 0) {
481
- const { updateExport: p } = R.getState().actions;
482
- for (const D of w)
483
- p(D.id, {
484
- status: "failed",
485
- error: "Export timed out. Please try again or contact support.",
486
- lastUpdatedAt: /* @__PURE__ */ new Date()
487
- });
488
- }
489
- const v = r.filter(
490
- (p) => u - p.startedAt.getTime() <= ge
491
- );
492
- if (v.length === 0) {
493
- l.current = !1;
494
- return;
495
- }
496
- const C = await Promise.allSettled(
497
- v.map(async (p) => {
498
- try {
499
- const D = await De(i, s, p.id);
500
- let I;
501
- if (D.status === "completed")
502
- try {
503
- I = await de(i, s, p.id);
504
- } catch (T) {
505
- console.error(
506
- `[useExportPolling] Failed to get download URL for ${p.id}:`,
507
- T
508
- );
509
- }
510
- return {
511
- id: p.id,
512
- status: D.status,
513
- progress: D.progress,
514
- completedChunks: D.completedChunks,
515
- completedAt: D.completedAt ? new Date(D.completedAt) : void 0,
516
- lastUpdatedAt: /* @__PURE__ */ new Date(),
517
- fileSize: D.fileSize,
518
- error: D.error,
519
- downloadUrl: I
520
- };
521
- } catch (D) {
522
- return console.error(
523
- `[useExportPolling] Failed to poll export ${p.id}:`,
524
- D
525
- ), null;
526
- }
527
- })
528
- ), { updateExport: S } = R.getState().actions;
529
- for (const p of C)
530
- p.status === "fulfilled" && p.value && S(p.value.id, p.value);
531
- const N = f();
532
- if (N.length > 0 && !document.hidden) {
533
- const p = N.reduce(
534
- (I, T) => T.startedAt < I ? T.startedAt : I,
535
- N[0].startedAt
536
- ), D = Ht(p);
537
- h.current && clearTimeout(h.current), h.current = setTimeout(() => {
538
- var I;
539
- (I = c.current) == null || I.call(c);
540
- }, D);
541
- } else
542
- l.current = !1;
543
- }, [i, s, f]);
544
- return z(() => {
545
- c.current = b;
546
- }, [b]), z(() => {
547
- var u;
548
- f().length > 0 && d && !l.current && (l.current = !0, (u = c.current) == null || u.call(c));
549
- }, [m, d, f]), z(() => {
550
- var u;
551
- const r = f();
552
- d && r.length > 0 && !l.current && (l.current = !0, (u = c.current) == null || u.call(c));
553
- }, [d, f]), z(() => {
554
- !d && h.current && (clearTimeout(h.current), h.current = null, l.current = !1);
555
- }, [d]), z(() => () => {
556
- h.current && (clearTimeout(h.current), h.current = null);
557
- }, []), {
558
- isPolling: l.current,
559
- isTabVisible: d,
560
- inProgressCount: f().length
561
- };
562
- }
563
- function xa() {
564
- const { authToken: e, tokenProps: a } = ie(), m = R((c) => c.activeExports), { addExport: d } = Ne(), o = X(!1), h = a == null ? void 0 : a.apiServiceUrl, l = e == null ? void 0 : e.accessToken;
565
- z(() => {
566
- if (o.current || !h || !l) return;
567
- (async () => {
568
- try {
569
- const { exports: i } = await tt(h, l, {
570
- status: ["pending", "processing", "chunking", "compacting", "completed", "failed"],
571
- limit: 20
572
- // Limit to recent exports
573
- });
574
- for (const s of i) {
575
- if (m.has(s.id)) continue;
576
- const f = s.totalChunks ? Math.round(s.completedChunks / s.totalChunks * 100) : 0;
577
- let b;
578
- if (s.status === "completed")
579
- try {
580
- b = await de(h, l, s.id);
581
- } catch (u) {
582
- console.error(
583
- `[useExportRecovery] Failed to get download URL for ${s.id}:`,
584
- u
585
- );
586
- }
587
- const r = {
588
- id: s.id,
589
- status: s.status,
590
- progress: f,
591
- title: jt(s),
592
- totalRows: s.totalRows,
593
- totalChunks: s.totalChunks,
594
- completedChunks: s.completedChunks,
595
- startedAt: new Date(s.createdAt),
596
- lastUpdatedAt: /* @__PURE__ */ new Date(),
597
- completedAt: s.completedAt ? new Date(s.completedAt) : void 0,
598
- fileSize: s.fileSize,
599
- error: s.error,
600
- expiresAt: new Date(s.expiresAt),
601
- downloadUrl: b
602
- };
603
- d(r);
604
- }
605
- o.current = !0;
606
- } catch (i) {
607
- console.error("[useExportRecovery] Failed to recover exports:", i), o.current = !0;
608
- }
609
- })();
610
- }, [h, l, d, m]);
611
- }
612
- function jt(e) {
613
- return e.title ? e.title : le(
614
- e.status
615
- ) ? "Export in progress..." : e.status === "completed" ? "Export completed" : e.status === "failed" ? "Export failed" : "Export";
616
- }
617
- function Gt({
618
- export: e,
619
- onRemove: a
620
- }) {
621
- const m = () => {
622
- e.downloadUrl && window.open(e.downloadUrl, "_blank");
623
- }, d = (c) => {
624
- c.stopPropagation(), a == null || a(e.id);
625
- }, o = () => {
626
- switch (e.status) {
627
- case "completed":
628
- return /* @__PURE__ */ t(rt, { className: "mt-0.5 h-5 w-5 shrink-0 text-green-600" });
629
- case "failed":
630
- return /* @__PURE__ */ t(Lt, { className: "mt-0.5 h-5 w-5 shrink-0 text-destructive" });
631
- default:
632
- return /* @__PURE__ */ t(ee, { className: "text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin" });
633
- }
634
- }, h = le(e.status), l = (() => {
635
- switch (e.status) {
636
- case "pending":
637
- return "Queued...";
638
- case "processing":
639
- return "Processing...";
640
- case "chunking":
641
- return "Processing...";
642
- case "compacting":
643
- return "Finalizing...";
644
- default:
645
- return "Processing...";
646
- }
647
- })();
648
- return /* @__PURE__ */ n("div", { className: "group p-4 transition-colors hover:bg-muted/50", children: [
649
- /* @__PURE__ */ n("div", { className: "mb-2 flex items-start justify-between gap-3", children: [
650
- /* @__PURE__ */ n("div", { className: "flex min-w-0 flex-1 items-start gap-3", children: [
651
- o(),
652
- /* @__PURE__ */ n("div", { className: "min-w-0 flex-1", children: [
653
- /* @__PURE__ */ t("h4", { className: "mb-1 truncate text-sm font-medium", children: e.title }),
654
- e.status === "completed" && /* @__PURE__ */ n("div", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
655
- /* @__PURE__ */ n("span", { children: [
656
- e.totalRows.toLocaleString(),
657
- " rows"
658
- ] }),
659
- e.fileSize && /* @__PURE__ */ n(_, { children: [
660
- /* @__PURE__ */ t("span", { children: "•" }),
661
- /* @__PURE__ */ t("span", { children: at(e.fileSize) })
662
- ] })
663
- ] }),
664
- h && /* @__PURE__ */ t("div", { className: "text-xs text-muted-foreground", children: l }),
665
- e.status === "failed" && /* @__PURE__ */ t("div", { className: "line-clamp-2 text-xs text-destructive", children: e.error || "Export failed" })
666
- ] })
667
- ] }),
668
- /* @__PURE__ */ t(
669
- P,
670
- {
671
- variant: "ghost",
672
- size: "icon",
673
- className: "h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",
674
- onClick: d,
675
- "aria-label": "Remove notification",
676
- children: /* @__PURE__ */ t(Le, { className: "h-4 w-4" })
677
- }
678
- )
679
- ] }),
680
- /* @__PURE__ */ n("div", { className: "ml-8", children: [
681
- e.status === "completed" && /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
682
- /* @__PURE__ */ t("span", { className: "text-xs text-muted-foreground", children: pe(e.startedAt, { addSuffix: !0 }) }),
683
- e.downloadUrl && /* @__PURE__ */ n(
684
- P,
685
- {
686
- size: "sm",
687
- variant: "outline",
688
- className: "h-8 bg-transparent",
689
- onClick: m,
690
- children: [
691
- /* @__PURE__ */ t(st, { className: "mr-1.5 h-3.5 w-3.5" }),
692
- "Download"
693
- ]
694
- }
695
- )
696
- ] }),
697
- h && /* @__PURE__ */ n("div", { children: [
698
- /* @__PURE__ */ t(ot, { value: e.progress, className: "h-1.5" }),
699
- /* @__PURE__ */ n("span", { className: "mt-1 block text-xs text-muted-foreground", children: [
700
- e.progress,
701
- "% complete"
702
- ] })
703
- ] }),
704
- e.status === "failed" && /* @__PURE__ */ t("span", { className: "text-xs text-muted-foreground", children: pe(e.startedAt, { addSuffix: !0 }) })
705
- ] })
706
- ] });
707
- }
708
- function Wt() {
709
- const { authToken: e, tokenProps: a } = ie(), m = R((v) => v.activeExports), { clearCompleted: d, removeExport: o, updateExport: h } = Ne(), [l, c] = k(!1), [i, s] = k(!1), f = Array.from(m.values()).sort(
710
- (v, C) => C.startedAt.getTime() - v.startedAt.getTime()
711
- ), b = f.some(
712
- (v) => v.status === "completed" || v.status === "failed"
713
- ), r = L(async () => {
714
- const v = a == null ? void 0 : a.apiServiceUrl, C = e == null ? void 0 : e.accessToken;
715
- if (!(!v || !C)) {
716
- c(!0);
717
- try {
718
- const S = Array.from(m.values());
719
- await Promise.all(
720
- S.map(async (N) => {
721
- try {
722
- const p = await De(v, C, N.id);
723
- let D;
724
- if (p.status === "completed")
725
- try {
726
- D = await de(
727
- v,
728
- C,
729
- N.id
730
- );
731
- } catch (I) {
732
- console.error(`Failed to get download URL for ${N.id}:`, I);
733
- }
734
- h(N.id, {
735
- status: p.status,
736
- progress: p.progress,
737
- completedChunks: p.completedChunks,
738
- completedAt: p.completedAt ? new Date(p.completedAt) : void 0,
739
- lastUpdatedAt: /* @__PURE__ */ new Date(),
740
- fileSize: p.fileSize,
741
- error: p.error,
742
- downloadUrl: D
743
- });
744
- } catch (p) {
745
- console.error(`Failed to refresh export ${N.id}:`, p);
746
- }
747
- })
748
- );
749
- } finally {
750
- c(!1);
751
- }
752
- }
753
- }, [
754
- m,
755
- e == null ? void 0 : e.accessToken,
756
- a == null ? void 0 : a.apiServiceUrl,
757
- h
758
- ]), u = L(async () => {
759
- const v = a == null ? void 0 : a.apiServiceUrl, C = e == null ? void 0 : e.accessToken;
760
- if (!v || !C) {
761
- d();
762
- return;
763
- }
764
- s(!0);
765
- try {
766
- const S = f.filter(
767
- (p) => p.status === "completed" || p.status === "failed"
768
- ), N = await Promise.allSettled(
769
- S.map(async (p) => (await ue(v, C, p.id), p.id))
770
- );
771
- for (const p of N)
772
- p.status === "fulfilled" ? o(p.value) : console.error("Failed to delete export:", p.reason);
773
- } finally {
774
- s(!1);
775
- }
776
- }, [
777
- f,
778
- a == null ? void 0 : a.apiServiceUrl,
779
- e == null ? void 0 : e.accessToken,
780
- d,
781
- o
782
- ]), w = L(
783
- async (v) => {
784
- const C = a == null ? void 0 : a.apiServiceUrl, S = e == null ? void 0 : e.accessToken;
785
- if (C && S)
786
- try {
787
- await ue(C, S, v), o(v);
788
- return;
789
- } catch (N) {
790
- console.error(`Failed to cancel export ${v}:`, N);
791
- }
792
- o(v);
793
- },
794
- [a == null ? void 0 : a.apiServiceUrl, e == null ? void 0 : e.accessToken, o]
795
- );
796
- return f.length === 0 ? /* @__PURE__ */ n("div", { className: "p-6 text-center", children: [
797
- /* @__PURE__ */ t(fe, { className: "mx-auto mb-2 h-8 w-8 text-muted-foreground" }),
798
- /* @__PURE__ */ t("p", { className: "text-sm text-muted-foreground", children: "No active exports" }),
799
- /* @__PURE__ */ t("p", { className: "mt-1 text-xs text-muted-foreground", children: "Large exports will appear here" })
800
- ] }) : /* @__PURE__ */ n("div", { className: "flex flex-col", children: [
801
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between border-b px-4 py-3", children: [
802
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
803
- /* @__PURE__ */ t(fe, { className: "h-5 w-5 text-muted-foreground" }),
804
- /* @__PURE__ */ t("h4", { className: "font-semibold", children: "Exports" })
805
- ] }),
806
- /* @__PURE__ */ n("div", { className: "flex items-center gap-1", children: [
807
- /* @__PURE__ */ t(
808
- P,
809
- {
810
- variant: "ghost",
811
- size: "sm",
812
- className: "h-7 w-7 p-0",
813
- onClick: r,
814
- disabled: l,
815
- title: "Refresh status",
816
- children: /* @__PURE__ */ t(
817
- nt,
818
- {
819
- className: `h-4 w-4 ${l ? "animate-spin" : ""}`
820
- }
821
- )
822
- }
823
- ),
824
- b && /* @__PURE__ */ t(
825
- P,
826
- {
827
- variant: "ghost",
828
- size: "sm",
829
- className: "h-7 px-2 text-sm",
830
- onClick: u,
831
- disabled: i,
832
- children: i ? "Clearing..." : "Clear all"
833
- }
834
- )
835
- ] })
836
- ] }),
837
- /* @__PURE__ */ t("div", { className: "max-h-[350px] overflow-y-auto", children: /* @__PURE__ */ t("div", { className: "divide-y", children: f.map((v) => /* @__PURE__ */ t(
838
- Gt,
839
- {
840
- export: v,
841
- onRemove: w
842
- },
843
- v.id
844
- )) }) })
845
- ] });
846
- }
847
- function Ca({
848
- variant: e
849
- }) {
850
- const a = R((i) => i.activeExports), m = it(), d = a.size > 0, o = Array.from(a.values()).some(
851
- (i) => i.status === "completed" || i.status === "failed"
852
- ), l = m > 0 ? m > 9 ? "9+" : String(m) : null;
853
- return /* @__PURE__ */ n(q, { children: [
854
- /* @__PURE__ */ t(Y, { asChild: !0, children: /* @__PURE__ */ n(
855
- P,
856
- {
857
- variant: e ?? "ghost",
858
- size: "xs",
859
- className: "relative w-7 px-0 text-muted-foreground hover:text-foreground",
860
- "aria-label": "Export notifications",
861
- children: [
862
- /* @__PURE__ */ t(lt, { className: "h-3.5 w-3.5" }),
863
- d && /* @__PURE__ */ t(
864
- "span",
865
- {
866
- className: `absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${l ? "-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold" : "right-1 top-1 h-1.5 w-1.5"}`,
867
- children: l
868
- }
869
- )
870
- ]
871
- }
872
- ) }),
873
- /* @__PURE__ */ t(K, { className: "w-80 p-0", align: "end", sideOffset: 8, children: /* @__PURE__ */ t(Wt, {}) })
874
- ] });
875
- }
876
- function Xt(e) {
877
- if (e)
878
- return {
879
- renamed: e.type === "rename" ? { oldId: e.oldId, newId: e.newId } : void 0,
880
- removedControlId: e.type === "remove" ? e.controlId : void 0,
881
- cardBindingsById: e.type === "add" || e.type === "update" ? e.cardBindingsById : void 0,
882
- affectedBindingControlIds: e.type === "add" || e.type === "update" ? e.affectedBindingControlIds : void 0
883
- };
884
- }
885
- function qt({
886
- open: e,
887
- onOpenChange: a,
888
- trigger: m,
889
- showTrigger: d = !0,
890
- initialMode: o = "manage"
891
- }) {
892
- const h = o === "create", {
893
- forceClose: l,
894
- handleOpenChange: c,
895
- isCreateFlowActive: i,
896
- preventPassiveDismissDuringCreate: s,
897
- resolvedOpen: f,
898
- setIsCreateFlowActive: b
899
- } = Ee({
900
- open: e,
901
- onOpenChange: a,
902
- initialCreateFlowActive: o === "create",
903
- // Dialog mode renders a built-in X close button — allow explicit
904
- // closes through `handleOpenChange`. Popover mode has no X; its
905
- // only close-via-trigger path is a re-click that would silently
906
- // wipe the in-progress create flow, so block everything during
907
- // create and make consumers use `forceClose()` from a dedicated
908
- // button.
909
- dismissMode: d ? "passive" : "explicit-only"
910
- }), r = E((g) => g.dashboard), { setDashboardControlsModel: u } = G(), { participants: w } = dt(ke(r)), v = Array.from(
911
- new Map(
912
- w.flatMap(
913
- (g) => g.fieldChoices.map((y) => {
914
- var F;
915
- return [
916
- y.value,
917
- {
918
- option: y,
919
- target: (F = g.fieldTargetMap) == null ? void 0 : F[y.value]
920
- }
921
- ];
922
- })
923
- )
924
- ).values()
925
- ), C = Array.from(
926
- new Map(
927
- w.flatMap(
928
- (g) => g.metricChoices.map((y) => {
929
- var F;
930
- return [
931
- y.value,
932
- {
933
- option: y,
934
- target: (F = g.metricTargetMap) == null ? void 0 : F[y.value]
935
- }
936
- ];
937
- })
938
- )
939
- ).values()
940
- ), S = Pe({
941
- ...r || {},
942
- controls: []
943
- }), N = ct(r), p = (g, y, F) => {
944
- u(
945
- g,
946
- y,
947
- Xt(F)
948
- );
949
- }, D = L(() => {
950
- if (h) {
951
- l();
952
- return;
953
- }
954
- b(!1);
955
- }, [h, l, b]), I = /* @__PURE__ */ t(
956
- Ie,
957
- {
958
- scope: "dashboard",
959
- controls: r.controls || [],
960
- reservedControlIds: S,
961
- defaultValues: r.defaultControlValues || {},
962
- usageByControlId: ut(r),
963
- availableFieldChoices: v,
964
- availableMetricChoices: C,
965
- structuralParticipants: w,
966
- structuralParticipantIdsByControlId: N,
967
- initialCreateFlow: o === "create",
968
- onCreateFlowActiveChange: b,
969
- onCreateFlowComplete: D,
970
- onChange: p,
971
- emptyMessage: "No dashboard controls yet."
972
- }
973
- ), T = i ? "Add dashboard control" : "Dashboard Controls", x = /* @__PURE__ */ n(_, { children: [
974
- /* @__PURE__ */ n("div", { className: "space-y-1", children: [
975
- /* @__PURE__ */ t("h4", { className: "text-sm font-medium", children: "Dashboard Controls" }),
976
- /* @__PURE__ */ t("p", { className: "text-xs text-muted-foreground", children: "Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control." })
977
- ] }),
978
- I
979
- ] });
980
- return d ? /* @__PURE__ */ n(q, { open: f, onOpenChange: c, children: [
981
- /* @__PURE__ */ t(Y, { asChild: !0, children: m || /* @__PURE__ */ n(P, { variant: "outline", className: "h-7 px-2", size: "sm", children: [
982
- /* @__PURE__ */ t(te, { className: "mr-2 h-4 w-4" }),
983
- "Controls"
984
- ] }) }),
985
- /* @__PURE__ */ t(
986
- K,
987
- {
988
- className: "w-[620px] max-w-[95vw] space-y-4",
989
- align: "end",
990
- onEscapeKeyDown: s,
991
- onPointerDownOutside: s,
992
- children: x
993
- }
994
- )
995
- ] }) : /* @__PURE__ */ t(ae, { open: f, onOpenChange: c, children: /* @__PURE__ */ n(
996
- se,
997
- {
998
- className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
999
- onEscapeKeyDown: s,
1000
- onPointerDownOutside: s,
1001
- children: [
1002
- /* @__PURE__ */ n(
1003
- oe,
1004
- {
1005
- className: i ? "space-y-0" : void 0,
1006
- children: [
1007
- /* @__PURE__ */ t(re, { className: "text-[15px]", children: T }),
1008
- /* @__PURE__ */ t(
1009
- ne,
1010
- {
1011
- className: i ? "sr-only" : "text-[13px]",
1012
- children: i ? "Configure and add a shared dashboard control." : "Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."
1013
- }
1014
- )
1015
- ]
1016
- }
1017
- ),
1018
- /* @__PURE__ */ t("div", { className: "min-h-0 overflow-y-auto pr-1", children: I })
1019
- ]
1020
- }
1021
- ) });
1022
- }
1023
- const Yt = [
1024
- "enum",
1025
- "multi_enum",
1026
- "text",
1027
- "number",
1028
- "boolean",
1029
- "date"
1030
- ];
1031
- function Kt({
1032
- open: e,
1033
- onOpenChange: a,
1034
- initialMode: m = "manage"
1035
- }) {
1036
- var x;
1037
- const d = m === "create", {
1038
- forceClose: o,
1039
- handleOpenChange: h,
1040
- isCreateFlowActive: l,
1041
- preventPassiveDismissDuringCreate: c,
1042
- resolvedOpen: i,
1043
- setIsCreateFlowActive: s
1044
- } = Ee({
1045
- open: e,
1046
- onOpenChange: a,
1047
- initialCreateFlowActive: m === "create",
1048
- dismissMode: "explicit-only"
1049
- }), f = E((g) => g.dashboard), b = E((g) => g.selectedSheetId), { setDashboardInputs: r } = G(), u = (x = f.sheets) == null ? void 0 : x.find(
1050
- (g) => g.id === b
1051
- ), w = (u == null ? void 0 : u.kind) === "document" && !!u.document, v = H(
1052
- () => w && (u != null && u.document) ? mt(f, u.id) : [],
1053
- [f, w, u == null ? void 0 : u.document, u == null ? void 0 : u.id]
1054
- ), C = H(
1055
- () => v.filter(
1056
- (g) => g.kind === "control"
1057
- ),
1058
- [v]
1059
- ), S = H(
1060
- () => C.map((g) => g.control),
1061
- [C]
1062
- ), N = H(
1063
- () => Jt(S),
1064
- [S]
1065
- ), p = H(
1066
- () => Qt(f),
1067
- [f]
1068
- ), D = L(() => {
1069
- if (d) {
1070
- o();
1071
- return;
1072
- }
1073
- s(!1);
1074
- }, [d, o, s]), I = L(
1075
- (g, y, F) => {
1076
- !w || !(u != null && u.document) || r(
1077
- ea({
1078
- allInputs: f.inputs || [],
1079
- documentSheetId: u.id,
1080
- currentDocumentInputs: v,
1081
- nextControls: g,
1082
- nextDefaultValues: y,
1083
- change: F
1084
- })
1085
- );
1086
- },
1087
- [
1088
- f.inputs,
1089
- v,
1090
- w,
1091
- u,
1092
- r
1093
- ]
1094
- );
1095
- return !w || !(u != null && u.document) ? null : /* @__PURE__ */ t(ae, { open: i, onOpenChange: h, children: /* @__PURE__ */ n(
1096
- se,
1097
- {
1098
- className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
1099
- onEscapeKeyDown: c,
1100
- onPointerDownOutside: c,
1101
- children: [
1102
- /* @__PURE__ */ n(oe, { className: l ? "space-y-0" : void 0, children: [
1103
- /* @__PURE__ */ t(re, { className: "text-[15px]", children: l ? "Add document control" : "Document Controls" }),
1104
- /* @__PURE__ */ t(
1105
- ne,
1106
- {
1107
- className: l ? "sr-only" : "text-[13px]",
1108
- children: l ? "Configure and add a document-local control input." : "Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."
1109
- }
1110
- )
1111
- ] }),
1112
- /* @__PURE__ */ t("div", { className: "min-h-0 overflow-y-auto pr-1", children: /* @__PURE__ */ t(
1113
- Ie,
1114
- {
1115
- scope: "dashboard",
1116
- controls: S,
1117
- reservedControlIds: p,
1118
- defaultValues: N,
1119
- usageByControlId: {},
1120
- availableFieldChoices: [],
1121
- availableMetricChoices: [],
1122
- structuralParticipants: [],
1123
- structuralParticipantIdsByControlId: {},
1124
- allowedControlTypes: Yt,
1125
- initialCreateFlow: m === "create",
1126
- onCreateFlowActiveChange: s,
1127
- onCreateFlowComplete: D,
1128
- onChange: I,
1129
- emptyMessage: "No document controls yet."
1130
- }
1131
- ) })
1132
- ]
1133
- }
1134
- ) });
1135
- }
1136
- function Qt(e) {
1137
- return (e.controls || []).map((a) => a.id);
1138
- }
1139
- function Jt(e) {
1140
- const a = {};
1141
- for (const m of e)
1142
- m.defaultValue !== void 0 && (a[m.id] = m.defaultValue);
1143
- return a;
1144
- }
1145
- function Zt(e, a) {
1146
- return a ? Object.prototype.hasOwnProperty.call(a, e.id) ? {
1147
- ...e,
1148
- defaultValue: a[e.id]
1149
- } : e.defaultValue === void 0 ? e : { ...e, defaultValue: void 0 } : e.defaultValue === void 0 ? e : { ...e, defaultValue: void 0 };
1150
- }
1151
- function ea({
1152
- allInputs: e,
1153
- documentSheetId: a,
1154
- currentDocumentInputs: m,
1155
- nextControls: d,
1156
- nextDefaultValues: o,
1157
- change: h
1158
- }) {
1159
- const l = new Map(
1160
- d.map((r) => [
1161
- r.id,
1162
- Zt(r, o)
1163
- ])
1164
- ), c = (h == null ? void 0 : h.type) === "rename" ? { oldId: h.oldId, newId: h.newId } : null, i = /* @__PURE__ */ new Set(), s = [];
1165
- for (const r of m) {
1166
- if (r.kind !== "control") {
1167
- s.push(r);
1168
- continue;
1169
- }
1170
- const u = l.get(r.control.id) || ((c == null ? void 0 : c.oldId) === r.control.id ? l.get(c.newId) : void 0);
1171
- if (!u)
1172
- continue;
1173
- i.add(u.id);
1174
- const w = ht(
1175
- u.id,
1176
- [...e, ...s].filter(
1177
- (C) => C.id !== r.id
1178
- )
1179
- ), v = u.id === w ? u : { ...u, id: w };
1180
- s.push({
1181
- ...r,
1182
- label: v.label,
1183
- variableName: w,
1184
- requiredAtExecution: v.requiredAtExecution,
1185
- control: v
1186
- });
1187
- }
1188
- for (const r of l.values())
1189
- i.has(r.id) || s.push(
1190
- pt({
1191
- control: r,
1192
- existingInputs: [...e, ...s],
1193
- sheetId: a
1194
- })
1195
- );
1196
- const f = new Set(
1197
- m.map((r) => r.id)
1198
- );
1199
- return [...e.filter(
1200
- (r) => !f.has(r.id)
1201
- ), ...s];
1202
- }
1203
- function ta({
1204
- showFilters: e,
1205
- onShowFiltersChange: a,
1206
- pickerContent: m,
1207
- settingsContent: d,
1208
- size: o = "default",
1209
- className: h,
1210
- primaryButtonClassName: l,
1211
- secondaryButtonClassName: c,
1212
- pickerContentClassName: i,
1213
- settingsContentClassName: s
1214
- }) {
1215
- const f = o === "toolbar", [b, r] = k(!1), u = ft("interactive");
1216
- return /* @__PURE__ */ n(
1217
- "div",
1218
- {
1219
- className: $(
1220
- // Height lives on the shell so the outer border is part of the
1221
- // h-7 box (matches regular `size="xs"` buttons). Inner triggers
1222
- // stretch to fill via `h-full`.
1223
- "relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",
1224
- f ? "h-8" : "h-7",
1225
- h
1226
- ),
1227
- children: [
1228
- /* @__PURE__ */ n(q, { open: e, onOpenChange: a, children: [
1229
- /* @__PURE__ */ t(Y, { asChild: !0, children: /* @__PURE__ */ n(
1230
- P,
1231
- {
1232
- variant: "ghost",
1233
- size: "xs",
1234
- className: $(
1235
- "h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",
1236
- l
1237
- ),
1238
- children: [
1239
- e ? /* @__PURE__ */ t(Vt, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Se, { className: "h-3.5 w-3.5" }),
1240
- "Filter"
1241
- ]
1242
- }
1243
- ) }),
1244
- /* @__PURE__ */ t(
1245
- K,
1246
- {
1247
- align: "end",
1248
- sideOffset: 6,
1249
- className: $(
1250
- "w-auto rounded-card border border-border/60 p-0 shadow-sm",
1251
- i
1252
- ),
1253
- style: u.contentStyle,
1254
- children: m
1255
- }
1256
- )
1257
- ] }),
1258
- /* @__PURE__ */ n(q, { open: b, onOpenChange: r, children: [
1259
- /* @__PURE__ */ t(Y, { asChild: !0, children: /* @__PURE__ */ t(
1260
- P,
1261
- {
1262
- variant: "ghost",
1263
- size: "xs",
1264
- className: $(
1265
- "h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",
1266
- c
1267
- ),
1268
- "aria-label": "Filter and control actions",
1269
- children: /* @__PURE__ */ t(Ce, { className: "h-3.5 w-3.5" })
1270
- }
1271
- ) }),
1272
- /* @__PURE__ */ t(
1273
- K,
1274
- {
1275
- align: "end",
1276
- sideOffset: 6,
1277
- className: $(
1278
- "w-auto rounded-card border border-border/60 p-0 shadow-sm",
1279
- s
1280
- ),
1281
- style: u.contentStyle,
1282
- children: d(() => r(!1))
1283
- }
1284
- )
1285
- ] })
1286
- ]
1287
- }
1288
- );
1289
- }
1290
- function aa() {
1291
- kt();
1292
- const e = E((i) => i.selectedSheetId), a = E((i) => i.selectedFrameId), m = E((i) => i.dashboard), d = E((i) => i.actions.getSelectedFrame), { setSelectedFrameId: o } = G(), { setCard: h } = we(), l = j((i) => i.card.dataSource);
1293
- return z(() => {
1294
- var s, f;
1295
- let i = d();
1296
- if (!i) {
1297
- const b = (s = m == null ? void 0 : m.sheets) == null ? void 0 : s.find((u) => u.id === e), r = (f = b == null ? void 0 : b.frames) == null ? void 0 : f[0];
1298
- r && (o(r.id), i = r);
1299
- }
1300
- if (i) {
1301
- const b = i.cards.find((r) => r.id === i.activeCardId);
1302
- b && h(b);
1303
- }
1304
- }, [d, e, a, m, o, h]), {
1305
- hasEntities: !!(l != null && l.selectedEntities && l.selectedEntities.length > 0)
1306
- };
1307
- }
1308
- function sa() {
1309
- const e = E((c) => c.dashboard), a = E(
1310
- (c) => c.semanticExecutionPayload
1311
- ), m = E((c) => c.actions.addFilter), { hasEntities: d } = aa(), o = H(
1312
- () => gt(e, a),
1313
- [e, a]
1314
- ), l = !vt(e.filters) && o.hasEligibleCards;
1315
- return /* @__PURE__ */ n("div", { className: "flex h-[520px] w-[400px] flex-col", children: [
1316
- l && /* @__PURE__ */ n("div", { className: "border-b border-border/60 p-2", children: [
1317
- /* @__PURE__ */ n("p", { className: "mb-1 flex items-center gap-1 px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: [
1318
- /* @__PURE__ */ t(bt, { className: "h-2.5 w-2.5" }),
1319
- "Suggested"
1320
- ] }),
1321
- /* @__PURE__ */ n(
1322
- "button",
1323
- {
1324
- type: "button",
1325
- onClick: () => m(Ct()),
1326
- title: `Eligible: ${o.eligibleCardCount} of ${o.totalCardCount} cards`,
1327
- className: "flex w-full items-start gap-2 rounded-[4px] px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",
1328
- children: [
1329
- /* @__PURE__ */ t(xt, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
1330
- /* @__PURE__ */ n("span", { className: "flex min-w-0 flex-col", children: [
1331
- /* @__PURE__ */ t("span", { className: "text-[12px] font-medium text-foreground", children: "Global date filter" }),
1332
- /* @__PURE__ */ t("span", { className: "text-[11px] leading-[1.4] text-muted-foreground", children: "One date range, applied across every date-aware card on the dashboard." })
1333
- ] })
1334
- ]
1335
- }
1336
- )
1337
- ] }),
1338
- !d && /* @__PURE__ */ n("div", { className: "flex flex-1 flex-col items-center justify-center px-6 py-8 text-center", children: [
1339
- /* @__PURE__ */ t(wt, { className: "mb-3 h-10 w-10 text-muted-foreground/50" }),
1340
- /* @__PURE__ */ t("h3", { className: "mb-1 text-[13px] font-medium text-foreground", children: "No fields configured" }),
1341
- /* @__PURE__ */ t("p", { className: "text-[11px] text-muted-foreground", children: "Configure a data source for this card to enable filtering." })
1342
- ] }),
1343
- d && /* @__PURE__ */ t("div", { className: "flex flex-1 overflow-hidden", children: /* @__PURE__ */ t(yt, { context: "filter" }) })
1344
- ] });
1345
- }
1346
- const ve = !1;
1347
- function oa({
1348
- onAddFilter: e,
1349
- onAddControl: a,
1350
- onManageControls: m,
1351
- onDismiss: d
1352
- }) {
1353
- const o = E(
1354
- (c) => c.dashboard.filterLayout
1355
- ), { setFilterLayout: h } = G();
1356
- o != null && o.displayMode;
1357
- const l = (o == null ? void 0 : o.toolbarWrap) ?? !1;
1358
- return o == null || o.showDownloadButton, /* @__PURE__ */ n("div", { className: "w-[300px]", children: [
1359
- /* @__PURE__ */ n("div", { className: "p-1", children: [
1360
- /* @__PURE__ */ t(
1361
- Q,
1362
- {
1363
- icon: Se,
1364
- label: "Add filter",
1365
- onClick: () => {
1366
- e(), d();
1367
- }
1368
- }
1369
- ),
1370
- /* @__PURE__ */ t(
1371
- Q,
1372
- {
1373
- icon: te,
1374
- label: "Add control",
1375
- onClick: () => {
1376
- a(), d();
1377
- }
1378
- }
1379
- ),
1380
- /* @__PURE__ */ t(
1381
- Q,
1382
- {
1383
- icon: Dt,
1384
- label: "Manage controls",
1385
- onClick: () => {
1386
- m(), d();
1387
- }
1388
- }
1389
- )
1390
- ] }),
1391
- /* @__PURE__ */ t("div", { className: "border-t border-border/60" }),
1392
- /* @__PURE__ */ n("div", { className: "space-y-1 p-2", children: [
1393
- /* @__PURE__ */ t("p", { className: "px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Display" }),
1394
- ve,
1395
- /* @__PURE__ */ t(
1396
- ra,
1397
- {
1398
- id: "filter-display-wrap",
1399
- label: "Wrap to multiple lines",
1400
- checked: l,
1401
- onCheckedChange: (c) => h({ toolbarWrap: c === !0 })
1402
- }
1403
- ),
1404
- ve
1405
- ] })
1406
- ] });
1407
- }
1408
- function Q({
1409
- icon: e,
1410
- label: a,
1411
- onClick: m
1412
- }) {
1413
- return /* @__PURE__ */ n(
1414
- "button",
1415
- {
1416
- type: "button",
1417
- onClick: m,
1418
- className: "flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[13px] text-foreground transition-colors hover:bg-muted/40",
1419
- children: [
1420
- /* @__PURE__ */ t(e, { className: "h-3.5 w-3.5 text-muted-foreground" }),
1421
- a
1422
- ]
1423
- }
1424
- );
1425
- }
1426
- function ra({
1427
- id: e,
1428
- label: a,
1429
- checked: m,
1430
- onCheckedChange: d
1431
- }) {
1432
- return /* @__PURE__ */ n("div", { className: "flex items-center gap-2 rounded-[4px] px-1 py-1 transition-colors hover:bg-muted/40", children: [
1433
- /* @__PURE__ */ t(Nt, { id: e, checked: m, onCheckedChange: d }),
1434
- /* @__PURE__ */ t(
1435
- J,
1436
- {
1437
- htmlFor: e,
1438
- className: "cursor-pointer text-[12px] font-normal leading-[1.3]",
1439
- children: a
1440
- }
1441
- )
1442
- ] });
1443
- }
1444
- function wa({
1445
- size: e,
1446
- className: a,
1447
- primaryButtonClassName: m,
1448
- secondaryButtonClassName: d,
1449
- pickerContentClassName: o,
1450
- settingsContentClassName: h
1451
- }) {
1452
- var T;
1453
- const [l, c] = k(null), i = E((x) => x.dashboard), s = E((x) => x.selectedSheetId), f = E((x) => x.showFilters), b = St((x) => x.setPanelOpen), r = E((x) => x.actions), { setDocumentInspectorTab: u, setShowFilters: w } = r, v = (T = i.sheets) == null ? void 0 : T.find(
1454
- (x) => x.id === s
1455
- ), C = Oe(v), S = L((x) => {
1456
- window.setTimeout(() => {
1457
- c(x);
1458
- }, 0);
1459
- }, []), N = L(
1460
- (x) => {
1461
- if (C && s) {
1462
- x && u(s, "inputs");
1463
- return;
1464
- }
1465
- x && b("dashboard", !1), w(x);
1466
- },
1467
- [
1468
- C,
1469
- s,
1470
- u,
1471
- b,
1472
- w
1473
- ]
1474
- ), p = L(() => {
1475
- N(!0);
1476
- }, [N]), D = L(() => {
1477
- S("create");
1478
- }, [S]), I = L(() => {
1479
- S("manage");
1480
- }, [S]);
1481
- return /* @__PURE__ */ n(_, { children: [
1482
- /* @__PURE__ */ t(
1483
- ta,
1484
- {
1485
- showFilters: C ? !1 : f,
1486
- onShowFiltersChange: N,
1487
- pickerContent: /* @__PURE__ */ t(sa, {}),
1488
- settingsContent: (x) => /* @__PURE__ */ t(
1489
- oa,
1490
- {
1491
- onAddFilter: p,
1492
- onAddControl: D,
1493
- onManageControls: I,
1494
- onDismiss: x
1495
- }
1496
- ),
1497
- size: e,
1498
- className: a,
1499
- primaryButtonClassName: m,
1500
- secondaryButtonClassName: d,
1501
- pickerContentClassName: o,
1502
- settingsContentClassName: h
1503
- }
1504
- ),
1505
- l ? C ? /* @__PURE__ */ t(
1506
- Kt,
1507
- {
1508
- open: !0,
1509
- onOpenChange: (x) => {
1510
- x || c(null);
1511
- },
1512
- initialMode: l
1513
- }
1514
- ) : /* @__PURE__ */ t(
1515
- qt,
1516
- {
1517
- open: !0,
1518
- onOpenChange: (x) => {
1519
- x || c(null);
1520
- },
1521
- showTrigger: !1,
1522
- initialMode: l
1523
- }
1524
- ) : null
1525
- ] });
1526
- }
1527
- export {
1528
- ga as A,
1529
- qt as D,
1530
- Wt as E,
1531
- Ca as N,
1532
- va as U,
1533
- fa as V,
1534
- Gt as a,
1535
- xa as b,
1536
- Kt as c,
1537
- ta as d,
1538
- wa as e,
1539
- ba as u
1540
- };