var initialInputControlState = {
isPressEnterToChange: false,
DRAG_START: 'DRAG_START',
INVALIDATE: 'INVALIDATE',
PRESS_DOWN: 'PRESS_DOWN',
PRESS_ENTER: 'PRESS_ENTER',
var inputControlActionTypes = actionTypes;
* Prepares initialState for the reducer.
* @param {Object} initialState The initial state.
* @return {Object} Prepared initialState for the reducer
function mergeInitialState() {
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialInputControlState;
var value = initialState.value;
return state_objectSpread(state_objectSpread(state_objectSpread({}, initialInputControlState), initialState), {}, {
* Composes multiple stateReducers into a single stateReducer, building
* the pipeline to control the flow for state and actions.
* @param {...Function} fns State reducers.
* @return {Function} The single composed stateReducer.
var state_composeStateReducers = function composeStateReducers() {
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
fns[_key] = arguments[_key];
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
return fns.reduceRight(function (state, fn) {
var fnState = fn.apply(void 0, args);
return Object(external_lodash_["isEmpty"])(fnState) ? state : state_objectSpread(state_objectSpread({}, state), fnState);
* Creates a reducer that opens the channel for external state subscription
* This technique uses the "stateReducer" design pattern:
* https://kentcdodds.com/blog/the-state-reducer-pattern/
* @param {Function} composedStateReducers A custom reducer that can subscribe and modify state.
* @return {Function} The reducer.
function inputControlStateReducer(composedStateReducers) {
return function (state, action) {
var nextState = state_objectSpread({}, state);
payload = action.payload;
case actionTypes.PRESS_UP:
nextState.isDirty = false;
case actionTypes.PRESS_DOWN:
nextState.isDirty = false;
case actionTypes.DRAG_START:
nextState.isDragging = true;
case actionTypes.DRAG_END:
nextState.isDragging = false;
nextState.value = payload.value;
if (state.isPressEnterToChange) {
nextState.isDirty = true;
nextState.value = payload.value;
nextState.isDirty = false;
nextState.isDirty = false;
nextState.value = payload.value || state.initialValue;
nextState.value = payload.value;
nextState.isDirty = false;
case actionTypes.INVALIDATE:
nextState.error = payload.error;
nextState._event = payload.event;
* Send the nextState + action to the composedReducers via
* this "bridge" mechanism. This allows external stateReducers
* to hook into actions, and modify state if needed.
return composedStateReducers(nextState, action);
* A custom hook that connects and external stateReducer with an internal
* reducer. This hook manages the internal state of InputControl.
* However, by connecting an external stateReducer function, other
* components can react to actions as well as modify state before it is
* This technique uses the "stateReducer" design pattern:
* https://kentcdodds.com/blog/the-state-reducer-pattern/
* @param {Function} stateReducer An external state reducer.
* @param {Object} initialState The initial state for the reducer.
* @return {Object} State, dispatch, and a collection of actions.
function useInputControlStateReducer() {
var stateReducer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialStateReducer;
var initialState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : initialInputControlState;
var _useReducer = Object(external_wp_element_["useReducer"])(inputControlStateReducer(stateReducer), mergeInitialState(initialState)),
_useReducer2 = Object(slicedToArray["a" /* default */])(_useReducer, 2),
dispatch = _useReducer2[1];
var createChangeEvent = function createChangeEvent(type) {
return function (nextValue, event) {
* Persist allows for the (Synthetic) event to be used outside of
* https://reactjs.org/docs/events.html#event-pooling
if (event && event.persist) {
var createKeyEvent = function createKeyEvent(type) {
return function (event) {
* Persist allows for the (Synthetic) event to be used outside of
* https://reactjs.org/docs/events.html#event-pooling
if (event && event.persist) {
var createDragEvent = function createDragEvent(type) {
return function (dragProps) {
* Actions for the reducer
var change = createChangeEvent(actionTypes.CHANGE);
var invalidate = createChangeEvent(actionTypes.INVALIDATE);
var reset = createChangeEvent(actionTypes.RESET);
var commit = createChangeEvent(actionTypes.COMMIT);
var update = createChangeEvent(actionTypes.UPDATE);
var dragStart = createDragEvent(actionTypes.DRAG_START);
var drag = createDragEvent(actionTypes.DRAG);
var dragEnd = createDragEvent(actionTypes.DRAG_END);
var pressUp = createKeyEvent(actionTypes.PRESS_UP);
var pressDown = createKeyEvent(actionTypes.PRESS_DOWN);
var pressEnter = createKeyEvent(actionTypes.PRESS_ENTER);
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/utils/values.js
/* eslint-disable jsdoc/valid-types */
* Determines if a value is null or undefined.
* @param {T | null | undefined} value The value to check.
* @return {value is T} Whether value is not null or undefined.
function isValueDefined(value) {
return value !== undefined && value !== null;
/* eslint-enable jsdoc/valid-types */
/* eslint-disable jsdoc/valid-types */
* Determines if a value is empty, null, or undefined.
* @param {T | "" | null | undefined} value The value to check.
* @return {value is T} Whether value is empty.
function isValueEmpty(value) {
var isEmptyString = value === '';
return !isValueDefined(value) || isEmptyString;
/* eslint-enable jsdoc/valid-types */
* Get the first defined/non-null value from an array.
* @param {Array<T | null | undefined>} values Values to derive from.
* @param {T} fallbackValue Fallback value if there are no defined values.
* @return {T} A defined value or the fallback value.
function getDefinedValue() {
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var fallbackValue = arguments.length > 1 ? arguments[1] : undefined;
return (_values$find = values.find(isValueDefined)) !== null && _values$find !== void 0 ? _values$find : fallbackValue;
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/utils/hooks/use-update-effect.js
* A `React.useEffect` that will not run on the first render.
* https://github.com/reakit/reakit/blob/HEAD/packages/reakit-utils/src/useUpdateEffect.ts
* @param {import('react').EffectCallback} effect
* @param {import('react').DependencyList} deps
function useUpdateEffect(effect, deps) {
var mounted = Object(external_wp_element_["useRef"])(false);
Object(external_wp_element_["useEffect"])(function () {
/* harmony default export */ var use_update_effect = (useUpdateEffect);
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/input-control/input-field.js
function InputField(_ref, ref) {
var _ref$disabled = _ref.disabled,
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
_ref$dragDirection = _ref.dragDirection,
dragDirection = _ref$dragDirection === void 0 ? 'n' : _ref$dragDirection,
_ref$dragThreshold = _ref.dragThreshold,
dragThreshold = _ref$dragThreshold === void 0 ? 10 : _ref$dragThreshold,
_ref$isDragEnabled = _ref.isDragEnabled,
isDragEnabled = _ref$isDragEnabled === void 0 ? false : _ref$isDragEnabled,
isFocused = _ref.isFocused,
_ref$isPressEnterToCh = _ref.isPressEnterToChange,
isPressEnterToChange = _ref$isPressEnterToCh === void 0 ? false : _ref$isPressEnterToCh,
_ref$onBlur = _ref.onBlur,
onBlur = _ref$onBlur === void 0 ? external_lodash_["noop"] : _ref$onBlur,
_ref$onChange = _ref.onChange,
onChange = _ref$onChange === void 0 ? external_lodash_["noop"] : _ref$onChange,
_ref$onDrag = _ref.onDrag,
onDrag = _ref$onDrag === void 0 ? external_lodash_["noop"] : _ref$onDrag,
_ref$onDragEnd = _ref.onDragEnd,
onDragEnd = _ref$onDragEnd === void 0 ? external_lodash_["noop"] : _ref$onDragEnd,
_ref$onDragStart = _ref.onDragStart,
onDragStart = _ref$onDragStart === void 0 ? external_lodash_["noop"] : _ref$onDragStart,
_ref$onFocus = _ref.onFocus,
onFocus = _ref$onFocus === void 0 ? external_lodash_["noop"] : _ref$onFocus,
_ref$onKeyDown = _ref.onKeyDown,
onKeyDown = _ref$onKeyDown === void 0 ? external_lodash_["noop"] : _ref$onKeyDown,
_ref$onValidate = _ref.onValidate,
onValidate = _ref$onValidate === void 0 ? external_lodash_["noop"] : _ref$onValidate,
size = _ref$size === void 0 ? 'default' : _ref$size,
setIsFocused = _ref.setIsFocused,
_ref$stateReducer = _ref.stateReducer,
stateReducer = _ref$stateReducer === void 0 ? function (state) {
props = Object(objectWithoutProperties["a" /* default */])(_ref, ["disabled", "dragDirection", "dragThreshold", "id", "isDragEnabled", "isFocused", "isPressEnterToChange", "onBlur", "onChange", "onDrag", "onDragEnd", "onDragStart", "onFocus", "onKeyDown", "onValidate", "size", "setIsFocused", "stateReducer", "value", "type"]);
var _useInputControlState = useInputControlStateReducer(stateReducer, {
isDragEnabled: isDragEnabled,
isPressEnterToChange: isPressEnterToChange
state = _useInputControlState.state,
change = _useInputControlState.change,
commit = _useInputControlState.commit,
drag = _useInputControlState.drag,
dragEnd = _useInputControlState.dragEnd,
dragStart = _useInputControlState.dragStart,
invalidate = _useInputControlState.invalidate,
pressDown = _useInputControlState.pressDown,
pressEnter = _useInputControlState.pressEnter,
pressUp = _useInputControlState.pressUp,
reset = _useInputControlState.reset,
update = _useInputControlState.update;
var _event = state._event,
isDragging = state.isDragging,
var wasDirtyOnBlur = Object(external_wp_element_["useRef"])(false);
var dragCursor = useDragCursor(isDragging, dragDirection);
* Handles syncronization of external and internal value state.
* If not focused and did not hold a dirty value[1] on blur
* updates the value from the props. Otherwise if not holding
* a dirty value[1] propagates the value and event through onChange.
* [1] value is only made dirty if isPressEnterToChange is true
use_update_effect(function () {
if (valueProp === value) {
if (!isFocused && !wasDirtyOnBlur.current) {
wasDirtyOnBlur.current = false;
}, [value, isDirty, isFocused, valueProp]);
var handleOnBlur = function handleOnBlur(event) {
* If isPressEnterToChange is set, this commits the value to
if (isPressEnterToChange && isDirty) {
wasDirtyOnBlur.current = true;
if (!isValueEmpty(value)) {
var handleOnFocus = function handleOnFocus(event) {
var handleOnChange = function handleOnChange(event) {
var nextValue = event.target.value;
change(nextValue, event);
var handleOnCommit = function handleOnCommit(event) {
var nextValue = event.target.value;
onValidate(nextValue, event);
commit(nextValue, event);
var handleOnKeyDown = function handleOnKeyDown(event) {
var keyCode = event.keyCode;