@thecb/components 10.11.0 → 10.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -27092,79 +27092,83 @@ var createFormat = function createFormat(formats, formatChar) {
27092
27092
  var FormattedInput = function FormattedInput(_ref) {
27093
27093
  var value = _ref.value,
27094
27094
  formatter = _ref.formatter,
27095
- _onChange = _ref.onChange,
27095
+ onChange = _ref.onChange,
27096
27096
  props = _objectWithoutProperties$1(_ref, ["value", "formatter", "onChange"]);
27097
27097
 
27098
- var inputEl = React.useRef(null);
27098
+ var _useState = React.useState(format$1(formatter)(value)),
27099
+ _useState2 = _slicedToArray$1(_useState, 2),
27100
+ formattedValue = _useState2[0],
27101
+ setFormattedValue = _useState2[1];
27099
27102
 
27100
- var _useState = React.useState({
27103
+ var inputEl = React.useRef(null);
27104
+ var stateRefs = React.useRef({
27101
27105
  selectionStart: 0,
27102
27106
  selectionEnd: 0,
27103
- rawValue: value,
27104
- "delete": false,
27105
- formattedValue: format$1(formatter)(value)
27106
- }),
27107
- _useState2 = _slicedToArray$1(_useState, 2),
27108
- state = _useState2[0],
27109
- setState = _useState2[1];
27110
-
27107
+ isDelete: false,
27108
+ rawValue: ''
27109
+ });
27111
27110
  React.useLayoutEffect(function () {
27112
27111
  // A lot of the work here is cursor manipulation
27113
27112
  if (inputEl.current && inputEl.current === document.activeElement) {
27114
- inputEl.current.setSelectionRange(state.selectionStart, state.selectionEnd);
27113
+ inputEl.current.setSelectionRange(stateRefs.current.selectionStart, stateRefs.current.selectionEnd);
27115
27114
  }
27116
- });
27115
+ }, [stateRefs]);
27116
+
27117
+ var handleChange = function handleChange(event) {
27118
+ var deleteKeyPressed = stateRefs.current.isDelete;
27119
+ var maxFormatExceeded = stateRefs.current.rawValue.length >= formatter.formats.length - 1;
27120
+
27121
+ if (maxFormatExceeded && !deleteKeyPressed) {
27122
+ return;
27123
+ }
27124
+ /* At the beginning of onChange, event.target.value is a concat of the previous formatted value
27125
+ * and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
27126
+ * the unformatted value for the user's onChange, the formatted string and unformatted injection need
27127
+ * to be separated, then unformat the formatted string, then insert (or delete) the injection from the
27128
+ * old unformatted value.
27129
+ */
27130
+
27131
+
27132
+ var injectionLength = event.target.value.length - formattedValue.length;
27133
+ var end = stateRefs.current.selectionStart === stateRefs.current.selectionEnd ? stateRefs.current.selectionStart + injectionLength : stateRefs.current.selectionEnd - 1;
27134
+ var injection = event.target.value.substring(stateRefs.current.selectionStart, end); // Injection is the new unformatted piece of the input
27135
+ // Need to find where to put it
27136
+
27137
+ var rawInjectionPointStart = formattedToUnformattedIndex(stateRefs.current.selectionStart, stateRefs.current.rawValue, formatter);
27138
+ var rawInjectionPointEnd = formattedToUnformattedIndex(stateRefs.current.selectionEnd, stateRefs.current.rawValue, formatter); // Unformat the previous formatted value for injection
27139
+ // Using the relevant format string, strips away chars not marked with the formatChar
27140
+
27141
+ var unformattedOldValue = unformat(formatter)(formattedValue, stateRefs.current.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
27142
+
27143
+ var injectIntoOldValue = inject(unformattedOldValue);
27144
+ var unformattedNewValue = deleteKeyPressed ? rawInjectionPointStart === rawInjectionPointEnd ? injectIntoOldValue(rawInjectionPointStart - 1, rawInjectionPointStart, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, injection);
27145
+ var lengthDifference = unformattedNewValue.length - stateRefs.current.rawValue.length;
27146
+ var rawIndex = formattedToUnformattedIndex(stateRefs.current.selectionStart, stateRefs.current.rawValue, formatter) + lengthDifference; // Find the new cursor position for the potential formatted value
27147
+ // Applied by useLayoutEffect
27148
+
27149
+ var newFormattedCursorPosition = stateRefs.current.selectionStart === stateRefs.current.selectionEnd ? unformattedToFormattedIndex(rawIndex, unformattedNewValue, formatter, deleteKeyPressed) : deleteKeyPressed ? stateRefs.current.selectionStart : stateRefs.current.selectionEnd;
27150
+ var formattedNewValue = format$1(formatter)(unformattedNewValue);
27151
+ setFormattedValue(formattedNewValue); // Apply the external onChange function to the raw underlying string
27152
+ // This is where the user generally updates the input value
27153
+
27154
+ if (onChange) {
27155
+ onChange(unformattedNewValue);
27156
+ }
27157
+ };
27158
+
27117
27159
  return React__default.createElement("input", _extends$2({}, props, {
27118
27160
  ref: inputEl,
27119
27161
  value: format$1(formatter)(value),
27120
27162
  onKeyDown: function onKeyDown(event) {
27121
- // Keep track of the state of the input before onChange, including if user is hitting delete
27122
- setState({
27123
- rawValue: value,
27163
+ // Keep track of the state of the input before onChange
27164
+ stateRefs.current = {
27165
+ isDelete: event.key === "Backspace" || event.key === "Delete",
27124
27166
  selectionStart: event.target.selectionStart,
27125
27167
  selectionEnd: event.target.selectionEnd,
27126
- "delete": event.key === "Backspace" || event.key === "Delete",
27127
- formattedValue: event.target.value
27128
- });
27168
+ rawValue: value
27169
+ };
27129
27170
  },
27130
- onChange: function onChange(event) {
27131
- /* At the beginning of onChange, event.target.value is a concat of the previous formatted value
27132
- * and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
27133
- * the unformatted value for the user's onChange, the formatted string and unformatted injection need
27134
- * to be separated, then unformat the formatted string, then insert (or delete) the injection from the
27135
- * old unformatted value.
27136
- */
27137
- var injectionLength = event.target.value.length - state.formattedValue.length;
27138
- var end = state.selectionStart === state.selectionEnd ? state.selectionStart + injectionLength : state.selectionEnd - 1;
27139
- var injection = event.target.value.substring(state.selectionStart, end); // Injection is the new unformatted piece of the input
27140
- // Need to find where to put it
27141
-
27142
- var rawInjectionPointStart = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter);
27143
- var rawInjectionPointEnd = formattedToUnformattedIndex(state.selectionEnd, state.rawValue, formatter); // Unformat the previous formatted value for injection
27144
- // Using the relevant format string, strips away chars not marked with the formatChar
27145
-
27146
- var unformattedOldValue = unformat(formatter)(state.formattedValue, state.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
27147
-
27148
- var injectIntoOldValue = inject(unformattedOldValue);
27149
- var unformattedNewValue = state["delete"] ? rawInjectionPointStart === rawInjectionPointEnd ? injectIntoOldValue(rawInjectionPointStart - 1, rawInjectionPointStart, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, injection);
27150
- var lengthDifference = unformattedNewValue.length - state.rawValue.length;
27151
- var rawIndex = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter) + lengthDifference; // Find the new cursor position for the potential formatted value
27152
- // Applied by useLayoutEffect
27153
-
27154
- var newFormattedCursorPosition = state.selectionStart == state.selectionEnd ? unformattedToFormattedIndex(rawIndex, unformattedNewValue, formatter, state["delete"]) : state["delete"] ? state.selectionStart : state.selectionEnd;
27155
- setState({
27156
- selectionStart: newFormattedCursorPosition,
27157
- selectionEnd: newFormattedCursorPosition,
27158
- rawValue: state.rawValue,
27159
- "delete": false,
27160
- formattedValue: state.formattedValue
27161
- }); // Apply the external onChange function to the raw underlying string
27162
- // This is where the user generally updates the input value
27163
-
27164
- if (_onChange) {
27165
- _onChange(unformattedNewValue);
27166
- }
27167
- }
27171
+ onChange: handleChange
27168
27172
  }));
27169
27173
  };
27170
27174
 
@@ -39053,6 +39057,15 @@ var allOptions = {
39053
39057
  }, {
39054
39058
  text: "Wyoming",
39055
39059
  value: "WY"
39060
+ }, {
39061
+ text: "Armed Forces Americas",
39062
+ value: "AA"
39063
+ }, {
39064
+ text: "Armed Forces Europe",
39065
+ value: "AE"
39066
+ }, {
39067
+ text: "Armed Forces Pacific",
39068
+ value: "AP"
39056
39069
  }],
39057
39070
  UM: [{
39058
39071
  text: "Palmyra Atoll",