@gspa/ui 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/DatePicker.vue_vue_type_script_setup_true_lang-CIKiZaO1.cjs +1 -0
- package/dist/DatePicker.vue_vue_type_script_setup_true_lang-Dx_9f8DO.js +557 -0
- package/dist/{FormField.vue_vue_type_script_setup_true_lang-DimMUyA-.js → FormField.vue_vue_type_script_setup_true_lang-BljDj5YZ.js} +1 -1
- package/dist/FormField.vue_vue_type_script_setup_true_lang-FWitIR3U.cjs +1 -0
- package/dist/Toast.css +1 -1
- package/dist/components/DatePicker.cjs +1 -1
- package/dist/components/DatePicker.js +2 -399
- package/dist/components/FormField.cjs +1 -1
- package/dist/components/FormField.js +1 -1
- package/dist/components/ReusableForm.cjs +1 -1
- package/dist/components/ReusableForm.js +2 -2
- package/dist/components/Toast.cjs +1 -1
- package/dist/components/Toast.js +121 -177
- package/dist/gspa-ui.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/src/components/Calendar.vue.d.ts +4 -4
- package/dist/src/components/DatePicker.vue.d.ts +139 -29
- package/dist/src/components/DatePicker.vue.d.ts.map +1 -1
- package/dist/src/components/Toast.vue.d.ts.map +1 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/FormField.vue_vue_type_script_setup_true_lang-mEO-VA6R.cjs +0 -1
package/README.md
CHANGED
|
@@ -898,8 +898,12 @@ A date picker component with calendar dropdown.
|
|
|
898
898
|
| `required` | `Boolean` | `false` | Whether required |
|
|
899
899
|
| `min` | `String \| Date` | - | Minimum selectable date |
|
|
900
900
|
| `max` | `String \| Date` | - | Maximum selectable date |
|
|
901
|
+
| `minDate` | `String \| Date` | - | Minimum selectable date (takes precedence over `min`) |
|
|
902
|
+
| `maxDate` | `String \| Date` | - | Maximum selectable date (takes precedence over `max`) |
|
|
903
|
+
| `yearRange` | `readonly [number, number]` | - | Inclusive years shown and selectable |
|
|
904
|
+
| `initialView` | `'day' \| 'month' \| 'year'` | `'day'` | View displayed whenever the calendar opens |
|
|
901
905
|
| `placeholder` | `String` | `'Select date'` | Placeholder text |
|
|
902
|
-
| `format` | `String` | `'MM/
|
|
906
|
+
| `format` | `String` | `'DD/MM/YYYY'` | Date format |
|
|
903
907
|
| `clearable` | `Boolean` | `true` | Show clear button |
|
|
904
908
|
| `showToday` | `Boolean` | `true` | Show today button in calendar |
|
|
905
909
|
| `calendarPosition` | `String` | `'left-0 bottom-full'` | Calendar dropdown position |
|
|
@@ -934,6 +938,18 @@ const maxDate = '2023-12-31'
|
|
|
934
938
|
</script>
|
|
935
939
|
```
|
|
936
940
|
|
|
941
|
+
For a date-of-birth field that emits an API-ready `YYYY-MM-DD` value:
|
|
942
|
+
|
|
943
|
+
```vue
|
|
944
|
+
<DatePicker
|
|
945
|
+
v-model="dateOfBirth"
|
|
946
|
+
initial-view="year"
|
|
947
|
+
:year-range="[1900, currentYear]"
|
|
948
|
+
:max-date="yesterday"
|
|
949
|
+
format="YYYY-MM-DD"
|
|
950
|
+
/>
|
|
951
|
+
```
|
|
952
|
+
|
|
937
953
|
## ReusableForm (v2)
|
|
938
954
|
|
|
939
955
|
A reusable inline form component with optional sectioned layout, field-level slot overrides, and cross-field validation.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("vue"),ze={class:"relative w-full rounded-md bg-(--ui-surface)"},He={class:"relative"},Ke=["id","value","disabled","placeholder","required","aria-describedby","aria-expanded"],Oe={class:"min-w-0"},Ue={class:"mb-3 flex items-center justify-between gap-2"},qe=["disabled","aria-disabled","aria-label"],je=["aria-label"],We=["disabled","aria-disabled","aria-label"],Ge={class:"mb-1 grid grid-cols-7 gap-1","aria-hidden":"true"},Ze=["aria-label"],Je=["data-day","data-focus-preferred","disabled","aria-disabled","aria-selected","aria-label","onClick","onKeydown"],Qe=["aria-label"],Xe=["data-focus-preferred","disabled","aria-disabled","aria-selected","aria-label","onClick"],et=["aria-label"],tt=["data-focus-preferred","disabled","aria-disabled","aria-selected","aria-label","onClick"],at={key:3,class:"mt-3 border-t pt-2 ui-border"},rt=["disabled","aria-disabled"],lt={key:0,class:"border-t pt-3 ui-border sm:border-l sm:border-t-0 sm:pl-3 sm:pt-0"},nt={class:"max-h-64 space-y-1 overflow-y-auto pr-1"},ot=["aria-selected","onClick"],k=12,it=e.defineComponent({__name:"DatePicker",props:{id:String,modelValue:{type:[String,Date],default:""},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1},min:[String,Date],max:[String,Date],minDate:[String,Date],maxDate:[String,Date],yearRange:Array,initialView:{type:String,default:"day",validator:f=>["day","month","year"].includes(f)},placeholder:{type:String,default:"Select date"},format:{type:String,default:"DD/MM/YYYY"},clearable:{type:Boolean,default:!0},showToday:{type:Boolean,default:!0},calendarPosition:{type:String,default:"left-0 bottom-full"},ariaDescribedby:String,customValidation:{type:Function,default:null},disabledDates:{type:[Array,Function],default:null},enableTime:{type:Boolean,default:!1},minuteInterval:{type:Number,default:1}},emits:["update:modelValue","validation-error"],setup(f,{emit:xe}){const i=f,S=xe,p=e.ref(!1),s=e.ref("day"),T=e.ref(null),z=e.ref(null),X=e.ref({}),v=A(new Date),c=e.ref(v.getMonth()),n=e.ref(v.getFullYear()),C=e.ref(v.getDate()),b=e.ref(Math.floor(v.getFullYear()/k)*k),u=e.ref(null),Y=e.ref(!1),D=e.ref("00:00"),we=["Su","Mo","Tu","We","Th","Fr","Sa"],ee=Array.from({length:12},(t,a)=>new Date(2e3,a,1).toLocaleString("default",{month:"long"})),x=e.computed(()=>I(i.minDate??i.min)),w=e.computed(()=>I(i.maxDate??i.max)),m=e.computed(()=>{if(!i.yearRange||i.yearRange.length!==2)return null;const t=Math.trunc(Number(i.yearRange[0])),a=Math.trunc(Number(i.yearRange[1]));return!Number.isFinite(t)||!Number.isFinite(a)?null:t<=a?[t,a]:[a,t]}),B=e.computed(()=>Math.max(m.value?.[0]??Number.NEGATIVE_INFINITY,x.value?.getFullYear()??Number.NEGATIVE_INFINITY)),F=e.computed(()=>Math.min(m.value?.[1]??Number.POSITIVE_INFINITY,w.value?.getFullYear()??Number.POSITIVE_INFINITY)),H=e.computed(()=>ee[c.value]),te=e.computed(()=>M(n.value,c.value)),ae=e.computed(()=>d(n.value,c.value,1).getDay()),re=e.computed(()=>{const t=M(n.value,c.value-1);return Array.from({length:ae.value},(a,r)=>t-ae.value+r+1)}),De=e.computed(()=>{const t=re.value.length+te.value,a=t%7===0?0:7-t%7;return Array.from({length:a},(r,l)=>l+1)}),le=e.computed(()=>Array.from({length:k},(t,a)=>b.value+a).filter(t=>t>=B.value&&t<=F.value)),ne=e.computed(()=>b.value+k-1),$=e.computed(()=>{if(s.value==="day")return`${H.value} ${n.value}`;if(s.value==="month")return String(n.value);const t=le.value;return t.length?`${t[0]}–${t[t.length-1]}`:`${b.value}–${ne.value}`}),Ne=e.computed(()=>s.value==="day"?`Select the month. Currently ${$.value}`:s.value==="month"?`Select the year. Currently ${n.value}`:`Return to day selection. Showing years ${$.value}`),Ee=e.computed(()=>s.value==="day"?"Previous month":s.value==="month"?"Previous year":"Previous year range"),Se=e.computed(()=>s.value==="day"?"Next month":s.value==="month"?"Next year":"Next year range"),K=e.computed(()=>s.value==="day"?j(n.value,c.value-1):s.value==="month"?n.value-1>=B.value:b.value>B.value),O=e.computed(()=>s.value==="day"?j(n.value,c.value+1):s.value==="month"?n.value+1<=F.value:ne.value<F.value),oe=e.computed(()=>u.value?i.enableTime?Me(u.value):ie(u.value):""),Be=e.computed(()=>{const t=Math.min(60,Math.max(1,Number(i.minuteInterval)||1)),a=[];for(let r=0;r<24;r++)for(let l=0;l<60;l+=t)a.push(`${String(r).padStart(2,"0")}:${String(l).padStart(2,"0")}`);return a});function d(t,a,r,l=0,o=0){const y=new Date(0);return y.setFullYear(t,a,r),y.setHours(l,o,0,0),y}function A(t){return d(t.getFullYear(),t.getMonth(),t.getDate())}function M(t,a){return d(t,a+1,0).getDate()}function I(t){if(!t)return null;if(t instanceof Date)return Number.isNaN(t.getTime())?null:d(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes());const a=t.match(/^(\d{4,})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?/);if(a){const[,l,o,y,h="0",V="0"]=a,ye=Number(l),he=Number(o)-1,ke=Number(y),P=d(ye,he,ke,Number(h),Number(V));return P.getFullYear()===ye&&P.getMonth()===he&&P.getDate()===ke?P:null}const r=new Date(t);return Number.isNaN(r.getTime())?null:r}function g(t){return d(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function ie(t){const a=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return i.format.replace("MM",a).replace("DD",r).replace("YYYY",String(t.getFullYear()))}function Me(t){const a=String(t.getHours()).padStart(2,"0"),r=String(t.getMinutes()).padStart(2,"0");return`${ie(t)} ${a}:${r}`}function Ve(t){const a=String(t.getFullYear()).padStart(4,"0"),r=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0");return`${a}-${r}-${l}`}function U(t){const a=g(t);return!(x.value&&a<g(x.value)||w.value&&a>g(w.value)||m.value&&(t.getFullYear()<m.value[0]||t.getFullYear()>m.value[1]))}function N(t){return!U(t)||i.disabledDates&&(typeof i.disabledDates=="function"&&i.disabledDates(new Date(t))||Array.isArray(i.disabledDates)&&i.disabledDates.some(a=>{const r=I(a);return r?g(r)===g(t):!1}))?!0:!!i.customValidation?.(new Date(t))}function q(t){return N(d(n.value,c.value,t))}function _(t){for(let a=1;a<=M(n.value,t);a++)if(!N(d(n.value,t,a)))return!1;return!0}function R(t){if(t<B.value||t>F.value)return!0;for(let a=0;a<12;a++)for(let r=1;r<=M(t,a);r++)if(!N(d(t,a,r)))return!1;return!0}function j(t,a){const r=d(t,a,1),l=d(r.getFullYear(),r.getMonth()+1,0);return!(r.getFullYear()<B.value||r.getFullYear()>F.value||x.value&&g(l)<g(x.value)||w.value&&g(r)>g(w.value))}function W(t){const a=m.value?.[0];return a!==void 0?a+Math.floor((t-a)/k)*k:Math.floor(t/k)*k}function ue(t){let a=A(t);return m.value&&a.getFullYear()<m.value[0]&&(a=d(m.value[0],0,1)),m.value&&a.getFullYear()>m.value[1]&&(a=d(m.value[1],11,31)),x.value&&g(a)<g(x.value)&&(a=A(x.value)),w.value&&g(a)>g(w.value)&&(a=A(w.value)),a}function Te(t){return v.getDate()===t&&v.getMonth()===c.value&&v.getFullYear()===n.value}function G(t){return!!(u.value&&u.value.getDate()===t&&u.value.getMonth()===c.value&&u.value.getFullYear()===n.value)}function se(t){if(!t)return Y.value=!1,S("validation-error",null),!0;const a=i.customValidation?.(new Date(t))||null;return Y.value=!!a,S("validation-error",a),!a}async function Z(){await e.nextTick();const t=z.value||(i.id?document.getElementById(i.id):null);if(!t||!T.value)return;const a=t.getBoundingClientRect(),r=T.value.offsetHeight||360,l=T.value.offsetWidth||(i.enableTime?448:320),o=window.innerHeight-a.bottom,y=o>=r||o>a.top?a.bottom+8:Math.max(8,a.top-r-8),h=Math.min(Math.max(16,a.left),Math.max(16,window.innerWidth-l-16));X.value={top:`${y}px`,left:`${h}px`}}function E(t){C.value=t.getDate(),c.value=t.getMonth(),n.value=t.getFullYear(),b.value=W(t.getFullYear())}async function de(){i.disabled||p.value||((!u.value||!U(u.value))&&E(ue(v)),s.value=i.initialView,b.value=W(n.value),p.value=!0,await Z(),await ve())}function Ye(){p.value?L():de()}function L(t=!1){p.value=!1,t&&e.nextTick(()=>z.value?.focus())}async function J(t){s.value=t,t==="year"&&(b.value=W(n.value)),await e.nextTick(),await Z(),await ve()}function Fe(){J({day:"month",month:"year",year:"day"}[s.value])}function Ce(){K.value&&(s.value==="day"?E(d(n.value,c.value-1,1)):s.value==="month"?n.value--:b.value=Math.max(b.value-k,B.value))}function $e(){O.value&&(s.value==="day"?E(d(n.value,c.value+1,1)):s.value==="month"?n.value++:b.value+=k)}function Ae(t){R(t)||(n.value=t,J("month"))}function Ie(t){_(t)||(c.value=t,C.value=Math.min(C.value,M(n.value,t)),J("day"))}function ce(t){const a=d(n.value,c.value,t);if(N(a)||!se(a))return;const[r="0",l="0"]=D.value.split(":");a.setHours(Number(r),Number(l),0,0),u.value=a,fe(a),i.enableTime||window.setTimeout(()=>L(),150)}function fe(t){const a=Ve(t);i.enableTime?S("update:modelValue",`${a}T${D.value}`):S("update:modelValue",a)}function _e(){N(v)||(E(v),ce(v.getDate()))}function Re(){u.value=null,D.value="00:00",Y.value=!1,S("update:modelValue",""),S("validation-error",null)}function Q(){return Array.from(T.value?.querySelectorAll("[data-picker-option]:not(:disabled)")||[])}async function ve(){await e.nextTick();const t=Q(),a=t.find(l=>l.getAttribute("aria-selected")==="true"),r=t.find(l=>l.dataset.focusPreferred==="true");(a||r||t[0])?.focus()}function me(t,a){const r=Q(),l=r.indexOf(t.currentTarget);if(l<0)return;let o=l;if(t.key==="ArrowRight")o=Math.min(r.length-1,l+1);else if(t.key==="ArrowLeft")o=Math.max(0,l-1);else if(t.key==="ArrowDown")o=Math.min(r.length-1,l+a);else if(t.key==="ArrowUp")o=Math.max(0,l-a);else if(t.key==="Home")o=l-l%a;else if(t.key==="End")o=Math.min(r.length-1,l+a-1-l%a);else return;t.preventDefault(),r[o]?.focus()}function Le(t,a){if(t.key==="PageUp"||t.key==="PageDown"){t.preventDefault();const h=t.key==="PageUp"?-1:1,V=d(n.value,c.value+h,Math.min(a,M(n.value,c.value+h)));j(V.getFullYear(),V.getMonth())&&(E(V),e.nextTick(()=>ge(V.getDate(),h)));return}if(!["ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"].includes(t.key))return;t.preventDefault();let l={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7}[t.key];t.key==="Home"&&(l=-d(n.value,c.value,a).getDay()),t.key==="End"&&(l=6-d(n.value,c.value,a).getDay());let o=d(n.value,c.value,a+l);const y=l<0?-1:1;for(let h=0;h<3660;h++){if(!U(o))return;if(!N(o)){E(o),e.nextTick(()=>ge(o.getDate(),y));return}o=d(o.getFullYear(),o.getMonth(),o.getDate()+y)}}function ge(t,a){const r=Q();(r.find(o=>Number(o.dataset.day)===t)||(a<0?r.at(-1):r[0]))?.focus()}function Pe(t){["Enter"," ","ArrowDown"].includes(t.key)?(t.preventDefault(),de()):t.key==="Escape"&&p.value&&(t.preventDefault(),L(!0))}function pe(t){t.key==="Escape"&&p.value&&(t.preventDefault(),L(!0))}function be(){p.value&&Z()}return e.watch(()=>i.modelValue,t=>{const a=I(t);if(!a){u.value=null,Y.value=!1;return}u.value=a,D.value=`${String(a.getHours()).padStart(2,"0")}:${String(a.getMinutes()).padStart(2,"0")}`,E(a),se(a)},{immediate:!0}),e.watch([m,x,w],()=>{!u.value&&!p.value&&E(ue(v))}),e.watch(D,t=>{if(!i.enableTime||!u.value)return;const[a="0",r="0"]=t.split(":");u.value.setHours(Number(a),Number(r),0,0),fe(u.value)}),e.onMounted(()=>{document.addEventListener("keydown",pe),window.addEventListener("resize",be)}),e.onBeforeUnmount(()=>{document.removeEventListener("keydown",pe),window.removeEventListener("resize",be)}),(t,a)=>(e.openBlock(),e.createElementBlock("div",ze,[e.createElementVNode("div",He,[e.createElementVNode("input",{id:f.id,ref_key:"inputRef",ref:z,type:"text",value:oe.value,readonly:"",disabled:f.disabled,placeholder:f.placeholder,required:f.required,"aria-describedby":f.ariaDescribedby,"aria-haspopup":"dialog","aria-expanded":p.value,class:e.normalizeClass(["w-full cursor-pointer rounded-md border px-3 py-2 pr-10 text-sm ui-surface ui-text placeholder:text-(--ui-text-muted) transition-colors","focus:border-(--ui-primary) focus:outline-none focus:ring-2 focus:ring-(--ui-ring)","disabled:cursor-not-allowed disabled:bg-(--ui-surface-muted) disabled:text-(--ui-text-muted)",Y.value?"border-(--ui-danger) focus:border-(--ui-danger) focus:ring-(--ui-danger)":"ui-border"]),onClick:Ye,onKeydown:Pe},null,42,Ke),a[4]||(a[4]=e.createElementVNode("div",{class:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2"},[e.createElementVNode("svg",{class:"h-4 w-4 ui-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})])],-1)),f.clearable&&oe.value&&!f.disabled?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"absolute right-9 top-1/2 -translate-y-1/2 rounded p-1 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring)","aria-label":"Clear date",onClick:e.withModifiers(Re,["stop"])},[...a[3]||(a[3]=[e.createElementVNode("svg",{class:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])):e.createCommentVNode("",!0)]),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.createVNode(e.Transition,{"enter-active-class":"transition duration-100 ease-out","enter-from-class":"scale-95 opacity-0","enter-to-class":"scale-100 opacity-100","leave-active-class":"transition duration-75 ease-in","leave-from-class":"scale-100 opacity-100","leave-to-class":"scale-95 opacity-0"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"calendarRef",ref:T,style:e.normalizeStyle(X.value),role:"dialog","aria-label":"Choose date","aria-modal":"false",class:e.normalizeClass(["fixed z-10000 max-w-[calc(100vw-2rem)] rounded-lg border p-3 shadow-xl ui-surface ui-border-strong",f.enableTime?"w-[28rem]":"w-80"]),onClick:a[2]||(a[2]=e.withModifiers(()=>{},["stop"]))},[e.createElementVNode("div",{class:e.normalizeClass(f.enableTime?"grid grid-cols-1 gap-3 sm:grid-cols-[1fr_7.75rem]":"block")},[e.createElementVNode("div",Oe,[e.createElementVNode("div",Ue,[e.createElementVNode("button",{type:"button",class:"rounded p-1.5 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",disabled:!K.value,"aria-disabled":!K.value,"aria-label":Ee.value,onClick:Ce},[...a[5]||(a[5]=[e.createElementVNode("svg",{class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 18l-6-6 6-6"})],-1)])],8,qe),e.createElementVNode("button",{type:"button",class:"min-w-0 flex-1 rounded px-2 py-1 text-sm font-semibold ui-text transition-colors hover:bg-(--ui-surface-muted) focus-visible:ring-2 focus-visible:ring-(--ui-ring)","aria-label":Ne.value,onClick:Fe},e.toDisplayString($.value),9,je),e.createElementVNode("button",{type:"button",class:"rounded p-1.5 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",disabled:!O.value,"aria-disabled":!O.value,"aria-label":Se.value,onClick:$e},[...a[6]||(a[6]=[e.createElementVNode("svg",{class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 18l6-6-6-6"})],-1)])],8,We)]),s.value==="day"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("div",Ge,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(we,r=>e.createElementVNode("div",{key:r,class:"py-1 text-center text-xs font-medium ui-text-muted"},e.toDisplayString(r),1)),64))]),e.createElementVNode("div",{class:"grid grid-cols-7 gap-1",role:"grid","aria-label":`${H.value} ${n.value}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(re.value,(r,l)=>(e.openBlock(),e.createElementBlock("div",{key:`prev-${l}`,class:"py-1.5 text-center text-xs ui-text-soft","aria-hidden":"true"},e.toDisplayString(r),1))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(te.value,r=>(e.openBlock(),e.createElementBlock("button",{key:r,type:"button",role:"gridcell","data-picker-option":"","data-day":r,"data-focus-preferred":r===C.value,disabled:q(r),"aria-disabled":q(r),"aria-selected":G(r),"aria-label":`${H.value} ${r}, ${n.value}`,class:e.normalizeClass(["h-8 w-full min-w-0 rounded text-xs font-medium transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",Te(r)&&!G(r)?"ui-primary-soft ring-1 ring-(--ui-primary)":"",G(r)?"ui-primary-bg":"ui-text hover:bg-(--ui-surface-muted)",q(r)?"cursor-not-allowed text-(--ui-text-soft) opacity-45 line-through hover:bg-transparent":"cursor-pointer"]),onClick:l=>ce(r),onKeydown:l=>Le(l,r)},e.toDisplayString(r),43,Je))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(De.value,(r,l)=>(e.openBlock(),e.createElementBlock("div",{key:`next-${l}`,class:"py-1.5 text-center text-xs ui-text-soft","aria-hidden":"true"},e.toDisplayString(r),1))),128))],8,Ze)],64)):s.value==="month"?(e.openBlock(),e.createElementBlock("div",{key:1,class:"grid grid-cols-3 gap-2",role:"grid","aria-label":`Select a month in ${n.value}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ee),(r,l)=>(e.openBlock(),e.createElementBlock("button",{key:r,type:"button",role:"gridcell","data-picker-option":"","data-focus-preferred":l===c.value,disabled:_(l),"aria-disabled":_(l),"aria-selected":u.value?.getFullYear()===n.value&&u.value?.getMonth()===l,"aria-label":`Select ${r} ${n.value}`,class:e.normalizeClass(["min-h-11 rounded px-2 py-2 text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",u.value?.getFullYear()===n.value&&u.value?.getMonth()===l?"ui-primary-bg":"ui-text hover:bg-(--ui-surface-muted)",_(l)?"cursor-not-allowed text-(--ui-text-soft) opacity-45 hover:bg-transparent":""]),onClick:o=>Ie(l),onKeydown:a[0]||(a[0]=o=>me(o,3))},e.toDisplayString(r.slice(0,3)),43,Xe))),128))],8,Qe)):(e.openBlock(),e.createElementBlock("div",{key:2,class:"grid grid-cols-3 gap-2 sm:grid-cols-4",role:"grid","aria-label":`Select a year from ${$.value}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(le.value,r=>(e.openBlock(),e.createElementBlock("button",{key:r,type:"button",role:"gridcell","data-picker-option":"","data-focus-preferred":r===n.value,disabled:R(r),"aria-disabled":R(r),"aria-selected":u.value?.getFullYear()===r,"aria-label":`Select year ${r}`,class:e.normalizeClass(["min-h-11 rounded px-1 py-2 text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",u.value?.getFullYear()===r?"ui-primary-bg":"ui-text hover:bg-(--ui-surface-muted)",R(r)?"cursor-not-allowed text-(--ui-text-soft) opacity-45 hover:bg-transparent":""]),onClick:l=>Ae(r),onKeydown:a[1]||(a[1]=l=>me(l,3))},e.toDisplayString(r),43,tt))),128))],8,et)),f.showToday&&s.value==="day"?(e.openBlock(),e.createElementBlock("div",at,[e.createElementVNode("button",{type:"button",class:"w-full rounded px-3 py-1.5 text-xs font-medium ui-primary transition-colors hover:bg-(--ui-primary-soft) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",disabled:N(e.unref(v)),"aria-disabled":N(e.unref(v)),onClick:_e}," Today ",8,rt)])):e.createCommentVNode("",!0)]),f.enableTime?(e.openBlock(),e.createElementBlock("div",lt,[a[7]||(a[7]=e.createElementVNode("div",{class:"mb-2 text-xs font-semibold ui-text"}," Time ",-1)),e.createElementVNode("div",nt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Be.value,r=>(e.openBlock(),e.createElementBlock("button",{key:r,type:"button",class:e.normalizeClass(["w-full rounded px-2 py-1.5 text-left text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",r===D.value?"ui-primary-bg":"ui-text hover:bg-(--ui-surface-muted)"]),"aria-selected":r===D.value,onClick:l=>D.value=r},e.toDisplayString(r),11,ot))),128))])])):e.createCommentVNode("",!0)],2)],6)):e.createCommentVNode("",!0)]),_:1})]))]))}});exports._sfc_main=it;
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { defineComponent as et, ref as h, computed as g, watch as se, onMounted as tt, onBeforeUnmount as at, createElementBlock as f, openBlock as d, createElementVNode as o, createBlock as rt, createCommentVNode as Z, normalizeClass as V, withModifiers as Ae, Teleport as lt, createVNode as nt, Transition as it, withCtx as ut, normalizeStyle as ot, toDisplayString as F, Fragment as C, renderList as A, unref as de, nextTick as R } from "vue";
|
|
2
|
+
const st = { class: "relative w-full rounded-md bg-(--ui-surface)" }, dt = { class: "relative" }, ct = ["id", "value", "disabled", "placeholder", "required", "aria-describedby", "aria-expanded"], ft = { class: "min-w-0" }, vt = { class: "mb-3 flex items-center justify-between gap-2" }, gt = ["disabled", "aria-disabled", "aria-label"], mt = ["aria-label"], bt = ["disabled", "aria-disabled", "aria-label"], pt = {
|
|
3
|
+
class: "mb-1 grid grid-cols-7 gap-1",
|
|
4
|
+
"aria-hidden": "true"
|
|
5
|
+
}, yt = ["aria-label"], ht = ["data-day", "data-focus-preferred", "disabled", "aria-disabled", "aria-selected", "aria-label", "onClick", "onKeydown"], xt = ["aria-label"], wt = ["data-focus-preferred", "disabled", "aria-disabled", "aria-selected", "aria-label", "onClick"], Dt = ["aria-label"], kt = ["data-focus-preferred", "disabled", "aria-disabled", "aria-selected", "aria-label", "onClick"], Mt = {
|
|
6
|
+
key: 3,
|
|
7
|
+
class: "mt-3 border-t pt-2 ui-border"
|
|
8
|
+
}, St = ["disabled", "aria-disabled"], Nt = {
|
|
9
|
+
key: 0,
|
|
10
|
+
class: "border-t pt-3 ui-border sm:border-l sm:border-t-0 sm:pl-3 sm:pt-0"
|
|
11
|
+
}, Yt = { class: "max-h-64 space-y-1 overflow-y-auto pr-1" }, Tt = ["aria-selected", "onClick"], M = 12, Ft = /* @__PURE__ */ et({
|
|
12
|
+
__name: "DatePicker",
|
|
13
|
+
props: {
|
|
14
|
+
id: String,
|
|
15
|
+
modelValue: { type: [String, Date], default: "" },
|
|
16
|
+
disabled: { type: Boolean, default: !1 },
|
|
17
|
+
required: { type: Boolean, default: !1 },
|
|
18
|
+
min: [String, Date],
|
|
19
|
+
max: [String, Date],
|
|
20
|
+
minDate: [String, Date],
|
|
21
|
+
maxDate: [String, Date],
|
|
22
|
+
yearRange: Array,
|
|
23
|
+
initialView: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: "day",
|
|
26
|
+
validator: (m) => ["day", "month", "year"].includes(m)
|
|
27
|
+
},
|
|
28
|
+
placeholder: { type: String, default: "Select date" },
|
|
29
|
+
format: { type: String, default: "DD/MM/YYYY" },
|
|
30
|
+
clearable: { type: Boolean, default: !0 },
|
|
31
|
+
showToday: { type: Boolean, default: !0 },
|
|
32
|
+
calendarPosition: { type: String, default: "left-0 bottom-full" },
|
|
33
|
+
ariaDescribedby: String,
|
|
34
|
+
customValidation: { type: Function, default: null },
|
|
35
|
+
disabledDates: { type: [Array, Function], default: null },
|
|
36
|
+
enableTime: { type: Boolean, default: !1 },
|
|
37
|
+
minuteInterval: { type: Number, default: 1 }
|
|
38
|
+
},
|
|
39
|
+
emits: ["update:modelValue", "validation-error"],
|
|
40
|
+
setup(m, { emit: Ie }) {
|
|
41
|
+
const i = m, I = Ie, x = h(!1), s = h("day"), P = h(null), J = h(null), ce = h({}), b = O(/* @__PURE__ */ new Date()), v = h(b.getMonth()), l = h(b.getFullYear()), z = h(b.getDate()), w = h(Math.floor(b.getFullYear() / M) * M), u = h(null), H = h(!1), Y = h("00:00"), Ee = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], fe = Array.from(
|
|
42
|
+
{ length: 12 },
|
|
43
|
+
(e, t) => new Date(2e3, t, 1).toLocaleString("default", { month: "long" })
|
|
44
|
+
), S = g(() => U(i.minDate ?? i.min)), N = g(() => U(i.maxDate ?? i.max)), p = g(() => {
|
|
45
|
+
if (!i.yearRange || i.yearRange.length !== 2) return null;
|
|
46
|
+
const e = Math.trunc(Number(i.yearRange[0])), t = Math.trunc(Number(i.yearRange[1]));
|
|
47
|
+
return !Number.isFinite(e) || !Number.isFinite(t) ? null : e <= t ? [e, t] : [t, e];
|
|
48
|
+
}), E = g(() => Math.max(
|
|
49
|
+
p.value?.[0] ?? Number.NEGATIVE_INFINITY,
|
|
50
|
+
S.value?.getFullYear() ?? Number.NEGATIVE_INFINITY
|
|
51
|
+
)), L = g(() => Math.min(
|
|
52
|
+
p.value?.[1] ?? Number.POSITIVE_INFINITY,
|
|
53
|
+
N.value?.getFullYear() ?? Number.POSITIVE_INFINITY
|
|
54
|
+
)), Q = g(() => fe[v.value]), ve = g(() => _(l.value, v.value)), ge = g(() => c(l.value, v.value, 1).getDay()), me = g(() => {
|
|
55
|
+
const e = _(l.value, v.value - 1);
|
|
56
|
+
return Array.from(
|
|
57
|
+
{ length: ge.value },
|
|
58
|
+
(t, a) => e - ge.value + a + 1
|
|
59
|
+
);
|
|
60
|
+
}), _e = g(() => {
|
|
61
|
+
const e = me.value.length + ve.value, t = e % 7 === 0 ? 0 : 7 - e % 7;
|
|
62
|
+
return Array.from({ length: t }, (a, r) => r + 1);
|
|
63
|
+
}), be = g(
|
|
64
|
+
() => Array.from({ length: M }, (e, t) => w.value + t).filter((e) => e >= E.value && e <= L.value)
|
|
65
|
+
), pe = g(() => w.value + M - 1), K = g(() => {
|
|
66
|
+
if (s.value === "day") return `${Q.value} ${l.value}`;
|
|
67
|
+
if (s.value === "month") return String(l.value);
|
|
68
|
+
const e = be.value;
|
|
69
|
+
return e.length ? `${e[0]}–${e[e.length - 1]}` : `${w.value}–${pe.value}`;
|
|
70
|
+
}), Be = g(() => s.value === "day" ? `Select the month. Currently ${K.value}` : s.value === "month" ? `Select the year. Currently ${l.value}` : `Return to day selection. Showing years ${K.value}`), Re = g(() => s.value === "day" ? "Previous month" : s.value === "month" ? "Previous year" : "Previous year range"), Pe = g(() => s.value === "day" ? "Next month" : s.value === "month" ? "Next year" : "Next year range"), X = g(() => s.value === "day" ? re(l.value, v.value - 1) : s.value === "month" ? l.value - 1 >= E.value : w.value > E.value), ee = g(() => s.value === "day" ? re(l.value, v.value + 1) : s.value === "month" ? l.value + 1 <= L.value : pe.value < L.value), ye = g(() => u.value ? i.enableTime ? Le(u.value) : he(u.value) : ""), He = g(() => {
|
|
71
|
+
const e = Math.min(60, Math.max(1, Number(i.minuteInterval) || 1)), t = [];
|
|
72
|
+
for (let a = 0; a < 24; a++)
|
|
73
|
+
for (let r = 0; r < 60; r += e)
|
|
74
|
+
t.push(`${String(a).padStart(2, "0")}:${String(r).padStart(2, "0")}`);
|
|
75
|
+
return t;
|
|
76
|
+
});
|
|
77
|
+
function c(e, t, a, r = 0, n = 0) {
|
|
78
|
+
const D = /* @__PURE__ */ new Date(0);
|
|
79
|
+
return D.setFullYear(e, t, a), D.setHours(r, n, 0, 0), D;
|
|
80
|
+
}
|
|
81
|
+
function O(e) {
|
|
82
|
+
return c(e.getFullYear(), e.getMonth(), e.getDate());
|
|
83
|
+
}
|
|
84
|
+
function _(e, t) {
|
|
85
|
+
return c(e, t + 1, 0).getDate();
|
|
86
|
+
}
|
|
87
|
+
function U(e) {
|
|
88
|
+
if (!e) return null;
|
|
89
|
+
if (e instanceof Date)
|
|
90
|
+
return Number.isNaN(e.getTime()) ? null : c(e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes());
|
|
91
|
+
const t = e.match(/^(\d{4,})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?/);
|
|
92
|
+
if (t) {
|
|
93
|
+
const [, r, n, D, k = "0", B = "0"] = t, Fe = Number(r), Ce = Number(n) - 1, Ve = Number(D), G = c(Fe, Ce, Ve, Number(k), Number(B));
|
|
94
|
+
return G.getFullYear() === Fe && G.getMonth() === Ce && G.getDate() === Ve ? G : null;
|
|
95
|
+
}
|
|
96
|
+
const a = new Date(e);
|
|
97
|
+
return Number.isNaN(a.getTime()) ? null : a;
|
|
98
|
+
}
|
|
99
|
+
function y(e) {
|
|
100
|
+
return c(e.getFullYear(), e.getMonth(), e.getDate()).getTime();
|
|
101
|
+
}
|
|
102
|
+
function he(e) {
|
|
103
|
+
const t = String(e.getMonth() + 1).padStart(2, "0"), a = String(e.getDate()).padStart(2, "0");
|
|
104
|
+
return i.format.replace("MM", t).replace("DD", a).replace("YYYY", String(e.getFullYear()));
|
|
105
|
+
}
|
|
106
|
+
function Le(e) {
|
|
107
|
+
const t = String(e.getHours()).padStart(2, "0"), a = String(e.getMinutes()).padStart(2, "0");
|
|
108
|
+
return `${he(e)} ${t}:${a}`;
|
|
109
|
+
}
|
|
110
|
+
function ze(e) {
|
|
111
|
+
const t = String(e.getFullYear()).padStart(4, "0"), a = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
|
|
112
|
+
return `${t}-${a}-${r}`;
|
|
113
|
+
}
|
|
114
|
+
function te(e) {
|
|
115
|
+
const t = y(e);
|
|
116
|
+
return !(S.value && t < y(S.value) || N.value && t > y(N.value) || p.value && (e.getFullYear() < p.value[0] || e.getFullYear() > p.value[1]));
|
|
117
|
+
}
|
|
118
|
+
function T(e) {
|
|
119
|
+
return !te(e) || i.disabledDates && (typeof i.disabledDates == "function" && i.disabledDates(new Date(e)) || Array.isArray(i.disabledDates) && i.disabledDates.some((t) => {
|
|
120
|
+
const a = U(t);
|
|
121
|
+
return a ? y(a) === y(e) : !1;
|
|
122
|
+
})) ? !0 : !!i.customValidation?.(new Date(e));
|
|
123
|
+
}
|
|
124
|
+
function ae(e) {
|
|
125
|
+
return T(c(l.value, v.value, e));
|
|
126
|
+
}
|
|
127
|
+
function j(e) {
|
|
128
|
+
for (let t = 1; t <= _(l.value, e); t++)
|
|
129
|
+
if (!T(c(l.value, e, t))) return !1;
|
|
130
|
+
return !0;
|
|
131
|
+
}
|
|
132
|
+
function q(e) {
|
|
133
|
+
if (e < E.value || e > L.value) return !0;
|
|
134
|
+
for (let t = 0; t < 12; t++)
|
|
135
|
+
for (let a = 1; a <= _(e, t); a++)
|
|
136
|
+
if (!T(c(e, t, a))) return !1;
|
|
137
|
+
return !0;
|
|
138
|
+
}
|
|
139
|
+
function re(e, t) {
|
|
140
|
+
const a = c(e, t, 1), r = c(a.getFullYear(), a.getMonth() + 1, 0);
|
|
141
|
+
return !(a.getFullYear() < E.value || a.getFullYear() > L.value || S.value && y(r) < y(S.value) || N.value && y(a) > y(N.value));
|
|
142
|
+
}
|
|
143
|
+
function le(e) {
|
|
144
|
+
const t = p.value?.[0];
|
|
145
|
+
return t !== void 0 ? t + Math.floor((e - t) / M) * M : Math.floor(e / M) * M;
|
|
146
|
+
}
|
|
147
|
+
function xe(e) {
|
|
148
|
+
let t = O(e);
|
|
149
|
+
return p.value && t.getFullYear() < p.value[0] && (t = c(p.value[0], 0, 1)), p.value && t.getFullYear() > p.value[1] && (t = c(p.value[1], 11, 31)), S.value && y(t) < y(S.value) && (t = O(S.value)), N.value && y(t) > y(N.value) && (t = O(N.value)), t;
|
|
150
|
+
}
|
|
151
|
+
function Ke(e) {
|
|
152
|
+
return b.getDate() === e && b.getMonth() === v.value && b.getFullYear() === l.value;
|
|
153
|
+
}
|
|
154
|
+
function ne(e) {
|
|
155
|
+
return !!(u.value && u.value.getDate() === e && u.value.getMonth() === v.value && u.value.getFullYear() === l.value);
|
|
156
|
+
}
|
|
157
|
+
function we(e) {
|
|
158
|
+
if (!e)
|
|
159
|
+
return H.value = !1, I("validation-error", null), !0;
|
|
160
|
+
const t = i.customValidation?.(new Date(e)) || null;
|
|
161
|
+
return H.value = !!t, I("validation-error", t), !t;
|
|
162
|
+
}
|
|
163
|
+
async function ie() {
|
|
164
|
+
await R();
|
|
165
|
+
const e = J.value || (i.id ? document.getElementById(i.id) : null);
|
|
166
|
+
if (!e || !P.value) return;
|
|
167
|
+
const t = e.getBoundingClientRect(), a = P.value.offsetHeight || 360, r = P.value.offsetWidth || (i.enableTime ? 448 : 320), n = window.innerHeight - t.bottom, D = n >= a || n > t.top ? t.bottom + 8 : Math.max(8, t.top - a - 8), k = Math.min(Math.max(16, t.left), Math.max(16, window.innerWidth - r - 16));
|
|
168
|
+
ce.value = { top: `${D}px`, left: `${k}px` };
|
|
169
|
+
}
|
|
170
|
+
function $(e) {
|
|
171
|
+
z.value = e.getDate(), v.value = e.getMonth(), l.value = e.getFullYear(), w.value = le(e.getFullYear());
|
|
172
|
+
}
|
|
173
|
+
async function De() {
|
|
174
|
+
i.disabled || x.value || ((!u.value || !te(u.value)) && $(xe(b)), s.value = i.initialView, w.value = le(l.value), x.value = !0, await ie(), await Se());
|
|
175
|
+
}
|
|
176
|
+
function Oe() {
|
|
177
|
+
x.value ? W() : De();
|
|
178
|
+
}
|
|
179
|
+
function W(e = !1) {
|
|
180
|
+
x.value = !1, e && R(() => J.value?.focus());
|
|
181
|
+
}
|
|
182
|
+
async function ue(e) {
|
|
183
|
+
s.value = e, e === "year" && (w.value = le(l.value)), await R(), await ie(), await Se();
|
|
184
|
+
}
|
|
185
|
+
function Ue() {
|
|
186
|
+
ue({ day: "month", month: "year", year: "day" }[s.value]);
|
|
187
|
+
}
|
|
188
|
+
function je() {
|
|
189
|
+
X.value && (s.value === "day" ? $(c(l.value, v.value - 1, 1)) : s.value === "month" ? l.value-- : w.value = Math.max(w.value - M, E.value));
|
|
190
|
+
}
|
|
191
|
+
function qe() {
|
|
192
|
+
ee.value && (s.value === "day" ? $(c(l.value, v.value + 1, 1)) : s.value === "month" ? l.value++ : w.value += M);
|
|
193
|
+
}
|
|
194
|
+
function We(e) {
|
|
195
|
+
q(e) || (l.value = e, ue("month"));
|
|
196
|
+
}
|
|
197
|
+
function Ge(e) {
|
|
198
|
+
j(e) || (v.value = e, z.value = Math.min(z.value, _(l.value, e)), ue("day"));
|
|
199
|
+
}
|
|
200
|
+
function ke(e) {
|
|
201
|
+
const t = c(l.value, v.value, e);
|
|
202
|
+
if (T(t) || !we(t)) return;
|
|
203
|
+
const [a = "0", r = "0"] = Y.value.split(":");
|
|
204
|
+
t.setHours(Number(a), Number(r), 0, 0), u.value = t, Me(t), i.enableTime || window.setTimeout(() => W(), 150);
|
|
205
|
+
}
|
|
206
|
+
function Me(e) {
|
|
207
|
+
const t = ze(e);
|
|
208
|
+
i.enableTime ? I("update:modelValue", `${t}T${Y.value}`) : I("update:modelValue", t);
|
|
209
|
+
}
|
|
210
|
+
function Ze() {
|
|
211
|
+
T(b) || ($(b), ke(b.getDate()));
|
|
212
|
+
}
|
|
213
|
+
function Je() {
|
|
214
|
+
u.value = null, Y.value = "00:00", H.value = !1, I("update:modelValue", ""), I("validation-error", null);
|
|
215
|
+
}
|
|
216
|
+
function oe() {
|
|
217
|
+
return Array.from(P.value?.querySelectorAll("[data-picker-option]:not(:disabled)") || []);
|
|
218
|
+
}
|
|
219
|
+
async function Se() {
|
|
220
|
+
await R();
|
|
221
|
+
const e = oe(), t = e.find((r) => r.getAttribute("aria-selected") === "true"), a = e.find((r) => r.dataset.focusPreferred === "true");
|
|
222
|
+
(t || a || e[0])?.focus();
|
|
223
|
+
}
|
|
224
|
+
function Ne(e, t) {
|
|
225
|
+
const a = oe(), r = a.indexOf(e.currentTarget);
|
|
226
|
+
if (r < 0) return;
|
|
227
|
+
let n = r;
|
|
228
|
+
if (e.key === "ArrowRight") n = Math.min(a.length - 1, r + 1);
|
|
229
|
+
else if (e.key === "ArrowLeft") n = Math.max(0, r - 1);
|
|
230
|
+
else if (e.key === "ArrowDown") n = Math.min(a.length - 1, r + t);
|
|
231
|
+
else if (e.key === "ArrowUp") n = Math.max(0, r - t);
|
|
232
|
+
else if (e.key === "Home") n = r - r % t;
|
|
233
|
+
else if (e.key === "End") n = Math.min(a.length - 1, r + t - 1 - r % t);
|
|
234
|
+
else return;
|
|
235
|
+
e.preventDefault(), a[n]?.focus();
|
|
236
|
+
}
|
|
237
|
+
function Qe(e, t) {
|
|
238
|
+
if (e.key === "PageUp" || e.key === "PageDown") {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
const k = e.key === "PageUp" ? -1 : 1, B = c(l.value, v.value + k, Math.min(t, _(l.value, v.value + k)));
|
|
241
|
+
re(B.getFullYear(), B.getMonth()) && ($(B), R(() => Ye(B.getDate(), k)));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (!["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) return;
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
let r = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: 7, ArrowUp: -7 }[e.key];
|
|
247
|
+
e.key === "Home" && (r = -c(l.value, v.value, t).getDay()), e.key === "End" && (r = 6 - c(l.value, v.value, t).getDay());
|
|
248
|
+
let n = c(l.value, v.value, t + r);
|
|
249
|
+
const D = r < 0 ? -1 : 1;
|
|
250
|
+
for (let k = 0; k < 3660; k++) {
|
|
251
|
+
if (!te(n)) return;
|
|
252
|
+
if (!T(n)) {
|
|
253
|
+
$(n), R(() => Ye(n.getDate(), D));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
n = c(n.getFullYear(), n.getMonth(), n.getDate() + D);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function Ye(e, t) {
|
|
260
|
+
const a = oe();
|
|
261
|
+
(a.find((n) => Number(n.dataset.day) === e) || (t < 0 ? a.at(-1) : a[0]))?.focus();
|
|
262
|
+
}
|
|
263
|
+
function Xe(e) {
|
|
264
|
+
["Enter", " ", "ArrowDown"].includes(e.key) ? (e.preventDefault(), De()) : e.key === "Escape" && x.value && (e.preventDefault(), W(!0));
|
|
265
|
+
}
|
|
266
|
+
function Te(e) {
|
|
267
|
+
e.key === "Escape" && x.value && (e.preventDefault(), W(!0));
|
|
268
|
+
}
|
|
269
|
+
function $e() {
|
|
270
|
+
x.value && ie();
|
|
271
|
+
}
|
|
272
|
+
return se(() => i.modelValue, (e) => {
|
|
273
|
+
const t = U(e);
|
|
274
|
+
if (!t) {
|
|
275
|
+
u.value = null, H.value = !1;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
u.value = t, Y.value = `${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}`, $(t), we(t);
|
|
279
|
+
}, { immediate: !0 }), se([p, S, N], () => {
|
|
280
|
+
!u.value && !x.value && $(xe(b));
|
|
281
|
+
}), se(Y, (e) => {
|
|
282
|
+
if (!i.enableTime || !u.value) return;
|
|
283
|
+
const [t = "0", a = "0"] = e.split(":");
|
|
284
|
+
u.value.setHours(Number(t), Number(a), 0, 0), Me(u.value);
|
|
285
|
+
}), tt(() => {
|
|
286
|
+
document.addEventListener("keydown", Te), window.addEventListener("resize", $e);
|
|
287
|
+
}), at(() => {
|
|
288
|
+
document.removeEventListener("keydown", Te), window.removeEventListener("resize", $e);
|
|
289
|
+
}), (e, t) => (d(), f("div", st, [
|
|
290
|
+
o("div", dt, [
|
|
291
|
+
o("input", {
|
|
292
|
+
id: m.id,
|
|
293
|
+
ref_key: "inputRef",
|
|
294
|
+
ref: J,
|
|
295
|
+
type: "text",
|
|
296
|
+
value: ye.value,
|
|
297
|
+
readonly: "",
|
|
298
|
+
disabled: m.disabled,
|
|
299
|
+
placeholder: m.placeholder,
|
|
300
|
+
required: m.required,
|
|
301
|
+
"aria-describedby": m.ariaDescribedby,
|
|
302
|
+
"aria-haspopup": "dialog",
|
|
303
|
+
"aria-expanded": x.value,
|
|
304
|
+
class: V([
|
|
305
|
+
"w-full cursor-pointer rounded-md border px-3 py-2 pr-10 text-sm ui-surface ui-text placeholder:text-(--ui-text-muted) transition-colors",
|
|
306
|
+
"focus:border-(--ui-primary) focus:outline-none focus:ring-2 focus:ring-(--ui-ring)",
|
|
307
|
+
"disabled:cursor-not-allowed disabled:bg-(--ui-surface-muted) disabled:text-(--ui-text-muted)",
|
|
308
|
+
H.value ? "border-(--ui-danger) focus:border-(--ui-danger) focus:ring-(--ui-danger)" : "ui-border"
|
|
309
|
+
]),
|
|
310
|
+
onClick: Oe,
|
|
311
|
+
onKeydown: Xe
|
|
312
|
+
}, null, 42, ct),
|
|
313
|
+
t[4] || (t[4] = o("div", { class: "pointer-events-none absolute right-3 top-1/2 -translate-y-1/2" }, [
|
|
314
|
+
o("svg", {
|
|
315
|
+
class: "h-4 w-4 ui-text-muted",
|
|
316
|
+
fill: "none",
|
|
317
|
+
stroke: "currentColor",
|
|
318
|
+
viewBox: "0 0 24 24",
|
|
319
|
+
"aria-hidden": "true"
|
|
320
|
+
}, [
|
|
321
|
+
o("path", {
|
|
322
|
+
"stroke-linecap": "round",
|
|
323
|
+
"stroke-linejoin": "round",
|
|
324
|
+
"stroke-width": "2",
|
|
325
|
+
d: "M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
|
326
|
+
})
|
|
327
|
+
])
|
|
328
|
+
], -1)),
|
|
329
|
+
m.clearable && ye.value && !m.disabled ? (d(), f("button", {
|
|
330
|
+
key: 0,
|
|
331
|
+
type: "button",
|
|
332
|
+
class: "absolute right-9 top-1/2 -translate-y-1/2 rounded p-1 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring)",
|
|
333
|
+
"aria-label": "Clear date",
|
|
334
|
+
onClick: Ae(Je, ["stop"])
|
|
335
|
+
}, [...t[3] || (t[3] = [
|
|
336
|
+
o("svg", {
|
|
337
|
+
class: "h-3.5 w-3.5",
|
|
338
|
+
fill: "none",
|
|
339
|
+
stroke: "currentColor",
|
|
340
|
+
viewBox: "0 0 24 24",
|
|
341
|
+
"aria-hidden": "true"
|
|
342
|
+
}, [
|
|
343
|
+
o("path", {
|
|
344
|
+
"stroke-linecap": "round",
|
|
345
|
+
"stroke-linejoin": "round",
|
|
346
|
+
"stroke-width": "2",
|
|
347
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
348
|
+
})
|
|
349
|
+
], -1)
|
|
350
|
+
])])) : Z("", !0)
|
|
351
|
+
]),
|
|
352
|
+
(d(), rt(lt, { to: "body" }, [
|
|
353
|
+
nt(it, {
|
|
354
|
+
"enter-active-class": "transition duration-100 ease-out",
|
|
355
|
+
"enter-from-class": "scale-95 opacity-0",
|
|
356
|
+
"enter-to-class": "scale-100 opacity-100",
|
|
357
|
+
"leave-active-class": "transition duration-75 ease-in",
|
|
358
|
+
"leave-from-class": "scale-100 opacity-100",
|
|
359
|
+
"leave-to-class": "scale-95 opacity-0"
|
|
360
|
+
}, {
|
|
361
|
+
default: ut(() => [
|
|
362
|
+
x.value ? (d(), f("div", {
|
|
363
|
+
key: 0,
|
|
364
|
+
ref_key: "calendarRef",
|
|
365
|
+
ref: P,
|
|
366
|
+
style: ot(ce.value),
|
|
367
|
+
role: "dialog",
|
|
368
|
+
"aria-label": "Choose date",
|
|
369
|
+
"aria-modal": "false",
|
|
370
|
+
class: V(["fixed z-10000 max-w-[calc(100vw-2rem)] rounded-lg border p-3 shadow-xl ui-surface ui-border-strong", m.enableTime ? "w-[28rem]" : "w-80"]),
|
|
371
|
+
onClick: t[2] || (t[2] = Ae(() => {
|
|
372
|
+
}, ["stop"]))
|
|
373
|
+
}, [
|
|
374
|
+
o("div", {
|
|
375
|
+
class: V(m.enableTime ? "grid grid-cols-1 gap-3 sm:grid-cols-[1fr_7.75rem]" : "block")
|
|
376
|
+
}, [
|
|
377
|
+
o("div", ft, [
|
|
378
|
+
o("div", vt, [
|
|
379
|
+
o("button", {
|
|
380
|
+
type: "button",
|
|
381
|
+
class: "rounded p-1.5 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",
|
|
382
|
+
disabled: !X.value,
|
|
383
|
+
"aria-disabled": !X.value,
|
|
384
|
+
"aria-label": Re.value,
|
|
385
|
+
onClick: je
|
|
386
|
+
}, [...t[5] || (t[5] = [
|
|
387
|
+
o("svg", {
|
|
388
|
+
class: "h-4 w-4",
|
|
389
|
+
fill: "none",
|
|
390
|
+
stroke: "currentColor",
|
|
391
|
+
viewBox: "0 0 24 24",
|
|
392
|
+
"aria-hidden": "true"
|
|
393
|
+
}, [
|
|
394
|
+
o("path", {
|
|
395
|
+
"stroke-linecap": "round",
|
|
396
|
+
"stroke-linejoin": "round",
|
|
397
|
+
"stroke-width": "2",
|
|
398
|
+
d: "M15 18l-6-6 6-6"
|
|
399
|
+
})
|
|
400
|
+
], -1)
|
|
401
|
+
])], 8, gt),
|
|
402
|
+
o("button", {
|
|
403
|
+
type: "button",
|
|
404
|
+
class: "min-w-0 flex-1 rounded px-2 py-1 text-sm font-semibold ui-text transition-colors hover:bg-(--ui-surface-muted) focus-visible:ring-2 focus-visible:ring-(--ui-ring)",
|
|
405
|
+
"aria-label": Be.value,
|
|
406
|
+
onClick: Ue
|
|
407
|
+
}, F(K.value), 9, mt),
|
|
408
|
+
o("button", {
|
|
409
|
+
type: "button",
|
|
410
|
+
class: "rounded p-1.5 ui-text-muted transition-colors hover:bg-(--ui-surface-muted) hover:text-(--ui-text) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",
|
|
411
|
+
disabled: !ee.value,
|
|
412
|
+
"aria-disabled": !ee.value,
|
|
413
|
+
"aria-label": Pe.value,
|
|
414
|
+
onClick: qe
|
|
415
|
+
}, [...t[6] || (t[6] = [
|
|
416
|
+
o("svg", {
|
|
417
|
+
class: "h-4 w-4",
|
|
418
|
+
fill: "none",
|
|
419
|
+
stroke: "currentColor",
|
|
420
|
+
viewBox: "0 0 24 24",
|
|
421
|
+
"aria-hidden": "true"
|
|
422
|
+
}, [
|
|
423
|
+
o("path", {
|
|
424
|
+
"stroke-linecap": "round",
|
|
425
|
+
"stroke-linejoin": "round",
|
|
426
|
+
"stroke-width": "2",
|
|
427
|
+
d: "M9 18l6-6-6-6"
|
|
428
|
+
})
|
|
429
|
+
], -1)
|
|
430
|
+
])], 8, bt)
|
|
431
|
+
]),
|
|
432
|
+
s.value === "day" ? (d(), f(C, { key: 0 }, [
|
|
433
|
+
o("div", pt, [
|
|
434
|
+
(d(), f(C, null, A(Ee, (a) => o("div", {
|
|
435
|
+
key: a,
|
|
436
|
+
class: "py-1 text-center text-xs font-medium ui-text-muted"
|
|
437
|
+
}, F(a), 1)), 64))
|
|
438
|
+
]),
|
|
439
|
+
o("div", {
|
|
440
|
+
class: "grid grid-cols-7 gap-1",
|
|
441
|
+
role: "grid",
|
|
442
|
+
"aria-label": `${Q.value} ${l.value}`
|
|
443
|
+
}, [
|
|
444
|
+
(d(!0), f(C, null, A(me.value, (a, r) => (d(), f("div", {
|
|
445
|
+
key: `prev-${r}`,
|
|
446
|
+
class: "py-1.5 text-center text-xs ui-text-soft",
|
|
447
|
+
"aria-hidden": "true"
|
|
448
|
+
}, F(a), 1))), 128)),
|
|
449
|
+
(d(!0), f(C, null, A(ve.value, (a) => (d(), f("button", {
|
|
450
|
+
key: a,
|
|
451
|
+
type: "button",
|
|
452
|
+
role: "gridcell",
|
|
453
|
+
"data-picker-option": "",
|
|
454
|
+
"data-day": a,
|
|
455
|
+
"data-focus-preferred": a === z.value,
|
|
456
|
+
disabled: ae(a),
|
|
457
|
+
"aria-disabled": ae(a),
|
|
458
|
+
"aria-selected": ne(a),
|
|
459
|
+
"aria-label": `${Q.value} ${a}, ${l.value}`,
|
|
460
|
+
class: V([
|
|
461
|
+
"h-8 w-full min-w-0 rounded text-xs font-medium transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",
|
|
462
|
+
Ke(a) && !ne(a) ? "ui-primary-soft ring-1 ring-(--ui-primary)" : "",
|
|
463
|
+
ne(a) ? "ui-primary-bg" : "ui-text hover:bg-(--ui-surface-muted)",
|
|
464
|
+
ae(a) ? "cursor-not-allowed text-(--ui-text-soft) opacity-45 line-through hover:bg-transparent" : "cursor-pointer"
|
|
465
|
+
]),
|
|
466
|
+
onClick: (r) => ke(a),
|
|
467
|
+
onKeydown: (r) => Qe(r, a)
|
|
468
|
+
}, F(a), 43, ht))), 128)),
|
|
469
|
+
(d(!0), f(C, null, A(_e.value, (a, r) => (d(), f("div", {
|
|
470
|
+
key: `next-${r}`,
|
|
471
|
+
class: "py-1.5 text-center text-xs ui-text-soft",
|
|
472
|
+
"aria-hidden": "true"
|
|
473
|
+
}, F(a), 1))), 128))
|
|
474
|
+
], 8, yt)
|
|
475
|
+
], 64)) : s.value === "month" ? (d(), f("div", {
|
|
476
|
+
key: 1,
|
|
477
|
+
class: "grid grid-cols-3 gap-2",
|
|
478
|
+
role: "grid",
|
|
479
|
+
"aria-label": `Select a month in ${l.value}`
|
|
480
|
+
}, [
|
|
481
|
+
(d(!0), f(C, null, A(de(fe), (a, r) => (d(), f("button", {
|
|
482
|
+
key: a,
|
|
483
|
+
type: "button",
|
|
484
|
+
role: "gridcell",
|
|
485
|
+
"data-picker-option": "",
|
|
486
|
+
"data-focus-preferred": r === v.value,
|
|
487
|
+
disabled: j(r),
|
|
488
|
+
"aria-disabled": j(r),
|
|
489
|
+
"aria-selected": u.value?.getFullYear() === l.value && u.value?.getMonth() === r,
|
|
490
|
+
"aria-label": `Select ${a} ${l.value}`,
|
|
491
|
+
class: V([
|
|
492
|
+
"min-h-11 rounded px-2 py-2 text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",
|
|
493
|
+
u.value?.getFullYear() === l.value && u.value?.getMonth() === r ? "ui-primary-bg" : "ui-text hover:bg-(--ui-surface-muted)",
|
|
494
|
+
j(r) ? "cursor-not-allowed text-(--ui-text-soft) opacity-45 hover:bg-transparent" : ""
|
|
495
|
+
]),
|
|
496
|
+
onClick: (n) => Ge(r),
|
|
497
|
+
onKeydown: t[0] || (t[0] = (n) => Ne(n, 3))
|
|
498
|
+
}, F(a.slice(0, 3)), 43, wt))), 128))
|
|
499
|
+
], 8, xt)) : (d(), f("div", {
|
|
500
|
+
key: 2,
|
|
501
|
+
class: "grid grid-cols-3 gap-2 sm:grid-cols-4",
|
|
502
|
+
role: "grid",
|
|
503
|
+
"aria-label": `Select a year from ${K.value}`
|
|
504
|
+
}, [
|
|
505
|
+
(d(!0), f(C, null, A(be.value, (a) => (d(), f("button", {
|
|
506
|
+
key: a,
|
|
507
|
+
type: "button",
|
|
508
|
+
role: "gridcell",
|
|
509
|
+
"data-picker-option": "",
|
|
510
|
+
"data-focus-preferred": a === l.value,
|
|
511
|
+
disabled: q(a),
|
|
512
|
+
"aria-disabled": q(a),
|
|
513
|
+
"aria-selected": u.value?.getFullYear() === a,
|
|
514
|
+
"aria-label": `Select year ${a}`,
|
|
515
|
+
class: V([
|
|
516
|
+
"min-h-11 rounded px-1 py-2 text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)",
|
|
517
|
+
u.value?.getFullYear() === a ? "ui-primary-bg" : "ui-text hover:bg-(--ui-surface-muted)",
|
|
518
|
+
q(a) ? "cursor-not-allowed text-(--ui-text-soft) opacity-45 hover:bg-transparent" : ""
|
|
519
|
+
]),
|
|
520
|
+
onClick: (r) => We(a),
|
|
521
|
+
onKeydown: t[1] || (t[1] = (r) => Ne(r, 3))
|
|
522
|
+
}, F(a), 43, kt))), 128))
|
|
523
|
+
], 8, Dt)),
|
|
524
|
+
m.showToday && s.value === "day" ? (d(), f("div", Mt, [
|
|
525
|
+
o("button", {
|
|
526
|
+
type: "button",
|
|
527
|
+
class: "w-full rounded px-3 py-1.5 text-xs font-medium ui-primary transition-colors hover:bg-(--ui-primary-soft) focus-visible:ring-2 focus-visible:ring-(--ui-ring) disabled:cursor-not-allowed disabled:opacity-40",
|
|
528
|
+
disabled: T(de(b)),
|
|
529
|
+
"aria-disabled": T(de(b)),
|
|
530
|
+
onClick: Ze
|
|
531
|
+
}, " Today ", 8, St)
|
|
532
|
+
])) : Z("", !0)
|
|
533
|
+
]),
|
|
534
|
+
m.enableTime ? (d(), f("div", Nt, [
|
|
535
|
+
t[7] || (t[7] = o("div", { class: "mb-2 text-xs font-semibold ui-text" }, " Time ", -1)),
|
|
536
|
+
o("div", Yt, [
|
|
537
|
+
(d(!0), f(C, null, A(He.value, (a) => (d(), f("button", {
|
|
538
|
+
key: a,
|
|
539
|
+
type: "button",
|
|
540
|
+
class: V(["w-full rounded px-2 py-1.5 text-left text-sm transition-colors focus-visible:ring-2 focus-visible:ring-(--ui-ring)", a === Y.value ? "ui-primary-bg" : "ui-text hover:bg-(--ui-surface-muted)"]),
|
|
541
|
+
"aria-selected": a === Y.value,
|
|
542
|
+
onClick: (r) => Y.value = a
|
|
543
|
+
}, F(a), 11, Tt))), 128))
|
|
544
|
+
])
|
|
545
|
+
])) : Z("", !0)
|
|
546
|
+
], 2)
|
|
547
|
+
], 6)) : Z("", !0)
|
|
548
|
+
]),
|
|
549
|
+
_: 1
|
|
550
|
+
})
|
|
551
|
+
]))
|
|
552
|
+
]));
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
export {
|
|
556
|
+
Ft as _
|
|
557
|
+
};
|
|
@@ -2,7 +2,7 @@ import { defineComponent as D, useId as N, computed as s, ref as F, provide as A
|
|
|
2
2
|
import { cva as g } from "class-variance-authority";
|
|
3
3
|
import { cn as f } from "./utils/cn.js";
|
|
4
4
|
import { FORM_FIELD_CONTEXT_KEY as R } from "./lib/form-field.js";
|
|
5
|
-
import U from "./
|
|
5
|
+
import { _ as U } from "./DatePicker.vue_vue_type_script_setup_true_lang-Dx_9f8DO.js";
|
|
6
6
|
const X = ["for"], Y = {
|
|
7
7
|
key: 0,
|
|
8
8
|
class: "ui-danger ml-1",
|