@octanejs/base-ui 0.1.30 → 0.1.32
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/cjs/accordion.cjs +497 -0
- package/dist/cjs/alert-dialog.cjs +65 -0
- package/dist/cjs/avatar.cjs +234 -0
- package/dist/cjs/button.cjs +54 -0
- package/dist/cjs/checkbox-group.cjs +165 -0
- package/dist/cjs/checkbox.cjs +475 -0
- package/dist/cjs/collapsible.cjs +700 -0
- package/dist/cjs/context-menu.cjs +257 -0
- package/dist/cjs/csp-provider.cjs +40 -0
- package/dist/cjs/dialog.cjs +741 -0
- package/dist/cjs/direction-provider.cjs +35 -0
- package/dist/cjs/field.cjs +559 -0
- package/dist/cjs/fieldset.cjs +101 -0
- package/dist/cjs/form.cjs +177 -0
- package/dist/cjs/index.cjs +133 -0
- package/dist/cjs/input.cjs +32 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/menu.cjs +2420 -0
- package/dist/cjs/menubar.cjs +132 -0
- package/dist/cjs/merge-props.cjs +34 -0
- package/dist/cjs/meter.cjs +169 -0
- package/dist/cjs/number-field.cjs +812 -0
- package/dist/cjs/popover.cjs +966 -0
- package/dist/cjs/preview-card.cjs +632 -0
- package/dist/cjs/progress.cjs +206 -0
- package/dist/cjs/radio-group.cjs +264 -0
- package/dist/cjs/radio.cjs +327 -0
- package/dist/cjs/separator.cjs +44 -0
- package/dist/cjs/slider.cjs +1384 -0
- package/dist/cjs/switch.cjs +306 -0
- package/dist/cjs/tabs.cjs +727 -0
- package/dist/cjs/toast.cjs +1766 -0
- package/dist/cjs/toggle-group.cjs +118 -0
- package/dist/cjs/toggle.cjs +121 -0
- package/dist/cjs/tooltip.cjs +835 -0
- package/dist/cjs/unstable-use-media-query.cjs +79 -0
- package/dist/cjs/use-render.cjs +40 -0
- package/dist/cjs/utils/CSPContext.cjs +38 -0
- package/dist/cjs/utils/CheckboxGroupContext.cjs +40 -0
- package/dist/cjs/utils/CompositeRootContext.cjs +40 -0
- package/dist/cjs/utils/ContextMenuRootContext.cjs +42 -0
- package/dist/cjs/utils/DirectionContext.cjs +34 -0
- package/dist/cjs/utils/FloatingPortalLite.cjs +47 -0
- package/dist/cjs/utils/InternalBackdrop.cjs +49 -0
- package/dist/cjs/utils/MenubarContext.cjs +40 -0
- package/dist/cjs/utils/RadioGroupContext.cjs +34 -0
- package/dist/cjs/utils/RequestQueue.cjs +111 -0
- package/dist/cjs/utils/TimeoutManager.cjs +50 -0
- package/dist/cjs/utils/ToggleGroupContext.cjs +40 -0
- package/dist/cjs/utils/adaptiveOriginMiddleware.cjs +94 -0
- package/dist/cjs/utils/addEventListener.cjs +33 -0
- package/dist/cjs/utils/areArraysEqual.cjs +30 -0
- package/dist/cjs/utils/clamp.cjs +30 -0
- package/dist/cjs/utils/closePart.cjs +70 -0
- package/dist/cjs/utils/collapsibleOpenStateMapping.cjs +42 -0
- package/dist/cjs/utils/composeRefs.cjs +68 -0
- package/dist/cjs/utils/composite/CompositeItem.cjs +59 -0
- package/dist/cjs/utils/composite/CompositeList.cjs +177 -0
- package/dist/cjs/utils/composite/CompositeListContext.cjs +43 -0
- package/dist/cjs/utils/composite/CompositeRoot.cjs +118 -0
- package/dist/cjs/utils/composite/grid-utils.cjs +343 -0
- package/dist/cjs/utils/composite/gridNavigation.cjs +92 -0
- package/dist/cjs/utils/composite/keys.cjs +174 -0
- package/dist/cjs/utils/composite/list-utils.cjs +90 -0
- package/dist/cjs/utils/composite/useCompositeItem.cjs +63 -0
- package/dist/cjs/utils/composite/useCompositeListItem.cjs +104 -0
- package/dist/cjs/utils/composite/useCompositeRoot.cjs +263 -0
- package/dist/cjs/utils/constants.cjs +56 -0
- package/dist/cjs/utils/contains.cjs +46 -0
- package/dist/cjs/utils/createChangeEventDetails.cjs +92 -0
- package/dist/cjs/utils/dom.cjs +35 -0
- package/dist/cjs/utils/empty.cjs +34 -0
- package/dist/cjs/utils/field/FieldItemContext.cjs +34 -0
- package/dist/cjs/utils/field/FieldRootContext.cjs +80 -0
- package/dist/cjs/utils/field/FormContext.cjs +41 -0
- package/dist/cjs/utils/field/LabelableContext.cjs +43 -0
- package/dist/cjs/utils/field/LabelableProvider.cjs +115 -0
- package/dist/cjs/utils/field/constants.cjs +68 -0
- package/dist/cjs/utils/field/getCombinedFieldValidityData.cjs +36 -0
- package/dist/cjs/utils/field/useAriaLabelledBy.cjs +87 -0
- package/dist/cjs/utils/field/useFieldControlRegistration.cjs +165 -0
- package/dist/cjs/utils/field/useFieldValidation.cjs +285 -0
- package/dist/cjs/utils/field/useLabel.cjs +99 -0
- package/dist/cjs/utils/field/useLabelableId.cjs +105 -0
- package/dist/cjs/utils/field/useRegisterFieldControl.cjs +60 -0
- package/dist/cjs/utils/findRootOwnerId.cjs +37 -0
- package/dist/cjs/utils/floating/FloatingDelayGroup.cjs +219 -0
- package/dist/cjs/utils/floating/FloatingFocusManager.cjs +685 -0
- package/dist/cjs/utils/floating/FloatingPortal.cjs +230 -0
- package/dist/cjs/utils/floating/FloatingRootStore.cjs +87 -0
- package/dist/cjs/utils/floating/FloatingTree.cjs +86 -0
- package/dist/cjs/utils/floating/FloatingTreeStore.cjs +41 -0
- package/dist/cjs/utils/floating/FocusGuard.cjs +54 -0
- package/dist/cjs/utils/floating/composite.cjs +42 -0
- package/dist/cjs/utils/floating/constants.cjs +34 -0
- package/dist/cjs/utils/floating/createAttribute.cjs +30 -0
- package/dist/cjs/utils/floating/createEventEmitter.cjs +44 -0
- package/dist/cjs/utils/floating/element.cjs +103 -0
- package/dist/cjs/utils/floating/enqueueFocus.cjs +51 -0
- package/dist/cjs/utils/floating/event.cjs +65 -0
- package/dist/cjs/utils/floating/getEmptyRootContext.cjs +42 -0
- package/dist/cjs/utils/floating/gridNavigation.cjs +45 -0
- package/dist/cjs/utils/floating/markOthers.cjs +181 -0
- package/dist/cjs/utils/floating/nodes.cjs +48 -0
- package/dist/cjs/utils/floating/safePolygon.cjs +301 -0
- package/dist/cjs/utils/floating/tabbable.cjs +242 -0
- package/dist/cjs/utils/floating/types.cjs +16 -0
- package/dist/cjs/utils/floating/useClick.cjs +153 -0
- package/dist/cjs/utils/floating/useClientPoint.cjs +225 -0
- package/dist/cjs/utils/floating/useDismiss.cjs +506 -0
- package/dist/cjs/utils/floating/useFloating.cjs +186 -0
- package/dist/cjs/utils/floating/useFloatingRootContext.cjs +75 -0
- package/dist/cjs/utils/floating/useFocus.cjs +184 -0
- package/dist/cjs/utils/floating/useHoverFloatingInteraction.cjs +231 -0
- package/dist/cjs/utils/floating/useHoverInteractionSharedState.cjs +113 -0
- package/dist/cjs/utils/floating/useHoverReferenceInteraction.cjs +380 -0
- package/dist/cjs/utils/floating/useHoverShared.cjs +65 -0
- package/dist/cjs/utils/floating/useListNavigation.cjs +665 -0
- package/dist/cjs/utils/floating/useSyncedFloatingRootContext.cjs +91 -0
- package/dist/cjs/utils/floating/useTypeahead.cjs +187 -0
- package/dist/cjs/utils/formatNumber.cjs +60 -0
- package/dist/cjs/utils/generateId.cjs +32 -0
- package/dist/cjs/utils/getCssDimensions.cjs +42 -0
- package/dist/cjs/utils/getDefaultFormSubmitter.cjs +42 -0
- package/dist/cjs/utils/getDisabledMountTransitionStyles.cjs +32 -0
- package/dist/cjs/utils/getElementRef.cjs +35 -0
- package/dist/cjs/utils/getPseudoElementBounds.cjs +56 -0
- package/dist/cjs/utils/getStateAttributesProps.cjs +46 -0
- package/dist/cjs/utils/hideMiddleware.cjs +42 -0
- package/dist/cjs/utils/inertValue.cjs +30 -0
- package/dist/cjs/utils/matchesFocusVisible.cjs +38 -0
- package/dist/cjs/utils/mergeCleanups.cjs +37 -0
- package/dist/cjs/utils/mergeObjects.cjs +39 -0
- package/dist/cjs/utils/mergeProps.cjs +182 -0
- package/dist/cjs/utils/noop.cjs +29 -0
- package/dist/cjs/utils/number/constants.cjs +34 -0
- package/dist/cjs/utils/number/parse.cjs +258 -0
- package/dist/cjs/utils/number/types.cjs +16 -0
- package/dist/cjs/utils/number/validate.cjs +104 -0
- package/dist/cjs/utils/owner.cjs +35 -0
- package/dist/cjs/utils/platform.cjs +83 -0
- package/dist/cjs/utils/popupStateMapping.cjs +74 -0
- package/dist/cjs/utils/popups/index.cjs +39 -0
- package/dist/cjs/utils/popups/inlineRect.cjs +218 -0
- package/dist/cjs/utils/popups/popupStoreUtils.cjs +379 -0
- package/dist/cjs/utils/popups/popupTriggerMap.cjs +76 -0
- package/dist/cjs/utils/popups/store.cjs +118 -0
- package/dist/cjs/utils/popups/useTriggerFocusGuards.cjs +72 -0
- package/dist/cjs/utils/resolveAriaLabelledBy.cjs +35 -0
- package/dist/cjs/utils/resolveClassName.cjs +30 -0
- package/dist/cjs/utils/resolveRef.cjs +33 -0
- package/dist/cjs/utils/resolveStyle.cjs +30 -0
- package/dist/cjs/utils/serializeValue.cjs +40 -0
- package/dist/cjs/utils/slider/asc.cjs +30 -0
- package/dist/cjs/utils/slider/getMidpoint.cjs +34 -0
- package/dist/cjs/utils/slider/getPushedThumbValues.cjs +73 -0
- package/dist/cjs/utils/slider/getSliderValue.cjs +42 -0
- package/dist/cjs/utils/slider/replaceArrayItemAtIndex.cjs +33 -0
- package/dist/cjs/utils/slider/resolveThumbCollision.cjs +155 -0
- package/dist/cjs/utils/slider/roundValueToStep.cjs +45 -0
- package/dist/cjs/utils/slider/validateMinimumDistance.cjs +40 -0
- package/dist/cjs/utils/slider/valueArrayToPercentages.cjs +36 -0
- package/dist/cjs/utils/store/ReactStore.cjs +135 -0
- package/dist/cjs/utils/store/Store.cjs +83 -0
- package/dist/cjs/utils/store/createSelector.cjs +74 -0
- package/dist/cjs/utils/store/useStore.cjs +51 -0
- package/dist/cjs/utils/stringifyLocale.cjs +36 -0
- package/dist/cjs/utils/useAnchorPositioning.cjs +421 -0
- package/dist/cjs/utils/useAnchoredPopupScrollLock.cjs +59 -0
- package/dist/cjs/utils/useAnimationFrame.cjs +93 -0
- package/dist/cjs/utils/useAnimationsFinished.cjs +98 -0
- package/dist/cjs/utils/useBaseUiId.cjs +36 -0
- package/dist/cjs/utils/useButton.cjs +177 -0
- package/dist/cjs/utils/useCheckboxGroupParent.cjs +114 -0
- package/dist/cjs/utils/useControlled.cjs +47 -0
- package/dist/cjs/utils/useEnhancedClickHandler.cjs +60 -0
- package/dist/cjs/utils/useFocusableWhenDisabled.cjs +77 -0
- package/dist/cjs/utils/useForcedRerendering.cjs +35 -0
- package/dist/cjs/utils/useIsHydrating.cjs +44 -0
- package/dist/cjs/utils/useMixedToggleClickHandler.cjs +66 -0
- package/dist/cjs/utils/useOnFirstRender.cjs +35 -0
- package/dist/cjs/utils/useOnMount.cjs +36 -0
- package/dist/cjs/utils/useOpenChangeComplete.cjs +57 -0
- package/dist/cjs/utils/useOpenInteractionType.cjs +69 -0
- package/dist/cjs/utils/usePopupAutoResize.cjs +191 -0
- package/dist/cjs/utils/usePopupViewport.cjs +283 -0
- package/dist/cjs/utils/usePositioner.cjs +53 -0
- package/dist/cjs/utils/usePressAndHold.cjs +51 -0
- package/dist/cjs/utils/usePreviousValue.cjs +47 -0
- package/dist/cjs/utils/useRefWithInit.cjs +41 -0
- package/dist/cjs/utils/useRegisteredLabelId.cjs +48 -0
- package/dist/cjs/utils/useRenderElement.cjs +106 -0
- package/dist/cjs/utils/useScrollLock.cjs +232 -0
- package/dist/cjs/utils/useStableCallback.cjs +41 -0
- package/dist/cjs/utils/useTimeout.cjs +66 -0
- package/dist/cjs/utils/useTransitionStatus.cjs +116 -0
- package/dist/cjs/utils/useValueAsRef.cjs +43 -0
- package/dist/cjs/utils/useValueChanged.cjs +55 -0
- package/dist/cjs/utils/valueToPercent.cjs +30 -0
- package/dist/cjs/utils/visuallyHidden.cjs +49 -0
- package/package.json +20 -8
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var number_field_exports = {};
|
|
20
|
+
__export(number_field_exports, {
|
|
21
|
+
NumberField: () => NumberField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(number_field_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
var import_useRenderElement = require("./utils/useRenderElement.cjs");
|
|
27
|
+
var import_composeRefs = require("./utils/composeRefs.cjs");
|
|
28
|
+
var import_useControlled = require("./utils/useControlled.cjs");
|
|
29
|
+
var import_useStableCallback = require("./utils/useStableCallback.cjs");
|
|
30
|
+
var import_useValueAsRef = require("./utils/useValueAsRef.cjs");
|
|
31
|
+
var import_useValueChanged = require("./utils/useValueChanged.cjs");
|
|
32
|
+
var import_useForcedRerendering = require("./utils/useForcedRerendering.cjs");
|
|
33
|
+
var import_addEventListener = require("./utils/addEventListener.cjs");
|
|
34
|
+
var import_platform = require("./utils/platform.cjs");
|
|
35
|
+
var import_owner = require("./utils/owner.cjs");
|
|
36
|
+
var import_visuallyHidden = require("./utils/visuallyHidden.cjs");
|
|
37
|
+
var import_list_utils = require("./utils/composite/list-utils.cjs");
|
|
38
|
+
var import_useButton = require("./utils/useButton.cjs");
|
|
39
|
+
var import_useLabelableId = require("./utils/field/useLabelableId.cjs");
|
|
40
|
+
var import_formatNumber = require("./utils/formatNumber.cjs");
|
|
41
|
+
var import_constants = require("./utils/field/constants.cjs");
|
|
42
|
+
var import_FieldRootContext = require("./utils/field/FieldRootContext.cjs");
|
|
43
|
+
var import_FormContext = require("./utils/field/FormContext.cjs");
|
|
44
|
+
var import_LabelableContext = require("./utils/field/LabelableContext.cjs");
|
|
45
|
+
var import_useRegisterFieldControl = require("./utils/field/useRegisterFieldControl.cjs");
|
|
46
|
+
var import_createChangeEventDetails = require("./utils/createChangeEventDetails.cjs");
|
|
47
|
+
var import_parse = require("./utils/number/parse.cjs");
|
|
48
|
+
var import_validate = require("./utils/number/validate.cjs");
|
|
49
|
+
var import_usePressAndHold = require("./utils/usePressAndHold.cjs");
|
|
50
|
+
var import_constants2 = require("./utils/number/constants.cjs");
|
|
51
|
+
const NAVIGATE_KEYS = /* @__PURE__ */ new Set([
|
|
52
|
+
"Backspace",
|
|
53
|
+
"Delete",
|
|
54
|
+
"ArrowLeft",
|
|
55
|
+
"ArrowRight",
|
|
56
|
+
"Tab",
|
|
57
|
+
"Enter",
|
|
58
|
+
"Escape"
|
|
59
|
+
]);
|
|
60
|
+
function activeElement(doc) {
|
|
61
|
+
return doc.activeElement;
|
|
62
|
+
}
|
|
63
|
+
const stateAttributesMapping = {
|
|
64
|
+
inputValue: () => null,
|
|
65
|
+
value: () => null,
|
|
66
|
+
...import_constants.fieldValidityMapping
|
|
67
|
+
};
|
|
68
|
+
const NumberFieldRootContext = (0, import_octane.createContext)(void 0);
|
|
69
|
+
function useNumberFieldRootContext() {
|
|
70
|
+
const context = (0, import_octane.useContext)(NumberFieldRootContext);
|
|
71
|
+
if (context === void 0) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Base UI: NumberFieldRootContext is missing. NumberField parts must be placed within <NumberField.Root>."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return context;
|
|
77
|
+
}
|
|
78
|
+
function NumberFieldRoot(props) {
|
|
79
|
+
const slot = (0, import_internal.S)("NumberFieldRoot");
|
|
80
|
+
const {
|
|
81
|
+
id: idProp,
|
|
82
|
+
min,
|
|
83
|
+
max,
|
|
84
|
+
smallStep = 0.1,
|
|
85
|
+
step: stepProp = 1,
|
|
86
|
+
largeStep = 10,
|
|
87
|
+
required = false,
|
|
88
|
+
disabled: disabledProp = false,
|
|
89
|
+
readOnly = false,
|
|
90
|
+
form,
|
|
91
|
+
name: nameProp,
|
|
92
|
+
defaultValue,
|
|
93
|
+
value: valueProp,
|
|
94
|
+
onValueChange: onValueChangeProp,
|
|
95
|
+
onValueCommitted: onValueCommittedProp,
|
|
96
|
+
allowWheelScrub = false,
|
|
97
|
+
snapOnStep = false,
|
|
98
|
+
allowOutOfRange = false,
|
|
99
|
+
format,
|
|
100
|
+
locale,
|
|
101
|
+
render,
|
|
102
|
+
className,
|
|
103
|
+
inputRef: inputRefProp,
|
|
104
|
+
style,
|
|
105
|
+
ref,
|
|
106
|
+
...elementProps
|
|
107
|
+
} = props;
|
|
108
|
+
const {
|
|
109
|
+
setDirty,
|
|
110
|
+
validityData,
|
|
111
|
+
disabled: fieldDisabled,
|
|
112
|
+
setFilled,
|
|
113
|
+
invalid,
|
|
114
|
+
name: fieldName,
|
|
115
|
+
state: fieldState,
|
|
116
|
+
validation
|
|
117
|
+
} = (0, import_FieldRootContext.useFieldRootContext)();
|
|
118
|
+
const { clearErrors } = (0, import_FormContext.useFormContext)();
|
|
119
|
+
const disabled = fieldDisabled || disabledProp;
|
|
120
|
+
const name = fieldName ?? nameProp;
|
|
121
|
+
const step = stepProp === "any" ? 1 : stepProp;
|
|
122
|
+
const [isScrubbing, setIsScrubbing] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "scrubbing"));
|
|
123
|
+
const minWithDefault = min ?? Number.MIN_SAFE_INTEGER;
|
|
124
|
+
const maxWithDefault = max ?? Number.MAX_SAFE_INTEGER;
|
|
125
|
+
const minWithZeroDefault = min ?? 0;
|
|
126
|
+
const formatStyle = format?.style;
|
|
127
|
+
const inputRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "inputRef"));
|
|
128
|
+
const hiddenInputRef = (0, import_composeRefs.useComposedRefs)(
|
|
129
|
+
inputRefProp,
|
|
130
|
+
validation.inputRef,
|
|
131
|
+
(0, import_internal.subSlot)(slot, "hiddenRef")
|
|
132
|
+
);
|
|
133
|
+
const id = (0, import_useLabelableId.useLabelableId)({ id: idProp }, (0, import_internal.subSlot)(slot, "id"));
|
|
134
|
+
const [valueUnwrapped, setValueUnwrapped] = (0, import_useControlled.useControlled)(
|
|
135
|
+
{ controlled: valueProp, default: defaultValue, name: "NumberField", state: "value" },
|
|
136
|
+
(0, import_internal.subSlot)(slot, "value")
|
|
137
|
+
);
|
|
138
|
+
const value = valueUnwrapped ?? null;
|
|
139
|
+
const valueRef = (0, import_useValueAsRef.useValueAsRef)(value, (0, import_internal.subSlot)(slot, "valueRef"));
|
|
140
|
+
(0, import_octane.useLayoutEffect)(() => setFilled(value !== null), [setFilled, value], (0, import_internal.subSlot)(slot, "e:filled"));
|
|
141
|
+
const forceRender = (0, import_useForcedRerendering.useForcedRerendering)((0, import_internal.subSlot)(slot, "force"));
|
|
142
|
+
const formatOptionsRef = (0, import_useValueAsRef.useValueAsRef)(
|
|
143
|
+
format,
|
|
144
|
+
(0, import_internal.subSlot)(slot, "fmtRef")
|
|
145
|
+
);
|
|
146
|
+
const hasPendingCommitRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "pending"));
|
|
147
|
+
const onValueCommitted = (0, import_useStableCallback.useStableCallback)(
|
|
148
|
+
(nextValue, eventDetails) => {
|
|
149
|
+
hasPendingCommitRef.current = false;
|
|
150
|
+
onValueCommittedProp?.(nextValue, eventDetails);
|
|
151
|
+
},
|
|
152
|
+
(0, import_internal.subSlot)(slot, "commit")
|
|
153
|
+
);
|
|
154
|
+
const allowInputSyncRef = (0, import_octane.useRef)(true, (0, import_internal.subSlot)(slot, "allowSync"));
|
|
155
|
+
const lastChangedValueRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "lastChanged"));
|
|
156
|
+
const [inputValue, setInputValue] = (0, import_octane.useState)(
|
|
157
|
+
() => (0, import_formatNumber.formatNumber)(value, locale, format),
|
|
158
|
+
(0, import_internal.subSlot)(slot, "inputValue")
|
|
159
|
+
);
|
|
160
|
+
const [inputMode, setInputMode] = (0, import_octane.useState)("numeric", (0, import_internal.subSlot)(slot, "inputMode"));
|
|
161
|
+
const getAllowedNonNumericKeys = (0, import_useStableCallback.useStableCallback)(
|
|
162
|
+
() => {
|
|
163
|
+
const { decimal, group, currency, literal } = (0, import_parse.getNumberLocaleDetails)(locale, format);
|
|
164
|
+
const keys = /* @__PURE__ */ new Set();
|
|
165
|
+
import_parse.BASE_NON_NUMERIC_SYMBOLS.forEach((symbol) => keys.add(symbol));
|
|
166
|
+
if (decimal) keys.add(decimal);
|
|
167
|
+
if (group) {
|
|
168
|
+
keys.add(group);
|
|
169
|
+
if (import_parse.SPACE_SEPARATOR_RE.test(group)) keys.add(" ");
|
|
170
|
+
}
|
|
171
|
+
const allowPercentSymbols = formatStyle === "percent" || formatStyle === "unit" && format?.unit === "percent";
|
|
172
|
+
const allowPermilleSymbols = formatStyle === "percent" || formatStyle === "unit" && format?.unit === "permille";
|
|
173
|
+
if (allowPercentSymbols) import_parse.PERCENTAGES.forEach((key) => keys.add(key));
|
|
174
|
+
if (allowPermilleSymbols) import_parse.PERMILLE.forEach((key) => keys.add(key));
|
|
175
|
+
if (formatStyle === "currency" && currency) keys.add(currency);
|
|
176
|
+
if (literal) {
|
|
177
|
+
Array.from(literal).forEach((char) => keys.add(char));
|
|
178
|
+
if (import_parse.SPACE_SEPARATOR_RE.test(literal)) keys.add(" ");
|
|
179
|
+
}
|
|
180
|
+
import_parse.PLUS_SIGNS_WITH_ASCII.forEach((key) => keys.add(key));
|
|
181
|
+
if (minWithDefault < 0 || allowOutOfRange) {
|
|
182
|
+
import_parse.MINUS_SIGNS_WITH_ASCII.forEach((key) => keys.add(key));
|
|
183
|
+
}
|
|
184
|
+
return keys;
|
|
185
|
+
},
|
|
186
|
+
(0, import_internal.subSlot)(slot, "allowedKeys")
|
|
187
|
+
);
|
|
188
|
+
const getStepAmount = (0, import_useStableCallback.useStableCallback)(
|
|
189
|
+
(event) => {
|
|
190
|
+
if (event?.altKey) return smallStep;
|
|
191
|
+
if (event?.shiftKey) return largeStep;
|
|
192
|
+
return step;
|
|
193
|
+
},
|
|
194
|
+
(0, import_internal.subSlot)(slot, "stepAmount")
|
|
195
|
+
);
|
|
196
|
+
const setValue = (0, import_useStableCallback.useStableCallback)(
|
|
197
|
+
(unvalidatedValue, details) => {
|
|
198
|
+
const eventWithOptionalKeyState = details.event;
|
|
199
|
+
const dir = details.direction;
|
|
200
|
+
const isInputReason = details.reason === import_createChangeEventDetails.REASONS.inputChange || details.reason === "input-clear" || details.reason === "input-blur" || details.reason === "input-paste" || details.reason === import_createChangeEventDetails.REASONS.none;
|
|
201
|
+
const shouldClampValue = !allowOutOfRange || !isInputReason;
|
|
202
|
+
const validatedValue = (0, import_validate.toValidatedNumber)(unvalidatedValue, {
|
|
203
|
+
step: dir ? getStepAmount(eventWithOptionalKeyState) * dir : void 0,
|
|
204
|
+
format: formatOptionsRef.current,
|
|
205
|
+
minWithDefault,
|
|
206
|
+
maxWithDefault,
|
|
207
|
+
minWithZeroDefault,
|
|
208
|
+
snapOnStep,
|
|
209
|
+
small: eventWithOptionalKeyState?.altKey ?? false,
|
|
210
|
+
clamp: shouldClampValue
|
|
211
|
+
});
|
|
212
|
+
const shouldFireChange = validatedValue !== value || isInputReason && (unvalidatedValue !== value || allowInputSyncRef.current === false);
|
|
213
|
+
if (shouldFireChange) {
|
|
214
|
+
onValueChangeProp?.(validatedValue, details);
|
|
215
|
+
if (details.isCanceled) return false;
|
|
216
|
+
setValueUnwrapped(validatedValue);
|
|
217
|
+
setDirty(validatedValue !== validityData.initialValue);
|
|
218
|
+
hasPendingCommitRef.current = true;
|
|
219
|
+
}
|
|
220
|
+
lastChangedValueRef.current = validatedValue;
|
|
221
|
+
if (allowInputSyncRef.current) {
|
|
222
|
+
setInputValue((0, import_formatNumber.formatNumber)(validatedValue, locale, format));
|
|
223
|
+
}
|
|
224
|
+
forceRender();
|
|
225
|
+
return shouldFireChange;
|
|
226
|
+
},
|
|
227
|
+
(0, import_internal.subSlot)(slot, "setValue")
|
|
228
|
+
);
|
|
229
|
+
const incrementValue = (0, import_useStableCallback.useStableCallback)(
|
|
230
|
+
(amount, params) => {
|
|
231
|
+
const { direction, currentValue, event, reason } = params;
|
|
232
|
+
const prevValue = currentValue == null ? valueRef.current : currentValue;
|
|
233
|
+
if (typeof prevValue !== "number") {
|
|
234
|
+
return setValue(0, (0, import_createChangeEventDetails.createChangeEventDetails)(reason, event));
|
|
235
|
+
}
|
|
236
|
+
return setValue(
|
|
237
|
+
prevValue + amount * direction,
|
|
238
|
+
(0, import_createChangeEventDetails.createChangeEventDetails)(reason, event, void 0, { direction })
|
|
239
|
+
);
|
|
240
|
+
},
|
|
241
|
+
(0, import_internal.subSlot)(slot, "increment")
|
|
242
|
+
);
|
|
243
|
+
(0, import_octane.useLayoutEffect)(
|
|
244
|
+
() => {
|
|
245
|
+
if (!allowInputSyncRef.current) return;
|
|
246
|
+
const nextInputValue = (0, import_formatNumber.formatNumber)(value, locale, format);
|
|
247
|
+
if (nextInputValue !== inputValue) setInputValue(nextInputValue);
|
|
248
|
+
},
|
|
249
|
+
void 0,
|
|
250
|
+
(0, import_internal.subSlot)(slot, "e:syncInput")
|
|
251
|
+
);
|
|
252
|
+
(0, import_octane.useLayoutEffect)(
|
|
253
|
+
() => {
|
|
254
|
+
if (!import_platform.platform.os.ios) return;
|
|
255
|
+
let computedInputMode = "text";
|
|
256
|
+
if (minWithDefault >= 0) computedInputMode = "decimal";
|
|
257
|
+
setInputMode(computedInputMode);
|
|
258
|
+
},
|
|
259
|
+
[minWithDefault],
|
|
260
|
+
(0, import_internal.subSlot)(slot, "e:inputMode")
|
|
261
|
+
);
|
|
262
|
+
(0, import_octane.useEffect)(
|
|
263
|
+
() => {
|
|
264
|
+
const element2 = inputRef.current;
|
|
265
|
+
if (disabled || readOnly || !allowWheelScrub || !element2) return void 0;
|
|
266
|
+
function handleWheel(event) {
|
|
267
|
+
if (event.ctrlKey || activeElement((0, import_owner.ownerDocument)(inputRef.current)) !== inputRef.current) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
allowInputSyncRef.current = true;
|
|
272
|
+
const amount = getStepAmount(event);
|
|
273
|
+
const changed = incrementValue(amount, {
|
|
274
|
+
direction: event.deltaY > 0 ? -1 : 1,
|
|
275
|
+
event,
|
|
276
|
+
reason: "wheel"
|
|
277
|
+
});
|
|
278
|
+
if (changed) {
|
|
279
|
+
onValueCommitted(
|
|
280
|
+
lastChangedValueRef.current ?? valueRef.current,
|
|
281
|
+
(0, import_createChangeEventDetails.createChangeEventDetails)("wheel", event)
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return (0, import_addEventListener.addEventListener)(element2, "wheel", handleWheel);
|
|
286
|
+
},
|
|
287
|
+
[allowWheelScrub, incrementValue, disabled, readOnly, getStepAmount, onValueCommitted],
|
|
288
|
+
(0, import_internal.subSlot)(slot, "e:wheel")
|
|
289
|
+
);
|
|
290
|
+
const state = (0, import_octane.useMemo)(
|
|
291
|
+
() => ({
|
|
292
|
+
...fieldState,
|
|
293
|
+
disabled,
|
|
294
|
+
readOnly,
|
|
295
|
+
required,
|
|
296
|
+
value,
|
|
297
|
+
inputValue,
|
|
298
|
+
scrubbing: isScrubbing
|
|
299
|
+
}),
|
|
300
|
+
[fieldState, disabled, readOnly, required, value, inputValue, isScrubbing],
|
|
301
|
+
(0, import_internal.subSlot)(slot, "state")
|
|
302
|
+
);
|
|
303
|
+
const contextValue = (0, import_octane.useMemo)(
|
|
304
|
+
() => ({
|
|
305
|
+
inputRef,
|
|
306
|
+
inputValue,
|
|
307
|
+
value,
|
|
308
|
+
minWithDefault,
|
|
309
|
+
maxWithDefault,
|
|
310
|
+
disabled,
|
|
311
|
+
readOnly,
|
|
312
|
+
id,
|
|
313
|
+
setValue,
|
|
314
|
+
incrementValue,
|
|
315
|
+
getStepAmount,
|
|
316
|
+
allowInputSyncRef,
|
|
317
|
+
formatOptionsRef,
|
|
318
|
+
valueRef,
|
|
319
|
+
lastChangedValueRef,
|
|
320
|
+
hasPendingCommitRef,
|
|
321
|
+
name,
|
|
322
|
+
nameProp,
|
|
323
|
+
required,
|
|
324
|
+
invalid,
|
|
325
|
+
inputMode,
|
|
326
|
+
getAllowedNonNumericKeys,
|
|
327
|
+
min,
|
|
328
|
+
max,
|
|
329
|
+
setInputValue,
|
|
330
|
+
locale,
|
|
331
|
+
isScrubbing,
|
|
332
|
+
setIsScrubbing,
|
|
333
|
+
state,
|
|
334
|
+
onValueCommitted
|
|
335
|
+
}),
|
|
336
|
+
[
|
|
337
|
+
inputValue,
|
|
338
|
+
value,
|
|
339
|
+
minWithDefault,
|
|
340
|
+
maxWithDefault,
|
|
341
|
+
disabled,
|
|
342
|
+
readOnly,
|
|
343
|
+
id,
|
|
344
|
+
setValue,
|
|
345
|
+
incrementValue,
|
|
346
|
+
getStepAmount,
|
|
347
|
+
name,
|
|
348
|
+
nameProp,
|
|
349
|
+
required,
|
|
350
|
+
invalid,
|
|
351
|
+
inputMode,
|
|
352
|
+
getAllowedNonNumericKeys,
|
|
353
|
+
min,
|
|
354
|
+
max,
|
|
355
|
+
locale,
|
|
356
|
+
isScrubbing,
|
|
357
|
+
state,
|
|
358
|
+
onValueCommitted
|
|
359
|
+
],
|
|
360
|
+
(0, import_internal.subSlot)(slot, "ctx")
|
|
361
|
+
);
|
|
362
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
363
|
+
"div",
|
|
364
|
+
{ render, className, style },
|
|
365
|
+
{ ref, state, props: elementProps, stateAttributesMapping },
|
|
366
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
367
|
+
);
|
|
368
|
+
const hiddenInputProps = validation.getValidationProps(disabled, {
|
|
369
|
+
onFocus() {
|
|
370
|
+
inputRef.current?.focus();
|
|
371
|
+
},
|
|
372
|
+
onChange(event) {
|
|
373
|
+
if (event.defaultPrevented || disabled || readOnly) return;
|
|
374
|
+
const nextValue = event.currentTarget.valueAsNumber;
|
|
375
|
+
const parsedValue = Number.isNaN(nextValue) ? null : nextValue;
|
|
376
|
+
const details = (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.none, event);
|
|
377
|
+
setValue(parsedValue, details);
|
|
378
|
+
clearErrors(name);
|
|
379
|
+
validation.change(lastChangedValueRef.current ?? parsedValue);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
const hiddenInput = (0, import_octane.createElement)("input", {
|
|
383
|
+
...hiddenInputProps,
|
|
384
|
+
// This form-facing control intentionally observes the native commit event;
|
|
385
|
+
// the visible text input above owns per-edit handling.
|
|
386
|
+
suppressNativeChangeWarning: true,
|
|
387
|
+
ref: hiddenInputRef,
|
|
388
|
+
type: "number",
|
|
389
|
+
form,
|
|
390
|
+
name,
|
|
391
|
+
value: value ?? "",
|
|
392
|
+
min,
|
|
393
|
+
max,
|
|
394
|
+
step: stepProp,
|
|
395
|
+
disabled,
|
|
396
|
+
readOnly,
|
|
397
|
+
required,
|
|
398
|
+
"aria-hidden": true,
|
|
399
|
+
tabIndex: -1,
|
|
400
|
+
style: name ? import_visuallyHidden.visuallyHiddenInput : import_visuallyHidden.visuallyHidden
|
|
401
|
+
});
|
|
402
|
+
return (0, import_octane.createElement)(NumberFieldRootContext.Provider, {
|
|
403
|
+
value: contextValue,
|
|
404
|
+
// Octane reconciles an ARRAY child as a keyed list, so each slot carries a stable key;
|
|
405
|
+
// values that cannot be keyed in place go through a keyed Fragment.
|
|
406
|
+
children: [
|
|
407
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "element", children: element }),
|
|
408
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "hidden-input", children: hiddenInput })
|
|
409
|
+
]
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
function NumberFieldGroup(props) {
|
|
413
|
+
const slot = (0, import_internal.S)("NumberFieldGroup");
|
|
414
|
+
const { render, className, style, ref, ...elementProps } = props;
|
|
415
|
+
const { state } = useNumberFieldRootContext();
|
|
416
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
417
|
+
"div",
|
|
418
|
+
{ render, className, style },
|
|
419
|
+
{ ref, state, props: [{ role: "group" }, elementProps], stateAttributesMapping },
|
|
420
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
function NumberFieldInput(props) {
|
|
424
|
+
const slot = (0, import_internal.S)("NumberFieldInput");
|
|
425
|
+
const { render, className, style, ref, ...elementProps } = props;
|
|
426
|
+
const {
|
|
427
|
+
allowInputSyncRef,
|
|
428
|
+
disabled,
|
|
429
|
+
formatOptionsRef,
|
|
430
|
+
getAllowedNonNumericKeys,
|
|
431
|
+
getStepAmount,
|
|
432
|
+
id,
|
|
433
|
+
incrementValue,
|
|
434
|
+
inputMode,
|
|
435
|
+
inputValue,
|
|
436
|
+
max,
|
|
437
|
+
min,
|
|
438
|
+
name,
|
|
439
|
+
nameProp,
|
|
440
|
+
readOnly,
|
|
441
|
+
required,
|
|
442
|
+
setValue,
|
|
443
|
+
state,
|
|
444
|
+
setInputValue,
|
|
445
|
+
locale,
|
|
446
|
+
inputRef,
|
|
447
|
+
value,
|
|
448
|
+
onValueCommitted,
|
|
449
|
+
lastChangedValueRef,
|
|
450
|
+
hasPendingCommitRef,
|
|
451
|
+
valueRef
|
|
452
|
+
} = useNumberFieldRootContext();
|
|
453
|
+
const { clearErrors } = (0, import_FormContext.useFormContext)();
|
|
454
|
+
const { validationMode, setTouched, setFocused, invalid, shouldValidateOnChange, validation } = (0, import_FieldRootContext.useFieldRootContext)();
|
|
455
|
+
const { labelId } = (0, import_LabelableContext.useLabelableContext)();
|
|
456
|
+
const hasTouchedInputRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "touched"));
|
|
457
|
+
const blockRevalidationRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "blockReval"));
|
|
458
|
+
const pendingCaretRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "caret"));
|
|
459
|
+
(0, import_useRegisterFieldControl.useRegisterFieldControl)(
|
|
460
|
+
inputRef,
|
|
461
|
+
id,
|
|
462
|
+
value,
|
|
463
|
+
void 0,
|
|
464
|
+
!disabled,
|
|
465
|
+
nameProp,
|
|
466
|
+
(0, import_internal.subSlot)(slot, "register")
|
|
467
|
+
);
|
|
468
|
+
(0, import_octane.useLayoutEffect)(
|
|
469
|
+
() => {
|
|
470
|
+
if (pendingCaretRef.current != null) {
|
|
471
|
+
const caret = pendingCaretRef.current;
|
|
472
|
+
pendingCaretRef.current = null;
|
|
473
|
+
inputRef.current?.setSelectionRange(caret, caret);
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
void 0,
|
|
477
|
+
(0, import_internal.subSlot)(slot, "e:caret")
|
|
478
|
+
);
|
|
479
|
+
(0, import_useValueChanged.useValueChanged)(
|
|
480
|
+
value,
|
|
481
|
+
() => {
|
|
482
|
+
clearErrors(name);
|
|
483
|
+
if (blockRevalidationRef.current && !shouldValidateOnChange()) {
|
|
484
|
+
blockRevalidationRef.current = false;
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
validation.change(value);
|
|
488
|
+
},
|
|
489
|
+
(0, import_internal.subSlot)(slot, "valueChanged")
|
|
490
|
+
);
|
|
491
|
+
const inputProps = {
|
|
492
|
+
id,
|
|
493
|
+
required,
|
|
494
|
+
disabled,
|
|
495
|
+
readOnly,
|
|
496
|
+
inputMode,
|
|
497
|
+
value: inputValue,
|
|
498
|
+
type: "text",
|
|
499
|
+
autoComplete: "off",
|
|
500
|
+
autoCorrect: "off",
|
|
501
|
+
spellCheck: "false",
|
|
502
|
+
"aria-roledescription": "Number field",
|
|
503
|
+
"aria-invalid": !disabled && invalid ? true : void 0,
|
|
504
|
+
"aria-labelledby": labelId,
|
|
505
|
+
onFocus(event) {
|
|
506
|
+
if (event.defaultPrevented || disabled) return;
|
|
507
|
+
setFocused(true);
|
|
508
|
+
if (hasTouchedInputRef.current) return;
|
|
509
|
+
hasTouchedInputRef.current = true;
|
|
510
|
+
const target = event.currentTarget;
|
|
511
|
+
const length = target.value.length;
|
|
512
|
+
target.setSelectionRange(length, length);
|
|
513
|
+
},
|
|
514
|
+
onBlur(event) {
|
|
515
|
+
if (event.defaultPrevented || disabled) return;
|
|
516
|
+
setTouched(true);
|
|
517
|
+
setFocused(false);
|
|
518
|
+
if (readOnly) return;
|
|
519
|
+
const hadManualInput = !allowInputSyncRef.current;
|
|
520
|
+
const hadPendingProgrammaticChange = hasPendingCommitRef.current;
|
|
521
|
+
allowInputSyncRef.current = true;
|
|
522
|
+
if (inputValue.trim() === "") {
|
|
523
|
+
const clearDetails = (0, import_createChangeEventDetails.createChangeEventDetails)("input-clear", event);
|
|
524
|
+
setValue(null, clearDetails);
|
|
525
|
+
if (clearDetails.isCanceled) return;
|
|
526
|
+
if (validationMode === "onBlur") validation.commit(null);
|
|
527
|
+
if (hadManualInput || hadPendingProgrammaticChange || value !== null) {
|
|
528
|
+
onValueCommitted(null, (0, import_createChangeEventDetails.createChangeEventDetails)("input-clear", event));
|
|
529
|
+
}
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const formatOptions = formatOptionsRef.current;
|
|
533
|
+
const parsedValue = (0, import_parse.parseNumber)(inputValue, locale, formatOptions);
|
|
534
|
+
if (parsedValue === null) return;
|
|
535
|
+
const hasRoundingOptions = (0, import_validate.hasNumberFormatRoundingOptions)(formatOptions);
|
|
536
|
+
let committed;
|
|
537
|
+
if (!hadManualInput && !hasRoundingOptions) {
|
|
538
|
+
committed = value;
|
|
539
|
+
} else if (hasRoundingOptions) {
|
|
540
|
+
committed = (0, import_validate.removeFloatingPointErrors)(parsedValue, formatOptions);
|
|
541
|
+
} else {
|
|
542
|
+
committed = parsedValue;
|
|
543
|
+
}
|
|
544
|
+
const shouldUpdateValue = value !== committed;
|
|
545
|
+
const shouldCommit = hadManualInput || shouldUpdateValue || hadPendingProgrammaticChange;
|
|
546
|
+
let committedValue = committed;
|
|
547
|
+
if (shouldUpdateValue) {
|
|
548
|
+
const changeDetails = (0, import_createChangeEventDetails.createChangeEventDetails)("input-blur", event);
|
|
549
|
+
blockRevalidationRef.current = true;
|
|
550
|
+
setValue(committed, changeDetails);
|
|
551
|
+
if (changeDetails.isCanceled) {
|
|
552
|
+
blockRevalidationRef.current = false;
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
committedValue = lastChangedValueRef.current ?? committed;
|
|
556
|
+
if (committedValue === value) blockRevalidationRef.current = false;
|
|
557
|
+
}
|
|
558
|
+
if (validationMode === "onBlur") validation.commit(committedValue);
|
|
559
|
+
if (shouldCommit)
|
|
560
|
+
onValueCommitted(committedValue, (0, import_createChangeEventDetails.createChangeEventDetails)("input-blur", event));
|
|
561
|
+
const canonicalText = (0, import_formatNumber.formatNumber)(committedValue, locale, formatOptions);
|
|
562
|
+
if (inputValue !== canonicalText) setInputValue(canonicalText);
|
|
563
|
+
},
|
|
564
|
+
onInput(event) {
|
|
565
|
+
if (event.defaultPrevented) return;
|
|
566
|
+
allowInputSyncRef.current = false;
|
|
567
|
+
const targetValue = event.currentTarget.value;
|
|
568
|
+
if (targetValue.trim() === "") {
|
|
569
|
+
setInputValue(targetValue);
|
|
570
|
+
setValue(null, (0, import_createChangeEventDetails.createChangeEventDetails)("input-clear", event));
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const allowedNonNumericKeys = getAllowedNonNumericKeys();
|
|
574
|
+
const isValidCharacterString = Array.from(targetValue).every(
|
|
575
|
+
(ch) => (0, import_parse.isNumeralChar)(ch) || import_parse.ANY_MINUS_DETECT_RE.test(ch) || allowedNonNumericKeys.has(ch)
|
|
576
|
+
);
|
|
577
|
+
if (!isValidCharacterString) return;
|
|
578
|
+
const parsedValue = (0, import_parse.parseNumber)(targetValue, locale, formatOptionsRef.current);
|
|
579
|
+
setInputValue(targetValue);
|
|
580
|
+
if (parsedValue !== null) {
|
|
581
|
+
setValue(parsedValue, (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.inputChange, event));
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
onKeyDown(event) {
|
|
585
|
+
if (event.defaultPrevented || readOnly || disabled) return;
|
|
586
|
+
const nativeEvent = event;
|
|
587
|
+
const hadManualInput = !allowInputSyncRef.current;
|
|
588
|
+
const allowedNonNumericKeys = getAllowedNonNumericKeys();
|
|
589
|
+
let isAllowedNonNumericKey = allowedNonNumericKeys.has(event.key);
|
|
590
|
+
const { decimal, currency, percentSign } = (0, import_parse.getNumberLocaleDetails)(
|
|
591
|
+
locale,
|
|
592
|
+
formatOptionsRef.current
|
|
593
|
+
);
|
|
594
|
+
const selectionStart = event.currentTarget.selectionStart;
|
|
595
|
+
const selectionEnd = event.currentTarget.selectionEnd;
|
|
596
|
+
const isAllSelected = selectionStart === 0 && selectionEnd === inputValue.length;
|
|
597
|
+
const selectionContainsIndex = (index) => selectionStart != null && selectionEnd != null && index >= selectionStart && index < selectionEnd;
|
|
598
|
+
const signGroups = [
|
|
599
|
+
[import_parse.ANY_MINUS_DETECT_RE, import_parse.ANY_MINUS_RE],
|
|
600
|
+
[import_parse.ANY_PLUS_DETECT_RE, import_parse.ANY_PLUS_RE]
|
|
601
|
+
];
|
|
602
|
+
signGroups.forEach(([detectRe, globalRe]) => {
|
|
603
|
+
if (detectRe.test(event.key) && Array.from(allowedNonNumericKeys).some((k) => detectRe.test(k))) {
|
|
604
|
+
const existingIndex = inputValue.search(globalRe);
|
|
605
|
+
const isReplacingExisting = existingIndex !== -1 && selectionContainsIndex(existingIndex);
|
|
606
|
+
isAllowedNonNumericKey = !(import_parse.ANY_MINUS_DETECT_RE.test(inputValue) || import_parse.ANY_PLUS_DETECT_RE.test(inputValue)) || isAllSelected || isReplacingExisting;
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
[decimal, currency, percentSign].forEach((symbol) => {
|
|
610
|
+
if (symbol && event.key === symbol) {
|
|
611
|
+
const symbolIndex = inputValue.indexOf(symbol);
|
|
612
|
+
const isSymbolHighlighted = selectionContainsIndex(symbolIndex);
|
|
613
|
+
isAllowedNonNumericKey = !inputValue.includes(symbol) || isAllSelected || isSymbolHighlighted;
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
const isNavigateKey = NAVIGATE_KEYS.has(event.key);
|
|
617
|
+
const isStepKey = event.key === "ArrowUp" || event.key === "ArrowDown";
|
|
618
|
+
if (event.which === 229 || event.altKey && !isStepKey || event.ctrlKey || event.metaKey || isAllowedNonNumericKey || (0, import_parse.isNumeralChar)(event.key) || isNavigateKey) {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const willSetHome = event.key === "Home" && min != null;
|
|
622
|
+
const willSetEnd = event.key === "End" && max != null;
|
|
623
|
+
if (event.key.length > 1 && !isStepKey && !willSetHome && !willSetEnd) return;
|
|
624
|
+
const currentValue = hadManualInput ? (0, import_parse.parseNumber)(inputValue, locale, formatOptionsRef.current) : null;
|
|
625
|
+
const amount = getStepAmount(event);
|
|
626
|
+
(0, import_list_utils.stopEvent)(event);
|
|
627
|
+
const commitDetails = (0, import_createChangeEventDetails.createChangeEventDetails)("keyboard", nativeEvent);
|
|
628
|
+
let changed = false;
|
|
629
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
630
|
+
allowInputSyncRef.current = true;
|
|
631
|
+
if (!hadManualInput) lastChangedValueRef.current = valueRef.current;
|
|
632
|
+
changed = incrementValue(amount, {
|
|
633
|
+
direction: event.key === "ArrowUp" ? 1 : -1,
|
|
634
|
+
currentValue,
|
|
635
|
+
event: nativeEvent,
|
|
636
|
+
reason: "keyboard"
|
|
637
|
+
});
|
|
638
|
+
} else if (willSetHome) {
|
|
639
|
+
allowInputSyncRef.current = true;
|
|
640
|
+
changed = setValue(min, (0, import_createChangeEventDetails.createChangeEventDetails)("keyboard", nativeEvent));
|
|
641
|
+
} else if (willSetEnd) {
|
|
642
|
+
allowInputSyncRef.current = true;
|
|
643
|
+
changed = setValue(max, (0, import_createChangeEventDetails.createChangeEventDetails)("keyboard", nativeEvent));
|
|
644
|
+
}
|
|
645
|
+
if (changed) onValueCommitted(lastChangedValueRef.current ?? valueRef.current, commitDetails);
|
|
646
|
+
},
|
|
647
|
+
onPaste(event) {
|
|
648
|
+
if (event.defaultPrevented || readOnly || disabled) return;
|
|
649
|
+
let pastedData = "";
|
|
650
|
+
try {
|
|
651
|
+
pastedData = event.clipboardData?.getData("text/plain") ?? "";
|
|
652
|
+
} catch {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
event.preventDefault();
|
|
656
|
+
const input = event.currentTarget;
|
|
657
|
+
const selectionStart = input.selectionStart ?? inputValue.length;
|
|
658
|
+
const selectionEnd = input.selectionEnd ?? inputValue.length;
|
|
659
|
+
const nextText = inputValue.slice(0, selectionStart) + pastedData + inputValue.slice(selectionEnd);
|
|
660
|
+
const parsedValue = (0, import_parse.parseNumber)(nextText, locale, formatOptionsRef.current);
|
|
661
|
+
if (parsedValue !== null) {
|
|
662
|
+
allowInputSyncRef.current = false;
|
|
663
|
+
pendingCaretRef.current = selectionStart + pastedData.length;
|
|
664
|
+
setValue(parsedValue, (0, import_createChangeEventDetails.createChangeEventDetails)("input-paste", event));
|
|
665
|
+
setInputValue(nextText);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
670
|
+
"input",
|
|
671
|
+
{ render, className, style },
|
|
672
|
+
{
|
|
673
|
+
ref: [ref, inputRef],
|
|
674
|
+
state,
|
|
675
|
+
props: [inputProps, elementProps, (p) => validation.getValidationProps(disabled, p)],
|
|
676
|
+
stateAttributesMapping
|
|
677
|
+
},
|
|
678
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
function useNumberFieldButton(params) {
|
|
682
|
+
const {
|
|
683
|
+
allowInputSyncRef,
|
|
684
|
+
disabled,
|
|
685
|
+
formatOptionsRef,
|
|
686
|
+
getStepAmount,
|
|
687
|
+
id,
|
|
688
|
+
incrementValue,
|
|
689
|
+
inputRef,
|
|
690
|
+
inputValue,
|
|
691
|
+
isIncrement,
|
|
692
|
+
locale,
|
|
693
|
+
readOnly,
|
|
694
|
+
setValue,
|
|
695
|
+
valueRef,
|
|
696
|
+
lastChangedValueRef,
|
|
697
|
+
onValueCommitted,
|
|
698
|
+
slot
|
|
699
|
+
} = params;
|
|
700
|
+
const pressReason = isIncrement ? import_createChangeEventDetails.REASONS.incrementPress : import_createChangeEventDetails.REASONS.decrementPress;
|
|
701
|
+
function commitValue(nativeEvent) {
|
|
702
|
+
const shouldCommitInputValue = !allowInputSyncRef.current;
|
|
703
|
+
allowInputSyncRef.current = true;
|
|
704
|
+
if (!shouldCommitInputValue) {
|
|
705
|
+
lastChangedValueRef.current = valueRef.current;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
const parsedValue = (0, import_parse.parseNumber)(inputValue, locale, formatOptionsRef.current);
|
|
709
|
+
if (parsedValue !== null) {
|
|
710
|
+
const details = (0, import_createChangeEventDetails.createChangeEventDetails)(pressReason, nativeEvent);
|
|
711
|
+
setValue(parsedValue, details);
|
|
712
|
+
if (!details.isCanceled) valueRef.current = parsedValue;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
const { pointerHandlers, shouldSkipClick } = (0, import_usePressAndHold.usePressAndHold)({
|
|
716
|
+
disabled: disabled || readOnly,
|
|
717
|
+
elementRef: inputRef,
|
|
718
|
+
tickDelay: import_constants2.CHANGE_VALUE_TICK_DELAY,
|
|
719
|
+
startDelay: import_constants2.START_AUTO_CHANGE_DELAY,
|
|
720
|
+
scrollDistance: import_constants2.SCROLLING_POINTER_MOVE_DISTANCE,
|
|
721
|
+
tick(triggerEvent) {
|
|
722
|
+
const amount = getStepAmount(triggerEvent);
|
|
723
|
+
return incrementValue(amount, {
|
|
724
|
+
direction: isIncrement ? 1 : -1,
|
|
725
|
+
event: triggerEvent,
|
|
726
|
+
reason: pressReason
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
onStop(nativeEvent) {
|
|
730
|
+
const committed = lastChangedValueRef.current ?? valueRef.current;
|
|
731
|
+
onValueCommitted(committed, (0, import_createChangeEventDetails.createChangeEventDetails)(pressReason, nativeEvent));
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
return {
|
|
735
|
+
disabled,
|
|
736
|
+
"aria-label": isIncrement ? "Increase" : "Decrease",
|
|
737
|
+
"aria-controls": id,
|
|
738
|
+
tabIndex: -1,
|
|
739
|
+
style: { WebkitUserSelect: "none", userSelect: "none" },
|
|
740
|
+
...pointerHandlers,
|
|
741
|
+
onClick(event) {
|
|
742
|
+
const isDisabled = disabled || readOnly;
|
|
743
|
+
if (event.defaultPrevented || isDisabled || shouldSkipClick(event)) return;
|
|
744
|
+
commitValue(event);
|
|
745
|
+
const amount = getStepAmount(event);
|
|
746
|
+
const prev = valueRef.current;
|
|
747
|
+
incrementValue(amount, { direction: isIncrement ? 1 : -1, event, reason: pressReason });
|
|
748
|
+
const committed = lastChangedValueRef.current ?? valueRef.current;
|
|
749
|
+
if (committed !== prev) {
|
|
750
|
+
onValueCommitted(committed, (0, import_createChangeEventDetails.createChangeEventDetails)(pressReason, event));
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
onPointerDown(event) {
|
|
754
|
+
const isMainButton = !event.button || event.button === 0;
|
|
755
|
+
if (event.defaultPrevented || readOnly || !isMainButton || disabled) return;
|
|
756
|
+
commitValue(event);
|
|
757
|
+
lastChangedValueRef.current = null;
|
|
758
|
+
if (!(0, import_usePressAndHold.isTouchLikePointerType)(event.pointerType)) inputRef.current?.focus();
|
|
759
|
+
pointerHandlers.onPointerDown(event);
|
|
760
|
+
},
|
|
761
|
+
_slot: slot
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function useNumberFieldStepperButton(componentProps, isIncrement, slot) {
|
|
765
|
+
const {
|
|
766
|
+
render,
|
|
767
|
+
className,
|
|
768
|
+
disabled: disabledProp = false,
|
|
769
|
+
nativeButton = true,
|
|
770
|
+
style,
|
|
771
|
+
ref,
|
|
772
|
+
...elementProps
|
|
773
|
+
} = componentProps;
|
|
774
|
+
const ctx = useNumberFieldRootContext();
|
|
775
|
+
const { disabled: contextDisabled, maxWithDefault, minWithDefault, readOnly, state, value } = ctx;
|
|
776
|
+
const isAtBoundary = value != null && (isIncrement ? value >= maxWithDefault : value <= minWithDefault);
|
|
777
|
+
const disabled = disabledProp || contextDisabled || isAtBoundary;
|
|
778
|
+
const buttonProps = useNumberFieldButton({ ...ctx, isIncrement, disabled, slot });
|
|
779
|
+
const { getButtonProps, buttonRef } = (0, import_useButton.useButton)(
|
|
780
|
+
{ disabled: disabled || readOnly, native: nativeButton, focusableWhenDisabled: true },
|
|
781
|
+
(0, import_internal.subSlot)(slot, "button")
|
|
782
|
+
);
|
|
783
|
+
const buttonState = { ...state, disabled };
|
|
784
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
785
|
+
"button",
|
|
786
|
+
{ render, className, style },
|
|
787
|
+
{
|
|
788
|
+
ref: [ref, buttonRef],
|
|
789
|
+
state: buttonState,
|
|
790
|
+
props: [buttonProps, elementProps, getButtonProps],
|
|
791
|
+
stateAttributesMapping
|
|
792
|
+
},
|
|
793
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
function NumberFieldIncrement(props) {
|
|
797
|
+
return useNumberFieldStepperButton(props, true, (0, import_internal.S)("NumberFieldIncrement"));
|
|
798
|
+
}
|
|
799
|
+
function NumberFieldDecrement(props) {
|
|
800
|
+
return useNumberFieldStepperButton(props, false, (0, import_internal.S)("NumberFieldDecrement"));
|
|
801
|
+
}
|
|
802
|
+
const NumberField = {
|
|
803
|
+
Root: NumberFieldRoot,
|
|
804
|
+
Group: NumberFieldGroup,
|
|
805
|
+
Input: NumberFieldInput,
|
|
806
|
+
Increment: NumberFieldIncrement,
|
|
807
|
+
Decrement: NumberFieldDecrement
|
|
808
|
+
};
|
|
809
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
810
|
+
0 && (module.exports = {
|
|
811
|
+
NumberField
|
|
812
|
+
});
|