Module 666944

2,601 characters · in web.692b1813fcabadaf.js
Dependencies
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{c:()=>S});var i=n(477900),r=n(582128),a=n(890497);n(321073);var s=n(536637),l=n.n(s),o=n(58703);let d=/^[0]+/,c=/:00/,u=/(AM|\u03a0\u039c|\u0938\u0941\u092c\u0939)/i,_=/(PM|\u039c\u039c|\u0936\u093e\u092e)/i,E=/\s+/;function A(e){return e.replace(d,"").replace(c,"").replace(u,"").replace(E,"")}function h(e){return e.replace(d,"").replace(_,"").replace(E,"")}function I(e,t){let n=t.toUpperCase().trim();if(0!==n.length)for(let t of[p,"H:mm","H.mm"]){let i=l()(`${e?.format("YYYY-MM-DD")} ${n}`,`YYYY-MM-DD ${t}`);if(A(i.format(t))===A(n))return i}}let f=l()("2021-04-12T00:00:00"),p="LT";function T(e,t){return e.clone().hours(t.hour()).minutes(t.minutes()).seconds(0)}function m(e,t){return e.value.unix()-t.value.unix()}class g{intervalInMinutes;labelFormat;options=[];_index={};constructor({intervalInMinutes:e=15,labelFormat:t=p}={}){if(e<=0)throw Error(`intervalInMinutes should be positive number, got ${e}`);this.intervalInMinutes=e,this.labelFormat=t,this._generateTimeOptions()}lookupByValue(e){if(null==e)return;let t=T(f,e);return this._index[t.unix()]}_createLabel(e){return(0,o.i$)(e.locale(l().locale()),this.labelFormat)}_generateTimeOptions(){this.options=[],this._index={};let e=l()(f),t=l()(e).add(1,"day"),n=l()(e);for(;n<t;){let e=this._createNewOption(n.clone());this.options.push(e),this._index[e.value.unix()]=e.value,n.add(this.intervalInMinutes,"minutes")}}_createNewOption(e){let t=T(f,e),n=this._createLabel(t);return{id:t.toISOString(),label:n,value:t}}_addNewOption(e){let t=T(f,e),n=this._createLabel(t);return this._index[t.unix()]=t,this.options.push({id:t.toISOString(),label:n,value:t}),this.options.sort(m),e}_guessOptions(e){let t=[];if(/[:\\.]/.test(e)){let n=I(f,e);if(null!=n){t.push(n.clone());let i=n.add({hours:12});i.isBefore(f.clone().add({hours:24}))&&h(i.format("LT"))===h(e)&&t.push(i)}}return t}getOptions(e){let t=this._guessOptions(e);if(!(t.length>0))return this.options;{let e=[...this.options];return t.forEach(t=>{null==this.lookupByValue(t)&&e.push(this._createNewOption(t))}),e.sort(m),e}}selectValue(e){let t=this.lookupByValue(e);return null==t?this._addNewOption(e):t}}function S(e){let{value:t,onChange:n,hideValue:s,disabled:l=!1,...o}=e,d=r.useMemo(()=>new g,[]),[c,u]=r.useState("");function _(e){null!=t&&n(T(t,d.selectValue(e)))}function E(){let e=I(t,c);null!=e&&_(e)}return(0,i.jsx)(a.Z,{...o,selectionMode:"single",options:d.getOptions(c),value:s?void 0:d.lookupByValue(t),onSelectionChange:_,disabled:l,onQueryChange:e=>u(e.target.value),onKeyDown:function(e){"Enter"===e.key&&E()},onBlur:E})}}