@nsail/ui 0.1.709 → 0.1.721
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/dist/field.js +10 -0
- package/dist/format.js +18 -0
- package/dist/ns.css +3 -1
- package/package.json +2 -2
package/dist/field.js
CHANGED
|
@@ -27,6 +27,11 @@ export function NsField({ name, multiline = false, autoFocus, label }) {
|
|
|
27
27
|
const raw = event.target.value;
|
|
28
28
|
set(raw === "" ? (field.nullable ? null : undefined) : Number(raw));
|
|
29
29
|
}
|
|
30
|
+
// An emptied exact number is absent, as a number is: "" is no long the server reads.
|
|
31
|
+
function exact(event) {
|
|
32
|
+
const raw = event.target.value;
|
|
33
|
+
set(raw === "" ? (field.nullable ? null : undefined) : raw);
|
|
34
|
+
}
|
|
30
35
|
const common = {
|
|
31
36
|
id,
|
|
32
37
|
name,
|
|
@@ -40,6 +45,11 @@ export function NsField({ name, multiline = false, autoFocus, label }) {
|
|
|
40
45
|
case "boolean":
|
|
41
46
|
control = _jsx("input", { ...common, type: "checkbox", checked: value === true, onChange: (e) => set(e.target.checked) });
|
|
42
47
|
break;
|
|
48
|
+
case "bigint":
|
|
49
|
+
case "decimal":
|
|
50
|
+
// The value stays the text the user typed: a Number would round it.
|
|
51
|
+
control = (_jsx("input", { ...common, type: "text", inputMode: field.kind === "bigint" ? "numeric" : "decimal", value: value === null || value === undefined ? "" : String(value), onChange: exact }));
|
|
52
|
+
break;
|
|
43
53
|
case "integer":
|
|
44
54
|
case "number":
|
|
45
55
|
control = (_jsx("input", { ...common, type: "number", min: field.min, max: field.max, step: field.kind === "integer" ? 1 : "any", value: value === null || value === undefined ? "" : String(value), onChange: number }));
|
package/dist/format.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 Leonardo Porro and Emmanuel Arias. https://github.com/nsail-ar/nsail-stack
|
|
3
|
+
const whole = /^-?\d+$/;
|
|
4
|
+
const fixed = /^-?\d*(\.\d+)?$/;
|
|
3
5
|
/** A wire value as a person reads it: the member's kind decides, the language formats. */
|
|
4
6
|
export function display(strings, field, value) {
|
|
5
7
|
if (value === null || value === undefined || value === "") {
|
|
@@ -17,6 +19,11 @@ export function display(strings, field, value) {
|
|
|
17
19
|
}
|
|
18
20
|
case "datetime":
|
|
19
21
|
return new Date(String(value)).toLocaleString(strings.language, { dateStyle: "short", timeStyle: "short" });
|
|
22
|
+
// A value that is not the wire's text (a Number a product still writes) shows as a figure.
|
|
23
|
+
case "bigint":
|
|
24
|
+
return whole.test(String(value)) ? BigInt(String(value)).toLocaleString(strings.language) : Number(value).toLocaleString(strings.language);
|
|
25
|
+
case "decimal":
|
|
26
|
+
return fixed.test(String(value)) ? decimal(strings.language, String(value)) : Number(value).toLocaleString(strings.language);
|
|
20
27
|
case "integer":
|
|
21
28
|
case "number":
|
|
22
29
|
return Number(value).toLocaleString(strings.language);
|
|
@@ -24,3 +31,14 @@ export function display(strings, field, value) {
|
|
|
24
31
|
return String(value);
|
|
25
32
|
}
|
|
26
33
|
}
|
|
34
|
+
// A decimal carries up to 28 fraction digits and Intl stops at 20 (and reads a string as a
|
|
35
|
+
// Number before Intl V3): the whole part is grouped as a BigInt and the fraction kept as sent.
|
|
36
|
+
function decimal(language, text) {
|
|
37
|
+
const negative = text.startsWith("-");
|
|
38
|
+
const [whole, fraction] = (negative ? text.slice(1) : text).split(".");
|
|
39
|
+
const parts = new Intl.NumberFormat(language).formatToParts(-0.5);
|
|
40
|
+
const point = parts.find((part) => part.type === "decimal")?.value ?? ".";
|
|
41
|
+
const minus = parts.find((part) => part.type === "minusSign")?.value ?? "-";
|
|
42
|
+
const grouped = BigInt(whole === "" ? "0" : whole).toLocaleString(language);
|
|
43
|
+
return `${negative ? minus : ""}${grouped}${fraction ? `${point}${fraction}` : ""}`;
|
|
44
|
+
}
|
package/dist/ns.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsail/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.721",
|
|
4
4
|
"description": "The Ns* components for a React client, drawn from the descriptors an Sdk generates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react-dom": ">=19"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nsail/stack": "0.1.
|
|
38
|
+
"@nsail/stack": "0.1.721"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -p tsconfig.build.json && node -e \"require('fs').copyFileSync('src/ns.css', 'dist/ns.css')\"",
|