@jobber/components 7.10.0 → 7.11.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.
Files changed (106) hide show
  1. package/dist/Autocomplete/index.cjs +1 -0
  2. package/dist/Autocomplete/index.mjs +1 -0
  3. package/dist/Card/index.cjs +3 -0
  4. package/dist/Card/index.mjs +3 -0
  5. package/dist/Chip/index.cjs +1 -0
  6. package/dist/Chip/index.mjs +1 -0
  7. package/dist/Chips/InternalChipDismissible/hooks/index.cjs +1 -0
  8. package/dist/Chips/InternalChipDismissible/hooks/index.mjs +1 -0
  9. package/dist/Chips/InternalChipDismissible/index.cjs +1 -0
  10. package/dist/Chips/InternalChipDismissible/index.mjs +1 -0
  11. package/dist/Chips/index.cjs +1 -0
  12. package/dist/Chips/index.mjs +1 -0
  13. package/dist/Combobox/components/ComboboxActivator/index.cjs +1 -0
  14. package/dist/Combobox/components/ComboboxActivator/index.mjs +1 -0
  15. package/dist/Combobox/components/ComboboxContent/index.cjs +1 -0
  16. package/dist/Combobox/components/ComboboxContent/index.mjs +1 -0
  17. package/dist/Combobox/components/ComboboxTrigger/index.cjs +1 -0
  18. package/dist/Combobox/components/ComboboxTrigger/index.mjs +1 -0
  19. package/dist/Combobox/index.cjs +1 -0
  20. package/dist/Combobox/index.mjs +1 -0
  21. package/dist/ConfirmationModal/index.cjs +1 -0
  22. package/dist/ConfirmationModal/index.mjs +1 -0
  23. package/dist/DataDump/index.cjs +3 -0
  24. package/dist/DataDump/index.mjs +3 -0
  25. package/dist/DataList/components/DataListActions/index.cjs +1 -0
  26. package/dist/DataList/components/DataListActions/index.mjs +1 -0
  27. package/dist/DataList/components/DataListBulkActions/index.cjs +1 -0
  28. package/dist/DataList/components/DataListBulkActions/index.mjs +1 -0
  29. package/dist/DataList/components/DataListFilters/components/DataListSort/index.cjs +1 -0
  30. package/dist/DataList/components/DataListFilters/components/DataListSort/index.mjs +1 -0
  31. package/dist/DataList/components/DataListFilters/index.cjs +1 -0
  32. package/dist/DataList/components/DataListFilters/index.mjs +1 -0
  33. package/dist/DataList/components/DataListHeader/index.cjs +1 -0
  34. package/dist/DataList/components/DataListHeader/index.mjs +1 -0
  35. package/dist/DataList/components/DataListItem/index.cjs +1 -0
  36. package/dist/DataList/components/DataListItem/index.mjs +1 -0
  37. package/dist/DataList/components/DataListItemActions/index.cjs +1 -0
  38. package/dist/DataList/components/DataListItemActions/index.mjs +1 -0
  39. package/dist/DataList/components/DataListItemActionsOverflow/index.cjs +1 -0
  40. package/dist/DataList/components/DataListItemActionsOverflow/index.mjs +1 -0
  41. package/dist/DataList/components/DataListItems/index.cjs +1 -0
  42. package/dist/DataList/components/DataListItems/index.mjs +1 -0
  43. package/dist/DataList/components/DataListLayout/index.cjs +1 -0
  44. package/dist/DataList/components/DataListLayout/index.mjs +1 -0
  45. package/dist/DataList/components/DataListLayoutActions/index.cjs +1 -0
  46. package/dist/DataList/components/DataListLayoutActions/index.mjs +1 -0
  47. package/dist/DataList/index.cjs +1 -0
  48. package/dist/DataList/index.mjs +1 -0
  49. package/dist/DatePicker/index.cjs +1 -0
  50. package/dist/DatePicker/index.mjs +1 -0
  51. package/dist/DrawerRoot-cjs.js +181 -968
  52. package/dist/DrawerRoot-es.js +5 -734
  53. package/dist/FormatFile/index.cjs +1 -0
  54. package/dist/FormatFile/index.mjs +1 -0
  55. package/dist/Gallery/index.cjs +1 -0
  56. package/dist/Gallery/index.mjs +1 -0
  57. package/dist/InputDate/index.cjs +1 -0
  58. package/dist/InputDate/index.mjs +1 -0
  59. package/dist/InputNumberExperimental-cjs.js +783 -0
  60. package/dist/InputNumberExperimental-es.js +763 -0
  61. package/dist/LightBox/index.cjs +1 -0
  62. package/dist/LightBox/index.mjs +1 -0
  63. package/dist/Menu/index.cjs +3 -0
  64. package/dist/Menu/index.mjs +3 -0
  65. package/dist/MenuSubmenuTrigger-cjs.js +202 -447
  66. package/dist/MenuSubmenuTrigger-es.js +7 -249
  67. package/dist/Modal/index.cjs +1 -0
  68. package/dist/Modal/index.mjs +1 -0
  69. package/dist/NumberFieldInput-cjs.js +1828 -0
  70. package/dist/NumberFieldInput-es.js +1788 -0
  71. package/dist/Page/index.cjs +3 -0
  72. package/dist/Page/index.mjs +3 -0
  73. package/dist/Popover/index.cjs +1 -0
  74. package/dist/Popover/index.mjs +1 -0
  75. package/dist/Tooltip/index.cjs +1 -0
  76. package/dist/Tooltip/index.mjs +1 -0
  77. package/dist/docs/Menu/Menu.md +197 -37
  78. package/dist/floating-ui.react-cjs.js +35 -34
  79. package/dist/floating-ui.react-dom-cjs.js +65 -64
  80. package/dist/floating-ui.react-dom-es.js +2 -1
  81. package/dist/floating-ui.react-es.js +2 -1
  82. package/dist/floating-ui.utils.dom-cjs.js +185 -0
  83. package/dist/floating-ui.utils.dom-es.js +165 -0
  84. package/dist/index.cjs +3 -0
  85. package/dist/index.esm-cjs.js +0 -183
  86. package/dist/index.esm-es.js +1 -165
  87. package/dist/index.mjs +3 -0
  88. package/dist/primitives/BottomSheet/index.cjs +3 -1
  89. package/dist/primitives/BottomSheet/index.mjs +3 -1
  90. package/dist/primitives/InputNumberExperimental/InputNumberExperimental.d.ts +20 -0
  91. package/dist/primitives/InputNumberExperimental/index.cjs +22 -0
  92. package/dist/primitives/InputNumberExperimental/index.d.ts +2 -0
  93. package/dist/primitives/InputNumberExperimental/index.mjs +16 -0
  94. package/dist/primitives/InputNumberExperimental/types.d.ts +147 -0
  95. package/dist/primitives/index.cjs +9 -1
  96. package/dist/primitives/index.d.ts +2 -0
  97. package/dist/primitives/index.mjs +8 -1
  98. package/dist/styles.css +499 -0
  99. package/dist/unstyledPrimitives/index.cjs +264 -2039
  100. package/dist/unstyledPrimitives/index.mjs +72 -1847
  101. package/dist/useBaseUiId-cjs.js +275 -0
  102. package/dist/useBaseUiId-es.js +251 -0
  103. package/dist/useValueChanged-cjs.js +820 -0
  104. package/dist/useValueChanged-es.js +736 -0
  105. package/package.json +2 -2
  106. package/rollup.config.mjs +13 -2
@@ -1,11 +1,15 @@
1
- import { f as useDialogRootContext, aV as useDrawerProviderContext, u as useIsoLayoutEffect, aW as DrawerBackdropCssVars, aX as DrawerPopupCssVars, e as useStableCallback, aY as DrawerProviderContext, aZ as CommonPopupDataAttributes, ae as popupStateMapping, ac as transitionStatusMapping, a_ as useDialogPortalContext, a$ as DialogStore, g as createChangeEventDetails, aF as imperativeAction, B as ownerDocument, y as contains, b0 as clamp, q as getTarget, b1 as useDrawerRootContext, l as useTimeout, aU as useTriggerRegistration, b2 as DrawerPopupDataAttributes, b3 as swipe, b4 as useDrawerSnapPoints, k as useAnimationFrame, b5 as DrawerViewportContext, b6 as BASE_UI_SWIPE_IGNORE_SELECTOR, b7 as TransitionStatusDataAttributes, b8 as DRAWER_CONTENT_ATTRIBUTE, a as DrawerBackdrop, c as DrawerContent, b as DrawerPopup, D as DrawerPortal, d as DrawerRoot, H as triggerHover, ar as useControlled, ab as itemPress, as as useTransitionStatus, af as useOpenChangeComplete, ak as useAnimationsFinished, an as inertValue, au as createSelector, b9 as useStore, J as useValueAsRef, aB as useOpenInteractionType, ba as createGenericEventDetails, bb as inputClear, bc as inputChange, a1 as focusOut, ah as outsidePress, bd as useValueChanged, be as none, bf as inputPress, aH as useDismiss, a8 as useInteractions, az as useOnFirstRender, bg as visuallyHiddenInput, bh as visuallyHidden, bi as Store, aR as pressableTriggerOpenStateMapping, Q as stopEvent, R as listNavigation, h as closePress, bj as isAndroid, bk as isFirefox, C as escapeKey, aa as triggerOpenStateMapping, bl as clearPress, aj as FloatingPortal, aE as useScrollLock, am as InternalBackdrop, ap as DROPDOWN_COLLISION_AVOIDANCE, ai as FloatingFocusManager, S as SafeReact, bm as chipRemovePress, E as useOnMount, G as Timeout, bn as isIOS, bo as inputBlur, bp as inputPaste, bq as incrementPress, br as decrementPress, bs as keyboard, bt as scrub, bu as isWebKit } from '../DrawerRoot-es.js';
2
- import { u as useBaseUiId, b as DrawerClose, a as DrawerTitle, D as DrawerTrigger, p as useMenuRootContext, q as useMenuPositionerContext, r as useContextMenuRootContext, s as useCompositeListItem, t as useMenuItem, R as REGULAR_ITEM, v as itemMapping, w as useDirection, x as MenuStore, m as MenuGroup, o as MenuGroupLabel, d as MenuItem, c as MenuLinkItem, k as MenuPopup, i as MenuPortal, j as MenuPositioner, l as MenuRadioGroup, e as MenuRadioItem, f as MenuRadioItemIndicator, h as MenuRoot, n as MenuSubmenuRoot, g as MenuSubmenuTrigger, M as MenuTrigger, y as useFloatingRootContext, z as useClick, A as useListNavigation, B as useTypeahead, C as useButton, E as getPseudoElementBounds, F as CompositeList, G as useAnchorPositioning, H as getDisabledMountTransitionStyles, I as IndexGuessBehavior, J as error } from '../MenuSubmenuTrigger-es.js';
1
+ import { u as useDialogRootContext, am as useDrawerProviderContext, an as DrawerBackdropCssVars, ao as DrawerPopupCssVars, ap as DrawerProviderContext, aq as CommonPopupDataAttributes, N as popupStateMapping, ar as useDialogPortalContext, as as DialogStore, l as contains, g as getTarget, at as useDrawerRootContext, al as useTriggerRegistration, au as DrawerPopupDataAttributes, av as useDrawerSnapPoints, aw as DrawerViewportContext, ax as BASE_UI_SWIPE_IGNORE_SELECTOR, ay as DRAWER_CONTENT_ATTRIBUTE, a as DrawerBackdrop, c as DrawerContent, b as DrawerPopup, D as DrawerPortal, d as DrawerRoot, V as inertValue, Z as createSelector, az as useStore, a4 as useOpenInteractionType, a9 as useDismiss, J as useInteractions, a2 as useOnFirstRender, aA as Store, ai as pressableTriggerOpenStateMapping, L as triggerOpenStateMapping, R as FloatingPortal, a7 as useScrollLock, U as InternalBackdrop, X as DROPDOWN_COLLISION_AVOIDANCE, Q as FloatingFocusManager } from '../DrawerRoot-es.js';
2
+ import { b as DrawerClose, a as DrawerTitle, D as DrawerTrigger, u as useMenuRootContext, p as useMenuPositionerContext, q as useContextMenuRootContext, r as useCompositeListItem, s as useMenuItem, R as REGULAR_ITEM, t as itemMapping, v as useDirection, w as MenuStore, m as MenuGroup, o as MenuGroupLabel, d as MenuItem, c as MenuLinkItem, k as MenuPopup, i as MenuPortal, j as MenuPositioner, l as MenuRadioGroup, e as MenuRadioItem, f as MenuRadioItemIndicator, h as MenuRoot, n as MenuSubmenuRoot, g as MenuSubmenuTrigger, M as MenuTrigger, x as useFloatingRootContext, y as useClick, z as useListNavigation, A as useTypeahead, B as getPseudoElementBounds, C as CompositeList, E as useAnchorPositioning, F as getDisabledMountTransitionStyles, I as IndexGuessBehavior } from '../MenuSubmenuTrigger-es.js';
3
3
  import * as React from 'react';
4
- import { u as useRenderElement, m as mergeProps, f as formatErrorMessage, N as NOOP, E as EMPTY_OBJECT, b as useRefWithInit, d as EMPTY_ARRAY, c as useMergedRefs } from '../useRenderElement-es.js';
4
+ import { u as useRenderElement, m as mergeProps, f as formatErrorMessage, N as NOOP, E as EMPTY_OBJECT, d as EMPTY_ARRAY, b as useRefWithInit, c as useMergedRefs } from '../useRenderElement-es.js';
5
+ import { u as useBaseUiId, a as useButton, e as error } from '../useBaseUiId-es.js';
6
+ import { u as useIsoLayoutEffect, a as useStableCallback, t as transitionStatusMapping, k as createChangeEventDetails, V as imperativeAction, s as ownerDocument, g as clamp, c as useTimeout, a3 as swipe, D as useAnimationFrame, X as TransitionStatusDataAttributes, K as triggerHover, h as useControlled, P as itemPress, d as useTransitionStatus, e as useOpenChangeComplete, R as useAnimationsFinished, i as useValueAsRef, r as createGenericEventDetails, o as inputClear, m as inputChange, M as focusOut, Q as outsidePress, y as useValueChanged, n as none, a4 as inputPress, v as visuallyHiddenInput, l as visuallyHidden, z as stopEvent, L as listNavigation, B as closePress, a1 as isAndroid, a5 as isFirefox, J as escapeKey, a6 as clearPress, S as SafeReact, a7 as chipRemovePress, a8 as scrub, _ as isWebKit } from '../useValueChanged-es.js';
5
7
  import { jsx, jsxs } from 'react/jsx-runtime';
6
- import { a as isHTMLElement, k as getComputedStyle, b as isElement, I as getWindow, L as round } from '../index.esm-es.js';
8
+ import { a as isHTMLElement, f as getComputedStyle, b as isElement, k as getWindow } from '../floating-ui.utils.dom-es.js';
7
9
  import * as ReactDOM from 'react-dom';
10
+ import { y as round } from '../index.esm-es.js';
8
11
  import { S as Separator } from '../Separator-es.js';
12
+ import { a as useFormContext, b as useFieldRootContext, i as useLabelableId, j as useField, f as fieldValidityMapping, u as useLabelableContext, k as DEFAULT_FIELD_STATE_ATTRIBUTES, l as useNumberFieldRootContext, m as DEFAULT_STEP, s as stateAttributesMapping$9, h as NumberFieldDecrement, c as NumberFieldGroup, e as NumberFieldIncrement, d as NumberFieldInput, N as NumberFieldRoot } from '../NumberFieldInput-es.js';
9
13
  import '../floating-ui.react-dom-es.js';
10
14
 
11
15
  /**
@@ -43,7 +47,7 @@ if (process.env.NODE_ENV !== "production") DialogDescription.displayName = "Dial
43
47
  */
44
48
  const DrawerDescription = DialogDescription;
45
49
 
46
- const stateAttributesMapping$a = {
50
+ const stateAttributesMapping$8 = {
47
51
  active(value) {
48
52
  if (value) {
49
53
  return {
@@ -113,12 +117,12 @@ const DrawerIndent = /*#__PURE__*/React.forwardRef(function DrawerIndent(compone
113
117
  [DrawerBackdropCssVars.swipeProgress]: '0'
114
118
  }
115
119
  }, elementProps],
116
- stateAttributesMapping: stateAttributesMapping$a
120
+ stateAttributesMapping: stateAttributesMapping$8
117
121
  });
118
122
  });
119
123
  if (process.env.NODE_ENV !== "production") DrawerIndent.displayName = "DrawerIndent";
120
124
 
121
- const stateAttributesMapping$9 = {
125
+ const stateAttributesMapping$7 = {
122
126
  active(value) {
123
127
  if (value) {
124
128
  return {
@@ -152,21 +156,11 @@ const DrawerIndentBackground = /*#__PURE__*/React.forwardRef(function DrawerInde
152
156
  ref: forwardedRef,
153
157
  state,
154
158
  props: elementProps,
155
- stateAttributesMapping: stateAttributesMapping$9
159
+ stateAttributesMapping: stateAttributesMapping$7
156
160
  });
157
161
  });
158
162
  if (process.env.NODE_ENV !== "production") DrawerIndentBackground.displayName = "DrawerIndentBackground";
159
163
 
160
- /**
161
- * Returns a function that forces a rerender.
162
- */
163
- function useForcedRerendering() {
164
- const [, setState] = React.useState({});
165
- return React.useCallback(() => {
166
- setState({});
167
- }, []);
168
- }
169
-
170
164
  function DrawerProvider(props) {
171
165
  const {
172
166
  children
@@ -278,7 +272,7 @@ let DialogViewportDataAttributes = function (DialogViewportDataAttributes) {
278
272
  return DialogViewportDataAttributes;
279
273
  }({});
280
274
 
281
- const stateAttributesMapping$8 = {
275
+ const stateAttributesMapping$6 = {
282
276
  ...popupStateMapping,
283
277
  ...transitionStatusMapping,
284
278
  nested(value) {
@@ -327,7 +321,7 @@ const DialogViewport = /*#__PURE__*/React.forwardRef(function DialogViewport(com
327
321
  enabled: shouldRender,
328
322
  state,
329
323
  ref: [forwardedRef, store.useStateSetter('viewportElement')],
330
- stateAttributesMapping: stateAttributesMapping$8,
324
+ stateAttributesMapping: stateAttributesMapping$6,
331
325
  props: [{
332
326
  role: 'presentation',
333
327
  hidden: !mounted,
@@ -1416,7 +1410,7 @@ const SWIPE_AREA_SWIPING_HOOK = {
1416
1410
  const SWIPE_AREA_DISABLED_HOOK = {
1417
1411
  [DrawerSwipeAreaDataAttributes.disabled]: ''
1418
1412
  };
1419
- const stateAttributesMapping$7 = {
1413
+ const stateAttributesMapping$5 = {
1420
1414
  open(value) {
1421
1415
  return value ? SWIPE_AREA_OPEN_HOOK : SWIPE_AREA_CLOSED_HOOK;
1422
1416
  },
@@ -1721,7 +1715,7 @@ const DrawerSwipeArea = /*#__PURE__*/React.forwardRef(function DrawerSwipeArea(c
1721
1715
  return useRenderElement('div', componentProps, {
1722
1716
  state,
1723
1717
  ref: [forwardedRef, swipeAreaRef, registerTrigger],
1724
- stateAttributesMapping: stateAttributesMapping$7,
1718
+ stateAttributesMapping: stateAttributesMapping$5,
1725
1719
  props: [{
1726
1720
  role: 'presentation',
1727
1721
  'aria-hidden': true,
@@ -2787,7 +2781,7 @@ const MenuArrow = /*#__PURE__*/React.forwardRef(function MenuArrow(componentProp
2787
2781
  });
2788
2782
  if (process.env.NODE_ENV !== "production") MenuArrow.displayName = "MenuArrow";
2789
2783
 
2790
- const stateAttributesMapping$6 = {
2784
+ const stateAttributesMapping$4 = {
2791
2785
  ...popupStateMapping,
2792
2786
  ...transitionStatusMapping
2793
2787
  };
@@ -2819,7 +2813,7 @@ const MenuBackdrop = /*#__PURE__*/React.forwardRef(function MenuBackdrop(compone
2819
2813
  return useRenderElement('div', componentProps, {
2820
2814
  ref: contextMenuContext?.backdropRef ? [forwardedRef, contextMenuContext.backdropRef] : forwardedRef,
2821
2815
  state,
2822
- stateAttributesMapping: stateAttributesMapping$6,
2816
+ stateAttributesMapping: stateAttributesMapping$4,
2823
2817
  props: [{
2824
2818
  role: 'presentation',
2825
2819
  hidden: !mounted,
@@ -3438,7 +3432,7 @@ let MenuViewportCssVars = /*#__PURE__*/function (MenuViewportCssVars) {
3438
3432
  return MenuViewportCssVars;
3439
3433
  }({});
3440
3434
 
3441
- const stateAttributesMapping$5 = {
3435
+ const stateAttributesMapping$3 = {
3442
3436
  activationDirection: value => value ? {
3443
3437
  'data-activation-direction': value
3444
3438
  } : null
@@ -3486,7 +3480,7 @@ const MenuViewport = /*#__PURE__*/React.forwardRef(function MenuViewport(compone
3486
3480
  props: [elementProps, {
3487
3481
  children: childrenToRender
3488
3482
  }],
3489
- stateAttributesMapping: stateAttributesMapping$5
3483
+ stateAttributesMapping: stateAttributesMapping$3
3490
3484
  });
3491
3485
  });
3492
3486
  if (process.env.NODE_ENV !== "production") MenuViewport.displayName = "MenuViewport";
@@ -3830,299 +3824,6 @@ const selectors = {
3830
3824
  submitOnItemClick: createSelector(state => state.submitOnItemClick)
3831
3825
  };
3832
3826
 
3833
- let FieldControlDataAttributes = /*#__PURE__*/function (FieldControlDataAttributes) {
3834
- /**
3835
- * Present when the field is disabled.
3836
- */
3837
- FieldControlDataAttributes["disabled"] = "data-disabled";
3838
- /**
3839
- * Present when the field is in valid state.
3840
- */
3841
- FieldControlDataAttributes["valid"] = "data-valid";
3842
- /**
3843
- * Present when the field is in invalid state.
3844
- */
3845
- FieldControlDataAttributes["invalid"] = "data-invalid";
3846
- /**
3847
- * Present when the field has been touched.
3848
- */
3849
- FieldControlDataAttributes["touched"] = "data-touched";
3850
- /**
3851
- * Present when the field's value has changed.
3852
- */
3853
- FieldControlDataAttributes["dirty"] = "data-dirty";
3854
- /**
3855
- * Present when the field is filled.
3856
- */
3857
- FieldControlDataAttributes["filled"] = "data-filled";
3858
- /**
3859
- * Present when the field control is focused.
3860
- */
3861
- FieldControlDataAttributes["focused"] = "data-focused";
3862
- return FieldControlDataAttributes;
3863
- }({});
3864
-
3865
- const DEFAULT_VALIDITY_STATE = {
3866
- badInput: false,
3867
- customError: false,
3868
- patternMismatch: false,
3869
- rangeOverflow: false,
3870
- rangeUnderflow: false,
3871
- stepMismatch: false,
3872
- tooLong: false,
3873
- tooShort: false,
3874
- typeMismatch: false,
3875
- valid: null,
3876
- valueMissing: false
3877
- };
3878
- const DEFAULT_FIELD_STATE_ATTRIBUTES = {
3879
- valid: null,
3880
- touched: false,
3881
- dirty: false,
3882
- filled: false,
3883
- focused: false
3884
- };
3885
- const DEFAULT_FIELD_ROOT_STATE = {
3886
- disabled: false,
3887
- ...DEFAULT_FIELD_STATE_ATTRIBUTES
3888
- };
3889
- const fieldValidityMapping = {
3890
- valid(value) {
3891
- if (value === null) {
3892
- return null;
3893
- }
3894
- if (value) {
3895
- return {
3896
- [FieldControlDataAttributes.valid]: ''
3897
- };
3898
- }
3899
- return {
3900
- [FieldControlDataAttributes.invalid]: ''
3901
- };
3902
- }
3903
- };
3904
-
3905
- const FieldRootContext = /*#__PURE__*/React.createContext({
3906
- invalid: undefined,
3907
- name: undefined,
3908
- validityData: {
3909
- state: DEFAULT_VALIDITY_STATE,
3910
- errors: [],
3911
- error: '',
3912
- value: '',
3913
- initialValue: null
3914
- },
3915
- setValidityData: NOOP,
3916
- disabled: undefined,
3917
- touched: DEFAULT_FIELD_STATE_ATTRIBUTES.touched,
3918
- setTouched: NOOP,
3919
- dirty: DEFAULT_FIELD_STATE_ATTRIBUTES.dirty,
3920
- setDirty: NOOP,
3921
- filled: DEFAULT_FIELD_STATE_ATTRIBUTES.filled,
3922
- setFilled: NOOP,
3923
- focused: DEFAULT_FIELD_STATE_ATTRIBUTES.focused,
3924
- setFocused: NOOP,
3925
- validate: () => null,
3926
- validationMode: 'onSubmit',
3927
- validationDebounceTime: 0,
3928
- shouldValidateOnChange: () => false,
3929
- state: DEFAULT_FIELD_ROOT_STATE,
3930
- markedDirtyRef: {
3931
- current: false
3932
- },
3933
- validation: {
3934
- getValidationProps: (props = EMPTY_OBJECT) => props,
3935
- getInputValidationProps: (props = EMPTY_OBJECT) => props,
3936
- inputRef: {
3937
- current: null
3938
- },
3939
- commit: async () => {}
3940
- }
3941
- });
3942
- if (process.env.NODE_ENV !== "production") FieldRootContext.displayName = "FieldRootContext";
3943
- function useFieldRootContext(optional = true) {
3944
- const context = React.useContext(FieldRootContext);
3945
- if (context.setValidityData === NOOP && !optional) {
3946
- throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: FieldRootContext is missing. Field parts must be placed within <Field.Root>.' : formatErrorMessage(28));
3947
- }
3948
- return context;
3949
- }
3950
-
3951
- /**
3952
- * Combines the field's client-side, stateful validity data with the external invalid state to
3953
- * determine the field's true validity.
3954
- */
3955
- function getCombinedFieldValidityData(validityData, invalid) {
3956
- return {
3957
- ...validityData,
3958
- state: {
3959
- ...validityData.state,
3960
- valid: !invalid && validityData.state.valid
3961
- }
3962
- };
3963
- }
3964
-
3965
- const FormContext = /*#__PURE__*/React.createContext({
3966
- formRef: {
3967
- current: {
3968
- fields: new Map()
3969
- }
3970
- },
3971
- errors: {},
3972
- clearErrors: NOOP,
3973
- validationMode: 'onSubmit',
3974
- submitAttemptedRef: {
3975
- current: false
3976
- }
3977
- });
3978
- if (process.env.NODE_ENV !== "production") FormContext.displayName = "FormContext";
3979
- function useFormContext() {
3980
- return React.useContext(FormContext);
3981
- }
3982
-
3983
- function useField(params) {
3984
- const {
3985
- enabled = true,
3986
- value,
3987
- id,
3988
- name,
3989
- controlRef,
3990
- commit
3991
- } = params;
3992
- const {
3993
- formRef
3994
- } = useFormContext();
3995
- const {
3996
- invalid,
3997
- markedDirtyRef,
3998
- validityData,
3999
- setValidityData
4000
- } = useFieldRootContext();
4001
- const getValue = useStableCallback(params.getValue);
4002
- useIsoLayoutEffect(() => {
4003
- if (!enabled) {
4004
- return;
4005
- }
4006
- let initialValue = value;
4007
- if (initialValue === undefined) {
4008
- initialValue = getValue();
4009
- }
4010
- if (validityData.initialValue === null && initialValue !== null) {
4011
- setValidityData(prev => ({
4012
- ...prev,
4013
- initialValue
4014
- }));
4015
- }
4016
- }, [enabled, setValidityData, value, validityData.initialValue, getValue]);
4017
- useIsoLayoutEffect(() => {
4018
- if (!enabled || !id) {
4019
- return;
4020
- }
4021
- formRef.current.fields.set(id, {
4022
- getValue,
4023
- name,
4024
- controlRef,
4025
- validityData: getCombinedFieldValidityData(validityData, invalid),
4026
- validate(flushSync = true) {
4027
- let nextValue = value;
4028
- if (nextValue === undefined) {
4029
- nextValue = getValue();
4030
- }
4031
- markedDirtyRef.current = true;
4032
- if (!flushSync) {
4033
- commit(nextValue);
4034
- } else {
4035
- // Synchronously update the validity state so the submit event can be prevented.
4036
- ReactDOM.flushSync(() => commit(nextValue));
4037
- }
4038
- }
4039
- });
4040
- }, [commit, controlRef, enabled, formRef, getValue, id, invalid, markedDirtyRef, name, validityData, value]);
4041
- useIsoLayoutEffect(() => {
4042
- const fields = formRef.current.fields;
4043
- return () => {
4044
- if (id) {
4045
- fields.delete(id);
4046
- }
4047
- };
4048
- }, [formRef, id]);
4049
- }
4050
-
4051
- /**
4052
- * A context for providing [labelable elements](https://html.spec.whatwg.org/multipage/forms.html#category-label)\
4053
- * with an accessible name (label) and description.
4054
- */
4055
- const LabelableContext = /*#__PURE__*/React.createContext({
4056
- controlId: undefined,
4057
- registerControlId: NOOP,
4058
- labelId: undefined,
4059
- setLabelId: NOOP,
4060
- messageIds: [],
4061
- setMessageIds: NOOP,
4062
- getDescriptionProps: externalProps => externalProps
4063
- });
4064
- if (process.env.NODE_ENV !== "production") LabelableContext.displayName = "LabelableContext";
4065
- function useLabelableContext() {
4066
- return React.useContext(LabelableContext);
4067
- }
4068
-
4069
- function useLabelableId(params = {}) {
4070
- const {
4071
- id,
4072
- implicit = false,
4073
- controlRef
4074
- } = params;
4075
- const {
4076
- controlId,
4077
- registerControlId
4078
- } = useLabelableContext();
4079
- const defaultId = useBaseUiId(id);
4080
- const controlIdForEffect = implicit ? controlId : undefined;
4081
- const controlSourceRef = useRefWithInit(() => Symbol('labelable-control'));
4082
- const hasRegisteredRef = React.useRef(false);
4083
- const hadExplicitIdRef = React.useRef(id != null);
4084
- const unregisterControlId = useStableCallback(() => {
4085
- if (!hasRegisteredRef.current || registerControlId === NOOP) {
4086
- return;
4087
- }
4088
- hasRegisteredRef.current = false;
4089
- registerControlId(controlSourceRef.current, undefined);
4090
- });
4091
- useIsoLayoutEffect(() => {
4092
- if (registerControlId === NOOP) {
4093
- return undefined;
4094
- }
4095
- let nextId;
4096
- if (implicit) {
4097
- const elem = controlRef?.current;
4098
- if (isElement(elem) && elem.closest('label') != null) {
4099
- nextId = id ?? null;
4100
- } else {
4101
- nextId = controlIdForEffect ?? defaultId;
4102
- }
4103
- } else if (id != null) {
4104
- hadExplicitIdRef.current = true;
4105
- nextId = id;
4106
- } else if (hadExplicitIdRef.current) {
4107
- nextId = defaultId;
4108
- } else {
4109
- unregisterControlId();
4110
- return undefined;
4111
- }
4112
- if (nextId === undefined) {
4113
- unregisterControlId();
4114
- return undefined;
4115
- }
4116
- hasRegisteredRef.current = true;
4117
- registerControlId(controlSourceRef.current, nextId);
4118
- return undefined;
4119
- }, [id, controlRef, controlIdForEffect, registerControlId, implicit, defaultId, controlSourceRef, unregisterControlId]);
4120
- React.useEffect(() => {
4121
- return unregisterControlId;
4122
- }, [unregisterControlId]);
4123
- return controlId ?? defaultId;
4124
- }
4125
-
4126
3827
  /**
4127
3828
  * Enhanced filter using Intl.Collator for more robust string matching.
4128
3829
  * Uses the provided `itemToStringLabel` function if available, otherwise falls back to:
@@ -5945,7 +5646,7 @@ const ComboboxIcon = /*#__PURE__*/React.forwardRef(function ComboboxIcon(compone
5945
5646
  });
5946
5647
  if (process.env.NODE_ENV !== "production") ComboboxIcon.displayName = "ComboboxIcon";
5947
5648
 
5948
- const stateAttributesMapping$4 = {
5649
+ const stateAttributesMapping$2 = {
5949
5650
  ...transitionStatusMapping,
5950
5651
  ...triggerOpenStateMapping
5951
5652
  };
@@ -6041,7 +5742,7 @@ const ComboboxClear = /*#__PURE__*/React.forwardRef(function ComboboxClear(compo
6041
5742
  store.state.inputRef.current?.focus();
6042
5743
  }
6043
5744
  }, elementProps, getButtonProps],
6044
- stateAttributesMapping: stateAttributesMapping$4
5745
+ stateAttributesMapping: stateAttributesMapping$2
6045
5746
  });
6046
5747
  const shouldRender = keepMounted || mounted;
6047
5748
  if (!shouldRender) {
@@ -6237,7 +5938,7 @@ const ComboboxPortal = /*#__PURE__*/React.forwardRef(function ComboboxPortal(pro
6237
5938
  });
6238
5939
  if (process.env.NODE_ENV !== "production") ComboboxPortal.displayName = "ComboboxPortal";
6239
5940
 
6240
- const stateAttributesMapping$3 = {
5941
+ const stateAttributesMapping$1 = {
6241
5942
  ...popupStateMapping,
6242
5943
  ...transitionStatusMapping
6243
5944
  };
@@ -6263,7 +5964,7 @@ const ComboboxBackdrop = /*#__PURE__*/React.forwardRef(function ComboboxBackdrop
6263
5964
  return useRenderElement('div', componentProps, {
6264
5965
  state,
6265
5966
  ref: forwardedRef,
6266
- stateAttributesMapping: stateAttributesMapping$3,
5967
+ stateAttributesMapping: stateAttributesMapping$1,
6267
5968
  props: [{
6268
5969
  role: 'presentation',
6269
5970
  hidden: !mounted,
@@ -6381,7 +6082,7 @@ const ComboboxPositioner = /*#__PURE__*/React.forwardRef(function ComboboxPositi
6381
6082
  });
6382
6083
  if (process.env.NODE_ENV !== "production") ComboboxPositioner.displayName = "ComboboxPositioner";
6383
6084
 
6384
- const stateAttributesMapping$2 = {
6085
+ const stateAttributesMapping = {
6385
6086
  ...popupStateMapping,
6386
6087
  ...transitionStatusMapping
6387
6088
  };
@@ -6442,7 +6143,7 @@ const ComboboxPopup = /*#__PURE__*/React.forwardRef(function ComboboxPopup(compo
6442
6143
  }
6443
6144
  }
6444
6145
  }, getDisabledMountTransitionStyles(transitionStatus), elementProps],
6445
- stateAttributesMapping: stateAttributesMapping$2
6146
+ stateAttributesMapping
6446
6147
  });
6447
6148
 
6448
6149
  // Default initial focus logic:
@@ -7322,1541 +7023,65 @@ var index_parts$1 = /*#__PURE__*/Object.freeze({
7322
7023
  useFilteredItems: useFilteredItems
7323
7024
  });
7324
7025
 
7325
- const cache = new Map();
7326
- function getFormatter(locale, options) {
7327
- const optionsString = JSON.stringify({
7328
- locale,
7329
- options
7330
- });
7331
- const cachedFormatter = cache.get(optionsString);
7332
- if (cachedFormatter) {
7333
- return cachedFormatter;
7334
- }
7335
- const formatter = new Intl.NumberFormat(locale, options);
7336
- cache.set(optionsString, formatter);
7337
- return formatter;
7338
- }
7339
- function formatNumber(value, locale, options) {
7340
- if (value == null) {
7341
- return '';
7342
- }
7343
- return getFormatter(locale, options).format(value);
7344
- }
7345
- function formatNumberMaxPrecision(value, locale, options) {
7346
- return formatNumber(value, locale, {
7347
- ...options,
7348
- maximumFractionDigits: 20
7349
- });
7350
- }
7351
-
7352
- const EMPTY = 0;
7353
- class Interval extends Timeout {
7354
- static create() {
7355
- return new Interval();
7356
- }
7357
-
7358
- /**
7359
- * Executes `fn` at `delay` interval, clearing any previously scheduled call.
7360
- */
7361
- start(delay, fn) {
7362
- this.clear();
7363
- this.currentId = setInterval(() => {
7364
- fn();
7365
- }, delay);
7366
- }
7367
- clear = () => {
7368
- if (this.currentId !== EMPTY) {
7369
- clearInterval(this.currentId);
7370
- this.currentId = EMPTY;
7371
- }
7372
- };
7373
- }
7374
-
7375
- /**
7376
- * A `setInterval` with automatic cleanup and guard.
7377
- */
7378
- function useInterval() {
7379
- const timeout = useRefWithInit(Interval.create).current;
7380
- useOnMount(timeout.disposeEffect);
7381
- return timeout;
7382
- }
7383
-
7384
- const NumberFieldRootContext = /*#__PURE__*/React.createContext(undefined);
7385
- if (process.env.NODE_ENV !== "production") NumberFieldRootContext.displayName = "NumberFieldRootContext";
7386
- function useNumberFieldRootContext() {
7387
- const context = React.useContext(NumberFieldRootContext);
7026
+ const NumberFieldScrubAreaContext = /*#__PURE__*/React.createContext(undefined);
7027
+ if (process.env.NODE_ENV !== "production") NumberFieldScrubAreaContext.displayName = "NumberFieldScrubAreaContext";
7028
+ function useNumberFieldScrubAreaContext() {
7029
+ const context = React.useContext(NumberFieldScrubAreaContext);
7388
7030
  if (context === undefined) {
7389
- throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: NumberFieldRootContext is missing. NumberField parts must be placed within <NumberField.Root>.' : formatErrorMessage(43));
7031
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: NumberFieldScrubAreaContext is missing. NumberFieldScrubArea parts must be placed within <NumberField.ScrubArea>.' : formatErrorMessage(44));
7390
7032
  }
7391
7033
  return context;
7392
7034
  }
7393
7035
 
7394
- const stateAttributesMapping$1 = {
7395
- inputValue: () => null,
7396
- value: () => null,
7397
- ...fieldValidityMapping
7398
- };
7399
-
7400
- const HAN_NUMERALS = ['零', '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
7401
- // Map Han numeral characters to ASCII digits. Includes both forms of zero.
7402
- const HAN_NUMERAL_TO_DIGIT = {
7403
- 零: '0',
7404
- 〇: '0',
7405
- 一: '1',
7406
- 二: '2',
7407
- 三: '3',
7408
- 四: '4',
7409
- 五: '5',
7410
- 六: '6',
7411
- 七: '7',
7412
- 八: '8',
7413
- 九: '9'
7414
- };
7415
- const ARABIC_NUMERALS = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
7416
- const PERSIAN_NUMERALS = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
7417
- const FULLWIDTH_NUMERALS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
7418
- const PERCENTAGES = ['%', '٪', '%', '﹪'];
7419
- const PERMILLE = ['‰', '؉'];
7420
- const UNICODE_MINUS_SIGNS = ['−', '-', '‒', '–', '—', '﹣'];
7421
- const UNICODE_PLUS_SIGNS = ['+', '﹢'];
7422
-
7423
- // Fullwidth punctuation common in CJK inputs
7424
- const FULLWIDTH_DECIMAL = '.'; // U+FF0E
7425
- const FULLWIDTH_GROUP = ','; // U+FF0C
7426
-
7427
- const ARABIC_RE = new RegExp(`[${ARABIC_NUMERALS.join('')}]`, 'g');
7428
- const PERSIAN_RE = new RegExp(`[${PERSIAN_NUMERALS.join('')}]`, 'g');
7429
- const FULLWIDTH_RE = new RegExp(`[${FULLWIDTH_NUMERALS.join('')}]`, 'g');
7430
- const HAN_RE = new RegExp(`[${HAN_NUMERALS.join('')}]`, 'g');
7431
- const PERCENT_RE = new RegExp(`[${PERCENTAGES.join('')}]`);
7432
- const PERMILLE_RE = new RegExp(`[${PERMILLE.join('')}]`);
7433
-
7434
- // Detection regexes (non-global to avoid lastIndex side effects)
7435
- const ARABIC_DETECT_RE = /[٠١٢٣٤٥٦٧٨٩]/;
7436
- const PERSIAN_DETECT_RE = /[۰۱۲۳۴۵۶۷۸۹]/;
7437
- const HAN_DETECT_RE = /[零〇一二三四五六七八九]/;
7438
- const FULLWIDTH_DETECT_RE = new RegExp(`[${FULLWIDTH_NUMERALS.join('')}]`);
7439
- const BASE_NON_NUMERIC_SYMBOLS = ['.', ',', FULLWIDTH_DECIMAL, FULLWIDTH_GROUP, '٫', '٬'];
7440
- const SPACE_SEPARATOR_RE = /\p{Zs}/u;
7441
- const PLUS_SIGNS_WITH_ASCII = ['+', ...UNICODE_PLUS_SIGNS];
7442
- const MINUS_SIGNS_WITH_ASCII = ['-', ...UNICODE_MINUS_SIGNS];
7443
- const escapeRegExp = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7444
- const escapeClassChar = s => s.replace(/[-\\\]^]/g, m => `\\${m}`); // escape for use inside [...]
7445
-
7446
- const charClassFrom = chars => `[${chars.map(escapeClassChar).join('')}]`;
7447
- const ANY_MINUS_CLASS = charClassFrom(['-'].concat(UNICODE_MINUS_SIGNS));
7448
- const ANY_PLUS_CLASS = charClassFrom(['+'].concat(UNICODE_PLUS_SIGNS));
7449
- const ANY_MINUS_RE = new RegExp(ANY_MINUS_CLASS, 'gu');
7450
- const ANY_PLUS_RE = new RegExp(ANY_PLUS_CLASS, 'gu');
7451
- const ANY_MINUS_DETECT_RE = new RegExp(ANY_MINUS_CLASS);
7452
- const ANY_PLUS_DETECT_RE = new RegExp(ANY_PLUS_CLASS);
7453
- function getNumberLocaleDetails(locale, options) {
7454
- const parts = getFormatter(locale, options).formatToParts(11111.1);
7455
- const result = {};
7456
- parts.forEach(part => {
7457
- result[part.type] = part.value;
7458
- });
7459
-
7460
- // The formatting options may result in not returning a decimal.
7461
- getFormatter(locale).formatToParts(0.1).forEach(part => {
7462
- if (part.type === 'decimal') {
7463
- result[part.type] = part.value;
7464
- }
7465
- });
7466
- return result;
7467
- }
7468
- function parseNumber(formattedNumber, locale, options) {
7469
- if (formattedNumber == null) {
7470
- return null;
7471
- }
7472
-
7473
- // Normalize control characters and whitespace; remove bidi/format controls
7474
- let input = String(formattedNumber).replace(/\p{Cf}/gu, '').trim();
7475
-
7476
- // Normalize unicode minus/plus to ASCII, handle leading/trailing signs
7477
- input = input.replace(ANY_MINUS_RE, '-').replace(ANY_PLUS_RE, '+');
7478
- let isNegative = false;
7479
-
7480
- // Trailing sign, e.g. "1234-" / "1234+"
7481
- const trailing = input.match(/([+-])\s*$/);
7482
- if (trailing) {
7483
- if (trailing[1] === '-') {
7484
- isNegative = true;
7485
- }
7486
- input = input.replace(/([+-])\s*$/, '');
7487
- }
7488
- // Leading sign
7489
- const leading = input.match(/^\s*([+-])/);
7490
- if (leading) {
7491
- if (leading[1] === '-') {
7492
- isNegative = true;
7493
- }
7494
- input = input.replace(/^\s*[+-]/, '');
7495
- }
7496
-
7497
- // Heuristic locale detection
7498
- let computedLocale = locale;
7499
- if (computedLocale === undefined) {
7500
- if (ARABIC_DETECT_RE.test(input) || PERSIAN_DETECT_RE.test(input)) {
7501
- computedLocale = 'ar';
7502
- } else if (HAN_DETECT_RE.test(input)) {
7503
- computedLocale = 'zh';
7504
- }
7505
- }
7506
- const {
7507
- group,
7508
- decimal,
7509
- currency
7510
- } = getNumberLocaleDetails(computedLocale, options);
7511
-
7512
- // Build robust unit regex from all unit parts (such as "km/h")
7513
- const unitParts = getFormatter(computedLocale, options).formatToParts(1).filter(p => p.type === 'unit').map(p => escapeRegExp(p.value));
7514
- const unitRegex = unitParts.length ? new RegExp(unitParts.join('|'), 'g') : null;
7515
- let groupRegex = null;
7516
- if (group) {
7517
- const isSpaceGroup = /\p{Zs}/u.test(group);
7518
- const isApostropheGroup = group === "'" || group === '’';
7519
-
7520
- // Check if the group separator is a space-like character.
7521
- // If so, we'll replace all such characters with an empty string.
7522
- if (isSpaceGroup) {
7523
- groupRegex = /\p{Zs}/gu;
7524
- } else if (isApostropheGroup) {
7525
- // Some environments format numbers with ASCII apostrophe and others with a curly apostrophe.
7526
- groupRegex = /['’]/g;
7527
- } else {
7528
- groupRegex = new RegExp(escapeRegExp(group), 'g');
7529
- }
7530
- }
7531
- const replacements = [{
7532
- regex: group ? groupRegex : null,
7533
- replacement: ''
7534
- }, {
7535
- regex: decimal ? new RegExp(escapeRegExp(decimal), 'g') : null,
7536
- replacement: '.'
7537
- },
7538
- // Fullwidth punctuation
7539
- {
7540
- regex: /./g,
7541
- replacement: '.'
7542
- },
7543
- // FULLWIDTH_DECIMAL
7544
- {
7545
- regex: /,/g,
7546
- replacement: ''
7547
- },
7548
- // FULLWIDTH_GROUP
7549
- // Arabic punctuation
7550
- {
7551
- regex: /٫/g,
7552
- replacement: '.'
7553
- },
7554
- // ARABIC DECIMAL SEPARATOR (U+066B)
7555
- {
7556
- regex: /٬/g,
7557
- replacement: ''
7558
- },
7559
- // ARABIC THOUSANDS SEPARATOR (U+066C)
7560
- // Currency & unit labels
7561
- {
7562
- regex: currency ? new RegExp(escapeRegExp(currency), 'g') : null,
7563
- replacement: ''
7564
- }, {
7565
- regex: unitRegex,
7566
- replacement: ''
7567
- },
7568
- // Numeral systems to ASCII digits
7569
- {
7570
- regex: ARABIC_RE,
7571
- replacement: ch => String(ARABIC_NUMERALS.indexOf(ch))
7572
- }, {
7573
- regex: PERSIAN_RE,
7574
- replacement: ch => String(PERSIAN_NUMERALS.indexOf(ch))
7575
- }, {
7576
- regex: FULLWIDTH_RE,
7577
- replacement: ch => String(FULLWIDTH_NUMERALS.indexOf(ch))
7578
- }, {
7579
- regex: HAN_RE,
7580
- replacement: ch => HAN_NUMERAL_TO_DIGIT[ch]
7581
- }];
7582
- let unformatted = replacements.reduce((acc, {
7583
- regex,
7584
- replacement
7585
- }) => {
7586
- return regex ? acc.replace(regex, replacement) : acc;
7587
- }, input);
7588
-
7589
- // Mixed-locale safety: keep only the last '.' as decimal
7590
- const lastDot = unformatted.lastIndexOf('.');
7591
- if (lastDot !== -1) {
7592
- unformatted = `${unformatted.slice(0, lastDot).replace(/\./g, '')}.${unformatted.slice(lastDot + 1).replace(/\./g, '')}`;
7593
- }
7594
-
7595
- // Guard against Infinity inputs (ASCII and symbol)
7596
- if (/^[-+]?Infinity$/i.test(input) || /[∞]/.test(input)) {
7597
- return null;
7598
- }
7599
- const parseTarget = (isNegative ? '-' : '') + unformatted;
7600
- let num = parseFloat(parseTarget);
7601
- const style = options?.style;
7602
- const isUnitPercent = style === 'unit' && options?.unit === 'percent';
7603
- const hasPercentSymbol = PERCENT_RE.test(formattedNumber) || style === 'percent';
7604
- const hasPermilleSymbol = PERMILLE_RE.test(formattedNumber);
7605
- if (hasPermilleSymbol) {
7606
- num /= 1000;
7607
- } else if (!isUnitPercent && hasPercentSymbol) {
7608
- num /= 100;
7036
+ // Calculates the viewport rect for the virtual cursor.
7037
+ function getViewportRect(teleportDistance, scrubAreaEl) {
7038
+ const win = getWindow(scrubAreaEl);
7039
+ const rect = scrubAreaEl.getBoundingClientRect();
7040
+ if (rect && teleportDistance != null) {
7041
+ return {
7042
+ x: rect.left - teleportDistance / 2,
7043
+ y: rect.top - teleportDistance / 2,
7044
+ width: rect.right + teleportDistance / 2,
7045
+ height: rect.bottom + teleportDistance / 2
7046
+ };
7609
7047
  }
7610
- if (Number.isNaN(num)) {
7611
- return null;
7048
+ const vV = win.visualViewport;
7049
+ if (vV) {
7050
+ return {
7051
+ x: vV.offsetLeft,
7052
+ y: vV.offsetTop,
7053
+ width: vV.offsetLeft + vV.width,
7054
+ height: vV.offsetTop + vV.height
7055
+ };
7612
7056
  }
7613
- return num;
7614
- }
7615
-
7616
- const CHANGE_VALUE_TICK_DELAY = 60;
7617
- const START_AUTO_CHANGE_DELAY = 400;
7618
- const TOUCH_TIMEOUT = 50;
7619
- const MAX_POINTER_MOVES_AFTER_TOUCH = 3;
7620
- const SCROLLING_POINTER_MOVE_DISTANCE = 8;
7621
- const DEFAULT_STEP = 1;
7622
-
7623
- const STEP_EPSILON_FACTOR = 1e-10;
7624
- function getFractionDigits(format) {
7625
- const defaultOptions = getFormatter('en-US').resolvedOptions();
7626
- const minimumFractionDigits = format?.minimumFractionDigits ?? defaultOptions.minimumFractionDigits ?? 0;
7627
- const maximumFractionDigits = Math.max(format?.maximumFractionDigits ?? defaultOptions.maximumFractionDigits ?? 20, minimumFractionDigits);
7628
7057
  return {
7629
- maximumFractionDigits,
7630
- minimumFractionDigits
7058
+ x: 0,
7059
+ y: 0,
7060
+ width: win.document.documentElement.clientWidth,
7061
+ height: win.document.documentElement.clientHeight
7631
7062
  };
7632
7063
  }
7633
- function roundToFractionDigits(value, maximumFractionDigits) {
7634
- if (!Number.isFinite(value)) {
7635
- return value;
7636
- }
7637
- const digits = Math.min(Math.max(maximumFractionDigits, 0), 20);
7638
- return Number(value.toFixed(digits));
7639
- }
7640
- function removeFloatingPointErrors(value, format) {
7641
- const {
7642
- maximumFractionDigits
7643
- } = getFractionDigits(format);
7644
- return roundToFractionDigits(value, maximumFractionDigits);
7645
- }
7646
- function snapToStep(clampedValue, base, step, mode = 'directional') {
7647
- if (step === 0) {
7648
- return clampedValue;
7649
- }
7650
- const stepSize = Math.abs(step);
7651
- const direction = Math.sign(step);
7652
- const tolerance = stepSize * STEP_EPSILON_FACTOR * direction;
7653
- const divisor = mode === 'nearest' ? step : stepSize;
7654
- const rawSteps = (clampedValue - base + tolerance) / divisor;
7655
- let snappedSteps;
7656
- if (mode === 'nearest') {
7657
- snappedSteps = Math.round(rawSteps);
7658
- } else if (direction > 0) {
7659
- snappedSteps = Math.floor(rawSteps);
7660
- } else {
7661
- snappedSteps = Math.ceil(rawSteps);
7662
- }
7663
- const stepForResult = mode === 'nearest' ? step : stepSize;
7664
- return base + snappedSteps * stepForResult;
7665
- }
7666
- function toValidatedNumber(value, {
7667
- step,
7668
- minWithDefault,
7669
- maxWithDefault,
7670
- minWithZeroDefault,
7671
- format,
7672
- snapOnStep,
7673
- small,
7674
- clamp: shouldClamp
7675
- }) {
7676
- if (value === null) {
7677
- return value;
7678
- }
7679
- const clampedValue = shouldClamp ? clamp(value, minWithDefault, maxWithDefault) : value;
7680
- if (step != null && snapOnStep) {
7681
- if (step === 0) {
7682
- return removeFloatingPointErrors(clampedValue, format);
7683
- }
7684
7064
 
7685
- // If a real minimum is provided, use it
7686
- let base = minWithZeroDefault;
7687
- if (!small && minWithDefault !== Number.MIN_SAFE_INTEGER) {
7688
- base = minWithDefault;
7065
+ // This lets us invert the scale of the cursor to match the OS scale, in which the cursor doesn't
7066
+ // scale with the content on pinch-zoom.
7067
+ function subscribeToVisualViewportResize(element, visualScaleRef) {
7068
+ const vV = getWindow(element).visualViewport;
7069
+ if (!vV) {
7070
+ return () => {};
7071
+ }
7072
+ function handleVisualResize() {
7073
+ if (vV) {
7074
+ visualScaleRef.current = vV.scale;
7689
7075
  }
7690
- const snappedValue = snapToStep(clampedValue, base, step, small ? 'nearest' : 'directional');
7691
- return removeFloatingPointErrors(snappedValue, format);
7692
7076
  }
7693
- return removeFloatingPointErrors(clampedValue, format);
7077
+ handleVisualResize();
7078
+ vV.addEventListener('resize', handleVisualResize);
7079
+ return () => {
7080
+ vV.removeEventListener('resize', handleVisualResize);
7081
+ };
7694
7082
  }
7695
7083
 
7696
- const NumberFieldRoot = /*#__PURE__*/React.forwardRef(function NumberFieldRoot(componentProps, forwardedRef) {
7697
- const {
7698
- id: idProp,
7699
- min,
7700
- max,
7701
- smallStep = 0.1,
7702
- step: stepProp = 1,
7703
- largeStep = 10,
7704
- required = false,
7705
- disabled: disabledProp = false,
7706
- readOnly = false,
7707
- name: nameProp,
7708
- defaultValue,
7709
- value: valueProp,
7710
- onValueChange: onValueChangeProp,
7711
- onValueCommitted: onValueCommittedProp,
7712
- allowWheelScrub = false,
7713
- snapOnStep = false,
7714
- allowOutOfRange = false,
7715
- format,
7716
- locale,
7717
- render,
7718
- className,
7719
- inputRef: inputRefProp,
7720
- ...elementProps
7721
- } = componentProps;
7722
- const {
7723
- setDirty,
7724
- validityData,
7725
- disabled: fieldDisabled,
7726
- setFilled,
7727
- invalid,
7728
- name: fieldName,
7729
- state: fieldState,
7730
- validation,
7731
- shouldValidateOnChange
7732
- } = useFieldRootContext();
7733
- const disabled = fieldDisabled || disabledProp;
7734
- const name = fieldName ?? nameProp;
7735
- const step = stepProp === 'any' ? 1 : stepProp;
7736
- const [isScrubbing, setIsScrubbing] = React.useState(false);
7737
- const minWithDefault = min ?? Number.MIN_SAFE_INTEGER;
7738
- const maxWithDefault = max ?? Number.MAX_SAFE_INTEGER;
7739
- const minWithZeroDefault = min ?? 0;
7740
- const formatStyle = format?.style;
7741
- const inputRef = React.useRef(null);
7742
- const hiddenInputRef = useMergedRefs(inputRefProp, validation.inputRef);
7743
- const id = useLabelableId({
7744
- id: idProp
7745
- });
7746
- const [valueUnwrapped, setValueUnwrapped] = useControlled({
7747
- controlled: valueProp,
7748
- default: defaultValue,
7749
- name: 'NumberField',
7750
- state: 'value'
7751
- });
7752
- const value = valueUnwrapped ?? null;
7753
- const valueRef = useValueAsRef(value);
7754
- useIsoLayoutEffect(() => {
7755
- setFilled(value !== null);
7756
- }, [setFilled, value]);
7757
- const forceRender = useForcedRerendering();
7758
- const formatOptionsRef = useValueAsRef(format);
7759
- const hasPendingCommitRef = React.useRef(false);
7760
- const onValueCommitted = useStableCallback((nextValue, eventDetails) => {
7761
- hasPendingCommitRef.current = false;
7762
- onValueCommittedProp?.(nextValue, eventDetails);
7763
- });
7764
- const startTickTimeout = useTimeout();
7765
- const tickInterval = useInterval();
7766
- const intentionalTouchCheckTimeout = useTimeout();
7767
- const isPressedRef = React.useRef(false);
7768
- const movesAfterTouchRef = React.useRef(0);
7769
- const allowInputSyncRef = React.useRef(true);
7770
- const lastChangedValueRef = React.useRef(null);
7771
- const unsubscribeFromGlobalContextMenuRef = React.useRef(() => {});
7772
-
7773
- // During SSR, the value is formatted on the server, whose locale may differ from the client's
7774
- // locale. This causes a hydration mismatch, which we manually suppress. This is preferable to
7775
- // rendering an empty input field and then updating it with the formatted value, as the user
7776
- // can still see the value prior to hydration, even if it's not formatted correctly.
7777
- const [inputValue, setInputValue] = React.useState(() => {
7778
- if (valueProp !== undefined) {
7779
- return getControlledInputValue(value, locale, format);
7780
- }
7781
- return formatNumber(value, locale, format);
7782
- });
7783
- const [inputMode, setInputMode] = React.useState('numeric');
7784
- const getAllowedNonNumericKeys = useStableCallback(() => {
7785
- const {
7786
- decimal,
7787
- group,
7788
- currency,
7789
- literal
7790
- } = getNumberLocaleDetails(locale, format);
7791
- const keys = new Set();
7792
- BASE_NON_NUMERIC_SYMBOLS.forEach(symbol => keys.add(symbol));
7793
- if (decimal) {
7794
- keys.add(decimal);
7795
- }
7796
- if (group) {
7797
- keys.add(group);
7798
- if (SPACE_SEPARATOR_RE.test(group)) {
7799
- keys.add(' ');
7800
- }
7801
- }
7802
- const allowPercentSymbols = formatStyle === 'percent' || formatStyle === 'unit' && format?.unit === 'percent';
7803
- const allowPermilleSymbols = formatStyle === 'percent' || formatStyle === 'unit' && format?.unit === 'permille';
7804
- if (allowPercentSymbols) {
7805
- PERCENTAGES.forEach(key => keys.add(key));
7806
- }
7807
- if (allowPermilleSymbols) {
7808
- PERMILLE.forEach(key => keys.add(key));
7809
- }
7810
- if (formatStyle === 'currency' && currency) {
7811
- keys.add(currency);
7812
- }
7813
- if (literal) {
7814
- // Some locales (e.g. de-DE) insert a literal space character between the number
7815
- // and the symbol, so allow those characters to be typed/removed.
7816
- Array.from(literal).forEach(char => keys.add(char));
7817
- if (SPACE_SEPARATOR_RE.test(literal)) {
7818
- keys.add(' ');
7819
- }
7820
- }
7821
-
7822
- // Allow plus sign in all cases; minus sign only when negatives are valid
7823
- PLUS_SIGNS_WITH_ASCII.forEach(key => keys.add(key));
7824
- if (minWithDefault < 0) {
7825
- MINUS_SIGNS_WITH_ASCII.forEach(key => keys.add(key));
7826
- }
7827
- return keys;
7828
- });
7829
- const getStepAmount = useStableCallback(event => {
7830
- if (event?.altKey) {
7831
- return smallStep;
7832
- }
7833
- if (event?.shiftKey) {
7834
- return largeStep;
7835
- }
7836
- return step;
7837
- });
7838
- const setValue = useStableCallback((unvalidatedValue, details) => {
7839
- const eventWithOptionalKeyState = details.event;
7840
- const dir = details.direction;
7841
- const reason = details.reason;
7842
- // Only allow out-of-range values for direct text entry (native-like behavior).
7843
- // Step-based interactions (keyboard arrows, buttons, wheel, scrub) still clamp to min/max.
7844
- const shouldClampValue = !allowOutOfRange || !(reason === inputChange || reason === inputBlur || reason === inputPaste || reason === inputClear || reason === none);
7845
- const validatedValue = toValidatedNumber(unvalidatedValue, {
7846
- step: dir ? getStepAmount(eventWithOptionalKeyState) * dir : undefined,
7847
- format: formatOptionsRef.current,
7848
- minWithDefault,
7849
- maxWithDefault,
7850
- minWithZeroDefault,
7851
- snapOnStep,
7852
- small: eventWithOptionalKeyState?.altKey ?? false,
7853
- clamp: shouldClampValue
7854
- });
7855
-
7856
- // Determine whether we should notify about a change even if the numeric value is unchanged.
7857
- // This is needed when the user input is clamped/snapped to the same current value, or when
7858
- // the source value differs but validation normalizes to the existing value.
7859
- const isInputReason = details.reason === inputChange || details.reason === inputClear || details.reason === inputBlur || details.reason === inputPaste || details.reason === none;
7860
- const shouldFireChange = validatedValue !== value || isInputReason && (unvalidatedValue !== value || allowInputSyncRef.current === false);
7861
- if (shouldFireChange) {
7862
- lastChangedValueRef.current = validatedValue;
7863
- onValueChangeProp?.(validatedValue, details);
7864
- if (details.isCanceled) {
7865
- return shouldFireChange;
7866
- }
7867
- setValueUnwrapped(validatedValue);
7868
- setDirty(validatedValue !== validityData.initialValue);
7869
- hasPendingCommitRef.current = true;
7870
- }
7871
-
7872
- // Keep the visible input in sync immediately when programmatic changes occur
7873
- // (increment/decrement, wheel, etc). During direct typing we don't want
7874
- // to overwrite the user-provided text until blur, so we gate on
7875
- // `allowInputSyncRef`.
7876
- if (allowInputSyncRef.current) {
7877
- setInputValue(formatNumber(validatedValue, locale, format));
7878
- }
7879
-
7880
- // Formatting can change even if the numeric value hasn't, so ensure a re-render when needed.
7881
- forceRender();
7882
- return shouldFireChange;
7883
- });
7884
- const incrementValue = useStableCallback((amount, {
7885
- direction,
7886
- currentValue,
7887
- event,
7888
- reason
7889
- }) => {
7890
- const prevValue = currentValue == null ? valueRef.current : currentValue;
7891
- const nextValue = typeof prevValue === 'number' ? prevValue + amount * direction : Math.max(0, min ?? 0);
7892
- const nativeEvent = event;
7893
- return setValue(nextValue, createChangeEventDetails(reason, nativeEvent, undefined, {
7894
- direction
7895
- }));
7896
- });
7897
- const stopAutoChange = useStableCallback(() => {
7898
- intentionalTouchCheckTimeout.clear();
7899
- startTickTimeout.clear();
7900
- tickInterval.clear();
7901
- unsubscribeFromGlobalContextMenuRef.current();
7902
- movesAfterTouchRef.current = 0;
7903
- });
7904
- const startAutoChange = useStableCallback((isIncrement, triggerEvent) => {
7905
- stopAutoChange();
7906
- if (!inputRef.current) {
7907
- return;
7908
- }
7909
- const win = getWindow(inputRef.current);
7910
- function handleContextMenu(event) {
7911
- event.preventDefault();
7912
- }
7913
-
7914
- // A global context menu is necessary to prevent the context menu from appearing when the touch
7915
- // is slightly outside of the element's hit area.
7916
- win.addEventListener('contextmenu', handleContextMenu);
7917
- unsubscribeFromGlobalContextMenuRef.current = () => {
7918
- win.removeEventListener('contextmenu', handleContextMenu);
7919
- };
7920
- win.addEventListener('pointerup', event => {
7921
- isPressedRef.current = false;
7922
- stopAutoChange();
7923
- const committed = lastChangedValueRef.current ?? valueRef.current;
7924
- const commitReason = isIncrement ? incrementPress : decrementPress;
7925
- onValueCommitted(committed, createGenericEventDetails(commitReason, event));
7926
- }, {
7927
- once: true
7928
- });
7929
- function tick() {
7930
- const amount = getStepAmount(triggerEvent) ?? DEFAULT_STEP;
7931
- return incrementValue(amount, {
7932
- direction: isIncrement ? 1 : -1,
7933
- event: triggerEvent,
7934
- reason: isIncrement ? 'increment-press' : 'decrement-press'
7935
- });
7936
- }
7937
- if (!tick()) {
7938
- stopAutoChange();
7939
- return;
7940
- }
7941
- startTickTimeout.start(START_AUTO_CHANGE_DELAY, () => {
7942
- tickInterval.start(CHANGE_VALUE_TICK_DELAY, () => {
7943
- if (!tick()) {
7944
- stopAutoChange();
7945
- }
7946
- });
7947
- });
7948
- });
7949
-
7950
- // We need to update the input value when the external `value` prop changes. This ends up acting
7951
- // as a single source of truth to update the input value, bypassing the need to manually set it in
7952
- // each event handler internally in this hook.
7953
- // This is done inside a layout effect as an alternative to the technique to set state during
7954
- // render as we're accessing a ref, which must be inside an effect.
7955
- // https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
7956
- //
7957
- // ESLint is disabled because it needs to run even if the parsed value hasn't changed, since the
7958
- // value still can be formatted differently.
7959
- // eslint-disable-next-line react-hooks/exhaustive-deps
7960
- useIsoLayoutEffect(function syncFormattedInputValueOnValueChange() {
7961
- // This ensures the value is only updated on blur rather than every keystroke, but still
7962
- // allows the input value to be updated when the value is changed externally.
7963
- if (!allowInputSyncRef.current) {
7964
- return;
7965
- }
7966
- const nextInputValue = valueProp !== undefined ? getControlledInputValue(value, locale, format) : formatNumber(value, locale, format);
7967
- if (nextInputValue !== inputValue) {
7968
- setInputValue(nextInputValue);
7969
- }
7970
- });
7971
- useIsoLayoutEffect(function setDynamicInputModeForIOS() {
7972
- if (!isIOS) {
7973
- return;
7974
- }
7975
-
7976
- // iOS numeric software keyboard doesn't have a minus key, so we need to use the default
7977
- // keyboard to let the user input a negative number.
7978
- let computedInputMode = 'text';
7979
- if (minWithDefault >= 0) {
7980
- // iOS numeric software keyboard doesn't have a decimal key for "numeric" input mode, but
7981
- // this is better than the "text" input if possible to use.
7982
- computedInputMode = 'decimal';
7983
- }
7984
- setInputMode(computedInputMode);
7985
- }, [minWithDefault, formatStyle]);
7986
- React.useEffect(() => {
7987
- return () => stopAutoChange();
7988
- }, [stopAutoChange]);
7989
-
7990
- // The `onWheel` prop can't be prevented, so we need to use a global event listener.
7991
- React.useEffect(function registerElementWheelListener() {
7992
- const element = inputRef.current;
7993
- if (disabled || readOnly || !allowWheelScrub || !element) {
7994
- return undefined;
7995
- }
7996
- function handleWheel(event) {
7997
- if (
7998
- // Allow pinch-zooming.
7999
- event.ctrlKey || ownerDocument(inputRef.current).activeElement !== inputRef.current) {
8000
- return;
8001
- }
8002
-
8003
- // Prevent the default behavior to avoid scrolling the page.
8004
- event.preventDefault();
8005
- const amount = getStepAmount(event) ?? DEFAULT_STEP;
8006
- incrementValue(amount, {
8007
- direction: event.deltaY > 0 ? -1 : 1,
8008
- event,
8009
- reason: 'wheel'
8010
- });
8011
- }
8012
- element.addEventListener('wheel', handleWheel);
8013
- return () => {
8014
- element.removeEventListener('wheel', handleWheel);
8015
- };
8016
- }, [allowWheelScrub, incrementValue, disabled, readOnly, largeStep, step, getStepAmount]);
8017
- const state = React.useMemo(() => ({
8018
- ...fieldState,
8019
- disabled,
8020
- readOnly,
8021
- required,
8022
- value,
8023
- inputValue,
8024
- scrubbing: isScrubbing
8025
- }), [fieldState, disabled, readOnly, required, value, inputValue, isScrubbing]);
8026
- const contextValue = React.useMemo(() => ({
8027
- inputRef,
8028
- inputValue,
8029
- value,
8030
- startAutoChange,
8031
- stopAutoChange,
8032
- minWithDefault,
8033
- maxWithDefault,
8034
- disabled,
8035
- readOnly,
8036
- id,
8037
- setValue,
8038
- incrementValue,
8039
- getStepAmount,
8040
- allowInputSyncRef,
8041
- formatOptionsRef,
8042
- valueRef,
8043
- lastChangedValueRef,
8044
- hasPendingCommitRef,
8045
- isPressedRef,
8046
- intentionalTouchCheckTimeout,
8047
- movesAfterTouchRef,
8048
- name,
8049
- required,
8050
- invalid,
8051
- inputMode,
8052
- getAllowedNonNumericKeys,
8053
- min,
8054
- max,
8055
- setInputValue,
8056
- locale,
8057
- isScrubbing,
8058
- setIsScrubbing,
8059
- state,
8060
- onValueCommitted
8061
- }), [inputRef, inputValue, value, startAutoChange, stopAutoChange, minWithDefault, maxWithDefault, disabled, readOnly, id, setValue, incrementValue, getStepAmount, formatOptionsRef, valueRef, intentionalTouchCheckTimeout, name, required, invalid, inputMode, getAllowedNonNumericKeys, min, max, setInputValue, locale, isScrubbing, state, onValueCommitted]);
8062
- const element = useRenderElement('div', componentProps, {
8063
- ref: forwardedRef,
8064
- state,
8065
- props: elementProps,
8066
- stateAttributesMapping: stateAttributesMapping$1
8067
- });
8068
- return /*#__PURE__*/jsxs(NumberFieldRootContext.Provider, {
8069
- value: contextValue,
8070
- children: [element, /*#__PURE__*/jsx("input", {
8071
- ...validation.getInputValidationProps({
8072
- onFocus() {
8073
- inputRef.current?.focus();
8074
- },
8075
- onChange(event) {
8076
- // Workaround for https://github.com/facebook/react/issues/9023
8077
- if (event.nativeEvent.defaultPrevented) {
8078
- return;
8079
- }
8080
-
8081
- // Handle browser autofill.
8082
- const nextValue = event.currentTarget.valueAsNumber;
8083
- const parsedValue = Number.isNaN(nextValue) ? null : nextValue;
8084
- const details = createChangeEventDetails(none, event.nativeEvent);
8085
- setDirty(parsedValue !== validityData.initialValue);
8086
- setValue(parsedValue, details);
8087
- if (shouldValidateOnChange()) {
8088
- validation.commit(parsedValue);
8089
- }
8090
- }
8091
- }),
8092
- ref: hiddenInputRef,
8093
- type: "number",
8094
- name: name,
8095
- value: value ?? '',
8096
- min: min,
8097
- max: max
8098
- // stepMismatch validation is broken unless an explicit `min` is added.
8099
- // See https://github.com/facebook/react/issues/12334.
8100
- ,
8101
- step: stepProp,
8102
- disabled: disabled,
8103
- required: required,
8104
- "aria-hidden": true,
8105
- tabIndex: -1,
8106
- style: name ? visuallyHiddenInput : visuallyHidden
8107
- })]
8108
- });
8109
- });
8110
- if (process.env.NODE_ENV !== "production") NumberFieldRoot.displayName = "NumberFieldRoot";
8111
- function getControlledInputValue(value, locale, format) {
8112
- const explicitPrecision = format?.maximumFractionDigits != null || format?.minimumFractionDigits != null;
8113
- return explicitPrecision ? formatNumber(value, locale, format) : formatNumberMaxPrecision(value, locale, format);
8114
- }
8115
-
8116
- /**
8117
- * Groups the input with the increment and decrement buttons.
8118
- * Renders a `<div>` element.
8119
- *
8120
- * Documentation: [Base UI Number Field](https://base-ui.com/react/components/number-field)
8121
- */
8122
- const NumberFieldGroup = /*#__PURE__*/React.forwardRef(function NumberFieldGroup(componentProps, forwardedRef) {
8123
- const {
8124
- render,
8125
- className,
8126
- ...elementProps
8127
- } = componentProps;
8128
- const {
8129
- state
8130
- } = useNumberFieldRootContext();
8131
- const element = useRenderElement('div', componentProps, {
8132
- ref: forwardedRef,
8133
- state,
8134
- props: [{
8135
- role: 'group'
8136
- }, elementProps],
8137
- stateAttributesMapping: stateAttributesMapping$1
8138
- });
8139
- return element;
8140
- });
8141
- if (process.env.NODE_ENV !== "production") NumberFieldGroup.displayName = "NumberFieldGroup";
8142
-
8143
- // Treat pen as touch-like to avoid forcing the software keyboard on stylus taps.
8144
- // Linux Chrome may emit "pen" historically for mouse usage due to a bug, but the touch path
8145
- // still works with minor behavioral differences.
8146
- function isTouchLikePointerType(pointerType) {
8147
- return pointerType === 'touch' || pointerType === 'pen';
8148
- }
8149
- function useNumberFieldButton(params) {
8150
- const {
8151
- allowInputSyncRef,
8152
- disabled,
8153
- formatOptionsRef,
8154
- getStepAmount,
8155
- id,
8156
- incrementValue,
8157
- inputRef,
8158
- inputValue,
8159
- intentionalTouchCheckTimeout,
8160
- isIncrement,
8161
- isPressedRef,
8162
- locale,
8163
- movesAfterTouchRef,
8164
- readOnly,
8165
- setValue,
8166
- startAutoChange,
8167
- stopAutoChange,
8168
- valueRef,
8169
- lastChangedValueRef,
8170
- onValueCommitted
8171
- } = params;
8172
- const incrementDownCoordsRef = React.useRef({
8173
- x: 0,
8174
- y: 0
8175
- });
8176
- const isTouchingButtonRef = React.useRef(false);
8177
- const ignoreClickRef = React.useRef(false);
8178
- const pointerTypeRef = React.useRef('');
8179
- const pressReason = isIncrement ? 'increment-press' : 'decrement-press';
8180
- function commitValue(nativeEvent) {
8181
- allowInputSyncRef.current = true;
8182
-
8183
- // The input may be dirty but not yet blurred, so the value won't have been committed.
8184
- const parsedValue = parseNumber(inputValue, locale, formatOptionsRef.current);
8185
- if (parsedValue !== null) {
8186
- // The increment value function needs to know the current input value to increment it
8187
- // correctly.
8188
- valueRef.current = parsedValue;
8189
- setValue(parsedValue, createChangeEventDetails(pressReason, nativeEvent, undefined, {
8190
- direction: isIncrement ? 1 : -1
8191
- }));
8192
- }
8193
- }
8194
- const props = {
8195
- disabled,
8196
- 'aria-readonly': readOnly || undefined,
8197
- 'aria-label': isIncrement ? 'Increase' : 'Decrease',
8198
- 'aria-controls': id,
8199
- // Keyboard users shouldn't have access to the buttons, since they can use the input element
8200
- // to change the value. On the other hand, `aria-hidden` is not applied because touch screen
8201
- // readers should be able to use the buttons.
8202
- tabIndex: -1,
8203
- style: {
8204
- WebkitUserSelect: 'none',
8205
- userSelect: 'none'
8206
- },
8207
- onTouchStart() {
8208
- isTouchingButtonRef.current = true;
8209
- },
8210
- onTouchEnd() {
8211
- isTouchingButtonRef.current = false;
8212
- },
8213
- onClick(event) {
8214
- const isDisabled = disabled || readOnly;
8215
- if (event.defaultPrevented || isDisabled || (
8216
- // If it's not a keyboard/virtual click, ignore.
8217
- isTouchLikePointerType(pointerTypeRef.current) ? ignoreClickRef.current : event.detail !== 0)) {
8218
- return;
8219
- }
8220
- commitValue(event.nativeEvent);
8221
- const amount = getStepAmount(event) ?? DEFAULT_STEP;
8222
- const prev = valueRef.current;
8223
- incrementValue(amount, {
8224
- direction: isIncrement ? 1 : -1,
8225
- event: event.nativeEvent,
8226
- reason: pressReason
8227
- });
8228
- const committed = lastChangedValueRef.current ?? valueRef.current;
8229
- if (committed !== prev) {
8230
- onValueCommitted(committed, createGenericEventDetails(pressReason, event.nativeEvent));
8231
- }
8232
- },
8233
- onPointerDown(event) {
8234
- const isMainButton = !event.button || event.button === 0;
8235
- if (event.defaultPrevented || readOnly || !isMainButton || disabled) {
8236
- return;
8237
- }
8238
- pointerTypeRef.current = event.pointerType;
8239
- ignoreClickRef.current = false;
8240
- isPressedRef.current = true;
8241
- incrementDownCoordsRef.current = {
8242
- x: event.clientX,
8243
- y: event.clientY
8244
- };
8245
- commitValue(event.nativeEvent);
8246
- const isTouchPointer = isTouchLikePointerType(event.pointerType);
8247
- if (!isTouchPointer) {
8248
- event.preventDefault();
8249
- inputRef.current?.focus();
8250
- startAutoChange(isIncrement, event);
8251
- } else {
8252
- // We need to check if the pointerdown was intentional, and not the result of a scroll
8253
- // or pinch-zoom. In that case, we don't want to change the value.
8254
- intentionalTouchCheckTimeout.start(TOUCH_TIMEOUT, () => {
8255
- const moves = movesAfterTouchRef.current;
8256
- movesAfterTouchRef.current = 0;
8257
- // Only start auto-change if the touch is still pressed (prevents races
8258
- // with pointerup occurring before the timeout fires on quick taps).
8259
- const stillPressed = isPressedRef.current;
8260
- if (stillPressed && moves != null && moves < MAX_POINTER_MOVES_AFTER_TOUCH) {
8261
- startAutoChange(isIncrement, event);
8262
- ignoreClickRef.current = true; // synthesized click should be ignored
8263
- } else {
8264
- // No auto-change (simple tap or scroll gesture), allow the click handler
8265
- // to perform a single increment and commit.
8266
- ignoreClickRef.current = false;
8267
- stopAutoChange();
8268
- }
8269
- });
8270
- }
8271
- },
8272
- onPointerUp(event) {
8273
- // Ensure we mark the press as released for touch flows even if auto-change never started,
8274
- // so the delayed auto-change check won’t start after a quick tap.
8275
- if (isTouchLikePointerType(event.pointerType)) {
8276
- isPressedRef.current = false;
8277
- }
8278
- },
8279
- onPointerMove(event) {
8280
- const isDisabled = disabled || readOnly;
8281
- if (isDisabled || !isTouchLikePointerType(event.pointerType) || !isPressedRef.current) {
8282
- return;
8283
- }
8284
- if (movesAfterTouchRef.current != null) {
8285
- movesAfterTouchRef.current += 1;
8286
- }
8287
- const {
8288
- x,
8289
- y
8290
- } = incrementDownCoordsRef.current;
8291
- const dx = x - event.clientX;
8292
- const dy = y - event.clientY;
8293
-
8294
- // An alternative to this technique is to detect when the NumberField's parent container
8295
- // has been scrolled
8296
- if (dx ** 2 + dy ** 2 > SCROLLING_POINTER_MOVE_DISTANCE ** 2) {
8297
- stopAutoChange();
8298
- }
8299
- },
8300
- onMouseEnter(event) {
8301
- const isDisabled = disabled || readOnly;
8302
- if (event.defaultPrevented || isDisabled || !isPressedRef.current || isTouchingButtonRef.current || isTouchLikePointerType(pointerTypeRef.current)) {
8303
- return;
8304
- }
8305
- startAutoChange(isIncrement, event);
8306
- },
8307
- onMouseLeave() {
8308
- if (isTouchingButtonRef.current) {
8309
- return;
8310
- }
8311
- stopAutoChange();
8312
- },
8313
- onMouseUp() {
8314
- if (isTouchingButtonRef.current) {
8315
- return;
8316
- }
8317
- stopAutoChange();
8318
- }
8319
- };
8320
- return props;
8321
- }
8322
-
8323
- /**
8324
- * A stepper button that increases the field value when clicked.
8325
- * Renders an `<button>` element.
8326
- *
8327
- * Documentation: [Base UI Number Field](https://base-ui.com/react/components/number-field)
8328
- */
8329
- const NumberFieldIncrement = /*#__PURE__*/React.forwardRef(function NumberFieldIncrement(componentProps, forwardedRef) {
8330
- const {
8331
- render,
8332
- className,
8333
- disabled: disabledProp = false,
8334
- nativeButton = true,
8335
- ...elementProps
8336
- } = componentProps;
8337
- const {
8338
- allowInputSyncRef,
8339
- disabled: contextDisabled,
8340
- formatOptionsRef,
8341
- getStepAmount,
8342
- id,
8343
- incrementValue,
8344
- inputRef,
8345
- inputValue,
8346
- intentionalTouchCheckTimeout,
8347
- isPressedRef,
8348
- locale,
8349
- maxWithDefault,
8350
- movesAfterTouchRef,
8351
- readOnly,
8352
- setValue,
8353
- startAutoChange,
8354
- state,
8355
- stopAutoChange,
8356
- value,
8357
- valueRef,
8358
- lastChangedValueRef,
8359
- onValueCommitted
8360
- } = useNumberFieldRootContext();
8361
- const isMax = value != null && value >= maxWithDefault;
8362
- const disabled = disabledProp || contextDisabled || isMax;
8363
- const props = useNumberFieldButton({
8364
- isIncrement: true,
8365
- inputRef,
8366
- startAutoChange,
8367
- stopAutoChange,
8368
- inputValue,
8369
- disabled,
8370
- readOnly,
8371
- id,
8372
- setValue,
8373
- getStepAmount,
8374
- incrementValue,
8375
- allowInputSyncRef,
8376
- formatOptionsRef,
8377
- valueRef,
8378
- isPressedRef,
8379
- intentionalTouchCheckTimeout,
8380
- movesAfterTouchRef,
8381
- locale,
8382
- lastChangedValueRef,
8383
- onValueCommitted
8384
- });
8385
- const {
8386
- getButtonProps,
8387
- buttonRef
8388
- } = useButton({
8389
- disabled,
8390
- native: nativeButton,
8391
- focusableWhenDisabled: true
8392
- });
8393
- const buttonState = React.useMemo(() => ({
8394
- ...state,
8395
- disabled
8396
- }), [state, disabled]);
8397
- const element = useRenderElement('button', componentProps, {
8398
- ref: [forwardedRef, buttonRef],
8399
- state: buttonState,
8400
- props: [props, elementProps, getButtonProps],
8401
- stateAttributesMapping: stateAttributesMapping$1
8402
- });
8403
- return element;
8404
- });
8405
- if (process.env.NODE_ENV !== "production") NumberFieldIncrement.displayName = "NumberFieldIncrement";
8406
-
8407
- /**
8408
- * A stepper button that decreases the field value when clicked.
8409
- * Renders an `<button>` element.
8410
- *
8411
- * Documentation: [Base UI Number Field](https://base-ui.com/react/components/number-field)
8412
- */
8413
- const NumberFieldDecrement = /*#__PURE__*/React.forwardRef(function NumberFieldDecrement(componentProps, forwardedRef) {
8414
- const {
8415
- render,
8416
- className,
8417
- disabled: disabledProp = false,
8418
- nativeButton = true,
8419
- ...elementProps
8420
- } = componentProps;
8421
- const {
8422
- allowInputSyncRef,
8423
- disabled: contextDisabled,
8424
- formatOptionsRef,
8425
- getStepAmount,
8426
- id,
8427
- incrementValue,
8428
- inputRef,
8429
- inputValue,
8430
- intentionalTouchCheckTimeout,
8431
- isPressedRef,
8432
- minWithDefault,
8433
- movesAfterTouchRef,
8434
- readOnly,
8435
- setValue,
8436
- startAutoChange,
8437
- state,
8438
- stopAutoChange,
8439
- value,
8440
- valueRef,
8441
- locale,
8442
- lastChangedValueRef,
8443
- onValueCommitted
8444
- } = useNumberFieldRootContext();
8445
- const isMin = value != null && value <= minWithDefault;
8446
- const disabled = disabledProp || contextDisabled || isMin;
8447
- const props = useNumberFieldButton({
8448
- isIncrement: false,
8449
- inputRef,
8450
- startAutoChange,
8451
- stopAutoChange,
8452
- inputValue,
8453
- disabled,
8454
- readOnly,
8455
- id,
8456
- setValue,
8457
- getStepAmount,
8458
- incrementValue,
8459
- allowInputSyncRef,
8460
- formatOptionsRef,
8461
- valueRef,
8462
- isPressedRef,
8463
- intentionalTouchCheckTimeout,
8464
- movesAfterTouchRef,
8465
- locale,
8466
- lastChangedValueRef,
8467
- onValueCommitted
8468
- });
8469
- const {
8470
- getButtonProps,
8471
- buttonRef
8472
- } = useButton({
8473
- disabled,
8474
- native: nativeButton,
8475
- focusableWhenDisabled: true
8476
- });
8477
- const buttonState = React.useMemo(() => ({
8478
- ...state,
8479
- disabled
8480
- }), [state, disabled]);
8481
- const element = useRenderElement('button', componentProps, {
8482
- ref: [forwardedRef, buttonRef],
8483
- state: buttonState,
8484
- props: [props, elementProps, getButtonProps],
8485
- stateAttributesMapping: stateAttributesMapping$1
8486
- });
8487
- return element;
8488
- });
8489
- if (process.env.NODE_ENV !== "production") NumberFieldDecrement.displayName = "NumberFieldDecrement";
8490
-
8491
- const stateAttributesMapping = {
8492
- ...fieldValidityMapping,
8493
- ...stateAttributesMapping$1
8494
- };
8495
- const NAVIGATE_KEYS = new Set(['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Enter', 'Escape']);
8496
-
8497
- /**
8498
- * The native input control in the number field.
8499
- * Renders an `<input>` element.
8500
- *
8501
- * Documentation: [Base UI Number Field](https://base-ui.com/react/components/number-field)
8502
- */
8503
- const NumberFieldInput = /*#__PURE__*/React.forwardRef(function NumberFieldInput(componentProps, forwardedRef) {
8504
- const {
8505
- render,
8506
- className,
8507
- ...elementProps
8508
- } = componentProps;
8509
- const {
8510
- allowInputSyncRef,
8511
- disabled,
8512
- formatOptionsRef,
8513
- getAllowedNonNumericKeys,
8514
- getStepAmount,
8515
- id,
8516
- incrementValue,
8517
- inputMode,
8518
- inputValue,
8519
- max,
8520
- min,
8521
- name,
8522
- readOnly,
8523
- required,
8524
- setValue,
8525
- state,
8526
- setInputValue,
8527
- locale,
8528
- inputRef,
8529
- value,
8530
- onValueCommitted,
8531
- lastChangedValueRef,
8532
- hasPendingCommitRef,
8533
- valueRef
8534
- } = useNumberFieldRootContext();
8535
- const {
8536
- clearErrors
8537
- } = useFormContext();
8538
- const {
8539
- validationMode,
8540
- setTouched,
8541
- setFocused,
8542
- invalid,
8543
- shouldValidateOnChange,
8544
- validation
8545
- } = useFieldRootContext();
8546
- const {
8547
- labelId
8548
- } = useLabelableContext();
8549
- const hasTouchedInputRef = React.useRef(false);
8550
- const blockRevalidationRef = React.useRef(false);
8551
- useField({
8552
- id,
8553
- commit: validation.commit,
8554
- value,
8555
- controlRef: inputRef,
8556
- name,
8557
- getValue: () => value ?? null
8558
- });
8559
- useValueChanged(value, previousValue => {
8560
- const validateOnChange = shouldValidateOnChange();
8561
- clearErrors(name);
8562
- if (validateOnChange) {
8563
- validation.commit(value);
8564
- }
8565
- if (previousValue === value || validateOnChange) {
8566
- return;
8567
- }
8568
- if (blockRevalidationRef.current) {
8569
- blockRevalidationRef.current = false;
8570
- return;
8571
- }
8572
- validation.commit(value, true);
8573
- });
8574
- const inputProps = {
8575
- id,
8576
- required,
8577
- disabled,
8578
- readOnly,
8579
- inputMode,
8580
- value: inputValue,
8581
- type: 'text',
8582
- autoComplete: 'off',
8583
- autoCorrect: 'off',
8584
- spellCheck: 'false',
8585
- 'aria-roledescription': 'Number field',
8586
- 'aria-invalid': invalid || undefined,
8587
- 'aria-labelledby': labelId,
8588
- // If the server's locale does not match the client's locale, the formatting may not match,
8589
- // causing a hydration mismatch.
8590
- suppressHydrationWarning: true,
8591
- onFocus(event) {
8592
- if (event.defaultPrevented || readOnly || disabled) {
8593
- return;
8594
- }
8595
- setFocused(true);
8596
- if (hasTouchedInputRef.current) {
8597
- return;
8598
- }
8599
- hasTouchedInputRef.current = true;
8600
-
8601
- // Browsers set selection at the start of the input field by default. We want to set it at
8602
- // the end for the first focus.
8603
- const target = event.currentTarget;
8604
- const length = target.value.length;
8605
- target.setSelectionRange(length, length);
8606
- },
8607
- onBlur(event) {
8608
- if (event.defaultPrevented || readOnly || disabled) {
8609
- return;
8610
- }
8611
- setTouched(true);
8612
- setFocused(false);
8613
- const hadManualInput = !allowInputSyncRef.current;
8614
- const hadPendingProgrammaticChange = hasPendingCommitRef.current;
8615
- allowInputSyncRef.current = true;
8616
- if (inputValue.trim() === '') {
8617
- setValue(null, createChangeEventDetails(inputClear, event.nativeEvent));
8618
- if (validationMode === 'onBlur') {
8619
- validation.commit(null);
8620
- }
8621
- onValueCommitted(null, createGenericEventDetails(inputClear, event.nativeEvent));
8622
- return;
8623
- }
8624
- const formatOptions = formatOptionsRef.current;
8625
- const parsedValue = parseNumber(inputValue, locale, formatOptions);
8626
- if (parsedValue === null) {
8627
- return;
8628
- }
8629
-
8630
- // If an explicit precision is requested, round the committed numeric value.
8631
- const hasExplicitPrecision = formatOptions?.maximumFractionDigits != null || formatOptions?.minimumFractionDigits != null;
8632
- const maxFrac = formatOptions?.maximumFractionDigits;
8633
- const committed = hasExplicitPrecision && typeof maxFrac === 'number' ? Number(parsedValue.toFixed(maxFrac)) : parsedValue;
8634
- const nextEventDetails = createGenericEventDetails(inputBlur, event.nativeEvent);
8635
- const shouldUpdateValue = value !== committed;
8636
- const shouldCommit = hadManualInput || shouldUpdateValue || hadPendingProgrammaticChange;
8637
- if (validationMode === 'onBlur') {
8638
- validation.commit(committed);
8639
- }
8640
- if (shouldUpdateValue) {
8641
- blockRevalidationRef.current = true;
8642
- setValue(committed, createChangeEventDetails(inputBlur, event.nativeEvent));
8643
- }
8644
- if (shouldCommit) {
8645
- onValueCommitted(committed, nextEventDetails);
8646
- }
8647
-
8648
- // Normalize only the displayed text
8649
- const canonicalText = formatNumber(committed, locale, formatOptions);
8650
- const maxPrecisionText = formatNumberMaxPrecision(parsedValue, locale, formatOptions);
8651
- const shouldPreserveFullPrecision = !hasExplicitPrecision && parsedValue === value && inputValue === maxPrecisionText;
8652
- if (!shouldPreserveFullPrecision && inputValue !== canonicalText) {
8653
- setInputValue(canonicalText);
8654
- }
8655
- },
8656
- onChange(event) {
8657
- // Workaround for https://github.com/facebook/react/issues/9023
8658
- if (event.nativeEvent.defaultPrevented) {
8659
- return;
8660
- }
8661
- allowInputSyncRef.current = false;
8662
- const targetValue = event.target.value;
8663
- if (targetValue.trim() === '') {
8664
- setInputValue(targetValue);
8665
- setValue(null, createChangeEventDetails(inputClear, event.nativeEvent));
8666
- return;
8667
- }
8668
-
8669
- // Update the input text immediately and only fire onValueChange if the typed value is
8670
- // currently parseable into a number. This preserves good UX for IME
8671
- // composition/partial input while still providing live numeric updates when possible.
8672
- const allowedNonNumericKeys = getAllowedNonNumericKeys();
8673
- const isValidCharacterString = Array.from(targetValue).every(ch => {
8674
- const isAsciiDigit = ch >= '0' && ch <= '9';
8675
- const isArabicNumeral = ARABIC_DETECT_RE.test(ch);
8676
- const isHanNumeral = HAN_DETECT_RE.test(ch);
8677
- const isPersianNumeral = PERSIAN_DETECT_RE.test(ch);
8678
- const isFullwidthNumeral = FULLWIDTH_DETECT_RE.test(ch);
8679
- const isMinus = ANY_MINUS_DETECT_RE.test(ch);
8680
- return isAsciiDigit || isArabicNumeral || isHanNumeral || isPersianNumeral || isFullwidthNumeral || isMinus || allowedNonNumericKeys.has(ch);
8681
- });
8682
- if (!isValidCharacterString) {
8683
- return;
8684
- }
8685
- const parsedValue = parseNumber(targetValue, locale, formatOptionsRef.current);
8686
- setInputValue(targetValue);
8687
- if (parsedValue !== null) {
8688
- setValue(parsedValue, createChangeEventDetails(inputChange, event.nativeEvent));
8689
- }
8690
- },
8691
- onKeyDown(event) {
8692
- if (event.defaultPrevented || readOnly || disabled) {
8693
- return;
8694
- }
8695
- const nativeEvent = event.nativeEvent;
8696
- allowInputSyncRef.current = true;
8697
- const allowedNonNumericKeys = getAllowedNonNumericKeys();
8698
- let isAllowedNonNumericKey = allowedNonNumericKeys.has(event.key);
8699
- const {
8700
- decimal,
8701
- currency,
8702
- percentSign
8703
- } = getNumberLocaleDetails(locale, formatOptionsRef.current);
8704
- const selectionStart = event.currentTarget.selectionStart;
8705
- const selectionEnd = event.currentTarget.selectionEnd;
8706
- const isAllSelected = selectionStart === 0 && selectionEnd === inputValue.length;
8707
-
8708
- // Normalize handling of plus/minus signs via precomputed regexes
8709
- const selectionContainsIndex = index => selectionStart != null && selectionEnd != null && index >= selectionStart && index < selectionEnd;
8710
- if (ANY_MINUS_DETECT_RE.test(event.key) && Array.from(allowedNonNumericKeys).some(k => ANY_MINUS_DETECT_RE.test(k || ''))) {
8711
- // Only allow one sign unless replacing the existing one or all text is selected
8712
- const existingIndex = inputValue.search(ANY_MINUS_RE);
8713
- const isReplacingExisting = existingIndex != null && existingIndex !== -1 && selectionContainsIndex(existingIndex);
8714
- isAllowedNonNumericKey = !(ANY_MINUS_DETECT_RE.test(inputValue) || ANY_PLUS_DETECT_RE.test(inputValue)) || isAllSelected || isReplacingExisting;
8715
- }
8716
- if (ANY_PLUS_DETECT_RE.test(event.key) && Array.from(allowedNonNumericKeys).some(k => ANY_PLUS_DETECT_RE.test(k || ''))) {
8717
- const existingIndex = inputValue.search(ANY_PLUS_RE);
8718
- const isReplacingExisting = existingIndex != null && existingIndex !== -1 && selectionContainsIndex(existingIndex);
8719
- isAllowedNonNumericKey = !(ANY_MINUS_DETECT_RE.test(inputValue) || ANY_PLUS_DETECT_RE.test(inputValue)) || isAllSelected || isReplacingExisting;
8720
- }
8721
-
8722
- // Only allow one of each symbol.
8723
- [decimal, currency, percentSign].forEach(symbol => {
8724
- if (event.key === symbol) {
8725
- const symbolIndex = inputValue.indexOf(symbol);
8726
- const isSymbolHighlighted = selectionContainsIndex(symbolIndex);
8727
- isAllowedNonNumericKey = !inputValue.includes(symbol) || isAllSelected || isSymbolHighlighted;
8728
- }
8729
- });
8730
- const isAsciiDigit = event.key >= '0' && event.key <= '9';
8731
- const isArabicNumeral = ARABIC_DETECT_RE.test(event.key);
8732
- const isHanNumeral = HAN_DETECT_RE.test(event.key);
8733
- const isFullwidthNumeral = FULLWIDTH_DETECT_RE.test(event.key);
8734
- const isNavigateKey = NAVIGATE_KEYS.has(event.key);
8735
- if (
8736
- // Allow composition events (e.g., pinyin)
8737
- // event.nativeEvent.isComposing does not work in Safari:
8738
- // https://bugs.webkit.org/show_bug.cgi?id=165004
8739
- event.which === 229 || event.altKey || event.ctrlKey || event.metaKey || isAllowedNonNumericKey || isAsciiDigit || isArabicNumeral || isFullwidthNumeral || isHanNumeral || isNavigateKey) {
8740
- return;
8741
- }
8742
-
8743
- // We need to commit the number at this point if the input hasn't been blurred.
8744
- const parsedValue = parseNumber(inputValue, locale, formatOptionsRef.current);
8745
- const amount = getStepAmount(event) ?? DEFAULT_STEP;
8746
-
8747
- // Prevent insertion of text or caret from moving.
8748
- stopEvent(event);
8749
- const commitDetails = createGenericEventDetails(keyboard, nativeEvent);
8750
- if (event.key === 'ArrowUp') {
8751
- incrementValue(amount, {
8752
- direction: 1,
8753
- currentValue: parsedValue,
8754
- event: nativeEvent,
8755
- reason: keyboard
8756
- });
8757
- onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
8758
- } else if (event.key === 'ArrowDown') {
8759
- incrementValue(amount, {
8760
- direction: -1,
8761
- currentValue: parsedValue,
8762
- event: nativeEvent,
8763
- reason: keyboard
8764
- });
8765
- onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
8766
- } else if (event.key === 'Home' && min != null) {
8767
- setValue(min, createChangeEventDetails(keyboard, nativeEvent));
8768
- onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
8769
- } else if (event.key === 'End' && max != null) {
8770
- setValue(max, createChangeEventDetails(keyboard, nativeEvent));
8771
- onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
8772
- }
8773
- },
8774
- onPaste(event) {
8775
- if (event.defaultPrevented || readOnly || disabled) {
8776
- return;
8777
- }
8778
-
8779
- // Prevent `onChange` from being called.
8780
- event.preventDefault();
8781
- const clipboardData = event.clipboardData || window.Clipboard;
8782
- const pastedData = clipboardData.getData('text/plain');
8783
- const parsedValue = parseNumber(pastedData, locale, formatOptionsRef.current);
8784
- if (parsedValue !== null) {
8785
- allowInputSyncRef.current = false;
8786
- setValue(parsedValue, createChangeEventDetails(inputPaste, event.nativeEvent));
8787
- setInputValue(pastedData);
8788
- }
8789
- }
8790
- };
8791
- const element = useRenderElement('input', componentProps, {
8792
- ref: [forwardedRef, inputRef],
8793
- state,
8794
- props: [inputProps, validation.getValidationProps(), elementProps],
8795
- stateAttributesMapping
8796
- });
8797
- return element;
8798
- });
8799
- if (process.env.NODE_ENV !== "production") NumberFieldInput.displayName = "NumberFieldInput";
8800
-
8801
- const NumberFieldScrubAreaContext = /*#__PURE__*/React.createContext(undefined);
8802
- if (process.env.NODE_ENV !== "production") NumberFieldScrubAreaContext.displayName = "NumberFieldScrubAreaContext";
8803
- function useNumberFieldScrubAreaContext() {
8804
- const context = React.useContext(NumberFieldScrubAreaContext);
8805
- if (context === undefined) {
8806
- throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: NumberFieldScrubAreaContext is missing. NumberFieldScrubArea parts must be placed within <NumberField.ScrubArea>.' : formatErrorMessage(44));
8807
- }
8808
- return context;
8809
- }
8810
-
8811
- // Calculates the viewport rect for the virtual cursor.
8812
- function getViewportRect(teleportDistance, scrubAreaEl) {
8813
- const win = getWindow(scrubAreaEl);
8814
- const rect = scrubAreaEl.getBoundingClientRect();
8815
- if (rect && teleportDistance != null) {
8816
- return {
8817
- x: rect.left - teleportDistance / 2,
8818
- y: rect.top - teleportDistance / 2,
8819
- width: rect.right + teleportDistance / 2,
8820
- height: rect.bottom + teleportDistance / 2
8821
- };
8822
- }
8823
- const vV = win.visualViewport;
8824
- if (vV) {
8825
- return {
8826
- x: vV.offsetLeft,
8827
- y: vV.offsetTop,
8828
- width: vV.offsetLeft + vV.width,
8829
- height: vV.offsetTop + vV.height
8830
- };
8831
- }
8832
- return {
8833
- x: 0,
8834
- y: 0,
8835
- width: win.document.documentElement.clientWidth,
8836
- height: win.document.documentElement.clientHeight
8837
- };
8838
- }
8839
-
8840
- // This lets us invert the scale of the cursor to match the OS scale, in which the cursor doesn't
8841
- // scale with the content on pinch-zoom.
8842
- function subscribeToVisualViewportResize(element, visualScaleRef) {
8843
- const vV = getWindow(element).visualViewport;
8844
- if (!vV) {
8845
- return () => {};
8846
- }
8847
- function handleVisualResize() {
8848
- if (vV) {
8849
- visualScaleRef.current = vV.scale;
8850
- }
8851
- }
8852
- handleVisualResize();
8853
- vV.addEventListener('resize', handleVisualResize);
8854
- return () => {
8855
- vV.removeEventListener('resize', handleVisualResize);
8856
- };
8857
- }
8858
-
8859
- const NumberFieldScrubArea = /*#__PURE__*/React.forwardRef(function NumberFieldScrubArea(componentProps, forwardedRef) {
7084
+ const NumberFieldScrubArea = /*#__PURE__*/React.forwardRef(function NumberFieldScrubArea(componentProps, forwardedRef) {
8860
7085
  const {
8861
7086
  render,
8862
7087
  className,
@@ -9089,7 +7314,7 @@ const NumberFieldScrubArea = /*#__PURE__*/React.forwardRef(function NumberFieldS
9089
7314
  ref: [forwardedRef, scrubAreaRef],
9090
7315
  state,
9091
7316
  props: [defaultProps, elementProps],
9092
- stateAttributesMapping: stateAttributesMapping$1
7317
+ stateAttributesMapping: stateAttributesMapping$9
9093
7318
  });
9094
7319
  const contextValue = React.useMemo(() => ({
9095
7320
  isScrubbing,
@@ -9147,7 +7372,7 @@ const NumberFieldScrubAreaCursor = /*#__PURE__*/React.forwardRef(function Number
9147
7372
  pointerEvents: 'none'
9148
7373
  }
9149
7374
  }, elementProps],
9150
- stateAttributesMapping: stateAttributesMapping$1
7375
+ stateAttributesMapping: stateAttributesMapping$9
9151
7376
  });
9152
7377
  return element && /*#__PURE__*/ReactDOM.createPortal(element, ownerDocument(domElement).body);
9153
7378
  });