@mtes-mct/monitor-ui 7.4.3 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/index.js +2251 -1567
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1311,7 +1311,7 @@ var tail$1 = tail;
|
|
|
1311
1311
|
* @symb R.pipe(f, g, h)(a)(b) = h(g(f(a)))(b)
|
|
1312
1312
|
*/
|
|
1313
1313
|
|
|
1314
|
-
function pipe() {
|
|
1314
|
+
function pipe$1() {
|
|
1315
1315
|
if (arguments.length === 0) {
|
|
1316
1316
|
throw new Error('pipe requires at least one argument');
|
|
1317
1317
|
}
|
|
@@ -3548,7 +3548,7 @@ const useClickOutsideEffect = (zoneRefOrzoneRefs, action, baseContainer) => {
|
|
|
3548
3548
|
const handleClickOutside = useCallback((event) => {
|
|
3549
3549
|
const eventTarget = event.target;
|
|
3550
3550
|
const zoneRefs = Array.isArray(zoneRefOrzoneRefs) ? zoneRefOrzoneRefs : [zoneRefOrzoneRefs];
|
|
3551
|
-
const isEventTargetInZones = pipe(map$1((zoneRef) => zoneRef.current && eventTarget ? zoneRef.current.contains(eventTarget) : false), any$1(identity$1))(zoneRefs);
|
|
3551
|
+
const isEventTargetInZones = pipe$1(map$1((zoneRef) => zoneRef.current && eventTarget ? zoneRef.current.contains(eventTarget) : false), any$1(identity$1))(zoneRefs);
|
|
3552
3552
|
if (isEventTargetInZones) {
|
|
3553
3553
|
return;
|
|
3554
3554
|
}
|
|
@@ -22921,13 +22921,13 @@ function isBoolean(value) {
|
|
|
22921
22921
|
)
|
|
22922
22922
|
}
|
|
22923
22923
|
|
|
22924
|
-
function isObject(value) {
|
|
22924
|
+
function isObject$1(value) {
|
|
22925
22925
|
return typeof value === 'object'
|
|
22926
22926
|
}
|
|
22927
22927
|
|
|
22928
22928
|
// Checks if `value` is object-like.
|
|
22929
22929
|
function isObjectLike(value) {
|
|
22930
|
-
return isObject(value) && value !== null
|
|
22930
|
+
return isObject$1(value) && value !== null
|
|
22931
22931
|
}
|
|
22932
22932
|
|
|
22933
22933
|
function isDefined(value) {
|
|
@@ -24225,7 +24225,7 @@ const isExpression = (query) =>
|
|
|
24225
24225
|
const isPath = (query) => !!query[KeyType.PATH];
|
|
24226
24226
|
|
|
24227
24227
|
const isLeaf = (query) =>
|
|
24228
|
-
!isArray(query) && isObject(query) && !isExpression(query);
|
|
24228
|
+
!isArray(query) && isObject$1(query) && !isExpression(query);
|
|
24229
24229
|
|
|
24230
24230
|
const convertToExplicit = (query) => ({
|
|
24231
24231
|
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
@@ -27500,7 +27500,7 @@ function _extends() {
|
|
|
27500
27500
|
return _extends.apply(this, arguments);
|
|
27501
27501
|
}
|
|
27502
27502
|
|
|
27503
|
-
function _objectWithoutPropertiesLoose$1
|
|
27503
|
+
function _objectWithoutPropertiesLoose$1(source, excluded) {
|
|
27504
27504
|
if (source == null) return {};
|
|
27505
27505
|
var target = {};
|
|
27506
27506
|
var sourceKeys = Object.keys(source);
|
|
@@ -27518,7 +27518,7 @@ function _objectWithoutPropertiesLoose$1$1(source, excluded) {
|
|
|
27518
27518
|
function _objectWithoutProperties$1(source, excluded) {
|
|
27519
27519
|
if (source == null) return {};
|
|
27520
27520
|
|
|
27521
|
-
var target = _objectWithoutPropertiesLoose$1
|
|
27521
|
+
var target = _objectWithoutPropertiesLoose$1(source, excluded);
|
|
27522
27522
|
|
|
27523
27523
|
var key, i;
|
|
27524
27524
|
|
|
@@ -27666,7 +27666,7 @@ function _isNativeReflectConstruct() {
|
|
|
27666
27666
|
}
|
|
27667
27667
|
}
|
|
27668
27668
|
|
|
27669
|
-
function _objectWithoutPropertiesLoose
|
|
27669
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
27670
27670
|
if (source == null) return {};
|
|
27671
27671
|
var target = {};
|
|
27672
27672
|
var sourceKeys = Object.keys(source);
|
|
@@ -27684,7 +27684,7 @@ function _objectWithoutPropertiesLoose$2(source, excluded) {
|
|
|
27684
27684
|
function _objectWithoutProperties(source, excluded) {
|
|
27685
27685
|
if (source == null) return {};
|
|
27686
27686
|
|
|
27687
|
-
var target = _objectWithoutPropertiesLoose
|
|
27687
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
27688
27688
|
|
|
27689
27689
|
var key, i;
|
|
27690
27690
|
|
|
@@ -28612,8 +28612,8 @@ function createMask$1(opts) {
|
|
|
28612
28612
|
}
|
|
28613
28613
|
IMask$1.createMask = createMask$1;
|
|
28614
28614
|
|
|
28615
|
-
var _excluded$4
|
|
28616
|
-
var DEFAULT_INPUT_DEFINITIONS
|
|
28615
|
+
var _excluded$4 = ["mask"];
|
|
28616
|
+
var DEFAULT_INPUT_DEFINITIONS = {
|
|
28617
28617
|
'0': /\d/,
|
|
28618
28618
|
'a': /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
|
|
28619
28619
|
// http://stackoverflow.com/a/22075070
|
|
@@ -28637,7 +28637,7 @@ var PatternInputDefinition$1 = /*#__PURE__*/function () {
|
|
|
28637
28637
|
_classCallCheck(this, PatternInputDefinition);
|
|
28638
28638
|
|
|
28639
28639
|
var mask = opts.mask,
|
|
28640
|
-
blockOpts = _objectWithoutProperties(opts, _excluded$4
|
|
28640
|
+
blockOpts = _objectWithoutProperties(opts, _excluded$4);
|
|
28641
28641
|
|
|
28642
28642
|
this.masked = createMask$1({
|
|
28643
28643
|
mask: mask
|
|
@@ -28926,7 +28926,7 @@ var PatternFixedDefinition$1 = /*#__PURE__*/function () {
|
|
|
28926
28926
|
return PatternFixedDefinition;
|
|
28927
28927
|
}();
|
|
28928
28928
|
|
|
28929
|
-
var _excluded$3
|
|
28929
|
+
var _excluded$3 = ["chunks"];
|
|
28930
28930
|
|
|
28931
28931
|
var ChunksTailDetails$1 = /*#__PURE__*/function () {
|
|
28932
28932
|
/** */
|
|
@@ -29045,7 +29045,7 @@ var ChunksTailDetails$1 = /*#__PURE__*/function () {
|
|
|
29045
29045
|
},
|
|
29046
29046
|
set: function set(state) {
|
|
29047
29047
|
var chunks = state.chunks,
|
|
29048
|
-
props = _objectWithoutProperties(state, _excluded$3
|
|
29048
|
+
props = _objectWithoutProperties(state, _excluded$3);
|
|
29049
29049
|
|
|
29050
29050
|
Object.assign(this, props);
|
|
29051
29051
|
this.chunks = chunks.map(function (cstate) {
|
|
@@ -29119,7 +29119,7 @@ var MaskedRegExp$1 = /*#__PURE__*/function (_Masked) {
|
|
|
29119
29119
|
}(Masked$1);
|
|
29120
29120
|
IMask$1.MaskedRegExp = MaskedRegExp$1;
|
|
29121
29121
|
|
|
29122
|
-
var _excluded$2
|
|
29122
|
+
var _excluded$2 = ["_blocks"];
|
|
29123
29123
|
|
|
29124
29124
|
/**
|
|
29125
29125
|
Pattern mask
|
|
@@ -29147,7 +29147,7 @@ var MaskedPattern$1 = /*#__PURE__*/function (_Masked) {
|
|
|
29147
29147
|
_classCallCheck(this, MaskedPattern);
|
|
29148
29148
|
|
|
29149
29149
|
// TODO type $Shape<MaskedPatternOptions>={} does not work
|
|
29150
|
-
opts.definitions = Object.assign({}, DEFAULT_INPUT_DEFINITIONS
|
|
29150
|
+
opts.definitions = Object.assign({}, DEFAULT_INPUT_DEFINITIONS, opts.definitions);
|
|
29151
29151
|
return _super.call(this, Object.assign({}, MaskedPattern.DEFAULTS, opts));
|
|
29152
29152
|
}
|
|
29153
29153
|
/**
|
|
@@ -29278,7 +29278,7 @@ var MaskedPattern$1 = /*#__PURE__*/function (_Masked) {
|
|
|
29278
29278
|
},
|
|
29279
29279
|
set: function set(state) {
|
|
29280
29280
|
var _blocks = state._blocks,
|
|
29281
|
-
maskedState = _objectWithoutProperties(state, _excluded$2
|
|
29281
|
+
maskedState = _objectWithoutProperties(state, _excluded$2);
|
|
29282
29282
|
|
|
29283
29283
|
this._blocks.forEach(function (b, bi) {
|
|
29284
29284
|
return b.state = _blocks[bi];
|
|
@@ -30410,7 +30410,7 @@ var HTMLContenteditableMaskElement$1 = /*#__PURE__*/function (_HTMLMaskElement)
|
|
|
30410
30410
|
}(HTMLMaskElement$1);
|
|
30411
30411
|
IMask$1.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement$1;
|
|
30412
30412
|
|
|
30413
|
-
var _excluded$1
|
|
30413
|
+
var _excluded$1 = ["mask"];
|
|
30414
30414
|
/** Listens to element events and controls changes between element and {@link Masked} */
|
|
30415
30415
|
|
|
30416
30416
|
var InputMask$1 = /*#__PURE__*/function () {
|
|
@@ -30629,7 +30629,7 @@ var InputMask$1 = /*#__PURE__*/function () {
|
|
|
30629
30629
|
key: "updateOptions",
|
|
30630
30630
|
value: function updateOptions(opts) {
|
|
30631
30631
|
var mask = opts.mask,
|
|
30632
|
-
restOpts = _objectWithoutProperties(opts, _excluded$1
|
|
30632
|
+
restOpts = _objectWithoutProperties(opts, _excluded$1);
|
|
30633
30633
|
|
|
30634
30634
|
var updateMask = !this.maskEquals(mask);
|
|
30635
30635
|
var updateOpts = !objectIncludes$1(this.masked, restOpts);
|
|
@@ -30817,7 +30817,7 @@ IMask$1.InputMask = InputMask$1;
|
|
|
30817
30817
|
|
|
30818
30818
|
/** Pattern which validates enum values */
|
|
30819
30819
|
|
|
30820
|
-
var MaskedEnum = /*#__PURE__*/function (_MaskedPattern) {
|
|
30820
|
+
var MaskedEnum$1 = /*#__PURE__*/function (_MaskedPattern) {
|
|
30821
30821
|
_inherits(MaskedEnum, _MaskedPattern);
|
|
30822
30822
|
|
|
30823
30823
|
var _super = _createSuper(MaskedEnum);
|
|
@@ -30863,7 +30863,7 @@ var MaskedEnum = /*#__PURE__*/function (_MaskedPattern) {
|
|
|
30863
30863
|
|
|
30864
30864
|
return MaskedEnum;
|
|
30865
30865
|
}(MaskedPattern$1);
|
|
30866
|
-
IMask$1.MaskedEnum = MaskedEnum;
|
|
30866
|
+
IMask$1.MaskedEnum = MaskedEnum$1;
|
|
30867
30867
|
|
|
30868
30868
|
var DEGREE_CHAR = '°';
|
|
30869
30869
|
var MINUTE_CHAR = '′';
|
|
@@ -31160,7 +31160,7 @@ var getArcSecondMask = function getArcSecondMask(precision) {
|
|
|
31160
31160
|
|
|
31161
31161
|
var getDirectionMask = function getDirectionMask(isLon) {
|
|
31162
31162
|
return {
|
|
31163
|
-
mask: MaskedEnum,
|
|
31163
|
+
mask: MaskedEnum$1,
|
|
31164
31164
|
"enum": isLon ? ['E', 'W'] : ['N', 'S'],
|
|
31165
31165
|
prepare: function prepare(str) {
|
|
31166
31166
|
return str.toUpperCase();
|
|
@@ -31353,7 +31353,7 @@ var useCoordMask = function useCoordMask(_ref) {
|
|
|
31353
31353
|
}, [controlledValue, inputRef, setValue]);
|
|
31354
31354
|
};
|
|
31355
31355
|
|
|
31356
|
-
var _excluded
|
|
31356
|
+
var _excluded = ["degreeChar", "minuteChar", "secondChar", "spacerChar", "placeholderChar", "ddPrecision", "dmsPrecision", "inputRef", "placeholder", "onChange", "value"];
|
|
31357
31357
|
/**
|
|
31358
31358
|
* CoordinateInput
|
|
31359
31359
|
*/
|
|
@@ -31371,7 +31371,7 @@ var CoordinateInput = function CoordinateInput(_ref) {
|
|
|
31371
31371
|
placeholder = _ref$placeholder === void 0 ? '04° 08′ 15″ N 162° 03′ 42″ E' : _ref$placeholder,
|
|
31372
31372
|
onChange = _ref.onChange,
|
|
31373
31373
|
controlledValue = _ref.value,
|
|
31374
|
-
props = _objectWithoutProperties$1(_ref, _excluded
|
|
31374
|
+
props = _objectWithoutProperties$1(_ref, _excluded);
|
|
31375
31375
|
|
|
31376
31376
|
var innerRef = useRef(null);
|
|
31377
31377
|
useCoordMask({
|
|
@@ -31413,92 +31413,26 @@ CoordinateInput.propTypes = {
|
|
|
31413
31413
|
value: PropTypes.string
|
|
31414
31414
|
};
|
|
31415
31415
|
|
|
31416
|
-
function _objectDestructuringEmpty(obj) {
|
|
31417
|
-
if (obj == null) throw new TypeError("Cannot destructure " + obj);
|
|
31418
|
-
}
|
|
31419
|
-
function _objectWithoutPropertiesLoose$1(source, excluded) {
|
|
31420
|
-
if (source == null) return {};
|
|
31421
|
-
var target = {};
|
|
31422
|
-
var sourceKeys = Object.keys(source);
|
|
31423
|
-
var key, i;
|
|
31424
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
31425
|
-
key = sourceKeys[i];
|
|
31426
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
31427
|
-
target[key] = source[key];
|
|
31428
|
-
}
|
|
31429
|
-
return target;
|
|
31430
|
-
}
|
|
31431
|
-
|
|
31432
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
31433
|
-
if (source == null) return {};
|
|
31434
|
-
var target = {};
|
|
31435
|
-
var sourceKeys = Object.keys(source);
|
|
31436
|
-
var key, i;
|
|
31437
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
31438
|
-
key = sourceKeys[i];
|
|
31439
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
31440
|
-
target[key] = source[key];
|
|
31441
|
-
}
|
|
31442
|
-
return target;
|
|
31443
|
-
}
|
|
31444
|
-
|
|
31445
|
-
/**
|
|
31446
|
-
Provides details of changing model value
|
|
31447
|
-
@param {Object} [details]
|
|
31448
|
-
@param {string} [details.inserted] - Inserted symbols
|
|
31449
|
-
@param {boolean} [details.skip] - Can skip chars
|
|
31450
|
-
@param {number} [details.removeCount] - Removed symbols count
|
|
31451
|
-
@param {number} [details.tailShift] - Additional offset if any changes occurred before tail
|
|
31452
|
-
*/
|
|
31453
|
-
class ChangeDetails {
|
|
31454
|
-
/** Inserted symbols */
|
|
31455
|
-
|
|
31456
|
-
/** Can skip chars */
|
|
31457
|
-
|
|
31458
|
-
/** Additional offset if any changes occurred before tail */
|
|
31459
|
-
|
|
31460
|
-
/** Raw inserted is used by dynamic mask */
|
|
31461
|
-
|
|
31462
|
-
constructor(details) {
|
|
31463
|
-
Object.assign(this, {
|
|
31464
|
-
inserted: '',
|
|
31465
|
-
rawInserted: '',
|
|
31466
|
-
skip: false,
|
|
31467
|
-
tailShift: 0
|
|
31468
|
-
}, details);
|
|
31469
|
-
}
|
|
31470
|
-
|
|
31471
|
-
/**
|
|
31472
|
-
Aggregate changes
|
|
31473
|
-
@returns {ChangeDetails} `this`
|
|
31474
|
-
*/
|
|
31475
|
-
aggregate(details) {
|
|
31476
|
-
this.rawInserted += details.rawInserted;
|
|
31477
|
-
this.skip = this.skip || details.skip;
|
|
31478
|
-
this.inserted += details.inserted;
|
|
31479
|
-
this.tailShift += details.tailShift;
|
|
31480
|
-
return this;
|
|
31481
|
-
}
|
|
31482
|
-
|
|
31483
|
-
/** Total offset considering all changes */
|
|
31484
|
-
get offset() {
|
|
31485
|
-
return this.tailShift + this.inserted.length;
|
|
31486
|
-
}
|
|
31487
|
-
}
|
|
31488
|
-
|
|
31489
31416
|
/** Checks if value is string */
|
|
31490
31417
|
function isString(str) {
|
|
31491
31418
|
return typeof str === 'string' || str instanceof String;
|
|
31492
31419
|
}
|
|
31493
31420
|
|
|
31494
|
-
/**
|
|
31495
|
-
|
|
31496
|
-
|
|
31497
|
-
|
|
31498
|
-
|
|
31499
|
-
|
|
31500
|
-
|
|
31501
|
-
|
|
31421
|
+
/** Checks if value is object */
|
|
31422
|
+
function isObject(obj) {
|
|
31423
|
+
var _obj$constructor;
|
|
31424
|
+
return typeof obj === 'object' && obj != null && (obj == null ? void 0 : (_obj$constructor = obj.constructor) == null ? void 0 : _obj$constructor.name) === 'Object';
|
|
31425
|
+
}
|
|
31426
|
+
function pick(obj, keys) {
|
|
31427
|
+
if (Array.isArray(keys)) return pick(obj, (_, k) => keys.includes(k));
|
|
31428
|
+
return Object.entries(obj).reduce((acc, _ref) => {
|
|
31429
|
+
let [k, v] = _ref;
|
|
31430
|
+
if (keys(v, k)) acc[k] = v;
|
|
31431
|
+
return acc;
|
|
31432
|
+
}, {});
|
|
31433
|
+
}
|
|
31434
|
+
|
|
31435
|
+
/** Direction */
|
|
31502
31436
|
const DIRECTION = {
|
|
31503
31437
|
NONE: 'NONE',
|
|
31504
31438
|
LEFT: 'LEFT',
|
|
@@ -31507,7 +31441,8 @@ const DIRECTION = {
|
|
|
31507
31441
|
FORCE_RIGHT: 'FORCE_RIGHT'
|
|
31508
31442
|
};
|
|
31509
31443
|
|
|
31510
|
-
/** */
|
|
31444
|
+
/** Direction */
|
|
31445
|
+
|
|
31511
31446
|
function forceDirection(direction) {
|
|
31512
31447
|
switch (direction) {
|
|
31513
31448
|
case DIRECTION.LEFT:
|
|
@@ -31518,16 +31453,18 @@ function forceDirection(direction) {
|
|
|
31518
31453
|
return direction;
|
|
31519
31454
|
}
|
|
31520
31455
|
}
|
|
31521
|
-
|
|
31522
|
-
|
|
31456
|
+
|
|
31457
|
+
/** Escapes regular expression control chars */
|
|
31458
|
+
function escapeRegExp(str) {
|
|
31459
|
+
return str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
|
|
31523
31460
|
}
|
|
31524
31461
|
|
|
31525
31462
|
// cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
|
|
31526
31463
|
function objectIncludes(b, a) {
|
|
31527
31464
|
if (a === b) return true;
|
|
31528
|
-
|
|
31529
|
-
arrB = Array.isArray(b)
|
|
31530
|
-
|
|
31465
|
+
const arrA = Array.isArray(a),
|
|
31466
|
+
arrB = Array.isArray(b);
|
|
31467
|
+
let i;
|
|
31531
31468
|
if (arrA && arrB) {
|
|
31532
31469
|
if (a.length != b.length) return false;
|
|
31533
31470
|
for (i = 0; i < a.length; i++) if (!objectIncludes(a[i], b[i])) return false;
|
|
@@ -31535,20 +31472,18 @@ function objectIncludes(b, a) {
|
|
|
31535
31472
|
}
|
|
31536
31473
|
if (arrA != arrB) return false;
|
|
31537
31474
|
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
31538
|
-
|
|
31475
|
+
const dateA = a instanceof Date,
|
|
31539
31476
|
dateB = b instanceof Date;
|
|
31540
31477
|
if (dateA && dateB) return a.getTime() == b.getTime();
|
|
31541
31478
|
if (dateA != dateB) return false;
|
|
31542
|
-
|
|
31479
|
+
const regexpA = a instanceof RegExp,
|
|
31543
31480
|
regexpB = b instanceof RegExp;
|
|
31544
31481
|
if (regexpA && regexpB) return a.toString() == b.toString();
|
|
31545
31482
|
if (regexpA != regexpB) return false;
|
|
31546
|
-
|
|
31483
|
+
const keys = Object.keys(a);
|
|
31547
31484
|
// if (keys.length !== Object.keys(b).length) return false;
|
|
31548
31485
|
|
|
31549
|
-
for (i = 0; i < keys.length; i++)
|
|
31550
|
-
// $FlowFixMe ... ???
|
|
31551
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
31486
|
+
for (i = 0; i < keys.length; i++) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
31552
31487
|
for (i = 0; i < keys.length; i++) if (!objectIncludes(b[keys[i]], a[keys[i]])) return false;
|
|
31553
31488
|
return true;
|
|
31554
31489
|
} else if (a && b && typeof a === 'function' && typeof b === 'function') {
|
|
@@ -31567,11 +31502,8 @@ class ActionDetails {
|
|
|
31567
31502
|
|
|
31568
31503
|
/** Old selection */
|
|
31569
31504
|
|
|
31570
|
-
constructor(
|
|
31571
|
-
this
|
|
31572
|
-
this.cursorPos = cursorPos;
|
|
31573
|
-
this.oldValue = oldValue;
|
|
31574
|
-
this.oldSelection = oldSelection;
|
|
31505
|
+
constructor(opts) {
|
|
31506
|
+
Object.assign(this, opts);
|
|
31575
31507
|
|
|
31576
31508
|
// double check if left part was changed (autofilling, other non-standard input triggers)
|
|
31577
31509
|
while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
|
|
@@ -31579,34 +31511,22 @@ class ActionDetails {
|
|
|
31579
31511
|
}
|
|
31580
31512
|
}
|
|
31581
31513
|
|
|
31582
|
-
/**
|
|
31583
|
-
Start changing position
|
|
31584
|
-
@readonly
|
|
31585
|
-
*/
|
|
31514
|
+
/** Start changing position */
|
|
31586
31515
|
get startChangePos() {
|
|
31587
31516
|
return Math.min(this.cursorPos, this.oldSelection.start);
|
|
31588
31517
|
}
|
|
31589
31518
|
|
|
31590
|
-
/**
|
|
31591
|
-
Inserted symbols count
|
|
31592
|
-
@readonly
|
|
31593
|
-
*/
|
|
31519
|
+
/** Inserted symbols count */
|
|
31594
31520
|
get insertedCount() {
|
|
31595
31521
|
return this.cursorPos - this.startChangePos;
|
|
31596
31522
|
}
|
|
31597
31523
|
|
|
31598
|
-
/**
|
|
31599
|
-
Inserted symbols
|
|
31600
|
-
@readonly
|
|
31601
|
-
*/
|
|
31524
|
+
/** Inserted symbols */
|
|
31602
31525
|
get inserted() {
|
|
31603
31526
|
return this.value.substr(this.startChangePos, this.insertedCount);
|
|
31604
31527
|
}
|
|
31605
31528
|
|
|
31606
|
-
/**
|
|
31607
|
-
Removed symbols count
|
|
31608
|
-
@readonly
|
|
31609
|
-
*/
|
|
31529
|
+
/** Removed symbols count */
|
|
31610
31530
|
get removedCount() {
|
|
31611
31531
|
// Math.max for opposite operation
|
|
31612
31532
|
return Math.max(this.oldSelection.end - this.startChangePos ||
|
|
@@ -31614,34 +31534,22 @@ class ActionDetails {
|
|
|
31614
31534
|
this.oldValue.length - this.value.length, 0);
|
|
31615
31535
|
}
|
|
31616
31536
|
|
|
31617
|
-
/**
|
|
31618
|
-
Removed symbols
|
|
31619
|
-
@readonly
|
|
31620
|
-
*/
|
|
31537
|
+
/** Removed symbols */
|
|
31621
31538
|
get removed() {
|
|
31622
31539
|
return this.oldValue.substr(this.startChangePos, this.removedCount);
|
|
31623
31540
|
}
|
|
31624
31541
|
|
|
31625
|
-
/**
|
|
31626
|
-
Unchanged head symbols
|
|
31627
|
-
@readonly
|
|
31628
|
-
*/
|
|
31542
|
+
/** Unchanged head symbols */
|
|
31629
31543
|
get head() {
|
|
31630
31544
|
return this.value.substring(0, this.startChangePos);
|
|
31631
31545
|
}
|
|
31632
31546
|
|
|
31633
|
-
/**
|
|
31634
|
-
Unchanged tail symbols
|
|
31635
|
-
@readonly
|
|
31636
|
-
*/
|
|
31547
|
+
/** Unchanged tail symbols */
|
|
31637
31548
|
get tail() {
|
|
31638
31549
|
return this.value.substring(this.startChangePos + this.insertedCount);
|
|
31639
31550
|
}
|
|
31640
31551
|
|
|
31641
|
-
/**
|
|
31642
|
-
Remove direction
|
|
31643
|
-
@readonly
|
|
31644
|
-
*/
|
|
31552
|
+
/** Remove direction */
|
|
31645
31553
|
get removeDirection() {
|
|
31646
31554
|
if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
|
|
31647
31555
|
|
|
@@ -31652,237 +31560,898 @@ class ActionDetails {
|
|
|
31652
31560
|
}
|
|
31653
31561
|
}
|
|
31654
31562
|
|
|
31655
|
-
/**
|
|
31656
|
-
|
|
31657
|
-
|
|
31658
|
-
|
|
31659
|
-
|
|
31660
|
-
|
|
31661
|
-
/** Start position */
|
|
31563
|
+
/** Applies mask on element */
|
|
31564
|
+
function IMask(el, opts) {
|
|
31565
|
+
// currently available only for input-like elements
|
|
31566
|
+
return new IMask.InputMask(el, opts);
|
|
31567
|
+
}
|
|
31662
31568
|
|
|
31663
|
-
|
|
31664
|
-
|
|
31665
|
-
|
|
31666
|
-
|
|
31667
|
-
|
|
31668
|
-
|
|
31669
|
-
|
|
31670
|
-
|
|
31671
|
-
|
|
31672
|
-
|
|
31673
|
-
|
|
31674
|
-
|
|
31675
|
-
|
|
31676
|
-
|
|
31677
|
-
|
|
31678
|
-
|
|
31679
|
-
|
|
31680
|
-
|
|
31681
|
-
|
|
31682
|
-
|
|
31683
|
-
|
|
31684
|
-
|
|
31685
|
-
|
|
31686
|
-
|
|
31569
|
+
// TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
|
|
31570
|
+
// export function maskedClass(mask: string): typeof MaskedPattern;
|
|
31571
|
+
// export function maskedClass(mask: DateConstructor): typeof MaskedDate;
|
|
31572
|
+
// export function maskedClass(mask: NumberConstructor): typeof MaskedNumber;
|
|
31573
|
+
// export function maskedClass(mask: Array<any> | ArrayConstructor): typeof MaskedDynamic;
|
|
31574
|
+
// export function maskedClass(mask: MaskedDate): typeof MaskedDate;
|
|
31575
|
+
// export function maskedClass(mask: MaskedNumber): typeof MaskedNumber;
|
|
31576
|
+
// export function maskedClass(mask: MaskedEnum): typeof MaskedEnum;
|
|
31577
|
+
// export function maskedClass(mask: MaskedRange): typeof MaskedRange;
|
|
31578
|
+
// export function maskedClass(mask: MaskedRegExp): typeof MaskedRegExp;
|
|
31579
|
+
// export function maskedClass(mask: MaskedFunction): typeof MaskedFunction;
|
|
31580
|
+
// export function maskedClass(mask: MaskedPattern): typeof MaskedPattern;
|
|
31581
|
+
// export function maskedClass(mask: MaskedDynamic): typeof MaskedDynamic;
|
|
31582
|
+
// export function maskedClass(mask: Masked): typeof Masked;
|
|
31583
|
+
// export function maskedClass(mask: typeof Masked): typeof Masked;
|
|
31584
|
+
// export function maskedClass(mask: typeof MaskedDate): typeof MaskedDate;
|
|
31585
|
+
// export function maskedClass(mask: typeof MaskedNumber): typeof MaskedNumber;
|
|
31586
|
+
// export function maskedClass(mask: typeof MaskedEnum): typeof MaskedEnum;
|
|
31587
|
+
// export function maskedClass(mask: typeof MaskedRange): typeof MaskedRange;
|
|
31588
|
+
// export function maskedClass(mask: typeof MaskedRegExp): typeof MaskedRegExp;
|
|
31589
|
+
// export function maskedClass(mask: typeof MaskedFunction): typeof MaskedFunction;
|
|
31590
|
+
// export function maskedClass(mask: typeof MaskedPattern): typeof MaskedPattern;
|
|
31591
|
+
// export function maskedClass(mask: typeof MaskedDynamic): typeof MaskedDynamic;
|
|
31592
|
+
// export function maskedClass<Mask extends typeof Masked> (mask: Mask): Mask;
|
|
31593
|
+
// export function maskedClass(mask: RegExp): typeof MaskedRegExp;
|
|
31594
|
+
// export function maskedClass(mask: (value: string, ...args: any[]) => boolean): typeof MaskedFunction;
|
|
31595
|
+
/** Get Masked class by mask type */
|
|
31596
|
+
function maskedClass(mask) /* TODO */{
|
|
31597
|
+
if (mask == null) throw new Error('mask property should be defined');
|
|
31598
|
+
if (mask instanceof RegExp) return IMask.MaskedRegExp;
|
|
31599
|
+
if (isString(mask)) return IMask.MaskedPattern;
|
|
31600
|
+
if (mask === Date) return IMask.MaskedDate;
|
|
31601
|
+
if (mask === Number) return IMask.MaskedNumber;
|
|
31602
|
+
if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic;
|
|
31603
|
+
if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask;
|
|
31604
|
+
if (IMask.Masked && mask instanceof IMask.Masked) return mask.constructor;
|
|
31605
|
+
if (mask instanceof Function) return IMask.MaskedFunction;
|
|
31606
|
+
console.warn('Mask not found for mask', mask); // eslint-disable-line no-console
|
|
31607
|
+
return IMask.Masked;
|
|
31608
|
+
}
|
|
31609
|
+
function normalizeOpts(opts) {
|
|
31610
|
+
if (!opts) throw new Error('Options in not defined');
|
|
31611
|
+
if (IMask.Masked) {
|
|
31612
|
+
if (opts.prototype instanceof IMask.Masked) return {
|
|
31613
|
+
mask: opts
|
|
31687
31614
|
};
|
|
31615
|
+
|
|
31616
|
+
/*
|
|
31617
|
+
handle cases like:
|
|
31618
|
+
1) opts = Masked
|
|
31619
|
+
2) opts = { mask: Masked, ...instanceOpts }
|
|
31620
|
+
*/
|
|
31621
|
+
const {
|
|
31622
|
+
mask = undefined,
|
|
31623
|
+
...instanceOpts
|
|
31624
|
+
} = opts instanceof IMask.Masked ? {
|
|
31625
|
+
mask: opts
|
|
31626
|
+
} : isObject(opts) && opts.mask instanceof IMask.Masked ? opts : {};
|
|
31627
|
+
if (mask) {
|
|
31628
|
+
const _mask = mask.mask;
|
|
31629
|
+
return {
|
|
31630
|
+
...pick(mask, (_, k) => !k.startsWith('_')),
|
|
31631
|
+
mask: mask.constructor,
|
|
31632
|
+
_mask,
|
|
31633
|
+
...instanceOpts
|
|
31634
|
+
};
|
|
31635
|
+
}
|
|
31688
31636
|
}
|
|
31689
|
-
|
|
31690
|
-
|
|
31691
|
-
}
|
|
31692
|
-
|
|
31693
|
-
|
|
31694
|
-
|
|
31695
|
-
this.value = this.value.slice(1);
|
|
31696
|
-
return shiftChar;
|
|
31697
|
-
}
|
|
31698
|
-
shift() {
|
|
31699
|
-
if (!this.value.length) return '';
|
|
31700
|
-
const shiftChar = this.value[this.value.length - 1];
|
|
31701
|
-
this.value = this.value.slice(0, -1);
|
|
31702
|
-
return shiftChar;
|
|
31703
|
-
}
|
|
31637
|
+
if (!isObject(opts)) return {
|
|
31638
|
+
mask: opts
|
|
31639
|
+
};
|
|
31640
|
+
return {
|
|
31641
|
+
...opts
|
|
31642
|
+
};
|
|
31704
31643
|
}
|
|
31705
31644
|
|
|
31706
|
-
|
|
31707
|
-
|
|
31708
|
-
|
|
31709
|
-
|
|
31710
|
-
|
|
31711
|
-
|
|
31712
|
-
|
|
31713
|
-
function
|
|
31714
|
-
|
|
31715
|
-
|
|
31716
|
-
|
|
31645
|
+
// TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
|
|
31646
|
+
|
|
31647
|
+
// From masked
|
|
31648
|
+
// export default function createMask<Opts extends Masked, ReturnMasked=Opts> (opts: Opts): ReturnMasked;
|
|
31649
|
+
// // From masked class
|
|
31650
|
+
// export default function createMask<Opts extends MaskedOptions<typeof Masked>, ReturnMasked extends Masked=InstanceType<Opts['mask']>> (opts: Opts): ReturnMasked;
|
|
31651
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedDate>, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31652
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedNumber>, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31653
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedEnum>, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31654
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedRange>, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31655
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedRegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31656
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedFunction>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31657
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedPattern>, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31658
|
+
// export default function createMask<Opts extends MaskedOptions<typeof MaskedDynamic>, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31659
|
+
// // From mask opts
|
|
31660
|
+
// export default function createMask<Opts extends MaskedOptions<Masked>, ReturnMasked=Opts extends MaskedOptions<infer M> ? M : never> (opts: Opts): ReturnMasked;
|
|
31661
|
+
// export default function createMask<Opts extends MaskedNumberOptions, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31662
|
+
// export default function createMask<Opts extends MaskedDateFactoryOptions, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31663
|
+
// export default function createMask<Opts extends MaskedEnumOptions, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31664
|
+
// export default function createMask<Opts extends MaskedRangeOptions, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31665
|
+
// export default function createMask<Opts extends MaskedPatternOptions, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31666
|
+
// export default function createMask<Opts extends MaskedDynamicOptions, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31667
|
+
// export default function createMask<Opts extends MaskedOptions<RegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31668
|
+
// export default function createMask<Opts extends MaskedOptions<Function>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
|
|
31669
|
+
|
|
31670
|
+
/** Creates new {@link Masked} depending on mask type */
|
|
31671
|
+
function createMask(opts) {
|
|
31672
|
+
if (IMask.Masked && opts instanceof IMask.Masked) return opts;
|
|
31673
|
+
const nOpts = normalizeOpts(opts);
|
|
31674
|
+
const MaskedClass = maskedClass(nOpts.mask);
|
|
31675
|
+
if (!MaskedClass) throw new Error('Masked class is not found for provided mask, appropriate module needs to be imported manually before creating mask.');
|
|
31676
|
+
if (nOpts.mask === MaskedClass) delete nOpts.mask;
|
|
31677
|
+
if (nOpts._mask) {
|
|
31678
|
+
nOpts.mask = nOpts._mask;
|
|
31679
|
+
delete nOpts._mask;
|
|
31680
|
+
}
|
|
31681
|
+
return new MaskedClass(nOpts);
|
|
31717
31682
|
}
|
|
31683
|
+
IMask.createMask = createMask;
|
|
31718
31684
|
|
|
31719
|
-
/**
|
|
31685
|
+
/** Generic element API to use with mask */
|
|
31686
|
+
class MaskElement {
|
|
31687
|
+
/** */
|
|
31720
31688
|
|
|
31721
|
-
/**
|
|
31689
|
+
/** */
|
|
31722
31690
|
|
|
31723
|
-
/**
|
|
31691
|
+
/** */
|
|
31724
31692
|
|
|
31725
|
-
/**
|
|
31726
|
-
|
|
31727
|
-
|
|
31693
|
+
/** Safely returns selection start */
|
|
31694
|
+
get selectionStart() {
|
|
31695
|
+
let start;
|
|
31696
|
+
try {
|
|
31697
|
+
start = this._unsafeSelectionStart;
|
|
31698
|
+
} catch {}
|
|
31699
|
+
return start != null ? start : this.value.length;
|
|
31700
|
+
}
|
|
31728
31701
|
|
|
31729
|
-
/**
|
|
31702
|
+
/** Safely returns selection end */
|
|
31703
|
+
get selectionEnd() {
|
|
31704
|
+
let end;
|
|
31705
|
+
try {
|
|
31706
|
+
end = this._unsafeSelectionEnd;
|
|
31707
|
+
} catch {}
|
|
31708
|
+
return end != null ? end : this.value.length;
|
|
31709
|
+
}
|
|
31730
31710
|
|
|
31731
|
-
/**
|
|
31732
|
-
|
|
31733
|
-
|
|
31734
|
-
|
|
31735
|
-
|
|
31736
|
-
|
|
31737
|
-
|
|
31711
|
+
/** Safely sets element selection */
|
|
31712
|
+
select(start, end) {
|
|
31713
|
+
if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
|
|
31714
|
+
try {
|
|
31715
|
+
this._unsafeSelect(start, end);
|
|
31716
|
+
} catch {}
|
|
31717
|
+
}
|
|
31718
|
+
|
|
31719
|
+
/** */
|
|
31720
|
+
get isActive() {
|
|
31721
|
+
return false;
|
|
31722
|
+
}
|
|
31738
31723
|
/** */
|
|
31724
|
+
|
|
31739
31725
|
/** */
|
|
31726
|
+
|
|
31740
31727
|
/** */
|
|
31741
|
-
|
|
31742
|
-
|
|
31743
|
-
|
|
31744
|
-
|
|
31728
|
+
}
|
|
31729
|
+
|
|
31730
|
+
IMask.MaskElement = MaskElement;
|
|
31731
|
+
|
|
31732
|
+
/** Bridge between HTMLElement and {@link Masked} */
|
|
31733
|
+
class HTMLMaskElement extends MaskElement {
|
|
31734
|
+
/** HTMLElement to use mask on */
|
|
31735
|
+
|
|
31736
|
+
constructor(input) {
|
|
31737
|
+
super();
|
|
31738
|
+
this.input = input;
|
|
31739
|
+
this._handlers = {};
|
|
31740
|
+
}
|
|
31741
|
+
get rootElement() {
|
|
31742
|
+
var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
|
|
31743
|
+
return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) == null ? void 0 : _this$input$getRootNo2.call(_this$input)) != null ? _this$input$getRootNo : document;
|
|
31745
31744
|
}
|
|
31746
31745
|
|
|
31747
|
-
/**
|
|
31748
|
-
|
|
31749
|
-
|
|
31750
|
-
|
|
31751
|
-
this.
|
|
31746
|
+
/**
|
|
31747
|
+
Is element in focus
|
|
31748
|
+
*/
|
|
31749
|
+
get isActive() {
|
|
31750
|
+
return this.input === this.rootElement.activeElement;
|
|
31752
31751
|
}
|
|
31753
31752
|
|
|
31754
31753
|
/**
|
|
31755
|
-
|
|
31756
|
-
@protected
|
|
31754
|
+
Binds HTMLElement events to mask internal events
|
|
31757
31755
|
*/
|
|
31758
|
-
|
|
31759
|
-
Object.
|
|
31756
|
+
bindEvents(handlers) {
|
|
31757
|
+
Object.keys(handlers).forEach(event => this._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]));
|
|
31760
31758
|
}
|
|
31761
31759
|
|
|
31762
|
-
/**
|
|
31763
|
-
|
|
31764
|
-
|
|
31765
|
-
|
|
31766
|
-
|
|
31760
|
+
/**
|
|
31761
|
+
Unbinds HTMLElement events to mask internal events
|
|
31762
|
+
*/
|
|
31763
|
+
unbindEvents() {
|
|
31764
|
+
Object.keys(this._handlers).forEach(event => this._toggleEventHandler(event));
|
|
31767
31765
|
}
|
|
31768
|
-
|
|
31769
|
-
this.
|
|
31766
|
+
_toggleEventHandler(event, handler) {
|
|
31767
|
+
if (this._handlers[event]) {
|
|
31768
|
+
this.input.removeEventListener(event, this._handlers[event]);
|
|
31769
|
+
delete this._handlers[event];
|
|
31770
|
+
}
|
|
31771
|
+
if (handler) {
|
|
31772
|
+
this.input.addEventListener(event, handler);
|
|
31773
|
+
this._handlers[event] = handler;
|
|
31774
|
+
}
|
|
31775
|
+
}
|
|
31776
|
+
}
|
|
31777
|
+
/** Mapping between HTMLElement events and mask internal events */
|
|
31778
|
+
HTMLMaskElement.EVENTS_MAP = {
|
|
31779
|
+
selectionChange: 'keydown',
|
|
31780
|
+
input: 'input',
|
|
31781
|
+
drop: 'drop',
|
|
31782
|
+
click: 'click',
|
|
31783
|
+
focus: 'focus',
|
|
31784
|
+
commit: 'blur'
|
|
31785
|
+
};
|
|
31786
|
+
IMask.HTMLMaskElement = HTMLMaskElement;
|
|
31787
|
+
|
|
31788
|
+
/** Bridge between InputElement and {@link Masked} */
|
|
31789
|
+
class HTMLInputMaskElement extends HTMLMaskElement {
|
|
31790
|
+
/** InputElement to use mask on */
|
|
31791
|
+
|
|
31792
|
+
constructor(input) {
|
|
31793
|
+
super(input);
|
|
31794
|
+
this.input = input;
|
|
31795
|
+
this._handlers = {};
|
|
31770
31796
|
}
|
|
31771
31797
|
|
|
31772
|
-
/**
|
|
31773
|
-
|
|
31774
|
-
this.
|
|
31798
|
+
/** Returns InputElement selection start */
|
|
31799
|
+
get _unsafeSelectionStart() {
|
|
31800
|
+
return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
|
|
31775
31801
|
}
|
|
31776
31802
|
|
|
31777
|
-
/** */
|
|
31803
|
+
/** Returns InputElement selection end */
|
|
31804
|
+
get _unsafeSelectionEnd() {
|
|
31805
|
+
return this.input.selectionEnd;
|
|
31806
|
+
}
|
|
31807
|
+
|
|
31808
|
+
/** Sets InputElement selection */
|
|
31809
|
+
_unsafeSelect(start, end) {
|
|
31810
|
+
this.input.setSelectionRange(start, end);
|
|
31811
|
+
}
|
|
31778
31812
|
get value() {
|
|
31779
|
-
return this.
|
|
31813
|
+
return this.input.value;
|
|
31780
31814
|
}
|
|
31781
31815
|
set value(value) {
|
|
31782
|
-
this.
|
|
31816
|
+
this.input.value = value;
|
|
31783
31817
|
}
|
|
31818
|
+
}
|
|
31819
|
+
IMask.HTMLMaskElement = HTMLMaskElement;
|
|
31784
31820
|
|
|
31785
|
-
|
|
31786
|
-
|
|
31787
|
-
|
|
31788
|
-
this.
|
|
31789
|
-
|
|
31790
|
-
|
|
31791
|
-
|
|
31792
|
-
|
|
31821
|
+
class HTMLContenteditableMaskElement extends HTMLMaskElement {
|
|
31822
|
+
/** Returns HTMLElement selection start */
|
|
31823
|
+
get _unsafeSelectionStart() {
|
|
31824
|
+
const root = this.rootElement;
|
|
31825
|
+
const selection = root.getSelection && root.getSelection();
|
|
31826
|
+
const anchorOffset = selection && selection.anchorOffset;
|
|
31827
|
+
const focusOffset = selection && selection.focusOffset;
|
|
31828
|
+
if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
|
|
31829
|
+
return anchorOffset;
|
|
31830
|
+
}
|
|
31831
|
+
return focusOffset;
|
|
31793
31832
|
}
|
|
31794
31833
|
|
|
31795
|
-
/** */
|
|
31796
|
-
get
|
|
31797
|
-
|
|
31834
|
+
/** Returns HTMLElement selection end */
|
|
31835
|
+
get _unsafeSelectionEnd() {
|
|
31836
|
+
const root = this.rootElement;
|
|
31837
|
+
const selection = root.getSelection && root.getSelection();
|
|
31838
|
+
const anchorOffset = selection && selection.anchorOffset;
|
|
31839
|
+
const focusOffset = selection && selection.focusOffset;
|
|
31840
|
+
if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
|
|
31841
|
+
return anchorOffset;
|
|
31842
|
+
}
|
|
31843
|
+
return focusOffset;
|
|
31798
31844
|
}
|
|
31799
|
-
|
|
31800
|
-
|
|
31801
|
-
|
|
31802
|
-
this.
|
|
31845
|
+
|
|
31846
|
+
/** Sets HTMLElement selection */
|
|
31847
|
+
_unsafeSelect(start, end) {
|
|
31848
|
+
if (!this.rootElement.createRange) return;
|
|
31849
|
+
const range = this.rootElement.createRange();
|
|
31850
|
+
range.setStart(this.input.firstChild || this.input, start);
|
|
31851
|
+
range.setEnd(this.input.lastChild || this.input, end);
|
|
31852
|
+
const root = this.rootElement;
|
|
31853
|
+
const selection = root.getSelection && root.getSelection();
|
|
31854
|
+
if (selection) {
|
|
31855
|
+
selection.removeAllRanges();
|
|
31856
|
+
selection.addRange(range);
|
|
31857
|
+
}
|
|
31803
31858
|
}
|
|
31804
31859
|
|
|
31805
|
-
/** */
|
|
31806
|
-
get
|
|
31807
|
-
return this.
|
|
31860
|
+
/** HTMLElement value */
|
|
31861
|
+
get value() {
|
|
31862
|
+
return this.input.textContent || '';
|
|
31808
31863
|
}
|
|
31809
|
-
set
|
|
31810
|
-
this.
|
|
31864
|
+
set value(value) {
|
|
31865
|
+
this.input.textContent = value;
|
|
31811
31866
|
}
|
|
31867
|
+
}
|
|
31868
|
+
IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
|
|
31812
31869
|
|
|
31813
|
-
|
|
31814
|
-
|
|
31815
|
-
|
|
31816
|
-
|
|
31870
|
+
/** Listens to element events and controls changes between element and {@link Masked} */
|
|
31871
|
+
class InputMask {
|
|
31872
|
+
/**
|
|
31873
|
+
View element
|
|
31874
|
+
*/
|
|
31875
|
+
|
|
31876
|
+
/** Internal {@link Masked} model */
|
|
31877
|
+
|
|
31878
|
+
constructor(el, opts) {
|
|
31879
|
+
this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLInputMaskElement(el);
|
|
31880
|
+
this.masked = createMask(opts);
|
|
31881
|
+
this._listeners = {};
|
|
31882
|
+
this._value = '';
|
|
31883
|
+
this._unmaskedValue = '';
|
|
31884
|
+
this._saveSelection = this._saveSelection.bind(this);
|
|
31885
|
+
this._onInput = this._onInput.bind(this);
|
|
31886
|
+
this._onChange = this._onChange.bind(this);
|
|
31887
|
+
this._onDrop = this._onDrop.bind(this);
|
|
31888
|
+
this._onFocus = this._onFocus.bind(this);
|
|
31889
|
+
this._onClick = this._onClick.bind(this);
|
|
31890
|
+
this.alignCursor = this.alignCursor.bind(this);
|
|
31891
|
+
this.alignCursorFriendly = this.alignCursorFriendly.bind(this);
|
|
31892
|
+
this._bindEvents();
|
|
31893
|
+
|
|
31894
|
+
// refresh
|
|
31895
|
+
this.updateValue();
|
|
31896
|
+
this._onChange();
|
|
31897
|
+
}
|
|
31898
|
+
maskEquals(mask) {
|
|
31899
|
+
var _this$masked;
|
|
31900
|
+
return mask == null || ((_this$masked = this.masked) == null ? void 0 : _this$masked.maskEquals(mask));
|
|
31901
|
+
}
|
|
31902
|
+
|
|
31903
|
+
/** Masked */
|
|
31904
|
+
get mask() {
|
|
31905
|
+
return this.masked.mask;
|
|
31906
|
+
}
|
|
31907
|
+
set mask(mask) {
|
|
31908
|
+
if (this.maskEquals(mask)) return;
|
|
31909
|
+
if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
|
|
31910
|
+
// TODO "any" no idea
|
|
31911
|
+
this.masked.updateOptions({
|
|
31912
|
+
mask
|
|
31913
|
+
});
|
|
31914
|
+
return;
|
|
31915
|
+
}
|
|
31916
|
+
const masked = mask instanceof IMask.Masked ? mask : createMask({
|
|
31917
|
+
mask
|
|
31817
31918
|
});
|
|
31919
|
+
masked.unmaskedValue = this.masked.unmaskedValue;
|
|
31920
|
+
this.masked = masked;
|
|
31818
31921
|
}
|
|
31819
|
-
|
|
31820
|
-
|
|
31821
|
-
|
|
31822
|
-
|
|
31823
|
-
}, '');
|
|
31824
|
-
this.doCommit();
|
|
31922
|
+
|
|
31923
|
+
/** Raw value */
|
|
31924
|
+
get value() {
|
|
31925
|
+
return this._value;
|
|
31825
31926
|
}
|
|
31826
|
-
|
|
31827
|
-
|
|
31927
|
+
set value(str) {
|
|
31928
|
+
if (this.value === str) return;
|
|
31929
|
+
this.masked.value = str;
|
|
31930
|
+
this.updateControl();
|
|
31931
|
+
this.alignCursor();
|
|
31828
31932
|
}
|
|
31829
31933
|
|
|
31830
|
-
/** */
|
|
31831
|
-
get
|
|
31832
|
-
return
|
|
31934
|
+
/** Unmasked value */
|
|
31935
|
+
get unmaskedValue() {
|
|
31936
|
+
return this._unmaskedValue;
|
|
31937
|
+
}
|
|
31938
|
+
set unmaskedValue(str) {
|
|
31939
|
+
if (this.unmaskedValue === str) return;
|
|
31940
|
+
this.masked.unmaskedValue = str;
|
|
31941
|
+
this.updateControl();
|
|
31942
|
+
this.alignCursor();
|
|
31833
31943
|
}
|
|
31834
31944
|
|
|
31835
|
-
/** */
|
|
31836
|
-
get
|
|
31837
|
-
return this.
|
|
31945
|
+
/** Typed unmasked value */
|
|
31946
|
+
get typedValue() {
|
|
31947
|
+
return this.masked.typedValue;
|
|
31948
|
+
}
|
|
31949
|
+
set typedValue(val) {
|
|
31950
|
+
if (this.masked.typedValueEquals(val)) return;
|
|
31951
|
+
this.masked.typedValue = val;
|
|
31952
|
+
this.updateControl();
|
|
31953
|
+
this.alignCursor();
|
|
31838
31954
|
}
|
|
31839
31955
|
|
|
31840
|
-
/**
|
|
31841
|
-
|
|
31842
|
-
return
|
|
31956
|
+
/** Display value */
|
|
31957
|
+
get displayValue() {
|
|
31958
|
+
return this.masked.displayValue;
|
|
31843
31959
|
}
|
|
31844
31960
|
|
|
31845
|
-
/**
|
|
31846
|
-
|
|
31847
|
-
|
|
31848
|
-
|
|
31849
|
-
|
|
31961
|
+
/** Starts listening to element events */
|
|
31962
|
+
_bindEvents() {
|
|
31963
|
+
this.el.bindEvents({
|
|
31964
|
+
selectionChange: this._saveSelection,
|
|
31965
|
+
input: this._onInput,
|
|
31966
|
+
drop: this._onDrop,
|
|
31967
|
+
click: this._onClick,
|
|
31968
|
+
focus: this._onFocus,
|
|
31969
|
+
commit: this._onChange
|
|
31970
|
+
});
|
|
31850
31971
|
}
|
|
31851
31972
|
|
|
31852
|
-
/**
|
|
31853
|
-
|
|
31854
|
-
|
|
31855
|
-
let toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
|
|
31856
|
-
return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos);
|
|
31973
|
+
/** Stops listening to element events */
|
|
31974
|
+
_unbindEvents() {
|
|
31975
|
+
if (this.el) this.el.unbindEvents();
|
|
31857
31976
|
}
|
|
31858
31977
|
|
|
31859
|
-
/**
|
|
31860
|
-
|
|
31861
|
-
|
|
31862
|
-
if (
|
|
31863
|
-
|
|
31978
|
+
/** Fires custom event */
|
|
31979
|
+
_fireEvent(ev, e) {
|
|
31980
|
+
const listeners = this._listeners[ev];
|
|
31981
|
+
if (!listeners) return;
|
|
31982
|
+
listeners.forEach(l => l(e));
|
|
31864
31983
|
}
|
|
31865
31984
|
|
|
31866
|
-
/**
|
|
31867
|
-
|
|
31868
|
-
|
|
31869
|
-
this._value += ch;
|
|
31870
|
-
return new ChangeDetails({
|
|
31871
|
-
inserted: ch,
|
|
31872
|
-
rawInserted: ch
|
|
31873
|
-
});
|
|
31985
|
+
/** Current selection start */
|
|
31986
|
+
get selectionStart() {
|
|
31987
|
+
return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
|
|
31874
31988
|
}
|
|
31875
31989
|
|
|
31876
|
-
/**
|
|
31877
|
-
|
|
31878
|
-
|
|
31879
|
-
|
|
31880
|
-
|
|
31881
|
-
|
|
31882
|
-
|
|
31883
|
-
|
|
31884
|
-
|
|
31885
|
-
|
|
31990
|
+
/** Current cursor position */
|
|
31991
|
+
get cursorPos() {
|
|
31992
|
+
return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
|
|
31993
|
+
}
|
|
31994
|
+
set cursorPos(pos) {
|
|
31995
|
+
if (!this.el || !this.el.isActive) return;
|
|
31996
|
+
this.el.select(pos, pos);
|
|
31997
|
+
this._saveSelection();
|
|
31998
|
+
}
|
|
31999
|
+
|
|
32000
|
+
/** Stores current selection */
|
|
32001
|
+
_saveSelection( /* ev */
|
|
32002
|
+
) {
|
|
32003
|
+
if (this.displayValue !== this.el.value) {
|
|
32004
|
+
console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console
|
|
32005
|
+
}
|
|
32006
|
+
|
|
32007
|
+
this._selection = {
|
|
32008
|
+
start: this.selectionStart,
|
|
32009
|
+
end: this.cursorPos
|
|
32010
|
+
};
|
|
32011
|
+
}
|
|
32012
|
+
|
|
32013
|
+
/** Syncronizes model value from view */
|
|
32014
|
+
updateValue() {
|
|
32015
|
+
this.masked.value = this.el.value;
|
|
32016
|
+
this._value = this.masked.value;
|
|
32017
|
+
}
|
|
32018
|
+
|
|
32019
|
+
/** Syncronizes view from model value, fires change events */
|
|
32020
|
+
updateControl() {
|
|
32021
|
+
const newUnmaskedValue = this.masked.unmaskedValue;
|
|
32022
|
+
const newValue = this.masked.value;
|
|
32023
|
+
const newDisplayValue = this.displayValue;
|
|
32024
|
+
const isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue;
|
|
32025
|
+
this._unmaskedValue = newUnmaskedValue;
|
|
32026
|
+
this._value = newValue;
|
|
32027
|
+
if (this.el.value !== newDisplayValue) this.el.value = newDisplayValue;
|
|
32028
|
+
if (isChanged) this._fireChangeEvents();
|
|
32029
|
+
}
|
|
32030
|
+
|
|
32031
|
+
/** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
|
|
32032
|
+
updateOptions(opts) {
|
|
32033
|
+
const {
|
|
32034
|
+
mask,
|
|
32035
|
+
...restOpts
|
|
32036
|
+
} = opts;
|
|
32037
|
+
const updateMask = !this.maskEquals(mask);
|
|
32038
|
+
const updateOpts = !objectIncludes(this.masked, restOpts);
|
|
32039
|
+
if (updateMask) this.mask = mask;
|
|
32040
|
+
if (updateOpts) this.masked.updateOptions(restOpts); // TODO
|
|
32041
|
+
|
|
32042
|
+
if (updateMask || updateOpts) this.updateControl();
|
|
32043
|
+
}
|
|
32044
|
+
|
|
32045
|
+
/** Updates cursor */
|
|
32046
|
+
updateCursor(cursorPos) {
|
|
32047
|
+
if (cursorPos == null) return;
|
|
32048
|
+
this.cursorPos = cursorPos;
|
|
32049
|
+
|
|
32050
|
+
// also queue change cursor for mobile browsers
|
|
32051
|
+
this._delayUpdateCursor(cursorPos);
|
|
32052
|
+
}
|
|
32053
|
+
|
|
32054
|
+
/** Delays cursor update to support mobile browsers */
|
|
32055
|
+
_delayUpdateCursor(cursorPos) {
|
|
32056
|
+
this._abortUpdateCursor();
|
|
32057
|
+
this._changingCursorPos = cursorPos;
|
|
32058
|
+
this._cursorChanging = setTimeout(() => {
|
|
32059
|
+
if (!this.el) return; // if was destroyed
|
|
32060
|
+
this.cursorPos = this._changingCursorPos;
|
|
32061
|
+
this._abortUpdateCursor();
|
|
32062
|
+
}, 10);
|
|
32063
|
+
}
|
|
32064
|
+
|
|
32065
|
+
/** Fires custom events */
|
|
32066
|
+
_fireChangeEvents() {
|
|
32067
|
+
this._fireEvent('accept', this._inputEvent);
|
|
32068
|
+
if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
|
|
32069
|
+
}
|
|
32070
|
+
|
|
32071
|
+
/** Aborts delayed cursor update */
|
|
32072
|
+
_abortUpdateCursor() {
|
|
32073
|
+
if (this._cursorChanging) {
|
|
32074
|
+
clearTimeout(this._cursorChanging);
|
|
32075
|
+
delete this._cursorChanging;
|
|
32076
|
+
}
|
|
32077
|
+
}
|
|
32078
|
+
|
|
32079
|
+
/** Aligns cursor to nearest available position */
|
|
32080
|
+
alignCursor() {
|
|
32081
|
+
this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
|
|
32082
|
+
}
|
|
32083
|
+
|
|
32084
|
+
/** Aligns cursor only if selection is empty */
|
|
32085
|
+
alignCursorFriendly() {
|
|
32086
|
+
if (this.selectionStart !== this.cursorPos) return; // skip if range is selected
|
|
32087
|
+
this.alignCursor();
|
|
32088
|
+
}
|
|
32089
|
+
|
|
32090
|
+
/** Adds listener on custom event */
|
|
32091
|
+
on(ev, handler) {
|
|
32092
|
+
if (!this._listeners[ev]) this._listeners[ev] = [];
|
|
32093
|
+
this._listeners[ev].push(handler);
|
|
32094
|
+
return this;
|
|
32095
|
+
}
|
|
32096
|
+
|
|
32097
|
+
/** Removes custom event listener */
|
|
32098
|
+
off(ev, handler) {
|
|
32099
|
+
if (!this._listeners[ev]) return this;
|
|
32100
|
+
if (!handler) {
|
|
32101
|
+
delete this._listeners[ev];
|
|
32102
|
+
return this;
|
|
32103
|
+
}
|
|
32104
|
+
const hIndex = this._listeners[ev].indexOf(handler);
|
|
32105
|
+
if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1);
|
|
32106
|
+
return this;
|
|
32107
|
+
}
|
|
32108
|
+
|
|
32109
|
+
/** Handles view input event */
|
|
32110
|
+
_onInput(e) {
|
|
32111
|
+
this._inputEvent = e;
|
|
32112
|
+
this._abortUpdateCursor();
|
|
32113
|
+
|
|
32114
|
+
// fix strange IE behavior
|
|
32115
|
+
if (!this._selection) return this.updateValue();
|
|
32116
|
+
const details = new ActionDetails({
|
|
32117
|
+
// new state
|
|
32118
|
+
value: this.el.value,
|
|
32119
|
+
cursorPos: this.cursorPos,
|
|
32120
|
+
// old state
|
|
32121
|
+
oldValue: this.displayValue,
|
|
32122
|
+
oldSelection: this._selection
|
|
32123
|
+
});
|
|
32124
|
+
const oldRawValue = this.masked.rawInputValue;
|
|
32125
|
+
const offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
|
|
32126
|
+
input: true,
|
|
32127
|
+
raw: true
|
|
32128
|
+
}).offset;
|
|
32129
|
+
|
|
32130
|
+
// force align in remove direction only if no input chars were removed
|
|
32131
|
+
// otherwise we still need to align with NONE (to get out from fixed symbols for instance)
|
|
32132
|
+
const removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
|
|
32133
|
+
let cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
|
|
32134
|
+
if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);
|
|
32135
|
+
this.updateControl();
|
|
32136
|
+
this.updateCursor(cursorPos);
|
|
32137
|
+
delete this._inputEvent;
|
|
32138
|
+
}
|
|
32139
|
+
|
|
32140
|
+
/** Handles view change event and commits model value */
|
|
32141
|
+
_onChange() {
|
|
32142
|
+
if (this.displayValue !== this.el.value) {
|
|
32143
|
+
this.updateValue();
|
|
32144
|
+
}
|
|
32145
|
+
this.masked.doCommit();
|
|
32146
|
+
this.updateControl();
|
|
32147
|
+
this._saveSelection();
|
|
32148
|
+
}
|
|
32149
|
+
|
|
32150
|
+
/** Handles view drop event, prevents by default */
|
|
32151
|
+
_onDrop(ev) {
|
|
32152
|
+
ev.preventDefault();
|
|
32153
|
+
ev.stopPropagation();
|
|
32154
|
+
}
|
|
32155
|
+
|
|
32156
|
+
/** Restore last selection on focus */
|
|
32157
|
+
_onFocus(ev) {
|
|
32158
|
+
this.alignCursorFriendly();
|
|
32159
|
+
}
|
|
32160
|
+
|
|
32161
|
+
/** Restore last selection on focus */
|
|
32162
|
+
_onClick(ev) {
|
|
32163
|
+
this.alignCursorFriendly();
|
|
32164
|
+
}
|
|
32165
|
+
|
|
32166
|
+
/** Unbind view events and removes element reference */
|
|
32167
|
+
destroy() {
|
|
32168
|
+
this._unbindEvents();
|
|
32169
|
+
this._listeners.length = 0;
|
|
32170
|
+
delete this.el;
|
|
32171
|
+
}
|
|
32172
|
+
}
|
|
32173
|
+
IMask.InputMask = InputMask;
|
|
32174
|
+
|
|
32175
|
+
/** Provides details of changing model value */
|
|
32176
|
+
class ChangeDetails {
|
|
32177
|
+
/** Inserted symbols */
|
|
32178
|
+
|
|
32179
|
+
/** Can skip chars */
|
|
32180
|
+
|
|
32181
|
+
/** Additional offset if any changes occurred before tail */
|
|
32182
|
+
|
|
32183
|
+
/** Raw inserted is used by dynamic mask */
|
|
32184
|
+
|
|
32185
|
+
static normalize(prep) {
|
|
32186
|
+
return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
|
|
32187
|
+
}
|
|
32188
|
+
constructor(details) {
|
|
32189
|
+
Object.assign(this, {
|
|
32190
|
+
inserted: '',
|
|
32191
|
+
rawInserted: '',
|
|
32192
|
+
skip: false,
|
|
32193
|
+
tailShift: 0
|
|
32194
|
+
}, details);
|
|
32195
|
+
}
|
|
32196
|
+
|
|
32197
|
+
/** Aggregate changes */
|
|
32198
|
+
aggregate(details) {
|
|
32199
|
+
this.rawInserted += details.rawInserted;
|
|
32200
|
+
this.skip = this.skip || details.skip;
|
|
32201
|
+
this.inserted += details.inserted;
|
|
32202
|
+
this.tailShift += details.tailShift;
|
|
32203
|
+
return this;
|
|
32204
|
+
}
|
|
32205
|
+
|
|
32206
|
+
/** Total offset considering all changes */
|
|
32207
|
+
get offset() {
|
|
32208
|
+
return this.tailShift + this.inserted.length;
|
|
32209
|
+
}
|
|
32210
|
+
}
|
|
32211
|
+
IMask.ChangeDetails = ChangeDetails;
|
|
32212
|
+
|
|
32213
|
+
/** Provides details of continuous extracted tail */
|
|
32214
|
+
class ContinuousTailDetails {
|
|
32215
|
+
/** Tail value as string */
|
|
32216
|
+
|
|
32217
|
+
/** Tail start position */
|
|
32218
|
+
|
|
32219
|
+
/** Start position */
|
|
32220
|
+
|
|
32221
|
+
constructor(value, from, stop) {
|
|
32222
|
+
if (value === void 0) {
|
|
32223
|
+
value = '';
|
|
32224
|
+
}
|
|
32225
|
+
if (from === void 0) {
|
|
32226
|
+
from = 0;
|
|
32227
|
+
}
|
|
32228
|
+
this.value = value;
|
|
32229
|
+
this.from = from;
|
|
32230
|
+
this.stop = stop;
|
|
32231
|
+
}
|
|
32232
|
+
toString() {
|
|
32233
|
+
return this.value;
|
|
32234
|
+
}
|
|
32235
|
+
extend(tail) {
|
|
32236
|
+
this.value += String(tail);
|
|
32237
|
+
}
|
|
32238
|
+
appendTo(masked) {
|
|
32239
|
+
return masked.append(this.toString(), {
|
|
32240
|
+
tail: true
|
|
32241
|
+
}).aggregate(masked._appendPlaceholder());
|
|
32242
|
+
}
|
|
32243
|
+
get state() {
|
|
32244
|
+
return {
|
|
32245
|
+
value: this.value,
|
|
32246
|
+
from: this.from,
|
|
32247
|
+
stop: this.stop
|
|
32248
|
+
};
|
|
32249
|
+
}
|
|
32250
|
+
set state(state) {
|
|
32251
|
+
Object.assign(this, state);
|
|
32252
|
+
}
|
|
32253
|
+
unshift(beforePos) {
|
|
32254
|
+
if (!this.value.length || beforePos != null && this.from >= beforePos) return '';
|
|
32255
|
+
const shiftChar = this.value[0];
|
|
32256
|
+
this.value = this.value.slice(1);
|
|
32257
|
+
return shiftChar;
|
|
32258
|
+
}
|
|
32259
|
+
shift() {
|
|
32260
|
+
if (!this.value.length) return '';
|
|
32261
|
+
const shiftChar = this.value[this.value.length - 1];
|
|
32262
|
+
this.value = this.value.slice(0, -1);
|
|
32263
|
+
return shiftChar;
|
|
32264
|
+
}
|
|
32265
|
+
}
|
|
32266
|
+
|
|
32267
|
+
/** Append flags */
|
|
32268
|
+
|
|
32269
|
+
/** Extract flags */
|
|
32270
|
+
|
|
32271
|
+
// see https://github.com/microsoft/TypeScript/issues/6223
|
|
32272
|
+
|
|
32273
|
+
/** Provides common masking stuff */
|
|
32274
|
+
class Masked {
|
|
32275
|
+
/** */
|
|
32276
|
+
|
|
32277
|
+
/** */
|
|
32278
|
+
|
|
32279
|
+
/** Transforms value before mask processing */
|
|
32280
|
+
|
|
32281
|
+
/** Transforms each char before mask processing */
|
|
32282
|
+
|
|
32283
|
+
/** Validates if value is acceptable */
|
|
32284
|
+
|
|
32285
|
+
/** Does additional processing at the end of editing */
|
|
32286
|
+
|
|
32287
|
+
/** Format typed value to string */
|
|
32288
|
+
|
|
32289
|
+
/** Parse string to get typed value */
|
|
32290
|
+
|
|
32291
|
+
/** Enable characters overwriting */
|
|
32292
|
+
|
|
32293
|
+
/** */
|
|
32294
|
+
|
|
32295
|
+
/** */
|
|
32296
|
+
|
|
32297
|
+
/** */
|
|
32298
|
+
|
|
32299
|
+
constructor(opts) {
|
|
32300
|
+
this._value = '';
|
|
32301
|
+
this._update({
|
|
32302
|
+
...Masked.DEFAULTS,
|
|
32303
|
+
...opts
|
|
32304
|
+
});
|
|
32305
|
+
this._initialized = true;
|
|
32306
|
+
}
|
|
32307
|
+
|
|
32308
|
+
/** Sets and applies new options */
|
|
32309
|
+
updateOptions(opts) {
|
|
32310
|
+
if (!Object.keys(opts).length) return;
|
|
32311
|
+
this.withValueRefresh(this._update.bind(this, opts));
|
|
32312
|
+
}
|
|
32313
|
+
|
|
32314
|
+
/** Sets new options */
|
|
32315
|
+
_update(opts) {
|
|
32316
|
+
Object.assign(this, opts);
|
|
32317
|
+
}
|
|
32318
|
+
|
|
32319
|
+
/** Mask state */
|
|
32320
|
+
get state() {
|
|
32321
|
+
return {
|
|
32322
|
+
_value: this.value,
|
|
32323
|
+
_rawInputValue: this.rawInputValue
|
|
32324
|
+
};
|
|
32325
|
+
}
|
|
32326
|
+
set state(state) {
|
|
32327
|
+
this._value = state._value;
|
|
32328
|
+
}
|
|
32329
|
+
|
|
32330
|
+
/** Resets value */
|
|
32331
|
+
reset() {
|
|
32332
|
+
this._value = '';
|
|
32333
|
+
}
|
|
32334
|
+
get value() {
|
|
32335
|
+
return this._value;
|
|
32336
|
+
}
|
|
32337
|
+
set value(value) {
|
|
32338
|
+
this.resolve(value, {
|
|
32339
|
+
input: true
|
|
32340
|
+
});
|
|
32341
|
+
}
|
|
32342
|
+
|
|
32343
|
+
/** Resolve new value */
|
|
32344
|
+
resolve(value, flags) {
|
|
32345
|
+
if (flags === void 0) {
|
|
32346
|
+
flags = {
|
|
32347
|
+
input: true
|
|
32348
|
+
};
|
|
32349
|
+
}
|
|
32350
|
+
this.reset();
|
|
32351
|
+
this.append(value, flags, '');
|
|
32352
|
+
this.doCommit();
|
|
32353
|
+
}
|
|
32354
|
+
get unmaskedValue() {
|
|
32355
|
+
return this.value;
|
|
32356
|
+
}
|
|
32357
|
+
set unmaskedValue(value) {
|
|
32358
|
+
this.resolve(value, {});
|
|
32359
|
+
}
|
|
32360
|
+
get typedValue() {
|
|
32361
|
+
return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
|
|
32362
|
+
}
|
|
32363
|
+
set typedValue(value) {
|
|
32364
|
+
if (this.format) {
|
|
32365
|
+
this.value = this.format(value, this);
|
|
32366
|
+
} else {
|
|
32367
|
+
this.unmaskedValue = String(value);
|
|
32368
|
+
}
|
|
32369
|
+
}
|
|
32370
|
+
|
|
32371
|
+
/** Value that includes raw user input */
|
|
32372
|
+
get rawInputValue() {
|
|
32373
|
+
return this.extractInput(0, this.value.length, {
|
|
32374
|
+
raw: true
|
|
32375
|
+
});
|
|
32376
|
+
}
|
|
32377
|
+
set rawInputValue(value) {
|
|
32378
|
+
this.resolve(value, {
|
|
32379
|
+
raw: true
|
|
32380
|
+
});
|
|
32381
|
+
}
|
|
32382
|
+
get displayValue() {
|
|
32383
|
+
return this.value;
|
|
32384
|
+
}
|
|
32385
|
+
get isComplete() {
|
|
32386
|
+
return true;
|
|
32387
|
+
}
|
|
32388
|
+
get isFilled() {
|
|
32389
|
+
return this.isComplete;
|
|
32390
|
+
}
|
|
32391
|
+
|
|
32392
|
+
/** Finds nearest input position in direction */
|
|
32393
|
+
nearestInputPos(cursorPos, direction) {
|
|
32394
|
+
return cursorPos;
|
|
32395
|
+
}
|
|
32396
|
+
totalInputPositions(fromPos, toPos) {
|
|
32397
|
+
if (fromPos === void 0) {
|
|
32398
|
+
fromPos = 0;
|
|
32399
|
+
}
|
|
32400
|
+
if (toPos === void 0) {
|
|
32401
|
+
toPos = this.value.length;
|
|
32402
|
+
}
|
|
32403
|
+
return Math.min(this.value.length, toPos - fromPos);
|
|
32404
|
+
}
|
|
32405
|
+
|
|
32406
|
+
/** Extracts value in range considering flags */
|
|
32407
|
+
extractInput(fromPos, toPos, flags) {
|
|
32408
|
+
if (fromPos === void 0) {
|
|
32409
|
+
fromPos = 0;
|
|
32410
|
+
}
|
|
32411
|
+
if (toPos === void 0) {
|
|
32412
|
+
toPos = this.value.length;
|
|
32413
|
+
}
|
|
32414
|
+
return this.value.slice(fromPos, toPos);
|
|
32415
|
+
}
|
|
32416
|
+
|
|
32417
|
+
/** Extracts tail in range */
|
|
32418
|
+
extractTail(fromPos, toPos) {
|
|
32419
|
+
if (fromPos === void 0) {
|
|
32420
|
+
fromPos = 0;
|
|
32421
|
+
}
|
|
32422
|
+
if (toPos === void 0) {
|
|
32423
|
+
toPos = this.value.length;
|
|
32424
|
+
}
|
|
32425
|
+
return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos);
|
|
32426
|
+
}
|
|
32427
|
+
|
|
32428
|
+
/** Appends tail */
|
|
32429
|
+
appendTail(tail) {
|
|
32430
|
+
if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
|
|
32431
|
+
return tail.appendTo(this);
|
|
32432
|
+
}
|
|
32433
|
+
|
|
32434
|
+
/** Appends char */
|
|
32435
|
+
_appendCharRaw(ch, flags) {
|
|
32436
|
+
if (!ch) return new ChangeDetails();
|
|
32437
|
+
this._value += ch;
|
|
32438
|
+
return new ChangeDetails({
|
|
32439
|
+
inserted: ch,
|
|
32440
|
+
rawInserted: ch
|
|
32441
|
+
});
|
|
32442
|
+
}
|
|
32443
|
+
|
|
32444
|
+
/** Appends char */
|
|
32445
|
+
_appendChar(ch, flags, checkTail) {
|
|
32446
|
+
if (flags === void 0) {
|
|
32447
|
+
flags = {};
|
|
32448
|
+
}
|
|
32449
|
+
const consistentState = this.state;
|
|
32450
|
+
let details;
|
|
32451
|
+
[ch, details] = this.doPrepareChar(ch, flags);
|
|
32452
|
+
details = details.aggregate(this._appendCharRaw(ch, flags));
|
|
32453
|
+
if (details.inserted) {
|
|
32454
|
+
let consistentTail;
|
|
31886
32455
|
let appended = this.doValidate(flags) !== false;
|
|
31887
32456
|
if (appended && checkTail != null) {
|
|
31888
32457
|
// validation ok, check tail
|
|
@@ -31917,28 +32486,31 @@ class Masked {
|
|
|
31917
32486
|
return details;
|
|
31918
32487
|
}
|
|
31919
32488
|
|
|
31920
|
-
/** Appends optional placeholder at end */
|
|
32489
|
+
/** Appends optional placeholder at the end */
|
|
31921
32490
|
_appendPlaceholder() {
|
|
31922
32491
|
return new ChangeDetails();
|
|
31923
32492
|
}
|
|
31924
32493
|
|
|
31925
|
-
/** Appends optional eager placeholder at end */
|
|
32494
|
+
/** Appends optional eager placeholder at the end */
|
|
31926
32495
|
_appendEager() {
|
|
31927
32496
|
return new ChangeDetails();
|
|
31928
32497
|
}
|
|
31929
32498
|
|
|
31930
32499
|
/** Appends symbols considering flags */
|
|
31931
|
-
// $FlowFixMe no ideas
|
|
31932
32500
|
append(str, flags, tail) {
|
|
31933
32501
|
if (!isString(str)) throw new Error('value should be string');
|
|
31934
|
-
const details = new ChangeDetails();
|
|
31935
32502
|
const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
|
|
31936
|
-
if (flags
|
|
32503
|
+
if (flags != null && flags.tail) flags._beforeTailState = this.state;
|
|
32504
|
+
let details;
|
|
32505
|
+
[str, details] = this.doPrepare(str, flags);
|
|
31937
32506
|
for (let ci = 0; ci < str.length; ++ci) {
|
|
31938
32507
|
const d = this._appendChar(str[ci], flags, checkTail);
|
|
31939
32508
|
if (!d.rawInserted && !this.doSkipInvalid(str[ci], flags, checkTail)) break;
|
|
31940
32509
|
details.aggregate(d);
|
|
31941
32510
|
}
|
|
32511
|
+
if ((this.eager === true || this.eager === 'append') && flags != null && flags.input && str) {
|
|
32512
|
+
details.aggregate(this._appendEager());
|
|
32513
|
+
}
|
|
31942
32514
|
|
|
31943
32515
|
// append tail but aggregate only tailShift
|
|
31944
32516
|
if (checkTail != null) {
|
|
@@ -31948,39 +32520,36 @@ class Masked {
|
|
|
31948
32520
|
// this._resetBeforeTailState();
|
|
31949
32521
|
}
|
|
31950
32522
|
|
|
31951
|
-
if ((this.eager === true || this.eager === 'append') && flags !== null && flags !== void 0 && flags.input && str) {
|
|
31952
|
-
details.aggregate(this._appendEager());
|
|
31953
|
-
}
|
|
31954
32523
|
return details;
|
|
31955
32524
|
}
|
|
31956
|
-
|
|
31957
|
-
|
|
31958
|
-
|
|
31959
|
-
|
|
31960
|
-
|
|
32525
|
+
remove(fromPos, toPos) {
|
|
32526
|
+
if (fromPos === void 0) {
|
|
32527
|
+
fromPos = 0;
|
|
32528
|
+
}
|
|
32529
|
+
if (toPos === void 0) {
|
|
32530
|
+
toPos = this.value.length;
|
|
32531
|
+
}
|
|
31961
32532
|
this._value = this.value.slice(0, fromPos) + this.value.slice(toPos);
|
|
31962
32533
|
return new ChangeDetails();
|
|
31963
32534
|
}
|
|
31964
32535
|
|
|
31965
32536
|
/** Calls function and reapplies current value */
|
|
31966
32537
|
withValueRefresh(fn) {
|
|
31967
|
-
if (this._refreshing || !this.
|
|
32538
|
+
if (this._refreshing || !this._initialized) return fn();
|
|
31968
32539
|
this._refreshing = true;
|
|
31969
32540
|
const rawInput = this.rawInputValue;
|
|
31970
32541
|
const value = this.value;
|
|
31971
32542
|
const ret = fn();
|
|
31972
32543
|
this.rawInputValue = rawInput;
|
|
31973
|
-
// append lost trailing chars at end
|
|
32544
|
+
// append lost trailing chars at the end
|
|
31974
32545
|
if (this.value && this.value !== value && value.indexOf(this.value) === 0) {
|
|
31975
32546
|
this.append(value.slice(this.value.length), {}, '');
|
|
31976
32547
|
}
|
|
31977
32548
|
delete this._refreshing;
|
|
31978
32549
|
return ret;
|
|
31979
32550
|
}
|
|
31980
|
-
|
|
31981
|
-
/** */
|
|
31982
32551
|
runIsolated(fn) {
|
|
31983
|
-
if (this._isolated || !this.
|
|
32552
|
+
if (this._isolated || !this._initialized) return fn(this);
|
|
31984
32553
|
this._isolated = true;
|
|
31985
32554
|
const state = this.state;
|
|
31986
32555
|
const ret = fn(this);
|
|
@@ -31988,52 +32557,44 @@ class Masked {
|
|
|
31988
32557
|
delete this._isolated;
|
|
31989
32558
|
return ret;
|
|
31990
32559
|
}
|
|
32560
|
+
doSkipInvalid(ch, flags, checkTail) {
|
|
32561
|
+
return Boolean(this.skipInvalid);
|
|
32562
|
+
}
|
|
31991
32563
|
|
|
31992
|
-
/** */
|
|
31993
|
-
|
|
31994
|
-
|
|
32564
|
+
/** Prepares string before mask processing */
|
|
32565
|
+
doPrepare(str, flags) {
|
|
32566
|
+
if (flags === void 0) {
|
|
32567
|
+
flags = {};
|
|
32568
|
+
}
|
|
32569
|
+
return ChangeDetails.normalize(this.prepare ? this.prepare(str, this, flags) : str);
|
|
31995
32570
|
}
|
|
31996
32571
|
|
|
31997
|
-
/**
|
|
31998
|
-
|
|
31999
|
-
|
|
32000
|
-
|
|
32001
|
-
|
|
32002
|
-
|
|
32003
|
-
return this.prepare ? this.prepare(str, this, flags) : str;
|
|
32572
|
+
/** Prepares each char before mask processing */
|
|
32573
|
+
doPrepareChar(str, flags) {
|
|
32574
|
+
if (flags === void 0) {
|
|
32575
|
+
flags = {};
|
|
32576
|
+
}
|
|
32577
|
+
return ChangeDetails.normalize(this.prepareChar ? this.prepareChar(str, this, flags) : str);
|
|
32004
32578
|
}
|
|
32005
32579
|
|
|
32006
|
-
/**
|
|
32007
|
-
Validates if value is acceptable
|
|
32008
|
-
@protected
|
|
32009
|
-
*/
|
|
32580
|
+
/** Validates if value is acceptable */
|
|
32010
32581
|
doValidate(flags) {
|
|
32011
32582
|
return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags));
|
|
32012
32583
|
}
|
|
32013
32584
|
|
|
32014
|
-
/**
|
|
32015
|
-
Does additional processing in the end of editing
|
|
32016
|
-
@protected
|
|
32017
|
-
*/
|
|
32585
|
+
/** Does additional processing at the end of editing */
|
|
32018
32586
|
doCommit() {
|
|
32019
32587
|
if (this.commit) this.commit(this.value, this);
|
|
32020
32588
|
}
|
|
32021
|
-
|
|
32022
|
-
|
|
32023
|
-
|
|
32024
|
-
|
|
32025
|
-
|
|
32026
|
-
|
|
32027
|
-
|
|
32028
|
-
|
|
32029
|
-
|
|
32030
|
-
}
|
|
32031
|
-
|
|
32032
|
-
/** */
|
|
32033
|
-
splice(start, deleteCount, inserted, removeDirection) {
|
|
32034
|
-
let flags = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
32035
|
-
input: true
|
|
32036
|
-
};
|
|
32589
|
+
splice(start, deleteCount, inserted, removeDirection, flags) {
|
|
32590
|
+
if (removeDirection === void 0) {
|
|
32591
|
+
removeDirection = DIRECTION.NONE;
|
|
32592
|
+
}
|
|
32593
|
+
if (flags === void 0) {
|
|
32594
|
+
flags = {
|
|
32595
|
+
input: true
|
|
32596
|
+
};
|
|
32597
|
+
}
|
|
32037
32598
|
const tailPos = start + deleteCount;
|
|
32038
32599
|
const tail = this.extractTail(tailPos);
|
|
32039
32600
|
const eagerRemove = this.eager === true || this.eager === 'remove';
|
|
@@ -32074,348 +32635,34 @@ class Masked {
|
|
|
32074
32635
|
}
|
|
32075
32636
|
typedValueEquals(value) {
|
|
32076
32637
|
const tval = this.typedValue;
|
|
32077
|
-
return value === tval || Masked.EMPTY_VALUES.includes(value) && Masked.EMPTY_VALUES.includes(tval) || this.
|
|
32638
|
+
return value === tval || Masked.EMPTY_VALUES.includes(value) && Masked.EMPTY_VALUES.includes(tval) || (this.format ? this.format(value, this) === this.format(this.typedValue, this) : false);
|
|
32078
32639
|
}
|
|
32079
32640
|
}
|
|
32080
32641
|
Masked.DEFAULTS = {
|
|
32081
|
-
format: String,
|
|
32082
|
-
parse: v => v,
|
|
32083
32642
|
skipInvalid: true
|
|
32084
32643
|
};
|
|
32085
32644
|
Masked.EMPTY_VALUES = [undefined, null, ''];
|
|
32086
32645
|
IMask.Masked = Masked;
|
|
32087
32646
|
|
|
32088
|
-
|
|
32089
|
-
function maskedClass(mask) {
|
|
32090
|
-
if (mask == null) {
|
|
32091
|
-
throw new Error('mask property should be defined');
|
|
32092
|
-
}
|
|
32093
|
-
|
|
32094
|
-
// $FlowFixMe
|
|
32095
|
-
if (mask instanceof RegExp) return IMask.MaskedRegExp;
|
|
32096
|
-
// $FlowFixMe
|
|
32097
|
-
if (isString(mask)) return IMask.MaskedPattern;
|
|
32098
|
-
// $FlowFixMe
|
|
32099
|
-
if (mask instanceof Date || mask === Date) return IMask.MaskedDate;
|
|
32100
|
-
// $FlowFixMe
|
|
32101
|
-
if (mask instanceof Number || typeof mask === 'number' || mask === Number) return IMask.MaskedNumber;
|
|
32102
|
-
// $FlowFixMe
|
|
32103
|
-
if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic;
|
|
32104
|
-
// $FlowFixMe
|
|
32105
|
-
if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask;
|
|
32106
|
-
// $FlowFixMe
|
|
32107
|
-
if (mask instanceof IMask.Masked) return mask.constructor;
|
|
32108
|
-
// $FlowFixMe
|
|
32109
|
-
if (mask instanceof Function) return IMask.MaskedFunction;
|
|
32110
|
-
console.warn('Mask not found for mask', mask); // eslint-disable-line no-console
|
|
32111
|
-
// $FlowFixMe
|
|
32112
|
-
return IMask.Masked;
|
|
32113
|
-
}
|
|
32114
|
-
|
|
32115
|
-
/** Creates new {@link Masked} depending on mask type */
|
|
32116
|
-
function createMask(opts) {
|
|
32117
|
-
// $FlowFixMe
|
|
32118
|
-
if (IMask.Masked && opts instanceof IMask.Masked) return opts;
|
|
32119
|
-
opts = Object.assign({}, opts);
|
|
32120
|
-
const mask = opts.mask;
|
|
32121
|
-
|
|
32122
|
-
// $FlowFixMe
|
|
32123
|
-
if (IMask.Masked && mask instanceof IMask.Masked) return mask;
|
|
32124
|
-
const MaskedClass = maskedClass(mask);
|
|
32125
|
-
if (!MaskedClass) throw new Error('Masked class is not found for provided mask, appropriate module needs to be import manually before creating mask.');
|
|
32126
|
-
return new MaskedClass(opts);
|
|
32127
|
-
}
|
|
32128
|
-
IMask.createMask = createMask;
|
|
32129
|
-
|
|
32130
|
-
const _excluded$4 = ["parent", "isOptional", "placeholderChar", "displayChar", "lazy", "eager"];
|
|
32131
|
-
|
|
32132
|
-
/** */
|
|
32133
|
-
|
|
32134
|
-
const DEFAULT_INPUT_DEFINITIONS = {
|
|
32135
|
-
'0': /\d/,
|
|
32136
|
-
'a': /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
|
|
32137
|
-
// http://stackoverflow.com/a/22075070
|
|
32138
|
-
'*': /./
|
|
32139
|
-
};
|
|
32140
|
-
|
|
32141
|
-
/** */
|
|
32142
|
-
class PatternInputDefinition {
|
|
32143
|
-
/** */
|
|
32144
|
-
|
|
32145
|
-
/** */
|
|
32146
|
-
|
|
32147
|
-
/** */
|
|
32148
|
-
|
|
32149
|
-
/** */
|
|
32150
|
-
|
|
32151
|
-
/** */
|
|
32152
|
-
|
|
32153
|
-
/** */
|
|
32154
|
-
|
|
32155
|
-
/** */
|
|
32156
|
-
|
|
32157
|
-
/** */
|
|
32158
|
-
|
|
32159
|
-
constructor(opts) {
|
|
32160
|
-
const {
|
|
32161
|
-
parent,
|
|
32162
|
-
isOptional,
|
|
32163
|
-
placeholderChar,
|
|
32164
|
-
displayChar,
|
|
32165
|
-
lazy,
|
|
32166
|
-
eager
|
|
32167
|
-
} = opts,
|
|
32168
|
-
maskOpts = _objectWithoutPropertiesLoose(opts, _excluded$4);
|
|
32169
|
-
this.masked = createMask(maskOpts);
|
|
32170
|
-
Object.assign(this, {
|
|
32171
|
-
parent,
|
|
32172
|
-
isOptional,
|
|
32173
|
-
placeholderChar,
|
|
32174
|
-
displayChar,
|
|
32175
|
-
lazy,
|
|
32176
|
-
eager
|
|
32177
|
-
});
|
|
32178
|
-
}
|
|
32179
|
-
reset() {
|
|
32180
|
-
this.isFilled = false;
|
|
32181
|
-
this.masked.reset();
|
|
32182
|
-
}
|
|
32183
|
-
remove() {
|
|
32184
|
-
let fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
32185
|
-
let toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
|
|
32186
|
-
if (fromPos === 0 && toPos >= 1) {
|
|
32187
|
-
this.isFilled = false;
|
|
32188
|
-
return this.masked.remove(fromPos, toPos);
|
|
32189
|
-
}
|
|
32190
|
-
return new ChangeDetails();
|
|
32191
|
-
}
|
|
32192
|
-
get value() {
|
|
32193
|
-
return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
|
|
32194
|
-
}
|
|
32195
|
-
get unmaskedValue() {
|
|
32196
|
-
return this.masked.unmaskedValue;
|
|
32197
|
-
}
|
|
32198
|
-
get displayValue() {
|
|
32199
|
-
return this.masked.value && this.displayChar || this.value;
|
|
32200
|
-
}
|
|
32201
|
-
get isComplete() {
|
|
32202
|
-
return Boolean(this.masked.value) || this.isOptional;
|
|
32203
|
-
}
|
|
32204
|
-
_appendChar(ch) {
|
|
32205
|
-
let flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32206
|
-
if (this.isFilled) return new ChangeDetails();
|
|
32207
|
-
const state = this.masked.state;
|
|
32208
|
-
// simulate input
|
|
32209
|
-
const details = this.masked._appendChar(ch, flags);
|
|
32210
|
-
if (details.inserted && this.doValidate(flags) === false) {
|
|
32211
|
-
details.inserted = details.rawInserted = '';
|
|
32212
|
-
this.masked.state = state;
|
|
32213
|
-
}
|
|
32214
|
-
if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) {
|
|
32215
|
-
details.inserted = this.placeholderChar;
|
|
32216
|
-
}
|
|
32217
|
-
details.skip = !details.inserted && !this.isOptional;
|
|
32218
|
-
this.isFilled = Boolean(details.inserted);
|
|
32219
|
-
return details;
|
|
32220
|
-
}
|
|
32221
|
-
append() {
|
|
32222
|
-
// TODO probably should be done via _appendChar
|
|
32223
|
-
return this.masked.append(...arguments);
|
|
32224
|
-
}
|
|
32225
|
-
_appendPlaceholder() {
|
|
32226
|
-
const details = new ChangeDetails();
|
|
32227
|
-
if (this.isFilled || this.isOptional) return details;
|
|
32228
|
-
this.isFilled = true;
|
|
32229
|
-
details.inserted = this.placeholderChar;
|
|
32230
|
-
return details;
|
|
32231
|
-
}
|
|
32232
|
-
_appendEager() {
|
|
32233
|
-
return new ChangeDetails();
|
|
32234
|
-
}
|
|
32235
|
-
extractTail() {
|
|
32236
|
-
return this.masked.extractTail(...arguments);
|
|
32237
|
-
}
|
|
32238
|
-
appendTail() {
|
|
32239
|
-
return this.masked.appendTail(...arguments);
|
|
32240
|
-
}
|
|
32241
|
-
extractInput() {
|
|
32242
|
-
let fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
32243
|
-
let toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
|
|
32244
|
-
let flags = arguments.length > 2 ? arguments[2] : undefined;
|
|
32245
|
-
return this.masked.extractInput(fromPos, toPos, flags);
|
|
32246
|
-
}
|
|
32247
|
-
nearestInputPos(cursorPos) {
|
|
32248
|
-
let direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
|
|
32249
|
-
const minPos = 0;
|
|
32250
|
-
const maxPos = this.value.length;
|
|
32251
|
-
const boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
|
|
32252
|
-
switch (direction) {
|
|
32253
|
-
case DIRECTION.LEFT:
|
|
32254
|
-
case DIRECTION.FORCE_LEFT:
|
|
32255
|
-
return this.isComplete ? boundPos : minPos;
|
|
32256
|
-
case DIRECTION.RIGHT:
|
|
32257
|
-
case DIRECTION.FORCE_RIGHT:
|
|
32258
|
-
return this.isComplete ? boundPos : maxPos;
|
|
32259
|
-
case DIRECTION.NONE:
|
|
32260
|
-
default:
|
|
32261
|
-
return boundPos;
|
|
32262
|
-
}
|
|
32263
|
-
}
|
|
32264
|
-
doValidate() {
|
|
32265
|
-
return this.masked.doValidate(...arguments) && (!this.parent || this.parent.doValidate(...arguments));
|
|
32266
|
-
}
|
|
32267
|
-
doCommit() {
|
|
32268
|
-
this.masked.doCommit();
|
|
32269
|
-
}
|
|
32270
|
-
get state() {
|
|
32271
|
-
return {
|
|
32272
|
-
masked: this.masked.state,
|
|
32273
|
-
isFilled: this.isFilled
|
|
32274
|
-
};
|
|
32275
|
-
}
|
|
32276
|
-
set state(state) {
|
|
32277
|
-
this.masked.state = state.masked;
|
|
32278
|
-
this.isFilled = state.isFilled;
|
|
32279
|
-
}
|
|
32280
|
-
}
|
|
32281
|
-
|
|
32282
|
-
/** */
|
|
32283
|
-
|
|
32284
|
-
class PatternFixedDefinition {
|
|
32285
|
-
/** */
|
|
32286
|
-
|
|
32287
|
-
/** */
|
|
32288
|
-
|
|
32289
|
-
/** */
|
|
32290
|
-
|
|
32291
|
-
/** */
|
|
32292
|
-
|
|
32293
|
-
/** */
|
|
32294
|
-
|
|
32647
|
+
class ChunksTailDetails {
|
|
32295
32648
|
/** */
|
|
32296
32649
|
|
|
32297
|
-
constructor(
|
|
32298
|
-
|
|
32299
|
-
|
|
32300
|
-
this.isFixed = true;
|
|
32301
|
-
}
|
|
32302
|
-
get value() {
|
|
32303
|
-
return this._value;
|
|
32304
|
-
}
|
|
32305
|
-
get unmaskedValue() {
|
|
32306
|
-
return this.isUnmasking ? this.value : '';
|
|
32307
|
-
}
|
|
32308
|
-
get displayValue() {
|
|
32309
|
-
return this.value;
|
|
32310
|
-
}
|
|
32311
|
-
reset() {
|
|
32312
|
-
this._isRawInput = false;
|
|
32313
|
-
this._value = '';
|
|
32314
|
-
}
|
|
32315
|
-
remove() {
|
|
32316
|
-
let fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
32317
|
-
let toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length;
|
|
32318
|
-
this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
|
|
32319
|
-
if (!this._value) this._isRawInput = false;
|
|
32320
|
-
return new ChangeDetails();
|
|
32321
|
-
}
|
|
32322
|
-
nearestInputPos(cursorPos) {
|
|
32323
|
-
let direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
|
|
32324
|
-
const minPos = 0;
|
|
32325
|
-
const maxPos = this._value.length;
|
|
32326
|
-
switch (direction) {
|
|
32327
|
-
case DIRECTION.LEFT:
|
|
32328
|
-
case DIRECTION.FORCE_LEFT:
|
|
32329
|
-
return minPos;
|
|
32330
|
-
case DIRECTION.NONE:
|
|
32331
|
-
case DIRECTION.RIGHT:
|
|
32332
|
-
case DIRECTION.FORCE_RIGHT:
|
|
32333
|
-
default:
|
|
32334
|
-
return maxPos;
|
|
32650
|
+
constructor(chunks, from) {
|
|
32651
|
+
if (chunks === void 0) {
|
|
32652
|
+
chunks = [];
|
|
32335
32653
|
}
|
|
32336
|
-
|
|
32337
|
-
|
|
32338
|
-
let fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
32339
|
-
let toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length;
|
|
32340
|
-
let flags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
32341
|
-
return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
|
|
32342
|
-
}
|
|
32343
|
-
get isComplete() {
|
|
32344
|
-
return true;
|
|
32345
|
-
}
|
|
32346
|
-
get isFilled() {
|
|
32347
|
-
return Boolean(this._value);
|
|
32348
|
-
}
|
|
32349
|
-
_appendChar(ch) {
|
|
32350
|
-
let flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32351
|
-
const details = new ChangeDetails();
|
|
32352
|
-
if (this._value) return details;
|
|
32353
|
-
const appendEager = this.eager === true || this.eager === 'append';
|
|
32354
|
-
const appended = this.char === ch;
|
|
32355
|
-
const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
|
|
32356
|
-
if (isResolved) details.rawInserted = this.char;
|
|
32357
|
-
this._value = details.inserted = this.char;
|
|
32358
|
-
this._isRawInput = isResolved && (flags.raw || flags.input);
|
|
32359
|
-
return details;
|
|
32360
|
-
}
|
|
32361
|
-
_appendEager() {
|
|
32362
|
-
return this._appendChar(this.char, {
|
|
32363
|
-
tail: true
|
|
32364
|
-
});
|
|
32365
|
-
}
|
|
32366
|
-
_appendPlaceholder() {
|
|
32367
|
-
const details = new ChangeDetails();
|
|
32368
|
-
if (this._value) return details;
|
|
32369
|
-
this._value = details.inserted = this.char;
|
|
32370
|
-
return details;
|
|
32371
|
-
}
|
|
32372
|
-
extractTail() {
|
|
32373
|
-
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
|
|
32374
|
-
return new ContinuousTailDetails('');
|
|
32375
|
-
}
|
|
32376
|
-
|
|
32377
|
-
// $FlowFixMe no ideas
|
|
32378
|
-
appendTail(tail) {
|
|
32379
|
-
if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
|
|
32380
|
-
return tail.appendTo(this);
|
|
32381
|
-
}
|
|
32382
|
-
append(str, flags, tail) {
|
|
32383
|
-
const details = this._appendChar(str[0], flags);
|
|
32384
|
-
if (tail != null) {
|
|
32385
|
-
details.tailShift += this.appendTail(tail).tailShift;
|
|
32654
|
+
if (from === void 0) {
|
|
32655
|
+
from = 0;
|
|
32386
32656
|
}
|
|
32387
|
-
return details;
|
|
32388
|
-
}
|
|
32389
|
-
doCommit() {}
|
|
32390
|
-
get state() {
|
|
32391
|
-
return {
|
|
32392
|
-
_value: this._value,
|
|
32393
|
-
_isRawInput: this._isRawInput
|
|
32394
|
-
};
|
|
32395
|
-
}
|
|
32396
|
-
set state(state) {
|
|
32397
|
-
Object.assign(this, state);
|
|
32398
|
-
}
|
|
32399
|
-
}
|
|
32400
|
-
|
|
32401
|
-
const _excluded$3 = ["chunks"];
|
|
32402
|
-
class ChunksTailDetails {
|
|
32403
|
-
/** */
|
|
32404
|
-
|
|
32405
|
-
constructor() {
|
|
32406
|
-
let chunks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
32407
|
-
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
32408
32657
|
this.chunks = chunks;
|
|
32409
32658
|
this.from = from;
|
|
32410
32659
|
}
|
|
32411
32660
|
toString() {
|
|
32412
32661
|
return this.chunks.map(String).join('');
|
|
32413
32662
|
}
|
|
32414
|
-
|
|
32415
|
-
// $FlowFixMe no ideas
|
|
32416
32663
|
extend(tailChunk) {
|
|
32417
32664
|
if (!String(tailChunk)) return;
|
|
32418
|
-
|
|
32665
|
+
tailChunk = isString(tailChunk) ? new ContinuousTailDetails(String(tailChunk)) : tailChunk;
|
|
32419
32666
|
const lastChunk = this.chunks[this.chunks.length - 1];
|
|
32420
32667
|
const extendLast = lastChunk && (
|
|
32421
32668
|
// if stops are same or tail has no stop
|
|
@@ -32436,7 +32683,7 @@ class ChunksTailDetails {
|
|
|
32436
32683
|
// unwrap floating chunks to parent, keeping `from` pos
|
|
32437
32684
|
let firstTailChunk;
|
|
32438
32685
|
while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) {
|
|
32439
|
-
firstTailChunk = tailChunk.chunks.shift();
|
|
32686
|
+
firstTailChunk = tailChunk.chunks.shift(); // not possible to be `undefined` because length was checked above
|
|
32440
32687
|
firstTailChunk.from += tailChunk.from;
|
|
32441
32688
|
this.extend(firstTailChunk);
|
|
32442
32689
|
}
|
|
@@ -32451,7 +32698,6 @@ class ChunksTailDetails {
|
|
|
32451
32698
|
}
|
|
32452
32699
|
}
|
|
32453
32700
|
appendTo(masked) {
|
|
32454
|
-
// $FlowFixMe
|
|
32455
32701
|
if (!(masked instanceof IMask.MaskedPattern)) {
|
|
32456
32702
|
const tail = new ContinuousTailDetails(this.toString());
|
|
32457
32703
|
return tail.appendTo(masked);
|
|
@@ -32468,7 +32714,8 @@ class ChunksTailDetails {
|
|
|
32468
32714
|
if (chunk instanceof ChunksTailDetails ||
|
|
32469
32715
|
// for continuous block also check if stop is exist
|
|
32470
32716
|
masked._stops.indexOf(stop) >= 0) {
|
|
32471
|
-
|
|
32717
|
+
const phDetails = masked._appendPlaceholder(stop);
|
|
32718
|
+
details.aggregate(phDetails);
|
|
32472
32719
|
}
|
|
32473
32720
|
chunkBlock = chunk instanceof ChunksTailDetails && masked._blocks[stop];
|
|
32474
32721
|
}
|
|
@@ -32501,13 +32748,12 @@ class ChunksTailDetails {
|
|
|
32501
32748
|
}
|
|
32502
32749
|
set state(state) {
|
|
32503
32750
|
const {
|
|
32504
|
-
|
|
32505
|
-
|
|
32506
|
-
|
|
32751
|
+
chunks,
|
|
32752
|
+
...props
|
|
32753
|
+
} = state;
|
|
32507
32754
|
Object.assign(this, props);
|
|
32508
32755
|
this.chunks = chunks.map(cstate => {
|
|
32509
32756
|
const chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
|
|
32510
|
-
// $FlowFixMe already checked above
|
|
32511
32757
|
chunk.state = cstate;
|
|
32512
32758
|
return chunk;
|
|
32513
32759
|
});
|
|
@@ -32553,158 +32799,476 @@ class ChunksTailDetails {
|
|
|
32553
32799
|
}
|
|
32554
32800
|
}
|
|
32555
32801
|
|
|
32556
|
-
class PatternCursor {
|
|
32557
|
-
constructor(masked, pos) {
|
|
32558
|
-
this.masked = masked;
|
|
32559
|
-
this._log = [];
|
|
32802
|
+
class PatternCursor {
|
|
32803
|
+
constructor(masked, pos) {
|
|
32804
|
+
this.masked = masked;
|
|
32805
|
+
this._log = [];
|
|
32806
|
+
const {
|
|
32807
|
+
offset,
|
|
32808
|
+
index
|
|
32809
|
+
} = masked._mapPosToBlock(pos) || (pos < 0 ?
|
|
32810
|
+
// first
|
|
32811
|
+
{
|
|
32812
|
+
index: 0,
|
|
32813
|
+
offset: 0
|
|
32814
|
+
} :
|
|
32815
|
+
// last
|
|
32816
|
+
{
|
|
32817
|
+
index: this.masked._blocks.length,
|
|
32818
|
+
offset: 0
|
|
32819
|
+
});
|
|
32820
|
+
this.offset = offset;
|
|
32821
|
+
this.index = index;
|
|
32822
|
+
this.ok = false;
|
|
32823
|
+
}
|
|
32824
|
+
get block() {
|
|
32825
|
+
return this.masked._blocks[this.index];
|
|
32826
|
+
}
|
|
32827
|
+
get pos() {
|
|
32828
|
+
return this.masked._blockStartPos(this.index) + this.offset;
|
|
32829
|
+
}
|
|
32830
|
+
get state() {
|
|
32831
|
+
return {
|
|
32832
|
+
index: this.index,
|
|
32833
|
+
offset: this.offset,
|
|
32834
|
+
ok: this.ok
|
|
32835
|
+
};
|
|
32836
|
+
}
|
|
32837
|
+
set state(s) {
|
|
32838
|
+
Object.assign(this, s);
|
|
32839
|
+
}
|
|
32840
|
+
pushState() {
|
|
32841
|
+
this._log.push(this.state);
|
|
32842
|
+
}
|
|
32843
|
+
popState() {
|
|
32844
|
+
const s = this._log.pop();
|
|
32845
|
+
if (s) this.state = s;
|
|
32846
|
+
return s;
|
|
32847
|
+
}
|
|
32848
|
+
bindBlock() {
|
|
32849
|
+
if (this.block) return;
|
|
32850
|
+
if (this.index < 0) {
|
|
32851
|
+
this.index = 0;
|
|
32852
|
+
this.offset = 0;
|
|
32853
|
+
}
|
|
32854
|
+
if (this.index >= this.masked._blocks.length) {
|
|
32855
|
+
this.index = this.masked._blocks.length - 1;
|
|
32856
|
+
this.offset = this.block.value.length; // TODO this is stupid type error, `block` depends on index that was changed above
|
|
32857
|
+
}
|
|
32858
|
+
}
|
|
32859
|
+
|
|
32860
|
+
_pushLeft(fn) {
|
|
32861
|
+
this.pushState();
|
|
32862
|
+
for (this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((_this$block = this.block) == null ? void 0 : _this$block.value.length) || 0) {
|
|
32863
|
+
var _this$block;
|
|
32864
|
+
if (fn()) return this.ok = true;
|
|
32865
|
+
}
|
|
32866
|
+
return this.ok = false;
|
|
32867
|
+
}
|
|
32868
|
+
_pushRight(fn) {
|
|
32869
|
+
this.pushState();
|
|
32870
|
+
for (this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0) {
|
|
32871
|
+
if (fn()) return this.ok = true;
|
|
32872
|
+
}
|
|
32873
|
+
return this.ok = false;
|
|
32874
|
+
}
|
|
32875
|
+
pushLeftBeforeFilled() {
|
|
32876
|
+
return this._pushLeft(() => {
|
|
32877
|
+
if (this.block.isFixed || !this.block.value) return;
|
|
32878
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_LEFT);
|
|
32879
|
+
if (this.offset !== 0) return true;
|
|
32880
|
+
});
|
|
32881
|
+
}
|
|
32882
|
+
pushLeftBeforeInput() {
|
|
32883
|
+
// cases:
|
|
32884
|
+
// filled input: 00|
|
|
32885
|
+
// optional empty input: 00[]|
|
|
32886
|
+
// nested block: XX<[]>|
|
|
32887
|
+
return this._pushLeft(() => {
|
|
32888
|
+
if (this.block.isFixed) return;
|
|
32889
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
|
|
32890
|
+
return true;
|
|
32891
|
+
});
|
|
32892
|
+
}
|
|
32893
|
+
pushLeftBeforeRequired() {
|
|
32894
|
+
return this._pushLeft(() => {
|
|
32895
|
+
if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
|
|
32896
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
|
|
32897
|
+
return true;
|
|
32898
|
+
});
|
|
32899
|
+
}
|
|
32900
|
+
pushRightBeforeFilled() {
|
|
32901
|
+
return this._pushRight(() => {
|
|
32902
|
+
if (this.block.isFixed || !this.block.value) return;
|
|
32903
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_RIGHT);
|
|
32904
|
+
if (this.offset !== this.block.value.length) return true;
|
|
32905
|
+
});
|
|
32906
|
+
}
|
|
32907
|
+
pushRightBeforeInput() {
|
|
32908
|
+
return this._pushRight(() => {
|
|
32909
|
+
if (this.block.isFixed) return;
|
|
32910
|
+
|
|
32911
|
+
// const o = this.offset;
|
|
32912
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
|
|
32913
|
+
// HACK cases like (STILL DOES NOT WORK FOR NESTED)
|
|
32914
|
+
// aa|X
|
|
32915
|
+
// aa<X|[]>X_ - this will not work
|
|
32916
|
+
// if (o && o === this.offset && this.block instanceof PatternInputDefinition) continue;
|
|
32917
|
+
return true;
|
|
32918
|
+
});
|
|
32919
|
+
}
|
|
32920
|
+
pushRightBeforeRequired() {
|
|
32921
|
+
return this._pushRight(() => {
|
|
32922
|
+
if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
|
|
32923
|
+
|
|
32924
|
+
// TODO check |[*]XX_
|
|
32925
|
+
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
|
|
32926
|
+
return true;
|
|
32927
|
+
});
|
|
32928
|
+
}
|
|
32929
|
+
}
|
|
32930
|
+
|
|
32931
|
+
class PatternFixedDefinition {
|
|
32932
|
+
/** */
|
|
32933
|
+
|
|
32934
|
+
/** */
|
|
32935
|
+
|
|
32936
|
+
/** */
|
|
32937
|
+
|
|
32938
|
+
/** */
|
|
32939
|
+
|
|
32940
|
+
/** */
|
|
32941
|
+
|
|
32942
|
+
/** */
|
|
32943
|
+
|
|
32944
|
+
constructor(opts) {
|
|
32945
|
+
Object.assign(this, opts);
|
|
32946
|
+
this._value = '';
|
|
32947
|
+
this.isFixed = true;
|
|
32948
|
+
}
|
|
32949
|
+
get value() {
|
|
32950
|
+
return this._value;
|
|
32951
|
+
}
|
|
32952
|
+
get unmaskedValue() {
|
|
32953
|
+
return this.isUnmasking ? this.value : '';
|
|
32954
|
+
}
|
|
32955
|
+
get rawInputValue() {
|
|
32956
|
+
return this._isRawInput ? this.value : '';
|
|
32957
|
+
}
|
|
32958
|
+
get displayValue() {
|
|
32959
|
+
return this.value;
|
|
32960
|
+
}
|
|
32961
|
+
reset() {
|
|
32962
|
+
this._isRawInput = false;
|
|
32963
|
+
this._value = '';
|
|
32964
|
+
}
|
|
32965
|
+
remove(fromPos, toPos) {
|
|
32966
|
+
if (fromPos === void 0) {
|
|
32967
|
+
fromPos = 0;
|
|
32968
|
+
}
|
|
32969
|
+
if (toPos === void 0) {
|
|
32970
|
+
toPos = this._value.length;
|
|
32971
|
+
}
|
|
32972
|
+
this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
|
|
32973
|
+
if (!this._value) this._isRawInput = false;
|
|
32974
|
+
return new ChangeDetails();
|
|
32975
|
+
}
|
|
32976
|
+
nearestInputPos(cursorPos, direction) {
|
|
32977
|
+
if (direction === void 0) {
|
|
32978
|
+
direction = DIRECTION.NONE;
|
|
32979
|
+
}
|
|
32980
|
+
const minPos = 0;
|
|
32981
|
+
const maxPos = this._value.length;
|
|
32982
|
+
switch (direction) {
|
|
32983
|
+
case DIRECTION.LEFT:
|
|
32984
|
+
case DIRECTION.FORCE_LEFT:
|
|
32985
|
+
return minPos;
|
|
32986
|
+
case DIRECTION.NONE:
|
|
32987
|
+
case DIRECTION.RIGHT:
|
|
32988
|
+
case DIRECTION.FORCE_RIGHT:
|
|
32989
|
+
default:
|
|
32990
|
+
return maxPos;
|
|
32991
|
+
}
|
|
32992
|
+
}
|
|
32993
|
+
totalInputPositions(fromPos, toPos) {
|
|
32994
|
+
if (fromPos === void 0) {
|
|
32995
|
+
fromPos = 0;
|
|
32996
|
+
}
|
|
32997
|
+
if (toPos === void 0) {
|
|
32998
|
+
toPos = this._value.length;
|
|
32999
|
+
}
|
|
33000
|
+
return this._isRawInput ? toPos - fromPos : 0;
|
|
33001
|
+
}
|
|
33002
|
+
extractInput(fromPos, toPos, flags) {
|
|
33003
|
+
if (fromPos === void 0) {
|
|
33004
|
+
fromPos = 0;
|
|
33005
|
+
}
|
|
33006
|
+
if (toPos === void 0) {
|
|
33007
|
+
toPos = this._value.length;
|
|
33008
|
+
}
|
|
33009
|
+
if (flags === void 0) {
|
|
33010
|
+
flags = {};
|
|
33011
|
+
}
|
|
33012
|
+
return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
|
|
33013
|
+
}
|
|
33014
|
+
get isComplete() {
|
|
33015
|
+
return true;
|
|
33016
|
+
}
|
|
33017
|
+
get isFilled() {
|
|
33018
|
+
return Boolean(this._value);
|
|
33019
|
+
}
|
|
33020
|
+
_appendChar(ch, flags) {
|
|
33021
|
+
if (flags === void 0) {
|
|
33022
|
+
flags = {};
|
|
33023
|
+
}
|
|
33024
|
+
const details = new ChangeDetails();
|
|
33025
|
+
if (this.isFilled) return details;
|
|
33026
|
+
const appendEager = this.eager === true || this.eager === 'append';
|
|
33027
|
+
const appended = this.char === ch;
|
|
33028
|
+
const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
|
|
33029
|
+
if (isResolved) details.rawInserted = this.char;
|
|
33030
|
+
this._value = details.inserted = this.char;
|
|
33031
|
+
this._isRawInput = isResolved && (flags.raw || flags.input);
|
|
33032
|
+
return details;
|
|
33033
|
+
}
|
|
33034
|
+
_appendEager() {
|
|
33035
|
+
return this._appendChar(this.char, {
|
|
33036
|
+
tail: true
|
|
33037
|
+
});
|
|
33038
|
+
}
|
|
33039
|
+
_appendPlaceholder() {
|
|
33040
|
+
const details = new ChangeDetails();
|
|
33041
|
+
if (this.isFilled) return details;
|
|
33042
|
+
this._value = details.inserted = this.char;
|
|
33043
|
+
return details;
|
|
33044
|
+
}
|
|
33045
|
+
extractTail() {
|
|
33046
|
+
return new ContinuousTailDetails('');
|
|
33047
|
+
}
|
|
33048
|
+
appendTail(tail) {
|
|
33049
|
+
if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
|
|
33050
|
+
return tail.appendTo(this);
|
|
33051
|
+
}
|
|
33052
|
+
append(str, flags, tail) {
|
|
33053
|
+
const details = this._appendChar(str[0], flags);
|
|
33054
|
+
if (tail != null) {
|
|
33055
|
+
details.tailShift += this.appendTail(tail).tailShift;
|
|
33056
|
+
}
|
|
33057
|
+
return details;
|
|
33058
|
+
}
|
|
33059
|
+
doCommit() {}
|
|
33060
|
+
get state() {
|
|
33061
|
+
return {
|
|
33062
|
+
_value: this._value,
|
|
33063
|
+
_rawInputValue: this.rawInputValue
|
|
33064
|
+
};
|
|
33065
|
+
}
|
|
33066
|
+
set state(state) {
|
|
33067
|
+
this._value = state._value;
|
|
33068
|
+
this._isRawInput = Boolean(state._rawInputValue);
|
|
33069
|
+
}
|
|
33070
|
+
}
|
|
33071
|
+
|
|
33072
|
+
class PatternInputDefinition {
|
|
33073
|
+
/** */
|
|
33074
|
+
|
|
33075
|
+
/** */
|
|
33076
|
+
|
|
33077
|
+
/** */
|
|
33078
|
+
|
|
33079
|
+
/** */
|
|
33080
|
+
|
|
33081
|
+
/** */
|
|
33082
|
+
|
|
33083
|
+
/** */
|
|
33084
|
+
|
|
33085
|
+
/** */
|
|
33086
|
+
|
|
33087
|
+
/** */
|
|
33088
|
+
|
|
33089
|
+
constructor(opts) {
|
|
32560
33090
|
const {
|
|
32561
|
-
|
|
32562
|
-
|
|
32563
|
-
|
|
32564
|
-
|
|
32565
|
-
|
|
32566
|
-
|
|
32567
|
-
|
|
32568
|
-
}
|
|
32569
|
-
|
|
32570
|
-
{
|
|
32571
|
-
|
|
32572
|
-
|
|
33091
|
+
parent,
|
|
33092
|
+
isOptional,
|
|
33093
|
+
placeholderChar,
|
|
33094
|
+
displayChar,
|
|
33095
|
+
lazy,
|
|
33096
|
+
eager,
|
|
33097
|
+
...maskOpts
|
|
33098
|
+
} = opts;
|
|
33099
|
+
this.masked = createMask(maskOpts);
|
|
33100
|
+
Object.assign(this, {
|
|
33101
|
+
parent,
|
|
33102
|
+
isOptional,
|
|
33103
|
+
placeholderChar,
|
|
33104
|
+
displayChar,
|
|
33105
|
+
lazy,
|
|
33106
|
+
eager
|
|
32573
33107
|
});
|
|
32574
|
-
this.offset = offset;
|
|
32575
|
-
this.index = index;
|
|
32576
|
-
this.ok = false;
|
|
32577
33108
|
}
|
|
32578
|
-
|
|
32579
|
-
|
|
33109
|
+
reset() {
|
|
33110
|
+
this.isFilled = false;
|
|
33111
|
+
this.masked.reset();
|
|
32580
33112
|
}
|
|
32581
|
-
|
|
32582
|
-
|
|
33113
|
+
remove(fromPos, toPos) {
|
|
33114
|
+
if (fromPos === void 0) {
|
|
33115
|
+
fromPos = 0;
|
|
33116
|
+
}
|
|
33117
|
+
if (toPos === void 0) {
|
|
33118
|
+
toPos = this.value.length;
|
|
33119
|
+
}
|
|
33120
|
+
if (fromPos === 0 && toPos >= 1) {
|
|
33121
|
+
this.isFilled = false;
|
|
33122
|
+
return this.masked.remove(fromPos, toPos);
|
|
33123
|
+
}
|
|
33124
|
+
return new ChangeDetails();
|
|
32583
33125
|
}
|
|
32584
|
-
get
|
|
32585
|
-
return
|
|
32586
|
-
index: this.index,
|
|
32587
|
-
offset: this.offset,
|
|
32588
|
-
ok: this.ok
|
|
32589
|
-
};
|
|
33126
|
+
get value() {
|
|
33127
|
+
return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
|
|
32590
33128
|
}
|
|
32591
|
-
|
|
32592
|
-
|
|
33129
|
+
get unmaskedValue() {
|
|
33130
|
+
return this.masked.unmaskedValue;
|
|
32593
33131
|
}
|
|
32594
|
-
|
|
32595
|
-
this.
|
|
33132
|
+
get rawInputValue() {
|
|
33133
|
+
return this.masked.rawInputValue;
|
|
32596
33134
|
}
|
|
32597
|
-
|
|
32598
|
-
|
|
32599
|
-
this.state = s;
|
|
32600
|
-
return s;
|
|
33135
|
+
get displayValue() {
|
|
33136
|
+
return this.masked.value && this.displayChar || this.value;
|
|
32601
33137
|
}
|
|
32602
|
-
|
|
32603
|
-
|
|
32604
|
-
|
|
32605
|
-
|
|
32606
|
-
|
|
33138
|
+
get isComplete() {
|
|
33139
|
+
return Boolean(this.masked.value) || this.isOptional;
|
|
33140
|
+
}
|
|
33141
|
+
_appendChar(ch, flags) {
|
|
33142
|
+
if (flags === void 0) {
|
|
33143
|
+
flags = {};
|
|
32607
33144
|
}
|
|
32608
|
-
if (this.
|
|
32609
|
-
|
|
32610
|
-
|
|
33145
|
+
if (this.isFilled) return new ChangeDetails();
|
|
33146
|
+
const state = this.masked.state;
|
|
33147
|
+
// simulate input
|
|
33148
|
+
const details = this.masked._appendChar(ch, this.currentMaskFlags(flags));
|
|
33149
|
+
if (details.inserted && this.doValidate(flags) === false) {
|
|
33150
|
+
details.inserted = details.rawInserted = '';
|
|
33151
|
+
this.masked.state = state;
|
|
32611
33152
|
}
|
|
33153
|
+
if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) {
|
|
33154
|
+
details.inserted = this.placeholderChar;
|
|
33155
|
+
}
|
|
33156
|
+
details.skip = !details.inserted && !this.isOptional;
|
|
33157
|
+
this.isFilled = Boolean(details.inserted);
|
|
33158
|
+
return details;
|
|
32612
33159
|
}
|
|
32613
|
-
|
|
32614
|
-
|
|
32615
|
-
|
|
32616
|
-
|
|
32617
|
-
|
|
33160
|
+
append(str, flags, tail) {
|
|
33161
|
+
// TODO probably should be done via _appendChar
|
|
33162
|
+
return this.masked.append(str, this.currentMaskFlags(flags), tail);
|
|
33163
|
+
}
|
|
33164
|
+
_appendPlaceholder() {
|
|
33165
|
+
const details = new ChangeDetails();
|
|
33166
|
+
if (this.isFilled || this.isOptional) return details;
|
|
33167
|
+
this.isFilled = true;
|
|
33168
|
+
details.inserted = this.placeholderChar;
|
|
33169
|
+
return details;
|
|
33170
|
+
}
|
|
33171
|
+
_appendEager() {
|
|
33172
|
+
return new ChangeDetails();
|
|
33173
|
+
}
|
|
33174
|
+
extractTail(fromPos, toPos) {
|
|
33175
|
+
return this.masked.extractTail(fromPos, toPos);
|
|
33176
|
+
}
|
|
33177
|
+
appendTail(tail) {
|
|
33178
|
+
return this.masked.appendTail(tail);
|
|
33179
|
+
}
|
|
33180
|
+
extractInput(fromPos, toPos, flags) {
|
|
33181
|
+
if (fromPos === void 0) {
|
|
33182
|
+
fromPos = 0;
|
|
32618
33183
|
}
|
|
32619
|
-
|
|
33184
|
+
if (toPos === void 0) {
|
|
33185
|
+
toPos = this.value.length;
|
|
33186
|
+
}
|
|
33187
|
+
return this.masked.extractInput(fromPos, toPos, flags);
|
|
32620
33188
|
}
|
|
32621
|
-
|
|
32622
|
-
|
|
32623
|
-
|
|
32624
|
-
|
|
33189
|
+
nearestInputPos(cursorPos, direction) {
|
|
33190
|
+
if (direction === void 0) {
|
|
33191
|
+
direction = DIRECTION.NONE;
|
|
33192
|
+
}
|
|
33193
|
+
const minPos = 0;
|
|
33194
|
+
const maxPos = this.value.length;
|
|
33195
|
+
const boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
|
|
33196
|
+
switch (direction) {
|
|
33197
|
+
case DIRECTION.LEFT:
|
|
33198
|
+
case DIRECTION.FORCE_LEFT:
|
|
33199
|
+
return this.isComplete ? boundPos : minPos;
|
|
33200
|
+
case DIRECTION.RIGHT:
|
|
33201
|
+
case DIRECTION.FORCE_RIGHT:
|
|
33202
|
+
return this.isComplete ? boundPos : maxPos;
|
|
33203
|
+
case DIRECTION.NONE:
|
|
33204
|
+
default:
|
|
33205
|
+
return boundPos;
|
|
32625
33206
|
}
|
|
32626
|
-
return this.ok = false;
|
|
32627
33207
|
}
|
|
32628
|
-
|
|
32629
|
-
|
|
32630
|
-
|
|
32631
|
-
|
|
32632
|
-
|
|
32633
|
-
|
|
33208
|
+
totalInputPositions(fromPos, toPos) {
|
|
33209
|
+
if (fromPos === void 0) {
|
|
33210
|
+
fromPos = 0;
|
|
33211
|
+
}
|
|
33212
|
+
if (toPos === void 0) {
|
|
33213
|
+
toPos = this.value.length;
|
|
33214
|
+
}
|
|
33215
|
+
return this.value.slice(fromPos, toPos).length;
|
|
32634
33216
|
}
|
|
32635
|
-
|
|
32636
|
-
|
|
32637
|
-
// filled input: 00|
|
|
32638
|
-
// optional empty input: 00[]|
|
|
32639
|
-
// nested block: XX<[]>|
|
|
32640
|
-
return this._pushLeft(() => {
|
|
32641
|
-
if (this.block.isFixed) return;
|
|
32642
|
-
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
|
|
32643
|
-
return true;
|
|
32644
|
-
});
|
|
33217
|
+
doValidate(flags) {
|
|
33218
|
+
return this.masked.doValidate(this.currentMaskFlags(flags)) && (!this.parent || this.parent.doValidate(this.currentMaskFlags(flags)));
|
|
32645
33219
|
}
|
|
32646
|
-
|
|
32647
|
-
|
|
32648
|
-
if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
|
|
32649
|
-
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
|
|
32650
|
-
return true;
|
|
32651
|
-
});
|
|
33220
|
+
doCommit() {
|
|
33221
|
+
this.masked.doCommit();
|
|
32652
33222
|
}
|
|
32653
|
-
|
|
32654
|
-
return
|
|
32655
|
-
|
|
32656
|
-
|
|
32657
|
-
|
|
32658
|
-
|
|
33223
|
+
get state() {
|
|
33224
|
+
return {
|
|
33225
|
+
_value: this.value,
|
|
33226
|
+
_rawInputValue: this.rawInputValue,
|
|
33227
|
+
masked: this.masked.state,
|
|
33228
|
+
isFilled: this.isFilled
|
|
33229
|
+
};
|
|
32659
33230
|
}
|
|
32660
|
-
|
|
32661
|
-
|
|
32662
|
-
|
|
32663
|
-
|
|
32664
|
-
// const o = this.offset;
|
|
32665
|
-
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
|
|
32666
|
-
// HACK cases like (STILL DOES NOT WORK FOR NESTED)
|
|
32667
|
-
// aa|X
|
|
32668
|
-
// aa<X|[]>X_ - this will not work
|
|
32669
|
-
// if (o && o === this.offset && this.block instanceof PatternInputDefinition) continue;
|
|
32670
|
-
return true;
|
|
32671
|
-
});
|
|
33231
|
+
set state(state) {
|
|
33232
|
+
this.masked.state = state.masked;
|
|
33233
|
+
this.isFilled = state.isFilled;
|
|
32672
33234
|
}
|
|
32673
|
-
|
|
32674
|
-
|
|
32675
|
-
|
|
32676
|
-
|
|
32677
|
-
|
|
32678
|
-
|
|
32679
|
-
return true;
|
|
32680
|
-
});
|
|
33235
|
+
currentMaskFlags(flags) {
|
|
33236
|
+
var _flags$_beforeTailSta;
|
|
33237
|
+
return {
|
|
33238
|
+
...flags,
|
|
33239
|
+
_beforeTailState: (flags == null ? void 0 : (_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.masked) || (flags == null ? void 0 : flags._beforeTailState)
|
|
33240
|
+
};
|
|
32681
33241
|
}
|
|
32682
33242
|
}
|
|
33243
|
+
PatternInputDefinition.DEFAULT_DEFINITIONS = {
|
|
33244
|
+
'0': /\d/,
|
|
33245
|
+
'a': /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
|
|
33246
|
+
// http://stackoverflow.com/a/22075070
|
|
33247
|
+
'*': /./
|
|
33248
|
+
};
|
|
32683
33249
|
|
|
32684
33250
|
/** Masking by RegExp */
|
|
32685
33251
|
class MaskedRegExp extends Masked {
|
|
32686
|
-
/**
|
|
32687
|
-
|
|
32688
|
-
|
|
32689
|
-
|
|
33252
|
+
/** */
|
|
33253
|
+
|
|
33254
|
+
/** Enable characters overwriting */
|
|
33255
|
+
|
|
33256
|
+
/** */
|
|
33257
|
+
|
|
33258
|
+
/** */
|
|
33259
|
+
|
|
33260
|
+
updateOptions(opts) {
|
|
33261
|
+
super.updateOptions(opts);
|
|
33262
|
+
}
|
|
32690
33263
|
_update(opts) {
|
|
32691
|
-
|
|
33264
|
+
const mask = opts.mask;
|
|
33265
|
+
if (mask) opts.validate = value => value.search(mask) >= 0;
|
|
32692
33266
|
super._update(opts);
|
|
32693
33267
|
}
|
|
32694
33268
|
}
|
|
32695
33269
|
IMask.MaskedRegExp = MaskedRegExp;
|
|
32696
33270
|
|
|
32697
|
-
|
|
32698
|
-
|
|
32699
|
-
/**
|
|
32700
|
-
Pattern mask
|
|
32701
|
-
@param {Object} opts
|
|
32702
|
-
@param {Object} opts.blocks
|
|
32703
|
-
@param {Object} opts.definitions
|
|
32704
|
-
@param {string} opts.placeholderChar
|
|
32705
|
-
@param {string} opts.displayChar
|
|
32706
|
-
@param {boolean} opts.lazy
|
|
32707
|
-
*/
|
|
33271
|
+
/** Pattern mask */
|
|
32708
33272
|
class MaskedPattern extends Masked {
|
|
32709
33273
|
/** */
|
|
32710
33274
|
|
|
@@ -32716,36 +33280,37 @@ class MaskedPattern extends Masked {
|
|
|
32716
33280
|
|
|
32717
33281
|
/** Show placeholder only when needed */
|
|
32718
33282
|
|
|
32719
|
-
|
|
32720
|
-
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32721
|
-
// TODO type $Shape<MaskedPatternOptions>={} does not work
|
|
32722
|
-
opts.definitions = Object.assign({}, DEFAULT_INPUT_DEFINITIONS, opts.definitions);
|
|
32723
|
-
super(Object.assign({}, MaskedPattern.DEFAULTS, opts));
|
|
32724
|
-
}
|
|
33283
|
+
/** Enable characters overwriting */
|
|
32725
33284
|
|
|
32726
|
-
/**
|
|
32727
|
-
|
|
32728
|
-
|
|
32729
|
-
|
|
32730
|
-
|
|
32731
|
-
|
|
33285
|
+
/** */
|
|
33286
|
+
|
|
33287
|
+
/** */
|
|
33288
|
+
|
|
33289
|
+
constructor(opts) {
|
|
33290
|
+
super({
|
|
33291
|
+
...MaskedPattern.DEFAULTS,
|
|
33292
|
+
...opts,
|
|
33293
|
+
definitions: Object.assign({}, PatternInputDefinition.DEFAULT_DEFINITIONS, opts == null ? void 0 : opts.definitions)
|
|
33294
|
+
});
|
|
33295
|
+
}
|
|
33296
|
+
updateOptions(opts) {
|
|
33297
|
+
super.updateOptions(opts);
|
|
33298
|
+
}
|
|
33299
|
+
_update(opts) {
|
|
32732
33300
|
opts.definitions = Object.assign({}, this.definitions, opts.definitions);
|
|
32733
33301
|
super._update(opts);
|
|
32734
33302
|
this._rebuildMask();
|
|
32735
33303
|
}
|
|
32736
|
-
|
|
32737
|
-
/** */
|
|
32738
33304
|
_rebuildMask() {
|
|
32739
33305
|
const defs = this.definitions;
|
|
32740
33306
|
this._blocks = [];
|
|
32741
33307
|
this._stops = [];
|
|
32742
33308
|
this._maskedBlocks = {};
|
|
32743
|
-
|
|
33309
|
+
const pattern = this.mask;
|
|
32744
33310
|
if (!pattern || !defs) return;
|
|
32745
33311
|
let unmaskingBlock = false;
|
|
32746
33312
|
let optionalBlock = false;
|
|
32747
33313
|
for (let i = 0; i < pattern.length; ++i) {
|
|
32748
|
-
var _defs$char, _defs$char2;
|
|
32749
33314
|
if (this.blocks) {
|
|
32750
33315
|
const p = pattern.slice(i);
|
|
32751
33316
|
const bNames = Object.keys(this.blocks).filter(bName => p.indexOf(bName) === 0);
|
|
@@ -32754,15 +33319,15 @@ class MaskedPattern extends Masked {
|
|
|
32754
33319
|
// use block name with max length
|
|
32755
33320
|
const bName = bNames[0];
|
|
32756
33321
|
if (bName) {
|
|
32757
|
-
|
|
32758
|
-
const maskedBlock = createMask(Object.assign({
|
|
32759
|
-
parent: this,
|
|
33322
|
+
const maskedBlock = createMask({
|
|
32760
33323
|
lazy: this.lazy,
|
|
32761
33324
|
eager: this.eager,
|
|
32762
33325
|
placeholderChar: this.placeholderChar,
|
|
32763
33326
|
displayChar: this.displayChar,
|
|
32764
|
-
overwrite: this.overwrite
|
|
32765
|
-
|
|
33327
|
+
overwrite: this.overwrite,
|
|
33328
|
+
...normalizeOpts(this.blocks[bName]),
|
|
33329
|
+
parent: this
|
|
33330
|
+
});
|
|
32766
33331
|
if (maskedBlock) {
|
|
32767
33332
|
this._blocks.push(maskedBlock);
|
|
32768
33333
|
|
|
@@ -32794,17 +33359,15 @@ class MaskedPattern extends Masked {
|
|
|
32794
33359
|
if (!char) break;
|
|
32795
33360
|
isInput = false;
|
|
32796
33361
|
}
|
|
32797
|
-
const
|
|
32798
|
-
mask: defs[char]
|
|
32799
|
-
};
|
|
32800
|
-
const def = isInput ? new PatternInputDefinition(Object.assign({
|
|
32801
|
-
parent: this,
|
|
33362
|
+
const def = isInput ? new PatternInputDefinition({
|
|
32802
33363
|
isOptional: optionalBlock,
|
|
32803
33364
|
lazy: this.lazy,
|
|
32804
33365
|
eager: this.eager,
|
|
32805
33366
|
placeholderChar: this.placeholderChar,
|
|
32806
|
-
displayChar: this.displayChar
|
|
32807
|
-
|
|
33367
|
+
displayChar: this.displayChar,
|
|
33368
|
+
...normalizeOpts(defs[char]),
|
|
33369
|
+
parent: this
|
|
33370
|
+
}) : new PatternFixedDefinition({
|
|
32808
33371
|
char,
|
|
32809
33372
|
eager: this.eager,
|
|
32810
33373
|
isUnmasking: unmaskingBlock
|
|
@@ -32812,42 +33375,27 @@ class MaskedPattern extends Masked {
|
|
|
32812
33375
|
this._blocks.push(def);
|
|
32813
33376
|
}
|
|
32814
33377
|
}
|
|
32815
|
-
|
|
32816
|
-
/**
|
|
32817
|
-
@override
|
|
32818
|
-
*/
|
|
32819
33378
|
get state() {
|
|
32820
|
-
return
|
|
33379
|
+
return {
|
|
33380
|
+
...super.state,
|
|
32821
33381
|
_blocks: this._blocks.map(b => b.state)
|
|
32822
|
-
}
|
|
33382
|
+
};
|
|
32823
33383
|
}
|
|
32824
33384
|
set state(state) {
|
|
32825
33385
|
const {
|
|
32826
|
-
|
|
32827
|
-
|
|
32828
|
-
|
|
33386
|
+
_blocks,
|
|
33387
|
+
...maskedState
|
|
33388
|
+
} = state;
|
|
32829
33389
|
this._blocks.forEach((b, bi) => b.state = _blocks[bi]);
|
|
32830
33390
|
super.state = maskedState;
|
|
32831
33391
|
}
|
|
32832
|
-
|
|
32833
|
-
/**
|
|
32834
|
-
@override
|
|
32835
|
-
*/
|
|
32836
33392
|
reset() {
|
|
32837
33393
|
super.reset();
|
|
32838
33394
|
this._blocks.forEach(b => b.reset());
|
|
32839
33395
|
}
|
|
32840
|
-
|
|
32841
|
-
/**
|
|
32842
|
-
@override
|
|
32843
|
-
*/
|
|
32844
33396
|
get isComplete() {
|
|
32845
33397
|
return this._blocks.every(b => b.isComplete);
|
|
32846
33398
|
}
|
|
32847
|
-
|
|
32848
|
-
/**
|
|
32849
|
-
@override
|
|
32850
|
-
*/
|
|
32851
33399
|
get isFilled() {
|
|
32852
33400
|
return this._blocks.every(b => b.isFilled);
|
|
32853
33401
|
}
|
|
@@ -32857,28 +33405,16 @@ class MaskedPattern extends Masked {
|
|
|
32857
33405
|
get isOptional() {
|
|
32858
33406
|
return this._blocks.every(b => b.isOptional);
|
|
32859
33407
|
}
|
|
32860
|
-
|
|
32861
|
-
/**
|
|
32862
|
-
@override
|
|
32863
|
-
*/
|
|
32864
33408
|
doCommit() {
|
|
32865
33409
|
this._blocks.forEach(b => b.doCommit());
|
|
32866
33410
|
super.doCommit();
|
|
32867
33411
|
}
|
|
32868
|
-
|
|
32869
|
-
/**
|
|
32870
|
-
@override
|
|
32871
|
-
*/
|
|
32872
33412
|
get unmaskedValue() {
|
|
32873
33413
|
return this._blocks.reduce((str, b) => str += b.unmaskedValue, '');
|
|
32874
33414
|
}
|
|
32875
33415
|
set unmaskedValue(unmaskedValue) {
|
|
32876
33416
|
super.unmaskedValue = unmaskedValue;
|
|
32877
33417
|
}
|
|
32878
|
-
|
|
32879
|
-
/**
|
|
32880
|
-
@override
|
|
32881
|
-
*/
|
|
32882
33418
|
get value() {
|
|
32883
33419
|
// TODO return _value when not in change?
|
|
32884
33420
|
return this._blocks.reduce((str, b) => str += b.value, '');
|
|
@@ -32889,21 +33425,13 @@ class MaskedPattern extends Masked {
|
|
|
32889
33425
|
get displayValue() {
|
|
32890
33426
|
return this._blocks.reduce((str, b) => str += b.displayValue, '');
|
|
32891
33427
|
}
|
|
32892
|
-
|
|
32893
|
-
/**
|
|
32894
|
-
@override
|
|
32895
|
-
*/
|
|
32896
33428
|
appendTail(tail) {
|
|
32897
33429
|
return super.appendTail(tail).aggregate(this._appendPlaceholder());
|
|
32898
33430
|
}
|
|
32899
|
-
|
|
32900
|
-
/**
|
|
32901
|
-
@override
|
|
32902
|
-
*/
|
|
32903
33431
|
_appendEager() {
|
|
32904
33432
|
var _this$_mapPosToBlock;
|
|
32905
33433
|
const details = new ChangeDetails();
|
|
32906
|
-
let startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.value.length))
|
|
33434
|
+
let startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.value.length)) == null ? void 0 : _this$_mapPosToBlock.index;
|
|
32907
33435
|
if (startBlockIndex == null) return details;
|
|
32908
33436
|
|
|
32909
33437
|
// TODO test if it works for nested pattern masks
|
|
@@ -32915,12 +33443,10 @@ class MaskedPattern extends Masked {
|
|
|
32915
33443
|
}
|
|
32916
33444
|
return details;
|
|
32917
33445
|
}
|
|
32918
|
-
|
|
32919
|
-
|
|
32920
|
-
|
|
32921
|
-
|
|
32922
|
-
_appendCharRaw(ch) {
|
|
32923
|
-
let flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33446
|
+
_appendCharRaw(ch, flags) {
|
|
33447
|
+
if (flags === void 0) {
|
|
33448
|
+
flags = {};
|
|
33449
|
+
}
|
|
32924
33450
|
const blockIter = this._mapPosToBlock(this.value.length);
|
|
32925
33451
|
const details = new ChangeDetails();
|
|
32926
33452
|
if (!blockIter) return details;
|
|
@@ -32928,9 +33454,10 @@ class MaskedPattern extends Masked {
|
|
|
32928
33454
|
var _flags$_beforeTailSta, _flags$_beforeTailSta2;
|
|
32929
33455
|
const block = this._blocks[bi];
|
|
32930
33456
|
if (!block) break;
|
|
32931
|
-
const blockDetails = block._appendChar(ch,
|
|
32932
|
-
|
|
32933
|
-
|
|
33457
|
+
const blockDetails = block._appendChar(ch, {
|
|
33458
|
+
...flags,
|
|
33459
|
+
_beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : (_flags$_beforeTailSta2 = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta2[bi]
|
|
33460
|
+
});
|
|
32934
33461
|
const skip = blockDetails.skip;
|
|
32935
33462
|
details.aggregate(blockDetails);
|
|
32936
33463
|
if (skip || blockDetails.rawInserted) break; // go next char
|
|
@@ -32938,13 +33465,13 @@ class MaskedPattern extends Masked {
|
|
|
32938
33465
|
|
|
32939
33466
|
return details;
|
|
32940
33467
|
}
|
|
32941
|
-
|
|
32942
|
-
|
|
32943
|
-
|
|
32944
|
-
|
|
32945
|
-
|
|
32946
|
-
|
|
32947
|
-
|
|
33468
|
+
extractTail(fromPos, toPos) {
|
|
33469
|
+
if (fromPos === void 0) {
|
|
33470
|
+
fromPos = 0;
|
|
33471
|
+
}
|
|
33472
|
+
if (toPos === void 0) {
|
|
33473
|
+
toPos = this.value.length;
|
|
33474
|
+
}
|
|
32948
33475
|
const chunkTail = new ChunksTailDetails();
|
|
32949
33476
|
if (fromPos === toPos) return chunkTail;
|
|
32950
33477
|
this._forEachBlocksInRange(fromPos, toPos, (b, bi, bFromPos, bToPos) => {
|
|
@@ -32956,14 +33483,16 @@ class MaskedPattern extends Masked {
|
|
|
32956
33483
|
});
|
|
32957
33484
|
return chunkTail;
|
|
32958
33485
|
}
|
|
32959
|
-
|
|
32960
|
-
|
|
32961
|
-
|
|
32962
|
-
|
|
32963
|
-
|
|
32964
|
-
|
|
32965
|
-
|
|
32966
|
-
|
|
33486
|
+
extractInput(fromPos, toPos, flags) {
|
|
33487
|
+
if (fromPos === void 0) {
|
|
33488
|
+
fromPos = 0;
|
|
33489
|
+
}
|
|
33490
|
+
if (toPos === void 0) {
|
|
33491
|
+
toPos = this.value.length;
|
|
33492
|
+
}
|
|
33493
|
+
if (flags === void 0) {
|
|
33494
|
+
flags = {};
|
|
33495
|
+
}
|
|
32967
33496
|
if (fromPos === toPos) return '';
|
|
32968
33497
|
let input = '';
|
|
32969
33498
|
this._forEachBlocksInRange(fromPos, toPos, (b, _, fromPos, toPos) => {
|
|
@@ -32990,9 +33519,8 @@ class MaskedPattern extends Masked {
|
|
|
32990
33519
|
const endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
|
|
32991
33520
|
this._blocks.slice(startBlockIndex, endBlockIndex).forEach(b => {
|
|
32992
33521
|
if (!b.lazy || toBlockIndex != null) {
|
|
32993
|
-
|
|
32994
|
-
const
|
|
32995
|
-
const bDetails = b._appendPlaceholder(...args);
|
|
33522
|
+
var _blocks2;
|
|
33523
|
+
const bDetails = b._appendPlaceholder((_blocks2 = b._blocks) == null ? void 0 : _blocks2.length);
|
|
32996
33524
|
this._value += bDetails.inserted;
|
|
32997
33525
|
details.aggregate(bDetails);
|
|
32998
33526
|
}
|
|
@@ -33015,16 +33543,13 @@ class MaskedPattern extends Masked {
|
|
|
33015
33543
|
}
|
|
33016
33544
|
}
|
|
33017
33545
|
}
|
|
33018
|
-
|
|
33019
|
-
/** */
|
|
33020
33546
|
_blockStartPos(blockIndex) {
|
|
33021
33547
|
return this._blocks.slice(0, blockIndex).reduce((pos, b) => pos += b.value.length, 0);
|
|
33022
33548
|
}
|
|
33023
|
-
|
|
33024
|
-
|
|
33025
|
-
|
|
33026
|
-
|
|
33027
|
-
let fn = arguments.length > 2 ? arguments[2] : undefined;
|
|
33549
|
+
_forEachBlocksInRange(fromPos, toPos, fn) {
|
|
33550
|
+
if (toPos === void 0) {
|
|
33551
|
+
toPos = this.value.length;
|
|
33552
|
+
}
|
|
33028
33553
|
const fromBlockIter = this._mapPosToBlock(fromPos);
|
|
33029
33554
|
if (fromBlockIter) {
|
|
33030
33555
|
const toBlockIter = this._mapPosToBlock(toPos);
|
|
@@ -33044,25 +33569,23 @@ class MaskedPattern extends Masked {
|
|
|
33044
33569
|
}
|
|
33045
33570
|
}
|
|
33046
33571
|
}
|
|
33047
|
-
|
|
33048
|
-
|
|
33049
|
-
|
|
33050
|
-
|
|
33051
|
-
|
|
33052
|
-
|
|
33053
|
-
|
|
33572
|
+
remove(fromPos, toPos) {
|
|
33573
|
+
if (fromPos === void 0) {
|
|
33574
|
+
fromPos = 0;
|
|
33575
|
+
}
|
|
33576
|
+
if (toPos === void 0) {
|
|
33577
|
+
toPos = this.value.length;
|
|
33578
|
+
}
|
|
33054
33579
|
const removeDetails = super.remove(fromPos, toPos);
|
|
33055
33580
|
this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
|
|
33056
33581
|
removeDetails.aggregate(b.remove(bFromPos, bToPos));
|
|
33057
33582
|
});
|
|
33058
33583
|
return removeDetails;
|
|
33059
33584
|
}
|
|
33060
|
-
|
|
33061
|
-
|
|
33062
|
-
|
|
33063
|
-
|
|
33064
|
-
nearestInputPos(cursorPos) {
|
|
33065
|
-
let direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
|
|
33585
|
+
nearestInputPos(cursorPos, direction) {
|
|
33586
|
+
if (direction === void 0) {
|
|
33587
|
+
direction = DIRECTION.NONE;
|
|
33588
|
+
}
|
|
33066
33589
|
if (!this._blocks.length) return 0;
|
|
33067
33590
|
const cursor = new PatternCursor(this, cursorPos);
|
|
33068
33591
|
if (direction === DIRECTION.NONE) {
|
|
@@ -33104,14 +33627,6 @@ class MaskedPattern extends Masked {
|
|
|
33104
33627
|
if (cursor.ok) return cursor.pos;
|
|
33105
33628
|
cursor.popState();
|
|
33106
33629
|
if (cursor.ok) return cursor.pos;
|
|
33107
|
-
|
|
33108
|
-
// cursor.popState();
|
|
33109
|
-
// if (
|
|
33110
|
-
// cursor.pushRightBeforeInput() &&
|
|
33111
|
-
// // TODO HACK for lazy if has aligned left inside fixed and has came to the start - use start position
|
|
33112
|
-
// (!this.lazy || this.extractInput())
|
|
33113
|
-
// ) return cursor.pos;
|
|
33114
|
-
|
|
33115
33630
|
return 0;
|
|
33116
33631
|
}
|
|
33117
33632
|
if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) {
|
|
@@ -33130,6 +33645,19 @@ class MaskedPattern extends Masked {
|
|
|
33130
33645
|
}
|
|
33131
33646
|
return cursorPos;
|
|
33132
33647
|
}
|
|
33648
|
+
totalInputPositions(fromPos, toPos) {
|
|
33649
|
+
if (fromPos === void 0) {
|
|
33650
|
+
fromPos = 0;
|
|
33651
|
+
}
|
|
33652
|
+
if (toPos === void 0) {
|
|
33653
|
+
toPos = this.value.length;
|
|
33654
|
+
}
|
|
33655
|
+
let total = 0;
|
|
33656
|
+
this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
|
|
33657
|
+
total += b.totalInputPositions(bFromPos, bToPos);
|
|
33658
|
+
});
|
|
33659
|
+
return total;
|
|
33660
|
+
}
|
|
33133
33661
|
|
|
33134
33662
|
/** Get block by name */
|
|
33135
33663
|
maskedBlock(name) {
|
|
@@ -33169,31 +33697,32 @@ class MaskedRange extends MaskedPattern {
|
|
|
33169
33697
|
get _matchFrom() {
|
|
33170
33698
|
return this.maxLength - String(this.from).length;
|
|
33171
33699
|
}
|
|
33700
|
+
constructor(opts) {
|
|
33701
|
+
super(opts); // mask will be created in _update
|
|
33702
|
+
}
|
|
33172
33703
|
|
|
33173
|
-
|
|
33174
|
-
|
|
33175
|
-
|
|
33704
|
+
updateOptions(opts) {
|
|
33705
|
+
super.updateOptions(opts);
|
|
33706
|
+
}
|
|
33176
33707
|
_update(opts) {
|
|
33177
|
-
|
|
33178
|
-
|
|
33179
|
-
|
|
33180
|
-
|
|
33181
|
-
|
|
33182
|
-
|
|
33183
|
-
|
|
33184
|
-
|
|
33185
|
-
|
|
33186
|
-
|
|
33187
|
-
|
|
33708
|
+
const {
|
|
33709
|
+
to = this.to || 0,
|
|
33710
|
+
from = this.from || 0,
|
|
33711
|
+
maxLength = this.maxLength || 0,
|
|
33712
|
+
autofix = this.autofix,
|
|
33713
|
+
...patternOpts
|
|
33714
|
+
} = opts;
|
|
33715
|
+
this.to = to;
|
|
33716
|
+
this.from = from;
|
|
33717
|
+
this.maxLength = Math.max(String(to).length, maxLength);
|
|
33718
|
+
this.autofix = autofix;
|
|
33719
|
+
const fromStr = String(this.from).padStart(this.maxLength, '0');
|
|
33720
|
+
const toStr = String(this.to).padStart(this.maxLength, '0');
|
|
33188
33721
|
let sameCharsCount = 0;
|
|
33189
33722
|
while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) ++sameCharsCount;
|
|
33190
|
-
|
|
33191
|
-
super._update(
|
|
33723
|
+
patternOpts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(this.maxLength - sameCharsCount);
|
|
33724
|
+
super._update(patternOpts);
|
|
33192
33725
|
}
|
|
33193
|
-
|
|
33194
|
-
/**
|
|
33195
|
-
@override
|
|
33196
|
-
*/
|
|
33197
33726
|
get isComplete() {
|
|
33198
33727
|
return super.isComplete && Boolean(this.value);
|
|
33199
33728
|
}
|
|
@@ -33209,40 +33738,33 @@ class MaskedRange extends MaskedPattern {
|
|
|
33209
33738
|
maxstr = maxstr.padEnd(this.maxLength, '9');
|
|
33210
33739
|
return [minstr, maxstr];
|
|
33211
33740
|
}
|
|
33212
|
-
|
|
33213
|
-
|
|
33214
|
-
|
|
33215
|
-
|
|
33216
|
-
*/
|
|
33217
|
-
doPrepare(ch) {
|
|
33218
|
-
let flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
33741
|
+
doPrepareChar(ch, flags) {
|
|
33742
|
+
if (flags === void 0) {
|
|
33743
|
+
flags = {};
|
|
33744
|
+
}
|
|
33219
33745
|
let details;
|
|
33220
|
-
[ch, details] =
|
|
33221
|
-
if (!this.autofix || !ch) return ch;
|
|
33746
|
+
[ch, details] = super.doPrepareChar(ch.replace(/\D/g, ''), flags);
|
|
33747
|
+
if (!this.autofix || !ch) return [ch, details];
|
|
33222
33748
|
const fromStr = String(this.from).padStart(this.maxLength, '0');
|
|
33223
33749
|
const toStr = String(this.to).padStart(this.maxLength, '0');
|
|
33224
|
-
|
|
33225
|
-
if (nextVal.length > this.maxLength) return '';
|
|
33750
|
+
const nextVal = this.value + ch;
|
|
33751
|
+
if (nextVal.length > this.maxLength) return ['', details];
|
|
33226
33752
|
const [minstr, maxstr] = this.boundaries(nextVal);
|
|
33227
|
-
if (Number(maxstr) < this.from) return fromStr[nextVal.length - 1];
|
|
33753
|
+
if (Number(maxstr) < this.from) return [fromStr[nextVal.length - 1], details];
|
|
33228
33754
|
if (Number(minstr) > this.to) {
|
|
33229
33755
|
if (this.autofix === 'pad' && nextVal.length < this.maxLength) {
|
|
33230
33756
|
return ['', details.aggregate(this.append(fromStr[nextVal.length - 1] + ch, flags))];
|
|
33231
33757
|
}
|
|
33232
|
-
return toStr[nextVal.length - 1];
|
|
33758
|
+
return [toStr[nextVal.length - 1], details];
|
|
33233
33759
|
}
|
|
33234
|
-
return ch;
|
|
33760
|
+
return [ch, details];
|
|
33235
33761
|
}
|
|
33236
|
-
|
|
33237
|
-
/**
|
|
33238
|
-
@override
|
|
33239
|
-
*/
|
|
33240
|
-
doValidate() {
|
|
33762
|
+
doValidate(flags) {
|
|
33241
33763
|
const str = this.value;
|
|
33242
33764
|
const firstNonZero = str.search(/[^0]/);
|
|
33243
33765
|
if (firstNonZero === -1 && str.length <= this._matchFrom) return true;
|
|
33244
33766
|
const [minstr, maxstr] = this.boundaries(str);
|
|
33245
|
-
return this.from <= Number(maxstr) && Number(minstr) <= this.to && super.doValidate(
|
|
33767
|
+
return this.from <= Number(maxstr) && Number(minstr) <= this.to && super.doValidate(flags);
|
|
33246
33768
|
}
|
|
33247
33769
|
}
|
|
33248
33770
|
IMask.MaskedRange = MaskedRange;
|
|
@@ -33257,48 +33779,65 @@ class MaskedDate extends MaskedPattern {
|
|
|
33257
33779
|
|
|
33258
33780
|
/** */
|
|
33259
33781
|
|
|
33260
|
-
/**
|
|
33261
|
-
|
|
33262
|
-
*/
|
|
33782
|
+
/** Format typed value to string */
|
|
33783
|
+
|
|
33784
|
+
/** Parse string to get typed value */
|
|
33785
|
+
|
|
33263
33786
|
constructor(opts) {
|
|
33264
|
-
|
|
33787
|
+
const {
|
|
33788
|
+
mask,
|
|
33789
|
+
pattern,
|
|
33790
|
+
...patternOpts
|
|
33791
|
+
} = {
|
|
33792
|
+
...MaskedDate.DEFAULTS,
|
|
33793
|
+
...opts
|
|
33794
|
+
};
|
|
33795
|
+
super({
|
|
33796
|
+
...patternOpts,
|
|
33797
|
+
mask: isString(mask) ? mask : pattern
|
|
33798
|
+
});
|
|
33799
|
+
}
|
|
33800
|
+
updateOptions(opts) {
|
|
33801
|
+
super.updateOptions(opts);
|
|
33265
33802
|
}
|
|
33266
|
-
|
|
33267
|
-
/**
|
|
33268
|
-
@override
|
|
33269
|
-
*/
|
|
33270
33803
|
_update(opts) {
|
|
33271
|
-
|
|
33272
|
-
|
|
33273
|
-
|
|
33274
|
-
|
|
33804
|
+
const {
|
|
33805
|
+
mask,
|
|
33806
|
+
pattern,
|
|
33807
|
+
blocks,
|
|
33808
|
+
...patternOpts
|
|
33809
|
+
} = {
|
|
33810
|
+
...MaskedDate.DEFAULTS,
|
|
33811
|
+
...opts
|
|
33812
|
+
};
|
|
33813
|
+
const patternBlocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
|
|
33275
33814
|
// adjust year block
|
|
33276
|
-
if (opts.min)
|
|
33277
|
-
if (opts.max)
|
|
33278
|
-
if (opts.min && opts.max &&
|
|
33279
|
-
|
|
33280
|
-
|
|
33281
|
-
if (
|
|
33282
|
-
|
|
33283
|
-
|
|
33815
|
+
if (opts.min) patternBlocks.Y.from = opts.min.getFullYear();
|
|
33816
|
+
if (opts.max) patternBlocks.Y.to = opts.max.getFullYear();
|
|
33817
|
+
if (opts.min && opts.max && patternBlocks.Y.from === patternBlocks.Y.to) {
|
|
33818
|
+
patternBlocks.m.from = opts.min.getMonth() + 1;
|
|
33819
|
+
patternBlocks.m.to = opts.max.getMonth() + 1;
|
|
33820
|
+
if (patternBlocks.m.from === patternBlocks.m.to) {
|
|
33821
|
+
patternBlocks.d.from = opts.min.getDate();
|
|
33822
|
+
patternBlocks.d.to = opts.max.getDate();
|
|
33284
33823
|
}
|
|
33285
33824
|
}
|
|
33286
|
-
Object.assign(
|
|
33825
|
+
Object.assign(patternBlocks, this.blocks, blocks);
|
|
33287
33826
|
|
|
33288
33827
|
// add autofix
|
|
33289
|
-
Object.keys(
|
|
33290
|
-
const b =
|
|
33828
|
+
Object.keys(patternBlocks).forEach(bk => {
|
|
33829
|
+
const b = patternBlocks[bk];
|
|
33291
33830
|
if (!('autofix' in b) && 'autofix' in opts) b.autofix = opts.autofix;
|
|
33292
33831
|
});
|
|
33293
|
-
super._update(
|
|
33832
|
+
super._update({
|
|
33833
|
+
...patternOpts,
|
|
33834
|
+
mask: isString(mask) ? mask : pattern,
|
|
33835
|
+
blocks: patternBlocks
|
|
33836
|
+
});
|
|
33294
33837
|
}
|
|
33295
|
-
|
|
33296
|
-
/**
|
|
33297
|
-
@override
|
|
33298
|
-
*/
|
|
33299
|
-
doValidate() {
|
|
33838
|
+
doValidate(flags) {
|
|
33300
33839
|
const date = this.date;
|
|
33301
|
-
return super.doValidate(
|
|
33840
|
+
return super.doValidate(flags) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
|
|
33302
33841
|
}
|
|
33303
33842
|
|
|
33304
33843
|
/** Checks if date is exists */
|
|
@@ -33313,38 +33852,16 @@ class MaskedDate extends MaskedPattern {
|
|
|
33313
33852
|
set date(date) {
|
|
33314
33853
|
this.typedValue = date;
|
|
33315
33854
|
}
|
|
33316
|
-
|
|
33317
|
-
/**
|
|
33318
|
-
@override
|
|
33319
|
-
*/
|
|
33320
33855
|
get typedValue() {
|
|
33321
33856
|
return this.isComplete ? super.typedValue : null;
|
|
33322
33857
|
}
|
|
33323
33858
|
set typedValue(value) {
|
|
33324
33859
|
super.typedValue = value;
|
|
33325
33860
|
}
|
|
33326
|
-
|
|
33327
|
-
/**
|
|
33328
|
-
@override
|
|
33329
|
-
*/
|
|
33330
33861
|
maskEquals(mask) {
|
|
33331
33862
|
return mask === Date || super.maskEquals(mask);
|
|
33332
33863
|
}
|
|
33333
33864
|
}
|
|
33334
|
-
MaskedDate.DEFAULTS = {
|
|
33335
|
-
pattern: 'd{.}`m{.}`Y',
|
|
33336
|
-
format: date => {
|
|
33337
|
-
if (!date) return '';
|
|
33338
|
-
const day = String(date.getDate()).padStart(2, '0');
|
|
33339
|
-
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
33340
|
-
const year = date.getFullYear();
|
|
33341
|
-
return [day, month, year].join('.');
|
|
33342
|
-
},
|
|
33343
|
-
parse: str => {
|
|
33344
|
-
const [day, month, year] = str.split('.');
|
|
33345
|
-
return new Date(year, month - 1, day);
|
|
33346
|
-
}
|
|
33347
|
-
};
|
|
33348
33865
|
MaskedDate.GET_DEFAULT_BLOCKS = () => ({
|
|
33349
33866
|
d: {
|
|
33350
33867
|
mask: MaskedRange,
|
|
@@ -33364,566 +33881,709 @@ MaskedDate.GET_DEFAULT_BLOCKS = () => ({
|
|
|
33364
33881
|
to: 9999
|
|
33365
33882
|
}
|
|
33366
33883
|
});
|
|
33367
|
-
|
|
33368
|
-
|
|
33369
|
-
|
|
33370
|
-
|
|
33371
|
-
|
|
33372
|
-
|
|
33373
|
-
|
|
33374
|
-
|
|
33375
|
-
|
|
33376
|
-
|
|
33377
|
-
|
|
33378
|
-
|
|
33379
|
-
|
|
33380
|
-
/** Safely returns selection start */
|
|
33381
|
-
get selectionStart() {
|
|
33382
|
-
let start;
|
|
33383
|
-
try {
|
|
33384
|
-
start = this._unsafeSelectionStart;
|
|
33385
|
-
} catch (e) {}
|
|
33386
|
-
return start != null ? start : this.value.length;
|
|
33387
|
-
}
|
|
33388
|
-
|
|
33389
|
-
/** Safely returns selection end */
|
|
33390
|
-
get selectionEnd() {
|
|
33391
|
-
let end;
|
|
33392
|
-
try {
|
|
33393
|
-
end = this._unsafeSelectionEnd;
|
|
33394
|
-
} catch (e) {}
|
|
33395
|
-
return end != null ? end : this.value.length;
|
|
33396
|
-
}
|
|
33397
|
-
|
|
33398
|
-
/** Safely sets element selection */
|
|
33399
|
-
select(start, end) {
|
|
33400
|
-
if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
|
|
33401
|
-
try {
|
|
33402
|
-
this._unsafeSelect(start, end);
|
|
33403
|
-
} catch (e) {}
|
|
33404
|
-
}
|
|
33405
|
-
|
|
33406
|
-
/** Should be overriden in subclasses */
|
|
33407
|
-
_unsafeSelect(start, end) {}
|
|
33408
|
-
/** Should be overriden in subclasses */
|
|
33409
|
-
get isActive() {
|
|
33410
|
-
return false;
|
|
33411
|
-
}
|
|
33412
|
-
/** Should be overriden in subclasses */
|
|
33413
|
-
bindEvents(handlers) {}
|
|
33414
|
-
/** Should be overriden in subclasses */
|
|
33415
|
-
unbindEvents() {}
|
|
33416
|
-
}
|
|
33417
|
-
IMask.MaskElement = MaskElement;
|
|
33418
|
-
|
|
33419
|
-
/** Bridge between HTMLElement and {@link Masked} */
|
|
33420
|
-
class HTMLMaskElement extends MaskElement {
|
|
33421
|
-
/** Mapping between HTMLElement events and mask internal events */
|
|
33422
|
-
|
|
33423
|
-
/** HTMLElement to use mask on */
|
|
33424
|
-
|
|
33425
|
-
/**
|
|
33426
|
-
@param {HTMLInputElement|HTMLTextAreaElement} input
|
|
33427
|
-
*/
|
|
33428
|
-
constructor(input) {
|
|
33429
|
-
super();
|
|
33430
|
-
this.input = input;
|
|
33431
|
-
this._handlers = {};
|
|
33432
|
-
}
|
|
33433
|
-
|
|
33434
|
-
/** */
|
|
33435
|
-
// $FlowFixMe https://github.com/facebook/flow/issues/2839
|
|
33436
|
-
get rootElement() {
|
|
33437
|
-
var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
|
|
33438
|
-
return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) === null || _this$input$getRootNo2 === void 0 ? void 0 : _this$input$getRootNo2.call(_this$input)) !== null && _this$input$getRootNo !== void 0 ? _this$input$getRootNo : document;
|
|
33439
|
-
}
|
|
33440
|
-
|
|
33441
|
-
/**
|
|
33442
|
-
Is element in focus
|
|
33443
|
-
@readonly
|
|
33444
|
-
*/
|
|
33445
|
-
get isActive() {
|
|
33446
|
-
//$FlowFixMe
|
|
33447
|
-
return this.input === this.rootElement.activeElement;
|
|
33448
|
-
}
|
|
33449
|
-
|
|
33450
|
-
/**
|
|
33451
|
-
Returns HTMLElement selection start
|
|
33452
|
-
@override
|
|
33453
|
-
*/
|
|
33454
|
-
get _unsafeSelectionStart() {
|
|
33455
|
-
return this.input.selectionStart;
|
|
33456
|
-
}
|
|
33457
|
-
|
|
33458
|
-
/**
|
|
33459
|
-
Returns HTMLElement selection end
|
|
33460
|
-
@override
|
|
33461
|
-
*/
|
|
33462
|
-
get _unsafeSelectionEnd() {
|
|
33463
|
-
return this.input.selectionEnd;
|
|
33464
|
-
}
|
|
33465
|
-
|
|
33466
|
-
/**
|
|
33467
|
-
Sets HTMLElement selection
|
|
33468
|
-
@override
|
|
33469
|
-
*/
|
|
33470
|
-
_unsafeSelect(start, end) {
|
|
33471
|
-
this.input.setSelectionRange(start, end);
|
|
33884
|
+
MaskedDate.DEFAULTS = {
|
|
33885
|
+
mask: Date,
|
|
33886
|
+
pattern: 'd{.}`m{.}`Y',
|
|
33887
|
+
format: (date, masked) => {
|
|
33888
|
+
if (!date) return '';
|
|
33889
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
33890
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
33891
|
+
const year = date.getFullYear();
|
|
33892
|
+
return [day, month, year].join('.');
|
|
33893
|
+
},
|
|
33894
|
+
parse: (str, masked) => {
|
|
33895
|
+
const [day, month, year] = str.split('.').map(Number);
|
|
33896
|
+
return new Date(year, month - 1, day);
|
|
33472
33897
|
}
|
|
33898
|
+
};
|
|
33899
|
+
IMask.MaskedDate = MaskedDate;
|
|
33473
33900
|
|
|
33474
|
-
|
|
33475
|
-
|
|
33476
|
-
|
|
33477
|
-
|
|
33478
|
-
|
|
33479
|
-
|
|
33901
|
+
/** Dynamic mask for choosing appropriate mask in run-time */
|
|
33902
|
+
class MaskedDynamic extends Masked {
|
|
33903
|
+
/** Currently chosen mask */
|
|
33904
|
+
|
|
33905
|
+
/** Compliled {@link Masked} options */
|
|
33906
|
+
|
|
33907
|
+
/** Chooses {@link Masked} depending on input value */
|
|
33908
|
+
|
|
33909
|
+
constructor(opts) {
|
|
33910
|
+
super({
|
|
33911
|
+
...MaskedDynamic.DEFAULTS,
|
|
33912
|
+
...opts
|
|
33913
|
+
});
|
|
33914
|
+
this.currentMask = undefined;
|
|
33480
33915
|
}
|
|
33481
|
-
|
|
33482
|
-
|
|
33916
|
+
updateOptions(opts) {
|
|
33917
|
+
super.updateOptions(opts);
|
|
33483
33918
|
}
|
|
33919
|
+
_update(opts) {
|
|
33920
|
+
super._update(opts);
|
|
33921
|
+
if ('mask' in opts) {
|
|
33922
|
+
// mask could be totally dynamic with only `dispatch` option
|
|
33923
|
+
this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(m => createMask({
|
|
33924
|
+
overwrite: this._overwrite,
|
|
33925
|
+
eager: this._eager,
|
|
33926
|
+
skipInvalid: this._skipInvalid,
|
|
33927
|
+
...normalizeOpts(m)
|
|
33928
|
+
})) : [];
|
|
33484
33929
|
|
|
33485
|
-
|
|
33486
|
-
|
|
33487
|
-
@override
|
|
33488
|
-
*/
|
|
33489
|
-
bindEvents(handlers) {
|
|
33490
|
-
Object.keys(handlers).forEach(event => this._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]));
|
|
33930
|
+
// this.currentMask = this.doDispatch(''); // probably not needed but lets see
|
|
33931
|
+
}
|
|
33491
33932
|
}
|
|
33492
33933
|
|
|
33493
|
-
|
|
33494
|
-
|
|
33495
|
-
|
|
33496
|
-
|
|
33497
|
-
|
|
33498
|
-
|
|
33934
|
+
_appendCharRaw(ch, flags) {
|
|
33935
|
+
if (flags === void 0) {
|
|
33936
|
+
flags = {};
|
|
33937
|
+
}
|
|
33938
|
+
const details = this._applyDispatch(ch, flags);
|
|
33939
|
+
if (this.currentMask) {
|
|
33940
|
+
details.aggregate(this.currentMask._appendChar(ch, this.currentMaskFlags(flags)));
|
|
33941
|
+
}
|
|
33942
|
+
return details;
|
|
33499
33943
|
}
|
|
33500
|
-
|
|
33501
|
-
|
|
33502
|
-
|
|
33503
|
-
if (this._handlers[event]) {
|
|
33504
|
-
this.input.removeEventListener(event, this._handlers[event]);
|
|
33505
|
-
delete this._handlers[event];
|
|
33944
|
+
_applyDispatch(appended, flags, tail) {
|
|
33945
|
+
if (appended === void 0) {
|
|
33946
|
+
appended = '';
|
|
33506
33947
|
}
|
|
33507
|
-
if (
|
|
33508
|
-
|
|
33509
|
-
|
|
33948
|
+
if (flags === void 0) {
|
|
33949
|
+
flags = {};
|
|
33950
|
+
}
|
|
33951
|
+
if (tail === void 0) {
|
|
33952
|
+
tail = '';
|
|
33953
|
+
}
|
|
33954
|
+
const prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
|
|
33955
|
+
const inputValue = this.rawInputValue;
|
|
33956
|
+
const insertValue = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._rawInputValue : inputValue;
|
|
33957
|
+
const tailValue = inputValue.slice(insertValue.length);
|
|
33958
|
+
const prevMask = this.currentMask;
|
|
33959
|
+
const details = new ChangeDetails();
|
|
33960
|
+
const prevMaskState = prevMask == null ? void 0 : prevMask.state;
|
|
33961
|
+
|
|
33962
|
+
// clone flags to prevent overwriting `_beforeTailState`
|
|
33963
|
+
this.currentMask = this.doDispatch(appended, {
|
|
33964
|
+
...flags
|
|
33965
|
+
}, tail);
|
|
33966
|
+
|
|
33967
|
+
// restore state after dispatch
|
|
33968
|
+
if (this.currentMask) {
|
|
33969
|
+
if (this.currentMask !== prevMask) {
|
|
33970
|
+
// if mask changed reapply input
|
|
33971
|
+
this.currentMask.reset();
|
|
33972
|
+
if (insertValue) {
|
|
33973
|
+
const d = this.currentMask.append(insertValue, {
|
|
33974
|
+
raw: true
|
|
33975
|
+
});
|
|
33976
|
+
details.tailShift = d.inserted.length - prevValueBeforeTail.length;
|
|
33977
|
+
}
|
|
33978
|
+
if (tailValue) {
|
|
33979
|
+
details.tailShift += this.currentMask.append(tailValue, {
|
|
33980
|
+
raw: true,
|
|
33981
|
+
tail: true
|
|
33982
|
+
}).tailShift;
|
|
33983
|
+
}
|
|
33984
|
+
} else if (prevMaskState) {
|
|
33985
|
+
// Dispatch can do something bad with state, so
|
|
33986
|
+
// restore prev mask state
|
|
33987
|
+
this.currentMask.state = prevMaskState;
|
|
33988
|
+
}
|
|
33510
33989
|
}
|
|
33990
|
+
return details;
|
|
33511
33991
|
}
|
|
33512
|
-
|
|
33513
|
-
|
|
33514
|
-
|
|
33515
|
-
|
|
33516
|
-
drop: 'drop',
|
|
33517
|
-
click: 'click',
|
|
33518
|
-
focus: 'focus',
|
|
33519
|
-
commit: 'blur'
|
|
33520
|
-
};
|
|
33521
|
-
IMask.HTMLMaskElement = HTMLMaskElement;
|
|
33522
|
-
|
|
33523
|
-
class HTMLContenteditableMaskElement extends HTMLMaskElement {
|
|
33524
|
-
/**
|
|
33525
|
-
Returns HTMLElement selection start
|
|
33526
|
-
@override
|
|
33527
|
-
*/
|
|
33528
|
-
get _unsafeSelectionStart() {
|
|
33529
|
-
const root = this.rootElement;
|
|
33530
|
-
const selection = root.getSelection && root.getSelection();
|
|
33531
|
-
const anchorOffset = selection && selection.anchorOffset;
|
|
33532
|
-
const focusOffset = selection && selection.focusOffset;
|
|
33533
|
-
if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
|
|
33534
|
-
return anchorOffset;
|
|
33992
|
+
_appendPlaceholder() {
|
|
33993
|
+
const details = this._applyDispatch();
|
|
33994
|
+
if (this.currentMask) {
|
|
33995
|
+
details.aggregate(this.currentMask._appendPlaceholder());
|
|
33535
33996
|
}
|
|
33536
|
-
return
|
|
33997
|
+
return details;
|
|
33537
33998
|
}
|
|
33538
|
-
|
|
33539
|
-
|
|
33540
|
-
|
|
33541
|
-
|
|
33542
|
-
*/
|
|
33543
|
-
get _unsafeSelectionEnd() {
|
|
33544
|
-
const root = this.rootElement;
|
|
33545
|
-
const selection = root.getSelection && root.getSelection();
|
|
33546
|
-
const anchorOffset = selection && selection.anchorOffset;
|
|
33547
|
-
const focusOffset = selection && selection.focusOffset;
|
|
33548
|
-
if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
|
|
33549
|
-
return anchorOffset;
|
|
33999
|
+
_appendEager() {
|
|
34000
|
+
const details = this._applyDispatch();
|
|
34001
|
+
if (this.currentMask) {
|
|
34002
|
+
details.aggregate(this.currentMask._appendEager());
|
|
33550
34003
|
}
|
|
33551
|
-
return
|
|
34004
|
+
return details;
|
|
33552
34005
|
}
|
|
33553
|
-
|
|
33554
|
-
|
|
33555
|
-
|
|
33556
|
-
|
|
33557
|
-
|
|
33558
|
-
|
|
33559
|
-
|
|
33560
|
-
|
|
33561
|
-
|
|
33562
|
-
|
|
33563
|
-
|
|
33564
|
-
|
|
33565
|
-
|
|
33566
|
-
|
|
33567
|
-
|
|
34006
|
+
appendTail(tail) {
|
|
34007
|
+
const details = new ChangeDetails();
|
|
34008
|
+
if (tail) details.aggregate(this._applyDispatch('', {}, tail));
|
|
34009
|
+
return details.aggregate(this.currentMask ? this.currentMask.appendTail(tail) : super.appendTail(tail));
|
|
34010
|
+
}
|
|
34011
|
+
currentMaskFlags(flags) {
|
|
34012
|
+
var _flags$_beforeTailSta, _flags$_beforeTailSta2;
|
|
34013
|
+
return {
|
|
34014
|
+
...flags,
|
|
34015
|
+
_beforeTailState: ((_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.currentMaskRef) === this.currentMask && ((_flags$_beforeTailSta2 = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta2.currentMask) || flags._beforeTailState
|
|
34016
|
+
};
|
|
34017
|
+
}
|
|
34018
|
+
doDispatch(appended, flags, tail) {
|
|
34019
|
+
if (flags === void 0) {
|
|
34020
|
+
flags = {};
|
|
34021
|
+
}
|
|
34022
|
+
if (tail === void 0) {
|
|
34023
|
+
tail = '';
|
|
33568
34024
|
}
|
|
34025
|
+
return this.dispatch(appended, this, flags, tail);
|
|
34026
|
+
}
|
|
34027
|
+
doValidate(flags) {
|
|
34028
|
+
return super.doValidate(flags) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(flags)));
|
|
34029
|
+
}
|
|
34030
|
+
doPrepare(str, flags) {
|
|
34031
|
+
if (flags === void 0) {
|
|
34032
|
+
flags = {};
|
|
34033
|
+
}
|
|
34034
|
+
let [s, details] = super.doPrepare(str, flags);
|
|
34035
|
+
if (this.currentMask) {
|
|
34036
|
+
let currentDetails;
|
|
34037
|
+
[s, currentDetails] = super.doPrepare(s, this.currentMaskFlags(flags));
|
|
34038
|
+
details = details.aggregate(currentDetails);
|
|
34039
|
+
}
|
|
34040
|
+
return [s, details];
|
|
34041
|
+
}
|
|
34042
|
+
doPrepareChar(str, flags) {
|
|
34043
|
+
if (flags === void 0) {
|
|
34044
|
+
flags = {};
|
|
34045
|
+
}
|
|
34046
|
+
let [s, details] = super.doPrepareChar(str, flags);
|
|
34047
|
+
if (this.currentMask) {
|
|
34048
|
+
let currentDetails;
|
|
34049
|
+
[s, currentDetails] = super.doPrepareChar(s, this.currentMaskFlags(flags));
|
|
34050
|
+
details = details.aggregate(currentDetails);
|
|
34051
|
+
}
|
|
34052
|
+
return [s, details];
|
|
34053
|
+
}
|
|
34054
|
+
reset() {
|
|
34055
|
+
var _this$currentMask;
|
|
34056
|
+
(_this$currentMask = this.currentMask) == null ? void 0 : _this$currentMask.reset();
|
|
34057
|
+
this.compiledMasks.forEach(m => m.reset());
|
|
33569
34058
|
}
|
|
33570
|
-
|
|
33571
|
-
/**
|
|
33572
|
-
HTMLElement value
|
|
33573
|
-
@override
|
|
33574
|
-
*/
|
|
33575
34059
|
get value() {
|
|
33576
|
-
|
|
33577
|
-
return this.input.textContent;
|
|
34060
|
+
return this.currentMask ? this.currentMask.value : '';
|
|
33578
34061
|
}
|
|
33579
34062
|
set value(value) {
|
|
33580
|
-
|
|
34063
|
+
super.value = value;
|
|
34064
|
+
}
|
|
34065
|
+
get unmaskedValue() {
|
|
34066
|
+
return this.currentMask ? this.currentMask.unmaskedValue : '';
|
|
34067
|
+
}
|
|
34068
|
+
set unmaskedValue(unmaskedValue) {
|
|
34069
|
+
super.unmaskedValue = unmaskedValue;
|
|
34070
|
+
}
|
|
34071
|
+
get typedValue() {
|
|
34072
|
+
return this.currentMask ? this.currentMask.typedValue : '';
|
|
33581
34073
|
}
|
|
33582
|
-
}
|
|
33583
|
-
IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
|
|
33584
|
-
|
|
33585
|
-
const _excluded$1 = ["mask"];
|
|
33586
|
-
|
|
33587
|
-
/** Listens to element events and controls changes between element and {@link Masked} */
|
|
33588
|
-
class InputMask {
|
|
33589
|
-
/**
|
|
33590
|
-
View element
|
|
33591
|
-
@readonly
|
|
33592
|
-
*/
|
|
33593
|
-
|
|
33594
|
-
/**
|
|
33595
|
-
Internal {@link Masked} model
|
|
33596
|
-
@readonly
|
|
33597
|
-
*/
|
|
33598
34074
|
|
|
33599
|
-
|
|
33600
|
-
|
|
33601
|
-
|
|
33602
|
-
*/
|
|
33603
|
-
constructor(el, opts) {
|
|
33604
|
-
this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLMaskElement(el);
|
|
33605
|
-
this.masked = createMask(opts);
|
|
33606
|
-
this._listeners = {};
|
|
33607
|
-
this._value = '';
|
|
33608
|
-
this._unmaskedValue = '';
|
|
33609
|
-
this._saveSelection = this._saveSelection.bind(this);
|
|
33610
|
-
this._onInput = this._onInput.bind(this);
|
|
33611
|
-
this._onChange = this._onChange.bind(this);
|
|
33612
|
-
this._onDrop = this._onDrop.bind(this);
|
|
33613
|
-
this._onFocus = this._onFocus.bind(this);
|
|
33614
|
-
this._onClick = this._onClick.bind(this);
|
|
33615
|
-
this.alignCursor = this.alignCursor.bind(this);
|
|
33616
|
-
this.alignCursorFriendly = this.alignCursorFriendly.bind(this);
|
|
33617
|
-
this._bindEvents();
|
|
34075
|
+
// probably typedValue should not be used with dynamic
|
|
34076
|
+
set typedValue(value) {
|
|
34077
|
+
let unmaskedValue = String(value);
|
|
33618
34078
|
|
|
33619
|
-
//
|
|
33620
|
-
this.
|
|
33621
|
-
|
|
34079
|
+
// double check it
|
|
34080
|
+
if (this.currentMask) {
|
|
34081
|
+
this.currentMask.typedValue = value;
|
|
34082
|
+
unmaskedValue = this.currentMask.unmaskedValue;
|
|
34083
|
+
}
|
|
34084
|
+
this.unmaskedValue = unmaskedValue;
|
|
33622
34085
|
}
|
|
33623
|
-
|
|
33624
|
-
|
|
33625
|
-
get mask() {
|
|
33626
|
-
return this.masked.mask;
|
|
34086
|
+
get displayValue() {
|
|
34087
|
+
return this.currentMask ? this.currentMask.displayValue : '';
|
|
33627
34088
|
}
|
|
33628
|
-
|
|
33629
|
-
var _this$
|
|
33630
|
-
return
|
|
34089
|
+
get isComplete() {
|
|
34090
|
+
var _this$currentMask2;
|
|
34091
|
+
return Boolean((_this$currentMask2 = this.currentMask) == null ? void 0 : _this$currentMask2.isComplete);
|
|
33631
34092
|
}
|
|
33632
|
-
|
|
33633
|
-
|
|
33634
|
-
|
|
33635
|
-
|
|
33636
|
-
|
|
33637
|
-
|
|
33638
|
-
|
|
33639
|
-
|
|
33640
|
-
|
|
34093
|
+
get isFilled() {
|
|
34094
|
+
var _this$currentMask3;
|
|
34095
|
+
return Boolean((_this$currentMask3 = this.currentMask) == null ? void 0 : _this$currentMask3.isFilled);
|
|
34096
|
+
}
|
|
34097
|
+
remove(fromPos, toPos) {
|
|
34098
|
+
const details = new ChangeDetails();
|
|
34099
|
+
if (this.currentMask) {
|
|
34100
|
+
details.aggregate(this.currentMask.remove(fromPos, toPos))
|
|
34101
|
+
// update with dispatch
|
|
34102
|
+
.aggregate(this._applyDispatch());
|
|
33641
34103
|
}
|
|
33642
|
-
|
|
33643
|
-
mask
|
|
33644
|
-
});
|
|
33645
|
-
masked.unmaskedValue = this.masked.unmaskedValue;
|
|
33646
|
-
this.masked = masked;
|
|
34104
|
+
return details;
|
|
33647
34105
|
}
|
|
33648
|
-
|
|
33649
|
-
|
|
33650
|
-
|
|
33651
|
-
|
|
34106
|
+
get state() {
|
|
34107
|
+
var _this$currentMask4;
|
|
34108
|
+
return {
|
|
34109
|
+
...super.state,
|
|
34110
|
+
_rawInputValue: this.rawInputValue,
|
|
34111
|
+
compiledMasks: this.compiledMasks.map(m => m.state),
|
|
34112
|
+
currentMaskRef: this.currentMask,
|
|
34113
|
+
currentMask: (_this$currentMask4 = this.currentMask) == null ? void 0 : _this$currentMask4.state
|
|
34114
|
+
};
|
|
33652
34115
|
}
|
|
33653
|
-
set
|
|
33654
|
-
|
|
33655
|
-
|
|
33656
|
-
|
|
33657
|
-
|
|
34116
|
+
set state(state) {
|
|
34117
|
+
const {
|
|
34118
|
+
compiledMasks,
|
|
34119
|
+
currentMaskRef,
|
|
34120
|
+
currentMask,
|
|
34121
|
+
...maskedState
|
|
34122
|
+
} = state;
|
|
34123
|
+
if (compiledMasks) this.compiledMasks.forEach((m, mi) => m.state = compiledMasks[mi]);
|
|
34124
|
+
if (currentMaskRef != null) {
|
|
34125
|
+
this.currentMask = currentMaskRef;
|
|
34126
|
+
this.currentMask.state = currentMask;
|
|
34127
|
+
}
|
|
34128
|
+
super.state = maskedState;
|
|
33658
34129
|
}
|
|
33659
|
-
|
|
33660
|
-
|
|
33661
|
-
get unmaskedValue() {
|
|
33662
|
-
return this._unmaskedValue;
|
|
34130
|
+
extractInput(fromPos, toPos, flags) {
|
|
34131
|
+
return this.currentMask ? this.currentMask.extractInput(fromPos, toPos, flags) : '';
|
|
33663
34132
|
}
|
|
33664
|
-
|
|
33665
|
-
|
|
33666
|
-
this.masked.unmaskedValue = str;
|
|
33667
|
-
this.updateControl();
|
|
33668
|
-
this.alignCursor();
|
|
34133
|
+
extractTail(fromPos, toPos) {
|
|
34134
|
+
return this.currentMask ? this.currentMask.extractTail(fromPos, toPos) : super.extractTail(fromPos, toPos);
|
|
33669
34135
|
}
|
|
33670
|
-
|
|
33671
|
-
|
|
33672
|
-
|
|
33673
|
-
return this.masked.typedValue;
|
|
34136
|
+
doCommit() {
|
|
34137
|
+
if (this.currentMask) this.currentMask.doCommit();
|
|
34138
|
+
super.doCommit();
|
|
33674
34139
|
}
|
|
33675
|
-
|
|
33676
|
-
|
|
33677
|
-
this.masked.typedValue = val;
|
|
33678
|
-
this.updateControl();
|
|
33679
|
-
this.alignCursor();
|
|
34140
|
+
nearestInputPos(cursorPos, direction) {
|
|
34141
|
+
return this.currentMask ? this.currentMask.nearestInputPos(cursorPos, direction) : super.nearestInputPos(cursorPos, direction);
|
|
33680
34142
|
}
|
|
33681
|
-
|
|
33682
|
-
|
|
33683
|
-
|
|
33684
|
-
|
|
34143
|
+
get overwrite() {
|
|
34144
|
+
return this.currentMask ? this.currentMask.overwrite : this._overwrite;
|
|
34145
|
+
}
|
|
34146
|
+
set overwrite(overwrite) {
|
|
34147
|
+
this._overwrite = overwrite;
|
|
34148
|
+
}
|
|
34149
|
+
get eager() {
|
|
34150
|
+
return this.currentMask ? this.currentMask.eager : this._eager;
|
|
34151
|
+
}
|
|
34152
|
+
set eager(eager) {
|
|
34153
|
+
this._eager = eager;
|
|
34154
|
+
}
|
|
34155
|
+
get skipInvalid() {
|
|
34156
|
+
return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
|
|
33685
34157
|
}
|
|
34158
|
+
set skipInvalid(skipInvalid) {
|
|
34159
|
+
this._skipInvalid = skipInvalid;
|
|
34160
|
+
}
|
|
34161
|
+
maskEquals(mask) {
|
|
34162
|
+
return Array.isArray(mask) ? this.compiledMasks.every((m, mi) => {
|
|
34163
|
+
if (!mask[mi]) return;
|
|
34164
|
+
const {
|
|
34165
|
+
mask: oldMask,
|
|
34166
|
+
...restOpts
|
|
34167
|
+
} = mask[mi];
|
|
34168
|
+
return objectIncludes(m, restOpts) && m.maskEquals(oldMask);
|
|
34169
|
+
}) : super.maskEquals(mask);
|
|
34170
|
+
}
|
|
34171
|
+
typedValueEquals(value) {
|
|
34172
|
+
var _this$currentMask5;
|
|
34173
|
+
return Boolean((_this$currentMask5 = this.currentMask) == null ? void 0 : _this$currentMask5.typedValueEquals(value));
|
|
34174
|
+
}
|
|
34175
|
+
}
|
|
34176
|
+
MaskedDynamic.DEFAULTS = void 0;
|
|
34177
|
+
MaskedDynamic.DEFAULTS = {
|
|
34178
|
+
dispatch: (appended, masked, flags, tail) => {
|
|
34179
|
+
if (!masked.compiledMasks.length) return;
|
|
34180
|
+
const inputValue = masked.rawInputValue;
|
|
33686
34181
|
|
|
33687
|
-
|
|
33688
|
-
|
|
33689
|
-
|
|
33690
|
-
|
|
33691
|
-
|
|
33692
|
-
|
|
33693
|
-
|
|
33694
|
-
|
|
33695
|
-
|
|
33696
|
-
|
|
33697
|
-
|
|
33698
|
-
|
|
34182
|
+
// simulate input
|
|
34183
|
+
const inputs = masked.compiledMasks.map((m, index) => {
|
|
34184
|
+
const isCurrent = masked.currentMask === m;
|
|
34185
|
+
const startInputPos = isCurrent ? m.value.length : m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT);
|
|
34186
|
+
if (m.rawInputValue !== inputValue) {
|
|
34187
|
+
m.reset();
|
|
34188
|
+
m.append(inputValue, {
|
|
34189
|
+
raw: true
|
|
34190
|
+
});
|
|
34191
|
+
} else if (!isCurrent) {
|
|
34192
|
+
m.remove(startInputPos);
|
|
34193
|
+
}
|
|
34194
|
+
m.append(appended, masked.currentMaskFlags(flags));
|
|
34195
|
+
m.appendTail(tail);
|
|
34196
|
+
return {
|
|
34197
|
+
index,
|
|
34198
|
+
weight: m.rawInputValue.length,
|
|
34199
|
+
totalInputPositions: m.totalInputPositions(0, Math.max(startInputPos, m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT)))
|
|
34200
|
+
};
|
|
33699
34201
|
});
|
|
33700
|
-
}
|
|
33701
34202
|
|
|
33702
|
-
|
|
33703
|
-
|
|
33704
|
-
|
|
33705
|
-
*/
|
|
33706
|
-
_unbindEvents() {
|
|
33707
|
-
if (this.el) this.el.unbindEvents();
|
|
34203
|
+
// pop masks with longer values first
|
|
34204
|
+
inputs.sort((i1, i2) => i2.weight - i1.weight || i2.totalInputPositions - i1.totalInputPositions);
|
|
34205
|
+
return masked.compiledMasks[inputs[0].index];
|
|
33708
34206
|
}
|
|
34207
|
+
};
|
|
34208
|
+
IMask.MaskedDynamic = MaskedDynamic;
|
|
33709
34209
|
|
|
33710
|
-
|
|
33711
|
-
|
|
33712
|
-
|
|
33713
|
-
|
|
33714
|
-
|
|
33715
|
-
|
|
33716
|
-
|
|
34210
|
+
/** Pattern which validates enum values */
|
|
34211
|
+
class MaskedEnum extends MaskedPattern {
|
|
34212
|
+
updateOptions(opts) {
|
|
34213
|
+
super.updateOptions(opts);
|
|
34214
|
+
}
|
|
34215
|
+
_update(opts) {
|
|
34216
|
+
const {
|
|
34217
|
+
enum: _enum,
|
|
34218
|
+
...eopts
|
|
34219
|
+
} = opts;
|
|
34220
|
+
if (_enum) {
|
|
34221
|
+
eopts.mask = '*'.repeat(_enum[0].length);
|
|
34222
|
+
this.enum = _enum;
|
|
33717
34223
|
}
|
|
33718
|
-
|
|
33719
|
-
if (!listeners) return;
|
|
33720
|
-
listeners.forEach(l => l(...args));
|
|
34224
|
+
super._update(eopts);
|
|
33721
34225
|
}
|
|
33722
|
-
|
|
33723
|
-
|
|
33724
|
-
Current selection start
|
|
33725
|
-
@readonly
|
|
33726
|
-
*/
|
|
33727
|
-
get selectionStart() {
|
|
33728
|
-
return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
|
|
34226
|
+
doValidate(flags) {
|
|
34227
|
+
return this.enum.some(e => e.indexOf(this.unmaskedValue) >= 0) && super.doValidate(flags);
|
|
33729
34228
|
}
|
|
34229
|
+
}
|
|
34230
|
+
IMask.MaskedEnum = MaskedEnum;
|
|
33730
34231
|
|
|
33731
|
-
|
|
33732
|
-
|
|
33733
|
-
|
|
34232
|
+
/** Masking by custom Function */
|
|
34233
|
+
class MaskedFunction extends Masked {
|
|
34234
|
+
/** */
|
|
34235
|
+
|
|
34236
|
+
/** Enable characters overwriting */
|
|
34237
|
+
|
|
34238
|
+
/** */
|
|
34239
|
+
|
|
34240
|
+
/** */
|
|
34241
|
+
|
|
34242
|
+
updateOptions(opts) {
|
|
34243
|
+
super.updateOptions(opts);
|
|
33734
34244
|
}
|
|
33735
|
-
|
|
33736
|
-
|
|
33737
|
-
|
|
33738
|
-
|
|
34245
|
+
_update(opts) {
|
|
34246
|
+
super._update({
|
|
34247
|
+
...opts,
|
|
34248
|
+
validate: opts.mask
|
|
34249
|
+
});
|
|
33739
34250
|
}
|
|
34251
|
+
}
|
|
34252
|
+
IMask.MaskedFunction = MaskedFunction;
|
|
33740
34253
|
|
|
33741
|
-
|
|
33742
|
-
|
|
33743
|
-
|
|
33744
|
-
|
|
33745
|
-
|
|
33746
|
-
) {
|
|
33747
|
-
if (this.displayValue !== this.el.value) {
|
|
33748
|
-
console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console
|
|
33749
|
-
}
|
|
34254
|
+
/**
|
|
34255
|
+
Number mask
|
|
34256
|
+
*/
|
|
34257
|
+
class MaskedNumber extends Masked {
|
|
34258
|
+
/** Single char */
|
|
33750
34259
|
|
|
33751
|
-
|
|
33752
|
-
start: this.selectionStart,
|
|
33753
|
-
end: this.cursorPos
|
|
33754
|
-
};
|
|
33755
|
-
}
|
|
34260
|
+
/** Single char */
|
|
33756
34261
|
|
|
33757
|
-
/**
|
|
33758
|
-
updateValue() {
|
|
33759
|
-
this.masked.value = this.el.value;
|
|
33760
|
-
this._value = this.masked.value;
|
|
33761
|
-
}
|
|
34262
|
+
/** Array of single chars */
|
|
33762
34263
|
|
|
33763
|
-
/**
|
|
33764
|
-
updateControl() {
|
|
33765
|
-
const newUnmaskedValue = this.masked.unmaskedValue;
|
|
33766
|
-
const newValue = this.masked.value;
|
|
33767
|
-
const newDisplayValue = this.displayValue;
|
|
33768
|
-
const isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue;
|
|
33769
|
-
this._unmaskedValue = newUnmaskedValue;
|
|
33770
|
-
this._value = newValue;
|
|
33771
|
-
if (this.el.value !== newDisplayValue) this.el.value = newDisplayValue;
|
|
33772
|
-
if (isChanged) this._fireChangeEvents();
|
|
33773
|
-
}
|
|
34264
|
+
/** */
|
|
33774
34265
|
|
|
33775
|
-
/**
|
|
33776
|
-
updateOptions(opts) {
|
|
33777
|
-
const {
|
|
33778
|
-
mask
|
|
33779
|
-
} = opts,
|
|
33780
|
-
restOpts = _objectWithoutPropertiesLoose(opts, _excluded$1);
|
|
33781
|
-
const updateMask = !this.maskEquals(mask);
|
|
33782
|
-
const updateOpts = !objectIncludes(this.masked, restOpts);
|
|
33783
|
-
if (updateMask) this.mask = mask;
|
|
33784
|
-
if (updateOpts) this.masked.updateOptions(restOpts);
|
|
33785
|
-
if (updateMask || updateOpts) this.updateControl();
|
|
33786
|
-
}
|
|
34266
|
+
/** */
|
|
33787
34267
|
|
|
33788
|
-
/**
|
|
33789
|
-
updateCursor(cursorPos) {
|
|
33790
|
-
if (cursorPos == null) return;
|
|
33791
|
-
this.cursorPos = cursorPos;
|
|
34268
|
+
/** Digits after point */
|
|
33792
34269
|
|
|
33793
|
-
|
|
33794
|
-
this._delayUpdateCursor(cursorPos);
|
|
33795
|
-
}
|
|
34270
|
+
/** Flag to remove leading and trailing zeros in the end of editing */
|
|
33796
34271
|
|
|
33797
|
-
/**
|
|
33798
|
-
Delays cursor update to support mobile browsers
|
|
33799
|
-
@private
|
|
33800
|
-
*/
|
|
33801
|
-
_delayUpdateCursor(cursorPos) {
|
|
33802
|
-
this._abortUpdateCursor();
|
|
33803
|
-
this._changingCursorPos = cursorPos;
|
|
33804
|
-
this._cursorChanging = setTimeout(() => {
|
|
33805
|
-
if (!this.el) return; // if was destroyed
|
|
33806
|
-
this.cursorPos = this._changingCursorPos;
|
|
33807
|
-
this._abortUpdateCursor();
|
|
33808
|
-
}, 10);
|
|
33809
|
-
}
|
|
34272
|
+
/** Flag to pad trailing zeros after point in the end of editing */
|
|
33810
34273
|
|
|
33811
|
-
/**
|
|
33812
|
-
Fires custom events
|
|
33813
|
-
@protected
|
|
33814
|
-
*/
|
|
33815
|
-
_fireChangeEvents() {
|
|
33816
|
-
this._fireEvent('accept', this._inputEvent);
|
|
33817
|
-
if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
|
|
33818
|
-
}
|
|
34274
|
+
/** Enable characters overwriting */
|
|
33819
34275
|
|
|
33820
|
-
/**
|
|
33821
|
-
Aborts delayed cursor update
|
|
33822
|
-
@private
|
|
33823
|
-
*/
|
|
33824
|
-
_abortUpdateCursor() {
|
|
33825
|
-
if (this._cursorChanging) {
|
|
33826
|
-
clearTimeout(this._cursorChanging);
|
|
33827
|
-
delete this._cursorChanging;
|
|
33828
|
-
}
|
|
33829
|
-
}
|
|
34276
|
+
/** */
|
|
33830
34277
|
|
|
33831
|
-
/**
|
|
33832
|
-
alignCursor() {
|
|
33833
|
-
this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
|
|
33834
|
-
}
|
|
34278
|
+
/** */
|
|
33835
34279
|
|
|
33836
|
-
/**
|
|
33837
|
-
alignCursorFriendly() {
|
|
33838
|
-
if (this.selectionStart !== this.cursorPos) return; // skip if range is selected
|
|
33839
|
-
this.alignCursor();
|
|
33840
|
-
}
|
|
34280
|
+
/** Format typed value to string */
|
|
33841
34281
|
|
|
33842
|
-
/**
|
|
33843
|
-
on(ev, handler) {
|
|
33844
|
-
if (!this._listeners[ev]) this._listeners[ev] = [];
|
|
33845
|
-
this._listeners[ev].push(handler);
|
|
33846
|
-
return this;
|
|
33847
|
-
}
|
|
34282
|
+
/** Parse string to get typed value */
|
|
33848
34283
|
|
|
33849
|
-
|
|
33850
|
-
|
|
33851
|
-
|
|
33852
|
-
|
|
33853
|
-
|
|
33854
|
-
|
|
34284
|
+
constructor(opts) {
|
|
34285
|
+
super({
|
|
34286
|
+
...MaskedNumber.DEFAULTS,
|
|
34287
|
+
...opts
|
|
34288
|
+
});
|
|
34289
|
+
}
|
|
34290
|
+
updateOptions(opts) {
|
|
34291
|
+
super.updateOptions(opts);
|
|
34292
|
+
}
|
|
34293
|
+
_update(opts) {
|
|
34294
|
+
super._update(opts);
|
|
34295
|
+
this._updateRegExps();
|
|
34296
|
+
}
|
|
34297
|
+
_updateRegExps() {
|
|
34298
|
+
const start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
|
|
34299
|
+
const mid = '\\d*';
|
|
34300
|
+
const end = (this.scale ? "(" + escapeRegExp(this.radix) + "\\d{0," + this.scale + "})?" : '') + '$';
|
|
34301
|
+
this._numberRegExp = new RegExp(start + mid + end);
|
|
34302
|
+
this._mapToRadixRegExp = new RegExp("[" + this.mapToRadix.map(escapeRegExp).join('') + "]", 'g');
|
|
34303
|
+
this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g');
|
|
34304
|
+
}
|
|
34305
|
+
_removeThousandsSeparators(value) {
|
|
34306
|
+
return value.replace(this._thousandsSeparatorRegExp, '');
|
|
34307
|
+
}
|
|
34308
|
+
_insertThousandsSeparators(value) {
|
|
34309
|
+
// https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
|
|
34310
|
+
const parts = value.split(this.radix);
|
|
34311
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator);
|
|
34312
|
+
return parts.join(this.radix);
|
|
34313
|
+
}
|
|
34314
|
+
doPrepareChar(ch, flags) {
|
|
34315
|
+
if (flags === void 0) {
|
|
34316
|
+
flags = {};
|
|
34317
|
+
}
|
|
34318
|
+
ch = this._removeThousandsSeparators(this.scale && this.mapToRadix.length && (
|
|
34319
|
+
/*
|
|
34320
|
+
radix should be mapped when
|
|
34321
|
+
1) input is done from keyboard = flags.input && flags.raw
|
|
34322
|
+
2) unmasked value is set = !flags.input && !flags.raw
|
|
34323
|
+
and should not be mapped when
|
|
34324
|
+
1) value is set = flags.input && !flags.raw
|
|
34325
|
+
2) raw value is set = !flags.input && flags.raw
|
|
34326
|
+
*/
|
|
34327
|
+
flags.input && flags.raw || !flags.input && !flags.raw) ? ch.replace(this._mapToRadixRegExp, this.radix) : ch);
|
|
34328
|
+
const [prepCh, details] = super.doPrepareChar(ch, flags);
|
|
34329
|
+
if (ch && !prepCh) details.skip = true;
|
|
34330
|
+
if (prepCh && !this.allowPositive && !this.value && prepCh !== '-') details.aggregate(this._appendChar('-'));
|
|
34331
|
+
return [prepCh, details];
|
|
34332
|
+
}
|
|
34333
|
+
_separatorsCount(to, extendOnSeparators) {
|
|
34334
|
+
if (extendOnSeparators === void 0) {
|
|
34335
|
+
extendOnSeparators = false;
|
|
34336
|
+
}
|
|
34337
|
+
let count = 0;
|
|
34338
|
+
for (let pos = 0; pos < to; ++pos) {
|
|
34339
|
+
if (this._value.indexOf(this.thousandsSeparator, pos) === pos) {
|
|
34340
|
+
++count;
|
|
34341
|
+
if (extendOnSeparators) to += this.thousandsSeparator.length;
|
|
34342
|
+
}
|
|
33855
34343
|
}
|
|
33856
|
-
|
|
33857
|
-
|
|
33858
|
-
|
|
34344
|
+
return count;
|
|
34345
|
+
}
|
|
34346
|
+
_separatorsCountFromSlice(slice) {
|
|
34347
|
+
if (slice === void 0) {
|
|
34348
|
+
slice = this._value;
|
|
34349
|
+
}
|
|
34350
|
+
return this._separatorsCount(this._removeThousandsSeparators(slice).length, true);
|
|
34351
|
+
}
|
|
34352
|
+
extractInput(fromPos, toPos, flags) {
|
|
34353
|
+
if (fromPos === void 0) {
|
|
34354
|
+
fromPos = 0;
|
|
34355
|
+
}
|
|
34356
|
+
if (toPos === void 0) {
|
|
34357
|
+
toPos = this.value.length;
|
|
34358
|
+
}
|
|
34359
|
+
[fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
|
|
34360
|
+
return this._removeThousandsSeparators(super.extractInput(fromPos, toPos, flags));
|
|
34361
|
+
}
|
|
34362
|
+
_appendCharRaw(ch, flags) {
|
|
34363
|
+
if (flags === void 0) {
|
|
34364
|
+
flags = {};
|
|
34365
|
+
}
|
|
34366
|
+
if (!this.thousandsSeparator) return super._appendCharRaw(ch, flags);
|
|
34367
|
+
const prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
|
|
34368
|
+
const prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
|
|
34369
|
+
this._value = this._removeThousandsSeparators(this.value);
|
|
34370
|
+
const appendDetails = super._appendCharRaw(ch, flags);
|
|
34371
|
+
this._value = this._insertThousandsSeparators(this._value);
|
|
34372
|
+
const beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
|
|
34373
|
+
const beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
|
|
34374
|
+
appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length;
|
|
34375
|
+
appendDetails.skip = !appendDetails.rawInserted && ch === this.thousandsSeparator;
|
|
34376
|
+
return appendDetails;
|
|
34377
|
+
}
|
|
34378
|
+
_findSeparatorAround(pos) {
|
|
34379
|
+
if (this.thousandsSeparator) {
|
|
34380
|
+
const searchFrom = pos - this.thousandsSeparator.length + 1;
|
|
34381
|
+
const separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom);
|
|
34382
|
+
if (separatorPos <= pos) return separatorPos;
|
|
34383
|
+
}
|
|
34384
|
+
return -1;
|
|
34385
|
+
}
|
|
34386
|
+
_adjustRangeWithSeparators(from, to) {
|
|
34387
|
+
const separatorAroundFromPos = this._findSeparatorAround(from);
|
|
34388
|
+
if (separatorAroundFromPos >= 0) from = separatorAroundFromPos;
|
|
34389
|
+
const separatorAroundToPos = this._findSeparatorAround(to);
|
|
34390
|
+
if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length;
|
|
34391
|
+
return [from, to];
|
|
34392
|
+
}
|
|
34393
|
+
remove(fromPos, toPos) {
|
|
34394
|
+
if (fromPos === void 0) {
|
|
34395
|
+
fromPos = 0;
|
|
34396
|
+
}
|
|
34397
|
+
if (toPos === void 0) {
|
|
34398
|
+
toPos = this.value.length;
|
|
34399
|
+
}
|
|
34400
|
+
[fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
|
|
34401
|
+
const valueBeforePos = this.value.slice(0, fromPos);
|
|
34402
|
+
const valueAfterPos = this.value.slice(toPos);
|
|
34403
|
+
const prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
|
|
34404
|
+
this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos));
|
|
34405
|
+
const beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
|
|
34406
|
+
return new ChangeDetails({
|
|
34407
|
+
tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length
|
|
34408
|
+
});
|
|
33859
34409
|
}
|
|
34410
|
+
nearestInputPos(cursorPos, direction) {
|
|
34411
|
+
if (!this.thousandsSeparator) return cursorPos;
|
|
34412
|
+
switch (direction) {
|
|
34413
|
+
case DIRECTION.NONE:
|
|
34414
|
+
case DIRECTION.LEFT:
|
|
34415
|
+
case DIRECTION.FORCE_LEFT:
|
|
34416
|
+
{
|
|
34417
|
+
const separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
|
|
34418
|
+
if (separatorAtLeftPos >= 0) {
|
|
34419
|
+
const separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
|
|
34420
|
+
if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) {
|
|
34421
|
+
return separatorAtLeftPos;
|
|
34422
|
+
}
|
|
34423
|
+
}
|
|
34424
|
+
break;
|
|
34425
|
+
}
|
|
34426
|
+
case DIRECTION.RIGHT:
|
|
34427
|
+
case DIRECTION.FORCE_RIGHT:
|
|
34428
|
+
{
|
|
34429
|
+
const separatorAtRightPos = this._findSeparatorAround(cursorPos);
|
|
34430
|
+
if (separatorAtRightPos >= 0) {
|
|
34431
|
+
return separatorAtRightPos + this.thousandsSeparator.length;
|
|
34432
|
+
}
|
|
34433
|
+
}
|
|
34434
|
+
}
|
|
34435
|
+
return cursorPos;
|
|
34436
|
+
}
|
|
34437
|
+
doValidate(flags) {
|
|
34438
|
+
// validate as string
|
|
34439
|
+
let valid = Boolean(this._removeThousandsSeparators(this.value).match(this._numberRegExp));
|
|
34440
|
+
if (valid) {
|
|
34441
|
+
// validate as number
|
|
34442
|
+
const number = this.number;
|
|
34443
|
+
valid = valid && !isNaN(number) && (
|
|
34444
|
+
// check min bound for negative values
|
|
34445
|
+
this.min == null || this.min >= 0 || this.min <= this.number) && (
|
|
34446
|
+
// check max bound for positive values
|
|
34447
|
+
this.max == null || this.max <= 0 || this.number <= this.max);
|
|
34448
|
+
}
|
|
34449
|
+
return valid && super.doValidate(flags);
|
|
34450
|
+
}
|
|
34451
|
+
doCommit() {
|
|
34452
|
+
if (this.value) {
|
|
34453
|
+
const number = this.number;
|
|
34454
|
+
let validnum = number;
|
|
34455
|
+
|
|
34456
|
+
// check bounds
|
|
34457
|
+
if (this.min != null) validnum = Math.max(validnum, this.min);
|
|
34458
|
+
if (this.max != null) validnum = Math.min(validnum, this.max);
|
|
34459
|
+
if (validnum !== number) this.unmaskedValue = this.format(validnum, this);
|
|
34460
|
+
let formatted = this.value;
|
|
34461
|
+
if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);
|
|
34462
|
+
if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted);
|
|
34463
|
+
this._value = formatted;
|
|
34464
|
+
}
|
|
34465
|
+
super.doCommit();
|
|
34466
|
+
}
|
|
34467
|
+
_normalizeZeros(value) {
|
|
34468
|
+
const parts = this._removeThousandsSeparators(value).split(this.radix);
|
|
33860
34469
|
|
|
33861
|
-
|
|
33862
|
-
|
|
33863
|
-
|
|
33864
|
-
|
|
33865
|
-
|
|
33866
|
-
|
|
33867
|
-
|
|
33868
|
-
|
|
33869
|
-
// new state
|
|
33870
|
-
this.el.value, this.cursorPos,
|
|
33871
|
-
// old state
|
|
33872
|
-
this.displayValue, this._selection);
|
|
33873
|
-
const oldRawValue = this.masked.rawInputValue;
|
|
33874
|
-
const offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
|
|
33875
|
-
input: true,
|
|
33876
|
-
raw: true
|
|
33877
|
-
}).offset;
|
|
34470
|
+
// remove leading zeros
|
|
34471
|
+
parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, (match, sign, zeros, num) => sign + num);
|
|
34472
|
+
// add leading zero
|
|
34473
|
+
if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0';
|
|
34474
|
+
if (parts.length > 1) {
|
|
34475
|
+
parts[1] = parts[1].replace(/0*$/, ''); // remove trailing zeros
|
|
34476
|
+
if (!parts[1].length) parts.length = 1; // remove fractional
|
|
34477
|
+
}
|
|
33878
34478
|
|
|
33879
|
-
|
|
33880
|
-
// otherwise we still need to align with NONE (to get out from fixed symbols for instance)
|
|
33881
|
-
const removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
|
|
33882
|
-
let cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
|
|
33883
|
-
if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);
|
|
33884
|
-
this.updateControl();
|
|
33885
|
-
this.updateCursor(cursorPos);
|
|
33886
|
-
delete this._inputEvent;
|
|
34479
|
+
return this._insertThousandsSeparators(parts.join(this.radix));
|
|
33887
34480
|
}
|
|
33888
|
-
|
|
33889
|
-
|
|
33890
|
-
|
|
33891
|
-
if (
|
|
33892
|
-
|
|
34481
|
+
_padFractionalZeros(value) {
|
|
34482
|
+
if (!value) return value;
|
|
34483
|
+
const parts = value.split(this.radix);
|
|
34484
|
+
if (parts.length < 2) parts.push('');
|
|
34485
|
+
parts[1] = parts[1].padEnd(this.scale, '0');
|
|
34486
|
+
return parts.join(this.radix);
|
|
34487
|
+
}
|
|
34488
|
+
doSkipInvalid(ch, flags, checkTail) {
|
|
34489
|
+
if (flags === void 0) {
|
|
34490
|
+
flags = {};
|
|
33893
34491
|
}
|
|
33894
|
-
this.
|
|
33895
|
-
|
|
33896
|
-
this._saveSelection();
|
|
34492
|
+
const dropFractional = this.scale === 0 && ch !== this.thousandsSeparator && (ch === this.radix || ch === MaskedNumber.UNMASKED_RADIX || this.mapToRadix.includes(ch));
|
|
34493
|
+
return super.doSkipInvalid(ch, flags, checkTail) && !dropFractional;
|
|
33897
34494
|
}
|
|
33898
|
-
|
|
33899
|
-
|
|
33900
|
-
|
|
33901
|
-
|
|
33902
|
-
|
|
34495
|
+
get unmaskedValue() {
|
|
34496
|
+
return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, MaskedNumber.UNMASKED_RADIX);
|
|
34497
|
+
}
|
|
34498
|
+
set unmaskedValue(unmaskedValue) {
|
|
34499
|
+
super.unmaskedValue = unmaskedValue;
|
|
34500
|
+
}
|
|
34501
|
+
get typedValue() {
|
|
34502
|
+
return this.parse(this.unmaskedValue, this);
|
|
34503
|
+
}
|
|
34504
|
+
set typedValue(n) {
|
|
34505
|
+
this.rawInputValue = this.format(n, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
|
|
33903
34506
|
}
|
|
33904
34507
|
|
|
33905
|
-
/**
|
|
33906
|
-
|
|
33907
|
-
this.
|
|
34508
|
+
/** Parsed Number */
|
|
34509
|
+
get number() {
|
|
34510
|
+
return this.typedValue;
|
|
34511
|
+
}
|
|
34512
|
+
set number(number) {
|
|
34513
|
+
this.typedValue = number;
|
|
33908
34514
|
}
|
|
33909
34515
|
|
|
33910
|
-
/**
|
|
33911
|
-
|
|
33912
|
-
|
|
34516
|
+
/**
|
|
34517
|
+
Is negative allowed
|
|
34518
|
+
*/
|
|
34519
|
+
get allowNegative() {
|
|
34520
|
+
return this.min != null && this.min < 0 || this.max != null && this.max < 0;
|
|
33913
34521
|
}
|
|
33914
34522
|
|
|
33915
|
-
/**
|
|
33916
|
-
|
|
33917
|
-
|
|
33918
|
-
|
|
33919
|
-
this.
|
|
33920
|
-
// $FlowFixMe
|
|
33921
|
-
delete this.el;
|
|
34523
|
+
/**
|
|
34524
|
+
Is positive allowed
|
|
34525
|
+
*/
|
|
34526
|
+
get allowPositive() {
|
|
34527
|
+
return this.min != null && this.min > 0 || this.max != null && this.max > 0;
|
|
33922
34528
|
}
|
|
34529
|
+
typedValueEquals(value) {
|
|
34530
|
+
// handle 0 -> '' case (typed = 0 even if value = '')
|
|
34531
|
+
// for details see https://github.com/uNmAnNeR/imaskjs/issues/134
|
|
34532
|
+
return (super.typedValueEquals(value) || MaskedNumber.EMPTY_VALUES.includes(value) && MaskedNumber.EMPTY_VALUES.includes(this.typedValue)) && !(value === 0 && this.value === '');
|
|
34533
|
+
}
|
|
34534
|
+
}
|
|
34535
|
+
MaskedNumber.UNMASKED_RADIX = '.';
|
|
34536
|
+
MaskedNumber.EMPTY_VALUES = [...Masked.EMPTY_VALUES, 0];
|
|
34537
|
+
MaskedNumber.DEFAULTS = {
|
|
34538
|
+
mask: Number,
|
|
34539
|
+
radix: ',',
|
|
34540
|
+
thousandsSeparator: '',
|
|
34541
|
+
mapToRadix: [MaskedNumber.UNMASKED_RADIX],
|
|
34542
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
34543
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
34544
|
+
scale: 2,
|
|
34545
|
+
normalizeZeros: true,
|
|
34546
|
+
padFractionalZeros: false,
|
|
34547
|
+
parse: Number,
|
|
34548
|
+
format: n => n.toLocaleString('en-US', {
|
|
34549
|
+
useGrouping: false,
|
|
34550
|
+
maximumFractionDigits: 20
|
|
34551
|
+
})
|
|
34552
|
+
};
|
|
34553
|
+
IMask.MaskedNumber = MaskedNumber;
|
|
34554
|
+
|
|
34555
|
+
/** Mask pipe source and destination types */
|
|
34556
|
+
const PIPE_TYPE = {
|
|
34557
|
+
MASKED: 'value',
|
|
34558
|
+
UNMASKED: 'unmaskedValue',
|
|
34559
|
+
TYPED: 'typedValue'
|
|
34560
|
+
};
|
|
34561
|
+
/** Creates new pipe function depending on mask type, source and destination options */
|
|
34562
|
+
function createPipe(arg, from, to) {
|
|
34563
|
+
if (from === void 0) {
|
|
34564
|
+
from = PIPE_TYPE.MASKED;
|
|
34565
|
+
}
|
|
34566
|
+
if (to === void 0) {
|
|
34567
|
+
to = PIPE_TYPE.MASKED;
|
|
34568
|
+
}
|
|
34569
|
+
const masked = createMask(arg);
|
|
34570
|
+
return value => masked.runIsolated(m => {
|
|
34571
|
+
m[from] = value;
|
|
34572
|
+
return m[to];
|
|
34573
|
+
});
|
|
33923
34574
|
}
|
|
33924
|
-
IMask.InputMask = InputMask;
|
|
33925
34575
|
|
|
33926
|
-
|
|
34576
|
+
/** Pipes value through mask depending on mask type, source and destination options */
|
|
34577
|
+
function pipe(value, mask, from, to) {
|
|
34578
|
+
return createPipe(mask, from, to)(value);
|
|
34579
|
+
}
|
|
34580
|
+
IMask.PIPE_TYPE = PIPE_TYPE;
|
|
34581
|
+
IMask.createPipe = createPipe;
|
|
34582
|
+
IMask.pipe = pipe;
|
|
34583
|
+
|
|
34584
|
+
try {
|
|
34585
|
+
globalThis.IMask = IMask;
|
|
34586
|
+
} catch {}
|
|
33927
34587
|
|
|
33928
34588
|
const MASK_PROPS = {
|
|
33929
34589
|
// common
|
|
@@ -33931,6 +34591,7 @@ const MASK_PROPS = {
|
|
|
33931
34591
|
value: PropTypes.any,
|
|
33932
34592
|
unmask: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['typed'])]),
|
|
33933
34593
|
prepare: PropTypes.func,
|
|
34594
|
+
prepareChar: PropTypes.func,
|
|
33934
34595
|
validate: PropTypes.func,
|
|
33935
34596
|
commit: PropTypes.func,
|
|
33936
34597
|
overwrite: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['shift'])]),
|
|
@@ -33945,6 +34606,12 @@ const MASK_PROPS = {
|
|
|
33945
34606
|
lazy: PropTypes.bool,
|
|
33946
34607
|
definitions: PropTypes.object,
|
|
33947
34608
|
blocks: PropTypes.object,
|
|
34609
|
+
// enum
|
|
34610
|
+
enum: PropTypes.arrayOf(PropTypes.string),
|
|
34611
|
+
// range
|
|
34612
|
+
maxLength: PropTypes.number,
|
|
34613
|
+
from: PropTypes.number,
|
|
34614
|
+
to: PropTypes.number,
|
|
33948
34615
|
// date
|
|
33949
34616
|
pattern: PropTypes.string,
|
|
33950
34617
|
format: PropTypes.func,
|
|
@@ -33955,7 +34622,6 @@ const MASK_PROPS = {
|
|
|
33955
34622
|
thousandsSeparator: PropTypes.string,
|
|
33956
34623
|
mapToRadix: PropTypes.arrayOf(PropTypes.string),
|
|
33957
34624
|
scale: PropTypes.number,
|
|
33958
|
-
signed: PropTypes.bool,
|
|
33959
34625
|
normalizeZeros: PropTypes.bool,
|
|
33960
34626
|
padFractionalZeros: PropTypes.bool,
|
|
33961
34627
|
min: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
|
|
@@ -33970,11 +34636,9 @@ const MASK_PROPS = {
|
|
|
33970
34636
|
const MASK_PROPS_NAMES = Object.keys(MASK_PROPS).filter(p => p !== 'value');
|
|
33971
34637
|
const NON_MASK_OPTIONS_PROPS_NAMES = ['value', 'unmask', 'onAccept', 'onComplete', 'inputRef'];
|
|
33972
34638
|
const MASK_OPTIONS_PROPS_NAMES = MASK_PROPS_NAMES.filter(pName => NON_MASK_OPTIONS_PROPS_NAMES.indexOf(pName) < 0);
|
|
33973
|
-
// TODO
|
|
33974
|
-
// 1. seems like it's wrong to have Opts as only mask options. Other component/input props should also be there. Where is "unmask" prop for instance?
|
|
33975
|
-
// 2. Unmask should be infered from Opts (see https://github.com/uNmAnNeR/imaskjs/issues/554#issuecomment-1114014010)
|
|
33976
34639
|
function IMaskMixin(ComposedComponent) {
|
|
33977
|
-
|
|
34640
|
+
var _class;
|
|
34641
|
+
const MaskedComponent = (_class = class MaskedComponent extends t.Component {
|
|
33978
34642
|
constructor(props) {
|
|
33979
34643
|
super(props);
|
|
33980
34644
|
this._inputRef = this._inputRef.bind(this);
|
|
@@ -33988,14 +34652,17 @@ function IMaskMixin(ComposedComponent) {
|
|
|
33988
34652
|
const maskOptions = this._extractMaskOptionsFromProps(props);
|
|
33989
34653
|
if (maskOptions.mask) {
|
|
33990
34654
|
if (this.maskRef) {
|
|
33991
|
-
this.maskRef.updateOptions(maskOptions);
|
|
33992
|
-
if ('value' in props) this.maskValue = props.value;
|
|
34655
|
+
this.maskRef.updateOptions(maskOptions); // TODO fix
|
|
34656
|
+
if ('value' in props && props.value !== undefined) this.maskValue = props.value;
|
|
33993
34657
|
} else {
|
|
33994
34658
|
this.initMask(maskOptions);
|
|
33995
34659
|
}
|
|
33996
34660
|
} else {
|
|
33997
34661
|
this.destroyMask();
|
|
33998
|
-
if ('value' in props
|
|
34662
|
+
if ('value' in props && props.value !== undefined) {
|
|
34663
|
+
var _this$element;
|
|
34664
|
+
if ((_this$element = this.element) != null && _this$element.isContentEditable && this.element.tagName !== 'INPUT' && this.element.tagName !== 'TEXTAREA') this.element.textContent = props.value;else this.element.value = props.value;
|
|
34665
|
+
}
|
|
33999
34666
|
}
|
|
34000
34667
|
}
|
|
34001
34668
|
componentWillUnmount() {
|
|
@@ -34007,10 +34674,12 @@ function IMaskMixin(ComposedComponent) {
|
|
|
34007
34674
|
if (Object.prototype.hasOwnProperty.call(this.props.inputRef, 'current')) this.props.inputRef.current = el;else this.props.inputRef(el);
|
|
34008
34675
|
}
|
|
34009
34676
|
}
|
|
34010
|
-
initMask() {
|
|
34011
|
-
|
|
34677
|
+
initMask(maskOptions) {
|
|
34678
|
+
if (maskOptions === void 0) {
|
|
34679
|
+
maskOptions = this._extractMaskOptionsFromProps(this.props);
|
|
34680
|
+
}
|
|
34012
34681
|
this.maskRef = IMask(this.element, maskOptions).on('accept', this._onAccept.bind(this)).on('complete', this._onComplete.bind(this));
|
|
34013
|
-
if ('value' in this.props) this.maskValue = this.props.value;
|
|
34682
|
+
if ('value' in this.props && this.props.value !== undefined) this.maskValue = this.props.value;
|
|
34014
34683
|
}
|
|
34015
34684
|
destroyMask() {
|
|
34016
34685
|
if (this.maskRef) {
|
|
@@ -34019,30 +34688,36 @@ function IMaskMixin(ComposedComponent) {
|
|
|
34019
34688
|
}
|
|
34020
34689
|
}
|
|
34021
34690
|
_extractMaskOptionsFromProps(props) {
|
|
34022
|
-
const
|
|
34691
|
+
const {
|
|
34692
|
+
...cloneProps
|
|
34693
|
+
} = props;
|
|
34023
34694
|
|
|
34024
|
-
// keep only mask options
|
|
34025
|
-
Object.keys(cloneProps)
|
|
34026
|
-
// TODO why need cast to string?
|
|
34027
|
-
.filter(prop => MASK_OPTIONS_PROPS_NAMES.indexOf(prop) < 0).forEach(nonMaskProp => {
|
|
34695
|
+
// keep only mask options
|
|
34696
|
+
Object.keys(cloneProps).filter(prop => MASK_OPTIONS_PROPS_NAMES.indexOf(prop) < 0).forEach(nonMaskProp => {
|
|
34028
34697
|
delete cloneProps[nonMaskProp];
|
|
34029
34698
|
});
|
|
34030
34699
|
return cloneProps;
|
|
34031
34700
|
}
|
|
34032
34701
|
_extractNonMaskProps(props) {
|
|
34033
|
-
const
|
|
34702
|
+
const {
|
|
34703
|
+
...cloneProps
|
|
34704
|
+
} = props;
|
|
34034
34705
|
MASK_PROPS_NAMES.forEach(maskProp => {
|
|
34035
34706
|
delete cloneProps[maskProp];
|
|
34036
34707
|
});
|
|
34708
|
+
if (!('defaultValue' in cloneProps)) cloneProps.defaultValue = props.mask ? '' : cloneProps.value;
|
|
34709
|
+
delete cloneProps.value;
|
|
34037
34710
|
return cloneProps;
|
|
34038
34711
|
}
|
|
34039
34712
|
get maskValue() {
|
|
34713
|
+
if (!this.maskRef) return '';
|
|
34040
34714
|
if (this.props.unmask === 'typed') return this.maskRef.typedValue;
|
|
34041
34715
|
if (this.props.unmask) return this.maskRef.unmaskedValue;
|
|
34042
34716
|
return this.maskRef.value;
|
|
34043
34717
|
}
|
|
34044
34718
|
set maskValue(value) {
|
|
34045
|
-
|
|
34719
|
+
if (!this.maskRef) return;
|
|
34720
|
+
value = value == null && this.props.unmask !== 'typed' ? '' : value;
|
|
34046
34721
|
if (this.props.unmask === 'typed') this.maskRef.typedValue = value;else if (this.props.unmask) this.maskRef.unmaskedValue = value;else this.maskRef.value = value;
|
|
34047
34722
|
}
|
|
34048
34723
|
_onAccept(e) {
|
|
@@ -34052,29 +34727,38 @@ function IMaskMixin(ComposedComponent) {
|
|
|
34052
34727
|
if (this.props.onComplete && this.maskRef) this.props.onComplete(this.maskValue, this.maskRef, e);
|
|
34053
34728
|
}
|
|
34054
34729
|
render() {
|
|
34055
|
-
return t.createElement(ComposedComponent,
|
|
34730
|
+
return t.createElement(ComposedComponent, {
|
|
34731
|
+
...this._extractNonMaskProps(this.props),
|
|
34056
34732
|
inputRef: this._inputRef
|
|
34057
|
-
})
|
|
34733
|
+
});
|
|
34058
34734
|
}
|
|
34059
|
-
};
|
|
34735
|
+
}, _class.displayName = void 0, _class.propTypes = void 0, _class);
|
|
34060
34736
|
const nestedComponentName = ComposedComponent.displayName || ComposedComponent.name || 'Component';
|
|
34061
|
-
MaskedComponent.displayName = "IMask("
|
|
34737
|
+
MaskedComponent.displayName = "IMask(" + nestedComponentName + ")";
|
|
34062
34738
|
MaskedComponent.propTypes = MASK_PROPS;
|
|
34063
|
-
return t.forwardRef((props, ref) => t.createElement(MaskedComponent,
|
|
34739
|
+
return t.forwardRef((props, ref) => t.createElement(MaskedComponent, {
|
|
34740
|
+
...props,
|
|
34064
34741
|
ref
|
|
34065
|
-
}))
|
|
34742
|
+
}));
|
|
34066
34743
|
}
|
|
34067
34744
|
|
|
34068
|
-
const
|
|
34069
|
-
const IMaskInput = IMaskMixin(_ref => {
|
|
34745
|
+
const IMaskInputClass = IMaskMixin(_ref => {
|
|
34070
34746
|
let {
|
|
34071
|
-
|
|
34072
|
-
|
|
34073
|
-
|
|
34074
|
-
return t.createElement('input',
|
|
34747
|
+
inputRef,
|
|
34748
|
+
...props
|
|
34749
|
+
} = _ref;
|
|
34750
|
+
return t.createElement('input', {
|
|
34751
|
+
...props,
|
|
34075
34752
|
ref: inputRef
|
|
34076
|
-
})
|
|
34753
|
+
});
|
|
34077
34754
|
});
|
|
34755
|
+
const IMaskInputFn = (props, ref) => t.createElement(IMaskInputClass, {
|
|
34756
|
+
...props,
|
|
34757
|
+
ref
|
|
34758
|
+
}) // TODO fix no idea
|
|
34759
|
+
;
|
|
34760
|
+
|
|
34761
|
+
const IMaskInput = t.forwardRef(IMaskInputFn);
|
|
34078
34762
|
|
|
34079
34763
|
/**
|
|
34080
34764
|
* @module ol/proj/Units
|
|
@@ -35017,10 +35701,10 @@ function DMDCoordinatesInput({ coordinates, coordinatesFormat, disabled = false,
|
|
|
35017
35701
|
function completeCoordinates(mask) {
|
|
35018
35702
|
setError('');
|
|
35019
35703
|
// eslint-disable-next-line no-underscore-dangle
|
|
35020
|
-
const latitude = mask._unmaskedValue.substring(0,
|
|
35704
|
+
const latitude = mask._unmaskedValue.substring(0, 7);
|
|
35021
35705
|
// eslint-disable-next-line no-underscore-dangle
|
|
35022
|
-
const longitude = mask._unmaskedValue.substring(
|
|
35023
|
-
const NS = latitude[latitude.length - 1];
|
|
35706
|
+
const longitude = mask._unmaskedValue.substring(7, mask._unmaskedValue.length);
|
|
35707
|
+
const NS = latitude[latitude.length - 1].toUpperCase();
|
|
35024
35708
|
if (!['N', 'S'].includes(NS)) {
|
|
35025
35709
|
setError('La latitude doit être N ou S');
|
|
35026
35710
|
return;
|
|
@@ -35031,8 +35715,8 @@ function DMDCoordinatesInput({ coordinates, coordinatesFormat, disabled = false,
|
|
|
35031
35715
|
return;
|
|
35032
35716
|
}
|
|
35033
35717
|
const latitudeMinutes = parseInt(latitude.substring(2, 4), 10);
|
|
35034
|
-
const latitudeSeconds = parseInt(latitude.substring(4,
|
|
35035
|
-
const EW = longitude[longitude.length - 1];
|
|
35718
|
+
const latitudeSeconds = parseInt(latitude.substring(4, 6), 10);
|
|
35719
|
+
const EW = longitude[longitude.length - 1].toUpperCase();
|
|
35036
35720
|
if (!['E', 'W'].includes(EW)) {
|
|
35037
35721
|
setError('La longitude doit être E ou W');
|
|
35038
35722
|
return;
|
|
@@ -35043,9 +35727,9 @@ function DMDCoordinatesInput({ coordinates, coordinatesFormat, disabled = false,
|
|
|
35043
35727
|
return;
|
|
35044
35728
|
}
|
|
35045
35729
|
const longitudeMinutes = parseInt(longitude.substring(3, 5), 10);
|
|
35046
|
-
const longitudeSeconds = parseInt(longitude.substring(5,
|
|
35047
|
-
const dLatitude = dmsToDecimal(latitudeDegrees, latitudeMinutes + 10 ** -
|
|
35048
|
-
const dLongitude = dmsToDecimal(longitudeDegrees, longitudeMinutes + 10 ** -
|
|
35730
|
+
const longitudeSeconds = parseInt(longitude.substring(5, 7), 10);
|
|
35731
|
+
const dLatitude = dmsToDecimal(latitudeDegrees, latitudeMinutes + 10 ** -2 * latitudeSeconds, 0, NS, 6);
|
|
35732
|
+
const dLongitude = dmsToDecimal(longitudeDegrees, longitudeMinutes + 10 ** -2 * longitudeSeconds, 0, EW, 6);
|
|
35049
35733
|
if (isNumeric(dLatitude) && isNumeric(dLongitude)) {
|
|
35050
35734
|
onChange([dLatitude, dLongitude], coordinates);
|
|
35051
35735
|
}
|
|
@@ -35053,7 +35737,7 @@ function DMDCoordinatesInput({ coordinates, coordinatesFormat, disabled = false,
|
|
|
35053
35737
|
setError('Format lat/long invalide');
|
|
35054
35738
|
}
|
|
35055
35739
|
}
|
|
35056
|
-
return (jsxs(Box$2, { children: [jsx(UntypedIMaskInput, { "data-cy": "dmd-coordinates-input", disabled: disabled, lazy: false, mask: "00\u00B0 00.
|
|
35740
|
+
return (jsxs(Box$2, { children: [jsx(UntypedIMaskInput, { "data-cy": "dmd-coordinates-input", disabled: disabled, lazy: false, mask: "00\u00B0 00.00\u2032 a 000\u00B0 00.00\u2032 a",
|
|
35057
35741
|
// @ts-ignore
|
|
35058
35742
|
onAccept: (_, mask) => setValue(mask.value), onComplete: (_, mask) => completeCoordinates(mask), placeholder: "__\u00B0 __.___\u2032 _ ___\u00B0 __.___\u2032", radix: ".", style: { border: error ? '1px solid red' : undefined },
|
|
35059
35743
|
// TODO Use `defaultValue` here.
|