@thecb/components 5.0.0-beta.11 → 5.0.0-beta.12
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 +233 -257
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +233 -257
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -5014,10 +5014,6 @@ var TextSpan = styled__default.span.withConfig({
|
|
|
5014
5014
|
|
|
5015
5015
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
5016
5016
|
|
|
5017
|
-
function unwrapExports (x) {
|
|
5018
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5019
|
-
}
|
|
5020
|
-
|
|
5021
5017
|
function createCommonjsModule(fn, module) {
|
|
5022
5018
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
5023
5019
|
}
|
|
@@ -20675,303 +20671,283 @@ var DisplayCard = function DisplayCard(_ref) {
|
|
|
20675
20671
|
}) : /*#__PURE__*/React__default.createElement(React.Fragment, null))))));
|
|
20676
20672
|
};
|
|
20677
20673
|
|
|
20678
|
-
|
|
20679
|
-
|
|
20680
|
-
|
|
20681
|
-
|
|
20682
|
-
var React__default = 'default' in React ? React['default'] : React;
|
|
20683
|
-
|
|
20684
|
-
function _extends() {
|
|
20685
|
-
_extends = Object.assign || function (target) {
|
|
20686
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
20687
|
-
var source = arguments[i];
|
|
20674
|
+
function _extends$2() {
|
|
20675
|
+
_extends$2 = Object.assign || function (target) {
|
|
20676
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
20677
|
+
var source = arguments[i];
|
|
20688
20678
|
|
|
20689
|
-
|
|
20690
|
-
|
|
20691
|
-
|
|
20692
|
-
}
|
|
20679
|
+
for (var key in source) {
|
|
20680
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
20681
|
+
target[key] = source[key];
|
|
20693
20682
|
}
|
|
20694
20683
|
}
|
|
20684
|
+
}
|
|
20695
20685
|
|
|
20696
|
-
|
|
20697
|
-
|
|
20698
|
-
|
|
20699
|
-
return _extends.apply(this, arguments);
|
|
20700
|
-
}
|
|
20686
|
+
return target;
|
|
20687
|
+
};
|
|
20701
20688
|
|
|
20702
|
-
|
|
20703
|
-
|
|
20704
|
-
var target = {};
|
|
20705
|
-
var sourceKeys = Object.keys(source);
|
|
20706
|
-
var key, i;
|
|
20689
|
+
return _extends$2.apply(this, arguments);
|
|
20690
|
+
}
|
|
20707
20691
|
|
|
20708
|
-
|
|
20709
|
-
|
|
20710
|
-
|
|
20711
|
-
|
|
20712
|
-
|
|
20692
|
+
function _objectWithoutPropertiesLoose$1(source, excluded) {
|
|
20693
|
+
if (source == null) return {};
|
|
20694
|
+
var target = {};
|
|
20695
|
+
var sourceKeys = Object.keys(source);
|
|
20696
|
+
var key, i;
|
|
20713
20697
|
|
|
20714
|
-
|
|
20698
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
20699
|
+
key = sourceKeys[i];
|
|
20700
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
20701
|
+
target[key] = source[key];
|
|
20715
20702
|
}
|
|
20716
20703
|
|
|
20717
|
-
|
|
20718
|
-
|
|
20704
|
+
return target;
|
|
20705
|
+
}
|
|
20719
20706
|
|
|
20720
|
-
|
|
20707
|
+
function _objectWithoutProperties$1(source, excluded) {
|
|
20708
|
+
if (source == null) return {};
|
|
20721
20709
|
|
|
20722
|
-
|
|
20710
|
+
var target = _objectWithoutPropertiesLoose$1(source, excluded);
|
|
20723
20711
|
|
|
20724
|
-
|
|
20725
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
20712
|
+
var key, i;
|
|
20726
20713
|
|
|
20727
|
-
|
|
20728
|
-
|
|
20729
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
20730
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
20731
|
-
target[key] = source[key];
|
|
20732
|
-
}
|
|
20733
|
-
}
|
|
20714
|
+
if (Object.getOwnPropertySymbols) {
|
|
20715
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
20734
20716
|
|
|
20735
|
-
|
|
20717
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
20718
|
+
key = sourceSymbolKeys[i];
|
|
20719
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
20720
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
20721
|
+
target[key] = source[key];
|
|
20722
|
+
}
|
|
20736
20723
|
}
|
|
20737
20724
|
|
|
20738
|
-
|
|
20739
|
-
|
|
20740
|
-
}
|
|
20725
|
+
return target;
|
|
20726
|
+
}
|
|
20741
20727
|
|
|
20742
|
-
|
|
20743
|
-
|
|
20744
|
-
|
|
20728
|
+
function _slicedToArray$1(arr, i) {
|
|
20729
|
+
return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _nonIterableRest$1();
|
|
20730
|
+
}
|
|
20745
20731
|
|
|
20746
|
-
|
|
20747
|
-
|
|
20748
|
-
|
|
20732
|
+
function _toConsumableArray$1(arr) {
|
|
20733
|
+
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
|
|
20734
|
+
}
|
|
20749
20735
|
|
|
20750
|
-
|
|
20751
|
-
|
|
20752
|
-
|
|
20736
|
+
function _arrayWithoutHoles$1(arr) {
|
|
20737
|
+
if (Array.isArray(arr)) {
|
|
20738
|
+
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
20753
20739
|
|
|
20754
|
-
|
|
20755
|
-
if (Array.isArray(arr)) return arr;
|
|
20740
|
+
return arr2;
|
|
20756
20741
|
}
|
|
20742
|
+
}
|
|
20743
|
+
|
|
20744
|
+
function _arrayWithHoles$1(arr) {
|
|
20745
|
+
if (Array.isArray(arr)) return arr;
|
|
20746
|
+
}
|
|
20757
20747
|
|
|
20758
|
-
|
|
20759
|
-
|
|
20748
|
+
function _iterableToArray$1(iter) {
|
|
20749
|
+
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
|
20750
|
+
}
|
|
20751
|
+
|
|
20752
|
+
function _iterableToArrayLimit$1(arr, i) {
|
|
20753
|
+
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
|
|
20754
|
+
return;
|
|
20760
20755
|
}
|
|
20761
20756
|
|
|
20762
|
-
|
|
20763
|
-
|
|
20764
|
-
|
|
20765
|
-
|
|
20757
|
+
var _arr = [];
|
|
20758
|
+
var _n = true;
|
|
20759
|
+
var _d = false;
|
|
20760
|
+
var _e = undefined;
|
|
20766
20761
|
|
|
20767
|
-
|
|
20768
|
-
var _n = true
|
|
20769
|
-
|
|
20770
|
-
var _e = undefined;
|
|
20762
|
+
try {
|
|
20763
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
20764
|
+
_arr.push(_s.value);
|
|
20771
20765
|
|
|
20766
|
+
if (i && _arr.length === i) break;
|
|
20767
|
+
}
|
|
20768
|
+
} catch (err) {
|
|
20769
|
+
_d = true;
|
|
20770
|
+
_e = err;
|
|
20771
|
+
} finally {
|
|
20772
20772
|
try {
|
|
20773
|
-
|
|
20774
|
-
_arr.push(_s.value);
|
|
20775
|
-
|
|
20776
|
-
if (i && _arr.length === i) break;
|
|
20777
|
-
}
|
|
20778
|
-
} catch (err) {
|
|
20779
|
-
_d = true;
|
|
20780
|
-
_e = err;
|
|
20773
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
20781
20774
|
} finally {
|
|
20782
|
-
|
|
20783
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
20784
|
-
} finally {
|
|
20785
|
-
if (_d) throw _e;
|
|
20786
|
-
}
|
|
20775
|
+
if (_d) throw _e;
|
|
20787
20776
|
}
|
|
20788
|
-
|
|
20789
|
-
return _arr;
|
|
20790
20777
|
}
|
|
20791
20778
|
|
|
20792
|
-
|
|
20793
|
-
|
|
20794
|
-
}
|
|
20779
|
+
return _arr;
|
|
20780
|
+
}
|
|
20795
20781
|
|
|
20796
|
-
|
|
20797
|
-
|
|
20798
|
-
|
|
20782
|
+
function _nonIterableSpread$1() {
|
|
20783
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
|
20784
|
+
}
|
|
20799
20785
|
|
|
20800
|
-
|
|
20801
|
-
|
|
20802
|
-
|
|
20803
|
-
var format = function format(formatter) {
|
|
20804
|
-
return function (value) {
|
|
20805
|
-
var usedFormat = formatter.formats[value.length];
|
|
20786
|
+
function _nonIterableRest$1() {
|
|
20787
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
20788
|
+
}
|
|
20806
20789
|
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
20790
|
+
var getUniqueFormatDelimiters = function getUniqueFormatDelimiters(formats, formatChar) {
|
|
20791
|
+
return _toConsumableArray$1(new Set(formats.join("").split(formatChar).join("").split("")));
|
|
20792
|
+
};
|
|
20793
|
+
var format$1 = function format(formatter) {
|
|
20794
|
+
return function (value) {
|
|
20795
|
+
var usedFormat = formatter.formats[value.length];
|
|
20810
20796
|
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
return v + (valuePieces[i] || "");
|
|
20815
|
-
});
|
|
20816
|
-
return zipped.join("");
|
|
20817
|
-
};
|
|
20818
|
-
};
|
|
20797
|
+
if (!usedFormat) {
|
|
20798
|
+
return value;
|
|
20799
|
+
}
|
|
20819
20800
|
|
|
20820
|
-
|
|
20821
|
-
var
|
|
20822
|
-
var
|
|
20823
|
-
|
|
20824
|
-
formatter.uniqueDelimiters.forEach(function (delim) {
|
|
20825
|
-
return count += format.split(delim).length - 1;
|
|
20801
|
+
var formatPieces = usedFormat.split(formatter.formatChar);
|
|
20802
|
+
var valuePieces = value.split("");
|
|
20803
|
+
var zipped = formatPieces.map(function (v, i) {
|
|
20804
|
+
return v + (valuePieces[i] || "");
|
|
20826
20805
|
});
|
|
20827
|
-
return
|
|
20806
|
+
return zipped.join("");
|
|
20828
20807
|
};
|
|
20808
|
+
};
|
|
20829
20809
|
|
|
20830
|
-
|
|
20831
|
-
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
}).join("");
|
|
20840
|
-
};
|
|
20841
|
-
};
|
|
20842
|
-
var inject = function inject(baseString) {
|
|
20843
|
-
return function (start, end, newString) {
|
|
20844
|
-
return baseString.substring(0, start) + newString + baseString.substring(end);
|
|
20845
|
-
};
|
|
20846
|
-
};
|
|
20847
|
-
var formattedToUnformattedIndex = function formattedToUnformattedIndex(formattedIndex, rawValue, formatter) {
|
|
20848
|
-
var maxFormatExceeded = rawValue.length >= formatter.formats.length;
|
|
20810
|
+
var countDelims = function countDelims(formatter, index) {
|
|
20811
|
+
var count = 0;
|
|
20812
|
+
var format = formatter.formats[index];
|
|
20813
|
+
if (!format) return 0;
|
|
20814
|
+
formatter.uniqueDelimiters.forEach(function (delim) {
|
|
20815
|
+
return count += format.split(delim).length - 1;
|
|
20816
|
+
});
|
|
20817
|
+
return count;
|
|
20818
|
+
};
|
|
20849
20819
|
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
var beforeString = formatString.slice(0, formattedIndex);
|
|
20855
|
-
return beforeString.split("").filter(function (c) {
|
|
20856
|
-
return c === formatter.formatChar;
|
|
20857
|
-
}).length;
|
|
20820
|
+
var unformat = function unformat(formatter) {
|
|
20821
|
+
return function (formattedValue, formatIndex) {
|
|
20822
|
+
if (formatIndex >= formatter.formats.length) {
|
|
20823
|
+
return formattedValue;
|
|
20858
20824
|
}
|
|
20859
|
-
};
|
|
20860
|
-
var unformattedToFormattedIndex = function unformattedToFormattedIndex(rawIndex, rawValue, formatter, del) {
|
|
20861
|
-
var maxFormatExceeded = rawValue.length >= formatter.formats.length; // If forced to stay formatted, offset by delims - 1
|
|
20862
|
-
// This is done so the component doesn't assume that any added chars will be kept
|
|
20863
|
-
// (i.e. if an external constraint is applied)
|
|
20864
|
-
|
|
20865
|
-
if (maxFormatExceeded) {
|
|
20866
|
-
var delims = countDelims(formatter, rawValue.length - 1);
|
|
20867
|
-
return delims > 0 && !del ? rawIndex + delims - 1 : rawIndex;
|
|
20868
|
-
} else {
|
|
20869
|
-
return formatter.formats[rawValue.length].split(formatter.formatChar).slice(0, rawIndex).reduce(function (acc, curr) {
|
|
20870
|
-
return curr.length + acc;
|
|
20871
|
-
}, 0) + rawIndex;
|
|
20872
|
-
}
|
|
20873
|
-
};
|
|
20874
20825
|
|
|
20875
|
-
|
|
20876
|
-
return {
|
|
20877
|
-
|
|
20878
|
-
|
|
20879
|
-
formatChar: formatChar
|
|
20880
|
-
};
|
|
20826
|
+
var format = formatter.formats[formatIndex];
|
|
20827
|
+
return formattedValue.split("").filter(function (_, i) {
|
|
20828
|
+
return !(format[i] != formatter.formatChar);
|
|
20829
|
+
}).join("");
|
|
20881
20830
|
};
|
|
20831
|
+
};
|
|
20832
|
+
var inject = function inject(baseString) {
|
|
20833
|
+
return function (start, end, newString) {
|
|
20834
|
+
return baseString.substring(0, start) + newString + baseString.substring(end);
|
|
20835
|
+
};
|
|
20836
|
+
};
|
|
20837
|
+
var formattedToUnformattedIndex = function formattedToUnformattedIndex(formattedIndex, rawValue, formatter) {
|
|
20838
|
+
var maxFormatExceeded = rawValue.length >= formatter.formats.length;
|
|
20882
20839
|
|
|
20883
|
-
|
|
20884
|
-
|
|
20885
|
-
|
|
20886
|
-
|
|
20887
|
-
|
|
20888
|
-
|
|
20889
|
-
|
|
20890
|
-
|
|
20891
|
-
|
|
20892
|
-
|
|
20893
|
-
|
|
20894
|
-
|
|
20895
|
-
|
|
20896
|
-
|
|
20897
|
-
}),
|
|
20898
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
20899
|
-
state = _useState2[0],
|
|
20900
|
-
setState = _useState2[1];
|
|
20901
|
-
|
|
20902
|
-
React.useLayoutEffect(function () {
|
|
20903
|
-
// A lot of the work here is cursor manipulation
|
|
20904
|
-
if (inputEl.current && inputEl.current === document.activeElement) {
|
|
20905
|
-
inputEl.current.setSelectionRange(state.selectionStart, state.selectionEnd);
|
|
20906
|
-
}
|
|
20907
|
-
});
|
|
20908
|
-
return React__default.createElement("input", _extends({}, props, {
|
|
20909
|
-
ref: inputEl,
|
|
20910
|
-
value: format(formatter)(value),
|
|
20911
|
-
onKeyDown: function onKeyDown(event) {
|
|
20912
|
-
// Keep track of the state of the input before onChange, including if user is hitting delete
|
|
20913
|
-
setState({
|
|
20914
|
-
rawValue: value,
|
|
20915
|
-
selectionStart: event.target.selectionStart,
|
|
20916
|
-
selectionEnd: event.target.selectionEnd,
|
|
20917
|
-
"delete": event.key === "Backspace" || event.key === "Delete",
|
|
20918
|
-
formattedValue: event.target.value
|
|
20919
|
-
});
|
|
20920
|
-
},
|
|
20921
|
-
onChange: function onChange(event) {
|
|
20922
|
-
/* At the beginning of onChange, event.target.value is a concat of the previous formatted value
|
|
20923
|
-
* and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
|
|
20924
|
-
* the unformatted value for the user's onChange, the formatted string and unformatted injection need
|
|
20925
|
-
* to be separated, then unformat the formatted string, then insert (or delete) the injection from the
|
|
20926
|
-
* old unformatted value.
|
|
20927
|
-
*/
|
|
20928
|
-
var injectionLength = event.target.value.length - state.formattedValue.length;
|
|
20929
|
-
var end = state.selectionStart === state.selectionEnd ? state.selectionStart + injectionLength : state.selectionEnd - 1;
|
|
20930
|
-
var injection = event.target.value.substring(state.selectionStart, end); // Injection is the new unformatted piece of the input
|
|
20931
|
-
// Need to find where to put it
|
|
20932
|
-
|
|
20933
|
-
var rawInjectionPointStart = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter);
|
|
20934
|
-
var rawInjectionPointEnd = formattedToUnformattedIndex(state.selectionEnd, state.rawValue, formatter); // Unformat the previous formatted value for injection
|
|
20935
|
-
// Using the relevant format string, strips away chars not marked with the formatChar
|
|
20936
|
-
|
|
20937
|
-
var unformattedOldValue = unformat(formatter)(state.formattedValue, state.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
|
|
20840
|
+
if (maxFormatExceeded) {
|
|
20841
|
+
return formattedIndex;
|
|
20842
|
+
} else {
|
|
20843
|
+
var formatString = formatter.formats[rawValue.length];
|
|
20844
|
+
var beforeString = formatString.slice(0, formattedIndex);
|
|
20845
|
+
return beforeString.split("").filter(function (c) {
|
|
20846
|
+
return c === formatter.formatChar;
|
|
20847
|
+
}).length;
|
|
20848
|
+
}
|
|
20849
|
+
};
|
|
20850
|
+
var unformattedToFormattedIndex = function unformattedToFormattedIndex(rawIndex, rawValue, formatter, del) {
|
|
20851
|
+
var maxFormatExceeded = rawValue.length >= formatter.formats.length; // If forced to stay formatted, offset by delims - 1
|
|
20852
|
+
// This is done so the component doesn't assume that any added chars will be kept
|
|
20853
|
+
// (i.e. if an external constraint is applied)
|
|
20938
20854
|
|
|
20939
|
-
|
|
20940
|
-
|
|
20941
|
-
|
|
20942
|
-
|
|
20943
|
-
|
|
20855
|
+
if (maxFormatExceeded) {
|
|
20856
|
+
var delims = countDelims(formatter, rawValue.length - 1);
|
|
20857
|
+
return delims > 0 && !del ? rawIndex + delims - 1 : rawIndex;
|
|
20858
|
+
} else {
|
|
20859
|
+
return formatter.formats[rawValue.length].split(formatter.formatChar).slice(0, rawIndex).reduce(function (acc, curr) {
|
|
20860
|
+
return curr.length + acc;
|
|
20861
|
+
}, 0) + rawIndex;
|
|
20862
|
+
}
|
|
20863
|
+
};
|
|
20944
20864
|
|
|
20945
|
-
|
|
20946
|
-
|
|
20947
|
-
|
|
20948
|
-
|
|
20949
|
-
|
|
20950
|
-
"delete": false,
|
|
20951
|
-
formattedValue: state.formattedValue
|
|
20952
|
-
}); // Apply the external onChange function to the raw underlying string
|
|
20953
|
-
// This is where the user generally updates the input value
|
|
20954
|
-
|
|
20955
|
-
if (_onChange) {
|
|
20956
|
-
_onChange(unformattedNewValue);
|
|
20957
|
-
}
|
|
20958
|
-
}
|
|
20959
|
-
}));
|
|
20865
|
+
var createFormat = function createFormat(formats, formatChar) {
|
|
20866
|
+
return {
|
|
20867
|
+
uniqueDelimiters: getUniqueFormatDelimiters(formats, formatChar),
|
|
20868
|
+
formats: formats,
|
|
20869
|
+
formatChar: formatChar
|
|
20960
20870
|
};
|
|
20871
|
+
};
|
|
20961
20872
|
|
|
20962
|
-
|
|
20963
|
-
|
|
20964
|
-
|
|
20873
|
+
var FormattedInput = function FormattedInput(_ref) {
|
|
20874
|
+
var value = _ref.value,
|
|
20875
|
+
formatter = _ref.formatter,
|
|
20876
|
+
_onChange = _ref.onChange,
|
|
20877
|
+
props = _objectWithoutProperties$1(_ref, ["value", "formatter", "onChange"]);
|
|
20965
20878
|
|
|
20966
|
-
|
|
20879
|
+
var inputEl = React.useRef(null);
|
|
20967
20880
|
|
|
20968
|
-
|
|
20969
|
-
|
|
20881
|
+
var _useState = React.useState({
|
|
20882
|
+
selectionStart: 0,
|
|
20883
|
+
selectionEnd: 0,
|
|
20884
|
+
rawValue: value,
|
|
20885
|
+
"delete": false,
|
|
20886
|
+
formattedValue: format$1(formatter)(value)
|
|
20887
|
+
}),
|
|
20888
|
+
_useState2 = _slicedToArray$1(_useState, 2),
|
|
20889
|
+
state = _useState2[0],
|
|
20890
|
+
setState = _useState2[1];
|
|
20970
20891
|
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
20974
|
-
|
|
20892
|
+
React.useLayoutEffect(function () {
|
|
20893
|
+
// A lot of the work here is cursor manipulation
|
|
20894
|
+
if (inputEl.current && inputEl.current === document.activeElement) {
|
|
20895
|
+
inputEl.current.setSelectionRange(state.selectionStart, state.selectionEnd);
|
|
20896
|
+
}
|
|
20897
|
+
});
|
|
20898
|
+
return React__default.createElement("input", _extends$2({}, props, {
|
|
20899
|
+
ref: inputEl,
|
|
20900
|
+
value: format$1(formatter)(value),
|
|
20901
|
+
onKeyDown: function onKeyDown(event) {
|
|
20902
|
+
// Keep track of the state of the input before onChange, including if user is hitting delete
|
|
20903
|
+
setState({
|
|
20904
|
+
rawValue: value,
|
|
20905
|
+
selectionStart: event.target.selectionStart,
|
|
20906
|
+
selectionEnd: event.target.selectionEnd,
|
|
20907
|
+
"delete": event.key === "Backspace" || event.key === "Delete",
|
|
20908
|
+
formattedValue: event.target.value
|
|
20909
|
+
});
|
|
20910
|
+
},
|
|
20911
|
+
onChange: function onChange(event) {
|
|
20912
|
+
/* At the beginning of onChange, event.target.value is a concat of the previous formatted value
|
|
20913
|
+
* and an unformatted injection at the start, end, or in the middle (maybe a deletion). To prepare
|
|
20914
|
+
* the unformatted value for the user's onChange, the formatted string and unformatted injection need
|
|
20915
|
+
* to be separated, then unformat the formatted string, then insert (or delete) the injection from the
|
|
20916
|
+
* old unformatted value.
|
|
20917
|
+
*/
|
|
20918
|
+
var injectionLength = event.target.value.length - state.formattedValue.length;
|
|
20919
|
+
var end = state.selectionStart === state.selectionEnd ? state.selectionStart + injectionLength : state.selectionEnd - 1;
|
|
20920
|
+
var injection = event.target.value.substring(state.selectionStart, end); // Injection is the new unformatted piece of the input
|
|
20921
|
+
// Need to find where to put it
|
|
20922
|
+
|
|
20923
|
+
var rawInjectionPointStart = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter);
|
|
20924
|
+
var rawInjectionPointEnd = formattedToUnformattedIndex(state.selectionEnd, state.rawValue, formatter); // Unformat the previous formatted value for injection
|
|
20925
|
+
// Using the relevant format string, strips away chars not marked with the formatChar
|
|
20926
|
+
|
|
20927
|
+
var unformattedOldValue = unformat(formatter)(state.formattedValue, state.rawValue.length); // Edit the previous unformatted value (either add, update or delete)
|
|
20928
|
+
|
|
20929
|
+
var injectIntoOldValue = inject(unformattedOldValue);
|
|
20930
|
+
var unformattedNewValue = state["delete"] ? rawInjectionPointStart === rawInjectionPointEnd ? injectIntoOldValue(rawInjectionPointStart - 1, rawInjectionPointStart, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, "") : injectIntoOldValue(rawInjectionPointStart, rawInjectionPointEnd, injection);
|
|
20931
|
+
var lengthDifference = unformattedNewValue.length - state.rawValue.length;
|
|
20932
|
+
var rawIndex = formattedToUnformattedIndex(state.selectionStart, state.rawValue, formatter) + lengthDifference; // Find the new cursor position for the potential formatted value
|
|
20933
|
+
// Applied by useLayoutEffect
|
|
20934
|
+
|
|
20935
|
+
var newFormattedCursorPosition = state.selectionStart == state.selectionEnd ? unformattedToFormattedIndex(rawIndex, unformattedNewValue, formatter, state["delete"]) : state["delete"] ? state.selectionStart : state.selectionEnd;
|
|
20936
|
+
setState({
|
|
20937
|
+
selectionStart: newFormattedCursorPosition,
|
|
20938
|
+
selectionEnd: newFormattedCursorPosition,
|
|
20939
|
+
rawValue: state.rawValue,
|
|
20940
|
+
"delete": false,
|
|
20941
|
+
formattedValue: state.formattedValue
|
|
20942
|
+
}); // Apply the external onChange function to the raw underlying string
|
|
20943
|
+
// This is where the user generally updates the input value
|
|
20944
|
+
|
|
20945
|
+
if (_onChange) {
|
|
20946
|
+
_onChange(unformattedNewValue);
|
|
20947
|
+
}
|
|
20948
|
+
}
|
|
20949
|
+
}));
|
|
20950
|
+
};
|
|
20975
20951
|
|
|
20976
20952
|
var linkColor$2 = {
|
|
20977
20953
|
"default": "".concat(MATISSE_BLUE),
|
|
@@ -21073,7 +21049,7 @@ var FormattedInputField = styled__default(function (_ref8) {
|
|
|
21073
21049
|
themeValues = _ref8.themeValues,
|
|
21074
21050
|
props = _objectWithoutProperties(_ref8, _excluded$p);
|
|
21075
21051
|
|
|
21076
|
-
return /*#__PURE__*/React__default.createElement(
|
|
21052
|
+
return /*#__PURE__*/React__default.createElement(FormattedInput, props);
|
|
21077
21053
|
}).withConfig({
|
|
21078
21054
|
displayName: "FormInput__FormattedInputField",
|
|
21079
21055
|
componentId: "sc-l094r1-1"
|
|
@@ -34865,11 +34841,11 @@ var zipFormats = ["", "_", "__", "___", "____", "_____", "______", "_____-__", "
|
|
|
34865
34841
|
var creditCardFormats = ["", "_", "__", "___", "____", "____ _", "____ __", "____ ___", "____ ____", "____ ____ _", "____ ____ __", "____ ____ ___", "____ ____ ____", "____ ____ ____ _", "____ ____ ____ __", "____ ____ ____ ___", "____ ____ ____ ____"];
|
|
34866
34842
|
var moneyFormats = ["", "$0.0_", "$0.__", "$_.__", "$__.__", "$___.__", "$_,___.__", "$__,___.__", "$___,___.__", "$_,___,___.__", "$__,___,___.__", "$___,___,___.__", "$_,___,___,___.__", "$__,___,___,___.__", "$___,___,___,___.__", "$_,___,___,___,___.__"];
|
|
34867
34843
|
var expirationDateFormats = ["", "_", "__/", "__/_", "__/__"];
|
|
34868
|
-
var zipFormat =
|
|
34869
|
-
var creditCardFormat =
|
|
34870
|
-
var expirationDateFormat =
|
|
34871
|
-
var phoneFormat =
|
|
34872
|
-
var moneyFormat =
|
|
34844
|
+
var zipFormat = createFormat(zipFormats, formatDelimiter);
|
|
34845
|
+
var creditCardFormat = createFormat(creditCardFormats, formatDelimiter);
|
|
34846
|
+
var expirationDateFormat = createFormat(expirationDateFormats, formatDelimiter);
|
|
34847
|
+
var phoneFormat = createFormat(phoneFormats, formatDelimiter);
|
|
34848
|
+
var moneyFormat = createFormat(moneyFormats, formatDelimiter);
|
|
34873
34849
|
|
|
34874
34850
|
var formats = /*#__PURE__*/Object.freeze({
|
|
34875
34851
|
__proto__: null,
|
|
@@ -40391,7 +40367,7 @@ var PhoneForm = function PhoneForm(_ref) {
|
|
|
40391
40367
|
field: fields.phone,
|
|
40392
40368
|
fieldActions: actions.fields.phone,
|
|
40393
40369
|
showErrors: showErrors,
|
|
40394
|
-
formatter:
|
|
40370
|
+
formatter: createFormat(phoneFormats, formatDelimiter),
|
|
40395
40371
|
onKeyUp: function onKeyUp(e) {
|
|
40396
40372
|
return e.key === "Enter" && handleSubmit(e);
|
|
40397
40373
|
},
|