UNPKG

@progress/kendo-vue-dateinputs

Version:
9 lines (8 loc) 5.6 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),k=require("@progress/kendo-vue-buttons"),L=require("@progress/kendo-date-math"),l=require("@progress/kendo-vue-common"),v=require("@progress/kendo-vue-intl"),u=require("../messages/main.js"),$=require("./TimeList.js"),p=require("../utils.js"),c=require("./models/TimePart.js"),o=require("./utils.js");function w(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!s.isVNode(t)}const m=new RegExp(`${c.TIME_PART.hour}|${c.TIME_PART.minute}|${c.TIME_PART.second}|${c.TIME_PART.dayperiod}|literal`);let h=function(t){return t[t.Left=0]="Left",t[t.Right=1]="Right",t}({});const T=s.defineComponent({name:"KendoTimePart",props:{cancelButton:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},format:{type:[String,Object],default:function(){return"hh:mm a"}},max:{type:Date,default:function(){return p.MAX_TIME}},min:{type:Date,default:function(){return p.MIN_TIME}},nowButton:{type:Boolean,default:!0},steps:{type:Object,default:function(){return{}}},smoothScroll:{type:Boolean,default:!0},tabIndex:Number,value:{type:Date,default:function(){return null}},boundRange:{type:Boolean,default:!1}},emits:{change:null,focus:null,blur:null,nowclick:null},created(){this.timeLists=[],this.snapTime=o.snapTime(o.generateSnappers(this.$props.steps,this.$props.min)),this.activeListIndex=-1,this.hasActiveButton=this.hasActiveButton.bind(this)},inject:{kendoIntlService:{default:null},kendoLocalizationService:{default:null}},data(){return{activeListIndex:null}},computed:{element(){return this._element},computedValue(){return o.timeInRange(this.snapTime(L.cloneDate(this.$props.value||p.MIDNIGHT_DATE)),this.computedMin,this.computedMax)},intl(){return v.provideIntlService(this)},computedMin(){return this.snapTime(this.$props.min)},computedMax(){return this.snapTime(this.$props.max)}},mounted(){this._nowButton=this.$refs.nowButton,this.dateFormatParts.forEach((t,e)=>{t.type!=="literal"&&this.timeLists.push(this.$refs["timeList"+e])})},setup(){const t=s.inject("kendoIntlService",{}),e=s.inject("kendoLocalizationService",{});return{kendoIntlService:t,kendoLocalizationService:e}},render(){let t;const{format:e,smoothScroll:n,disabled:i}=this.$props;this.snapTime=o.snapTime(o.generateSnappers(this.$props.steps,this.computedMin)),this.dateFormatParts=this.intl.splitDateFormat(e).filter(this.timeFormatFilter);const y=l.classNames({"k-disabled":i},"k-time-part"),f=v.provideLocalizationService(this),g=f.toLanguageString(u.selectNow,u.messages[u.selectNow]);return s.createVNode("div",{class:y},[s.createVNode("div",{class:"k-time-header"},[s.createVNode("span",{class:"k-title"},[this.intl.formatDate(this.computedValue,this.dateFormatParts.reduce(this.timeFormatReducer,""))]),this.showNowButton()&&s.createVNode(k.Button,{type:"button",ref:"nowButton",fillMode:"flat",class:"k-time-now",title:g,"aria-label":g,onClick:this.onNowClick,tabIndex:i?-1:0},w(t=f.toLanguageString(u.now,u.messages[u.now]))?t:{default:()=>[t]})]),s.createVNode("div",{class:"k-time-list-container",onKeydown:this.handleKeyDown},[s.createVNode("span",{class:"k-time-highlight"},null),this.dateFormatParts.map(function(r,a){return r.type!=="literal"?s.createVNode("div",{key:a,class:l.classNames("k-time-list-wrapper",{"k-focus":a===this.activeListIndex}),role:"presentation",tabindex:-1},[s.createVNode("span",{class:"k-title",onMousedown:d=>{d.preventDefault()}},[this.intl.dateFieldName(r)]),s.createVNode($.TimeList,{min:this.computedMin,max:this.computedMax,boundRange:this.$props.boundRange,part:r,step:r.type?this.$props.steps[r.type]:1,smoothScroll:n,ref:"timeList"+a,id:a,onFocus:d=>{this.handleListFocus(d,a)},onBlur:this.handleListBlur,onChange:this.handleChange,value:this.computedValue,disabled:i},null)]):s.createVNode("div",{key:a,class:"k-time-separator"},[r.pattern])},this)])])},methods:{onNowClick(t){this.$emit("nowclick",t)},focus(t){this.$nextTick(()=>{const e=this.timeLists[0];!this.hasActiveButton()&&e&&e.$el&&e.focus(t)})},timeFormatReducer(t,e){return t+e.pattern},timeFormatFilter(t,e,n){const i=e>=1&&n[e-1];return i&&i&&t.type==="literal"?m.test(i.type||""):m.test(t.type||"")},hasActiveButton(){return l.canUseDOM&&this._nowButton&&document.activeElement===this._nowButton.$el},focusList(t){this.timeLists.length&&this.timeLists.reduce(this.listReducer,[]).map(e=>t===h.Right?e.next:e.prev).map(e=>e&&e.$el&&e.$el.focus({preventScroll:!0}))},listReducer(t,e,n,i){return t.length||e.$props.id!==this.activeListIndex?t:[{next:i[n+1]||e,prev:i[n-1]||e}]},showNowButton(){return!this.hasSteps()&&this.$props.nowButton&&o.isInTimeRange(o.getNow(),this.computedMin,this.computedMax)},hasSteps(){const t=Object.keys(this.$props.steps);return t.length!==t.reduce((e,n)=>e+this.$props.steps[n],0)},handleKeyDown(t){const{keyCode:e}=t;switch(e){case l.Keys.left:t.preventDefault(),this.focusList(h.Left);return;case l.Keys.right:t.preventDefault(),this.focusList(h.Right);return;default:return}},handleListBlur(t){this.$emit("blur",t)},handleListFocus(t,e){this.$emit("focus",t),this.activeListIndex=e},handleChange(t){this.$emit("change",t)}}});exports.Direction=h;exports.TimePart=T;