serverside_pivot 0.0.95 → 0.0.96

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 (39) hide show
  1. package/dist/react/chunks/ContextMenu-DJuS4qTZ.mjs +198 -0
  2. package/dist/react/chunks/{DetailDrawer-DCKIxSpW.mjs → DetailDrawer-DgKSC5Vu.mjs} +1 -1
  3. package/dist/react/chunks/{DetailSidePanel-DgUWPBQk.mjs → DetailSidePanel-CC5Dugyl.mjs} +1 -1
  4. package/dist/react/chunks/{DetailSurfaceContent-BEL6xuaZ.mjs → DetailSurfaceContent-CrQVHlcU.mjs} +52 -53
  5. package/dist/react/chunks/{ECharts2dRenderer-Dgkp9_1P.mjs → ECharts2dRenderer-46gLrUdf.mjs} +1 -1
  6. package/dist/react/chunks/{ECharts3dRenderer-70VOp8V0.mjs → ECharts3dRenderer-Dg4ta5Bl.mjs} +1 -1
  7. package/dist/react/chunks/{EditSidePanel-CygqVXLX.mjs → EditSidePanel-CkShaByb.mjs} +1 -1
  8. package/dist/react/chunks/{InlineDetailPanel-BUBRWdFW.mjs → InlineDetailPanel-mnwjoD0I.mjs} +1 -1
  9. package/dist/react/chunks/{PivotCharts-VX5-mEEp.mjs → PivotCharts-MX-Z7DlR.mjs} +1207 -1193
  10. package/dist/react/chunks/{ReportEditor-B5j-CU9-.mjs → ReportEditor-U0E42xKL.mjs} +506 -480
  11. package/dist/react/chunks/SidebarPanel-BzRW1Kgq.mjs +3944 -0
  12. package/dist/react/chunks/{SparklineDetailGraph-Cfe2KcOp.mjs → SparklineDetailGraph-35Tim_8B.mjs} +1 -1
  13. package/dist/react/chunks/{installCanvasRenderer-C4h5pc1p.mjs → installCanvasRenderer-DRq0xpXO.mjs} +1 -1
  14. package/dist/react/chunks/react-CL4GbEOd.mjs +33206 -0
  15. package/dist/react/chunks/{xlsx.mini.min-CzdkdH3N.mjs → xlsx.mini.min-kfIgXMVB.mjs} +1 -1
  16. package/dist/react/components/DashTanstackPivot.react.d.ts +4 -0
  17. package/dist/react/components/ShimmerFallback.d.ts +11 -0
  18. package/dist/react/components/ThemedSelect.d.ts +8 -0
  19. package/dist/react/contexts/PivotThemeContext.d.ts +1 -0
  20. package/dist/react/hooks/useColumnDefs.d.ts +1 -1
  21. package/dist/react/hooks/useRenderHelpers.d.ts +1 -1
  22. package/dist/react/hooks/useServerSideRowModel.d.ts +1 -1
  23. package/dist/react/index.mjs +5 -5
  24. package/dist/react/react.d.ts +1 -1
  25. package/dist/react/runtime/client/clientPivotTransport.d.ts +1 -0
  26. package/dist/react/runtime/client/duckdbWasmExecutor.d.ts +3 -0
  27. package/dist/react/runtime/client/types.d.ts +12 -0
  28. package/dist/react/runtime/runtimeDomains.d.ts +94 -2
  29. package/dist/react/runtime/useRuntimeColumnAutoSizing.d.ts +1 -1
  30. package/dist/react/runtime/useRuntimeViewSnapshot.d.ts +1 -1
  31. package/dist/react/utils/dataBars.d.ts +1 -0
  32. package/dist/react/utils/domEvents.d.ts +1 -0
  33. package/dist/react/utils/helpers.d.ts +5 -0
  34. package/dist/react/utils/pivotLayoutUtils.d.ts +4 -0
  35. package/dist/react/utils/sorting.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/dist/react/chunks/ContextMenu-1G-o1ms9.mjs +0 -195
  38. package/dist/react/chunks/SidebarPanel-LXUE6nPd.mjs +0 -3742
  39. package/dist/react/chunks/react-CDa-ADnG.mjs +0 -31199
@@ -1,3742 +0,0 @@
1
- import e, { useState as be, useRef as mt, useEffect as er } from "react";
2
- import { z, Z as fe, _ as Wr, $ as Br, a0 as xt, a1 as Je, a2 as Ir, a3 as Lr, a4 as Pr, a5 as Fe, a6 as Qe, a7 as et, F as Or, a8 as Hr, a9 as Ur, aa as jr, ab as Pe, ac as tr, ad as Vr, ae as Ht, af as Zr, ag as Yr, ah as Kr, ai as Gr, aj as Nr, ak as Xr } from "./react-CDa-ADnG.mjs";
3
- const Jr = ({ column: t, theme: n, styles: s, onFilter: a, currentFilter: l, options: g, optionMeta: u, onSearchOptions: E, onLoadMoreOptions: d, onOpen: $ }) => {
4
- const [i, m] = be(!1), T = l && (l.conditions || l.value), L = () => m(!1), _ = () => {
5
- const D = !i;
6
- m(D), D && typeof $ == "function" && $(t.id);
7
- };
8
- return /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, /* @__PURE__ */ e.createElement(
9
- "div",
10
- {
11
- style: {
12
- ...s.columnItem,
13
- cursor: "pointer",
14
- background: i ? n.select : "transparent",
15
- borderLeft: T ? `3px solid ${n.primary}` : "3px solid transparent"
16
- },
17
- onClick: _
18
- },
19
- /* @__PURE__ */ e.createElement("span", { style: { marginRight: "8px", opacity: 0.7, display: "flex" } }, i ? /* @__PURE__ */ e.createElement(z.ChevronDown, null) : /* @__PURE__ */ e.createElement(z.ChevronRight, null)),
20
- /* @__PURE__ */ e.createElement("span", { style: { flex: 1, fontWeight: 500, display: "flex", alignItems: "center", gap: "6px" } }, T && /* @__PURE__ */ e.createElement(z.Filter, { style: { fontSize: "12px", color: n.primary } }), fe(typeof t.header == "string" ? t.header : t.columnDef && typeof t.columnDef.header == "string" ? t.columnDef.header : t.id))
21
- ), i && /* @__PURE__ */ e.createElement("div", { style: { padding: "8px", borderBottom: `1px solid ${n.border}44` } }, /* @__PURE__ */ e.createElement(
22
- Wr,
23
- {
24
- column: t,
25
- onFilter: a,
26
- currentFilter: l,
27
- options: g,
28
- optionMeta: u,
29
- onSearchOptions: E,
30
- onLoadMoreOptions: d,
31
- theme: n,
32
- onClose: L
33
- }
34
- )));
35
- }, gt = ({ title: t, children: n, items: s, renderItem: a, theme: l, styles: g, initialExpanded: u = !0, count: E, onDrop: d, sectionId: $ }) => {
36
- const [i, m] = be(u), [T, L] = be(u ? 200 : 0), [_, D] = be(!1), y = mt(null);
37
- mt(null), er(() => {
38
- if (i && y.current) {
39
- const k = y.current.scrollHeight;
40
- L(Math.min(k, 300));
41
- } else
42
- L(0);
43
- }, [i, s, E]);
44
- const h = Br({
45
- count: s ? s.length : 0,
46
- getScrollElement: () => y.current,
47
- estimateSize: () => 32,
48
- overscan: 10,
49
- enabled: !!s && i
50
- }), w = (k) => {
51
- k.preventDefault(), D(!0);
52
- }, W = () => {
53
- D(!1);
54
- }, O = (k) => {
55
- k.preventDefault(), D(!1);
56
- const P = k.dataTransfer.getData("text/plain");
57
- d && P && d(P, $);
58
- };
59
- return /* @__PURE__ */ e.createElement(
60
- "div",
61
- {
62
- style: {
63
- ...g.toolPanelSection,
64
- flex: i ? "0 1 auto" : "0 0 auto",
65
- minHeight: i ? "40px" : "32px",
66
- overflow: "hidden"
67
- // Prevent overlap
68
- },
69
- onDragOver: w,
70
- onDragLeave: W,
71
- onDrop: O
72
- },
73
- /* @__PURE__ */ e.createElement("div", { style: g.toolPanelSectionHeader, onClick: () => m(!i) }, /* @__PURE__ */ e.createElement("span", { style: { marginRight: "8px", opacity: 0.7, display: "flex" } }, i ? /* @__PURE__ */ e.createElement(z.ChevronDown, null) : /* @__PURE__ */ e.createElement(z.ChevronRight, null)), /* @__PURE__ */ e.createElement("span", { style: { flex: 1 } }, t), E !== void 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", opacity: 0.5, background: l.hover, padding: "2px 6px", borderRadius: "10px" } }, E)),
74
- /* @__PURE__ */ e.createElement(
75
- "div",
76
- {
77
- ref: y,
78
- style: {
79
- ...g.toolPanelList,
80
- height: `${T}px`,
81
- overflowY: i ? "auto" : "hidden",
82
- transition: "height 0.3s ease",
83
- opacity: i ? 1 : 0
84
- }
85
- },
86
- s ? /* @__PURE__ */ e.createElement("div", { style: {
87
- height: `${h.getTotalSize()}px`,
88
- width: "100%",
89
- position: "relative"
90
- } }, h.getVirtualItems().map(
91
- /** @param {any} [virtualRow] @returns {any} */
92
- (k) => /* @__PURE__ */ e.createElement(
93
- "div",
94
- {
95
- key: k.index,
96
- style: {
97
- position: "absolute",
98
- top: 0,
99
- left: 0,
100
- width: "100%",
101
- height: `${k.size}px`,
102
- transform: `translateY(${k.start}px)`
103
- }
104
- },
105
- a(s[k.index], k.index)
106
- )
107
- )) : n
108
- )
109
- );
110
- }, rr = ({ column: t, level: n, theme: s, styles: a, handlePinColumn: l, colSearch: g, selectedCols: u, setSelectedCols: E, onDrop: d, sectionId: $ }) => {
111
- const [i, m] = be(n < 1), [T, L] = be(!1), [_, D] = be(!1), y = mt(null), h = t.columns && t.columns.length > 0, w = t.columnDef.header;
112
- let W = typeof w == "string" ? w : t.id;
113
- typeof W == "string" && W.startsWith("group_") && (W = t.id.replace("group_", "").split("|||").pop() || W), t.headerVal && (W = t.headerVal), W = fe(W);
114
- const O = t.getIsPinned(), k = t.getIsVisible(), P = h ? xt(t) : [t.id], o = P.length > 0 && P.every((v) => u.has(v)), A = !o && P.some((v) => u.has(v));
115
- if (er(() => {
116
- y.current && (y.current.indeterminate = A);
117
- }, [A]), g && !W.toLowerCase().includes(g.toLowerCase()))
118
- if (h) {
119
- const v = (U) => {
120
- const Q = U.columnDef.header;
121
- return (typeof Q == "string" ? Q : U.id).toLowerCase().includes(g.toLowerCase()) ? !0 : U.columns ? U.columns.some(v) : !1;
122
- };
123
- if (!v(t)) return null;
124
- } else
125
- return null;
126
- const R = (v) => {
127
- v.stopPropagation();
128
- const U = new Set(u), Q = h ? xt(t) : [t.id];
129
- Q.every(
130
- /** @param {any} [id] @returns {any} */
131
- (ee) => U.has(ee)
132
- ) ? Q.forEach(
133
- /** @param {any} [id] @returns {any} */
134
- (ee) => U.delete(ee)
135
- ) : Q.forEach(
136
- /** @param {any} [id] @returns {any} */
137
- (ee) => U.add(ee)
138
- ), E(U);
139
- }, B = (v) => {
140
- if (v.stopPropagation(), h) {
141
- const U = Ir(t), Q = U.some(
142
- /** @param {any} [c] @returns {any} */
143
- (V) => !V.getIsVisible()
144
- );
145
- U.forEach(
146
- /** @param {any} [c] @returns {any} */
147
- (V) => V.toggleVisibility(Q)
148
- );
149
- } else
150
- t.toggleVisibility();
151
- }, M = (v, U) => {
152
- v.stopPropagation(), l(t.id, U);
153
- }, H = (v) => {
154
- D(!0), v.dataTransfer.setData("text/plain", t.id), v.dataTransfer.effectAllowed = "move";
155
- }, K = () => {
156
- D(!1);
157
- }, x = (v) => {
158
- v.preventDefault(), v.stopPropagation();
159
- const U = v.dataTransfer.getData("text/plain");
160
- U && d && U !== t.id && d(U, $, t.id);
161
- }, F = (v) => {
162
- v.key === "Enter" ? B(v) : v.key === " " ? (v.preventDefault(), R(v)) : v.altKey && v.key === "ArrowLeft" ? (v.preventDefault(), l(t.id, "left")) : v.altKey && v.key === "ArrowRight" ? (v.preventDefault(), l(t.id, "right")) : v.altKey && v.key === "ArrowDown" && (v.preventDefault(), l(t.id, !1));
163
- };
164
- return /* @__PURE__ */ e.createElement(
165
- "div",
166
- {
167
- style: { display: "flex", flexDirection: "column", opacity: _ ? 0.5 : 1 },
168
- draggable: !h,
169
- onDragStart: H,
170
- onDragEnd: K,
171
- onDragOver: (v) => v.preventDefault(),
172
- onDrop: x,
173
- role: "treeitem",
174
- "aria-selected": o || A,
175
- "aria-expanded": i
176
- },
177
- /* @__PURE__ */ e.createElement(
178
- "div",
179
- {
180
- style: {
181
- ...a.columnItem,
182
- paddingLeft: `${n * 12 + 8}px`,
183
- // Reduced indentation step
184
- background: o || A ? s.select : T ? s.hover : "transparent",
185
- borderLeft: O ? `3px solid ${s.primary}` : "3px solid transparent"
186
- },
187
- onMouseEnter: (v) => !(o || A) && L(!0),
188
- onMouseLeave: (v) => !(o || A) && L(!1),
189
- tabIndex: 0,
190
- onKeyDown: F
191
- },
192
- /* @__PURE__ */ e.createElement(
193
- "input",
194
- {
195
- ref: y,
196
- type: "checkbox",
197
- checked: o,
198
- onChange: R,
199
- onClick: (v) => v.stopPropagation(),
200
- style: { margin: 0, cursor: "pointer", pointerEvents: "auto" },
201
- tabIndex: -1
202
- }
203
- ),
204
- !h && /* @__PURE__ */ e.createElement("span", { style: { cursor: "grab", display: "flex", opacity: 0.7, marginRight: "4px" } }, /* @__PURE__ */ e.createElement(z.DragIndicator, null)),
205
- h ? /* @__PURE__ */ e.createElement(
206
- "span",
207
- {
208
- role: "button",
209
- tabIndex: 0,
210
- "aria-expanded": i,
211
- "aria-label": i ? `Collapse ${W}` : `Expand ${W}`,
212
- onClick: () => m(!i),
213
- onKeyDown: (v) => {
214
- (v.key === "Enter" || v.key === " ") && (v.preventDefault(), m(!i));
215
- },
216
- style: { cursor: "pointer", display: "flex", opacity: 0.7, marginRight: "4px" }
217
- },
218
- i ? /* @__PURE__ */ e.createElement(z.ChevronDown, null) : /* @__PURE__ */ e.createElement(z.ChevronRight, null)
219
- ) : /* @__PURE__ */ e.createElement("span", { style: { width: "20px" } }),
220
- /* @__PURE__ */ e.createElement(
221
- "span",
222
- {
223
- onClick: B,
224
- style: {
225
- cursor: "pointer",
226
- display: "flex",
227
- color: k ? s.primary : s.textSec,
228
- opacity: k ? 1 : 0.5,
229
- marginRight: "4px"
230
- },
231
- title: k ? "Hide Column" : "Show Column",
232
- "aria-label": k ? "Hide Column" : "Show Column"
233
- },
234
- k ? /* @__PURE__ */ e.createElement(z.Visibility, null) : /* @__PURE__ */ e.createElement(z.VisibilityOff, null)
235
- ),
236
- /* @__PURE__ */ e.createElement(
237
- "span",
238
- {
239
- style: {
240
- flex: 1,
241
- overflow: "hidden",
242
- textOverflow: "ellipsis",
243
- whiteSpace: "nowrap",
244
- fontWeight: h ? 600 : 400,
245
- cursor: h ? "pointer" : "default",
246
- color: k ? s.text : s.textSec,
247
- opacity: k ? 1 : 0.6,
248
- display: "flex",
249
- alignItems: "center"
250
- },
251
- onClick: () => h && m(!i),
252
- title: W
253
- },
254
- h && /* @__PURE__ */ e.createElement(z.Group, { style: { marginRight: "6px", fontSize: "14px", opacity: 0.8 } }),
255
- W
256
- ),
257
- !h && /* @__PURE__ */ e.createElement("div", { className: "pin-controls" }, /* @__PURE__ */ e.createElement("button", { onClick: (v) => M(v, "left"), title: "Pin Column Left", "aria-label": "Pin Column Left" }, /* @__PURE__ */ e.createElement(z.PinLeft, null)), /* @__PURE__ */ e.createElement("button", { onClick: (v) => M(v, !1), title: "Unpin Column", "aria-label": "Unpin Column" }, /* @__PURE__ */ e.createElement(z.Unpin, null)), /* @__PURE__ */ e.createElement("button", { onClick: (v) => M(v, "right"), title: "Pin Column Right", "aria-label": "Pin Column Right" }, /* @__PURE__ */ e.createElement(z.PinRight, null)))
258
- ),
259
- h && i && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, t.columns.filter(
260
- /** @param {any} [child] @returns {any} */
261
- (v) => Je(v, $)
262
- ).map(
263
- /** @param {any} [child] @returns {any} */
264
- (v) => /* @__PURE__ */ e.createElement(
265
- rr,
266
- {
267
- key: v.id,
268
- column: v,
269
- level: n + 1,
270
- theme: s,
271
- styles: a,
272
- handlePinColumn: l,
273
- colSearch: g,
274
- selectedCols: u,
275
- setSelectedCols: E,
276
- onDrop: d,
277
- sectionId: $
278
- }
279
- )
280
- ))
281
- );
282
- }, nr = /\b[A-Za-z_][A-Za-z0-9_]*\b/g, lr = /^[A-Za-z_][A-Za-z0-9_]*$/, tt = /\[([^\]]+)\]/g, qr = /* @__PURE__ */ new Set(["abs", "round", "ceil", "floor", "max", "min", "int", "float"]), Qr = /* @__PURE__ */ new Set(["True", "False", "None", "and", "or", "not", "if", "else", "in", "is"]), Ee = {
283
- type: "line",
284
- metric: "last",
285
- showCurrentValue: !0,
286
- showDelta: !0,
287
- compact: !1,
288
- hideColumns: !1,
289
- placement: "before",
290
- source: "pivot",
291
- displayMode: "trend"
292
- };
293
- function ar(t) {
294
- return String(t || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
295
- }
296
- function ve(t, n = "formula") {
297
- const a = String(t || "").trim().toLowerCase().replace(/\s+/g, "").replace(/[^a-z0-9_]/g, "") || String(n || "formula").toLowerCase().replace(/[^a-z0-9_]/g, "") || "formula";
298
- return /^[a-z_]/.test(a) ? a : `f_${a}`;
299
- }
300
- function N(t) {
301
- return !t || typeof t != "object" ? "" : String(
302
- t.formulaRef || ve(t.label || "", t.field || "formula") || t.field || ""
303
- ).trim();
304
- }
305
- function ze(t) {
306
- const n = String(t || "").trim().toLowerCase();
307
- return ["columns", "display", "displayed", "displayed_columns", "rendered", "rendered_columns"].includes(n) ? "columns" : "measures";
308
- }
309
- function xe(t) {
310
- return ze(t) === "columns";
311
- }
312
- const en = [
313
- { value: "eq", label: "Equals" },
314
- { value: "ne", label: "Does not equal" },
315
- { value: "contains", label: "Contains" },
316
- { value: "starts_with", label: "Starts with" },
317
- { value: "ends_with", label: "Ends with" },
318
- { value: "gt", label: ">" },
319
- { value: "gte", label: ">=" },
320
- { value: "lt", label: "<" },
321
- { value: "lte", label: "<=" },
322
- { value: "in", label: "In list" },
323
- { value: "not_in", label: "Not in list" },
324
- { value: "is_null", label: "Is empty" },
325
- { value: "is_not_null", label: "Is not empty" }
326
- ], Ut = /* @__PURE__ */ new Set(["in", "not_in"]), tn = /* @__PURE__ */ new Set(["is_null", "is_not_null"]);
327
- function or(t) {
328
- return { field: t && t[0] || "", operator: "eq", value: "", values: [], caseSensitive: !1 };
329
- }
330
- function ir(t, n = 0) {
331
- return {
332
- id: `rule-${Date.now().toString(36)}-${n}`,
333
- label: n === 0 ? "Group A" : `Group ${n + 1}`,
334
- condition: { op: "AND", clauses: [or(t)] }
335
- };
336
- }
337
- function jt(t, n = null) {
338
- if (n) {
339
- const a = Fe([n])[0] || n;
340
- return { ...JSON.parse(JSON.stringify(a)), __editingField: a.field, __editingId: a.id };
341
- }
342
- const s = Qe(`category_${Date.now().toString(36)}`);
343
- return {
344
- id: s,
345
- field: et(s),
346
- name: "New Category",
347
- fallbackLabel: "Other",
348
- order: "creation",
349
- rules: [ir(t, 0)],
350
- __isNew: !0
351
- };
352
- }
353
- function rn(t, n) {
354
- if (!n) return "string";
355
- const s = Array.isArray(t) ? t.slice(0, 250) : [];
356
- for (let a = 0; a < s.length; a += 1) {
357
- const l = s[a];
358
- if (!l || typeof l != "object") continue;
359
- const g = l[n];
360
- if (!(g == null || g === "")) {
361
- if (typeof g == "number" && Number.isFinite(g)) return "number";
362
- if (g instanceof Date && !Number.isNaN(g.getTime())) return "date";
363
- if (typeof g == "string") {
364
- const u = g.trim();
365
- if (!u) continue;
366
- if (Number.isFinite(Number(u))) return "number";
367
- const E = Date.parse(u);
368
- return !Number.isNaN(E) && /[-/T:]/.test(u) ? "date" : "string";
369
- }
370
- }
371
- }
372
- return "string";
373
- }
374
- const qe = (t, n, s) => (Array.isArray(n) ? n : []).filter((a) => rn(t, a) === s);
375
- function nn(t, n) {
376
- const a = qe(n, t, "date")[0] || t[0] || "", l = Qe(`${a || "date"}_month`);
377
- return {
378
- id: l,
379
- field: et(l),
380
- kind: "date_group",
381
- name: a ? `${fe(a)} Month` : "Date Month",
382
- sourceField: a,
383
- granularity: "month",
384
- fiscalYearStartMonth: 1,
385
- fallbackLabel: "No date",
386
- __isNew: !0
387
- };
388
- }
389
- function ln(t, n) {
390
- const a = qe(n, t, "number")[0] || t[0] || "", l = Qe(`${a || "number"}_bins`);
391
- return {
392
- id: l,
393
- field: et(l),
394
- kind: "number_group",
395
- name: a ? `${fe(a)} Bins` : "Number Bins",
396
- sourceField: a,
397
- binSize: 10,
398
- minValue: "",
399
- maxValue: "",
400
- precision: 0,
401
- fallbackLabel: "No value",
402
- __isNew: !0
403
- };
404
- }
405
- const Vt = (t) => String(t || "").split(",").map((n) => n.trim()).filter(Boolean), Zt = (t) => String(t || "").trim().replace(/\s+/g, " ").toLowerCase(), sr = (t) => t && (t.__editingField || t.field) ? t.__editingField || t.field : "";
406
- function an(t, n) {
407
- const s = Array.isArray(t) ? t : [], a = sr(n);
408
- if (!a) return s;
409
- const l = s.findIndex(
410
- /** @param {any} [dimension] @returns {any} */
411
- (g) => g && g.field === a
412
- );
413
- return l >= 0 ? s.slice(0, l) : s;
414
- }
415
- function Yt(t) {
416
- const n = [];
417
- return (t && Array.isArray(t.rules) ? t.rules : []).forEach(
418
- /** @param {any} [rule] @returns {any} */
419
- (s) => {
420
- (s && s.condition && Array.isArray(s.condition.clauses) ? s.condition.clauses : []).forEach(
421
- /** @param {any} [clause] @returns {any} */
422
- (l) => {
423
- l && l.field && n.push(l.field);
424
- }
425
- );
426
- }
427
- ), Array.from(new Set(n));
428
- }
429
- function on(t, n) {
430
- const s = (Array.isArray(t) ? t : []).filter((a) => a && typeof a == "object").filter((a) => !a._isTotal && a._path !== "__grand_total__" && a._path !== "__color_scale_stats__");
431
- return Lr(s, n || []);
432
- }
433
- function sn(t, n) {
434
- return !Array.isArray(t) || t.length === 0 || !Array.isArray(n) || n.length === 0 ? !1 : n.every((s) => t.some((a) => a && Object.prototype.hasOwnProperty.call(a, s)));
435
- }
436
- const cn = (t, n) => (n && Array.isArray(n.rules) ? n.rules : []).map(
437
- /** @param {any} [rule] @returns {any} */
438
- (s) => ({
439
- label: s && s.label ? s.label : "Rule",
440
- count: t.reduce(
441
- /** @param {any} [matches] @param {any} [row] @returns {any} */
442
- (a, l) => Pr(l, s.condition) ? a + 1 : a,
443
- 0
444
- )
445
- })
446
- ), un = e.lazy(() => import(
447
- /* webpackChunkName: "pivot-report-editor" */
448
- "./ReportEditor-B5j-CU9-.mjs"
449
- ).then((t) => ({
450
- default: t.ReportEditor
451
- }))), pn = (t) => /* @__PURE__ */ e.createElement(e.Suspense, { fallback: /* @__PURE__ */ e.createElement("div", { role: "status", style: { padding: "16px" } }, "Loading report builder…") }, /* @__PURE__ */ e.createElement(un, { ...t }));
452
- function Kt({
453
- availableFields: t,
454
- customDimensions: n,
455
- setCustomDimensions: s,
456
- data: a,
457
- theme: l,
458
- showNotification: g,
459
- getFieldLabel: u,
460
- onDeleteField: E
461
- }) {
462
- const d = e.useMemo(
463
- () => (t || []).filter(
464
- /** @param {any} [field] @returns {any} */
465
- (o) => o && !tr(o)
466
- ),
467
- [t]
468
- ), $ = e.useMemo(
469
- () => Fe(n || []),
470
- [n]
471
- ), [i, m] = e.useState(null), T = e.useMemo(
472
- () => an($, i),
473
- [i, $]
474
- ), L = e.useMemo(() => {
475
- const o = /* @__PURE__ */ new Set(), A = [];
476
- return d.forEach(
477
- /** @param {any} [field] @returns {any} */
478
- (R) => {
479
- R && !o.has(R) && (o.add(R), A.push(R));
480
- }
481
- ), T.forEach(
482
- /** @param {any} [dimension] @returns {any} */
483
- (R) => {
484
- R && R.field && !o.has(R.field) && (o.add(R.field), A.push(R.field));
485
- }
486
- ), A;
487
- }, [T, d]), _ = e.useMemo(
488
- () => {
489
- const o = qe(a, d, "date");
490
- return o.length > 0 ? o : d;
491
- },
492
- [d, a]
493
- ), D = e.useMemo(
494
- () => {
495
- const o = qe(a, d, "number");
496
- return o.length > 0 ? o : d;
497
- },
498
- [d, a]
499
- ), y = e.useMemo(
500
- () => on(a, T),
501
- [T, a]
502
- ), h = e.useMemo(() => ({
503
- border: `1px solid ${l.border}`,
504
- background: l.background,
505
- color: l.text,
506
- borderRadius: "8px",
507
- fontSize: "12px",
508
- padding: "7px 8px",
509
- outline: "none",
510
- minWidth: 0
511
- }), [l.background, l.border, l.text]), w = e.useCallback((o = "default") => ({
512
- border: o === "primary" ? `1px solid ${l.primary}` : `1px solid ${l.border}`,
513
- background: o === "primary" ? l.primary || "#2563EB" : l.hover || "#F8FAFC",
514
- color: o === "primary" ? "#fff" : l.text,
515
- borderRadius: "8px",
516
- fontSize: "11px",
517
- fontWeight: 700,
518
- padding: "6px 9px",
519
- cursor: "pointer",
520
- display: "inline-flex",
521
- alignItems: "center",
522
- gap: "5px"
523
- }), [l.border, l.hover, l.primary, l.text]);
524
- e.useEffect(() => {
525
- if (!i) return;
526
- const o = (A) => {
527
- A.key === "Escape" && (A.preventDefault(), m(null));
528
- };
529
- return window.addEventListener("keydown", o), () => window.removeEventListener("keydown", o);
530
- }, [i]);
531
- const W = e.useCallback((o, A) => {
532
- m(
533
- /** @param {any} [current] @returns {any} */
534
- (R) => {
535
- if (!R) return R;
536
- const B = [...R.rules || []];
537
- return B[o] = typeof A == "function" ? A(B[o]) : A, { ...R, rules: B };
538
- }
539
- );
540
- }, []), O = e.useCallback((o, A, R) => {
541
- W(
542
- o,
543
- /** @param {any} [rule] @returns {any} */
544
- (B) => {
545
- const M = B.condition || { op: "AND", clauses: [] }, H = [...M.clauses || []];
546
- return H[A] = { ...H[A], ...R }, { ...B, condition: { ...M, clauses: H } };
547
- }
548
- );
549
- }, [W]), k = e.useCallback(() => {
550
- const o = Fe([i])[0];
551
- if (!o || !o.name) {
552
- g && g("A grouped field needs a name.", "warning");
553
- return;
554
- }
555
- if (o.kind === "category" && (!o.rules || o.rules.length === 0)) {
556
- g && g("A category needs at least one valid rule.", "warning");
557
- return;
558
- }
559
- if ((o.kind === "date_group" || o.kind === "number_group") && !o.sourceField) {
560
- g && g("Choose the source field to group.", "warning");
561
- return;
562
- }
563
- const A = sr(i), R = Zt(o.name);
564
- if ($.some(
565
- /** @param {any} [dimension] @returns {any} */
566
- (M) => M && M.field !== A && Zt(M.name) === R
567
- )) {
568
- g && g(`A category named "${o.name}" already exists.`, "warning");
569
- return;
570
- }
571
- if (o.kind === "category") {
572
- const M = new Set(L);
573
- if (Yt(o).find(
574
- /** @param {any} [field] @returns {any} */
575
- (x) => !M.has(x)
576
- )) {
577
- g && g("A category can only use base fields or categories defined before it.", "warning");
578
- return;
579
- }
580
- const K = Yt(o);
581
- if (sn(y, K)) {
582
- const x = cn(y, o).find(
583
- /** @param {any} [summary] @returns {any} */
584
- (F) => F.count === 0
585
- );
586
- if (x) {
587
- g && g(`"${x.label}" does not match any current row. Adjust the condition before applying.`, "warning");
588
- return;
589
- }
590
- }
591
- }
592
- if (o.kind === "date_group" && !_.includes(o.sourceField)) {
593
- g && g("Choose a date field for date grouping.", "warning");
594
- return;
595
- }
596
- if (o.kind === "number_group") {
597
- if (!D.includes(o.sourceField)) {
598
- g && g("Choose a numeric field for number grouping.", "warning");
599
- return;
600
- }
601
- if (!Number.isFinite(Number(o.binSize)) || Number(o.binSize) <= 0) {
602
- g && g("Number bins need a positive bin size.", "warning");
603
- return;
604
- }
605
- }
606
- s(
607
- /** @param {any} [previous] @returns {any} */
608
- (M) => [...Fe(M || []).filter(
609
- /** @param {any} [dimension] @returns {any} */
610
- (x) => x.id !== o.id && x.field !== o.field && x.field !== A
611
- ), o]
612
- ), m(null), g && g(`Applied ${o.name}.`, "success");
613
- }, [L, _, i, $, D, s, g, y]), P = e.useCallback((o) => {
614
- const A = Fe([o])[0];
615
- A && (s(
616
- /** @param {any} [previous] @returns {any} */
617
- (R) => Fe(R || []).filter(
618
- /** @param {any} [item] @returns {any} */
619
- (B) => B.field !== A.field
620
- )
621
- ), typeof E == "function" && E(A.field), i && i.field === A.field && m(null), g && g(`Removed ${A.name}.`, "success"));
622
- }, [i, E, s, g]);
623
- return /* @__PURE__ */ e.createElement("div", { style: {
624
- border: `1px solid ${l.border}`,
625
- background: l.headerBg || l.surfaceInset || l.background,
626
- borderRadius: "12px",
627
- padding: "10px",
628
- marginBottom: "14px",
629
- display: "flex",
630
- flexDirection: "column",
631
- gap: "10px"
632
- } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px" } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", fontWeight: 800 } }, "Custom Categories"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, marginTop: "2px" } }, "Named filter rules that become fields.")), /* @__PURE__ */ e.createElement(
633
- "button",
634
- {
635
- type: "button",
636
- onClick: () => m(jt(L)),
637
- style: w("primary")
638
- },
639
- "+ Category"
640
- )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
641
- "button",
642
- {
643
- type: "button",
644
- onClick: () => m(nn(d, a)),
645
- disabled: _.length === 0,
646
- style: { ...w(), opacity: _.length === 0 ? 0.5 : 1, cursor: _.length === 0 ? "not-allowed" : "pointer" },
647
- title: _.length === 0 ? "No date fields detected" : "Create date buckets"
648
- },
649
- /* @__PURE__ */ e.createElement(z.Group, null),
650
- " Date Group"
651
- ), /* @__PURE__ */ e.createElement(
652
- "button",
653
- {
654
- type: "button",
655
- onClick: () => m(ln(d, a)),
656
- disabled: D.length === 0,
657
- style: { ...w(), opacity: D.length === 0 ? 0.5 : 1, cursor: D.length === 0 ? "not-allowed" : "pointer" },
658
- title: D.length === 0 ? "No numeric fields detected" : "Create numeric bins"
659
- },
660
- /* @__PURE__ */ e.createElement(z.NumberFormat, null),
661
- " Number Bins"
662
- )), $.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, $.map(
663
- /** @param {any} [dimension] @returns {any} */
664
- (o) => {
665
- const A = o.kind || "category", R = A === "date_group" ? `${u(o.sourceField)} by ${o.granularity}` : A === "number_group" ? `${u(o.sourceField)} every ${o.binSize}` : `${o.rules.length} rule${o.rules.length === 1 ? "" : "s"} | fallback: ${o.fallbackLabel}`;
666
- return /* @__PURE__ */ e.createElement(
667
- "div",
668
- {
669
- key: o.field,
670
- style: {
671
- border: `1px solid ${l.border}`,
672
- background: l.background,
673
- borderRadius: "10px",
674
- padding: "8px",
675
- display: "flex",
676
- alignItems: "center",
677
- gap: "8px"
678
- }
679
- },
680
- A === "number_group" ? /* @__PURE__ */ e.createElement(z.NumberFormat, null) : /* @__PURE__ */ e.createElement(z.Branch, null),
681
- /* @__PURE__ */ e.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "12px", fontWeight: 800, color: l.text, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, o.name), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec } }, R)),
682
- /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => m(jt(d, o)), style: w() }, /* @__PURE__ */ e.createElement(z.Edit, null), " Edit"),
683
- /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => P(o), style: { ...w(), color: "#B91C1C" } }, /* @__PURE__ */ e.createElement(z.Delete, null))
684
- );
685
- }
686
- )), i && /* @__PURE__ */ e.createElement(
687
- "div",
688
- {
689
- role: "presentation",
690
- onMouseDown: (o) => {
691
- o.target === o.currentTarget && m(null);
692
- },
693
- style: {
694
- position: "fixed",
695
- inset: 0,
696
- zIndex: 1e4,
697
- background: "rgba(15, 23, 42, 0.38)",
698
- backdropFilter: "blur(4px)",
699
- display: "flex",
700
- alignItems: "center",
701
- justifyContent: "center",
702
- padding: "24px"
703
- }
704
- },
705
- /* @__PURE__ */ e.createElement(
706
- "div",
707
- {
708
- role: "dialog",
709
- "aria-modal": "true",
710
- "aria-label": i.kind === "date_group" || i.kind === "number_group" ? i.__editingField ? "Edit grouped field" : "Add grouped field" : i.__editingField ? "Edit custom category" : "Add custom category",
711
- style: {
712
- width: "min(780px, calc(100vw - 32px))",
713
- maxHeight: "calc(100vh - 48px)",
714
- border: `1px solid ${l.primary || "#2563EB"}55`,
715
- background: l.background,
716
- color: l.text,
717
- borderRadius: "16px",
718
- boxShadow: "0 24px 80px rgba(15, 23, 42, 0.28)",
719
- overflow: "hidden"
720
- }
721
- },
722
- /* @__PURE__ */ e.createElement("div", { style: {
723
- padding: "14px 16px",
724
- borderBottom: `1px solid ${l.border}`,
725
- background: l.headerBg || l.surfaceInset || l.background,
726
- display: "flex",
727
- alignItems: "center",
728
- justifyContent: "space-between",
729
- gap: "12px"
730
- } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "13px", fontWeight: 900, color: l.text } }, i.kind === "date_group" || i.kind === "number_group" ? i.__editingField ? "Edit Grouped Field" : "Add Grouped Field" : i.__editingField ? "Edit Custom Category" : "Add Custom Category"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, marginTop: "2px" } }, i.kind === "date_group" ? "Create calendar buckets from a date field." : i.kind === "number_group" ? "Create fixed-width numeric bins from a number field." : "Rules can use base fields and categories defined before this one.")), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => m(null), style: { ...w(), padding: "6px 8px" }, "aria-label": "Close category editor" }, /* @__PURE__ */ e.createElement(z.Close, null))),
731
- /* @__PURE__ */ e.createElement("div", { style: {
732
- padding: "14px",
733
- overflowY: "auto",
734
- maxHeight: "calc(100vh - 128px)",
735
- display: "flex",
736
- flexDirection: "column",
737
- gap: "10px"
738
- } }, /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 120px 150px", gap: "8px" } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Category Name", /* @__PURE__ */ e.createElement(
739
- "input",
740
- {
741
- value: i.name || "",
742
- onChange: (o) => {
743
- const A = o.target.value, R = i.id || Qe(A);
744
- m({ ...i, name: A, id: R, field: i.field || et(R) });
745
- },
746
- style: h,
747
- placeholder: "Example: Priority Segment"
748
- }
749
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Else", /* @__PURE__ */ e.createElement(
750
- "input",
751
- {
752
- value: i.fallbackLabel || "",
753
- onChange: (o) => m({ ...i, fallbackLabel: o.target.value }),
754
- style: h,
755
- placeholder: "Other"
756
- }
757
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Member Order", /* @__PURE__ */ e.createElement(
758
- "select",
759
- {
760
- value: i.order || "creation",
761
- onChange: (o) => m({ ...i, order: o.target.value }),
762
- style: h
763
- },
764
- /* @__PURE__ */ e.createElement("option", { value: "creation" }, "Creation Order"),
765
- /* @__PURE__ */ e.createElement("option", { value: "alpha" }, "Alphabetical (A→Z)"),
766
- /* @__PURE__ */ e.createElement("option", { value: "alpha_desc" }, "Alphabetical (Z→A)"),
767
- /* @__PURE__ */ e.createElement("option", { value: "numeric" }, "Numeric (0→9)"),
768
- /* @__PURE__ */ e.createElement("option", { value: "numeric_desc" }, "Numeric (9→0)")
769
- ))), i.kind === "date_group" && /* @__PURE__ */ e.createElement("div", { style: {
770
- border: `1px solid ${l.border}`,
771
- borderRadius: "10px",
772
- padding: "10px",
773
- background: l.hover || "#F8FAFC",
774
- display: "grid",
775
- gridTemplateColumns: "1.4fr 1fr 1fr",
776
- gap: "8px"
777
- } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Date Field", /* @__PURE__ */ e.createElement(
778
- "select",
779
- {
780
- value: i.sourceField || "",
781
- onChange: (o) => m({
782
- ...i,
783
- sourceField: o.target.value,
784
- name: i.__isNew ? `${u(o.target.value)} ${fe(i.granularity || "month")}` : i.name
785
- }),
786
- style: h
787
- },
788
- _.map(
789
- /** @param {any} [field] @returns {any} */
790
- (o) => /* @__PURE__ */ e.createElement("option", { key: o, value: o }, u(o))
791
- )
792
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Date Part", /* @__PURE__ */ e.createElement(
793
- "select",
794
- {
795
- value: i.granularity || "month",
796
- onChange: (o) => m({ ...i, granularity: o.target.value }),
797
- style: h
798
- },
799
- Array.from(Yr).map((o) => /* @__PURE__ */ e.createElement("option", { key: o, value: o }, fe(o)))
800
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Fiscal Start", /* @__PURE__ */ e.createElement(
801
- "select",
802
- {
803
- value: i.fiscalYearStartMonth || 1,
804
- onChange: (o) => m({ ...i, fiscalYearStartMonth: Number(o.target.value) }),
805
- style: h
806
- },
807
- ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].map((o, A) => /* @__PURE__ */ e.createElement("option", { key: o, value: A + 1 }, o))
808
- ))), i.kind === "number_group" && /* @__PURE__ */ e.createElement("div", { style: {
809
- border: `1px solid ${l.border}`,
810
- borderRadius: "10px",
811
- padding: "10px",
812
- background: l.hover || "#F8FAFC",
813
- display: "grid",
814
- gridTemplateColumns: "1.4fr 0.8fr 0.8fr 0.8fr 0.7fr",
815
- gap: "8px"
816
- } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Number Field", /* @__PURE__ */ e.createElement(
817
- "select",
818
- {
819
- value: i.sourceField || "",
820
- onChange: (o) => m({
821
- ...i,
822
- sourceField: o.target.value,
823
- name: i.__isNew ? `${u(o.target.value)} Bins` : i.name
824
- }),
825
- style: h
826
- },
827
- D.map(
828
- /** @param {any} [field] @returns {any} */
829
- (o) => /* @__PURE__ */ e.createElement("option", { key: o, value: o }, u(o))
830
- )
831
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Bin Size", /* @__PURE__ */ e.createElement(
832
- "input",
833
- {
834
- type: "number",
835
- value: i.binSize === void 0 ? "" : i.binSize,
836
- onChange: (o) => m({ ...i, binSize: o.target.value }),
837
- style: h
838
- }
839
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Min", /* @__PURE__ */ e.createElement(
840
- "input",
841
- {
842
- type: "number",
843
- value: i.minValue === null || i.minValue === void 0 ? "" : i.minValue,
844
- onChange: (o) => m({ ...i, minValue: o.target.value }),
845
- style: h
846
- }
847
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Max", /* @__PURE__ */ e.createElement(
848
- "input",
849
- {
850
- type: "number",
851
- value: i.maxValue === null || i.maxValue === void 0 ? "" : i.maxValue,
852
- onChange: (o) => m({ ...i, maxValue: o.target.value }),
853
- style: h
854
- }
855
- )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Decimals", /* @__PURE__ */ e.createElement(
856
- "input",
857
- {
858
- type: "number",
859
- min: "0",
860
- max: "8",
861
- value: i.precision === null || i.precision === void 0 ? "" : i.precision,
862
- onChange: (o) => m({ ...i, precision: o.target.value }),
863
- style: h
864
- }
865
- ))), (!i.kind || i.kind === "category") && (i.rules || []).map(
866
- /** @param {any} [rule] @param {any} [ruleIndex] @returns {any} */
867
- (o, A) => {
868
- const R = o.condition || { op: "AND", clauses: [] }, B = R.clauses || [];
869
- return /* @__PURE__ */ e.createElement("div", { key: o.id || A, style: {
870
- border: `1px solid ${l.border}`,
871
- borderRadius: "10px",
872
- padding: "8px",
873
- background: l.hover || "#F8FAFC",
874
- display: "flex",
875
- flexDirection: "column",
876
- gap: "8px"
877
- } }, /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 78px 28px", gap: "8px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
878
- "input",
879
- {
880
- value: o.label || "",
881
- onChange: (M) => W(A, { ...o, label: M.target.value }),
882
- style: h,
883
- placeholder: "Category value"
884
- }
885
- ), /* @__PURE__ */ e.createElement(
886
- "select",
887
- {
888
- value: R.op || "AND",
889
- onChange: (M) => W(A, { ...o, condition: { ...R, op: M.target.value } }),
890
- style: h
891
- },
892
- /* @__PURE__ */ e.createElement("option", { value: "AND" }, "AND"),
893
- /* @__PURE__ */ e.createElement("option", { value: "OR" }, "OR")
894
- ), /* @__PURE__ */ e.createElement(
895
- "button",
896
- {
897
- type: "button",
898
- onClick: () => m({ ...i, rules: (i.rules || []).filter(
899
- /** @param {any} [_] @param {any} [index] @returns {any} */
900
- (M, H) => H !== A
901
- ) }),
902
- style: { ...w(), padding: "6px", justifyContent: "center", color: "#B91C1C" },
903
- title: "Remove rule"
904
- },
905
- /* @__PURE__ */ e.createElement(z.Close, null)
906
- )), B.map(
907
- /** @param {any} [clause] @param {any} [clauseIndex] @returns {any} */
908
- (M, H) => {
909
- const K = tn.has(M.operator), x = Ut.has(M.operator);
910
- return /* @__PURE__ */ e.createElement("div", { key: `${o.id || A}:${H}`, style: { display: "grid", gridTemplateColumns: K ? "1fr 130px 28px" : "1fr 130px 1fr 28px", gap: "6px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
911
- "select",
912
- {
913
- value: M.field || "",
914
- onChange: (F) => O(A, H, { field: F.target.value }),
915
- style: h
916
- },
917
- L.map(
918
- /** @param {any} [field] @returns {any} */
919
- (F) => /* @__PURE__ */ e.createElement("option", { key: F, value: F }, u(F))
920
- )
921
- ), /* @__PURE__ */ e.createElement(
922
- "select",
923
- {
924
- value: M.operator || "eq",
925
- onChange: (F) => {
926
- const v = F.target.value;
927
- O(A, H, {
928
- operator: v,
929
- values: Ut.has(v) ? M.values && M.values.length ? M.values : Vt(M.value) : M.values
930
- });
931
- },
932
- style: h
933
- },
934
- en.map((F) => /* @__PURE__ */ e.createElement("option", { key: F.value, value: F.value }, F.label))
935
- ), !K && /* @__PURE__ */ e.createElement(
936
- "input",
937
- {
938
- value: x ? (M.values || []).join(", ") : M.value || "",
939
- onChange: (F) => O(A, H, x ? { values: Vt(F.target.value), value: F.target.value } : { value: F.target.value }),
940
- style: h,
941
- placeholder: x ? "A, B, C" : "Value"
942
- }
943
- ), /* @__PURE__ */ e.createElement(
944
- "button",
945
- {
946
- type: "button",
947
- onClick: () => W(A, {
948
- ...o,
949
- condition: {
950
- ...R,
951
- clauses: B.filter(
952
- /** @param {any} [_] @param {any} [index] @returns {any} */
953
- (F, v) => v !== H
954
- )
955
- }
956
- }),
957
- style: { ...w(), padding: "6px", justifyContent: "center", color: "#B91C1C" },
958
- title: "Remove condition"
959
- },
960
- /* @__PURE__ */ e.createElement(z.Close, null)
961
- ));
962
- }
963
- ), /* @__PURE__ */ e.createElement(
964
- "button",
965
- {
966
- type: "button",
967
- onClick: () => W(A, {
968
- ...o,
969
- condition: {
970
- ...R,
971
- clauses: [...B, or(L)]
972
- }
973
- }),
974
- style: { ...w(), alignSelf: "flex-start" }
975
- },
976
- "+ Condition"
977
- ));
978
- }
979
- ), (!i.kind || i.kind === "category") && /* @__PURE__ */ e.createElement(
980
- "button",
981
- {
982
- type: "button",
983
- onClick: () => m({
984
- ...i,
985
- rules: [...i.rules || [], ir(L, (i.rules || []).length)]
986
- }),
987
- style: { ...w(), alignSelf: "flex-start" }
988
- },
989
- "+ Rule"
990
- ), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px" } }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => m(null), style: w() }, "Cancel"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: k, style: w("primary") }, i.kind === "date_group" || i.kind === "number_group" ? "Apply Group" : "Apply Category")))
991
- )
992
- ));
993
- }
994
- function cr(t) {
995
- const n = [], s = /* @__PURE__ */ new Set();
996
- return String(t || "").replace(tt, (a, l) => {
997
- const g = String(l || "").trim();
998
- return g && !s.has(g) && (n.push(g), s.add(g)), "";
999
- }), n;
1000
- }
1001
- function Gt(t, n = []) {
1002
- const s = String(t || ""), a = [], l = /* @__PURE__ */ new Set(), g = (d) => {
1003
- const $ = String(d || "").trim();
1004
- !$ || l.has($) || (a.push($), l.add($));
1005
- };
1006
- cr(s).forEach(g);
1007
- let u = s.replace(tt, " ");
1008
- return (Array.isArray(n) ? n : Array.from(n || [])).map((d) => String(d || "").trim()).filter((d) => d && !lr.test(d)).sort((d, $) => $.length - d.length).forEach(
1009
- /** @param {any} [reference] @returns {any} */
1010
- (d) => {
1011
- const $ = new RegExp(`(^|[^A-Za-z0-9_])${ar(d)}(?=$|[^A-Za-z0-9_])`, "g");
1012
- u = u.replace(
1013
- $,
1014
- /** @param {any} [match] @param {any} [prefix] @returns {any} */
1015
- (i, m) => (g(d), `${m} `)
1016
- );
1017
- }
1018
- ), u.replace(
1019
- nr,
1020
- /** @param {any} [token] @param {any} [offset] @returns {any} */
1021
- (d, $) => {
1022
- const i = u.slice($ + d.length).trimStart();
1023
- return Qr.has(d) || qr.has(d) && i.startsWith("(") || g(d), d;
1024
- }
1025
- ), a;
1026
- }
1027
- function le(t) {
1028
- const n = String(t || "").trim();
1029
- return n ? `[${n}]` : "";
1030
- }
1031
- function ye(t) {
1032
- const n = String(t || "").trim();
1033
- return n ? lr.test(n) ? n : `[${n}]` : "";
1034
- }
1035
- function dn(t, n, s = "formula") {
1036
- const a = ve(t, s), l = new Set(
1037
- (Array.isArray(n) ? n : []).map((E) => E ? E.agg === "formula" ? N(E) : E.field : null).filter(Boolean).map((E) => String(E).toLowerCase())
1038
- );
1039
- if (!l.has(a)) return a;
1040
- let g = 2, u = `${a}${g}`;
1041
- for (; l.has(u); )
1042
- g += 1, u = `${a}${g}`;
1043
- return u;
1044
- }
1045
- function fn(t, n, s) {
1046
- if (!t || !n || n === s) return t;
1047
- const a = ye(s), l = [];
1048
- let u = String(t).replace(tt, (E, d) => String(d || "").trim() === n ? a : (l.push(E), `@@${l.length - 1}@@`)).replace(new RegExp(`\\b${ar(n)}\\b`, "g"), a);
1049
- return l.forEach((E, d) => {
1050
- u = u.replace(`@@${d}@@`, E);
1051
- }), u;
1052
- }
1053
- function yt(t, n, s) {
1054
- t(
1055
- /** @param {any} [prev] @returns {any} */
1056
- (a) => {
1057
- const l = [...a];
1058
- return l[n] ? (l[n] = s(l[n]), l) : a;
1059
- }
1060
- );
1061
- }
1062
- function Nt(t) {
1063
- return !t || typeof t.closest != "function" ? !1 : !!t.closest('button, input, select, textarea, [contenteditable="true"]');
1064
- }
1065
- function gn(t) {
1066
- if (!t || typeof t != "object") return "";
1067
- const n = t.field === void 0 || t.field === null ? "" : String(t.field), s = t.agg === void 0 || t.agg === null ? "" : String(t.agg);
1068
- return `${n}::${s}`;
1069
- }
1070
- function bt(t) {
1071
- const n = Xr(t);
1072
- return n ? {
1073
- ...Ee,
1074
- ...n,
1075
- header: n.header || "",
1076
- color: n.color || "",
1077
- positiveColor: n.positiveColor || "",
1078
- negativeColor: n.negativeColor || ""
1079
- } : null;
1080
- }
1081
- function mn(t) {
1082
- const n = {
1083
- ...Ee,
1084
- ...t || {}
1085
- }, s = {
1086
- type: n.type || Ee.type,
1087
- metric: n.metric || Ee.metric,
1088
- showCurrentValue: n.showCurrentValue !== !1,
1089
- showDelta: n.showDelta !== !1,
1090
- compact: !!n.compact,
1091
- hideColumns: !!n.hideColumns,
1092
- placement: "before",
1093
- source: n.source === "field" ? "field" : "pivot",
1094
- displayMode: n.displayMode === "value" ? "value" : "trend"
1095
- };
1096
- return ["header", "color", "positiveColor", "negativeColor"].forEach((a) => {
1097
- const l = typeof n[a] == "string" ? n[a].trim() : "";
1098
- l && (s[a] = l);
1099
- }), Number.isFinite(Number(n.areaOpacity)) && (s.areaOpacity = Math.max(0.02, Math.min(0.45, Number(n.areaOpacity)))), s;
1100
- }
1101
- function ur(t, n = []) {
1102
- const s = String(t && t.agg || "").trim().toLowerCase(), a = Array.isArray(n) && n.length > 0, l = s === "array_agg", g = s !== "array_agg" && a;
1103
- return {
1104
- canUseFieldSeries: l,
1105
- canUsePivotSeries: g,
1106
- canUseAny: l || g,
1107
- defaultSource: l ? "field" : g ? "pivot" : null
1108
- };
1109
- }
1110
- function vt(t, n) {
1111
- return !n || !n.canUseAny ? !1 : t === "field" ? n.canUseFieldSeries : n.canUsePivotSeries;
1112
- }
1113
- function pr(t, n) {
1114
- const s = mn(t);
1115
- return !n || !n.canUseAny ? null : vt(s.source, n) ? s : {
1116
- ...s,
1117
- source: n.defaultSource
1118
- };
1119
- }
1120
- function Et(t) {
1121
- if (!Array.isArray(t) || t.length === 0) return "";
1122
- const n = t.map((s) => s && ye(s.field)).filter(Boolean);
1123
- return n.length === 0 ? "" : n.length === 1 ? `${n[0]} * 100` : `${n[0]} - ${n[1]}`;
1124
- }
1125
- function Xt(t) {
1126
- const n = (Array.isArray(t) ? t : []).map((s) => s && s.id).filter(Boolean);
1127
- return n.length === 0 ? "" : n.length === 1 ? `${le(n[0])} * 100` : `${le(n[0])} - ${le(n[1])}`;
1128
- }
1129
- function xn(t) {
1130
- const n = new Set(
1131
- (Array.isArray(t) ? t : []).map((a) => a && a.field).filter(Boolean)
1132
- );
1133
- let s = 1;
1134
- for (; n.has(`formula_${s}`); ) s += 1;
1135
- return `formula_${s}`;
1136
- }
1137
- function yn(t, n, s = null, a = null, l = "measures", g = [], u = []) {
1138
- const E = String(t || "").trim(), d = xe(l);
1139
- if (!E)
1140
- return {
1141
- tone: "warning",
1142
- text: d ? "Enter a formula using bracketed rendered columns. Example: [Cash Equity_day_pnl_sum] - [ETF_day_pnl_sum]" : "Enter a formula using value fields. Example: sales - [day pnl]"
1143
- };
1144
- let $ = 0;
1145
- for (const k of E)
1146
- if (k === "(" && ($ += 1), k === ")" && ($ -= 1), $ < 0)
1147
- return { tone: "warning", text: "Parentheses are unbalanced." };
1148
- if ($ !== 0)
1149
- return { tone: "warning", text: "Parentheses are unbalanced." };
1150
- if (d) {
1151
- const k = Array.isArray(g) ? g : [], P = new Set(
1152
- k.map(
1153
- /** @param {any} [option] @returns {any} */
1154
- (B) => B && B.id
1155
- ).filter(Boolean)
1156
- ), o = cr(E);
1157
- if (o.length === 0)
1158
- return {
1159
- tone: "warning",
1160
- text: "Insert at least one rendered column reference like [column_id]."
1161
- };
1162
- const A = E.replace(tt, ""), R = Array.from(new Set(A.match(nr) || []));
1163
- if (R.length > 0)
1164
- return {
1165
- tone: "warning",
1166
- text: `Rendered columns must use brackets: ${R.join(", ")}`
1167
- };
1168
- if (P.size > 0) {
1169
- const B = o.filter(
1170
- /** @param {any} [columnId] @returns {any} */
1171
- (M) => !P.has(M)
1172
- );
1173
- if (B.length > 0)
1174
- return {
1175
- tone: "warning",
1176
- text: `Unknown rendered columns: ${B.join(", ")}`
1177
- };
1178
- }
1179
- return s && o.includes(s) ? {
1180
- tone: "warning",
1181
- text: "A displayed-column formula cannot reference its own output column."
1182
- } : {
1183
- tone: "success",
1184
- text: `Using rendered columns: ${o.join(", ")}`
1185
- };
1186
- }
1187
- const i = Array.isArray(n) ? n.filter((k) => k && k.field) : [];
1188
- if (i.length === 0)
1189
- return {
1190
- tone: "warning",
1191
- text: "Add at least one value or formula reference before creating formulas."
1192
- };
1193
- const m = i.filter(
1194
- /** @param {any} [config] @returns {any} */
1195
- (k) => k.agg === "formula"
1196
- ), T = /* @__PURE__ */ new Map();
1197
- m.forEach(
1198
- /** @param {any} [config] @returns {any} */
1199
- (k) => {
1200
- const P = k.field === s ? ve(a || N(k), k.field) : N(k);
1201
- P && (T.set(P, P), T.set(P.toLowerCase(), P));
1202
- }
1203
- );
1204
- const L = i.filter(
1205
- /** @param {any} [config] @returns {any} */
1206
- (k) => k.agg !== "formula"
1207
- ).map(
1208
- /** @param {any} [config] @returns {any} */
1209
- (k) => k.field
1210
- ).filter(Boolean), _ = new Set(L), D = /* @__PURE__ */ new Set([...L, ...m.map(
1211
- /** @param {any} [config] @returns {any} */
1212
- (k) => k.field === s ? ve(a || N(k), k.field) : N(k)
1213
- ).filter(Boolean), ...Array.isArray(u) ? u : []]), y = Array.from(D), h = Gt(E, y), w = h.map(
1214
- /** @param {any} [token] @returns {any} */
1215
- (k) => T.get(k) || T.get(k.toLowerCase()) || k
1216
- ), W = w.filter(
1217
- /** @param {any} [token] @returns {any} */
1218
- (k) => !D.has(k) && !_.has(k)
1219
- );
1220
- if (W.length > 0)
1221
- return {
1222
- tone: "warning",
1223
- text: `Unknown fields: ${W.join(", ")}`
1224
- };
1225
- const O = s ? ve(a || s, s) : null;
1226
- if (s && O && i.some(
1227
- /** @param {any} [config] @returns {any} */
1228
- (P) => {
1229
- if (!P || P.field === s) return !1;
1230
- const o = P.agg === "formula" ? N(P) : P.field;
1231
- return String(o || "").toLowerCase() === O.toLowerCase();
1232
- }
1233
- ))
1234
- return {
1235
- tone: "warning",
1236
- text: `Reference key "${O}" is already in use.`
1237
- };
1238
- if (O && w.includes(O))
1239
- return {
1240
- tone: "warning",
1241
- text: "A formula cannot reference itself."
1242
- };
1243
- if (s && O) {
1244
- const k = {};
1245
- m.forEach(
1246
- /** @param {any} [config] @returns {any} */
1247
- (R) => {
1248
- const B = R.field === s ? O : N(R), M = R.field === s ? E : String(R.formula || ""), H = Gt(M, y).map(
1249
- /** @param {any} [token] @returns {any} */
1250
- (K) => T.get(K) || T.get(K.toLowerCase()) || K
1251
- ).filter(
1252
- /** @param {any} [token] @returns {any} */
1253
- (K) => K !== B && m.some(
1254
- /** @param {any} [candidate] @returns {any} */
1255
- (x) => N(x) === K || x.field === s && O === K
1256
- )
1257
- );
1258
- k[B] = H;
1259
- }
1260
- );
1261
- const P = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), A = (R) => {
1262
- if (P.has(R)) return !0;
1263
- if (o.has(R)) return !1;
1264
- P.add(R);
1265
- const B = k[R] || [];
1266
- for (const M of B)
1267
- if (A(M)) return !0;
1268
- return P.delete(R), o.add(R), !1;
1269
- };
1270
- if (A(O))
1271
- return {
1272
- tone: "warning",
1273
- text: "Circular formula reference detected."
1274
- };
1275
- }
1276
- return h.length === 0 ? {
1277
- tone: "warning",
1278
- text: "Insert at least one measure or formula reference."
1279
- } : {
1280
- tone: "success",
1281
- text: `Using ${w.join(", ")}`
1282
- };
1283
- }
1284
- function bn(t) {
1285
- if (!Array.isArray(t) || t.length === 0) return [];
1286
- const n = t.map((s) => s && ye(s.field)).filter(Boolean);
1287
- return n.length === 0 ? [] : n.length === 1 ? [{ label: "Scale x100", value: `${n[0]} * 100` }] : [
1288
- { label: "Difference", value: `${n[0]} - ${n[1]}` },
1289
- { label: "Ratio %", value: `(${n[0]} / ${n[1]}) * 100` },
1290
- { label: "Margin %", value: `((${n[0]} - ${n[1]}) / ${n[0]}) * 100` }
1291
- ];
1292
- }
1293
- function En(t) {
1294
- const n = (Array.isArray(t) ? t : []).map((s) => s && s.id).filter(Boolean);
1295
- return n.length === 0 ? [] : n.length === 1 ? [{ label: "Scale x100", value: `${le(n[0])} * 100` }] : [
1296
- { label: "Difference", value: `${le(n[0])} - ${le(n[1])}` },
1297
- { label: "Ratio %", value: `(${le(n[0])} / ${le(n[1])}) * 100` },
1298
- { label: "Spread %", value: `((${le(n[0])} - ${le(n[1])}) / ${le(n[0])}) * 100` }
1299
- ];
1300
- }
1301
- function vn(t, n) {
1302
- const s = {
1303
- muted: {
1304
- text: t.textSec,
1305
- border: t.border,
1306
- background: t.headerSubtleBg || t.background
1307
- },
1308
- success: {
1309
- text: t.primary,
1310
- border: `${t.primary}33`,
1311
- background: `${t.primary}10`
1312
- },
1313
- warning: {
1314
- text: "#B45309",
1315
- border: "#F59E0B55",
1316
- background: "#F59E0B12"
1317
- }
1318
- };
1319
- return s[n] || s.muted;
1320
- }
1321
- function Sn({ item: t, idx: n, setValConfigs: s, theme: a, colFields: l = [], onClose: g }) {
1322
- const u = e.useMemo(
1323
- () => bt(t && t.sparkline) || { ...Ee },
1324
- // eslint-disable-next-line react-hooks/exhaustive-deps
1325
- [t && t.sparkline]
1326
- ), E = e.useMemo(
1327
- () => ur(t, l),
1328
- [l, t]
1329
- ), d = e.useMemo(() => {
1330
- const y = [];
1331
- return E.canUsePivotSeries && y.push({ value: "pivot", label: "Linked pivot" }), E.canUseFieldSeries && y.push({ value: "field", label: "Series field" }), y;
1332
- }, [E]), $ = vt(u.source || "pivot", E) ? u.source || "pivot" : E.defaultSource, i = e.useCallback((y) => {
1333
- yt(
1334
- s,
1335
- n,
1336
- /** @param {any} [current] @returns {any} */
1337
- (h) => {
1338
- const w = bt(h.sparkline) || { ...Ee }, W = pr({ ...w, ...y }, E);
1339
- return W ? {
1340
- ...h,
1341
- sparkline: W
1342
- } : h;
1343
- }
1344
- );
1345
- }, [E, n, s]), m = e.useCallback((y) => y.stopPropagation(), []), T = [
1346
- { value: "line", label: "Line" },
1347
- { value: "area", label: "Area" },
1348
- { value: "column", label: "Column" },
1349
- { value: "bar", label: "Bar" }
1350
- ], L = {
1351
- background: a.background,
1352
- border: `1px solid ${a.border}`,
1353
- borderRadius: "5px",
1354
- color: a.text,
1355
- fontSize: "11px",
1356
- padding: "4px 7px",
1357
- outline: "none",
1358
- width: "100%",
1359
- boxSizing: "border-box"
1360
- }, _ = {
1361
- fontSize: "10px",
1362
- fontWeight: 700,
1363
- letterSpacing: "0.06em",
1364
- color: a.textSec,
1365
- textTransform: "uppercase",
1366
- marginBottom: "6px",
1367
- display: "block"
1368
- }, D = {
1369
- marginBottom: "14px"
1370
- };
1371
- return /* @__PURE__ */ e.createElement(
1372
- "div",
1373
- {
1374
- style: { position: "fixed", inset: 0, background: "rgba(0,0,0,0.45)", zIndex: 9999, display: "flex", alignItems: "center", justifyContent: "center" },
1375
- onMouseDown: m,
1376
- onClick: g
1377
- },
1378
- /* @__PURE__ */ e.createElement(
1379
- "div",
1380
- {
1381
- onClick: m,
1382
- style: {
1383
- background: a.background,
1384
- border: `1px solid ${a.border}`,
1385
- borderRadius: "12px",
1386
- boxShadow: "0 8px 32px rgba(0,0,0,0.22)",
1387
- width: "320px",
1388
- maxHeight: "80vh",
1389
- overflow: "auto",
1390
- padding: "18px 20px 16px",
1391
- fontFamily: "'Inter', ui-sans-serif, system-ui, sans-serif"
1392
- }
1393
- },
1394
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "16px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "13px", fontWeight: 700, color: a.text } }, "Sparkline Column"), /* @__PURE__ */ e.createElement(
1395
- "button",
1396
- {
1397
- type: "button",
1398
- onClick: g,
1399
- style: { background: "none", border: "none", cursor: "pointer", color: a.textSec, fontSize: "18px", lineHeight: 1, padding: "2px 4px" }
1400
- },
1401
- "×"
1402
- )),
1403
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Data source"), d.length > 0 ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, d.map(
1404
- /** @param {any} p0 @returns {any} */
1405
- ({ value: y, label: h }) => /* @__PURE__ */ e.createElement(
1406
- "button",
1407
- {
1408
- key: y,
1409
- type: "button",
1410
- onClick: () => i({ source: y }),
1411
- style: {
1412
- flex: 1,
1413
- padding: "4px 0",
1414
- fontSize: "11px",
1415
- fontWeight: 600,
1416
- borderRadius: "6px",
1417
- cursor: "pointer",
1418
- border: `1px solid ${$ === y ? a.primary : a.border}`,
1419
- background: $ === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1420
- color: $ === y ? a.primary : a.textSec
1421
- }
1422
- },
1423
- h
1424
- )
1425
- )), /* @__PURE__ */ e.createElement("div", { style: { marginTop: "5px", fontSize: "10px", color: a.textSec, lineHeight: 1.4 } }, $ === "pivot" ? "Trend values are collected across the pivot columns. Source value cells stay numeric unless hidden." : "Each cell already contains the full data series for its row.")) : /* @__PURE__ */ e.createElement(
1426
- "div",
1427
- {
1428
- "data-value-sparkline-unavailable": "true",
1429
- style: {
1430
- padding: "7px 8px",
1431
- borderRadius: "6px",
1432
- border: `1px solid ${a.warning || "#F59E0B"}55`,
1433
- background: `${a.warning || "#F59E0B"}12`,
1434
- color: a.text,
1435
- fontSize: "10px",
1436
- lineHeight: 1.45
1437
- }
1438
- },
1439
- "Add a column field for linked trends, or use the Series aggregation for field data."
1440
- )),
1441
- $ === "field" && /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Cell display"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, [
1442
- { value: "trend", label: "Trendline" },
1443
- { value: "value", label: "Value" }
1444
- ].map(({ value: y, label: h }) => /* @__PURE__ */ e.createElement(
1445
- "button",
1446
- {
1447
- key: y,
1448
- type: "button",
1449
- onClick: () => i({ displayMode: y }),
1450
- style: {
1451
- flex: 1,
1452
- padding: "4px 0",
1453
- fontSize: "11px",
1454
- fontWeight: 600,
1455
- borderRadius: "6px",
1456
- cursor: "pointer",
1457
- border: `1px solid ${(u.displayMode || "trend") === y ? a.primary : a.border}`,
1458
- background: (u.displayMode || "trend") === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1459
- color: (u.displayMode || "trend") === y ? a.primary : a.textSec
1460
- }
1461
- },
1462
- h
1463
- ))), /* @__PURE__ */ e.createElement("div", { style: { marginTop: "5px", fontSize: "10px", color: a.textSec, lineHeight: 1.4 } }, (u.displayMode || "trend") === "value" ? "Show the selected summary metric from the series." : "Draw the series in the cell.")),
1464
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Chart type"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, T.map(({ value: y, label: h }) => /* @__PURE__ */ e.createElement(
1465
- "button",
1466
- {
1467
- key: y,
1468
- type: "button",
1469
- onClick: () => i({ type: y }),
1470
- style: {
1471
- flex: 1,
1472
- padding: "4px 0",
1473
- fontSize: "11px",
1474
- fontWeight: 600,
1475
- borderRadius: "6px",
1476
- cursor: "pointer",
1477
- border: `1px solid ${u.type === y ? a.primary : a.border}`,
1478
- background: u.type === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1479
- color: u.type === y ? a.primary : a.textSec
1480
- }
1481
- },
1482
- h
1483
- )))),
1484
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Summary metric"), /* @__PURE__ */ e.createElement(
1485
- "select",
1486
- {
1487
- value: u.metric,
1488
- onChange: (y) => i({ metric: y.target.value }),
1489
- style: { ...L, cursor: "pointer" }
1490
- },
1491
- /* @__PURE__ */ e.createElement("option", { value: "last" }, "Last value"),
1492
- /* @__PURE__ */ e.createElement("option", { value: "first" }, "First value"),
1493
- /* @__PURE__ */ e.createElement("option", { value: "min" }, "Minimum"),
1494
- /* @__PURE__ */ e.createElement("option", { value: "max" }, "Maximum"),
1495
- /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Average"),
1496
- /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"),
1497
- /* @__PURE__ */ e.createElement("option", { value: "delta" }, "Delta (last − first)")
1498
- )),
1499
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Display"), /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: "6px" } }, [
1500
- { key: "showCurrentValue", label: "Value label" },
1501
- { key: "showDelta", label: "Delta label" },
1502
- { key: "compact", label: "Compact cell" },
1503
- { key: "hideColumns", label: "Hide source values" }
1504
- ].map(({ key: y, label: h }) => /* @__PURE__ */ e.createElement("label", { key: y, style: { display: "flex", alignItems: "center", gap: "5px", fontSize: "11px", color: a.text, cursor: "pointer", userSelect: "none" } }, /* @__PURE__ */ e.createElement(
1505
- "input",
1506
- {
1507
- type: "checkbox",
1508
- checked: !!u[y],
1509
- onChange: (w) => i({ [y]: w.target.checked }),
1510
- style: { accentColor: a.primary, width: "13px", height: "13px", cursor: "pointer" }
1511
- }
1512
- ), h))), u.hideColumns && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "6px", fontSize: "10px", color: a.textSec, background: `${a.primary}10`, border: `1px solid ${a.primary}30`, borderRadius: "6px", padding: "5px 8px", lineHeight: 1.4 } }, "Source value columns are hidden; the trend column remains."), !u.hideColumns && $ === "pivot" && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "6px", fontSize: "10px", color: a.textSec, background: a.headerSubtleBg || a.background, border: `1px solid ${a.border}`, borderRadius: "6px", padding: "5px 8px", lineHeight: 1.4 } }, "Source value columns stay numeric; the trend column is added beside them.")),
1513
- $ === "pivot" && /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Position"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: a.textSec, lineHeight: 1.4, background: a.headerSubtleBg || a.background, border: `1px solid ${a.border}`, borderRadius: "6px", padding: "6px 8px" } }, "Trend columns are placed before the matching value columns.")),
1514
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Colors"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, [
1515
- { key: "color", label: "Line / fill color", always: !0 },
1516
- { key: "positiveColor", label: "Positive bar color", always: !1 },
1517
- { key: "negativeColor", label: "Negative bar color", always: !1 }
1518
- ].filter(({ always: y }) => y || u.type === "column" || u.type === "bar").map(({ key: y, label: h }) => /* @__PURE__ */ e.createElement("div", { key: y }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: a.textSec, marginBottom: "3px", display: "block" } }, h), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "5px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
1519
- "input",
1520
- {
1521
- type: "color",
1522
- value: u[y] || (y === "negativeColor" ? "#B91C1C" : y === "positiveColor" ? "#2F855A" : "#2563EB"),
1523
- onChange: (w) => i({ [y]: w.target.value }),
1524
- style: { width: "28px", height: "26px", padding: "1px 2px", border: `1px solid ${a.border}`, borderRadius: "4px", cursor: "pointer", background: "none" }
1525
- }
1526
- ), /* @__PURE__ */ e.createElement(
1527
- "input",
1528
- {
1529
- type: "text",
1530
- value: u[y] || "",
1531
- onChange: (w) => i({ [y]: w.target.value }),
1532
- placeholder: "Auto",
1533
- style: { ...L, flex: 1 }
1534
- }
1535
- ), u[y] && /* @__PURE__ */ e.createElement(
1536
- "button",
1537
- {
1538
- type: "button",
1539
- onClick: () => i({ [y]: "" }),
1540
- style: { background: "none", border: "none", cursor: "pointer", color: a.textSec, fontSize: "14px", lineHeight: 1, padding: "2px" },
1541
- title: "Reset to auto"
1542
- },
1543
- "×"
1544
- )))))),
1545
- u.type === "area" && /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Area fill opacity"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px" } }, /* @__PURE__ */ e.createElement(
1546
- "input",
1547
- {
1548
- type: "range",
1549
- min: "0.02",
1550
- max: "0.45",
1551
- step: "0.01",
1552
- value: u.areaOpacity != null ? u.areaOpacity : 0.14,
1553
- onChange: (y) => i({ areaOpacity: Number(y.target.value) }),
1554
- style: { flex: 1, accentColor: a.primary }
1555
- }
1556
- ), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "11px", color: a.textSec, minWidth: "32px", textAlign: "right" } }, Math.round((u.areaOpacity != null ? u.areaOpacity : 0.14) * 100), "%"))),
1557
- /* @__PURE__ */ e.createElement("div", { style: D }, /* @__PURE__ */ e.createElement("span", { style: _ }, "Column header label"), /* @__PURE__ */ e.createElement(
1558
- "input",
1559
- {
1560
- type: "text",
1561
- value: u.header || "",
1562
- onChange: (y) => i({ header: y.target.value }),
1563
- placeholder: "Auto (e.g. Sales Trend)",
1564
- style: L
1565
- }
1566
- )),
1567
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "flex-end" } }, /* @__PURE__ */ e.createElement(
1568
- "button",
1569
- {
1570
- type: "button",
1571
- onClick: g,
1572
- style: {
1573
- background: a.primary,
1574
- color: "#fff",
1575
- border: "none",
1576
- borderRadius: "7px",
1577
- padding: "6px 18px",
1578
- fontSize: "12px",
1579
- fontWeight: 700,
1580
- cursor: "pointer"
1581
- }
1582
- },
1583
- "Done"
1584
- ))
1585
- )
1586
- );
1587
- }
1588
- function dr({ item: t, idx: n, setValConfigs: s, theme: a, colFields: l = [], fixedSparklineValueKeySet: g = /* @__PURE__ */ new Set(), showNotification: u }) {
1589
- const [E, d] = e.useState(!1), $ = bt(t && t.sparkline), i = gn(t), m = !!(i && g && g.has(i)), T = e.useMemo(
1590
- () => ur(t, l),
1591
- [l, t]
1592
- ), L = !!$, _ = !!($ && vt($.source || "pivot", T)), D = e.useCallback((W) => W.stopPropagation(), []), y = e.useCallback(() => {
1593
- let W = !1;
1594
- return yt(
1595
- s,
1596
- n,
1597
- /** @param {any} [current] @returns {any} */
1598
- (O) => {
1599
- const k = pr(
1600
- O.sparkline || Ee,
1601
- T
1602
- );
1603
- return k ? (W = !0, { ...O, sparkline: k }) : O;
1604
- }
1605
- ), W;
1606
- }, [T, n, s]), h = e.useCallback((W) => {
1607
- if (W.stopPropagation(), L) {
1608
- if (m) {
1609
- u && u("This trend is defined by the app. You can adjust its settings, but not remove it here.", "info");
1610
- return;
1611
- }
1612
- yt(
1613
- s,
1614
- n,
1615
- /** @param {any} [current] @returns {any} */
1616
- (O) => ({ ...O, sparkline: !1 })
1617
- ), u && u("Removed trend column.", "info");
1618
- } else T.canUseAny && y() ? (d(!0), u && u("Trend column enabled.", "success")) : u && u("Trend needs a column field, or a Series aggregation for field data.", "warning");
1619
- }, [T.canUseAny, L, y, n, m, s, u]), w = e.useCallback((W) => {
1620
- if (W.stopPropagation(), !T.canUseAny) {
1621
- u && u("Trend settings are not available for this value selection.", "warning");
1622
- return;
1623
- }
1624
- y(), d(!0);
1625
- }, [T.canUseAny, y, u]);
1626
- return L ? /* @__PURE__ */ e.createElement(
1627
- "div",
1628
- {
1629
- "data-value-sparkline-controls": "true",
1630
- "data-value-sparkline-available": T.canUseAny ? "true" : "false",
1631
- "data-value-sparkline-enabled": _ ? "true" : "false",
1632
- onMouseDown: D,
1633
- onClick: D,
1634
- style: { marginTop: "6px", paddingTop: "6px", borderTop: `1px solid ${a.border}`, width: "100%", display: "flex", alignItems: "center", gap: "6px" }
1635
- },
1636
- /* @__PURE__ */ e.createElement(
1637
- "button",
1638
- {
1639
- type: "button",
1640
- "data-value-sparkline-settings": "true",
1641
- onClick: w,
1642
- style: {
1643
- border: `1px solid ${a.border}`,
1644
- background: a.headerSubtleBg || a.background,
1645
- color: a.textSec,
1646
- borderRadius: "6px",
1647
- cursor: "pointer",
1648
- padding: "3px 8px",
1649
- fontSize: "10px",
1650
- lineHeight: "16px",
1651
- fontWeight: 600,
1652
- flexShrink: 0
1653
- },
1654
- title: "Configure sparkline"
1655
- },
1656
- "Settings"
1657
- ),
1658
- m && /* @__PURE__ */ e.createElement(
1659
- "span",
1660
- {
1661
- "data-value-sparkline-fixed": "true",
1662
- style: { fontSize: "10px", color: a.textSec, flexShrink: 0 },
1663
- title: "This trend is defined by the app"
1664
- },
1665
- "App trend"
1666
- ),
1667
- !m && /* @__PURE__ */ e.createElement(
1668
- "button",
1669
- {
1670
- type: "button",
1671
- "data-value-sparkline-toggle": "true",
1672
- onClick: h,
1673
- style: {
1674
- border: `1px solid ${a.border}`,
1675
- background: a.background,
1676
- color: a.textSec,
1677
- borderRadius: "6px",
1678
- cursor: "pointer",
1679
- padding: "3px 8px",
1680
- fontSize: "10px",
1681
- lineHeight: "16px",
1682
- fontWeight: 600,
1683
- flexShrink: 0
1684
- },
1685
- title: "Remove trend"
1686
- },
1687
- "Remove Trend"
1688
- ),
1689
- _ && !E && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: a.primary, flex: 1, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, (t.sparkline && t.sparkline.source) === "field" ? `series ${(t.sparkline && t.sparkline.displayMode) === "value" ? "value" : "trend"}` : "linked pivot", " | ", ["line", "area", "column", "bar"].includes(t.sparkline && t.sparkline.type) ? t.sparkline.type : "line", " | ", t.sparkline && t.sparkline.metric || "last"),
1690
- E && /* @__PURE__ */ e.createElement(
1691
- Sn,
1692
- {
1693
- item: t,
1694
- idx: n,
1695
- setValConfigs: s,
1696
- theme: a,
1697
- colFields: l,
1698
- onClose: () => d(!1)
1699
- }
1700
- )
1701
- ) : null;
1702
- }
1703
- function Jt({ item: t, idx: n, selected: s, onSelect: a, onRemove: l, setValConfigs: g, theme: u, styles: E, dropLine: d, zoneId: $, valueSelectStyle: i, colFields: m = [], fixedSparklineValueKeySet: T = /* @__PURE__ */ new Set(), showNotification: L, serverError: _ = null }) {
1704
- const D = s ? `${u.primary}77` : _ ? "#F59E0B88" : u.border, y = s ? u.headerBg || `${u.primary}0f` : u.background || "transparent", h = String(t.formula || "").trim() || "Empty formula";
1705
- return /* @__PURE__ */ e.createElement(
1706
- "div",
1707
- {
1708
- onClick: () => a(t.field),
1709
- style: {
1710
- ...E.chip,
1711
- border: `1px solid ${D}`,
1712
- background: y,
1713
- borderLeft: s ? `3px solid ${u.primary}` : "3px solid transparent",
1714
- boxShadow: "none",
1715
- cursor: "pointer",
1716
- flexWrap: "wrap",
1717
- alignItems: "flex-start"
1718
- },
1719
- title: "Select formula"
1720
- },
1721
- d && d.zone === $ && d.idx === n && /* @__PURE__ */ e.createElement("div", { style: { ...E.dropLine, top: -2 } }),
1722
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(z.DragIndicator, null), /* @__PURE__ */ e.createElement("span", { style: {
1723
- fontSize: "10px",
1724
- fontWeight: 700,
1725
- color: u.primary,
1726
- background: `${u.primary}18`,
1727
- borderRadius: "999px",
1728
- padding: "3px 7px",
1729
- letterSpacing: "0.5px",
1730
- flexShrink: 0
1731
- } }, "fx"), /* @__PURE__ */ e.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0 } }, /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 600, display: "block", minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, t.label || "Formula"), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: u.textSec, fontFamily: "monospace", flexShrink: 0 } }, N(t)), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "9px", color: u.textSec, border: `1px solid ${u.border}`, borderRadius: "999px", padding: "1px 6px", flexShrink: 0 } }, xe(t.formulaScope) ? "columns" : "values")), /* @__PURE__ */ e.createElement("div", { style: {
1732
- marginTop: "2px",
1733
- fontSize: "10px",
1734
- lineHeight: 1.35,
1735
- color: u.textSec,
1736
- fontFamily: "monospace",
1737
- whiteSpace: "nowrap",
1738
- overflow: "hidden",
1739
- textOverflow: "ellipsis"
1740
- } }, "=", h), _ && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "2px", fontSize: "9px", color: "#B45309" } }, "⚠ ", hn[_] || _))),
1741
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", marginLeft: "8px", alignItems: "center", flexShrink: 0 } }, s && /* @__PURE__ */ e.createElement("span", { style: {
1742
- fontSize: "9px",
1743
- color: u.primary,
1744
- background: `${u.primary}14`,
1745
- borderRadius: "999px",
1746
- padding: "2px 6px",
1747
- flexShrink: 0
1748
- } }, "Active"), /* @__PURE__ */ e.createElement(
1749
- "span",
1750
- {
1751
- onClick: (w) => {
1752
- w.stopPropagation(), l(n);
1753
- },
1754
- style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" }
1755
- },
1756
- /* @__PURE__ */ e.createElement(z.Close, null)
1757
- )),
1758
- /* @__PURE__ */ e.createElement(
1759
- dr,
1760
- {
1761
- item: t,
1762
- idx: n,
1763
- setValConfigs: g,
1764
- theme: u,
1765
- valueSelectStyle: i,
1766
- colFields: m,
1767
- fixedSparklineValueKeySet: T,
1768
- showNotification: L
1769
- }
1770
- ),
1771
- d && d.zone === $ && d.idx === n + 1 && /* @__PURE__ */ e.createElement("div", { style: { ...E.dropLine, bottom: -2 } })
1772
- );
1773
- }
1774
- const hn = {
1775
- self_reference: "Formula references itself (server)",
1776
- circular_reference: "Circular dependency with another formula (server)",
1777
- expression_error: "Expression could not be evaluated (server)",
1778
- missing_reference: "Unknown field reference (server)"
1779
- };
1780
- function kn({ item: t, idx: n, valConfigs: s, setValConfigs: a, theme: l, onClose: g, onRemove: u, displayedColumnOptions: E = [], availableRawFields: d = [], serverError: $ = null }) {
1781
- const i = e.useRef(null), [m, T] = e.useState({
1782
- label: t.label || "",
1783
- formula: t.formula || "",
1784
- formulaRef: N(t),
1785
- formulaScope: ze(t.formulaScope)
1786
- }), L = e.useRef(t);
1787
- L.current = t, e.useEffect(() => {
1788
- const x = L.current;
1789
- T({
1790
- label: x.label || "",
1791
- formula: x.formula || "",
1792
- formulaRef: N(x),
1793
- formulaScope: ze(x.formulaScope)
1794
- });
1795
- }, [t.field]), e.useEffect(() => {
1796
- if (!i.current) return;
1797
- i.current.focus();
1798
- const x = i.current.value.length;
1799
- i.current.setSelectionRange(x, x);
1800
- }, [t.field]);
1801
- const _ = e.useMemo(
1802
- () => s.filter(
1803
- /** @param {any} [config] @returns {any} */
1804
- (x) => x && x.field
1805
- ),
1806
- [s]
1807
- ), D = e.useMemo(
1808
- () => _.filter(
1809
- /** @param {any} [config] @returns {any} */
1810
- (x) => x.agg !== "formula"
1811
- ),
1812
- [_]
1813
- ), y = e.useMemo(
1814
- () => _.filter(
1815
- /** @param {any} [config] @returns {any} */
1816
- (x) => x.agg === "formula" && x.field !== t.field
1817
- ),
1818
- [t.field, _]
1819
- ), h = e.useMemo(
1820
- () => (Array.isArray(E) ? E : []).filter((x) => x && x.id && x.id !== t.field),
1821
- [E, t.field]
1822
- ), w = e.useMemo(
1823
- () => {
1824
- const x = new Set(_.map(
1825
- /** @param {any} [c] @returns {any} */
1826
- (F) => F.field
1827
- ).filter(Boolean));
1828
- return (Array.isArray(d) ? d : []).filter((F) => !x.has(F));
1829
- },
1830
- [d, _]
1831
- ), W = e.useMemo(
1832
- () => yn(
1833
- m.formula,
1834
- _,
1835
- t.field,
1836
- m.formulaRef,
1837
- m.formulaScope,
1838
- h,
1839
- w
1840
- ),
1841
- [h, m.formula, m.formulaRef, m.formulaScope, t.field, _, w]
1842
- ), O = e.useMemo(
1843
- () => vn(l, W.tone),
1844
- [W.tone, l]
1845
- ), k = e.useMemo(
1846
- () => xe(m.formulaScope) ? En(h) : bn(D),
1847
- [h, m.formulaScope, D]
1848
- ), P = e.useMemo(
1849
- () => xe(m.formulaScope) ? Xt(h) || "[column_id] - [other_column_id]" : Et(D) || `${ye(m.formulaRef || t.field)} * 100`,
1850
- [h, m.formulaRef, m.formulaScope, t.field, D]
1851
- ), o = m.label !== (t.label || "") || m.formula !== (t.formula || "") || m.formulaRef !== N(t) || m.formulaScope !== ze(t.formulaScope), A = e.useCallback(() => {
1852
- const x = ve(m.formulaRef, t.field);
1853
- a(
1854
- /** @param {any} [prev] @returns {any} */
1855
- (F) => {
1856
- const v = [...F], U = v[n];
1857
- if (!U) return F;
1858
- const Q = N(U);
1859
- let V = x;
1860
- const ee = new Set(
1861
- v.filter((Z, te) => Z && te !== n).map((Z) => Z.agg === "formula" ? N(Z) : Z.field).filter(Boolean).map((Z) => String(Z).toLowerCase())
1862
- );
1863
- if (ee.has(V.toLowerCase())) {
1864
- let Z = 2, te = `${V}${Z}`;
1865
- for (; ee.has(te.toLowerCase()); )
1866
- Z += 1, te = `${V}${Z}`;
1867
- V = te;
1868
- }
1869
- if (v[n] = {
1870
- ...U,
1871
- label: m.label,
1872
- formula: m.formula,
1873
- formulaRef: V,
1874
- formulaScope: m.formulaScope
1875
- }, Q && Q !== V)
1876
- for (let Z = 0; Z < v.length; Z += 1) {
1877
- if (Z === n) continue;
1878
- const te = v[Z];
1879
- !te || te.agg !== "formula" || !te.formula || (v[Z] = {
1880
- ...te,
1881
- formula: fn(te.formula, Q, V)
1882
- });
1883
- }
1884
- return v;
1885
- }
1886
- );
1887
- }, [m.formula, m.formulaRef, m.formulaScope, m.label, n, t.field, a]), R = e.useCallback(() => {
1888
- T({
1889
- label: t.label || "",
1890
- formula: t.formula || "",
1891
- formulaRef: N(t),
1892
- formulaScope: ze(t.formulaScope)
1893
- }), g();
1894
- }, [t.field, t.formula, t.formulaRef, t.formulaScope, t.label, g]), B = e.useCallback((x) => {
1895
- const F = i.current;
1896
- if (!F) return;
1897
- const v = m.formula || "", U = F.selectionStart ?? v.length, Q = F.selectionEnd ?? v.length, V = `${v.slice(0, U)}${x}${v.slice(Q)}`;
1898
- T(
1899
- /** @param {any} [prev] @returns {any} */
1900
- (Z) => ({ ...Z, formula: V })
1901
- );
1902
- const ee = U + x.length;
1903
- setTimeout(() => {
1904
- i.current && (i.current.focus(), i.current.setSelectionRange(ee, ee));
1905
- }, 0);
1906
- }, [m.formula]), M = e.useCallback(() => {
1907
- A(), g();
1908
- }, [A, g]), H = {
1909
- border: `1px solid ${l.border}`,
1910
- background: l.background,
1911
- color: l.text,
1912
- borderRadius: "999px",
1913
- cursor: "pointer",
1914
- padding: "3px 9px",
1915
- fontSize: "10px",
1916
- lineHeight: "16px"
1917
- }, K = {
1918
- border: `1px solid ${l.border}`,
1919
- background: l.headerSubtleBg || l.background,
1920
- color: l.text,
1921
- borderRadius: "6px",
1922
- cursor: "pointer",
1923
- padding: "3px 8px",
1924
- fontSize: "10px",
1925
- lineHeight: "16px",
1926
- fontFamily: "monospace"
1927
- };
1928
- return /* @__PURE__ */ e.createElement(
1929
- "div",
1930
- {
1931
- onClick: R,
1932
- style: {
1933
- position: "fixed",
1934
- inset: 0,
1935
- zIndex: 10006,
1936
- background: "rgba(2, 6, 23, 0.45)",
1937
- display: "flex",
1938
- alignItems: "center",
1939
- justifyContent: "center",
1940
- padding: "24px"
1941
- }
1942
- },
1943
- /* @__PURE__ */ e.createElement(
1944
- "div",
1945
- {
1946
- onClick: (x) => x.stopPropagation(),
1947
- onKeyDown: (x) => {
1948
- x.key === "Escape" && R(), (x.ctrlKey || x.metaKey) && x.key === "Enter" && M();
1949
- },
1950
- style: {
1951
- width: "min(760px, 92vw)",
1952
- maxHeight: "80vh",
1953
- overflowY: "auto",
1954
- background: l.surfaceBg || l.background || "#fff",
1955
- border: `1px solid ${l.border}`,
1956
- borderRadius: l.radius || "16px",
1957
- boxShadow: l.shadowMd || "0 18px 40px rgba(0,0,0,0.28)",
1958
- padding: "18px"
1959
- }
1960
- },
1961
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px", marginBottom: "14px" } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "15px", fontWeight: 800, color: l.text } }, "Formula Editor"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec } }, "Use a stable reference key for formulas. Renaming the key updates dependent formulas.")), /* @__PURE__ */ e.createElement(
1962
- "button",
1963
- {
1964
- type: "button",
1965
- onClick: R,
1966
- style: {
1967
- border: `1px solid ${l.border}`,
1968
- background: l.headerSubtleBg || l.background,
1969
- color: l.text,
1970
- borderRadius: "8px",
1971
- padding: "7px 10px",
1972
- fontSize: "11px",
1973
- fontWeight: 700,
1974
- cursor: "pointer"
1975
- }
1976
- },
1977
- "Close"
1978
- )),
1979
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap", marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", flex: 1, minWidth: "180px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Label"), /* @__PURE__ */ e.createElement(
1980
- "input",
1981
- {
1982
- value: m.label,
1983
- onChange: (x) => T(
1984
- /** @param {any} [prev] @returns {any} */
1985
- (F) => ({ ...F, label: x.target.value })
1986
- ),
1987
- placeholder: "Formula label",
1988
- style: {
1989
- border: `1px solid ${l.border}`,
1990
- background: l.background,
1991
- color: l.text,
1992
- borderRadius: "8px",
1993
- padding: "8px 10px",
1994
- fontSize: "12px",
1995
- fontWeight: 600,
1996
- outline: "none"
1997
- }
1998
- }
1999
- )), /* @__PURE__ */ e.createElement("label", { style: { minWidth: "180px", flex: "0 0 auto", display: "flex", flexDirection: "column", gap: "4px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Reference key"), /* @__PURE__ */ e.createElement(
2000
- "input",
2001
- {
2002
- value: m.formulaRef,
2003
- onChange: (x) => T(
2004
- /** @param {any} [prev] @returns {any} */
2005
- (F) => ({ ...F, formulaRef: ve(x.target.value, t.field) })
2006
- ),
2007
- placeholder: "formula1",
2008
- style: {
2009
- border: `1px solid ${l.border}`,
2010
- background: l.headerSubtleBg || l.background,
2011
- color: l.text,
2012
- borderRadius: "8px",
2013
- padding: "8px 10px",
2014
- fontSize: "12px",
2015
- fontFamily: "monospace",
2016
- outline: "none"
2017
- }
2018
- }
2019
- )), /* @__PURE__ */ e.createElement("label", { style: { minWidth: "180px", flex: "0 0 auto", display: "flex", flexDirection: "column", gap: "4px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Formula type"), /* @__PURE__ */ e.createElement(
2020
- "select",
2021
- {
2022
- value: m.formulaScope,
2023
- onChange: (x) => {
2024
- const F = ze(x.target.value);
2025
- T(
2026
- /** @param {any} [prev] @returns {any} */
2027
- (v) => ({
2028
- ...v,
2029
- formulaScope: F,
2030
- formula: v.formula || (F === "columns" ? Xt(h) : Et(D))
2031
- })
2032
- );
2033
- },
2034
- style: {
2035
- border: `1px solid ${l.border}`,
2036
- background: l.headerSubtleBg || l.background,
2037
- color: l.text,
2038
- borderRadius: "8px",
2039
- padding: "8px 10px",
2040
- fontSize: "12px",
2041
- outline: "none"
2042
- }
2043
- },
2044
- /* @__PURE__ */ e.createElement("option", { value: "measures" }, "Value formula"),
2045
- /* @__PURE__ */ e.createElement("option", { value: "columns" }, "Displayed columns")
2046
- ))),
2047
- /* @__PURE__ */ e.createElement("div", { style: { marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "4px" } }, "Formula"), /* @__PURE__ */ e.createElement(
2048
- "textarea",
2049
- {
2050
- ref: i,
2051
- value: m.formula,
2052
- onChange: (x) => T(
2053
- /** @param {any} [prev] @returns {any} */
2054
- (F) => ({ ...F, formula: x.target.value })
2055
- ),
2056
- placeholder: P,
2057
- rows: 4,
2058
- style: {
2059
- width: "100%",
2060
- boxSizing: "border-box",
2061
- resize: "vertical",
2062
- border: `1px solid ${l.border}`,
2063
- background: l.background,
2064
- color: l.text,
2065
- borderRadius: "10px",
2066
- fontFamily: "monospace",
2067
- fontSize: "12px",
2068
- lineHeight: 1.5,
2069
- padding: "10px 12px",
2070
- outline: "none"
2071
- }
2072
- }
2073
- )),
2074
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", flexWrap: "wrap", marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("div", { style: {
2075
- padding: "5px 9px",
2076
- borderRadius: "999px",
2077
- border: `1px solid ${O.border}`,
2078
- background: O.background,
2079
- color: O.text,
2080
- fontSize: "10px",
2081
- lineHeight: "14px"
2082
- } }, W.text), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec } }, "Ctrl/Cmd + Enter applies")),
2083
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginBottom: "12px" } }, k.map(
2084
- /** @param {any} [template] @returns {any} */
2085
- (x) => /* @__PURE__ */ e.createElement(
2086
- "button",
2087
- {
2088
- key: x.label,
2089
- type: "button",
2090
- onClick: () => T(
2091
- /** @param {any} [prev] @returns {any} */
2092
- (F) => ({ ...F, formula: x.value })
2093
- ),
2094
- style: H
2095
- },
2096
- x.label
2097
- )
2098
- ), ["+", "-", "*", "/", "(", ")", "* 100"].map((x) => /* @__PURE__ */ e.createElement(
2099
- "button",
2100
- {
2101
- key: x,
2102
- type: "button",
2103
- onMouseDown: (F) => F.preventDefault(),
2104
- onClick: () => B(x),
2105
- style: K
2106
- },
2107
- x
2108
- ))),
2109
- /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr", gap: "12px", marginBottom: "14px" } }, xe(m.formulaScope) ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Rendered Columns"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, h.map(
2110
- /** @param {any} [column] @returns {any} */
2111
- (x) => /* @__PURE__ */ e.createElement(
2112
- "button",
2113
- {
2114
- key: x.id,
2115
- type: "button",
2116
- onMouseDown: (F) => F.preventDefault(),
2117
- onClick: () => B(le(x.id)),
2118
- style: H,
2119
- title: `Insert ${x.id}`
2120
- },
2121
- x.label || x.id
2122
- )
2123
- ), h.length === 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "11px", color: l.textSec } }, "Render the pivot once, or type a bracketed column id directly."))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Measures"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, D.map(
2124
- /** @param {any} [config] @returns {any} */
2125
- (x) => /* @__PURE__ */ e.createElement(
2126
- "button",
2127
- {
2128
- key: x.field,
2129
- type: "button",
2130
- onMouseDown: (F) => F.preventDefault(),
2131
- onClick: () => B(ye(x.field)),
2132
- style: H,
2133
- title: `Insert ${x.field}`
2134
- },
2135
- x.field
2136
- )
2137
- ))), !xe(m.formulaScope) && y.length > 0 && /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Formula References"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, y.map(
2138
- /** @param {any} [config] @returns {any} */
2139
- (x) => /* @__PURE__ */ e.createElement(
2140
- "button",
2141
- {
2142
- key: x.field,
2143
- type: "button",
2144
- onMouseDown: (F) => F.preventDefault(),
2145
- onClick: () => B(ye(N(x))),
2146
- style: H,
2147
- title: `${N(x)}${x.label ? ` (${x.label})` : ""}`
2148
- },
2149
- N(x)
2150
- )
2151
- ))), !xe(m.formulaScope) && w.length > 0 && /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Data Fields (auto-aggregated as sum)"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, w.map(
2152
- /** @param {any} [f] @returns {any} */
2153
- (x) => /* @__PURE__ */ e.createElement(
2154
- "button",
2155
- {
2156
- key: x,
2157
- type: "button",
2158
- onMouseDown: (F) => F.preventDefault(),
2159
- onClick: () => B(ye(x)),
2160
- style: { ...H, borderColor: `${l.primary}66`, color: l.primary, background: `${l.primary}0d` },
2161
- title: `Insert: ${x}`
2162
- },
2163
- fe(x)
2164
- )
2165
- )))),
2166
- /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "space-between", gap: "8px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
2167
- "button",
2168
- {
2169
- type: "button",
2170
- onClick: () => {
2171
- u(n), g();
2172
- },
2173
- style: {
2174
- border: `1px solid ${l.border}`,
2175
- background: l.background,
2176
- color: l.textSec,
2177
- borderRadius: "8px",
2178
- padding: "8px 12px",
2179
- fontSize: "11px",
2180
- fontWeight: 700,
2181
- cursor: "pointer"
2182
- }
2183
- },
2184
- "Delete Formula"
2185
- ), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
2186
- "button",
2187
- {
2188
- type: "button",
2189
- onClick: R,
2190
- style: {
2191
- border: `1px solid ${l.border}`,
2192
- background: l.background,
2193
- color: l.textSec,
2194
- borderRadius: "8px",
2195
- padding: "8px 12px",
2196
- fontSize: "11px",
2197
- fontWeight: 700,
2198
- cursor: "pointer"
2199
- }
2200
- },
2201
- "Cancel"
2202
- ), /* @__PURE__ */ e.createElement(
2203
- "button",
2204
- {
2205
- type: "button",
2206
- onClick: M,
2207
- disabled: !o,
2208
- style: {
2209
- border: `1px solid ${o ? `${l.primary}66` : l.border}`,
2210
- background: o ? `${l.primary}14` : l.background,
2211
- color: o ? l.primary : l.textSec,
2212
- borderRadius: "8px",
2213
- padding: "8px 12px",
2214
- fontSize: "11px",
2215
- fontWeight: 700,
2216
- cursor: o ? "pointer" : "default",
2217
- opacity: o ? 1 : 0.7
2218
- }
2219
- },
2220
- "Apply"
2221
- )))
2222
- )
2223
- );
2224
- }
2225
- function qt({
2226
- panelId: t,
2227
- panelLabel: n,
2228
- size: s,
2229
- onSizeChange: a,
2230
- theme: l,
2231
- outerStyle: g = {},
2232
- contentStyle: u = {},
2233
- children: E
2234
- }) {
2235
- const d = e.useRef(null), $ = e.useRef(null), i = e.useMemo(() => Kr(t), [t]), m = e.useMemo(
2236
- () => Gr(t, s),
2237
- [t, s]
2238
- ), T = e.useCallback(() => {
2239
- if ($.current) {
2240
- const D = $.current;
2241
- $.current = null, D();
2242
- }
2243
- }, []);
2244
- e.useEffect(() => (() => T()), [T]);
2245
- const L = e.useCallback((D, y) => {
2246
- if (!d.current || typeof a != "function") return;
2247
- D.preventDefault(), D.stopPropagation(), T();
2248
- const h = d.current.getBoundingClientRect(), w = d.current.parentElement ? d.current.parentElement.getBoundingClientRect() : h, W = {
2249
- startX: D.clientX,
2250
- startY: D.clientY,
2251
- startWidth: h.width,
2252
- startHeight: h.height,
2253
- maxWidth: Math.max(i.minWidth, Math.min(i.maxWidth, Math.floor(w.width)))
2254
- }, O = document.body.style.cursor, k = document.body.style.userSelect;
2255
- document.body.style.cursor = y === "both" ? "nwse-resize" : y === "width" ? "ew-resize" : "ns-resize", document.body.style.userSelect = "none";
2256
- const P = (R) => {
2257
- const B = R.clientX - W.startX, M = R.clientY - W.startY, H = y === "height" ? m.width : Math.max(i.minWidth, Math.min(W.maxWidth, Math.round(W.startWidth + B))), K = y === "width" ? m.height : Math.max(i.minHeight, Math.min(i.maxHeight, Math.round(W.startHeight + M)));
2258
- a(t, { width: H, height: K });
2259
- }, o = () => {
2260
- document.body.style.cursor = O, document.body.style.userSelect = k, window.removeEventListener("mousemove", P), window.removeEventListener("mouseup", A);
2261
- }, A = () => T();
2262
- $.current = o, window.addEventListener("mousemove", P), window.addEventListener("mouseup", A);
2263
- }, [
2264
- i.maxHeight,
2265
- i.maxWidth,
2266
- i.minHeight,
2267
- i.minWidth,
2268
- a,
2269
- t,
2270
- m.height,
2271
- m.width,
2272
- T
2273
- ]), _ = `${l.primary}55`;
2274
- return /* @__PURE__ */ e.createElement(
2275
- "div",
2276
- {
2277
- ref: d,
2278
- style: {
2279
- position: "relative",
2280
- width: m.width === null ? "100%" : `${m.width}px`,
2281
- maxWidth: "100%",
2282
- height: `${m.height}px`,
2283
- minHeight: `${i.minHeight}px`,
2284
- maxHeight: `${i.maxHeight}px`,
2285
- boxSizing: "border-box",
2286
- overflow: "hidden",
2287
- ...g
2288
- }
2289
- },
2290
- /* @__PURE__ */ e.createElement(
2291
- "div",
2292
- {
2293
- style: {
2294
- width: "100%",
2295
- height: "100%",
2296
- overflow: "auto",
2297
- boxSizing: "border-box",
2298
- ...u
2299
- }
2300
- },
2301
- E
2302
- ),
2303
- /* @__PURE__ */ e.createElement(
2304
- "div",
2305
- {
2306
- onMouseDown: (D) => L(D, "width"),
2307
- style: {
2308
- position: "absolute",
2309
- top: 0,
2310
- right: 0,
2311
- bottom: "12px",
2312
- width: "12px",
2313
- cursor: "ew-resize",
2314
- zIndex: 4,
2315
- touchAction: "none"
2316
- },
2317
- title: `Resize ${n} width`
2318
- }
2319
- ),
2320
- /* @__PURE__ */ e.createElement(
2321
- "div",
2322
- {
2323
- onMouseDown: (D) => L(D, "height"),
2324
- style: {
2325
- position: "absolute",
2326
- left: 0,
2327
- right: "12px",
2328
- bottom: 0,
2329
- height: "12px",
2330
- cursor: "ns-resize",
2331
- zIndex: 4,
2332
- touchAction: "none"
2333
- },
2334
- title: `Resize ${n} height`
2335
- }
2336
- ),
2337
- /* @__PURE__ */ e.createElement(
2338
- "div",
2339
- {
2340
- onMouseDown: (D) => L(D, "both"),
2341
- style: {
2342
- position: "absolute",
2343
- right: 0,
2344
- bottom: 0,
2345
- width: "14px",
2346
- height: "14px",
2347
- cursor: "nwse-resize",
2348
- zIndex: 5,
2349
- touchAction: "none"
2350
- },
2351
- title: `Resize ${n}`
2352
- },
2353
- /* @__PURE__ */ e.createElement(
2354
- "div",
2355
- {
2356
- style: {
2357
- position: "absolute",
2358
- right: "4px",
2359
- bottom: "4px",
2360
- width: "3px",
2361
- height: "3px",
2362
- borderRadius: "999px",
2363
- background: _,
2364
- boxShadow: `-4px 0 0 ${_}, 0 -4px 0 ${_}, -4px -4px 0 ${_}`
2365
- }
2366
- }
2367
- )
2368
- )
2369
- );
2370
- }
2371
- function Qt({ measureAxis: t, setMeasureAxis: n, theme: s, valueSelectStyle: a, regularValueCount: l }) {
2372
- const g = e.useMemo(() => Pe(t), [t]), u = e.useCallback((d) => {
2373
- typeof n == "function" && n(
2374
- /** @param {any} [previous] @returns {any} */
2375
- ($) => ({
2376
- ...Pe($),
2377
- ...typeof d == "function" ? d(Pe($)) : d
2378
- })
2379
- );
2380
- }, [n]), E = {
2381
- ...a,
2382
- width: "112px",
2383
- padding: "3px 6px",
2384
- fontSize: "10px"
2385
- };
2386
- return /* @__PURE__ */ e.createElement("div", { style: {
2387
- display: "flex",
2388
- alignItems: "center",
2389
- gap: "6px",
2390
- flexWrap: "wrap",
2391
- padding: "6px",
2392
- border: `1px solid ${s.border}`,
2393
- borderRadius: s.radiusSm || "6px",
2394
- background: s.surfaceInset || s.headerSubtleBg || s.background
2395
- } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: s.textSec, fontWeight: 700, textTransform: "uppercase" } }, "Values as"), /* @__PURE__ */ e.createElement(
2396
- "select",
2397
- {
2398
- value: g.placement,
2399
- onChange: (d) => u({ placement: d.target.value }),
2400
- style: { ...a, width: "98px" },
2401
- title: "Values placement"
2402
- },
2403
- /* @__PURE__ */ e.createElement("option", { value: "none" }, "Columns"),
2404
- /* @__PURE__ */ e.createElement("option", { value: "rows" }, "Rows"),
2405
- /* @__PURE__ */ e.createElement("option", { value: "columns" }, "Column Axis")
2406
- ), g.placement !== "none" && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
2407
- "input",
2408
- {
2409
- value: g.labelField,
2410
- onChange: (d) => u({ labelField: d.target.value }),
2411
- style: E,
2412
- title: "Measure label field"
2413
- }
2414
- ), /* @__PURE__ */ e.createElement(
2415
- "input",
2416
- {
2417
- value: g.valueField,
2418
- onChange: (d) => u({ valueField: d.target.value }),
2419
- style: { ...E, width: "82px" },
2420
- title: "Measure value field"
2421
- }
2422
- ), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", alignItems: "center", gap: "4px", fontSize: "10px", color: s.textSec } }, /* @__PURE__ */ e.createElement(
2423
- "input",
2424
- {
2425
- type: "checkbox",
2426
- checked: g.suppressEmptyMembers,
2427
- onChange: (d) => u({ suppressEmptyMembers: d.target.checked })
2428
- }
2429
- ), "Empty"), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", alignItems: "center", gap: "4px", fontSize: "10px", color: s.textSec } }, /* @__PURE__ */ e.createElement(
2430
- "input",
2431
- {
2432
- type: "checkbox",
2433
- checked: g.suppressZeroMembers,
2434
- onChange: (d) => u({ suppressZeroMembers: d.target.checked })
2435
- }
2436
- ), "Zero")), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: s.textSec } }, l, " selected"));
2437
- }
2438
- const Fn = e.memo(
2439
- /** @param {any} p0 @returns {any} */
2440
- function({
2441
- sidebarTab: n,
2442
- setSidebarTab: s,
2443
- rowFields: a,
2444
- setRowFields: l,
2445
- colFields: g,
2446
- setColFields: u,
2447
- valConfigs: E,
2448
- setValConfigs: d,
2449
- measureAxis: $ = {},
2450
- setMeasureAxis: i = null,
2451
- columnVisibility: m,
2452
- setColumnVisibility: T,
2453
- columnPinning: L,
2454
- setColumnPinning: _,
2455
- availableFields: D,
2456
- table: y,
2457
- pinningPresets: h,
2458
- showNotification: w,
2459
- filterAnchorEl: W,
2460
- setFilterAnchorEl: O,
2461
- colSearch: k,
2462
- setColSearch: P,
2463
- colTypeFilter: o,
2464
- setColTypeFilter: A,
2465
- selectedCols: R,
2466
- setSelectedCols: B,
2467
- dropLine: M,
2468
- onDragStart: H,
2469
- onDragOver: K,
2470
- onDrop: x,
2471
- onDragEnd: F,
2472
- onKeyboardFieldDrop: v,
2473
- handleHeaderFilter: U,
2474
- handleFilterClick: Q,
2475
- requestFilterOptions: V,
2476
- handleExpandAllRows: ee,
2477
- handlePinColumn: Z,
2478
- toggleAllColumnsPinned: te,
2479
- activeFilterCol: Cn,
2480
- closeFilterPopover: wn,
2481
- filterOptions: Me,
2482
- filterOptionMeta: Oe = {},
2483
- clientFilterOptionMap: He = {},
2484
- data: Se,
2485
- sidebarWidth: rt,
2486
- setSidebarWidth: St,
2487
- fieldPanelSizes: Ue,
2488
- setFieldPanelSizes: nt,
2489
- fixedSparklineValueKeys: lt = [],
2490
- sparklineFields: Rn = null,
2491
- displayedColumnOptions: fr = [],
2492
- reportEditorSelection: gr = null,
2493
- showReportConfigColumn: mr = !0,
2494
- setShowReportConfigColumn: xr = null,
2495
- formulaErrors: he = {},
2496
- serverSide: je = !1
2497
- }) {
2498
- Or("SidebarPanel");
2499
- const { theme: c, styles: Y } = Hr(), {
2500
- filters: ae,
2501
- setFilters: at,
2502
- pivotMode: yr,
2503
- reportDef: br,
2504
- setReportDef: Er,
2505
- savedReports: vr,
2506
- setSavedReports: Sr,
2507
- activeReportId: hr,
2508
- setActiveReportId: kr,
2509
- customDimensions: _e,
2510
- setCustomDimensions: ht
2511
- } = Ur(), [Ve, kt] = e.useState({ columnId: null, anchorEl: null }), [ke, Ce] = e.useState(null), [se, ge] = e.useState(null), [we, Cr] = e.useState("report"), Ze = e.useRef(null), [wr, Ye] = e.useState(null), pe = e.useRef(null), Ct = e.useRef(0), Ke = e.useRef(null), ce = e.useRef(null), [G, ot] = e.useState(null), [it, wt] = e.useState(""), st = e.useMemo(
2512
- () => new Set(Array.isArray(lt) ? lt : []),
2513
- [lt]
2514
- ), X = e.useCallback(
2515
- (r) => jr(r, _e),
2516
- [_e]
2517
- ), Rt = e.useMemo(
2518
- () => Pe($),
2519
- [$]
2520
- ), de = Rt.labelField || "Measure Name", Re = e.useMemo(
2521
- () => (D || []).filter(
2522
- /** @param {any} [field] @returns {any} */
2523
- (r) => r
2524
- ),
2525
- [D]
2526
- ), J = e.useMemo(
2527
- () => Re.filter(
2528
- /** @param {any} [field] @returns {any} */
2529
- (r) => r && !tr(r)
2530
- ),
2531
- [Re]
2532
- ), Te = Array.isArray(E) && E.length > 0 && de && !Re.includes(de), De = e.useMemo(
2533
- () => Te ? [de, ...Re] : Re,
2534
- [Re, de, Te]
2535
- ), We = it.trim().toLowerCase(), Ge = e.useCallback((r) => {
2536
- if (!We) return !0;
2537
- const f = Te && r === de ? "measure name measure names metric metrics value values" : "";
2538
- return String(r || "").toLowerCase().includes(We) || String(X(r) || "").toLowerCase().includes(We) || f.includes(We);
2539
- }, [X, de, We, Te]), ct = e.useMemo(
2540
- () => De.length > 8 ? De.filter(Ge) : De,
2541
- [De, Ge]
2542
- ), ut = e.useMemo(
2543
- () => J.length > 8 ? J.filter(Ge) : J,
2544
- [J, Ge]
2545
- ), Dt = e.useCallback((r) => {
2546
- l(
2547
- /** @param {any} [prev] @returns {any} */
2548
- (f) => (f || []).filter(
2549
- /** @param {any} [item] @returns {any} */
2550
- (p) => p !== r
2551
- )
2552
- ), u(
2553
- /** @param {any} [prev] @returns {any} */
2554
- (f) => (f || []).filter(
2555
- /** @param {any} [item] @returns {any} */
2556
- (p) => p !== r
2557
- )
2558
- ), d(
2559
- /** @param {any} [prev] @returns {any} */
2560
- (f) => (f || []).filter(
2561
- /** @param {any} [item] @returns {any} */
2562
- (p) => !(p && p.field === r)
2563
- )
2564
- ), at(
2565
- /** @param {any} [prev] @returns {any} */
2566
- (f) => {
2567
- if (!f || !Object.prototype.hasOwnProperty.call(f, r)) return f;
2568
- const p = { ...f };
2569
- return delete p[r], p;
2570
- }
2571
- );
2572
- }, [u, at, l, d]), Rr = e.useCallback((r) => {
2573
- const f = pe.current;
2574
- if (!f) return;
2575
- const p = 60, b = 12, S = f.getBoundingClientRect(), I = r.clientY, q = I - S.top, C = S.bottom - I;
2576
- let j = 0;
2577
- if (q < p && q >= 0 ? j = -1 : C < p && C >= 0 && (j = 1), j === 0) {
2578
- ce.current && (cancelAnimationFrame(ce.current), ce.current = null);
2579
- return;
2580
- }
2581
- const ie = () => {
2582
- pe.current && (pe.current.scrollTop += j * b, ce.current = requestAnimationFrame(ie));
2583
- };
2584
- ce.current || (ce.current = requestAnimationFrame(ie));
2585
- }, []), At = e.useCallback(() => {
2586
- ce.current && (cancelAnimationFrame(ce.current), ce.current = null);
2587
- }, []), oe = e.useMemo(
2588
- () => E.filter(
2589
- /** @param {any} [config] @returns {any} */
2590
- (r) => r && r.agg === "formula"
2591
- ),
2592
- [E]
2593
- ), me = e.useMemo(
2594
- () => oe.length,
2595
- [oe]
2596
- ), Ae = e.useMemo(
2597
- () => E.filter(
2598
- /** @param {any} [config] @returns {any} */
2599
- (r) => r && r.agg !== "formula"
2600
- ).length,
2601
- [E]
2602
- ), Dr = e.useMemo(() => [
2603
- { id: "rows", label: "Rows", icon: /* @__PURE__ */ e.createElement(z.List, null) },
2604
- { id: "cols", label: "Columns", icon: /* @__PURE__ */ e.createElement(z.Columns, null) },
2605
- { id: "vals", label: "Values", icon: /* @__PURE__ */ e.createElement(z.Sigma, null) },
2606
- { id: "filter", label: "Filters", icon: /* @__PURE__ */ e.createElement(z.Filter, null) }
2607
- ], []), Be = e.useMemo(() => ({
2608
- filter: Object.keys(ae || {}).filter((r) => r !== "global"),
2609
- rows: a || [],
2610
- cols: g || [],
2611
- vals: E || []
2612
- }), [g, ae, a, E]), Ne = e.useCallback(() => {
2613
- G && w && w("Keyboard move cancelled.", "info"), ot(null);
2614
- }, [G, w]), $t = e.useCallback((r, f, p, b) => {
2615
- if (typeof v != "function") return;
2616
- ot({ field: r, zone: f, idx: p, label: b }), w && w(`Picked up ${b}. Focus a target field or zone and press Enter.`, "info");
2617
- }, [v, w]), Xe = e.useCallback((r, f = null) => {
2618
- if (!G || typeof v != "function") return !1;
2619
- const p = Be[r] || [], b = Number(f), S = Number.isFinite(b) ? Math.max(0, Math.min(Math.floor(b), p.length)) : p.length, I = v({
2620
- field: G.field,
2621
- srcZone: G.zone,
2622
- srcIdx: G.idx,
2623
- targetZone: r,
2624
- targetIdx: S,
2625
- source: "layout:keyboard-drop"
2626
- });
2627
- return I !== !1 && (w && w(`Moved ${G.label}.`, "success"), ot(null)), I !== !1;
2628
- }, [G, v, w, Be]), Ft = e.useCallback((r, f, p, b, S) => {
2629
- if (!Nt(r.target)) {
2630
- if (r.key === "Escape") {
2631
- r.preventDefault(), r.stopPropagation(), Ne();
2632
- return;
2633
- }
2634
- r.key !== "Enter" && r.key !== " " || (r.preventDefault(), r.stopPropagation(), G ? Xe(p, b) : $t(f, p, b, S));
2635
- }
2636
- }, [Ne, Xe, G, $t]), Ar = e.useCallback((r, f) => {
2637
- if (!Nt(r.target)) {
2638
- if (r.key === "Escape") {
2639
- r.preventDefault(), r.stopPropagation(), Ne();
2640
- return;
2641
- }
2642
- !G || r.key !== "Enter" && r.key !== " " || (r.preventDefault(), r.stopPropagation(), Xe(f, (Be[f] || []).length));
2643
- }
2644
- }, [Ne, Xe, G, Be]), $r = e.useCallback((r) => {
2645
- r.preventDefault();
2646
- const f = r.clientX, p = rt || 288;
2647
- Ke.current = { startX: f, startWidth: p };
2648
- const b = (I) => {
2649
- const q = I.clientX - Ke.current.startX, C = Math.max(200, Math.min(520, Ke.current.startWidth + q));
2650
- St(C);
2651
- }, S = () => {
2652
- Ke.current = null, window.removeEventListener("mousemove", b), window.removeEventListener("mouseup", S);
2653
- };
2654
- window.addEventListener("mousemove", b), window.addEventListener("mouseup", S);
2655
- }, [rt, St]), zt = e.useCallback((r, f) => {
2656
- typeof nt == "function" && nt(
2657
- /** @param {any} [prev] @returns {any} */
2658
- (p) => {
2659
- const b = Vr(p, r, f), S = p && p[r] ? p[r] : null, I = b[r];
2660
- return S && S.width === I.width && S.height === I.height ? p : b;
2661
- }
2662
- );
2663
- }, [nt]), Mt = Y.dropZone && Y.dropZone.padding || "8px", _t = e.useMemo(() => {
2664
- const r = { ...Y.dropZone || {} };
2665
- return delete r.minHeight, delete r.maxHeight, delete r.overflowY, delete r.padding, delete r.border, delete r.boxShadow, r;
2666
- }, [Y.dropZone]), Tt = e.useCallback((r) => {
2667
- if (Me && Me[r]) return Me[r];
2668
- if (He && He[r]) return He[r];
2669
- if (!y || !y.getColumn) return [];
2670
- if (!y.getColumn(r)) return [];
2671
- const p = /* @__PURE__ */ new Set();
2672
- return (y.getCoreRowModel ? y.getCoreRowModel().rows : []).forEach(
2673
- /** @param {any} [row] @returns {any} */
2674
- (S) => {
2675
- const I = S.getValue(r);
2676
- I != null && I !== "" && p.add(I);
2677
- }
2678
- ), Array.from(p).sort((S, I) => String(S).localeCompare(String(I), void 0, { numeric: !0, sensitivity: "base" }));
2679
- }, [He, Me, y]), ue = e.useMemo(() => ({
2680
- border: `1px solid ${c.border}`,
2681
- background: c.headerSubtleBg || c.surfaceInset || c.background,
2682
- color: c.text,
2683
- cursor: "pointer",
2684
- borderRadius: c.radiusSm || "8px",
2685
- fontSize: "9px",
2686
- lineHeight: 1.2,
2687
- padding: "1px 4px",
2688
- minHeight: "20px",
2689
- outline: "none"
2690
- }), [c.background, c.border, c.headerSubtleBg, c.radiusSm, c.surfaceInset, c.text]), Wt = e.useCallback((r, f) => {
2691
- d(
2692
- /** @param {any} [prev] @returns {any} */
2693
- (p) => {
2694
- const b = [...p], S = b[r];
2695
- if (!S) return p;
2696
- if (Ht(f) && !S.weightField) {
2697
- const I = Array.isArray(J) && J.length > 0 ? J.find((j) => j !== S.field) || J[0] : "", q = typeof window < "u" ? window.prompt(
2698
- `Weight field for weighted average of ${fe(S.field)}`,
2699
- S.weightField || I || ""
2700
- ) : S.weightField || I || "", C = typeof q == "string" ? q.trim() : "";
2701
- return C ? Array.isArray(J) && J.length > 0 && !J.includes(C) ? (w && w(`Unknown weight field: ${C}`, "warning"), p) : (b[r] = { ...S, agg: f, weightField: C }, b) : (w && w("Weighted average requires a weight field.", "warning"), p);
2702
- }
2703
- return b[r] = { ...S, agg: f }, b;
2704
- }
2705
- );
2706
- }, [J, d, w]), Fr = e.useCallback((r, f) => {
2707
- if (!f) {
2708
- w && w("Weighted average requires a weight field.", "warning");
2709
- return;
2710
- }
2711
- d(
2712
- /** @param {any} [prev] @returns {any} */
2713
- (p) => {
2714
- const b = [...p], S = b[r];
2715
- return S ? (b[r] = { ...S, weightField: f }, b) : p;
2716
- }
2717
- );
2718
- }, [d, w]), zr = e.useCallback((r, f) => {
2719
- d(
2720
- /** @param {any} [prev] @returns {any} */
2721
- (p) => {
2722
- const b = [...p], S = b[r];
2723
- return S ? (b[r] = {
2724
- ...S,
2725
- windowFn: f === "none" ? null : f
2726
- }, b) : p;
2727
- }
2728
- );
2729
- }, [d]), Bt = e.useCallback(() => {
2730
- const r = xn(E), f = E.filter(
2731
- /** @param {any} [config] @returns {any} */
2732
- (I) => I && I.agg !== "formula"
2733
- ), p = `Formula ${me + 1}`, b = Et(f), S = dn(p, E, r);
2734
- Ce(r), ge(r), d(
2735
- /** @param {any} [prev] @returns {any} */
2736
- (I) => [
2737
- ...I,
2738
- {
2739
- field: r,
2740
- agg: "formula",
2741
- label: p,
2742
- formula: b,
2743
- formulaRef: S,
2744
- formulaScope: "measures"
2745
- }
2746
- ]
2747
- ), w && (f.length === 0 ? w("Added a formula column. Add at least one regular value measure to reference in it.", "warning") : w(`Added ${p}.`, "success"));
2748
- }, [me, ge, d, Ce, w, E]), Mr = (r, f) => {
2749
- r.stopPropagation(), pe.current && (Ct.current = pe.current.scrollTop), kt(
2750
- /** @param {any} [prev] @returns {any} */
2751
- (p) => p.columnId === f ? { columnId: null, anchorEl: null } : { columnId: f, anchorEl: r.currentTarget }
2752
- ), V && V(f);
2753
- }, _r = () => kt({ columnId: null, anchorEl: null });
2754
- e.useEffect(() => {
2755
- pe.current && Ve.columnId && (pe.current.scrollTop = Ct.current);
2756
- }, [Me, Ve.columnId]), e.useEffect(() => {
2757
- if (oe.length === 0) {
2758
- ke !== null && Ce(null), se !== null && ge(null);
2759
- return;
2760
- }
2761
- oe.some(
2762
- /** @param {any} [config] @returns {any} */
2763
- (f) => f.field === ke
2764
- ) || Ce(oe[oe.length - 1].field), se && !oe.some(
2765
- /** @param {any} [config] @returns {any} */
2766
- (f) => f.field === se
2767
- ) && ge(null);
2768
- }, [ke, oe, se]);
2769
- const pt = e.useMemo(
2770
- () => E.findIndex(
2771
- /** @param {any} [config] @returns {any} */
2772
- (r) => r && r.agg === "formula" && r.field === se
2773
- ),
2774
- [se, E]
2775
- ), dt = pt >= 0 ? E[pt] : null, It = e.useCallback((r) => {
2776
- Ce(r), ge(r);
2777
- }, []), Ie = e.useCallback((r) => {
2778
- const f = E[r] && E[r].agg === "formula" ? E[r].field : null;
2779
- if (d(
2780
- /** @param {any} [prev] @returns {any} */
2781
- (p) => p.filter(
2782
- /** @param {any} [_] @param {any} [index] @returns {any} */
2783
- (b, S) => S !== r
2784
- )
2785
- ), f && f === ke) {
2786
- const p = oe.find(
2787
- /** @param {any} [config] @returns {any} */
2788
- (b) => b.field !== f
2789
- );
2790
- Ce(p ? p.field : null);
2791
- }
2792
- f && f === se && ge(null);
2793
- }, [ke, oe, se, d, E]), $e = yr === "report", Lt = Math.max(rt || 288, $e ? 380 : 0), Pt = (r, f) => {
2794
- if (r <= 8) return null;
2795
- const p = it.trim().length > 0;
2796
- return /* @__PURE__ */ e.createElement("div", { style: {
2797
- display: "flex",
2798
- alignItems: "center",
2799
- gap: "6px",
2800
- margin: "0 2px 8px",
2801
- padding: "5px 8px",
2802
- border: `1px solid ${c.border}`,
2803
- borderRadius: c.radiusSm || "8px",
2804
- background: c.headerSubtleBg || c.surfaceInset || c.background
2805
- } }, /* @__PURE__ */ e.createElement(z.Search, { style: { flexShrink: 0, color: c.textSec } }), /* @__PURE__ */ e.createElement(
2806
- "input",
2807
- {
2808
- type: "search",
2809
- "aria-label": "Search available fields",
2810
- placeholder: `Search ${r} fields...`,
2811
- value: it,
2812
- onChange: (b) => wt(b.target.value),
2813
- style: {
2814
- flex: 1,
2815
- minWidth: 0,
2816
- border: "none",
2817
- outline: "none",
2818
- background: "transparent",
2819
- color: c.text,
2820
- fontSize: "12px"
2821
- }
2822
- }
2823
- ), p && /* @__PURE__ */ e.createElement(
2824
- "button",
2825
- {
2826
- type: "button",
2827
- "aria-label": "Clear available field search",
2828
- title: "Clear search",
2829
- onClick: () => wt(""),
2830
- style: {
2831
- border: "none",
2832
- background: "transparent",
2833
- color: c.textSec,
2834
- cursor: "pointer",
2835
- padding: 0,
2836
- display: "flex",
2837
- alignItems: "center"
2838
- }
2839
- },
2840
- /* @__PURE__ */ e.createElement(z.Close, null)
2841
- ), p && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec, whiteSpace: "nowrap" } }, f, "/", r));
2842
- };
2843
- return /* @__PURE__ */ e.createElement("div", { style: { position: "relative", display: "flex", flexShrink: 0 } }, /* @__PURE__ */ e.createElement("div", { ref: pe, style: { ...Y.sidebar, width: `${Lt}px`, minWidth: `${Lt}px` }, role: "complementary", "aria-label": "Tool Panel", onDragOver: Rr, onDragLeave: At, onDrop: At }, /* @__PURE__ */ e.createElement(
2844
- "div",
2845
- {
2846
- id: "pivot-sidebar-keyboard-dnd-help",
2847
- style: { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 }
2848
- },
2849
- "Press Enter or Space on a field to pick it up. Focus a target field or zone and press Enter or Space to drop it. Press Escape to cancel."
2850
- ), $e ? /* @__PURE__ */ e.createElement("div", { style: { display: "flex", borderBottom: `1px solid ${c.border}`, marginBottom: "16px" } }, [
2851
- { id: "report", label: "Builder", icon: /* @__PURE__ */ e.createElement(z.Report, null) },
2852
- { id: "fields", label: "Fields", icon: /* @__PURE__ */ e.createElement(z.Sigma, null) },
2853
- { id: "columns", label: "Columns", icon: /* @__PURE__ */ e.createElement(z.Columns, null) }
2854
- ].map((r) => /* @__PURE__ */ e.createElement(
2855
- "div",
2856
- {
2857
- key: r.id,
2858
- onClick: () => Cr(r.id),
2859
- style: {
2860
- padding: "8px 14px",
2861
- cursor: "pointer",
2862
- borderBottom: we === r.id ? `2px solid ${c.primary}` : "2px solid transparent",
2863
- fontWeight: we === r.id ? 600 : 400,
2864
- color: we === r.id ? c.primary : c.textSec,
2865
- display: "flex",
2866
- alignItems: "center",
2867
- gap: "5px",
2868
- fontSize: "13px"
2869
- }
2870
- },
2871
- r.icon,
2872
- r.label
2873
- ))) : /* @__PURE__ */ e.createElement("div", { style: { display: "flex", borderBottom: `1px solid ${c.border}`, marginBottom: "16px" } }, /* @__PURE__ */ e.createElement(
2874
- "div",
2875
- {
2876
- onClick: () => s("fields"),
2877
- style: {
2878
- padding: "8px 16px",
2879
- cursor: "pointer",
2880
- borderBottom: n === "fields" ? `2px solid ${c.primary}` : "none",
2881
- fontWeight: n === "fields" ? 600 : 400,
2882
- color: n === "fields" ? c.primary : c.textSec
2883
- }
2884
- },
2885
- "Fields"
2886
- ), /* @__PURE__ */ e.createElement(
2887
- "div",
2888
- {
2889
- onClick: () => s("filters"),
2890
- style: {
2891
- padding: "8px 16px",
2892
- cursor: "pointer",
2893
- borderBottom: n === "filters" ? `2px solid ${c.primary}` : "none",
2894
- fontWeight: n === "filters" ? 600 : 400,
2895
- color: n === "filters" ? c.primary : c.textSec,
2896
- display: "flex",
2897
- alignItems: "center",
2898
- gap: "6px"
2899
- }
2900
- },
2901
- "Filters",
2902
- Object.keys(ae).length > 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "6px", height: "6px", borderRadius: "50%", background: "#d32f2f" } })
2903
- ), /* @__PURE__ */ e.createElement(
2904
- "div",
2905
- {
2906
- onClick: () => s("columns"),
2907
- style: {
2908
- padding: "8px 16px",
2909
- cursor: "pointer",
2910
- borderBottom: n === "columns" ? `2px solid ${c.primary}` : "none",
2911
- fontWeight: n === "columns" ? 600 : 400,
2912
- color: n === "columns" ? c.primary : c.textSec
2913
- }
2914
- },
2915
- "Columns"
2916
- )), $e && we === "report" ? /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", padding: "0 12px 12px" } }, /* @__PURE__ */ e.createElement(
2917
- pn,
2918
- {
2919
- reportDef: br,
2920
- setReportDef: Er,
2921
- availableFields: D,
2922
- customDimensions: _e,
2923
- theme: c,
2924
- styles: Y,
2925
- data: Se,
2926
- valConfigs: E,
2927
- colFields: g,
2928
- setColFields: u,
2929
- setValConfigs: d,
2930
- savedReports: vr,
2931
- setSavedReports: Sr,
2932
- activeReportId: hr,
2933
- setActiveReportId: kr,
2934
- showNotification: w,
2935
- requestedSelection: gr,
2936
- showReportConfigColumn: mr,
2937
- setShowReportConfigColumn: xr
2938
- }
2939
- )) : $e && we === "fields" ? /* @__PURE__ */ e.createElement("div", { style: { padding: "0 4px" } }, /* @__PURE__ */ e.createElement(
2940
- Kt,
2941
- {
2942
- availableFields: D,
2943
- customDimensions: _e,
2944
- setCustomDimensions: ht,
2945
- data: Se,
2946
- theme: c,
2947
- showNotification: w,
2948
- getFieldLabel: X,
2949
- onDeleteField: Dt
2950
- }
2951
- ), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: c.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px", padding: "0 2px" } }, /* @__PURE__ */ e.createElement(z.Database, { style: { verticalAlign: "middle", marginRight: "4px" } }), "Available Fields — click to add"), Pt(J.length, ut.length), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginBottom: "14px" } }, ut.map(
2952
- /** @param {any} [f] @returns {any} */
2953
- (r) => {
2954
- const f = E.some(
2955
- /** @param {any} [c] @returns {any} */
2956
- (p) => p && p.field === r && p.agg !== "formula"
2957
- );
2958
- return /* @__PURE__ */ e.createElement(
2959
- "div",
2960
- {
2961
- key: r,
2962
- onClick: () => {
2963
- f || d(
2964
- /** @param {any} [prev] @returns {any} */
2965
- (p) => [...p, { field: r, agg: "sum", label: X(r) }]
2966
- );
2967
- },
2968
- style: {
2969
- padding: "3px 9px",
2970
- fontSize: "11px",
2971
- lineHeight: 1.4,
2972
- fontWeight: 500,
2973
- borderRadius: "999px",
2974
- border: `1px solid ${f || c.isDark ? c.border : "#D7DDEA"}`,
2975
- background: f ? c.select || c.headerBg : c.isDark ? c.background : "#ffffff",
2976
- color: f ? c.primary : c.text,
2977
- cursor: f ? "default" : "pointer",
2978
- opacity: f ? 0.6 : 1,
2979
- userSelect: "none"
2980
- },
2981
- title: f ? `${X(r)} already in values` : `Add ${X(r)} to values`
2982
- },
2983
- X(r),
2984
- f ? " ✓" : ""
2985
- );
2986
- }
2987
- ), J.length > 8 && ut.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "100%", padding: "8px 2px", fontSize: "11px", color: c.textSec } }, "No fields match the current search.")), /* @__PURE__ */ e.createElement("div", { style: { borderTop: `1px solid ${c.border}`, paddingTop: "10px", marginBottom: "8px" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "0 2px 8px 2px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: Bt, style: { border: `1px solid ${c.primary}66`, background: `${c.primary}12`, color: c.primary, borderRadius: "999px", cursor: "pointer", padding: "4px 10px", fontSize: "11px", fontWeight: 700 } }, "+ Add Formula"), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, Ae, " value", Ae === 1 ? "" : "s", " · ", me, " formula", me === 1 ? "" : "s")), /* @__PURE__ */ e.createElement(
2988
- Qt,
2989
- {
2990
- measureAxis: $,
2991
- setMeasureAxis: i,
2992
- theme: c,
2993
- valueSelectStyle: ue,
2994
- regularValueCount: Ae
2995
- }
2996
- )), E.map(
2997
- /** @param {any} [item] @param {any} [idx] @returns {any} */
2998
- (r, f) => {
2999
- const p = r && r.agg === "formula";
3000
- if (!r) return null;
3001
- const b = wr === f;
3002
- return /* @__PURE__ */ e.createElement(
3003
- "div",
3004
- {
3005
- key: r.field || f,
3006
- draggable: !0,
3007
- onDragStart: () => {
3008
- Ze.current = f;
3009
- },
3010
- onDragOver: (S) => {
3011
- S.preventDefault(), Ye(f);
3012
- },
3013
- onDragLeave: () => Ye(null),
3014
- onDrop: (S) => {
3015
- S.preventDefault();
3016
- const I = Ze.current;
3017
- Ye(null), Ze.current = null, !(I === null || I === f) && d(
3018
- /** @param {any} [prev] @returns {any} */
3019
- (q) => {
3020
- const C = [...q], [j] = C.splice(I, 1);
3021
- return C.splice(f, 0, j), C;
3022
- }
3023
- );
3024
- },
3025
- onDragEnd: () => {
3026
- Ze.current = null, Ye(null);
3027
- },
3028
- style: { marginBottom: "6px", borderTop: b ? `2px solid ${c.primary}` : "2px solid transparent", cursor: "grab" }
3029
- },
3030
- p ? /* @__PURE__ */ e.createElement(Jt, { item: r, idx: f, selected: r.field === se, onSelect: It, onRemove: Ie, setValConfigs: d, theme: c, styles: Y, dropLine: null, zoneId: "vals", valueSelectStyle: ue, colFields: g, fixedSparklineValueKeySet: st, showNotification: w, serverError: he && he[r.field] || null }) : /* @__PURE__ */ e.createElement("div", { style: { ...Y.chip, flexWrap: "wrap", alignItems: "flex-start" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(z.DragIndicator, { style: { flexShrink: 0, opacity: 0.4 } }), /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 500, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, X(r.field))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "4px", marginLeft: "8px", flexWrap: "nowrap", flexShrink: 0 } }, /* @__PURE__ */ e.createElement("select", { value: r.agg, onChange: (S) => Wt(f, S.target.value), style: { ...ue, width: "74px" } }, /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"), /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Avg"), /* @__PURE__ */ e.createElement("option", { value: "count" }, "Cnt"), /* @__PURE__ */ e.createElement("option", { value: "min" }, "Min"), /* @__PURE__ */ e.createElement("option", { value: "max" }, "Max"), /* @__PURE__ */ e.createElement("option", { value: "weighted_avg" }, "WAvg")), /* @__PURE__ */ e.createElement("span", { onClick: () => Ie(f), style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" } }, /* @__PURE__ */ e.createElement(z.Close, null))))
3031
- );
3032
- }
3033
- ), E.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { opacity: 0.5, fontSize: "11px", padding: "12px", textAlign: "center" } }, "No value fields. Click a field above or add a formula.")) : !$e && n === "filters" ? /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", display: "flex", flexDirection: "column", padding: "8px" } }, /* @__PURE__ */ e.createElement("div", { style: { marginBottom: "10px", display: "flex", alignItems: "center", background: c.background, borderRadius: "6px", padding: "4px 8px", border: `1px solid ${c.border}` } }, /* @__PURE__ */ e.createElement(z.Search, null), /* @__PURE__ */ e.createElement(
3034
- "input",
3035
- {
3036
- placeholder: "Search columns...",
3037
- value: k,
3038
- onChange: (r) => P(r.target.value),
3039
- style: { border: "none", background: "transparent", marginLeft: "10px", outline: "none", width: "100%", color: c.text, fontSize: "13px" }
3040
- }
3041
- )), (() => {
3042
- const p = D.map(
3043
- /** @param {any} [field] @returns {any} */
3044
- (b) => {
3045
- const S = y.getColumn(b);
3046
- return S || { id: b, header: X(b), columnDef: { header: X(b) } };
3047
- }
3048
- ).filter(
3049
- /** @param {any} [col] @returns {any} */
3050
- (b) => {
3051
- const S = b.columnDef && typeof b.columnDef.header == "string" ? b.columnDef.header : typeof b.header == "string" ? b.header : b.id;
3052
- return String(S).toLowerCase().includes(k.toLowerCase()) || b.id.toLowerCase().includes(k.toLowerCase());
3053
- }
3054
- );
3055
- return /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, p.map(
3056
- /** @param {any} [col] @returns {any} */
3057
- (b) => /* @__PURE__ */ e.createElement(
3058
- Jr,
3059
- {
3060
- key: b.id,
3061
- column: b,
3062
- theme: c,
3063
- styles: Y,
3064
- onFilter: (
3065
- /** @param {any} [val] @returns {any} */
3066
- ((S) => U(b.id, S))
3067
- ),
3068
- currentFilter: ae[b.id],
3069
- options: Tt(b.id),
3070
- optionMeta: Oe && Oe[b.id],
3071
- onSearchOptions: je ? (
3072
- /** @param {any} [search] @returns {any} */
3073
- ((S) => V && V(b.id, { search: S, offset: 0 }))
3074
- ) : void 0,
3075
- onLoadMoreOptions: je ? (
3076
- /** @param {any} [search] @param {any} [offset] @returns {any} */
3077
- ((S, I) => V && V(b.id, { search: S, offset: I }))
3078
- ) : void 0,
3079
- onOpen: V
3080
- }
3081
- )
3082
- ));
3083
- })()) : ($e ? we !== "columns" : n !== "columns") ? /* @__PURE__ */ e.createElement(e.Fragment, null, n === "fields" && /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
3084
- Kt,
3085
- {
3086
- availableFields: D,
3087
- customDimensions: _e,
3088
- setCustomDimensions: ht,
3089
- data: Se,
3090
- theme: c,
3091
- showNotification: w,
3092
- getFieldLabel: X,
3093
- onDeleteField: Dt
3094
- }
3095
- ), /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitleSm }, /* @__PURE__ */ e.createElement(z.Database, null), " Available Fields"), Pt(De.length, ct.length), /* @__PURE__ */ e.createElement(
3096
- qt,
3097
- {
3098
- panelId: "availableFields",
3099
- panelLabel: "Available Fields",
3100
- size: Ue && Ue.availableFields,
3101
- onSizeChange: zt,
3102
- theme: c,
3103
- outerStyle: _t,
3104
- contentStyle: {
3105
- display: "flex",
3106
- flexWrap: "wrap",
3107
- gap: "4px",
3108
- alignContent: "flex-start",
3109
- padding: "2px 12px 12px 2px"
3110
- }
3111
- },
3112
- ct.map(
3113
- /** @param {any} [f] @returns {any} */
3114
- (r) => {
3115
- const f = Te && r === de, p = f ? "Measure Names" : X(r), b = f ? "measureAxis" : "pool";
3116
- return /* @__PURE__ */ e.createElement(
3117
- "div",
3118
- {
3119
- key: f ? `__measure_axis__${r}` : r,
3120
- draggable: !0,
3121
- "data-sidebar-field-chip": f ? "measure-axis-label" : "available",
3122
- role: "button",
3123
- tabIndex: 0,
3124
- "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3125
- "aria-grabbed": G && G.zone === b && G.field === r ? "true" : "false",
3126
- "aria-label": `Move ${p}`,
3127
- onDragStart: (S) => H(S, r, b),
3128
- onDragEnd: F,
3129
- onKeyDown: (S) => Ft(S, r, b, -1, p),
3130
- title: f ? "Drag to Rows or Columns to show measure names" : `Move ${X(r)}`,
3131
- style: {
3132
- padding: "4px 8px",
3133
- fontSize: "11px",
3134
- lineHeight: 1.2,
3135
- fontWeight: f ? 700 : 500,
3136
- fontFamily: "'Inter', ui-sans-serif, system-ui, sans-serif",
3137
- borderRadius: c.radiusSm || c.radius || "10px",
3138
- border: f ? `1px dashed ${c.primary}` : `1px solid ${c.isDark ? c.border : "#D7DDEA"}`,
3139
- background: f ? `${c.primary}12` : c.isDark ? c.background : c.surfaceInset || "#ffffff",
3140
- color: f ? c.primary : c.isDark ? c.text : "#334155",
3141
- display: "inline-flex",
3142
- alignItems: "center",
3143
- gap: "4px",
3144
- boxShadow: c.isDark ? "none" : c.shadowInset || "0 1px 2px rgba(0,0,0,0.04)",
3145
- cursor: "grab",
3146
- userSelect: "none",
3147
- minHeight: "24px"
3148
- }
3149
- },
3150
- f && /* @__PURE__ */ e.createElement(z.Sigma, null),
3151
- p
3152
- );
3153
- }
3154
- ),
3155
- De.length > 8 && ct.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "100%", padding: "8px 2px", fontSize: "11px", color: c.textSec } }, "No fields match the current search.")
3156
- )), Dr.map(
3157
- /** @param {any} [zone] @returns {any} */
3158
- (r) => {
3159
- const f = Be[r.id] || [];
3160
- return /* @__PURE__ */ e.createElement("div", { key: r.id, style: { marginBottom: "20px" } }, /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitle }, r.icon, r.label), r.id === "vals" && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "0 4px 8px 4px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
3161
- "button",
3162
- {
3163
- type: "button",
3164
- onClick: Bt,
3165
- style: {
3166
- border: `1px solid ${c.primary}66`,
3167
- background: `${c.primary}12`,
3168
- color: c.primary,
3169
- borderRadius: "999px",
3170
- cursor: "pointer",
3171
- padding: "4px 10px",
3172
- fontSize: "11px",
3173
- fontWeight: 700
3174
- }
3175
- },
3176
- "+ Add Formula"
3177
- ), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, Ae, " value measure", Ae === 1 ? "" : "s", " available"), me > 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, me, " formula", me === 1 ? "" : "s"), /* @__PURE__ */ e.createElement(
3178
- Qt,
3179
- {
3180
- measureAxis: $,
3181
- setMeasureAxis: i,
3182
- theme: c,
3183
- valueSelectStyle: ue,
3184
- regularValueCount: Ae
3185
- }
3186
- )), r.id === "rows" && a.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", padding: "0 4px 6px 4px" } }, /* @__PURE__ */ e.createElement(
3187
- "button",
3188
- {
3189
- title: "Expand all hierarchy levels",
3190
- onClick: () => ee(!0),
3191
- style: { flex: 1, border: `1px solid ${c.primary}`, background: c.select, cursor: "pointer", padding: "3px 6px", fontSize: "11px", color: c.primary, borderRadius: "4px", fontWeight: 600 }
3192
- },
3193
- "+ Expand All"
3194
- ), /* @__PURE__ */ e.createElement(
3195
- "button",
3196
- {
3197
- title: "Collapse all rows",
3198
- onClick: () => ee(!1),
3199
- style: { flex: 1, border: `1px solid ${c.border}`, background: c.background, cursor: "pointer", padding: "3px 6px", fontSize: "11px", color: c.textSec, borderRadius: "4px" }
3200
- },
3201
- "- Collapse All"
3202
- )), /* @__PURE__ */ e.createElement(
3203
- qt,
3204
- {
3205
- panelId: r.id,
3206
- panelLabel: r.label,
3207
- size: Ue && Ue[r.id],
3208
- onSizeChange: zt,
3209
- theme: c,
3210
- outerStyle: _t,
3211
- contentStyle: { padding: `${Mt} 12px 12px ${Mt}` }
3212
- },
3213
- /* @__PURE__ */ e.createElement(
3214
- "div",
3215
- {
3216
- "data-sidebar-drop-zone": r.id,
3217
- role: "group",
3218
- tabIndex: 0,
3219
- "aria-label": `${r.label} drop zone`,
3220
- "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3221
- onKeyDown: (p) => Ar(p, r.id),
3222
- onDragOver: (p) => {
3223
- p.target === p.currentTarget ? K(p, r.id, f.length) : (p.preventDefault(), p.dataTransfer && (p.dataTransfer.dropEffect = "move"));
3224
- },
3225
- onDrop: (p) => x(p, r.id)
3226
- },
3227
- f.map(
3228
- /** @param {any} [item] @param {any} [idx] @returns {any} */
3229
- (p, b) => {
3230
- const S = r.id === "vals" ? p.field : p, I = r.id === "vals" ? p.agg === "formula" ? p.label || "Formula" : X(p.field) : X(p), q = (r.id === "rows" || r.id === "cols") && S === de && Rt.placement !== "none";
3231
- return /* @__PURE__ */ e.createElement(
3232
- "div",
3233
- {
3234
- key: b,
3235
- draggable: !0,
3236
- "data-sidebar-field-chip": "zone",
3237
- role: "button",
3238
- tabIndex: 0,
3239
- "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3240
- "aria-grabbed": G && G.zone === r.id && G.idx === b ? "true" : "false",
3241
- "aria-label": `Move ${I}`,
3242
- onKeyDown: (C) => Ft(C, p, r.id, b, I),
3243
- onDragStart: (C) => H(C, p, r.id, b),
3244
- onDragOver: (C) => K(C, r.id, b),
3245
- onDragEnd: F
3246
- },
3247
- r.id === "vals" && p.agg === "formula" ? /* @__PURE__ */ e.createElement(
3248
- Jt,
3249
- {
3250
- item: p,
3251
- idx: b,
3252
- selected: p.field === ke,
3253
- onSelect: It,
3254
- onRemove: Ie,
3255
- setValConfigs: d,
3256
- theme: c,
3257
- styles: Y,
3258
- dropLine: M,
3259
- zoneId: r.id,
3260
- valueSelectStyle: ue,
3261
- colFields: g,
3262
- fixedSparklineValueKeySet: st,
3263
- showNotification: w,
3264
- serverError: he && he[p.field] || null
3265
- }
3266
- ) : /* @__PURE__ */ e.createElement("div", { style: {
3267
- ...Y.chip,
3268
- ...r.id === "vals" ? { flexWrap: "wrap", alignItems: "flex-start" } : {}
3269
- } }, M && M.zone === r.id && M.idx === b && /* @__PURE__ */ e.createElement("div", { style: { ...Y.dropLine, top: -2 } }), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(z.DragIndicator, null), /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 500, display: "block", minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, I)), r.id === "vals" && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "4px", marginLeft: "8px", flexWrap: "nowrap", flexShrink: 0 } }, /* @__PURE__ */ e.createElement("select", { value: p.agg, onChange: (C) => Wt(b, C.target.value), style: { ...ue, width: "74px" }, title: "Aggregation" }, /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"), /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Avg"), /* @__PURE__ */ e.createElement("option", { value: "count" }, "Cnt"), /* @__PURE__ */ e.createElement("option", { value: "min" }, "Min"), /* @__PURE__ */ e.createElement("option", { value: "max" }, "Max"), /* @__PURE__ */ e.createElement("option", { value: "weighted_avg" }, "WAvg"), /* @__PURE__ */ e.createElement("option", { value: "array_agg" }, "Series")), Ht(p.agg) && /* @__PURE__ */ e.createElement("select", { value: p.weightField || "", onChange: (C) => Fr(b, C.target.value), style: { ...ue, width: "92px" }, title: "Weight field" }, /* @__PURE__ */ e.createElement("option", { value: "", disabled: !0 }, "Weight"), J.map(
3270
- /** @param {any} [fieldName] @returns {any} */
3271
- (C) => /* @__PURE__ */ e.createElement("option", { key: C, value: C }, X(C))
3272
- )), /* @__PURE__ */ e.createElement("select", { value: p.windowFn || "none", onChange: (C) => zr(b, C.target.value), style: { ...ue, width: "56px" } }, /* @__PURE__ */ e.createElement("option", { value: "none" }, "Norm"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_row" }, "%Row"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_col" }, "%Col"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_grand_total" }, "%Tot"))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", marginLeft: "auto", alignItems: "center" } }, r.id === "filter" && /* @__PURE__ */ e.createElement("div", { onClick: (C) => Mr(C, S), style: { cursor: "pointer", display: "flex", alignItems: "center", padding: "2px", borderRadius: "4px" } }, /* @__PURE__ */ e.createElement(z.Filter, null)), /* @__PURE__ */ e.createElement("span", { onClick: () => {
3273
- if (q && typeof i == "function") {
3274
- i(
3275
- /** @param {any} [previous] @returns {any} */
3276
- (C) => ({
3277
- ...Pe(C),
3278
- placement: "none"
3279
- })
3280
- );
3281
- return;
3282
- }
3283
- if (r.id === "filter") {
3284
- const C = { ...ae };
3285
- delete C[S], at(C);
3286
- }
3287
- r.id === "rows" && l(
3288
- /** @param {any} [p] @returns {any} */
3289
- (C) => C.filter(
3290
- /** @param {any} [x] @returns {any} */
3291
- (j) => j !== S
3292
- )
3293
- ), r.id === "cols" && u(
3294
- /** @param {any} [p] @returns {any} */
3295
- (C) => C.filter(
3296
- /** @param {any} [x] @returns {any} */
3297
- (j) => j !== S
3298
- )
3299
- ), r.id === "vals" && Ie(b);
3300
- }, style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" } }, /* @__PURE__ */ e.createElement(z.Close, null))), r.id === "filter" && Ve.columnId === S && /* @__PURE__ */ e.createElement(
3301
- Zr,
3302
- {
3303
- column: { header: I, id: S },
3304
- anchorEl: Ve.anchorEl,
3305
- onClose: _r,
3306
- onFilter: (
3307
- /** @param {any} [filterValue] @returns {any} */
3308
- ((C) => U(S, C))
3309
- ),
3310
- currentFilter: ae[S],
3311
- options: Tt(S),
3312
- optionMeta: Oe && Oe[S],
3313
- onSearchOptions: je ? (
3314
- /** @param {any} [search] @returns {any} */
3315
- ((C) => V && V(S, { search: C, offset: 0 }))
3316
- ) : void 0,
3317
- onLoadMoreOptions: je ? (
3318
- /** @param {any} [search] @param {any} [offset] @returns {any} */
3319
- ((C, j) => V && V(S, { search: C, offset: j }))
3320
- ) : void 0,
3321
- theme: c
3322
- }
3323
- ), r.id === "vals" && /* @__PURE__ */ e.createElement(
3324
- dr,
3325
- {
3326
- item: p,
3327
- idx: b,
3328
- setValConfigs: d,
3329
- theme: c,
3330
- valueSelectStyle: ue,
3331
- colFields: g,
3332
- fixedSparklineValueKeySet: st,
3333
- showNotification: w
3334
- }
3335
- ), M && M.zone === r.id && M.idx === b + 1 && /* @__PURE__ */ e.createElement("div", { style: { ...Y.dropLine, bottom: -2 } })),
3336
- r.id === "filter" && ae[S] && ae[S].conditions && /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: c.primary, padding: "0 8px 4px 8px", marginTop: "-4px" } }, ae[S].conditions.map(
3337
- /** @param {any} [c] @returns {any} */
3338
- (C) => `${C.type}: ${C.value}${C.caseSensitive ? " (Match Case)" : ""}`
3339
- ).join(` ${ae[S].operator} `))
3340
- );
3341
- }
3342
- ),
3343
- f.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { opacity: 0.5, fontSize: "11px", padding: "8px", textAlign: "center", pointerEvents: "none" } }, "Drag fields here"),
3344
- /* @__PURE__ */ e.createElement("div", { style: { height: 20 }, onDragOver: (p) => K(p, r.id, f.length), onDrop: (p) => x(p, r.id) })
3345
- )
3346
- ));
3347
- }
3348
- )) : /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "16px", height: "100%", overflow: "hidden" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "10px", padding: "8px", background: c.headerBg, borderRadius: "8px", boxShadow: "0 1px 3px rgba(0,0,0,0.08)" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", background: c.background, borderRadius: "6px", padding: "8px 12px", border: `2px solid ${c.border}`, transition: "border-color 0.2s" } }, /* @__PURE__ */ e.createElement(z.Search, null), /* @__PURE__ */ e.createElement(
3349
- "input",
3350
- {
3351
- placeholder: "Search columns...",
3352
- value: k,
3353
- onChange: (r) => P(r.target.value),
3354
- style: {
3355
- border: "none",
3356
- background: "transparent",
3357
- marginLeft: "10px",
3358
- outline: "none",
3359
- width: "100%",
3360
- color: c.text,
3361
- fontSize: "13px",
3362
- fontWeight: 500
3363
- }
3364
- }
3365
- ), k && /* @__PURE__ */ e.createElement(
3366
- "span",
3367
- {
3368
- onClick: () => P(""),
3369
- style: {
3370
- cursor: "pointer",
3371
- display: "flex",
3372
- padding: "4px",
3373
- borderRadius: "4px",
3374
- background: c.hover,
3375
- transition: "background 0.2s"
3376
- },
3377
- onMouseEnter: (r) => r.currentTarget.style.background = c.select,
3378
- onMouseLeave: (r) => r.currentTarget.style.background = c.hover
3379
- },
3380
- /* @__PURE__ */ e.createElement(z.Close, null)
3381
- )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, [
3382
- { value: "all", label: "All", icon: "📊" },
3383
- { value: "number", label: "Numbers", icon: "🔢" },
3384
- { value: "string", label: "Text", icon: "📝" },
3385
- { value: "date", label: "Dates", icon: "📅" }
3386
- ].map((r) => /* @__PURE__ */ e.createElement(
3387
- "button",
3388
- {
3389
- key: r.value,
3390
- onClick: () => A(r.value),
3391
- style: {
3392
- padding: "6px 12px",
3393
- borderRadius: "6px",
3394
- border: "none",
3395
- background: o === r.value ? c.primary : c.background,
3396
- color: o === r.value ? "#fff" : c.text,
3397
- cursor: "pointer",
3398
- fontSize: "11px",
3399
- fontWeight: 600,
3400
- display: "flex",
3401
- alignItems: "center",
3402
- gap: "4px",
3403
- transition: "all 0.2s",
3404
- boxShadow: o === r.value ? "0 2px 4px rgba(0,0,0,0.1)" : "none"
3405
- },
3406
- onMouseEnter: (f) => {
3407
- o !== r.value && (f.currentTarget.style.background = c.hover);
3408
- },
3409
- onMouseLeave: (f) => {
3410
- o !== r.value && (f.currentTarget.style.background = c.background);
3411
- }
3412
- },
3413
- /* @__PURE__ */ e.createElement("span", null, r.icon),
3414
- /* @__PURE__ */ e.createElement("span", null, r.label)
3415
- )))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", padding: "0 8px" } }, /* @__PURE__ */ e.createElement(
3416
- "button",
3417
- {
3418
- onClick: () => y.toggleAllColumnsVisible(!0),
3419
- style: {
3420
- ...Y.btn,
3421
- padding: "8px 12px",
3422
- fontSize: "11px",
3423
- flex: 1,
3424
- justifyContent: "center",
3425
- background: c.background,
3426
- fontWeight: 600,
3427
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3428
- transition: "all 0.2s"
3429
- },
3430
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3431
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3432
- },
3433
- /* @__PURE__ */ e.createElement(z.Visibility, { style: { fontSize: "14px" } }),
3434
- /* @__PURE__ */ e.createElement("span", null, "Show All")
3435
- ), /* @__PURE__ */ e.createElement(
3436
- "button",
3437
- {
3438
- onClick: () => y.toggleAllColumnsVisible(!1),
3439
- style: {
3440
- ...Y.btn,
3441
- padding: "8px 12px",
3442
- fontSize: "11px",
3443
- flex: 1,
3444
- justifyContent: "center",
3445
- background: c.background,
3446
- fontWeight: 600,
3447
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3448
- transition: "all 0.2s"
3449
- },
3450
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3451
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3452
- },
3453
- /* @__PURE__ */ e.createElement(z.VisibilityOff, { style: { fontSize: "14px" } }),
3454
- /* @__PURE__ */ e.createElement("span", null, "Hide All")
3455
- ), /* @__PURE__ */ e.createElement(
3456
- "button",
3457
- {
3458
- onClick: () => te(!1),
3459
- style: {
3460
- ...Y.btn,
3461
- padding: "8px 12px",
3462
- fontSize: "11px",
3463
- flex: 1,
3464
- justifyContent: "center",
3465
- background: c.background,
3466
- fontWeight: 600,
3467
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3468
- transition: "all 0.2s"
3469
- },
3470
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3471
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3472
- },
3473
- /* @__PURE__ */ e.createElement(z.Unpin, { style: { fontSize: "14px" } }),
3474
- /* @__PURE__ */ e.createElement("span", null, "Unpin All")
3475
- )), R.size > 0 && /* @__PURE__ */ e.createElement("div", { style: {
3476
- display: "flex",
3477
- flexDirection: "column",
3478
- gap: "8px",
3479
- background: `linear-gradient(135deg, ${c.select}ee, ${c.select}dd)`,
3480
- padding: "12px",
3481
- borderRadius: "8px",
3482
- border: `2px solid ${c.primary}66`,
3483
- boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3484
- margin: "0 8px"
3485
- } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } }, /* @__PURE__ */ e.createElement("span", { style: {
3486
- fontSize: "12px",
3487
- fontWeight: 700,
3488
- padding: "4px 10px",
3489
- color: c.primary,
3490
- background: c.background,
3491
- borderRadius: "6px",
3492
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)"
3493
- } }, R.size, " Column", R.size > 1 ? "s" : "", " Selected"), /* @__PURE__ */ e.createElement(
3494
- "button",
3495
- {
3496
- onClick: () => B(/* @__PURE__ */ new Set()),
3497
- style: {
3498
- border: "none",
3499
- background: c.background,
3500
- cursor: "pointer",
3501
- display: "flex",
3502
- color: c.textSec,
3503
- padding: "4px",
3504
- borderRadius: "4px",
3505
- transition: "all 0.2s"
3506
- },
3507
- onMouseEnter: (r) => r.currentTarget.style.background = c.hover,
3508
- onMouseLeave: (r) => r.currentTarget.style.background = c.background
3509
- },
3510
- /* @__PURE__ */ e.createElement(z.Close, null)
3511
- )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
3512
- "button",
3513
- {
3514
- onClick: () => {
3515
- Array.from(R).forEach((r) => Z(r, "left")), B(/* @__PURE__ */ new Set());
3516
- },
3517
- style: {
3518
- ...Y.btn,
3519
- padding: "6px 12px",
3520
- fontSize: "11px",
3521
- background: c.background,
3522
- flex: 1,
3523
- justifyContent: "center",
3524
- fontWeight: 600,
3525
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3526
- transition: "all 0.2s"
3527
- },
3528
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3529
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3530
- },
3531
- /* @__PURE__ */ e.createElement(z.PinLeft, null),
3532
- /* @__PURE__ */ e.createElement("span", null, "Pin Left")
3533
- ), /* @__PURE__ */ e.createElement(
3534
- "button",
3535
- {
3536
- onClick: () => {
3537
- Array.from(R).forEach((r) => Z(r, !1)), B(/* @__PURE__ */ new Set());
3538
- },
3539
- style: {
3540
- ...Y.btn,
3541
- padding: "6px 12px",
3542
- fontSize: "11px",
3543
- background: c.background,
3544
- flex: 1,
3545
- justifyContent: "center",
3546
- fontWeight: 600,
3547
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3548
- transition: "all 0.2s"
3549
- },
3550
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3551
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3552
- },
3553
- /* @__PURE__ */ e.createElement(z.Unpin, null),
3554
- /* @__PURE__ */ e.createElement("span", null, "Unpin")
3555
- ), /* @__PURE__ */ e.createElement(
3556
- "button",
3557
- {
3558
- onClick: () => {
3559
- Array.from(R).forEach((r) => Z(r, "right")), B(/* @__PURE__ */ new Set());
3560
- },
3561
- style: {
3562
- ...Y.btn,
3563
- padding: "6px 12px",
3564
- fontSize: "11px",
3565
- background: c.background,
3566
- flex: 1,
3567
- justifyContent: "center",
3568
- fontWeight: 600,
3569
- boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3570
- transition: "all 0.2s"
3571
- },
3572
- onMouseEnter: (r) => r.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3573
- onMouseLeave: (r) => r.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3574
- },
3575
- /* @__PURE__ */ e.createElement(z.PinRight, null),
3576
- /* @__PURE__ */ e.createElement("span", null, "Pin Right")
3577
- ))), /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", display: "flex", flexDirection: "column" } }, (() => {
3578
- const f = y.getAllColumns().filter(
3579
- /** @param {any} [c] @returns {any} */
3580
- (C) => !C.parent && C.id !== "no_data"
3581
- ).filter(
3582
- /** @param {any} [col] @returns {any} */
3583
- (C) => {
3584
- if (o === "all") return !0;
3585
- let j = "string";
3586
- if (E.find(
3587
- /** @param {any} [v] @returns {any} */
3588
- (re) => C.id.includes(re.field)
3589
- ))
3590
- j = "number";
3591
- else if (Se && Se.length > 0) {
3592
- const re = Se[0];
3593
- let ne = re[C.id];
3594
- if (ne === void 0 && C.accessorFn)
3595
- try {
3596
- ne = C.accessorFn(re);
3597
- } catch {
3598
- }
3599
- typeof ne == "number" ? j = "number" : ne instanceof Date ? j = "date" : typeof ne == "string" && (!isNaN(Number(ne)) && ne.trim() !== "" ? j = "number" : !isNaN(Date.parse(ne)) && ne.includes("-") && (j = "date"));
3600
- }
3601
- return j === o;
3602
- }
3603
- ), p = f.filter(
3604
- /** @param {any} [c] @returns {any} */
3605
- (C) => Je(C, "left")
3606
- ), b = f.filter(
3607
- /** @param {any} [c] @returns {any} */
3608
- (C) => Je(C, "right")
3609
- ), S = f.filter(
3610
- /** @param {any} [c] @returns {any} */
3611
- (C) => Je(C, "unpinned")
3612
- ), I = (C, j) => C.map(
3613
- /** @param {any} [column] @returns {any} */
3614
- (ie) => /* @__PURE__ */ e.createElement(
3615
- rr,
3616
- {
3617
- key: ie.id,
3618
- column: ie,
3619
- level: 0,
3620
- theme: c,
3621
- styles: Y,
3622
- handlePinColumn: Z,
3623
- colSearch: k,
3624
- selectedCols: R,
3625
- setSelectedCols: B,
3626
- onDrop: q,
3627
- sectionId: j
3628
- }
3629
- )
3630
- ), q = (C, j, ie) => {
3631
- let re;
3632
- const ne = L || { left: [], right: [] };
3633
- if (ie) {
3634
- const Le = j === "left" ? ne.left : j === "right" ? ne.right : null;
3635
- if (Le) {
3636
- if (re = Le.indexOf(ie), re === -1) {
3637
- const ft = y.getColumn(ie);
3638
- if (ft && Nr(ft)) {
3639
- const Ot = xt(ft).find(
3640
- /** @param {any} [id] @returns {any} */
3641
- (Tr) => Le.includes(Tr)
3642
- );
3643
- Ot && (re = Le.indexOf(Ot));
3644
- }
3645
- }
3646
- re === -1 && (re = void 0);
3647
- }
3648
- }
3649
- j === "left" ? Z(C, "left", re) : j === "right" ? Z(C, "right", re) : Z(C, !1);
3650
- };
3651
- return /* @__PURE__ */ e.createElement(e.Fragment, null, p.length > 0 && /* @__PURE__ */ e.createElement(
3652
- gt,
3653
- {
3654
- title: "Pinned Left",
3655
- count: p.length,
3656
- theme: c,
3657
- styles: Y,
3658
- sectionId: "left",
3659
- onDrop: q
3660
- },
3661
- I(p, "left")
3662
- ), b.length > 0 && /* @__PURE__ */ e.createElement(
3663
- gt,
3664
- {
3665
- title: "Pinned Right",
3666
- count: b.length,
3667
- theme: c,
3668
- styles: Y,
3669
- sectionId: "right",
3670
- onDrop: q
3671
- },
3672
- I(b, "right")
3673
- ), /* @__PURE__ */ e.createElement(
3674
- gt,
3675
- {
3676
- title: "Columns",
3677
- count: S.length,
3678
- theme: c,
3679
- styles: Y,
3680
- sectionId: "unpinned",
3681
- onDrop: q
3682
- },
3683
- I(S, "unpinned")
3684
- ));
3685
- })()), h && h.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { padding: "8px", borderTop: `1px solid ${c.border}` } }, /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitle }, "Pinning Presets"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", flexWrap: "wrap" } }, h.map(
3686
- /** @param {any} [preset] @param {any} [i] @returns {any} */
3687
- (r, f) => /* @__PURE__ */ e.createElement(
3688
- "button",
3689
- {
3690
- key: f,
3691
- onClick: () => {
3692
- _(r.config), w(`Applied preset: ${r.name}`);
3693
- },
3694
- style: { ...Y.btn, fontSize: "11px", background: c.headerBg }
3695
- },
3696
- r.name
3697
- )
3698
- ))), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: c.textSec, fontStyle: "italic", padding: "8px", background: c.headerBg, borderTop: `1px solid ${c.border}44` } }, /* @__PURE__ */ e.createElement(z.Lock, { style: { verticalAlign: "middle", marginRight: "4px", opacity: 0.5 } }), "Drag columns or use pin icons to freeze areas."))), dt && /* @__PURE__ */ e.createElement(
3699
- kn,
3700
- {
3701
- item: dt,
3702
- idx: pt,
3703
- valConfigs: E,
3704
- setValConfigs: d,
3705
- theme: c,
3706
- onClose: () => ge(null),
3707
- onRemove: Ie,
3708
- displayedColumnOptions: fr,
3709
- availableRawFields: J,
3710
- serverError: he && he[dt.field] || null
3711
- }
3712
- ), /* @__PURE__ */ e.createElement(
3713
- "div",
3714
- {
3715
- onMouseDown: $r,
3716
- style: {
3717
- position: "absolute",
3718
- right: 0,
3719
- top: 0,
3720
- bottom: 0,
3721
- width: "5px",
3722
- cursor: "col-resize",
3723
- zIndex: 10,
3724
- background: "transparent"
3725
- },
3726
- title: "Drag to resize panel"
3727
- },
3728
- /* @__PURE__ */ e.createElement("div", { style: {
3729
- position: "absolute",
3730
- right: 0,
3731
- top: 0,
3732
- bottom: 0,
3733
- width: "2px",
3734
- background: c.border,
3735
- transition: "background 0.15s"
3736
- } })
3737
- ));
3738
- }
3739
- );
3740
- export {
3741
- Fn as SidebarPanel
3742
- };