@openg2p/registry-widgets 1.1.1 → 1.1.2-dev.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.
package/dist/index.js CHANGED
@@ -673,6 +673,21 @@ const getFormattedNumberLength = (value, format) => {
673
673
  const formatted = formatNumber(typeof value === 'string' ? parseFloat(value) : value, format);
674
674
  return formatted.length;
675
675
  };
676
+ const normalizeNumericDefault = (defaultValue, format) => {
677
+ if (defaultValue === undefined) {
678
+ return undefined;
679
+ }
680
+ if (defaultValue === null || defaultValue === '') {
681
+ return null;
682
+ }
683
+ const numValue = typeof defaultValue === 'number'
684
+ ? defaultValue
685
+ : parseNumber(String(defaultValue), format);
686
+ if (numValue === null || isNaN(numValue)) {
687
+ return undefined;
688
+ }
689
+ return applyDecimalPrecision(numValue, format);
690
+ };
676
691
 
677
692
  /**
678
693
  * Date input utilities for parsing, formatting, and validation
@@ -7447,7 +7462,18 @@ const TextInputWidget = ({ config }) => {
7447
7462
  };
7448
7463
 
7449
7464
  const NumberInputWidget = ({ config }) => {
7450
- const { value, formattedValue, error, touched, isEnabled, onChange, onBlur, config: widgetConfig, } = useBaseWidget({ config });
7465
+ const resolvedConfig = React.useMemo(() => {
7466
+ const rawDefault = config['widget-data-default'];
7467
+ if (rawDefault === undefined) {
7468
+ return config;
7469
+ }
7470
+ const normalizedDefault = normalizeNumericDefault(rawDefault, config['widget-data-format']);
7471
+ if (normalizedDefault === undefined || normalizedDefault === rawDefault) {
7472
+ return config;
7473
+ }
7474
+ return { ...config, 'widget-data-default': normalizedDefault };
7475
+ }, [config]);
7476
+ const { value, formattedValue, error, touched, isEnabled, onChange, onBlur, config: widgetConfig, } = useBaseWidget({ config: resolvedConfig });
7451
7477
  const { translate, translateConfig } = useWidgetTranslation();
7452
7478
  const formatConfig = widgetConfig['widget-data-format'];
7453
7479
  const validationConfig = widgetConfig['widget-data-validation'];
@@ -11798,6 +11824,7 @@ exports.getValueByPath = getValueByPath;
11798
11824
  exports.getWidgetValue = getWidgetValue;
11799
11825
  exports.initI18n = initI18n;
11800
11826
  exports.isAllowedKey = isAllowedKey;
11827
+ exports.normalizeNumericDefault = normalizeNumericDefault;
11801
11828
  exports.parseDataPath = parseDataPath;
11802
11829
  exports.parseNumber = parseNumber;
11803
11830
  exports.registerDefaultWidgets = registerDefaultWidgets;