jb-date-input
Version:
jalali date input web component
2 lines • 5.19 kB
JavaScript
var e=Object.create,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,u=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,c=(e,u,c,o)=>{if(u&&"object"==typeof u||"function"==typeof u)for(var l,i=n(u),s=0,f=i.length;s<f;s++)l=i[s],a.call(e,l)||l===c||t(e,l,{get:(e=>u[e]).bind(null,l),enumerable:!(o=r(u,l))||o.enumerable});return e},o=(r,n,a)=>(a=null!=r?e(u(r)):{},c(!n&&r&&r.__esModule?a:t(a,"default",{value:r,enumerable:!0}),r));const l=o(require("react")),i=o(require("jb-date-input"));function s(e,t,r,n=!1){let u=(0,l.useCallback)(t=>{e.current&&"function"==typeof r&&r(t)},[e,r]);(0,l.useEffect)(()=>{let r=e.current;return r&&r.addEventListener(t,u,{passive:n,capture:!1}),function(){r&&r.removeEventListener(t,u,{passive:n,capture:!1})}},[e,t,r,n])}const f=(0,l.forwardRef)((e,t)=>{let r=(0,l.useRef)(null);(0,l.useImperativeHandle)(t,()=>r?r.current:{},[r]);let n=(0,l.useRef)([]);return(0,l.useEffect)(()=>{e.format&&(e.format!==r.current?.valueFormat&&r.current?.setAttribute("format",e.format),n.current.length>0&&(n.current.forEach(e=>{e()}),n.current=[]))},[e.format]),(0,l.useEffect)(()=>{e.max&&(e.format&&e.format!==r.current?.valueFormat?n.current.push(()=>{e.max&&r.current?.setMaxDate(e.max)}):r.current?.setMaxDate(e.max))},[e.max]),(0,l.useEffect)(()=>{e.name?r?.current?.setAttribute("name",e.name||""):r?.current?.removeAttribute("name")},[e.name]),(0,l.useEffect)(()=>{e.min&&(e.format&&e.format!==r.current?.valueFormat?n.current.push(()=>{e.min&&r.current?.setMinDate(e.min)}):r.current?.setMinDate(e.min))},[e.min]),(0,l.useEffect)(()=>{r.current&&e.value&&(r.current.value=e.value)},[e.value]),(0,l.useEffect)(()=>{r.current&&r.current.setAttribute("message",e.message||"")},[e.message]),(0,l.useEffect)(()=>{r.current&&Array.isArray(e.jalaliMonthList)&&r.current.setMonthList("JALALI",e.jalaliMonthList)},[e.jalaliMonthList]),(0,l.useEffect)(()=>{r.current&&Array.isArray(e.gregorianMonthList)&&r.current.setMonthList("GREGORIAN",e.gregorianMonthList)},[e.gregorianMonthList]),(0,l.useEffect)(()=>{r.current&&void 0!==e.placeholder&&(r.current.placeholder=e.placeholder)},[e.placeholder]),(0,l.useEffect)(()=>{r.current&&void 0!==e.overflowHandler&&(r.current.elements.popover.overflowHandler=e.overflowHandler)},[e.overflowHandler]),(0,l.useEffect)(()=>{r.current&&void 0!==e.overflowRef&&(r.current.elements.popover.overflowDom=e.overflowRef.current)},[e.overflowRef]),(0,l.useEffect)(()=>{r.current&&"string"==typeof e.style&&r.current.setAttribute("style",e.style)},[e.style]),(0,l.useEffect)(()=>{r.current&&Array.isArray(e.validationList)&&(r.current.validation.list=e.validationList)},[e.validationList]),(0,l.useEffect)(()=>{r.current&&e.direction&&r.current.setAttribute("direction",e.direction)},[e.direction]),(0,l.useEffect)(()=>{r.current&&(e.required?r.current.required=!0:r.current.required=!1)},[e.required,r.current]),(0,l.useEffect)(()=>{"object"==typeof e.calendarDefaultDateView&&e.calendarDefaultDateView.year&&e.calendarDefaultDateView.month&&r.current?.setCalendarDefaultDateView(e.calendarDefaultDateView.year,e.calendarDefaultDateView.month,e.calendarDefaultDateView.dateType)},[e.calendarDefaultDateView]),(0,l.useEffect)(()=>{e.showPersianNumber?r.current?.setAttribute("show-persian-number","true"):r.current?.removeAttribute("show-persian-number")},[e.showPersianNumber]),(0,l.useEffect)(()=>{"boolean"==typeof e.disabled&&r?.current?.setAttribute("disabled",`${e.disabled}`)},[e.disabled]),(0,l.useEffect)(()=>{e.error?r?.current?.setAttribute("error",e.error):r?.current?.removeAttribute("error")},[e.error]),s(r,"load",e.onLoad,!0),s(r,"init",e.onInit,!0),s(r,"invalid",e.onInvalid,!0),s(r,"change",e.onChange,!0),s(r,"beforeinput",e.onBeforeInput,!1),s(r,"input",e.onInput,!0),s(r,"keyup",e.onKeyUp,!0),s(r,"keydown",e.onKeyDown,!1),s(r,"keypress",e.onKeyPress,!0),s(r,"select",e.onSelect,!0),s(r,"focus",e.onFocus,!0),s(r,"blur",e.onBlur,!0),l.default.createElement("jb-date-input",{class:e.className?e.className:"",label:e.label,"value-type":e.valueType?e.valueType:"GREGORIAN",ref:r,"input-type":e.inputType?e.inputType:"JALALI"},e.children)});f.displayName="JBDateInput",exports.JBDateInput=f,exports.useJBDateInput=function(e){let[t,r]=(0,l.useState)(i.emptyInputValueString),n=(0,l.useRef)(null);(0,l.useEffect)(()=>{n.current&&setTimeout(()=>{e.ref.current.setSelectionRange(n.current.selectionStart,n.current.selectionEnd),n.current=null},0)},[t,n.current]);let u=()=>{if(null===n.current){let r=(0,i.getFixedCaretPos)({inputValue:t,selectionStart:e.ref.current.selectionStart});null!=r&&r!==e.ref.current.selectionStart&&e.ref.current.setSelectionRange(r,r)}};return s(e.ref,"beforeinput",function(u){n.current=(0,i.handleBeforeInput)({dateInputType:e.dateInputType,selection:{start:e.ref.current.selectionStart,end:e.ref.current.selectionEnd},value:t,showPersianNumber:e.showPersianNumber,event:{inputType:u.inputType,data:u.data}}),u.preventDefault(),r(n.current.value),e.ref.current.setSelectionRange(n.current.selectionStart,n.current.selectionEnd)}),{value:t,setValue:r,onFocus:()=>{u()},onClick:()=>{u()},onChange:()=>{}}};
//# sourceMappingURL=JBDateInput.cjs.js.map