UNPKG

@gsretail.com/gui-core

Version:

A skeleton to create your own React component library using Rollup, TypeScript, Sass and Storybook

2 lines (1 loc) 1.95 kB
import t from"./pattern.js";import e from"./range.js";import a from"../core/holder.js";import{isString as s}from"../core/utils.js";import"../core/change-details.js";import"./base.js";import"./factory.js";import"./regexp.js";class r extends t{static GET_DEFAULT_BLOCKS=()=>({d:{mask:e,from:1,to:31,maxLength:2},m:{mask:e,from:1,to:12,maxLength:2},Y:{mask:e,from:1900,to:9999}});static DEFAULTS={mask:Date,pattern:"d{.}`m{.}`Y",format:(t,e)=>{if(!t)return"";return[String(t.getDate()).padStart(2,"0"),String(t.getMonth()+1).padStart(2,"0"),t.getFullYear()].join(".")},parse:(t,e)=>{const[a,s,r]=t.split(".").map(Number);return new Date(r,s-1,a)}};static extractPatternOptions(t){const{mask:e,pattern:a,...r}=t;return{...r,mask:s(e)?e:a}}constructor(t){super(r.extractPatternOptions({...r.DEFAULTS,...t}))}updateOptions(t){super.updateOptions(t)}_update(t){const{mask:e,pattern:a,blocks:o,...i}={...r.DEFAULTS,...t},n=Object.assign({},r.GET_DEFAULT_BLOCKS());t.min&&(n.Y.from=t.min.getFullYear()),t.max&&(n.Y.to=t.max.getFullYear()),t.min&&t.max&&n.Y.from===n.Y.to&&(n.m.from=t.min.getMonth()+1,n.m.to=t.max.getMonth()+1,n.m.from===n.m.to&&(n.d.from=t.min.getDate(),n.d.to=t.max.getDate())),Object.assign(n,this.blocks,o),Object.keys(n).forEach((e=>{const a=n[e];!("autofix"in a)&&"autofix"in t&&(a.autofix=t.autofix)})),super._update({...i,mask:s(e)?e:a,blocks:n})}doValidate(t){const e=this.date;return super.doValidate(t)&&(!this.isComplete||this.isDateExist(this.value)&&null!=e&&(null==this.min||this.min<=e)&&(null==this.max||e<=this.max))}isDateExist(t){return this.format(this.parse(t,this),this).indexOf(t)>=0}get date(){return this.typedValue}set date(t){this.typedValue=t}get typedValue(){return this.isComplete?super.typedValue:null}set typedValue(t){super.typedValue=t}maskEquals(t){return t===Date||super.maskEquals(t)}optionsIsChanged(t){return super.optionsIsChanged(r.extractPatternOptions(t))}}a.MaskedDate=r;export{r as default};