GULP DIST

This commit is contained in:
2022-04-07 14:11:14 +02:00
parent 0a1f83b99c
commit 5e7215d041
137 changed files with 18556 additions and 2641 deletions

View File

@@ -1,310 +0,0 @@
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {
while (!Object.prototype.hasOwnProperty.call(object, property)) {
object = _getPrototypeOf(object);
if (object === null) break;
}
return object;
}
function _get(target, property, receiver) {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get;
} else {
_get = function _get(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
var desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.get) {
return desc.get.call(receiver);
}
return desc.value;
};
}
return _get(target, property, receiver || target);
}
function set(target, property, value, receiver) {
if (typeof Reflect !== "undefined" && Reflect.set) {
set = Reflect.set;
} else {
set = function set(target, property, value, receiver) {
var base = _superPropBase(target, property);
var desc;
if (base) {
desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.set) {
desc.set.call(receiver, value);
return true;
} else if (!desc.writable) {
return false;
}
}
desc = Object.getOwnPropertyDescriptor(receiver, property);
if (desc) {
if (!desc.writable) {
return false;
}
desc.value = value;
Object.defineProperty(receiver, property, desc);
} else {
_defineProperty(receiver, property, value);
}
return true;
};
}
return set(target, property, value, receiver);
}
function _set(target, property, value, receiver, isStrict) {
var s = set(target, property, value, receiver || target);
if (!s && isStrict) {
throw new Error('failed to set property');
}
return value;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
export { _createClass as _, _classCallCheck as a, _objectWithoutProperties as b, _typeof as c, _inherits as d, _createSuper as e, _slicedToArray as f, _get as g, _getPrototypeOf as h, _set as i };

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import HTMLMaskElement from './html-mask-element.js';
import IMask from '../core/holder.js';
import './mask-element.js';
@@ -24,7 +24,14 @@ var HTMLContenteditableMaskElement = /*#__PURE__*/function (_HTMLMaskElement) {
function get() {
var root = this.rootElement;
var selection = root.getSelection && root.getSelection();
return selection && selection.anchorOffset;
var anchorOffset = selection && selection.anchorOffset;
var focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
return anchorOffset;
}
return focusOffset;
}
/**
Returns HTMLElement selection end
@@ -36,7 +43,14 @@ var HTMLContenteditableMaskElement = /*#__PURE__*/function (_HTMLMaskElement) {
get: function get() {
var root = this.rootElement;
var selection = root.getSelection && root.getSelection();
return selection && this._unsafeSelectionStart + String(selection).length;
var anchorOffset = selection && selection.anchorOffset;
var focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
return anchorOffset;
}
return focusOffset;
}
/**
Sets HTMLElement selection

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import MaskElement from './mask-element.js';
import IMask from '../core/holder.js';
@@ -33,7 +33,9 @@ var HTMLMaskElement = /*#__PURE__*/function (_MaskElement) {
_createClass(HTMLMaskElement, [{
key: "rootElement",
get: function get() {
return this.input.getRootNode ? this.input.getRootNode() : document;
var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
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;
}
/**
Is element in focus

View File

@@ -1,19 +1,20 @@
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import { objectIncludes, DIRECTION } from '../core/utils.js';
import ActionDetails from '../core/action-details.js';
import MaskedDate from '../masked/date.js';
import '../masked/date.js';
import createMask, { maskedClass } from '../masked/factory.js';
import MaskElement from './mask-element.js';
import HTMLMaskElement from './html-mask-element.js';
import HTMLContenteditableMaskElement from './html-contenteditable-mask-element.js';
import IMask from '../core/holder.js';
import '../masked/pattern.js';
import '../core/change-details.js';
import '../masked/pattern.js';
import '../masked/base.js';
import '../core/continuous-tail-details.js';
import '../masked/pattern/input-definition.js';
import '../masked/pattern/fixed-definition.js';
import '../masked/pattern/chunk-tail-details.js';
import '../masked/pattern/cursor.js';
import '../masked/regexp.js';
import '../masked/range.js';
@@ -68,7 +69,7 @@ var InputMask = /*#__PURE__*/function () {
return this.masked.mask;
},
set: function set(mask) {
if (this.maskEquals(mask)) return;
if (this.maskEquals(mask)) return; // $FlowFixMe No ideas ... after update
if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
this.masked.updateOptions({
@@ -88,7 +89,9 @@ var InputMask = /*#__PURE__*/function () {
}, {
key: "maskEquals",
value: function maskEquals(mask) {
return mask == null || mask === this.masked.mask || mask === Date && this.masked instanceof MaskedDate;
var _this$masked;
return mask == null || ((_this$masked = this.masked) === null || _this$masked === void 0 ? void 0 : _this$masked.maskEquals(mask));
}
}, {
key: "value",
@@ -199,7 +202,9 @@ var InputMask = /*#__PURE__*/function () {
}, {
key: "_saveSelection",
value: function _saveSelection() {
value: function
/* ev */
_saveSelection() {
if (this.value !== this.el.value) {
console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console
}
@@ -305,7 +310,7 @@ var InputMask = /*#__PURE__*/function () {
}, {
key: "alignCursor",
value: function alignCursor() {
this.cursorPos = this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT);
this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
}
/** Aligns cursor only if selection is empty */
@@ -364,6 +369,7 @@ var InputMask = /*#__PURE__*/function () {
var removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
var cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);
this.updateControl();
this.updateCursor(cursorPos);
delete this._inputEvent;

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import IMask from '../core/holder.js';
/**

View File

@@ -1,5 +1,6 @@
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import { DIRECTION } from './utils.js';
import './change-details.js';
/** Provides details of changing input */
@@ -104,9 +105,10 @@ var ActionDetails = /*#__PURE__*/function () {
}, {
key: "removeDirection",
get: function get() {
if (!this.removedCount || this.insertedCount) return DIRECTION.NONE; // align right if delete at right or if range removed (event with backspace)
if (!this.removedCount || this.insertedCount) return DIRECTION.NONE; // align right if delete at right
return this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos ? DIRECTION.RIGHT : DIRECTION.LEFT;
return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) && // if not range removed (event with backspace)
this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
}
}]);

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-b054ecd2.js';
/**
Provides details of changing model value

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-b054ecd2.js';
/** Provides details of continuous extracted tail */
var ContinuousTailDetails = /*#__PURE__*/function () {
@@ -49,13 +49,21 @@ var ContinuousTailDetails = /*#__PURE__*/function () {
Object.assign(this, state);
}
}, {
key: "shiftBefore",
value: function shiftBefore(pos) {
if (this.from >= pos || !this.value.length) return '';
key: "unshift",
value: function unshift(beforePos) {
if (!this.value.length || beforePos != null && this.from >= beforePos) return '';
var shiftChar = this.value[0];
this.value = this.value.slice(1);
return shiftChar;
}
}, {
key: "shift",
value: function shift() {
if (!this.value.length) return '';
var shiftChar = this.value[this.value.length - 1];
this.value = this.value.slice(0, -1);
return shiftChar;
}
}]);
return ContinuousTailDetails;

View File

@@ -1,6 +1,8 @@
import { c as _typeof } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { c as _typeof } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import ChangeDetails from './change-details.js';
/** Checks if value is string */
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
@@ -64,6 +66,9 @@ function forceDirection(direction) {
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
function normalizePrepare(prep) {
return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
} // cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
function objectIncludes(b, a) {
@@ -96,6 +101,7 @@ function objectIncludes(b, a) {
var keys = Object.keys(a); // if (keys.length !== Object.keys(b).length) return false;
for (i = 0; i < keys.length; i++) {
// $FlowFixMe ... ???
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
}
@@ -112,4 +118,4 @@ function objectIncludes(b, a) {
}
/** Selection range */
export { DIRECTION, escapeRegExp, forceDirection, indexInDirection, isString, objectIncludes, posInDirection };
export { DIRECTION, escapeRegExp, forceDirection, indexInDirection, isString, normalizePrepare, objectIncludes, posInDirection };

View File

@@ -78,7 +78,7 @@ declare namespace IMask {
} & Partial<
Pick<
Masked<MaskType>,
'parent' | 'prepare' | 'validate' | 'commit' | 'overwrite'
'parent' | 'prepare' | 'validate' | 'commit' | 'overwrite' | 'eager'
>
>;
type MaskedTypedValue<MaskType> = MaskType extends (typeof Number)
@@ -99,14 +99,15 @@ declare namespace IMask {
value: string,
masked: Masked<MaskType>,
flags: AppendFlags,
) => string;
) => string | [string, ChangeDetails];
validate: (
value: string,
masked: Masked<MaskType>,
flags: AppendFlags,
) => boolean;
commit: (value: string, masked: Masked<MaskType>) => void;
overwrite?: boolean;
overwrite?: boolean | 'shift';
eager?: boolean;
isInitialized: boolean;
constructor(opts: BaseMaskedOptions<MaskType>);
@@ -122,7 +123,7 @@ declare namespace IMask {
tail?: string | TailDetails
): ChangeDetails;
remove(fromPos?: number, toPos?: number): ChangeDetails;
doPrepare(str: string, flags: AppendFlags): string;
doPrepare(str: string, flags: AppendFlags): string | [string, ChangeDetails];
doValidate(flags: AppendFlags): boolean;
doCommit(): boolean;
splice(
@@ -269,7 +270,7 @@ declare namespace IMask {
readonly maxLength: number;
readonly from: number;
readonly to: number;
readonly autofix?: boolean;
readonly autofix?: boolean | 'pad';
constructor(opts: MaskedRangeOptions);
updateOptions(opts: Partial<MaskedRangeOptions>): void;
@@ -351,7 +352,7 @@ declare namespace IMask {
readonly pattern: string;
readonly min?: Date;
readonly max?: Date;
readonly autofix?: boolean;
readonly autofix?: boolean | 'pad';
date: Date;
constructor(opts: MaskedDateOptions);
@@ -375,7 +376,7 @@ declare namespace IMask {
readonly compiledMasks: Array<AnyMasked>;
dispatch: (
value: string,
masked: AnyMasked,
masked: MaskedDynamic,
flags: AppendFlags
) => AnyMasked;

View File

@@ -1,18 +1,19 @@
import './controls/input.js';
import IMask from './core/holder.js';
export { default } from './core/holder.js';
import './_rollupPluginBabelHelpers-a0b34764.js';
import './_rollupPluginBabelHelpers-b054ecd2.js';
import './core/utils.js';
import './core/change-details.js';
import './core/action-details.js';
import './masked/date.js';
import './masked/pattern.js';
import './core/change-details.js';
import './masked/base.js';
import './core/continuous-tail-details.js';
import './masked/pattern/input-definition.js';
import './masked/factory.js';
import './masked/pattern/fixed-definition.js';
import './masked/pattern/chunk-tail-details.js';
import './masked/pattern/cursor.js';
import './masked/regexp.js';
import './masked/range.js';
import './controls/mask-element.js';

View File

@@ -15,14 +15,15 @@ export { default as MaskElement } from './controls/mask-element.js';
export { default as HTMLMaskElement } from './controls/html-mask-element.js';
export { default as HTMLContenteditableMaskElement } from './controls/html-contenteditable-mask-element.js';
export { PIPE_TYPE, createPipe, pipe } from './masked/pipe.js';
import './_rollupPluginBabelHelpers-a0b34764.js';
import './_rollupPluginBabelHelpers-b054ecd2.js';
import './core/utils.js';
import './core/action-details.js';
import './core/change-details.js';
import './core/action-details.js';
import './core/continuous-tail-details.js';
import './masked/pattern/input-definition.js';
import './masked/pattern/fixed-definition.js';
import './masked/pattern/chunk-tail-details.js';
import './masked/pattern/cursor.js';
try {
globalThis.IMask = IMask;

View File

@@ -1,7 +1,7 @@
import { _ as _createClass, a as _classCallCheck } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck, f as _slicedToArray } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import ChangeDetails from '../core/change-details.js';
import ContinuousTailDetails from '../core/continuous-tail-details.js';
import { isString } from '../core/utils.js';
import { isString, normalizePrepare, forceDirection, DIRECTION } from '../core/utils.js';
import IMask from '../core/holder.js';
/** Supported mask type */
@@ -27,6 +27,8 @@ var Masked = /*#__PURE__*/function () {
/** Enable characters overwriting */
/** */
/** */
function Masked(opts) {
_classCallCheck(this, Masked);
@@ -43,7 +45,8 @@ var Masked = /*#__PURE__*/function () {
_createClass(Masked, [{
key: "updateOptions",
value: function updateOptions(opts) {
if (!Object.keys(opts).length) return;
if (!Object.keys(opts).length) return; // $FlowFixMe
this.withValueRefresh(this._update.bind(this, opts));
}
/**
@@ -142,6 +145,13 @@ var Masked = /*#__PURE__*/function () {
get: function get() {
return true;
}
/** */
}, {
key: "isFilled",
get: function get() {
return this.isComplete;
}
/** Finds nearest input position in direction */
}, {
@@ -196,8 +206,15 @@ var Masked = /*#__PURE__*/function () {
var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var checkTail = arguments.length > 2 ? arguments[2] : undefined;
var consistentState = this.state;
var details;
var details = this._appendCharRaw(this.doPrepare(ch, flags), flags);
var _normalizePrepare = normalizePrepare(this.doPrepare(ch, flags));
var _normalizePrepare2 = _slicedToArray(_normalizePrepare, 2);
ch = _normalizePrepare2[0];
details = _normalizePrepare2[1];
details = details.aggregate(this._appendCharRaw(ch, flags));
if (details.inserted) {
var consistentTail;
@@ -207,13 +224,22 @@ var Masked = /*#__PURE__*/function () {
// validation ok, check tail
var beforeTailState = this.state;
if (this.overwrite) {
if (this.overwrite === true) {
consistentTail = checkTail.state;
checkTail.shiftBefore(this.value.length);
checkTail.unshift(this.value.length);
}
var tailDetails = this.appendTail(checkTail);
appended = tailDetails.rawInserted === checkTail.toString(); // if ok, rollback state after tail
appended = tailDetails.rawInserted === checkTail.toString(); // not ok, try shift
if (!(appended && tailDetails.inserted) && this.overwrite === 'shift') {
this.state = beforeTailState;
consistentTail = checkTail.state;
checkTail.shift();
tailDetails = this.appendTail(checkTail);
appended = tailDetails.rawInserted === checkTail.toString();
} // if ok, rollback state after tail
if (appended && tailDetails.inserted) this.state = beforeTailState;
} // revert all if something went wrong
@@ -235,6 +261,13 @@ var Masked = /*#__PURE__*/function () {
value: function _appendPlaceholder() {
return new ChangeDetails();
}
/** Appends optional eager placeholder at end */
}, {
key: "_appendEager",
value: function _appendEager() {
return new ChangeDetails();
}
/** Appends symbols considering flags */
// $FlowFixMe no ideas
@@ -257,6 +290,10 @@ var Masked = /*#__PURE__*/function () {
// this._resetBeforeTailState();
}
if (this.eager && flags !== null && flags !== void 0 && flags.input && str) {
details.aggregate(this._appendEager());
}
return details;
}
/** */
@@ -353,14 +390,43 @@ var Masked = /*#__PURE__*/function () {
value: function splice(start, deleteCount, inserted, removeDirection) {
var tailPos = start + deleteCount;
var tail = this.extractTail(tailPos);
var startChangePos = this.nearestInputPos(start, removeDirection);
var changeDetails = new ChangeDetails({
var oldRawValue;
if (this.eager) {
removeDirection = forceDirection(removeDirection);
oldRawValue = this.extractInput(0, tailPos, {
raw: true
});
}
var startChangePos = this.nearestInputPos(start, deleteCount > 1 && start !== 0 && !this.eager ? DIRECTION.NONE : removeDirection);
var details = new ChangeDetails({
tailShift: startChangePos - start // adjust tailShift if start was aligned
}).aggregate(this.remove(startChangePos)).aggregate(this.append(inserted, {
}).aggregate(this.remove(startChangePos));
if (this.eager && removeDirection !== DIRECTION.NONE && oldRawValue === this.rawInputValue) {
if (removeDirection === DIRECTION.FORCE_LEFT) {
var valLength;
while (oldRawValue === this.rawInputValue && (valLength = this.value.length)) {
details.aggregate(new ChangeDetails({
tailShift: -1
})).aggregate(this.remove(valLength - 1));
}
} else if (removeDirection === DIRECTION.FORCE_RIGHT) {
tail.unshift();
}
}
return details.aggregate(this.append(inserted, {
input: true
}, tail));
return changeDetails;
}
}, {
key: "maskEquals",
value: function maskEquals(mask) {
return this.mask === mask;
}
}]);

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, f as _slicedToArray, g as _get, h as _getPrototypeOf, i as _set } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, f as _slicedToArray, g as _get, h as _getPrototypeOf, i as _set } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import MaskedPattern from './pattern.js';
import MaskedRange from './range.js';
import IMask from '../core/holder.js';
@@ -10,6 +10,7 @@ import './pattern/input-definition.js';
import './factory.js';
import './pattern/fixed-definition.js';
import './pattern/chunk-tail-details.js';
import './pattern/cursor.js';
import './regexp.js';
/** Date mask */
@@ -61,11 +62,11 @@ var MaskedDate = /*#__PURE__*/function (_MaskedPattern) {
}
}
Object.assign(opts.blocks, blocks); // add autofix
Object.assign(opts.blocks, this.blocks, blocks); // add autofix
Object.keys(opts.blocks).forEach(function (bk) {
var b = opts.blocks[bk];
if (!('autofix' in b)) b.autofix = opts.autofix;
if (!('autofix' in b) && 'autofix' in opts) b.autofix = opts.autofix;
});
_get(_getPrototypeOf(MaskedDate.prototype), "_update", this).call(this, opts);
@@ -116,6 +117,15 @@ var MaskedDate = /*#__PURE__*/function (_MaskedPattern) {
set: function set(value) {
_set(_getPrototypeOf(MaskedDate.prototype), "typedValue", value, this, true);
}
/**
@override
*/
}, {
key: "maskEquals",
value: function maskEquals(mask) {
return mask === Date || _get(_getPrototypeOf(MaskedDate.prototype), "maskEquals", this).call(this, mask);
}
}]);
return MaskedDate;
@@ -123,6 +133,7 @@ var MaskedDate = /*#__PURE__*/function (_MaskedPattern) {
MaskedDate.DEFAULTS = {
pattern: 'd{.}`m{.}`Y',
format: function format(date) {
if (!date) return '';
var day = String(date.getDate()).padStart(2, '0');
var month = String(date.getMonth() + 1).padStart(2, '0');
var year = date.getFullYear();

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, i as _set, b as _objectWithoutProperties } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, i as _set, b as _objectWithoutProperties } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import ChangeDetails from '../core/change-details.js';
import createMask from './factory.js';
import Masked from './base.js';
@@ -122,6 +122,21 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
return details;
}
/**
@override
*/
}, {
key: "_appendEager",
value: function _appendEager() {
var details = this._applyDispatch.apply(this, arguments);
if (this.currentMask) {
details.aggregate(this.currentMask._appendEager());
}
return details;
}
/**
@override
*/
@@ -154,7 +169,9 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
}, {
key: "reset",
value: function reset() {
if (this.currentMask) this.currentMask.reset();
var _this$currentMask2;
(_this$currentMask2 = this.currentMask) === null || _this$currentMask2 === void 0 ? void 0 : _this$currentMask2.reset();
this.compiledMasks.forEach(function (m) {
return m.reset();
});
@@ -210,7 +227,20 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
}, {
key: "isComplete",
get: function get() {
return !!this.currentMask && this.currentMask.isComplete;
var _this$currentMask3;
return Boolean((_this$currentMask3 = this.currentMask) === null || _this$currentMask3 === void 0 ? void 0 : _this$currentMask3.isComplete);
}
/**
@override
*/
}, {
key: "isFilled",
get: function get() {
var _this$currentMask4;
return Boolean((_this$currentMask4 = this.currentMask) === null || _this$currentMask4 === void 0 ? void 0 : _this$currentMask4.isFilled);
}
/**
@override
@@ -222,9 +252,9 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
var details = new ChangeDetails();
if (this.currentMask) {
var _this$currentMask2;
var _this$currentMask5;
details.aggregate((_this$currentMask2 = this.currentMask).remove.apply(_this$currentMask2, arguments)) // update with dispatch
details.aggregate((_this$currentMask5 = this.currentMask).remove.apply(_this$currentMask5, arguments)) // update with dispatch
.aggregate(this._applyDispatch());
}
@@ -270,9 +300,9 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
}, {
key: "extractInput",
value: function extractInput() {
var _this$currentMask3;
var _this$currentMask6;
return this.currentMask ? (_this$currentMask3 = this.currentMask).extractInput.apply(_this$currentMask3, arguments) : '';
return this.currentMask ? (_this$currentMask6 = this.currentMask).extractInput.apply(_this$currentMask6, arguments) : '';
}
/**
@override
@@ -281,13 +311,13 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
}, {
key: "extractTail",
value: function extractTail() {
var _this$currentMask4, _get3;
var _this$currentMask7, _get3;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return this.currentMask ? (_this$currentMask4 = this.currentMask).extractTail.apply(_this$currentMask4, args) : (_get3 = _get(_getPrototypeOf(MaskedDynamic.prototype), "extractTail", this)).call.apply(_get3, [this].concat(args));
return this.currentMask ? (_this$currentMask7 = this.currentMask).extractTail.apply(_this$currentMask7, args) : (_get3 = _get(_getPrototypeOf(MaskedDynamic.prototype), "extractTail", this)).call.apply(_get3, [this].concat(args));
}
/**
@override
@@ -307,13 +337,13 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
}, {
key: "nearestInputPos",
value: function nearestInputPos() {
var _this$currentMask5, _get4;
var _this$currentMask8, _get4;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return this.currentMask ? (_this$currentMask5 = this.currentMask).nearestInputPos.apply(_this$currentMask5, args) : (_get4 = _get(_getPrototypeOf(MaskedDynamic.prototype), "nearestInputPos", this)).call.apply(_get4, [this].concat(args));
return this.currentMask ? (_this$currentMask8 = this.currentMask).nearestInputPos.apply(_this$currentMask8, args) : (_get4 = _get(_getPrototypeOf(MaskedDynamic.prototype), "nearestInputPos", this)).call.apply(_get4, [this].concat(args));
}
}, {
key: "overwrite",
@@ -323,6 +353,27 @@ var MaskedDynamic = /*#__PURE__*/function (_Masked) {
set: function set(overwrite) {
console.warn('"overwrite" option is not available in dynamic mask, use this option in siblings');
}
}, {
key: "eager",
get: function get() {
return this.currentMask ? this.currentMask.eager : _get(_getPrototypeOf(MaskedDynamic.prototype), "eager", this);
},
set: function set(eager) {
console.warn('"eager" option is not available in dynamic mask, use this option in siblings');
}
/**
@override
*/
}, {
key: "maskEquals",
value: function maskEquals(mask) {
return Array.isArray(mask) && this.compiledMasks.every(function (m, mi) {
var _mask$mi;
return m.maskEquals((_mask$mi = mask[mi]) === null || _mask$mi === void 0 ? void 0 : _mask$mi.mask);
});
}
}]);
return MaskedDynamic;

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import MaskedPattern from './pattern.js';
import IMask from '../core/holder.js';
import '../core/utils.js';
@@ -9,6 +9,7 @@ import './pattern/input-definition.js';
import './factory.js';
import './pattern/fixed-definition.js';
import './pattern/chunk-tail-details.js';
import './pattern/cursor.js';
import './regexp.js';
/** Pattern which validates enum values */

View File

@@ -1,6 +1,7 @@
import { isString } from '../core/utils.js';
import IMask from '../core/holder.js';
import '../_rollupPluginBabelHelpers-a0b34764.js';
import '../_rollupPluginBabelHelpers-b054ecd2.js';
import '../core/change-details.js';
/** Get Masked class by mask type */
@@ -22,9 +23,9 @@ function maskedClass(mask) {
if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask; // $FlowFixMe
if (mask instanceof Function) return IMask.MaskedFunction; // $FlowFixMe
if (mask instanceof IMask.Masked) return mask.constructor; // $FlowFixMe
if (mask instanceof IMask.Masked) return mask.constructor;
if (mask instanceof Function) return IMask.MaskedFunction;
console.warn('Mask not found for mask', mask); // eslint-disable-line no-console
// $FlowFixMe

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import Masked from './base.js';
import IMask from '../core/holder.js';
import '../core/change-details.js';

View File

@@ -1,5 +1,5 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, f as _slicedToArray, i as _set } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { escapeRegExp, DIRECTION } from '../core/utils.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, f as _slicedToArray, i as _set } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import { escapeRegExp, normalizePrepare, DIRECTION } from '../core/utils.js';
import ChangeDetails from '../core/change-details.js';
import Masked from './base.js';
import IMask from '../core/holder.js';
@@ -95,14 +95,24 @@ var MaskedNumber = /*#__PURE__*/function (_Masked) {
}, {
key: "doPrepare",
value: function doPrepare(str) {
value: function doPrepare(ch) {
var _get2;
ch = ch.replace(this._mapToRadixRegExp, this.radix);
var noSepCh = this._removeThousandsSeparators(ch);
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return (_get2 = _get(_getPrototypeOf(MaskedNumber.prototype), "doPrepare", this)).call.apply(_get2, [this, this._removeThousandsSeparators(str.replace(this._mapToRadixRegExp, this.radix))].concat(args));
var _normalizePrepare = normalizePrepare((_get2 = _get(_getPrototypeOf(MaskedNumber.prototype), "doPrepare", this)).call.apply(_get2, [this, noSepCh].concat(args))),
_normalizePrepare2 = _slicedToArray(_normalizePrepare, 2),
prepCh = _normalizePrepare2[0],
details = _normalizePrepare2[1];
if (ch && !noSepCh) details.skip = true;
return [prepCh, details];
}
/** */
@@ -282,7 +292,9 @@ var MaskedNumber = /*#__PURE__*/function (_Masked) {
if (valid) {
// validate as number
var number = this.number;
valid = valid && !isNaN(number) && (this.min == null || this.min >= 0 || this.min <= this.number) && (this.max == null || this.max <= 0 || this.number <= this.max);
valid = valid && !isNaN(number) && ( // check min bound for negative values
this.min == null || this.min >= 0 || this.min <= this.number) && ( // check max bound for positive values
this.max == null || this.max <= 0 || this.number <= this.max);
}
return valid && _get(_getPrototypeOf(MaskedNumber.prototype), "doValidate", this).call(this, flags);
@@ -303,7 +315,7 @@ var MaskedNumber = /*#__PURE__*/function (_Masked) {
if (validnum !== number) this.unmaskedValue = String(validnum);
var formatted = this.value;
if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);
if (this.padFractionalZeros) formatted = this._padFractionalZeros(formatted);
if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted);
this._value = formatted;
}

View File

@@ -1,10 +1,11 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, b as _objectWithoutProperties, i as _set } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { DIRECTION, forceDirection } from '../core/utils.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, b as _objectWithoutProperties, i as _set } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import { DIRECTION } from '../core/utils.js';
import ChangeDetails from '../core/change-details.js';
import Masked from './base.js';
import PatternInputDefinition, { DEFAULT_INPUT_DEFINITIONS } from './pattern/input-definition.js';
import PatternFixedDefinition from './pattern/fixed-definition.js';
import ChunksTailDetails from './pattern/chunk-tail-details.js';
import PatternCursor from './pattern/cursor.js';
import createMask from './factory.js';
import IMask from '../core/holder.js';
import './regexp.js';
@@ -92,6 +93,7 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
var maskedBlock = createMask(Object.assign({
parent: _this,
lazy: _this.lazy,
eager: _this.eager,
placeholderChar: _this.placeholderChar,
overwrite: _this.overwrite
}, _this.blocks[bName]));
@@ -114,8 +116,7 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
}
var char = pattern[i];
var _isInput = (char in defs);
var isInput = (char in defs);
if (char === MaskedPattern.STOP_CHAR) {
this._stops.push(this._blocks.length);
@@ -137,17 +138,19 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
++i;
char = pattern[i];
if (!char) break;
_isInput = false;
isInput = false;
}
var def = _isInput ? new PatternInputDefinition({
var def = isInput ? new PatternInputDefinition({
parent: this,
lazy: this.lazy,
eager: this.eager,
placeholderChar: this.placeholderChar,
mask: defs[char],
isOptional: optionalBlock
}) : new PatternFixedDefinition({
char: char,
eager: this.eager,
isUnmasking: unmaskingBlock
});
@@ -205,6 +208,31 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
@override
*/
}, {
key: "isFilled",
get: function get() {
return this._blocks.every(function (b) {
return b.isFilled;
});
}
}, {
key: "isFixed",
get: function get() {
return this._blocks.every(function (b) {
return b.isFixed;
});
}
}, {
key: "isOptional",
get: function get() {
return this._blocks.every(function (b) {
return b.isOptional;
});
}
/**
@override
*/
}, {
key: "doCommit",
value: function doCommit() {
@@ -256,6 +284,30 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
@override
*/
}, {
key: "_appendEager",
value: function _appendEager() {
var _this$_mapPosToBlock;
var details = new ChangeDetails();
var startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.value.length)) === null || _this$_mapPosToBlock === void 0 ? void 0 : _this$_mapPosToBlock.index;
if (startBlockIndex == null) return details; // TODO test if it works for nested pattern masks
if (this._blocks[startBlockIndex].isFilled) ++startBlockIndex;
for (var bi = startBlockIndex; bi < this._blocks.length; ++bi) {
var d = this._blocks[bi]._appendEager();
if (!d.inserted) break;
details.aggregate(d);
}
return details;
}
/**
@override
*/
}, {
key: "_appendCharRaw",
value: function _appendCharRaw(ch) {
@@ -267,10 +319,14 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
if (!blockIter) return details;
for (var bi = blockIter.index;; ++bi) {
var _flags$_beforeTailSta;
var _block = this._blocks[bi];
if (!_block) break;
var blockDetails = _block._appendChar(ch, flags);
var blockDetails = _block._appendChar(ch, Object.assign({}, flags, {
_beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) === null || _flags$_beforeTailSta === void 0 ? void 0 : _flags$_beforeTailSta._blocks[bi]
}));
var skip = blockDetails.skip;
details.aggregate(blockDetails);
@@ -449,220 +505,69 @@ var MaskedPattern = /*#__PURE__*/function (_Masked) {
key: "nearestInputPos",
value: function nearestInputPos(cursorPos) {
var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
// TODO refactor - extract alignblock
var beginBlockData = this._mapPosToBlock(cursorPos) || {
index: 0,
offset: 0
};
var beginBlockOffset = beginBlockData.offset,
beginBlockIndex = beginBlockData.index;
var beginBlock = this._blocks[beginBlockIndex];
if (!beginBlock) return cursorPos;
var beginBlockCursorPos = beginBlockOffset; // if position inside block - try to adjust it
if (beginBlockCursorPos !== 0 && beginBlockCursorPos < beginBlock.value.length) {
beginBlockCursorPos = beginBlock.nearestInputPos(beginBlockOffset, forceDirection(direction));
}
var cursorAtRight = beginBlockCursorPos === beginBlock.value.length;
var cursorAtLeft = beginBlockCursorPos === 0; // cursor is INSIDE first block (not at bounds)
if (!cursorAtLeft && !cursorAtRight) return this._blockStartPos(beginBlockIndex) + beginBlockCursorPos;
var searchBlockIndex = cursorAtRight ? beginBlockIndex + 1 : beginBlockIndex;
if (!this._blocks.length) return 0;
var cursor = new PatternCursor(this, cursorPos);
if (direction === DIRECTION.NONE) {
// NONE direction used to calculate start input position if no chars were removed
// FOR NONE:
// -
// input|any
// ->
// any|input
// <-
// filled-input|any
// check if first block at left is input
if (searchBlockIndex > 0) {
var blockIndexAtLeft = searchBlockIndex - 1;
var blockAtLeft = this._blocks[blockIndexAtLeft];
var blockInputPos = blockAtLeft.nearestInputPos(0, DIRECTION.NONE); // is input
// -------------------------------------------------
// NONE should only go out from fixed to the right!
// -------------------------------------------------
if (cursor.pushRightBeforeInput()) return cursor.pos;
cursor.popState();
if (cursor.pushLeftBeforeInput()) return cursor.pos;
return this.value.length;
} // FORCE is only about a|* otherwise is 0
if (!blockAtLeft.value.length || blockInputPos !== blockAtLeft.value.length) {
return this._blockStartPos(searchBlockIndex);
}
} // ->
var firstInputAtRight = searchBlockIndex;
for (var bi = firstInputAtRight; bi < this._blocks.length; ++bi) {
var blockAtRight = this._blocks[bi];
var _blockInputPos = blockAtRight.nearestInputPos(0, DIRECTION.NONE);
if (!blockAtRight.value.length || _blockInputPos !== blockAtRight.value.length) {
return this._blockStartPos(bi) + _blockInputPos;
}
} // <-
// find first non-fixed symbol
for (var _bi = searchBlockIndex - 1; _bi >= 0; --_bi) {
var _block3 = this._blocks[_bi];
var _blockInputPos2 = _block3.nearestInputPos(0, DIRECTION.NONE); // is input
if (!_block3.value.length || _blockInputPos2 !== _block3.value.length) {
return this._blockStartPos(_bi) + _block3.value.length;
}
}
return cursorPos;
}
if (direction === DIRECTION.LEFT || direction === DIRECTION.FORCE_LEFT) {
// -
// any|filled-input
// <-
// any|first not empty is not-len-aligned
// not-0-aligned|any
// ->
// any|not-len-aligned or end
// check if first block at right is filled input
var firstFilledBlockIndexAtRight;
for (var _bi2 = searchBlockIndex; _bi2 < this._blocks.length; ++_bi2) {
if (this._blocks[_bi2].value) {
firstFilledBlockIndexAtRight = _bi2;
break;
}
}
if (firstFilledBlockIndexAtRight != null) {
var filledBlock = this._blocks[firstFilledBlockIndexAtRight];
var _blockInputPos3 = filledBlock.nearestInputPos(0, DIRECTION.RIGHT);
if (_blockInputPos3 === 0 && filledBlock.unmaskedValue.length) {
// filled block is input
return this._blockStartPos(firstFilledBlockIndexAtRight) + _blockInputPos3;
}
} // <-
// find this vars
// try to break fast when *|a
if (direction === DIRECTION.LEFT) {
cursor.pushRightBeforeFilled();
if (cursor.ok && cursor.pos === cursorPos) return cursorPos;
cursor.popState();
} // forward flow
var firstFilledInputBlockIndex = -1;
var firstEmptyInputBlockIndex; // TODO consider nested empty inputs
for (var _bi3 = searchBlockIndex - 1; _bi3 >= 0; --_bi3) {
var _block4 = this._blocks[_bi3];
var _blockInputPos4 = _block4.nearestInputPos(_block4.value.length, DIRECTION.FORCE_LEFT);
if (!_block4.value || _blockInputPos4 !== 0) firstEmptyInputBlockIndex = _bi3;
if (_blockInputPos4 !== 0) {
if (_blockInputPos4 !== _block4.value.length) {
// aligned inside block - return immediately
return this._blockStartPos(_bi3) + _blockInputPos4;
} else {
// found filled
firstFilledInputBlockIndex = _bi3;
break;
}
}
}
cursor.pushLeftBeforeInput();
cursor.pushLeftBeforeRequired();
cursor.pushLeftBeforeFilled(); // backward flow
if (direction === DIRECTION.LEFT) {
// try find first empty input before start searching position only when not forced
for (var _bi4 = firstFilledInputBlockIndex + 1; _bi4 <= Math.min(searchBlockIndex, this._blocks.length - 1); ++_bi4) {
var _block5 = this._blocks[_bi4];
var _blockInputPos5 = _block5.nearestInputPos(0, DIRECTION.NONE);
var blockAlignedPos = this._blockStartPos(_bi4) + _blockInputPos5;
if (blockAlignedPos > cursorPos) break; // if block is not lazy input
if (_blockInputPos5 !== _block5.value.length) return blockAlignedPos;
}
} // process overflow
if (firstFilledInputBlockIndex >= 0) {
return this._blockStartPos(firstFilledInputBlockIndex) + this._blocks[firstFilledInputBlockIndex].value.length;
} // for lazy if has aligned left inside fixed and has came to the start - use start position
if (direction === DIRECTION.FORCE_LEFT || this.lazy && !this.extractInput() && !isInput(this._blocks[searchBlockIndex])) {
return 0;
cursor.pushRightBeforeInput();
cursor.pushRightBeforeRequired();
if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
cursor.popState();
if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
cursor.popState();
}
if (firstEmptyInputBlockIndex != null) {
return this._blockStartPos(firstEmptyInputBlockIndex);
} // find first input
for (var _bi5 = searchBlockIndex; _bi5 < this._blocks.length; ++_bi5) {
var _block6 = this._blocks[_bi5];
var _blockInputPos6 = _block6.nearestInputPos(0, DIRECTION.NONE); // is input
if (!_block6.value.length || _blockInputPos6 !== _block6.value.length) {
return this._blockStartPos(_bi5) + _blockInputPos6;
}
}
if (cursor.ok) return cursor.pos;
if (direction === DIRECTION.FORCE_LEFT) return 0;
cursor.popState();
if (cursor.ok) return cursor.pos;
cursor.popState();
if (cursor.ok) return cursor.pos; // cursor.popState();
// if (
// cursor.pushRightBeforeInput() &&
// // TODO HACK for lazy if has aligned left inside fixed and has came to the start - use start position
// (!this.lazy || this.extractInput())
// ) return cursor.pos;
return 0;
}
if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) {
// ->
// any|not-len-aligned and filled
// any|not-len-aligned
// <-
// not-0-aligned or start|any
var firstInputBlockAlignedIndex;
var firstInputBlockAlignedPos;
// forward flow
cursor.pushRightBeforeInput();
cursor.pushRightBeforeRequired();
if (cursor.pushRightBeforeFilled()) return cursor.pos;
if (direction === DIRECTION.FORCE_RIGHT) return this.value.length; // backward flow
for (var _bi6 = searchBlockIndex; _bi6 < this._blocks.length; ++_bi6) {
var _block7 = this._blocks[_bi6];
var _blockInputPos7 = _block7.nearestInputPos(0, DIRECTION.NONE);
if (_blockInputPos7 !== _block7.value.length) {
firstInputBlockAlignedPos = this._blockStartPos(_bi6) + _blockInputPos7;
firstInputBlockAlignedIndex = _bi6;
break;
}
}
if (firstInputBlockAlignedIndex != null && firstInputBlockAlignedPos != null) {
for (var _bi7 = firstInputBlockAlignedIndex; _bi7 < this._blocks.length; ++_bi7) {
var _block8 = this._blocks[_bi7];
var _blockInputPos8 = _block8.nearestInputPos(0, DIRECTION.FORCE_RIGHT);
if (_blockInputPos8 !== _block8.value.length) {
return this._blockStartPos(_bi7) + _blockInputPos8;
}
}
return direction === DIRECTION.FORCE_RIGHT ? this.value.length : firstInputBlockAlignedPos;
}
for (var _bi8 = Math.min(searchBlockIndex, this._blocks.length - 1); _bi8 >= 0; --_bi8) {
var _block9 = this._blocks[_bi8];
var _blockInputPos9 = _block9.nearestInputPos(_block9.value.length, DIRECTION.LEFT);
if (_blockInputPos9 !== 0) {
var alignedPos = this._blockStartPos(_bi8) + _blockInputPos9;
if (alignedPos >= cursorPos) return alignedPos;
break;
}
}
cursor.popState();
if (cursor.ok) return cursor.pos;
cursor.popState();
if (cursor.ok) return cursor.pos;
return this.nearestInputPos(cursorPos, DIRECTION.LEFT);
}
return cursorPos;
@@ -699,13 +604,6 @@ MaskedPattern.STOP_CHAR = '`';
MaskedPattern.ESCAPE_CHAR = '\\';
MaskedPattern.InputDefinition = PatternInputDefinition;
MaskedPattern.FixedDefinition = PatternFixedDefinition;
function isInput(block) {
if (!block) return false;
var value = block.value;
return !value || block.nearestInputPos(0, DIRECTION.NONE) !== value.length;
}
IMask.MaskedPattern = MaskedPattern;
export { MaskedPattern as default };

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../../_rollupPluginBabelHelpers-b054ecd2.js';
import ChangeDetails from '../../core/change-details.js';
import { isString } from '../../core/utils.js';
import ContinuousTailDetails from '../../core/continuous-tail-details.js';
@@ -30,7 +30,8 @@ var ChunksTailDetails = /*#__PURE__*/function () {
if (!String(tailChunk)) return;
if (isString(tailChunk)) tailChunk = new ContinuousTailDetails(String(tailChunk));
var lastChunk = this.chunks[this.chunks.length - 1];
var extendLast = lastChunk && (lastChunk.stop === tailChunk.stop || tailChunk.stop == null) && // if tail chunk goes just after last chunk
var extendLast = lastChunk && ( // if stops are same or tail has no stop
lastChunk.stop === tailChunk.stop || tailChunk.stop == null) && // if tail chunk goes just after last chunk
tailChunk.from === lastChunk.from + lastChunk.toString().length;
if (tailChunk instanceof ContinuousTailDetails) {
@@ -81,7 +82,8 @@ var ChunksTailDetails = /*#__PURE__*/function () {
var stop = chunk.stop;
var chunkBlock = void 0;
if (stop != null && (!lastBlockIter || lastBlockIter.index <= stop)) {
if (stop != null && ( // if block not found or stop is behind lastBlock
!lastBlockIter || lastBlockIter.index <= stop)) {
if (chunk instanceof ChunksTailDetails || // for continuous block also check if stop is exist
masked._stops.indexOf(stop) >= 0) {
details.aggregate(masked._appendPlaceholder(stop));
@@ -134,15 +136,15 @@ var ChunksTailDetails = /*#__PURE__*/function () {
});
}
}, {
key: "shiftBefore",
value: function shiftBefore(pos) {
if (this.from >= pos || !this.chunks.length) return '';
var chunkShiftPos = pos - this.from;
key: "unshift",
value: function unshift(beforePos) {
if (!this.chunks.length || beforePos != null && this.from >= beforePos) return '';
var chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos;
var ci = 0;
while (ci < this.chunks.length) {
var chunk = this.chunks[ci];
var shiftChar = chunk.shiftBefore(chunkShiftPos);
var shiftChar = chunk.unshift(chunkShiftPos);
if (chunk.toString()) {
// chunk still contains value
@@ -157,6 +159,31 @@ var ChunksTailDetails = /*#__PURE__*/function () {
if (shiftChar) return shiftChar;
}
return '';
}
}, {
key: "shift",
value: function shift() {
if (!this.chunks.length) return '';
var ci = this.chunks.length - 1;
while (0 <= ci) {
var chunk = this.chunks[ci];
var shiftChar = chunk.shift();
if (chunk.toString()) {
// chunk still contains value
// but not shifted - means no more available chars to shift
if (!shiftChar) break;
--ci;
} else {
// clean if chunk has no value
this.chunks.splice(ci, 1);
}
if (shiftChar) return shiftChar;
}
return '';
}
}]);

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck } from '../../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck } from '../../_rollupPluginBabelHelpers-b054ecd2.js';
import ChangeDetails from '../../core/change-details.js';
import { DIRECTION, isString } from '../../core/utils.js';
import ContinuousTailDetails from '../../core/continuous-tail-details.js';
@@ -10,12 +10,17 @@ var PatternFixedDefinition = /*#__PURE__*/function () {
/** */
/** */
/** */
/** */
function PatternFixedDefinition(opts) {
_classCallCheck(this, PatternFixedDefinition);
Object.assign(this, opts);
this._value = '';
this.isFixed = true;
}
_createClass(PatternFixedDefinition, [{
@@ -75,19 +80,29 @@ var PatternFixedDefinition = /*#__PURE__*/function () {
get: function get() {
return true;
}
}, {
key: "isFilled",
get: function get() {
return Boolean(this._value);
}
}, {
key: "_appendChar",
value: function _appendChar(str) {
value: function _appendChar(ch) {
var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var details = new ChangeDetails();
if (this._value) return details;
var appended = this.char === str[0];
var isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && !flags.tail;
var appended = this.char === ch;
var isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && !this.eager && !flags.tail;
if (isResolved) details.rawInserted = this.char;
this._value = details.inserted = this.char;
this._isRawInput = isResolved && (flags.raw || flags.input);
return details;
}
}, {
key: "_appendEager",
value: function _appendEager() {
return this._appendChar(this.char);
}
}, {
key: "_appendPlaceholder",
value: function _appendPlaceholder() {
@@ -112,7 +127,7 @@ var PatternFixedDefinition = /*#__PURE__*/function () {
}, {
key: "append",
value: function append(str, flags, tail) {
var details = this._appendChar(str, flags);
var details = this._appendChar(str[0], flags);
if (tail != null) {
details.tailShift += this.appendTail(tail).tailShift;

View File

@@ -1,4 +1,4 @@
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../../_rollupPluginBabelHelpers-a0b34764.js';
import { _ as _createClass, a as _classCallCheck, b as _objectWithoutProperties } from '../../_rollupPluginBabelHelpers-b054ecd2.js';
import createMask from '../factory.js';
import ChangeDetails from '../../core/change-details.js';
import { DIRECTION } from '../../core/utils.js';
@@ -24,6 +24,8 @@ var PatternInputDefinition = /*#__PURE__*/function () {
/** */
/** */
/** */
function PatternInputDefinition(opts) {
_classCallCheck(this, PatternInputDefinition);
@@ -40,7 +42,7 @@ var PatternInputDefinition = /*#__PURE__*/function () {
_createClass(PatternInputDefinition, [{
key: "reset",
value: function reset() {
this._isFilled = false;
this.isFilled = false;
this.masked.reset();
}
}, {
@@ -50,7 +52,7 @@ var PatternInputDefinition = /*#__PURE__*/function () {
var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
if (fromPos === 0 && toPos >= 1) {
this._isFilled = false;
this.isFilled = false;
return this.masked.remove(fromPos, toPos);
}
@@ -59,7 +61,7 @@ var PatternInputDefinition = /*#__PURE__*/function () {
}, {
key: "value",
get: function get() {
return this.masked.value || (this._isFilled && !this.isOptional ? this.placeholderChar : '');
return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
}
}, {
key: "unmaskedValue",
@@ -73,12 +75,12 @@ var PatternInputDefinition = /*#__PURE__*/function () {
}
}, {
key: "_appendChar",
value: function _appendChar(str) {
value: function _appendChar(ch) {
var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this._isFilled) return new ChangeDetails();
if (this.isFilled) return new ChangeDetails();
var state = this.masked.state; // simulate input
var details = this.masked._appendChar(str, flags);
var details = this.masked._appendChar(ch, flags);
if (details.inserted && this.doValidate(flags) === false) {
details.inserted = details.rawInserted = '';
@@ -90,7 +92,7 @@ var PatternInputDefinition = /*#__PURE__*/function () {
}
details.skip = !details.inserted && !this.isOptional;
this._isFilled = Boolean(details.inserted);
this.isFilled = Boolean(details.inserted);
return details;
}
}, {
@@ -98,17 +100,23 @@ var PatternInputDefinition = /*#__PURE__*/function () {
value: function append() {
var _this$masked;
// TODO probably should be done via _appendChar
return (_this$masked = this.masked).append.apply(_this$masked, arguments);
}
}, {
key: "_appendPlaceholder",
value: function _appendPlaceholder() {
var details = new ChangeDetails();
if (this._isFilled || this.isOptional) return details;
this._isFilled = true;
if (this.isFilled || this.isOptional) return details;
this.isFilled = true;
details.inserted = this.placeholderChar;
return details;
}
}, {
key: "_appendEager",
value: function _appendEager() {
return new ChangeDetails();
}
}, {
key: "extractTail",
value: function extractTail() {
@@ -170,12 +178,12 @@ var PatternInputDefinition = /*#__PURE__*/function () {
get: function get() {
return {
masked: this.masked.state,
_isFilled: this._isFilled
isFilled: this.isFilled
};
},
set: function set(state) {
this.masked.state = state.masked;
this._isFilled = state._isFilled;
this.isFilled = state.isFilled;
}
}]);

View File

@@ -1,7 +1,8 @@
import createMask from './factory.js';
import IMask from '../core/holder.js';
import '../core/utils.js';
import '../_rollupPluginBabelHelpers-a0b34764.js';
import '../_rollupPluginBabelHelpers-b054ecd2.js';
import '../core/change-details.js';
/** Mask pipe source and destination types */

View File

@@ -1,7 +1,7 @@
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, f as _slicedToArray } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, a as _classCallCheck, _ as _createClass, g as _get, h as _getPrototypeOf, f as _slicedToArray } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import MaskedPattern from './pattern.js';
import { normalizePrepare } from '../core/utils.js';
import IMask from '../core/holder.js';
import '../core/utils.js';
import '../core/change-details.js';
import './base.js';
import '../core/continuous-tail-details.js';
@@ -9,6 +9,7 @@ import './pattern/input-definition.js';
import './factory.js';
import './pattern/fixed-definition.js';
import './pattern/chunk-tail-details.js';
import './pattern/cursor.js';
import './regexp.js';
/** Pattern which accepts ranges */
@@ -50,7 +51,8 @@ var MaskedRange = /*#__PURE__*/function (_MaskedPattern) {
// TODO type
opts = Object.assign({
to: this.to || 0,
from: this.from || 0
from: this.from || 0,
maxLength: this.maxLength || 0
}, opts);
var maxLength = String(opts.to).length;
if (opts.maxLength != null) maxLength = Math.max(maxLength, opts.maxLength);
@@ -95,34 +97,46 @@ var MaskedRange = /*#__PURE__*/function (_MaskedPattern) {
minstr = minstr.padEnd(this.maxLength, '0');
maxstr = maxstr.padEnd(this.maxLength, '9');
return [minstr, maxstr];
}
} // TODO str is a single char everytime
/**
@override
*/
}, {
key: "doPrepare",
value: function doPrepare(str) {
value: function doPrepare(ch) {
var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
str = _get(_getPrototypeOf(MaskedRange.prototype), "doPrepare", this).call(this, str, flags).replace(/\D/g, '');
if (!this.autofix) return str;
var details;
var _normalizePrepare = normalizePrepare(_get(_getPrototypeOf(MaskedRange.prototype), "doPrepare", this).call(this, ch.replace(/\D/g, ''), flags));
var _normalizePrepare2 = _slicedToArray(_normalizePrepare, 2);
ch = _normalizePrepare2[0];
details = _normalizePrepare2[1];
if (!this.autofix || !ch) return ch;
var fromStr = String(this.from).padStart(this.maxLength, '0');
var toStr = String(this.to).padStart(this.maxLength, '0');
var val = this.value;
var prepStr = '';
var nextVal = this.value + ch;
if (nextVal.length > this.maxLength) return '';
for (var ci = 0; ci < str.length; ++ci) {
var nextVal = val + prepStr + str[ci];
var _this$boundaries = this.boundaries(nextVal),
_this$boundaries2 = _slicedToArray(_this$boundaries, 2),
minstr = _this$boundaries2[0],
maxstr = _this$boundaries2[1];
var _this$boundaries = this.boundaries(nextVal),
_this$boundaries2 = _slicedToArray(_this$boundaries, 2),
minstr = _this$boundaries2[0],
maxstr = _this$boundaries2[1];
if (Number(maxstr) < this.from) return fromStr[nextVal.length - 1];
if (Number(maxstr) < this.from) prepStr += fromStr[nextVal.length - 1];else if (Number(minstr) > this.to) prepStr += toStr[nextVal.length - 1];else prepStr += str[ci];
if (Number(minstr) > this.to) {
if (this.autofix === 'pad' && nextVal.length < this.maxLength) {
return ['', details.aggregate(this.append(fromStr[nextVal.length - 1] + ch, flags))];
}
return toStr[nextVal.length - 1];
}
return prepStr;
return ch;
}
/**
@override

View File

@@ -1,4 +1,4 @@
import { d as _inherits, e as _createSuper, _ as _createClass, a as _classCallCheck, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-a0b34764.js';
import { d as _inherits, e as _createSuper, _ as _createClass, a as _classCallCheck, g as _get, h as _getPrototypeOf } from '../_rollupPluginBabelHelpers-b054ecd2.js';
import Masked from './base.js';
import IMask from '../core/holder.js';
import '../core/change-details.js';

View File

@@ -67,4 +67,4 @@ $({
});
// TODO: Remove from `core-js@4`
require('./es.global-this');
require('../modules/es.global-this');