@declarion/react 0.365.0 → 0.366.0

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.
@@ -8,20 +8,21 @@ import { refLabel as o, useRefRecords as s } from "../../hooks/useRefRecords.js"
8
8
  import { useSchema as c } from "../../hooks/useSchema.js";
9
9
  import { renderField as l } from "../fields/index.js";
10
10
  import { coerceDisplayString as u } from "../../lib/display-value.js";
11
- import { useText as d } from "../../hooks/useText.js";
12
- import { RetryButton as f } from "../primitives/RetryButton.js";
13
- import { useState as p } from "react";
14
- import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
11
+ import { formatDecimalText as d } from "../../lib/decimal-text.js";
12
+ import { useText as f } from "../../hooks/useText.js";
13
+ import { RetryButton as p } from "../primitives/RetryButton.js";
14
+ import { useState as m } from "react";
15
+ import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
15
16
  // src/components/params/param-editors.tsx
16
- var _ = t["undo-2"];
17
- function v({ param: t, description: n, onReset: r }) {
18
- let a = d(), [o, s] = p(!1);
19
- return /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h(e, {
17
+ var v = t["undo-2"];
18
+ function y({ param: t, description: n, onReset: r }) {
19
+ let a = f(), [o, s] = m(!1);
20
+ return /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(e, {
20
21
  size: "xs",
21
- icon: /* @__PURE__ */ h(_, { size: 12 }),
22
+ icon: /* @__PURE__ */ g(v, { size: 12 }),
22
23
  onClick: () => s(!0),
23
24
  children: a("params.reset", "Reset to default")
24
- }), /* @__PURE__ */ h(i, {
25
+ }), /* @__PURE__ */ g(i, {
25
26
  open: o,
26
27
  onOpenChange: s,
27
28
  title: a("params.reset_confirm.title", "Reset {name} to default?", { name: a(t.name) || t.code }),
@@ -30,8 +31,8 @@ function v({ param: t, description: n, onReset: r }) {
30
31
  onConfirm: () => r(t)
31
32
  })] });
32
33
  }
33
- function y({ text: e, onRetry: n }) {
34
- return /* @__PURE__ */ g("div", {
34
+ function b({ text: e, onRetry: n }) {
35
+ return /* @__PURE__ */ _("div", {
35
36
  style: {
36
37
  padding: "8px 10px",
37
38
  background: "var(--danger-soft)",
@@ -43,30 +44,30 @@ function y({ text: e, onRetry: n }) {
43
44
  alignItems: "center"
44
45
  },
45
46
  children: [
46
- /* @__PURE__ */ h(t.info, { size: 13 }),
47
- /* @__PURE__ */ h("span", { children: e }),
48
- n && /* @__PURE__ */ h(f, { onRetry: n })
47
+ /* @__PURE__ */ g(t.info, { size: 13 }),
48
+ /* @__PURE__ */ g("span", { children: e }),
49
+ n && /* @__PURE__ */ g(p, { onRetry: n })
49
50
  ]
50
51
  });
51
52
  }
52
- function b(e, t) {
53
- let n = d(), { data: r } = c(), i = e.flatMap((e) => e.ref?.entity && e.value != null && e.value !== "" ? [{
53
+ function x(e, t) {
54
+ let n = f(), { data: r } = c(), i = e.flatMap((e) => e.ref?.entity && e.value != null && e.value !== "" ? [{
54
55
  ref: e.ref,
55
56
  value: e.value
56
57
  }] : []), { refs: a } = s(i, t, r?.entities);
57
58
  return (e) => e.ref?.entity ? o(n, a, e.ref, e.value, r?.entities) : void 0;
58
59
  }
59
- function x({ type: e, value: t, values: n, structure: r, label: i, maxWidth: a = 180 }) {
60
- let o = d(), { data: s } = c(), l = (e) => {
60
+ function S({ type: e, value: t, values: n, structure: r, label: i, maxWidth: a = 180 }) {
61
+ let o = f(), { data: s } = c(), l = (e) => {
61
62
  let t = n?.find((t) => t.code === e);
62
63
  return t && o(t.name) || u(e);
63
- }, f = (e) => {
64
+ }, p = (e) => {
64
65
  let t = r ? s?.structures?.[r]?.fields : void 0;
65
66
  return t ? [...t].filter(([t]) => t in e).map(([e, t]) => t.display ? o(t.display.name) : e).join(", ") || "—" : `{${Object.keys(e).join(", ")}}`;
66
- }, p;
67
- return p = i === void 0 ? t == null || t === "" ? "—" : n && n.length > 0 ? (Array.isArray(t) ? t.map(l).join(", ") : l(t)) || "—" : e === "bool" ? t ? o("params.value.on", "On") : o("params.value.off", "Off") : e === "multilang" || e === "multilang_text" ? o(t) || "—" : e === "multilang_array" && Array.isArray(t) ? t.map((e) => o(e)).join(", ") || "—" : e === "json" || e === "structure" ? Array.isArray(t) ? `[${t.map((e) => e && typeof e == "object" ? "{…}" : u(e)).join(", ")}]` : t && typeof t == "object" ? f(t) : u(t) : u(t) : i, /* @__PURE__ */ h("span", {
67
+ }, m;
68
+ return m = i === void 0 ? t == null || t === "" ? "—" : n && n.length > 0 ? (Array.isArray(t) ? t.map(l).join(", ") : l(t)) || "—" : (e === "int" || e === "decimal") && (typeof t == "number" || typeof t == "string") ? d(String(t), new Intl.NumberFormat(o.language)) : e === "bool" ? t ? o("params.value.on", "On") : o("params.value.off", "Off") : e === "multilang" || e === "multilang_text" ? o(t) || "—" : e === "multilang_array" && Array.isArray(t) ? t.map((e) => o(e)).join(", ") || "—" : e === "json" || e === "structure" ? Array.isArray(t) ? `[${t.map((e) => e && typeof e == "object" ? "{…}" : u(e)).join(", ")}]` : t && typeof t == "object" ? p(t) : u(t) : u(t) : i, /* @__PURE__ */ g("span", {
68
69
  className: "mono",
69
- title: p,
70
+ title: m,
70
71
  style: {
71
72
  display: "inline-block",
72
73
  verticalAlign: "middle",
@@ -77,16 +78,16 @@ function x({ type: e, value: t, values: n, structure: r, label: i, maxWidth: a =
77
78
  textOverflow: "ellipsis",
78
79
  whiteSpace: "nowrap"
79
80
  },
80
- children: p
81
+ children: m
81
82
  });
82
83
  }
83
- function S({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
84
- let u = d(), [f, m] = p(() => w(i, o)), [_, v] = p(!1), [b, x] = p(null);
84
+ function C({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
85
+ let u = f(), [d, p] = m(() => T(i, o)), [h, v] = m(!1), [y, x] = m(null);
85
86
  async function S() {
86
87
  x(null);
87
88
  let e;
88
89
  try {
89
- e = T(u, f);
90
+ e = E(u, d);
90
91
  } catch (e) {
91
92
  x(String(e instanceof Error ? e.message : e));
92
93
  return;
@@ -98,21 +99,21 @@ function S({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
98
99
  v(!1);
99
100
  }
100
101
  }
101
- return /* @__PURE__ */ g(a, {
102
+ return /* @__PURE__ */ _(a, {
102
103
  label: u(i.name) || i.code,
103
104
  maxWidth: 440,
104
105
  onClose: c,
105
106
  testId: "param-edit-dialog",
106
107
  children: [
107
- /* @__PURE__ */ g("div", {
108
+ /* @__PURE__ */ _("div", {
108
109
  style: { padding: "14px 18px 0" },
109
- children: [/* @__PURE__ */ h("div", {
110
+ children: [/* @__PURE__ */ g("div", {
110
111
  style: {
111
112
  fontSize: 14,
112
113
  fontWeight: 600
113
114
  },
114
115
  children: u(i.name) || i.code
115
- }), i.description && /* @__PURE__ */ h("div", {
116
+ }), i.description && /* @__PURE__ */ g("div", {
116
117
  style: {
117
118
  fontSize: 11.5,
118
119
  color: "var(--text-3)",
@@ -121,7 +122,7 @@ function S({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
121
122
  children: u(i.description)
122
123
  })]
123
124
  }),
124
- /* @__PURE__ */ g("div", {
125
+ /* @__PURE__ */ _("div", {
125
126
  style: {
126
127
  padding: "12px 18px 16px",
127
128
  display: "flex",
@@ -130,16 +131,16 @@ function S({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
130
131
  overflowY: "auto"
131
132
  },
132
133
  children: [
133
- /* @__PURE__ */ h(n, { children: u("params.value", "Value") }),
134
- /* @__PURE__ */ h(C, {
134
+ /* @__PURE__ */ g(n, { children: u("params.value", "Value") }),
135
+ /* @__PURE__ */ g(w, {
135
136
  param: i,
136
- value: f,
137
- onChange: m
137
+ value: d,
138
+ onChange: p
138
139
  }),
139
- (b || s) && /* @__PURE__ */ h(y, { text: b || s })
140
+ (y || s) && /* @__PURE__ */ g(b, { text: y || s })
140
141
  ]
141
142
  }),
142
- /* @__PURE__ */ g("div", {
143
+ /* @__PURE__ */ _("div", {
143
144
  style: {
144
145
  padding: "10px 16px",
145
146
  borderTop: "1px solid var(--divider)",
@@ -149,32 +150,32 @@ function S({ param: i, current: o, error: s, onCancel: c, onSave: l }) {
149
150
  flexShrink: 0
150
151
  },
151
152
  children: [
152
- /* @__PURE__ */ h("div", { style: { flex: 1 } }),
153
- /* @__PURE__ */ h(e, {
153
+ /* @__PURE__ */ g("div", { style: { flex: 1 } }),
154
+ /* @__PURE__ */ g(e, {
154
155
  onClick: c,
155
156
  children: u("dialog.cancel", "Cancel")
156
157
  }),
157
- /* @__PURE__ */ h(e, {
158
+ /* @__PURE__ */ g(e, {
158
159
  kind: "primary",
159
- icon: h(_ ? r : t.check, { size: 13 }),
160
+ icon: g(h ? r : t.check, { size: 13 }),
160
161
  onClick: S,
161
- disabled: _,
162
- children: _ ? u("dialog.saving", "Saving…") : u("dialog.save", "Save")
162
+ disabled: h,
163
+ children: h ? u("dialog.saving", "Saving…") : u("dialog.save", "Save")
163
164
  })
164
165
  ]
165
166
  })
166
167
  ]
167
168
  });
168
169
  }
169
- function C({ param: e, value: t, onChange: n }) {
170
- let r = d(), i = {
170
+ function w({ param: e, value: t, onChange: n }) {
171
+ let r = f(), i = {
171
172
  type: e.type,
172
173
  structure: e.structure,
173
174
  array: e.array,
174
175
  values: e.values,
175
176
  ref: e.ref
176
177
  };
177
- return /* @__PURE__ */ h(m, { children: l({
178
+ return /* @__PURE__ */ g(h, { children: l({
178
179
  field: i,
179
180
  fieldName: e.code,
180
181
  value: t,
@@ -183,22 +184,22 @@ function C({ param: e, value: t, onChange: n }) {
183
184
  t: r
184
185
  }) });
185
186
  }
186
- function w(e, t) {
187
+ function T(e, t) {
187
188
  return e.type === "bool" ? t === !0 : e.type === "structure" ? t ?? (e.array ? [] : {}) : t ?? null;
188
189
  }
189
- function T(e, t) {
190
+ function E(e, t) {
190
191
  if (t == null) throw Error(e("params.value.required", "Enter a value."));
191
192
  return t;
192
193
  }
193
- var E = /* @__PURE__ */ new Set([
194
+ var D = /* @__PURE__ */ new Set([
194
195
  "server",
195
196
  "database",
196
197
  "auth",
197
198
  "sso",
198
199
  "seeder"
199
200
  ]);
200
- function D(e) {
201
+ function O(e) {
201
202
  let t = e.scopes ?? [];
202
- return t.length === 0 ? !E.has(e.category ?? "") : t.includes("tenant");
203
+ return t.length === 0 ? !D.has(e.category ?? "") : t.includes("tenant");
203
204
  }
204
- export { S as EditParamDialog, y as ErrorLine, v as ResetParamControl, x as ValuePreview, D as paramTenantEditable, b as useParamRefLabels };
205
+ export { C as EditParamDialog, b as ErrorLine, y as ResetParamControl, S as ValuePreview, O as paramTenantEditable, x as useParamRefLabels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@declarion/react",
3
- "version": "0.365.0",
3
+ "version": "0.366.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "React SDK for Declarion, the schema-driven business apps platform.",