@gsretail.com/gui-core
Version:
A skeleton to create your own React component library using Rollup, TypeScript, Sass and Storybook
2 lines (1 loc) • 2.29 kB
JavaScript
import t from"../core/change-details.js";import e from"../core/holder.js";import s,{normalizeOpts as a}from"./factory.js";import r from"./pattern.js";import"./base.js";import"./regexp.js";class i extends r{get repeatFrom(){return(Array.isArray(this.repeat)?this.repeat[0]:this.repeat===1/0?0:this.repeat)??0}get repeatTo(){return(Array.isArray(this.repeat)?this.repeat[1]:this.repeat)??1/0}constructor(t){super(t)}updateOptions(t){super.updateOptions(t)}_update(t){const{repeat:e,...r}=a(t);this._blockOpts=Object.assign({},this._blockOpts,r);const i=s(this._blockOpts);this.repeat=e??i.repeat??this.repeat??1/0,super._update({mask:"m".repeat(Math.max(this.repeatTo===1/0&&this._blocks?.length||0,this.repeatFrom)),blocks:{m:i},eager:i.eager,overwrite:i.overwrite,skipInvalid:i.skipInvalid,lazy:i.lazy,placeholderChar:i.placeholderChar,displayChar:i.displayChar})}_allocateBlock(t){return t<this._blocks.length?this._blocks[t]:this.repeatTo===1/0||this._blocks.length<this.repeatTo?(this._blocks.push(s(this._blockOpts)),this.mask+="m",this._blocks[this._blocks.length-1]):void 0}_appendCharRaw(e,s){void 0===s&&(s={});const a=new t;for(let t,r,i=this._mapPosToBlock(this.displayValue.length)?.index??Math.max(this._blocks.length-1,0);t=this._blocks[i]??(r=!r&&this._allocateBlock(i));++i){const o=t._appendChar(e,{...s,_beforeTailState:s._beforeTailState?._blocks?.[i]});if(o.skip&&r){this._blocks.pop(),this.mask=this.mask.slice(1);break}if(a.aggregate(o),o.skip||o.rawInserted)break}return a}_trimEmptyTail(t,e){void 0===t&&(t=0);const s=Math.max(this._mapPosToBlock(t)?.index||0,this.repeatFrom,0);let a;null!=e&&(a=this._mapPosToBlock(e)?.index),null==a&&(a=this._blocks.length-1);let r=0;for(let t=a;s<=t&&!this._blocks[t].unmaskedValue;--t,++r);r&&(this._blocks.splice(a-r+1,r),this.mask=this.mask.slice(r))}reset(){super.reset(),this._trimEmptyTail()}remove(t,e){void 0===t&&(t=0),void 0===e&&(e=this.displayValue.length);const s=super.remove(t,e);return this._trimEmptyTail(t,e),s}totalInputPositions(t,e){return void 0===t&&(t=0),null==e&&this.repeatTo===1/0?1/0:super.totalInputPositions(t,e)}get state(){return super.state}set state(t){this._blocks.length=t._blocks.length,this.mask=this.mask.slice(0,this._blocks.length),super.state=t}}e.RepeatBlock=i;export{i as default};