@nice2dev/ui 1.4.6 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # [1.0.27] — 2026-06-07
2
2
 
3
+ ## 1.4.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 27c3663: Development Studio, round 43 — part 7: the data source designer.
8
+
9
+ - **NiceQueryDesigner** (`@nice2dev/ui`):
10
+ - **Browser** — a database browser of the module's tables, its dependencies' tables and its other sources. Tick a
11
+ table to take every column; shift-click a range.
12
+ - **Canvas** — tables with their joins drawn between columns: drag from a column's dot, or join along foreign keys
13
+ with one tool. The same table can come twice under its own name.
14
+ - **Related tables** — added already nested: one object, or a list.
15
+ - **Icon tools** — pick columns in bulk, filter, sort, group, sum, count, computed column, distinct, shape, arrange,
16
+ undo/redo.
17
+ - **Tabs** — the result's columns (names, totals, order, one or many at once), the filter as groups of rules in
18
+ plain words, groups and totals (a date by month, HAVING), joins (match columns, which rows, where the table goes),
19
+ shape (plain rows, records with nested objects and lists, one record), parameters, SQL and a preview.
20
+ - **SQL for five databases** — PostgreSQL, SQL Server, MySQL, SQLite, Oracle. React-free:
21
+ - `generateQuerySql`;
22
+ - `planQuerySql` (the main query plus one query per nested list);
23
+ - `assembleQueryRows`, `quoteSqlName`, `functionSql`, `datePartSql`;
24
+ - the model helpers in `queryDesign` (`addTableInstance`, `pickColumns`, `suggestJoins`, `relatedTables`,
25
+ `addRelatedTable`, `outputColumns`, …).
26
+ - **The query model grows additively** — older consumers read it as before:
27
+ - `NiceQueryModel` gets `filter` / `having` (rule trees) and `computed`;
28
+ - `QueryJoin` gets `pairs`, `nest` and `as`; `QueryGroupBy` gets `datePart`; `QueryColumn` gets `order`;
29
+ - `NiceDataSourceDef` gets `shape`, `dialect`, `parameters` and `description`;
30
+ - a schema column gets `references`, and a schema table gets `entity` and `description`.
31
+ - **NiceDataSourceEditor** — a module data source of four kinds (`NiceModuleDataSource`): a designed query, SQL with
32
+ parameters and columns, a union of other sources, fixed rows. Model helpers: `moduleDataSourceColumns`,
33
+ `moduleDataSourceTable`, `standardDataSources`, …
34
+ - **The studio** (`@nice2dev/ui-forms`):
35
+ - data sources open in the designer;
36
+ - every entity's standard sources (all rows, one by Id) show read-only and are duplicated into editable ones;
37
+ - a new source starts the module's data sources file when there is none;
38
+ - entities give the designer their foreign keys;
39
+ - new prop `previewDataSource`.
40
+ - **OmniVerk** (`@nice2dev/erp-adapter`):
41
+ - `omniverkDataSourcesKind` for `*.datasources.json`, and a new file under the module's prefix;
42
+ - a warning for a data source the manifest lists that no file defines.
43
+
44
+ - Updated dependencies [27c3663]
45
+ - @nice2dev/i18n@1.4.7
46
+ - @nice2dev/ui-core@1.4.7
47
+
3
48
  ## 1.4.6
4
49
 
5
50
  ### Patch Changes
@@ -0,0 +1,370 @@
1
+ import { jsx as a, jsxs as m, Fragment as D } from "react/jsx-runtime";
2
+ import { useNiceTranslation as C, useControllableState as J, NiceIcon as w } from "@nice2dev/ui-core";
3
+ import { useMemo as z, useState as E } from "react";
4
+ import { NiceCheckbox as $ } from "../editors/inputs/NiceCheckbox.mjs";
5
+ import { NiceSelect as v } from "../editors/inputs/NiceSelect.mjs";
6
+ import { NiceTextInput as k } from "../editors/inputs/NiceTextInput.mjs";
7
+ import { NiceSimpleCodeEditor as R } from "../editors/rich/NiceCodeEditor.mjs";
8
+ import { newModuleDataSource as A, moduleDataSourceColumns as x, NICE_MODULE_DATA_SOURCE_KINDS as K, moduleDataSourceParameters as U } from "./moduleDataSource.mjs";
9
+ import { NiceQueryDesigner as B } from "./NiceQueryDesigner.mjs";
10
+ /* empty css */
11
+ const Q = ["", "postgresql", "sqlserver", "mysql", "sqlite", "oracle"], j = [], F = [], W = 50, Y = (i, b) => {
12
+ switch (b) {
13
+ case "query":
14
+ return i("dataSourceEditor.kind.query", "Visual query");
15
+ case "sql":
16
+ return i("dataSourceEditor.kind.sql", "SQL");
17
+ case "union":
18
+ return i("dataSourceEditor.kind.union", "Union of sources");
19
+ case "static":
20
+ return i("dataSourceEditor.kind.static", "Fixed rows");
21
+ }
22
+ };
23
+ function P({
24
+ legend: i,
25
+ rows: b,
26
+ onChange: S,
27
+ extra: h,
28
+ readOnly: d,
29
+ fresh: g
30
+ }) {
31
+ const { t: l } = C(), p = (s, t) => S(b.map((n, r) => r === s ? t : n));
32
+ return /* @__PURE__ */ m("fieldset", { className: "nice-data-source-editor__rows", children: [
33
+ /* @__PURE__ */ a("legend", { children: i }),
34
+ b.map((s, t) => /* @__PURE__ */ m("div", { className: "nice-data-source-editor__row", children: [
35
+ /* @__PURE__ */ a(
36
+ k,
37
+ {
38
+ label: l("dataSourceEditor.name", "Name"),
39
+ labelPlacement: "inside",
40
+ value: s.name,
41
+ onChange: (n) => p(t, { ...s, name: n }),
42
+ readOnly: d,
43
+ size: "sm"
44
+ }
45
+ ),
46
+ /* @__PURE__ */ a(
47
+ k,
48
+ {
49
+ label: l("dataSourceEditor.type", "Type"),
50
+ labelPlacement: "inside",
51
+ value: s.dataType ?? "",
52
+ onChange: (n) => p(t, { ...s, dataType: n || void 0 }),
53
+ readOnly: d,
54
+ size: "sm"
55
+ }
56
+ ),
57
+ h && /* @__PURE__ */ a(
58
+ k,
59
+ {
60
+ label: h.label,
61
+ labelPlacement: "inside",
62
+ value: h.get(s),
63
+ onChange: (n) => p(t, h.set(s, n)),
64
+ readOnly: d,
65
+ size: "sm"
66
+ }
67
+ ),
68
+ !d && /* @__PURE__ */ a(
69
+ "button",
70
+ {
71
+ type: "button",
72
+ className: "nice-data-source-editor__icon-btn",
73
+ "aria-label": l("dataSourceEditor.remove", "Remove"),
74
+ onClick: () => S(b.filter((n, r) => r !== t)),
75
+ children: /* @__PURE__ */ a(w, { name: "trash", size: 14 })
76
+ }
77
+ )
78
+ ] }, t)),
79
+ !d && /* @__PURE__ */ m(
80
+ "button",
81
+ {
82
+ type: "button",
83
+ className: "nice-data-source-editor__add",
84
+ onClick: () => S([...b, g(b.length + 1)]),
85
+ children: [
86
+ /* @__PURE__ */ a(w, { name: "plus", size: 14 }),
87
+ l("dataSourceEditor.add", "Add")
88
+ ]
89
+ }
90
+ )
91
+ ] });
92
+ }
93
+ function ce({
94
+ value: i,
95
+ defaultValue: b,
96
+ onChange: S,
97
+ schemas: h = j,
98
+ extraSchemas: d = j,
99
+ sources: g = F,
100
+ kinds: l = K,
101
+ dialects: p = Q,
102
+ onPreview: s,
103
+ readOnly: t = !1,
104
+ height: n,
105
+ className: r,
106
+ style: c,
107
+ id: f,
108
+ "data-testid": V
109
+ }) {
110
+ const { t: u } = C(), [o, I] = J({
111
+ value: i,
112
+ defaultValue: b ?? A("query", "source1"),
113
+ onChange: S
114
+ }), q = z(() => g.filter((e) => e.key !== o.key), [g, o.key]);
115
+ z(() => [...h, ...d], [h, d]);
116
+ const y = (e) => I(e), _ = (e) => y({ ...o, ...e }), L = (e) => {
117
+ e !== o.kind && y(A(e, o.key, { label: o.label, description: o.description }));
118
+ };
119
+ let N;
120
+ switch (o.kind) {
121
+ case "query":
122
+ N = /* @__PURE__ */ a(
123
+ B,
124
+ {
125
+ value: o,
126
+ onChange: (e) => y({ ...e, key: o.key, label: o.label }),
127
+ schemas: h,
128
+ extraSchemas: d,
129
+ sources: q,
130
+ onPreview: s,
131
+ readOnly: t,
132
+ height: n
133
+ }
134
+ );
135
+ break;
136
+ case "sql":
137
+ N = /* @__PURE__ */ m(D, { children: [
138
+ /* @__PURE__ */ a(
139
+ v,
140
+ {
141
+ label: u("dataSourceEditor.dialect", "Dialect"),
142
+ value: o.dialect ?? "",
143
+ options: p.map((e) => ({
144
+ value: e,
145
+ label: e || u("dataSourceEditor.dialect.portable", "Portable SQL")
146
+ })),
147
+ onChange: (e) => _({ dialect: String(e) || void 0 }),
148
+ disabled: t,
149
+ size: "sm"
150
+ }
151
+ ),
152
+ /* @__PURE__ */ a("div", { className: "nice-data-source-editor__code", children: /* @__PURE__ */ a(
153
+ R,
154
+ {
155
+ value: o.sql,
156
+ onChange: (e) => _({ sql: e }),
157
+ language: "sql",
158
+ height: 220,
159
+ lineNumbers: !0,
160
+ readOnly: t
161
+ }
162
+ ) }),
163
+ /* @__PURE__ */ a(
164
+ P,
165
+ {
166
+ legend: u("dataSourceEditor.parameters", "Parameters"),
167
+ rows: o.parameters ?? [],
168
+ onChange: (e) => _({ parameters: e }),
169
+ extra: {
170
+ label: u("dataSourceEditor.default", "Default"),
171
+ get: (e) => e.defaultValue ?? "",
172
+ set: (e, M) => ({ ...e, defaultValue: M || void 0 })
173
+ },
174
+ readOnly: t,
175
+ fresh: (e) => ({ name: `param${e}`, dataType: "string" })
176
+ }
177
+ ),
178
+ /* @__PURE__ */ a(
179
+ P,
180
+ {
181
+ legend: u("dataSourceEditor.columns", "Columns it returns"),
182
+ rows: o.columns ?? [],
183
+ onChange: (e) => _({ columns: e }),
184
+ readOnly: t,
185
+ fresh: (e) => ({ name: `column${e}`, dataType: "string" })
186
+ }
187
+ )
188
+ ] });
189
+ break;
190
+ case "union":
191
+ N = /* @__PURE__ */ m(D, { children: [
192
+ /* @__PURE__ */ a(
193
+ v,
194
+ {
195
+ label: u("dataSourceEditor.sources", "Sources, in order"),
196
+ value: o.sources,
197
+ options: q.map((e) => ({ value: e.key, label: e.label || e.key })),
198
+ onChange: (e) => _({ sources: (Array.isArray(e) ? e : [e]).filter(Boolean) }),
199
+ multiple: !0,
200
+ disabled: t,
201
+ size: "sm"
202
+ }
203
+ ),
204
+ /* @__PURE__ */ a(
205
+ $,
206
+ {
207
+ label: u("dataSourceEditor.distinct", "Drop rows that repeat"),
208
+ checked: !!o.distinct,
209
+ onChange: (e) => _({ distinct: e || void 0 }),
210
+ disabled: t
211
+ }
212
+ )
213
+ ] });
214
+ break;
215
+ case "static":
216
+ N = /* @__PURE__ */ a(
217
+ G,
218
+ {
219
+ rows: o.rows,
220
+ onChange: (e) => _({ rows: e }),
221
+ readOnly: t,
222
+ label: u("dataSourceEditor.rows", "Rows (JSON)"),
223
+ invalid: u("dataSourceEditor.rowsInvalid", "Rows must be a JSON list of objects.")
224
+ }
225
+ );
226
+ break;
227
+ }
228
+ const T = x(o, { sources: g });
229
+ return /* @__PURE__ */ m(
230
+ "div",
231
+ {
232
+ id: f,
233
+ className: `nice-data-source-editor${r ? ` ${r}` : ""}`,
234
+ style: c,
235
+ "data-testid": V,
236
+ children: [
237
+ /* @__PURE__ */ m("div", { className: "nice-data-source-editor__head", children: [
238
+ /* @__PURE__ */ a(
239
+ k,
240
+ {
241
+ label: u("dataSourceEditor.key", "Key"),
242
+ value: o.key,
243
+ onChange: (e) => _({ key: e }),
244
+ readOnly: t,
245
+ size: "sm"
246
+ }
247
+ ),
248
+ /* @__PURE__ */ a(
249
+ k,
250
+ {
251
+ label: u("dataSourceEditor.label", "Name"),
252
+ value: o.label ?? "",
253
+ onChange: (e) => _({ label: e || void 0 }),
254
+ readOnly: t,
255
+ size: "sm"
256
+ }
257
+ ),
258
+ /* @__PURE__ */ a(
259
+ v,
260
+ {
261
+ label: u("dataSourceEditor.kind", "Kind"),
262
+ value: o.kind,
263
+ options: l.map((e) => ({ value: e, label: Y(u, e) })),
264
+ onChange: (e) => L(String(e)),
265
+ disabled: t,
266
+ size: "sm"
267
+ }
268
+ )
269
+ ] }),
270
+ /* @__PURE__ */ a("div", { className: `nice-data-source-editor__body nice-data-source-editor__body--${o.kind}`, children: N }),
271
+ T.length > 0 && o.kind !== "query" && /* @__PURE__ */ m("p", { className: "nice-data-source-editor__columns", children: [
272
+ /* @__PURE__ */ a("strong", { children: u("dataSourceEditor.gives", "Gives:") }),
273
+ " ",
274
+ T.map((e) => e.name).join(", ")
275
+ ] }),
276
+ s && o.kind !== "query" && /* @__PURE__ */ a(X, { def: o, onPreview: s })
277
+ ]
278
+ }
279
+ );
280
+ }
281
+ function G({
282
+ rows: i,
283
+ onChange: b,
284
+ readOnly: S,
285
+ label: h,
286
+ invalid: d
287
+ }) {
288
+ const [g, l] = E(() => JSON.stringify(i, null, 2)), [p, s] = E(!1);
289
+ return /* @__PURE__ */ m("div", { className: "nice-data-source-editor__code", children: [
290
+ /* @__PURE__ */ a("span", { className: "nice-data-source-editor__label", children: h }),
291
+ /* @__PURE__ */ a(
292
+ R,
293
+ {
294
+ value: g,
295
+ onChange: (t) => {
296
+ l(t);
297
+ try {
298
+ const n = JSON.parse(t), r = Array.isArray(n) && n.every((c) => typeof c == "object" && c !== null && !Array.isArray(c));
299
+ s(!r), r && b(n);
300
+ } catch {
301
+ s(!0);
302
+ }
303
+ },
304
+ language: "json",
305
+ height: 220,
306
+ lineNumbers: !0,
307
+ readOnly: S
308
+ }
309
+ ),
310
+ p && /* @__PURE__ */ a("p", { className: "nice-data-source-editor__error", role: "status", children: d })
311
+ ] });
312
+ }
313
+ const H = (i) => i == null ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
314
+ function X({
315
+ def: i,
316
+ onPreview: b
317
+ }) {
318
+ const { t: S } = C(), h = U(i), [d, g] = E({}), [l, p] = E({ kind: "idle" }), s = async () => {
319
+ p({ kind: "running" });
320
+ const r = Object.fromEntries(
321
+ h.map((c) => [c.name, d[c.name] ?? c.defaultValue ?? ""])
322
+ );
323
+ try {
324
+ p({ kind: "rows", rows: await b(i, r) });
325
+ } catch (c) {
326
+ p({ kind: "error", message: c instanceof Error ? c.message : String(c) });
327
+ }
328
+ }, t = l.kind === "rows" ? l.rows.slice(0, W) : [], n = [...new Set(t.flatMap((r) => Object.keys(r)))];
329
+ return /* @__PURE__ */ m("section", { className: "nice-data-source-editor__preview", children: [
330
+ /* @__PURE__ */ m("div", { className: "nice-data-source-editor__row", children: [
331
+ h.map((r) => /* @__PURE__ */ a(
332
+ k,
333
+ {
334
+ label: r.name,
335
+ value: d[r.name] ?? r.defaultValue ?? "",
336
+ onChange: (c) => g((f) => ({ ...f, [r.name]: c })),
337
+ size: "sm"
338
+ },
339
+ r.name
340
+ )),
341
+ /* @__PURE__ */ m(
342
+ "button",
343
+ {
344
+ type: "button",
345
+ className: "nice-data-source-editor__run",
346
+ onClick: () => void s(),
347
+ disabled: l.kind === "running",
348
+ children: [
349
+ /* @__PURE__ */ a(w, { name: "play", size: 14 }),
350
+ S("dataSourceEditor.preview", "Preview")
351
+ ]
352
+ }
353
+ )
354
+ ] }),
355
+ l.kind === "error" && /* @__PURE__ */ a("p", { className: "nice-data-source-editor__error", role: "status", children: l.message }),
356
+ l.kind === "rows" && /* @__PURE__ */ m("div", { className: "nice-data-source-editor__result", role: "status", children: [
357
+ /* @__PURE__ */ a("span", { className: "nice-data-source-editor__label", children: S("dataSourceEditor.rowsCount", "{count} rows").replace(
358
+ "{count}",
359
+ String(l.rows.length)
360
+ ) }),
361
+ t.length > 0 && /* @__PURE__ */ m("table", { className: "nice-data-source-editor__table", children: [
362
+ /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: n.map((r) => /* @__PURE__ */ a("th", { scope: "col", children: r }, r)) }) }),
363
+ /* @__PURE__ */ a("tbody", { children: t.map((r, c) => /* @__PURE__ */ a("tr", { children: n.map((f) => /* @__PURE__ */ a("td", { children: H(r[f]) }, f)) }, c)) })
364
+ ] })
365
+ ] })
366
+ ] });
367
+ }
368
+ export {
369
+ ce as NiceDataSourceEditor
370
+ };