@nice2dev/ui 1.4.5 → 1.4.7

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 (36) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/dist/{NiceDataGrid-mrnaLHQk.cjs → NiceDataGrid-D3qRQSjy.cjs} +1 -1
  3. package/dist/NiceForm-BWb4LTQJ.cjs +1 -0
  4. package/dist/{NiceHtmlEditor-C1OVtLQ6.cjs → NiceHtmlEditor-BzECmDO3.cjs} +1 -1
  5. package/dist/{NiceMention-tgJKS8PH.cjs → NiceMention-CYRqPKGU.cjs} +19 -19
  6. package/dist/NiceModuleLifecyclePanel-CiYbPcHV.cjs +1 -0
  7. package/dist/{NicePagination-D7XxeNFz.cjs → NicePagination-BAxwqeEd.cjs} +1 -1
  8. package/dist/{NicePivotGrid-Cnkr9WkC.cjs → NicePivotGrid-Cxu5PECg.cjs} +1 -1
  9. package/dist/{NiceSavedQueryPanel-U1-yaw-Q.cjs → NiceSavedQueryPanel-BSZhE-_l.cjs} +6 -6
  10. package/dist/{NiceScheduler-Boo-D1S-.cjs → NiceScheduler-BqYiHPvz.cjs} +1 -1
  11. package/dist/{core-lazy-C_qnVGxE.cjs → core-lazy-BQexApr7.cjs} +1 -1
  12. package/dist/data.cjs +1 -1
  13. package/dist/database/NiceDataSourceEditor.mjs +370 -0
  14. package/dist/database/NiceQueryDesigner.mjs +958 -0
  15. package/dist/database/moduleDataSource.mjs +151 -0
  16. package/dist/database/queryDesign.mjs +396 -0
  17. package/dist/database/queryDesignerPanels.mjs +1214 -0
  18. package/dist/database/querySql.mjs +481 -0
  19. package/dist/editors.cjs +1 -1
  20. package/dist/index.cjs +188 -181
  21. package/dist/index.d.ts +674 -0
  22. package/dist/index.mjs +774 -720
  23. package/dist/lazy.cjs +1 -1
  24. package/dist/navigation.cjs +1 -1
  25. package/dist/no-code/NiceNoCodeScriptEditor.mjs +584 -0
  26. package/dist/no-code/noCodeScript.mjs +326 -0
  27. package/dist/no-code-B1jzfUF5.cjs +331 -0
  28. package/dist/no-code.cjs +1 -1
  29. package/dist/no-code.d.ts +177 -0
  30. package/dist/no-code.mjs +26 -16
  31. package/dist/style.css +2 -2
  32. package/package.json +4 -4
  33. package/dist/NiceForm-O3sv-DNX.cjs +0 -1
  34. package/dist/NiceModuleLifecyclePanel-DKlqKPy2.cjs +0 -1
  35. package/dist/NiceSelect-BNPXs6FQ.cjs +0 -1
  36. package/dist/no-code-B3BHeyG-.cjs +0 -331
@@ -0,0 +1,1214 @@
1
+ import { jsx as e, jsxs as p, Fragment as L } from "react/jsx-runtime";
2
+ import { useNiceTranslation as N, NiceIcon as k } from "@nice2dev/ui-core";
3
+ import { useState as $ } from "react";
4
+ import { NiceSelect as B } from "../editors/inputs/NiceSelect.mjs";
5
+ import { NiceTextInput as V } from "../editors/inputs/NiceTextInput.mjs";
6
+ import { NiceSimpleCodeEditor as H } from "../editors/rich/NiceCodeEditor.mjs";
7
+ import { outputColumns as M, tableHandleOf as w, emptyFilterGroup as j, nestPathOf as J, queryParameterNames as G, NICE_SQL_FUNCTIONS as T, designId as z, conditionsToFilter as Y, valueTypeOf as U, updateFilterNode as K, operatorsFor as X } from "./queryDesign.mjs";
8
+ import { planSqlText as Z, planQuerySql as O } from "./querySql.mjs";
9
+ const A = ["COUNT", "COUNT_DISTINCT", "SUM", "AVG", "MIN", "MAX"], R = (n, i) => ({
10
+ COUNT: n("queryDesigner.agg.count", "Count"),
11
+ COUNT_DISTINCT: n("queryDesigner.agg.countDistinct", "Count different"),
12
+ SUM: n("queryDesigner.agg.sum", "Sum"),
13
+ AVG: n("queryDesigner.agg.avg", "Average"),
14
+ MIN: n("queryDesigner.agg.min", "Smallest"),
15
+ MAX: n("queryDesigner.agg.max", "Largest")
16
+ })[i], Q = (n, i) => ({
17
+ eq: n("queryDesigner.op.eq", "is"),
18
+ ne: n("queryDesigner.op.ne", "is not"),
19
+ contains: n("queryDesigner.op.contains", "contains"),
20
+ notContains: n("queryDesigner.op.notContains", "does not contain"),
21
+ startsWith: n("queryDesigner.op.startsWith", "starts with"),
22
+ endsWith: n("queryDesigner.op.endsWith", "ends with"),
23
+ gt: n("queryDesigner.op.gt", "is more than"),
24
+ ge: n("queryDesigner.op.ge", "is at least"),
25
+ lt: n("queryDesigner.op.lt", "is less than"),
26
+ le: n("queryDesigner.op.le", "is at most"),
27
+ between: n("queryDesigner.op.between", "is between"),
28
+ in: n("queryDesigner.op.in", "is one of"),
29
+ notIn: n("queryDesigner.op.notIn", "is none of"),
30
+ isEmpty: n("queryDesigner.op.isEmpty", "is empty"),
31
+ isNotEmpty: n("queryDesigner.op.isNotEmpty", "is not empty"),
32
+ isTrue: n("queryDesigner.op.isTrue", "is yes"),
33
+ isFalse: n("queryDesigner.op.isFalse", "is no"),
34
+ today: n("queryDesigner.op.today", "is today"),
35
+ lastDays: n("queryDesigner.op.lastDays", "in the last … days"),
36
+ nextDays: n("queryDesigner.op.nextDays", "in the next … days"),
37
+ thisMonth: n("queryDesigner.op.thisMonth", "is this month"),
38
+ thisYear: n("queryDesigner.op.thisYear", "is this year")
39
+ })[i], F = (n, i) => ({
40
+ upper: n("queryDesigner.fn.upper", "Upper case"),
41
+ lower: n("queryDesigner.fn.lower", "Lower case"),
42
+ trim: n("queryDesigner.fn.trim", "Trim spaces"),
43
+ concat: n("queryDesigner.fn.concat", "Join texts"),
44
+ left: n("queryDesigner.fn.left", "First characters"),
45
+ length: n("queryDesigner.fn.length", "Length"),
46
+ replace: n("queryDesigner.fn.replace", "Replace text"),
47
+ round: n("queryDesigner.fn.round", "Round"),
48
+ abs: n("queryDesigner.fn.abs", "Without sign"),
49
+ floor: n("queryDesigner.fn.floor", "Round down"),
50
+ ceil: n("queryDesigner.fn.ceil", "Round up"),
51
+ add: n("queryDesigner.fn.add", "Add"),
52
+ subtract: n("queryDesigner.fn.subtract", "Subtract"),
53
+ multiply: n("queryDesigner.fn.multiply", "Multiply"),
54
+ divide: n("queryDesigner.fn.divide", "Divide"),
55
+ year: n("queryDesigner.fn.year", "Year"),
56
+ month: n("queryDesigner.fn.month", "Month"),
57
+ day: n("queryDesigner.fn.day", "Day"),
58
+ date: n("queryDesigner.fn.date", "Date without time"),
59
+ daysBetween: n("queryDesigner.fn.daysBetween", "Days between"),
60
+ now: n("queryDesigner.fn.now", "Now"),
61
+ coalesce: n("queryDesigner.fn.coalesce", "First not empty")
62
+ })[i], ee = (n, i) => ({
63
+ year: n("queryDesigner.part.year", "by year"),
64
+ quarter: n("queryDesigner.part.quarter", "by quarter"),
65
+ month: n("queryDesigner.part.month", "by month"),
66
+ day: n("queryDesigner.part.day", "by day")
67
+ })[i];
68
+ function I(n, i) {
69
+ return [
70
+ ...n.tables.flatMap(
71
+ (o) => o.columns.map((t) => ({
72
+ value: `${o.id}|${t.name}`,
73
+ label: `${w(o)} · ${t.name}`
74
+ }))
75
+ ),
76
+ ...(n.computed ?? []).map((o) => ({
77
+ value: `c|${o.id}`,
78
+ label: `${o.alias} (${i("queryDesigner.computed", "computed")})`
79
+ }))
80
+ ];
81
+ }
82
+ const W = (n) => n?.kind === "column" ? `${n.tableId}|${n.column}` : n?.kind === "computed" ? `c|${n.id}` : "", E = (n) => {
83
+ const [i, o] = n.split("|");
84
+ return i === "c" ? { kind: "computed", id: o } : { kind: "column", tableId: i, column: o };
85
+ };
86
+ function ne(n, i) {
87
+ if (i?.kind === "column")
88
+ return U(
89
+ n.tables.find((o) => o.id === i.tableId)?.columns.find((o) => o.name === i.column)?.dataType
90
+ );
91
+ if (i?.kind === "computed") {
92
+ const o = n.computed?.find((t) => t.id === i.id);
93
+ return T.find((t) => t.id === o?.fn)?.result ?? "any";
94
+ }
95
+ return "any";
96
+ }
97
+ function _({
98
+ icon: n,
99
+ label: i,
100
+ onClick: o,
101
+ disabled: t,
102
+ pressed: l
103
+ }) {
104
+ return /* @__PURE__ */ e(
105
+ "button",
106
+ {
107
+ type: "button",
108
+ className: `nice-query-designer__icon-btn${l ? " nice-query-designer__icon-btn--on" : ""}`,
109
+ title: i,
110
+ "aria-label": i,
111
+ "aria-pressed": l,
112
+ disabled: t,
113
+ onClick: o,
114
+ children: /* @__PURE__ */ e(k, { name: n, size: 14 })
115
+ }
116
+ );
117
+ }
118
+ function he({ def: n, setQuery: i, readOnly: o }) {
119
+ const { t } = N(), l = n.query, d = M(l), [g, h] = $(/* @__PURE__ */ new Set()), m = new Map(l.tables.map((u) => [u.id, u])), s = [...g].filter((u) => d.some((y) => y.key === u)), a = (u, y) => i({
120
+ ...l,
121
+ tables: l.tables.map((v) => ({
122
+ ...v,
123
+ columns: v.columns.map(
124
+ (b) => u.includes(`t:${v.id}:${b.name}`) ? { ...b, ...y(b) } : b
125
+ )
126
+ })),
127
+ computed: l.computed?.map((v) => u.includes(`c:${v.id}`) ? { ...v, ...y(v) } : v)
128
+ }), r = (u, y) => {
129
+ if (y < 0 || y >= d.length)
130
+ return;
131
+ const v = [...d], [b] = v.splice(u, 1);
132
+ v.splice(y, 0, b);
133
+ const f = new Map(v.map((D, C) => [D.key, C]));
134
+ i({
135
+ ...l,
136
+ tables: l.tables.map((D) => ({
137
+ ...D,
138
+ columns: D.columns.map((C) => {
139
+ const P = f.get(`t:${D.id}:${C.name}`);
140
+ return P === void 0 ? C : { ...C, order: P };
141
+ })
142
+ })),
143
+ computed: l.computed?.map((D) => {
144
+ const C = f.get(`c:${D.id}`);
145
+ return C === void 0 ? D : { ...D, order: C };
146
+ })
147
+ });
148
+ }, c = (u) => l.sorts.find((y) => y.tableId === u.tableId && y.column === u.column), q = (u, y) => {
149
+ if (!u.tableId || !u.column)
150
+ return;
151
+ const v = l.sorts.filter((b) => !(b.tableId === u.tableId && b.column === u.column));
152
+ i({
153
+ ...l,
154
+ sorts: y ? [
155
+ ...v,
156
+ {
157
+ id: z("s"),
158
+ tableId: u.tableId,
159
+ column: u.column,
160
+ direction: y
161
+ }
162
+ ] : v
163
+ });
164
+ };
165
+ return d.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-query-designer__muted", children: t(
166
+ "queryDesigner.columns.empty",
167
+ "No columns yet: tick them on the canvas or in the browser."
168
+ ) }) : /* @__PURE__ */ p("div", { className: "nice-query-designer__panel", children: [
169
+ s.length > 0 && !o && /* @__PURE__ */ p(
170
+ "div",
171
+ {
172
+ className: "nice-query-designer__bulk",
173
+ role: "group",
174
+ "aria-label": t("queryDesigner.columns.bulk", "Picked columns"),
175
+ children: [
176
+ /* @__PURE__ */ e("span", { children: t("queryDesigner.columns.checked", "{count} checked").replace(
177
+ "{count}",
178
+ String(s.length)
179
+ ) }),
180
+ /* @__PURE__ */ e(
181
+ B,
182
+ {
183
+ "aria-label": t("queryDesigner.columns.total", "Total"),
184
+ placeholder: t("queryDesigner.columns.setTotal", "Set the total"),
185
+ value: "",
186
+ options: [
187
+ { value: "-", label: t("queryDesigner.agg.none", "No total") },
188
+ ...A.map((u) => ({ value: u, label: R(t, u) }))
189
+ ],
190
+ onChange: (u) => a(s, () => ({
191
+ aggregate: u === "-" ? void 0 : String(u)
192
+ })),
193
+ size: "sm"
194
+ }
195
+ ),
196
+ /* @__PURE__ */ e(
197
+ _,
198
+ {
199
+ icon: "eye-off",
200
+ label: t("queryDesigner.columns.drop", "Leave out of the result"),
201
+ onClick: () => {
202
+ a(s, () => ({ selected: !1 })), h(/* @__PURE__ */ new Set());
203
+ }
204
+ }
205
+ )
206
+ ]
207
+ }
208
+ ),
209
+ /* @__PURE__ */ p("table", { className: "nice-query-designer__grid", children: [
210
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ p("tr", { children: [
211
+ /* @__PURE__ */ e("th", { scope: "col", children: /* @__PURE__ */ e(
212
+ "input",
213
+ {
214
+ type: "checkbox",
215
+ "aria-label": t("queryDesigner.columns.checkAll", "Check every column"),
216
+ checked: s.length === d.length,
217
+ onChange: (u) => h(new Set(u.target.checked ? d.map((y) => y.key) : []))
218
+ }
219
+ ) }),
220
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.columns.source", "From") }),
221
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.columns.name", "Name in the result") }),
222
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.columns.total", "Total") }),
223
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.columns.sort", "Sort") }),
224
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.columns.part", "Part") }),
225
+ /* @__PURE__ */ e("th", { scope: "col", children: /* @__PURE__ */ e("span", { className: "nice-query-designer__sr", children: t("queryDesigner.columns.actions", "Actions") }) })
226
+ ] }) }),
227
+ /* @__PURE__ */ e("tbody", { children: d.map((u, y) => {
228
+ const v = u.tableId ? m.get(u.tableId) : void 0, b = u.computedId ? l.computed?.find((f) => f.id === u.computedId) : void 0;
229
+ return /* @__PURE__ */ p("tr", { children: [
230
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
231
+ "input",
232
+ {
233
+ type: "checkbox",
234
+ "aria-label": u.name,
235
+ checked: g.has(u.key),
236
+ onChange: (f) => {
237
+ const D = new Set(g);
238
+ f.target.checked ? D.add(u.key) : D.delete(u.key), h(D);
239
+ }
240
+ }
241
+ ) }),
242
+ /* @__PURE__ */ e("td", { children: b ? /* @__PURE__ */ e(
243
+ re,
244
+ {
245
+ q: l,
246
+ computed: b,
247
+ readOnly: o,
248
+ onChange: (f) => i({
249
+ ...l,
250
+ computed: l.computed.map((D) => D.id === b.id ? f : D)
251
+ })
252
+ }
253
+ ) : /* @__PURE__ */ e("span", { children: v ? `${w(v)} · ${u.column}` : u.column }) }),
254
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
255
+ "input",
256
+ {
257
+ className: "nice-query-designer__input",
258
+ value: b ? b.alias : v?.columns.find((f) => f.name === u.column)?.alias ?? "",
259
+ placeholder: u.column,
260
+ "aria-label": t("queryDesigner.columns.name", "Name in the result"),
261
+ readOnly: o,
262
+ onChange: (f) => a(
263
+ [u.key],
264
+ () => b ? { alias: f.target.value } : { alias: f.target.value || void 0 }
265
+ )
266
+ }
267
+ ) }),
268
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ p(
269
+ "select",
270
+ {
271
+ className: "nice-query-designer__input",
272
+ value: u.aggregate ?? "",
273
+ disabled: o,
274
+ "aria-label": t("queryDesigner.columns.total", "Total"),
275
+ onChange: (f) => a([u.key], () => ({
276
+ aggregate: f.target.value || void 0
277
+ })),
278
+ children: [
279
+ /* @__PURE__ */ e("option", { value: "", children: t("queryDesigner.agg.none", "No total") }),
280
+ A.map((f) => /* @__PURE__ */ e("option", { value: f, children: R(t, f) }, f))
281
+ ]
282
+ }
283
+ ) }),
284
+ /* @__PURE__ */ e("td", { children: u.tableId && /* @__PURE__ */ p(
285
+ "select",
286
+ {
287
+ className: "nice-query-designer__input",
288
+ value: c(u)?.direction ?? "",
289
+ disabled: o,
290
+ "aria-label": t("queryDesigner.columns.sort", "Sort"),
291
+ onChange: (f) => q(u, f.target.value),
292
+ children: [
293
+ /* @__PURE__ */ e("option", { value: "", children: t("queryDesigner.sort.none", "Not sorted") }),
294
+ /* @__PURE__ */ e("option", { value: "ASC", children: t("queryDesigner.sort.asc", "Ascending") }),
295
+ /* @__PURE__ */ e("option", { value: "DESC", children: t("queryDesigner.sort.desc", "Descending") })
296
+ ]
297
+ }
298
+ ) }),
299
+ /* @__PURE__ */ e("td", { className: "nice-query-designer__muted", children: u.path.length ? u.path.join(" · ") : t("queryDesigner.columns.row", "the row") }),
300
+ /* @__PURE__ */ p("td", { className: "nice-query-designer__actions", children: [
301
+ /* @__PURE__ */ e(
302
+ _,
303
+ {
304
+ icon: "arrow-up",
305
+ label: t("queryDesigner.columns.up", "Move up"),
306
+ disabled: o || y === 0,
307
+ onClick: () => r(y, y - 1)
308
+ }
309
+ ),
310
+ /* @__PURE__ */ e(
311
+ _,
312
+ {
313
+ icon: "arrow-down",
314
+ label: t("queryDesigner.columns.down", "Move down"),
315
+ disabled: o || y === d.length - 1,
316
+ onClick: () => r(y, y + 1)
317
+ }
318
+ ),
319
+ /* @__PURE__ */ e(
320
+ _,
321
+ {
322
+ icon: b ? "trash" : "eye-off",
323
+ label: b ? t("queryDesigner.columns.removeComputed", "Remove the computed column") : t("queryDesigner.columns.drop", "Leave out of the result"),
324
+ disabled: o,
325
+ onClick: () => b ? i({ ...l, computed: l.computed.filter((f) => f.id !== b.id) }) : a([u.key], () => ({ selected: !1 }))
326
+ }
327
+ )
328
+ ] })
329
+ ] }, u.key);
330
+ }) })
331
+ ] })
332
+ ] });
333
+ }
334
+ function re({
335
+ q: n,
336
+ computed: i,
337
+ readOnly: o,
338
+ onChange: t
339
+ }) {
340
+ const { t: l } = N(), d = T.find((s) => s.id === i.fn), g = Math.max(d?.args.length ?? 0, d?.variadic ? i.args.length : 0), h = ["text", "number", "date", "other"], m = {
341
+ text: l("queryDesigner.fnGroup.text", "Text"),
342
+ number: l("queryDesigner.fnGroup.number", "Numbers"),
343
+ date: l("queryDesigner.fnGroup.date", "Dates"),
344
+ other: l("queryDesigner.fnGroup.other", "Other")
345
+ };
346
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__computed", children: [
347
+ /* @__PURE__ */ e(
348
+ "select",
349
+ {
350
+ className: "nice-query-designer__input",
351
+ value: i.fn,
352
+ disabled: o,
353
+ "aria-label": l("queryDesigner.computed.fn", "Function"),
354
+ onChange: (s) => {
355
+ const a = T.find((r) => r.id === s.target.value);
356
+ t({
357
+ ...i,
358
+ fn: a.id,
359
+ args: a.args.map((r, c) => i.args[c] ?? { kind: "value", value: "" })
360
+ });
361
+ },
362
+ children: h.map((s) => /* @__PURE__ */ e("optgroup", { label: m[s], children: T.filter((a) => a.group === s).map((a) => /* @__PURE__ */ e("option", { value: a.id, children: F(l, a.id) }, a.id)) }, s))
363
+ }
364
+ ),
365
+ Array.from({ length: g }, (s, a) => /* @__PURE__ */ e(
366
+ S,
367
+ {
368
+ q: n,
369
+ value: i.args[a],
370
+ readOnly: o,
371
+ allowColumn: !0,
372
+ label: `${F(l, i.fn)} ${a + 1}`,
373
+ onChange: (r) => t({
374
+ ...i,
375
+ args: Array.from(
376
+ { length: Math.max(g, a + 1) },
377
+ (c, q) => q === a ? r : i.args[q] ?? { kind: "value", value: "" }
378
+ )
379
+ })
380
+ },
381
+ a
382
+ )),
383
+ d?.variadic && !o && /* @__PURE__ */ e(
384
+ _,
385
+ {
386
+ icon: "plus",
387
+ label: l("queryDesigner.computed.addArg", "One more"),
388
+ onClick: () => t({ ...i, args: [...i.args, { kind: "value", value: "" }] })
389
+ }
390
+ )
391
+ ] });
392
+ }
393
+ function S({
394
+ q: n,
395
+ value: i,
396
+ onChange: o,
397
+ readOnly: t,
398
+ allowColumn: l,
399
+ label: d,
400
+ type: g = "any"
401
+ }) {
402
+ const { t: h } = N(), m = i?.kind === "parameter" ? "parameter" : i?.kind === "column" || i?.kind === "computed" ? "column" : "value", s = (a) => a === "parameter" ? { kind: "parameter", name: "" } : a === "column" ? E(I(n, h)[0]?.value ?? "|") : { kind: "value", value: "" };
403
+ return /* @__PURE__ */ p("span", { className: "nice-query-designer__operand", children: [
404
+ /* @__PURE__ */ p(
405
+ "select",
406
+ {
407
+ className: "nice-query-designer__input nice-query-designer__input--kind",
408
+ value: m,
409
+ disabled: t,
410
+ "aria-label": `${d}: ${h("queryDesigner.operand.kind", "what it is")}`,
411
+ onChange: (a) => o(s(a.target.value)),
412
+ children: [
413
+ /* @__PURE__ */ e("option", { value: "value", children: h("queryDesigner.operand.value", "value") }),
414
+ /* @__PURE__ */ e("option", { value: "parameter", children: h("queryDesigner.operand.parameter", "parameter") }),
415
+ l && /* @__PURE__ */ e("option", { value: "column", children: h("queryDesigner.operand.column", "column") })
416
+ ]
417
+ }
418
+ ),
419
+ m === "column" ? /* @__PURE__ */ e(
420
+ "select",
421
+ {
422
+ className: "nice-query-designer__input",
423
+ value: W(i),
424
+ disabled: t,
425
+ "aria-label": d,
426
+ onChange: (a) => o(E(a.target.value)),
427
+ children: I(n, h).map((a) => /* @__PURE__ */ e("option", { value: a.value, children: a.label }, a.value))
428
+ }
429
+ ) : m === "parameter" ? /* @__PURE__ */ e(
430
+ "input",
431
+ {
432
+ className: "nice-query-designer__input",
433
+ value: i?.kind === "parameter" ? i.name : "",
434
+ placeholder: h("queryDesigner.operand.parameterName", "name, e.g. id"),
435
+ "aria-label": d,
436
+ readOnly: t,
437
+ onChange: (a) => o({ kind: "parameter", name: a.target.value.replace(/[^A-Za-z0-9_]/g, "") })
438
+ }
439
+ ) : /* @__PURE__ */ e(
440
+ "input",
441
+ {
442
+ className: "nice-query-designer__input",
443
+ type: g === "number" ? "number" : g === "date" ? "date" : "text",
444
+ value: i?.kind === "value" ? i.value : i?.kind === "values" ? i.values.join(", ") : "",
445
+ "aria-label": d,
446
+ readOnly: t,
447
+ onChange: (a) => o({ kind: "value", value: a.target.value })
448
+ }
449
+ )
450
+ ] });
451
+ }
452
+ const ie = (n) => n.filter ?? (n.conditions.length ? Y(n.conditions) : j());
453
+ function ye({ def: n, setQuery: i, readOnly: o }) {
454
+ const t = n.query;
455
+ return /* @__PURE__ */ e("div", { className: "nice-query-designer__panel", children: /* @__PURE__ */ e(
456
+ x,
457
+ {
458
+ q: t,
459
+ group: ie(t),
460
+ root: !0,
461
+ readOnly: o,
462
+ onChange: (l) => i({ ...t, filter: l, conditions: [] })
463
+ }
464
+ ) });
465
+ }
466
+ function x({
467
+ q: n,
468
+ group: i,
469
+ root: o,
470
+ readOnly: t,
471
+ totals: l,
472
+ onChange: d,
473
+ onRemove: g
474
+ }) {
475
+ const { t: h } = N(), m = I(n, h)[0]?.value, s = () => ({
476
+ kind: "rule",
477
+ id: z("r"),
478
+ left: m ? {
479
+ ...E(m),
480
+ ...l ? { aggregate: "SUM" } : {}
481
+ } : { kind: "value", value: "" },
482
+ operator: l ? "gt" : "eq",
483
+ right: { kind: "value", value: "" }
484
+ }), a = (r, c) => d(K(i, r, () => c));
485
+ return /* @__PURE__ */ p("div", { className: `nice-query-designer__group${o ? " nice-query-designer__group--root" : ""}`, children: [
486
+ /* @__PURE__ */ p("div", { className: "nice-query-designer__group-head", children: [
487
+ /* @__PURE__ */ p(
488
+ "select",
489
+ {
490
+ className: "nice-query-designer__input",
491
+ value: `${i.not ? "not-" : ""}${i.logic}`,
492
+ disabled: t,
493
+ "aria-label": h("queryDesigner.filter.logic", "Which rules must hold"),
494
+ onChange: (r) => {
495
+ const c = r.target.value;
496
+ d({
497
+ ...i,
498
+ not: c.startsWith("not-"),
499
+ logic: c.endsWith("OR") ? "OR" : "AND"
500
+ });
501
+ },
502
+ children: [
503
+ /* @__PURE__ */ e("option", { value: "AND", children: h("queryDesigner.filter.all", "All of these hold") }),
504
+ /* @__PURE__ */ e("option", { value: "OR", children: h("queryDesigner.filter.any", "Any of these holds") }),
505
+ /* @__PURE__ */ e("option", { value: "not-AND", children: h("queryDesigner.filter.notAll", "Not all of these hold") }),
506
+ /* @__PURE__ */ e("option", { value: "not-OR", children: h("queryDesigner.filter.none", "None of these holds") })
507
+ ]
508
+ }
509
+ ),
510
+ !t && /* @__PURE__ */ p(L, { children: [
511
+ /* @__PURE__ */ p(
512
+ "button",
513
+ {
514
+ type: "button",
515
+ className: "nice-query-designer__chip",
516
+ disabled: !m,
517
+ onClick: () => d({ ...i, items: [...i.items, s()] }),
518
+ children: [
519
+ /* @__PURE__ */ e(k, { name: "plus", size: 12 }),
520
+ h("queryDesigner.filter.addRule", "Rule")
521
+ ]
522
+ }
523
+ ),
524
+ /* @__PURE__ */ p(
525
+ "button",
526
+ {
527
+ type: "button",
528
+ className: "nice-query-designer__chip",
529
+ onClick: () => d({
530
+ ...i,
531
+ items: [...i.items, j(i.logic === "AND" ? "OR" : "AND")]
532
+ }),
533
+ children: [
534
+ /* @__PURE__ */ e(k, { name: "group", size: 12 }),
535
+ h("queryDesigner.filter.addGroup", "Group")
536
+ ]
537
+ }
538
+ ),
539
+ !o && g && /* @__PURE__ */ e(
540
+ _,
541
+ {
542
+ icon: "trash",
543
+ label: h("queryDesigner.filter.removeGroup", "Remove the group"),
544
+ onClick: g
545
+ }
546
+ )
547
+ ] })
548
+ ] }),
549
+ i.items.length === 0 && o && /* @__PURE__ */ e("p", { className: "nice-query-designer__muted", children: l ? h("queryDesigner.having.empty", "No conditions on the totals.") : h("queryDesigner.filter.empty", "Every row is read. Add a rule to keep only some.") }),
550
+ /* @__PURE__ */ e("ul", { className: "nice-query-designer__rules", children: i.items.map((r) => /* @__PURE__ */ e("li", { children: r.kind === "group" ? /* @__PURE__ */ e(
551
+ x,
552
+ {
553
+ q: n,
554
+ group: r,
555
+ readOnly: t,
556
+ totals: l,
557
+ onChange: (c) => a(r.id, c),
558
+ onRemove: () => a(r.id, null)
559
+ }
560
+ ) : /* @__PURE__ */ e(
561
+ te,
562
+ {
563
+ q: n,
564
+ rule: r,
565
+ readOnly: t,
566
+ totals: l,
567
+ onChange: (c) => a(r.id, c),
568
+ onRemove: () => a(r.id, null)
569
+ }
570
+ ) }, r.id)) })
571
+ ] });
572
+ }
573
+ function te({
574
+ q: n,
575
+ rule: i,
576
+ readOnly: o,
577
+ totals: t,
578
+ onChange: l,
579
+ onRemove: d
580
+ }) {
581
+ const { t: g } = N(), h = t && i.left.kind === "column" && i.left.aggregate ? "number" : ne(n, i.left), m = X(h), s = m.find((r) => r.id === i.operator) ?? m[0], a = g("queryDesigner.filter.value", "Value");
582
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__rule", children: [
583
+ t && i.left.kind === "column" && /* @__PURE__ */ e(
584
+ "select",
585
+ {
586
+ className: "nice-query-designer__input",
587
+ value: i.left.aggregate ?? "SUM",
588
+ disabled: o,
589
+ "aria-label": g("queryDesigner.columns.total", "Total"),
590
+ onChange: (r) => l({
591
+ ...i,
592
+ left: {
593
+ ...i.left,
594
+ aggregate: r.target.value
595
+ }
596
+ }),
597
+ children: A.map((r) => /* @__PURE__ */ e("option", { value: r, children: R(g, r) }, r))
598
+ }
599
+ ),
600
+ /* @__PURE__ */ e(
601
+ "select",
602
+ {
603
+ className: "nice-query-designer__input",
604
+ value: W(i.left),
605
+ disabled: o,
606
+ "aria-label": g("queryDesigner.filter.column", "Column"),
607
+ onChange: (r) => {
608
+ const c = E(r.target.value);
609
+ l({
610
+ ...i,
611
+ left: t && c.kind === "column" ? { ...c, aggregate: "SUM" } : c
612
+ });
613
+ },
614
+ children: I(n, g).map((r) => /* @__PURE__ */ e("option", { value: r.value, children: r.label }, r.value))
615
+ }
616
+ ),
617
+ /* @__PURE__ */ e(
618
+ "select",
619
+ {
620
+ className: "nice-query-designer__input",
621
+ value: s.id,
622
+ disabled: o,
623
+ "aria-label": g("queryDesigner.filter.operator", "Comparison"),
624
+ onChange: (r) => l({ ...i, operator: r.target.value }),
625
+ children: m.map((r) => /* @__PURE__ */ e("option", { value: r.id, children: Q(g, r.id) }, r.id))
626
+ }
627
+ ),
628
+ s.takes === "one" && /* @__PURE__ */ e(
629
+ S,
630
+ {
631
+ q: n,
632
+ value: i.right,
633
+ type: h,
634
+ readOnly: o,
635
+ allowColumn: !0,
636
+ label: a,
637
+ onChange: (r) => l({ ...i, right: r })
638
+ }
639
+ ),
640
+ s.takes === "two" && /* @__PURE__ */ p(L, { children: [
641
+ /* @__PURE__ */ e(
642
+ S,
643
+ {
644
+ q: n,
645
+ value: i.right,
646
+ type: h,
647
+ readOnly: o,
648
+ label: g("queryDesigner.filter.from", "From"),
649
+ onChange: (r) => l({ ...i, right: r })
650
+ }
651
+ ),
652
+ /* @__PURE__ */ e("span", { className: "nice-query-designer__muted", children: g("queryDesigner.filter.and", "and") }),
653
+ /* @__PURE__ */ e(
654
+ S,
655
+ {
656
+ q: n,
657
+ value: i.right2,
658
+ type: h,
659
+ readOnly: o,
660
+ label: g("queryDesigner.filter.to", "To"),
661
+ onChange: (r) => l({ ...i, right2: r })
662
+ }
663
+ )
664
+ ] }),
665
+ s.takes === "list" && /* @__PURE__ */ e(
666
+ "input",
667
+ {
668
+ className: "nice-query-designer__input nice-query-designer__input--wide",
669
+ value: i.right?.kind === "values" ? i.right.values.join(", ") : i.right?.kind === "value" ? i.right.value : "",
670
+ placeholder: g("queryDesigner.filter.list", "values, separated by commas"),
671
+ "aria-label": a,
672
+ readOnly: o,
673
+ onChange: (r) => l({
674
+ ...i,
675
+ right: {
676
+ kind: "values",
677
+ values: r.target.value.split(",").map((c) => c.trim()).filter((c, q, u) => c || q < u.length - 1)
678
+ }
679
+ })
680
+ }
681
+ ),
682
+ s.takes === "days" && /* @__PURE__ */ e(
683
+ "input",
684
+ {
685
+ className: "nice-query-designer__input nice-query-designer__input--narrow",
686
+ type: "number",
687
+ min: 0,
688
+ value: i.right?.kind === "value" ? i.right.value : "",
689
+ "aria-label": g("queryDesigner.filter.days", "Days"),
690
+ readOnly: o,
691
+ onChange: (r) => l({ ...i, right: { kind: "value", value: r.target.value } })
692
+ }
693
+ ),
694
+ !o && /* @__PURE__ */ e(
695
+ _,
696
+ {
697
+ icon: "trash",
698
+ label: g("queryDesigner.filter.removeRule", "Remove the rule"),
699
+ onClick: d
700
+ }
701
+ )
702
+ ] });
703
+ }
704
+ function qe({ def: n, setQuery: i, readOnly: o }) {
705
+ const { t } = N(), l = n.query, d = I(l, t).filter((m) => !m.value.startsWith("c|")), g = M(l).filter((m) => m.aggregate), h = (m, s) => U(
706
+ l.tables.find((a) => a.id === m)?.columns.find((a) => a.name === s)?.dataType
707
+ );
708
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__panel nice-query-designer__panel--split", children: [
709
+ /* @__PURE__ */ p("section", { children: [
710
+ /* @__PURE__ */ e("h4", { children: t("queryDesigner.groups.by", "Group by") }),
711
+ /* @__PURE__ */ e("ul", { className: "nice-query-designer__rules", children: l.groupBy.map((m, s) => /* @__PURE__ */ p("li", { className: "nice-query-designer__rule", children: [
712
+ /* @__PURE__ */ e(
713
+ "select",
714
+ {
715
+ className: "nice-query-designer__input",
716
+ value: `${m.tableId}|${m.column}`,
717
+ disabled: o,
718
+ "aria-label": t("queryDesigner.filter.column", "Column"),
719
+ onChange: (a) => {
720
+ const [r, c] = a.target.value.split("|");
721
+ i({
722
+ ...l,
723
+ groupBy: l.groupBy.map((q, u) => u === s ? { tableId: r, column: c } : q)
724
+ });
725
+ },
726
+ children: d.map((a) => /* @__PURE__ */ e("option", { value: a.value, children: a.label }, a.value))
727
+ }
728
+ ),
729
+ h(m.tableId, m.column) === "date" && /* @__PURE__ */ p(
730
+ "select",
731
+ {
732
+ className: "nice-query-designer__input",
733
+ value: m.datePart ?? "",
734
+ disabled: o,
735
+ "aria-label": t("queryDesigner.groups.part", "Date part"),
736
+ onChange: (a) => i({
737
+ ...l,
738
+ groupBy: l.groupBy.map(
739
+ (r, c) => c === s ? {
740
+ ...r,
741
+ datePart: a.target.value || void 0
742
+ } : r
743
+ )
744
+ }),
745
+ children: [
746
+ /* @__PURE__ */ e("option", { value: "", children: t("queryDesigner.part.exact", "exact date") }),
747
+ ["year", "quarter", "month", "day"].map((a) => /* @__PURE__ */ e("option", { value: a, children: ee(t, a) }, a))
748
+ ]
749
+ }
750
+ ),
751
+ !o && /* @__PURE__ */ e(
752
+ _,
753
+ {
754
+ icon: "trash",
755
+ label: t("queryDesigner.groups.remove", "Stop grouping by it"),
756
+ onClick: () => i({ ...l, groupBy: l.groupBy.filter((a, r) => r !== s) })
757
+ }
758
+ )
759
+ ] }, `${m.tableId}|${m.column}|${s}`)) }),
760
+ !o && d.length > 0 && /* @__PURE__ */ p(
761
+ "button",
762
+ {
763
+ type: "button",
764
+ className: "nice-query-designer__chip",
765
+ onClick: () => {
766
+ const [m, s] = d[0].value.split("|");
767
+ i({ ...l, groupBy: [...l.groupBy, { tableId: m, column: s }] });
768
+ },
769
+ children: [
770
+ /* @__PURE__ */ e(k, { name: "plus", size: 12 }),
771
+ t("queryDesigner.groups.add", "Group by a column")
772
+ ]
773
+ }
774
+ ),
775
+ /* @__PURE__ */ e("p", { className: "nice-query-designer__muted", children: g.length ? t(
776
+ "queryDesigner.groups.totals",
777
+ "Totals: {list}. Every other column shown groups the rows."
778
+ ).replace(
779
+ "{list}",
780
+ g.map((m) => `${R(t, m.aggregate)} ${m.name}`).join(", ")
781
+ ) : t(
782
+ "queryDesigner.groups.noTotals",
783
+ "No totals yet: set one on a column (Columns tab, or the sum and count tools)."
784
+ ) })
785
+ ] }),
786
+ /* @__PURE__ */ p("section", { children: [
787
+ /* @__PURE__ */ e("h4", { children: t("queryDesigner.groups.having", "Keep only groups whose totals…") }),
788
+ /* @__PURE__ */ e(
789
+ x,
790
+ {
791
+ q: l,
792
+ group: l.having ?? j(),
793
+ root: !0,
794
+ totals: !0,
795
+ readOnly: o,
796
+ onChange: (m) => i({ ...l, having: m })
797
+ }
798
+ )
799
+ ] })
800
+ ] });
801
+ }
802
+ const se = ["INNER", "LEFT", "RIGHT", "FULL"];
803
+ function be({
804
+ def: n,
805
+ setQuery: i,
806
+ readOnly: o,
807
+ picked: t,
808
+ onSelectPart: l
809
+ }) {
810
+ const { t: d } = N(), g = n.query, h = new Map(g.tables.map((r) => [r.id, r])), m = (r) => ({
811
+ INNER: d("queryDesigner.joinType.inner", "Only rows that match"),
812
+ LEFT: d("queryDesigner.joinType.left", "Every row on the left"),
813
+ RIGHT: d("queryDesigner.joinType.right", "Every row on the right"),
814
+ FULL: d("queryDesigner.joinType.full", "Every row of both"),
815
+ CROSS: d("queryDesigner.joinType.cross", "Every combination")
816
+ })[r], s = (r, c) => i({ ...g, joins: g.joins.map((q) => q.id === r ? { ...q, ...c } : q) }), a = (r, c, q, u) => /* @__PURE__ */ e(
817
+ "select",
818
+ {
819
+ className: "nice-query-designer__input",
820
+ value: c,
821
+ disabled: o,
822
+ "aria-label": q,
823
+ onChange: (y) => u(y.target.value),
824
+ children: (r?.columns ?? []).map((y) => /* @__PURE__ */ e("option", { value: y.name, children: y.name }, y.name))
825
+ }
826
+ );
827
+ return g.joins.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-query-designer__muted", children: d(
828
+ "queryDesigner.joins.empty",
829
+ "No joins yet: drag from a column dot to a column of another table, use the join tool, or add a related table."
830
+ ) }) : /* @__PURE__ */ e("div", { className: "nice-query-designer__panel", children: /* @__PURE__ */ e("ul", { className: "nice-query-designer__joins", children: g.joins.map((r) => {
831
+ const c = h.get(r.leftTableId), q = h.get(r.rightTableId);
832
+ return /* @__PURE__ */ p(
833
+ "li",
834
+ {
835
+ className: `nice-query-designer__join-row${t.joinId === r.id ? " nice-query-designer__join-row--picked" : ""}`,
836
+ children: [
837
+ /* @__PURE__ */ p("div", { className: "nice-query-designer__rule", children: [
838
+ /* @__PURE__ */ p(
839
+ "button",
840
+ {
841
+ type: "button",
842
+ className: "nice-query-designer__chip",
843
+ onClick: () => l({ joinId: r.id }),
844
+ "aria-pressed": t.joinId === r.id,
845
+ children: [
846
+ /* @__PURE__ */ e(k, { name: "link", size: 12 }),
847
+ `${c ? w(c) : "?"} · ${q ? w(q) : "?"}`
848
+ ]
849
+ }
850
+ ),
851
+ /* @__PURE__ */ e(
852
+ "select",
853
+ {
854
+ className: "nice-query-designer__input",
855
+ value: r.type,
856
+ disabled: o,
857
+ "aria-label": d("queryDesigner.joins.type", "Which rows"),
858
+ onChange: (u) => s(r.id, { type: u.target.value }),
859
+ children: se.map((u) => /* @__PURE__ */ e("option", { value: u, children: m(u) }, u))
860
+ }
861
+ ),
862
+ /* @__PURE__ */ p(
863
+ "select",
864
+ {
865
+ className: "nice-query-designer__input",
866
+ value: r.nest ?? "flat",
867
+ disabled: o,
868
+ "aria-label": d("queryDesigner.joins.nest", "Where its columns go"),
869
+ onChange: (u) => s(r.id, { nest: u.target.value }),
870
+ children: [
871
+ /* @__PURE__ */ e("option", { value: "flat", children: d("queryDesigner.nest.flat", "In the row") }),
872
+ /* @__PURE__ */ e("option", { value: "object", children: d("queryDesigner.nest.object", "As one object") }),
873
+ /* @__PURE__ */ e("option", { value: "list", children: d("queryDesigner.nest.list", "As a list") })
874
+ ]
875
+ }
876
+ ),
877
+ (r.nest === "object" || r.nest === "list") && /* @__PURE__ */ e(
878
+ "input",
879
+ {
880
+ className: "nice-query-designer__input",
881
+ value: r.as ?? "",
882
+ placeholder: q ? w(q) : "",
883
+ "aria-label": d("queryDesigner.joins.as", "Name of the nested part"),
884
+ readOnly: o,
885
+ onChange: (u) => s(r.id, { as: u.target.value || void 0 })
886
+ }
887
+ ),
888
+ !o && /* @__PURE__ */ e(
889
+ _,
890
+ {
891
+ icon: "unlink",
892
+ label: d("queryDesigner.joins.remove", "Remove the join"),
893
+ onClick: () => i({ ...g, joins: g.joins.filter((u) => u.id !== r.id) })
894
+ }
895
+ )
896
+ ] }),
897
+ [{ leftColumn: r.leftColumn, rightColumn: r.rightColumn }, ...r.pairs ?? []].map(
898
+ (u, y) => /* @__PURE__ */ p("div", { className: "nice-query-designer__rule nice-query-designer__pair", children: [
899
+ a(
900
+ c,
901
+ u.leftColumn,
902
+ `${c ? w(c) : ""} ${d("queryDesigner.filter.column", "Column")}`,
903
+ (v) => y === 0 ? s(r.id, { leftColumn: v }) : s(r.id, {
904
+ pairs: r.pairs.map(
905
+ (b, f) => f === y - 1 ? { ...b, leftColumn: v } : b
906
+ )
907
+ })
908
+ ),
909
+ /* @__PURE__ */ e("span", { className: "nice-query-designer__muted", children: "=" }),
910
+ a(
911
+ q,
912
+ u.rightColumn,
913
+ `${q ? w(q) : ""} ${d("queryDesigner.filter.column", "Column")}`,
914
+ (v) => y === 0 ? s(r.id, { rightColumn: v }) : s(r.id, {
915
+ pairs: r.pairs.map(
916
+ (b, f) => f === y - 1 ? { ...b, rightColumn: v } : b
917
+ )
918
+ })
919
+ ),
920
+ y > 0 && !o && /* @__PURE__ */ e(
921
+ _,
922
+ {
923
+ icon: "minus",
924
+ label: d("queryDesigner.joins.removePair", "Remove this match"),
925
+ onClick: () => s(r.id, { pairs: r.pairs.filter((v, b) => b !== y - 1) })
926
+ }
927
+ )
928
+ ] }, y)
929
+ ),
930
+ !o && /* @__PURE__ */ p(
931
+ "button",
932
+ {
933
+ type: "button",
934
+ className: "nice-query-designer__chip",
935
+ onClick: () => s(r.id, {
936
+ pairs: [
937
+ ...r.pairs ?? [],
938
+ { leftColumn: r.leftColumn, rightColumn: r.rightColumn }
939
+ ]
940
+ }),
941
+ children: [
942
+ /* @__PURE__ */ e(k, { name: "plus", size: 12 }),
943
+ d("queryDesigner.joins.addPair", "Match one more column")
944
+ ]
945
+ }
946
+ )
947
+ ]
948
+ },
949
+ r.id
950
+ );
951
+ }) }) });
952
+ }
953
+ function fe({ def: n, commit: i, readOnly: o }) {
954
+ const { t } = N(), l = n.shape ?? "list", d = M(n.query), g = /* @__PURE__ */ new Map([["", []]]);
955
+ if (l !== "flat") {
956
+ for (const s of n.query.joins)
957
+ if (s.nest === "object" || s.nest === "list") {
958
+ const a = J(n.query, s.rightTableId).join(".");
959
+ g.has(a) || g.set(a, []);
960
+ }
961
+ }
962
+ for (const s of d) {
963
+ const a = l === "flat" ? "" : s.path.join(".");
964
+ g.set(a, [...g.get(a) ?? [], s]);
965
+ }
966
+ const h = new Set(
967
+ n.query.joins.filter((s) => s.nest === "list").map(
968
+ (s) => s.as || n.query.tables.find((a) => a.id === s.rightTableId)?.alias || n.query.tables.find((a) => a.id === s.rightTableId)?.name
969
+ )
970
+ ), m = [
971
+ {
972
+ id: "flat",
973
+ icon: "table",
974
+ label: t("queryDesigner.shape.flat", "Plain rows"),
975
+ hint: t(
976
+ "queryDesigner.shape.flatHint",
977
+ "Every joined column in the row: a table, a CSV, a chart."
978
+ )
979
+ },
980
+ {
981
+ id: "list",
982
+ icon: "list",
983
+ label: t("queryDesigner.shape.list", "Records with nested parts"),
984
+ hint: t(
985
+ "queryDesigner.shape.listHint",
986
+ "Joins nested as objects and lists: a list of invoices with their lines."
987
+ )
988
+ },
989
+ {
990
+ id: "object",
991
+ icon: "box",
992
+ label: t("queryDesigner.shape.object", "One record"),
993
+ hint: t(
994
+ "queryDesigner.shape.objectHint",
995
+ "The first record, e.g. WHERE Id = @id: a print of one invoice."
996
+ )
997
+ }
998
+ ];
999
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__panel nice-query-designer__panel--split", children: [
1000
+ /* @__PURE__ */ e("section", { className: "nice-query-designer__shapes", children: m.map((s) => /* @__PURE__ */ p(
1001
+ "button",
1002
+ {
1003
+ type: "button",
1004
+ className: `nice-query-designer__shape${l === s.id ? " nice-query-designer__shape--on" : ""}`,
1005
+ "aria-pressed": l === s.id,
1006
+ disabled: o,
1007
+ onClick: () => i({ ...n, shape: s.id }),
1008
+ children: [
1009
+ /* @__PURE__ */ e(k, { name: s.icon, size: 18 }),
1010
+ /* @__PURE__ */ e("strong", { children: s.label }),
1011
+ /* @__PURE__ */ e("span", { children: s.hint })
1012
+ ]
1013
+ },
1014
+ s.id
1015
+ )) }),
1016
+ /* @__PURE__ */ p("section", { children: [
1017
+ /* @__PURE__ */ e("h4", { children: t("queryDesigner.shape.result", "What it returns") }),
1018
+ /* @__PURE__ */ e("ul", { className: "nice-query-designer__tree", children: [...g.entries()].sort((s, a) => s[0].localeCompare(a[0])).map(([s, a]) => /* @__PURE__ */ p(
1019
+ "li",
1020
+ {
1021
+ style: { paddingInlineStart: `${s ? s.split(".").length * 16 : 0}px` },
1022
+ children: [
1023
+ /* @__PURE__ */ e(
1024
+ k,
1025
+ {
1026
+ name: s ? h.has(s.split(".").pop()) ? "list" : "box" : l === "object" ? "box" : l === "flat" ? "table" : "list",
1027
+ size: 14
1028
+ }
1029
+ ),
1030
+ /* @__PURE__ */ e("strong", { children: s ? s.split(".").pop() : n.label || n.key }),
1031
+ /* @__PURE__ */ e("span", { className: "nice-query-designer__muted", children: a.length ? a.map((r) => r.name).join(", ") : t("queryDesigner.shape.noColumns", "no columns picked yet") })
1032
+ ]
1033
+ },
1034
+ s || "."
1035
+ )) })
1036
+ ] })
1037
+ ] });
1038
+ }
1039
+ function ve({ def: n, commit: i, readOnly: o }) {
1040
+ const { t } = N(), l = G(n.query), d = n.parameters ?? [], g = [.../* @__PURE__ */ new Set([...d.map((s) => s.name), ...l])], h = (s) => d.find((a) => a.name === s) ?? { name: s }, m = (s, a) => {
1041
+ const r = d.some((c) => c.name === s);
1042
+ i({
1043
+ ...n,
1044
+ parameters: r ? d.map((c) => c.name === s ? { ...c, ...a } : c) : [...d, { name: s, ...a }]
1045
+ });
1046
+ };
1047
+ return g.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-query-designer__muted", children: t(
1048
+ "queryDesigner.params.empty",
1049
+ 'No parameters: pick "parameter" on the right of a rule (e.g. Id is parameter id).'
1050
+ ) }) : /* @__PURE__ */ e("div", { className: "nice-query-designer__panel", children: /* @__PURE__ */ p("table", { className: "nice-query-designer__grid", children: [
1051
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ p("tr", { children: [
1052
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.params.name", "Name") }),
1053
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.params.type", "Type") }),
1054
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.params.default", "Default") }),
1055
+ /* @__PURE__ */ e("th", { scope: "col", children: t("queryDesigner.params.required", "Required") }),
1056
+ /* @__PURE__ */ e("th", { scope: "col", children: /* @__PURE__ */ e("span", { className: "nice-query-designer__sr", children: t("queryDesigner.columns.actions", "Actions") }) })
1057
+ ] }) }),
1058
+ /* @__PURE__ */ e("tbody", { children: g.map((s) => {
1059
+ const a = h(s);
1060
+ return /* @__PURE__ */ p("tr", { children: [
1061
+ /* @__PURE__ */ p("td", { children: [
1062
+ /* @__PURE__ */ e("code", { children: s }),
1063
+ !l.includes(s) && /* @__PURE__ */ p("span", { className: "nice-query-designer__muted", children: [
1064
+ " ",
1065
+ t("queryDesigner.params.unused", "(not used)")
1066
+ ] })
1067
+ ] }),
1068
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ p(
1069
+ "select",
1070
+ {
1071
+ className: "nice-query-designer__input",
1072
+ value: a.dataType ?? "text",
1073
+ disabled: o,
1074
+ "aria-label": t("queryDesigner.params.type", "Type"),
1075
+ onChange: (r) => m(s, { dataType: r.target.value }),
1076
+ children: [
1077
+ /* @__PURE__ */ e("option", { value: "text", children: t("queryDesigner.type.text", "Text") }),
1078
+ /* @__PURE__ */ e("option", { value: "number", children: t("queryDesigner.type.number", "Number") }),
1079
+ /* @__PURE__ */ e("option", { value: "date", children: t("queryDesigner.type.date", "Date") }),
1080
+ /* @__PURE__ */ e("option", { value: "boolean", children: t("queryDesigner.type.boolean", "Yes / no") })
1081
+ ]
1082
+ }
1083
+ ) }),
1084
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
1085
+ "input",
1086
+ {
1087
+ className: "nice-query-designer__input",
1088
+ value: a.defaultValue ?? "",
1089
+ "aria-label": t("queryDesigner.params.default", "Default"),
1090
+ readOnly: o,
1091
+ onChange: (r) => m(s, { defaultValue: r.target.value || void 0 })
1092
+ }
1093
+ ) }),
1094
+ /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
1095
+ "input",
1096
+ {
1097
+ type: "checkbox",
1098
+ checked: !!a.required,
1099
+ disabled: o,
1100
+ "aria-label": t("queryDesigner.params.required", "Required"),
1101
+ onChange: (r) => m(s, { required: r.target.checked || void 0 })
1102
+ }
1103
+ ) }),
1104
+ /* @__PURE__ */ e("td", { className: "nice-query-designer__actions", children: !l.includes(s) && !o && /* @__PURE__ */ e(
1105
+ _,
1106
+ {
1107
+ icon: "trash",
1108
+ label: t("queryDesigner.params.remove", "Remove the parameter"),
1109
+ onClick: () => i({ ...n, parameters: d.filter((r) => r.name !== s) })
1110
+ }
1111
+ ) })
1112
+ ] }, s);
1113
+ }) })
1114
+ ] }) });
1115
+ }
1116
+ function De({ def: n, sourceSql: i }) {
1117
+ const { t: o } = N(), [t, l] = $(!1), d = Z(
1118
+ O(n.query, {
1119
+ dialect: n.dialect ?? "postgresql",
1120
+ shape: n.shape ?? "list",
1121
+ sources: i
1122
+ })
1123
+ );
1124
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__panel nice-query-designer__sql", children: [
1125
+ /* @__PURE__ */ e("div", { className: "nice-query-designer__rule", children: /* @__PURE__ */ p(
1126
+ "button",
1127
+ {
1128
+ type: "button",
1129
+ className: "nice-query-designer__chip",
1130
+ disabled: !d,
1131
+ onClick: () => {
1132
+ navigator.clipboard?.writeText(d).then(() => l(!0));
1133
+ },
1134
+ children: [
1135
+ /* @__PURE__ */ e(k, { name: t ? "check" : "copy", size: 12 }),
1136
+ t ? o("queryDesigner.sql.copied", "Copied") : o("queryDesigner.sql.copy", "Copy the SQL")
1137
+ ]
1138
+ }
1139
+ ) }),
1140
+ /* @__PURE__ */ e(H, { value: d, language: "sql", height: 220, lineNumbers: !0, readOnly: !0 })
1141
+ ] });
1142
+ }
1143
+ const ae = (n) => n == null ? "" : typeof n == "object" ? JSON.stringify(n) : String(n);
1144
+ function _e({ def: n, onPreview: i }) {
1145
+ const { t: o } = N(), t = [
1146
+ .../* @__PURE__ */ new Set([...(n.parameters ?? []).map((c) => c.name), ...G(n.query)])
1147
+ ], [l, d] = $({}), [g, h] = $({ kind: "idle" }), m = async () => {
1148
+ if (i) {
1149
+ h({ kind: "running" });
1150
+ try {
1151
+ const c = Object.fromEntries(
1152
+ t.map((q) => [
1153
+ q,
1154
+ l[q] ?? n.parameters?.find((u) => u.name === q)?.defaultValue ?? ""
1155
+ ])
1156
+ );
1157
+ h({ kind: "rows", rows: await i(n, c) });
1158
+ } catch (c) {
1159
+ h({ kind: "error", message: c instanceof Error ? c.message : String(c) });
1160
+ }
1161
+ }
1162
+ }, s = g.kind === "rows" ? g.rows.slice(0, 50) : [], a = s.some(
1163
+ (c) => Object.values(c).some((q) => typeof q == "object" && q !== null)
1164
+ ), r = [...new Set(s.flatMap((c) => Object.keys(c)))];
1165
+ return /* @__PURE__ */ p("div", { className: "nice-query-designer__panel", children: [
1166
+ /* @__PURE__ */ p("div", { className: "nice-query-designer__rule", children: [
1167
+ t.map((c) => /* @__PURE__ */ e(
1168
+ V,
1169
+ {
1170
+ label: c,
1171
+ labelPlacement: "inside",
1172
+ value: l[c] ?? n.parameters?.find((q) => q.name === c)?.defaultValue ?? "",
1173
+ onChange: (q) => d((u) => ({ ...u, [c]: q })),
1174
+ size: "sm"
1175
+ },
1176
+ c
1177
+ )),
1178
+ /* @__PURE__ */ p(
1179
+ "button",
1180
+ {
1181
+ type: "button",
1182
+ className: "nice-query-designer__chip",
1183
+ disabled: g.kind === "running",
1184
+ onClick: () => void m(),
1185
+ children: [
1186
+ /* @__PURE__ */ e(k, { name: "play", size: 12 }),
1187
+ o("queryDesigner.preview.run", "Run")
1188
+ ]
1189
+ }
1190
+ )
1191
+ ] }),
1192
+ g.kind === "error" && /* @__PURE__ */ e("p", { className: "nice-query-designer__error", role: "status", children: g.message }),
1193
+ g.kind === "rows" && /* @__PURE__ */ p("div", { className: "nice-query-designer__result", role: "status", children: [
1194
+ /* @__PURE__ */ e("span", { className: "nice-query-designer__muted", children: o("queryDesigner.preview.count", "{count} rows").replace(
1195
+ "{count}",
1196
+ String(g.rows.length)
1197
+ ) }),
1198
+ a ? /* @__PURE__ */ e("pre", { className: "nice-query-designer__json", children: JSON.stringify(s, null, 2) }) : s.length > 0 && /* @__PURE__ */ p("table", { className: "nice-query-designer__grid", children: [
1199
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { children: r.map((c) => /* @__PURE__ */ e("th", { scope: "col", children: c }, c)) }) }),
1200
+ /* @__PURE__ */ e("tbody", { children: s.map((c, q) => /* @__PURE__ */ e("tr", { children: r.map((u) => /* @__PURE__ */ e("td", { children: ae(c[u]) }, u)) }, q)) })
1201
+ ] })
1202
+ ] })
1203
+ ] });
1204
+ }
1205
+ export {
1206
+ he as ColumnsPanel,
1207
+ ye as FilterPanel,
1208
+ qe as GroupsPanel,
1209
+ be as JoinsPanel,
1210
+ ve as ParametersPanel,
1211
+ _e as PreviewPanel,
1212
+ fe as ShapePanel,
1213
+ De as SqlPanel
1214
+ };