@open-mercato/ui 0.10.1-develop.8287.1.7313a0fe67 → 0.10.1-develop.8291.1.6ec3aee41c
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/backend/CrudForm.js +12 -8
- package/dist/backend/CrudForm.js.map +2 -2
- package/dist/utils/format.js +46 -7
- package/dist/utils/format.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/CrudForm.tsx +19 -9
- package/src/backend/__tests__/CrudForm.accessibleLabels.test.tsx +12 -0
- package/src/utils/__tests__/format.test.ts +64 -0
- package/src/utils/format.ts +82 -6
package/dist/backend/CrudForm.js
CHANGED
|
@@ -90,7 +90,8 @@ import { useInjectionSpotEvents, InjectionSpot, useInjectionWidgets } from "./in
|
|
|
90
90
|
import { dispatchBackendMutationError } from "./injection/mutationEvents.js";
|
|
91
91
|
import { VersionHistoryAction } from "./version-history/VersionHistoryAction.js";
|
|
92
92
|
import { parseBooleanWithDefault } from "@open-mercato/shared/lib/boolean";
|
|
93
|
-
import { parseLocaleNumber, resolveLocaleNumberSeparators } from "@open-mercato/shared/lib/number";
|
|
93
|
+
import { parseLocaleDecimal, parseLocaleNumber, resolveLocaleNumberSeparators } from "@open-mercato/shared/lib/number";
|
|
94
|
+
import { addDecimals, decimalToString } from "@open-mercato/shared/lib/decimal";
|
|
94
95
|
import { cn } from "@open-mercato/shared/lib/utils";
|
|
95
96
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
96
97
|
import { getTelemetryRuntime } from "@open-mercato/shared/lib/telemetry/runtime";
|
|
@@ -3379,6 +3380,7 @@ function NumberInput({
|
|
|
3379
3380
|
placeholder,
|
|
3380
3381
|
autoFocus,
|
|
3381
3382
|
onSubmit,
|
|
3383
|
+
exact = false,
|
|
3382
3384
|
disabled,
|
|
3383
3385
|
readOnly
|
|
3384
3386
|
}) {
|
|
@@ -3393,9 +3395,9 @@ function NumberInput({
|
|
|
3393
3395
|
const parse = React.useCallback(
|
|
3394
3396
|
(raw) => {
|
|
3395
3397
|
if (raw === "") return void 0;
|
|
3396
|
-
return parseLocaleNumber(raw, locale) ?? void 0;
|
|
3398
|
+
return (exact ? parseLocaleDecimal(raw, locale) : parseLocaleNumber(raw, locale)) ?? void 0;
|
|
3397
3399
|
},
|
|
3398
|
-
[locale]
|
|
3400
|
+
[exact, locale]
|
|
3399
3401
|
);
|
|
3400
3402
|
const commitIfChanged = React.useCallback(() => {
|
|
3401
3403
|
if (local === serializedValue) return;
|
|
@@ -3421,12 +3423,13 @@ function NumberInput({
|
|
|
3421
3423
|
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
3422
3424
|
e.preventDefault();
|
|
3423
3425
|
const base = parse(local) ?? 0;
|
|
3424
|
-
const
|
|
3426
|
+
const step = e.key === "ArrowUp" ? 1 : -1;
|
|
3427
|
+
const stepped = exact ? decimalToString(addDecimals(base, step)) : Number((Number(base) + step).toFixed(10));
|
|
3425
3428
|
const { decimal } = resolveLocaleNumberSeparators(locale);
|
|
3426
3429
|
setLocal(decimal === "." ? String(stepped) : String(stepped).replace(".", decimal));
|
|
3427
3430
|
onChange(stepped);
|
|
3428
3431
|
}
|
|
3429
|
-
}, [commitIfChanged, local, locale, onChange, onSubmit, parse]);
|
|
3432
|
+
}, [commitIfChanged, exact, local, locale, onChange, onSubmit, parse]);
|
|
3430
3433
|
const handleFocus = React.useCallback(() => {
|
|
3431
3434
|
isFocusedRef.current = true;
|
|
3432
3435
|
}, []);
|
|
@@ -3612,7 +3615,7 @@ const SimpleMarkdownEditor = React.memo(function SimpleMarkdownEditor2({ value =
|
|
|
3612
3615
|
] });
|
|
3613
3616
|
}, (prev, next) => prev.value === next.value);
|
|
3614
3617
|
function supportsWrapperBlurValidation(field) {
|
|
3615
|
-
return field.type === "text" || field.type === "password" || field.type === "textarea" || field.type === "checkbox" || field.type === "select" || field.type === "number";
|
|
3618
|
+
return field.type === "text" || field.type === "password" || field.type === "textarea" || field.type === "checkbox" || field.type === "select" || field.type === "number" || field.type === "decimal";
|
|
3616
3619
|
}
|
|
3617
3620
|
const ListboxMultiSelect = React.memo(function ListboxMultiSelect2({
|
|
3618
3621
|
options,
|
|
@@ -3737,7 +3740,7 @@ const FieldControl = React.memo(
|
|
|
3737
3740
|
const singleSelectLabel = singleSelectValue ? options.find((option) => option.value === singleSelectValue)?.label : void 0;
|
|
3738
3741
|
const controlId = `${formId}-field-${field.id}`;
|
|
3739
3742
|
const labelId = `${controlId}-label`;
|
|
3740
|
-
const hasSingleControl = field.type === "text" || field.type === "password" || field.type === "number" || field.type === "textarea" || field.type === "combobox" || field.type === "select" && !builtin?.multiple;
|
|
3743
|
+
const hasSingleControl = field.type === "text" || field.type === "password" || field.type === "number" || field.type === "decimal" || field.type === "textarea" || field.type === "combobox" || field.type === "select" && !builtin?.multiple;
|
|
3741
3744
|
return /* @__PURE__ */ jsxs(
|
|
3742
3745
|
"div",
|
|
3743
3746
|
{
|
|
@@ -3789,7 +3792,7 @@ const FieldControl = React.memo(
|
|
|
3789
3792
|
inputType: "password"
|
|
3790
3793
|
}
|
|
3791
3794
|
),
|
|
3792
|
-
field.type === "number" && /* @__PURE__ */ jsx(
|
|
3795
|
+
(field.type === "number" || field.type === "decimal") && /* @__PURE__ */ jsx(
|
|
3793
3796
|
NumberInput,
|
|
3794
3797
|
{
|
|
3795
3798
|
id: controlId,
|
|
@@ -3798,6 +3801,7 @@ const FieldControl = React.memo(
|
|
|
3798
3801
|
onChange: fieldSetValue,
|
|
3799
3802
|
autoFocus: autoFocusField,
|
|
3800
3803
|
onSubmit: onSubmitRequest,
|
|
3804
|
+
exact: field.type === "decimal",
|
|
3801
3805
|
disabled,
|
|
3802
3806
|
readOnly
|
|
3803
3807
|
}
|