GULP DIST
This commit is contained in:
+109
-211
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user