@nice2dev/ui 1.1.9 → 1.1.10
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/CHANGELOG.md +74 -0
- package/README.md +17 -16
- package/dist/NiceCodeEditor-BfkH1bsZ.cjs +260 -0
- package/dist/NiceCodeEditor-CduGYggj.js +1179 -0
- package/dist/NiceColorPicker-CdUnhM-A.cjs +1 -0
- package/dist/NiceColorPicker-DpXwnDwL.js +598 -0
- package/dist/NiceConfirmDialog-B7aNRL2K.cjs +1 -0
- package/dist/NiceConfirmDialog-BdhWenrO.js +81 -0
- package/dist/NiceDataGrid-CVYEo_nv.cjs +10 -0
- package/dist/NiceDataGrid-D-rm4lu8.js +2217 -0
- package/dist/NiceDocumentViewer-BgcgLWJ3.cjs +180 -0
- package/dist/NiceDocumentViewer-sukmGhRx.js +672 -0
- package/dist/NiceForm-DVc0Xoly.js +4819 -0
- package/dist/NiceForm-qD_RKPYz.cjs +1 -0
- package/dist/NiceGantt-4UBd4uJ8.cjs +1 -0
- package/dist/NiceGantt-B_1lwEsp.js +328 -0
- package/dist/NiceHtmlEditor-Bce9Vwe1.cjs +10 -0
- package/dist/NiceHtmlEditor-CGRgcu2h.js +848 -0
- package/dist/NiceLoginForm-BTuQ0eKk.cjs +1 -0
- package/dist/NiceLoginForm-o1A-TBcp.js +736 -0
- package/dist/NiceMention-Dds9GQzk.cjs +430 -0
- package/dist/NiceMention-DlLXWddO.js +11268 -0
- package/dist/NiceModal-Dr1e3nQZ.cjs +1 -0
- package/dist/NiceModal-sihGCfDy.js +95 -0
- package/dist/NiceModuleLifecyclePanel-Du7G3-RG.js +7053 -0
- package/dist/NiceModuleLifecyclePanel-js1p7LIY.cjs +1 -0
- package/dist/NicePagination-D44waj9o.cjs +1 -0
- package/dist/NicePagination-DdxH8KMG.js +179 -0
- package/dist/NicePivotGrid-B2YHP3Z6.js +1183 -0
- package/dist/NicePivotGrid-BtVUWiud.cjs +152 -0
- package/dist/NiceSavedQueryPanel-C0A-eoYN.js +5142 -0
- package/dist/NiceSavedQueryPanel-ZrilZRtf.cjs +586 -0
- package/dist/NiceScheduler-KSzaUQxC.js +1693 -0
- package/dist/NiceScheduler-O3AwmdGG.cjs +5 -0
- package/dist/NiceSelect-BCbWtu1v.js +433 -0
- package/dist/NiceSelect-BqtiQbfD.cjs +1 -0
- package/dist/NiceWindow-BU1Ce7gS.js +1623 -0
- package/dist/NiceWindow-jjdE6vGy.cjs +1 -0
- package/dist/charts-C44vJber.cjs +768 -0
- package/dist/charts-XVlDwU0y.js +4732 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.mjs +8 -8
- package/dist/core-BxiH7vkV.cjs +1 -0
- package/dist/core-DMV6_SEE.js +795 -0
- package/dist/data-branching-oEH04O3i.js +6273 -0
- package/dist/data-branching-wmsbLNfa.cjs +1 -0
- package/dist/data-branching.cjs +1 -1
- package/dist/data-branching.mjs +1 -1
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +2 -2
- package/dist/data.mjs +3 -3
- package/dist/devops-Bt6EsfPa.cjs +17 -0
- package/dist/devops-CnZQ1rU5.js +8312 -0
- package/dist/devops.cjs +1 -1
- package/dist/devops.mjs +1 -1
- package/dist/editors.cjs +1 -1
- package/dist/editors.d.ts +2 -1
- package/dist/editors.mjs +7 -7
- package/dist/feedback.cjs +1 -1
- package/dist/feedback.mjs +3 -3
- package/dist/index.cjs +142 -142
- package/dist/index.d.ts +45 -26
- package/dist/index.mjs +7480 -7459
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.mjs +24 -24
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.mjs +69 -69
- package/dist/no-code-4GtIBr6f.js +7503 -0
- package/dist/no-code-Bdwh1vyS.cjs +332 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.mjs +1 -1
- package/dist/overlays.cjs +1 -1
- package/dist/overlays.mjs +102 -102
- package/dist/pickerCommons-31hyz1gs.js +1122 -0
- package/dist/pickerCommons-BifIkPdk.cjs +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),ce=require("@nice2dev/ui-core"),N=require("react"),O=require("./NiceColorPicker-CdUnhM-A.cjs"),je=require("./devops-Bt6EsfPa.cjs"),Se=require("./NiceForm-qD_RKPYz.cjs"),lt=require("./NiceModal-Dr1e3nQZ.cjs"),Ce=({children:e,className:n,style:c,direction:d="horizontal",size:a,disabled:u,readOnly:_,loading:x,error:k,errorPlacement:A="bottom"})=>{const b=t.jsxs("div",{className:`nice-btn-group ${d==="vertical"?"nice-btn-group--vertical":""} ${x?"nice-btn-group--loading":""} ${_?"nice-btn-group--readonly":""} ${n||""}`,style:c,role:"group","aria-busy":x||void 0,children:[N.Children.map(e,M=>{if(!N.isValidElement(M))return M;const s={};return u&&(s.disabled=!0),_&&(s.disabled=!0),x&&(s.disabled=!0),a&&(s.size=a),N.cloneElement(M,s)}),x&&t.jsx("span",{className:"nice-btn-group__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]});if(!k)return b;const D=t.jsx("div",{className:"nice-field__error",role:"alert",children:k});return A==="right"?t.jsxs("span",{className:`nice-btn-field nice-btn-field--right ${a?`nice-field--${a}`:""}`,style:{display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"8px",width:"fit-content"},children:[b,D]}):t.jsxs("span",{className:`nice-btn-field nice-btn-field--bottom ${a?`nice-field--${a}`:""}`,style:{display:"inline-flex",flexDirection:"column",alignItems:"flex-start",gap:"4px",width:"fit-content"},children:[b,D]})},F=(e,n)=>{const c=new Date(e);return c.setDate(c.getDate()+n),c},B=(e,n)=>e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate(),dt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],ut=["January","February","March","April","May","June","July","August","September","October","November","December"],mt=["sun","mon","tue","wed","thu","fri","sat"],ht=["january","february","march","april","may","june","july","august","september","october","november","december"];function ue(e){return mt.map((n,c)=>e(n,dt[c]))}function gt(e){return ht.map((n,c)=>e(n,ut[c]))}function Be(e){const n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return["janShort","febShort","marShort","aprShort","mayShort","junShort","julShort","augShort","sepShort","octShort","novShort","decShort"].map((d,a)=>e(d,n[a]))}const pt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],yt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];function ke(e){return yt.map((n,c)=>e(n,pt[c]))}function ft(e,n,c){const d=[];for(const a of e){if(!a.recurrence){d.push(a);continue}const{freq:u,interval:_=1,until:x,count:k}=a.recurrence,A=new Date(a.end).getTime()-new Date(a.start).getTime();let b=new Date(a.start),D=0;const M=x?new Date(Math.min(x.getTime(),c.getTime())):c;for(;b<=M&&(!k||D<k);){const s=new Date(b.getTime()+A);s>=n&&d.push({...a,id:`${a.id}_${D}`,start:new Date(b),end:s}),D++;const v=new Date(b);u==="daily"?v.setDate(v.getDate()+_):u==="weekly"?v.setDate(v.getDate()+7*_):u==="monthly"?v.setMonth(v.getMonth()+_):u==="yearly"&&v.setFullYear(v.getFullYear()+_),b=v}}return d}function ze(e,n){return e.filter(c=>{const d=new Date(c.start),a=new Date(c.end);return n>=new Date(d.getFullYear(),d.getMonth(),d.getDate())&&n<=new Date(a.getFullYear(),a.getMonth(),a.getDate())})}function Ve(e="r"){return`${e}_${Math.random().toString(36).slice(2,9)}`}function Ke(e={}){return{id:e.id??Ve(),title:e.title??"",description:e.description??"",servings:e.servings??2,prepMinutes:e.prepMinutes,cookMinutes:e.cookMinutes,difficulty:e.difficulty,cuisine:e.cuisine,tags:e.tags??[],ingredients:e.ingredients??[],steps:e.steps??[],photos:e.photos??[],nutrition:e.nutrition,sourceUrl:e.sourceUrl,createdAt:e.createdAt??new Date,updatedAt:e.updatedAt??new Date}}function Ue(e){const n=(e.prepMinutes??0)+(e.cookMinutes??0);return n>0?n:void 0}const me=({ev:e,renderEvent:n,onClick:c,draggable:d,dragRef:a,onHover:u,categoryColor:_})=>{const x=_||e.color||"var(--nice-color-primary, #3b82f6)",A={solid:{backgroundColor:x,color:"var(--nice-text-on-primary, #fff)"},striped:{background:`repeating-linear-gradient(45deg, ${x}, ${x} 4px, transparent 4px, transparent 8px)`,border:`1px solid ${x}`,color:"var(--nice-text-primary, #333)"},outlined:{backgroundColor:"transparent",border:`2px solid ${x}`,color:x},dashed:{backgroundColor:"transparent",border:`2px dashed ${x}`,color:x}}[e.eventStyle||"solid"];return t.jsx("div",{className:`nice-scheduler__event nice-scheduler__event--${e.eventStyle||"solid"}`,style:A,draggable:d,onDragStart:()=>{a.current={event:e}},onDragEnd:()=>{a.current=null},onClick:b=>{b.stopPropagation(),c?.(e)},onMouseEnter:b=>u(e,b.currentTarget.getBoundingClientRect()),onMouseLeave:()=>u(null),children:n?n(e):e.title})};function te(e,n){if(!(!e.category||!n))return n.find(c=>c.key===e.category)?.color}const vt=({events:e,curDate:n,firstDayOfWeek:c,onSlotClick:d,onEventClick:a,draggable:u,dragRef:_,categories:x,renderEvent:k,onHoverEvent:A,readOnly:b,t:D})=>{const M=ue(D),s=n.getFullYear(),v=n.getMonth(),S=new Date(s,v,1),o=new Date(s,v+1,0),l=(S.getDay()-c+7)%7,$=o.getDate(),g=[];for(let m=l-1;m>=0;m--)g.push({date:F(S,-m-1),isCurrentMonth:!1});for(let m=0;m<$;m++)g.push({date:new Date(s,v,m+1),isCurrentMonth:!0});let L=1;for(;g.length<42;)g.push({date:new Date(s,v+1,L++),isCurrentMonth:!1});return t.jsxs("div",{className:"nice-scheduler__month",children:[t.jsx("div",{className:"nice-scheduler__month-header",children:Array.from({length:7},(m,p)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:M[(c+p)%7]},p))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:g.map((m,p)=>{const E=ze(e,m.date),h=B(m.date,new Date),w=m.date.getDay(),I=w===0||w===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${m.isCurrentMonth?"":"nice-scheduler__month-cell--other"} ${h?"nice-scheduler__month-cell--today":""} ${I?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!b&&d?.(m.date,F(m.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:m.date.getDate()}),E.slice(0,3).map(P=>t.jsx(me,{ev:P,renderEvent:k,onClick:a,draggable:u&&!b,dragRef:_,onHover:A,categoryColor:te(P,x)},P.id)),E.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",E.length-3]})]},p)})})]})},_t=({events:e,days:n,startHour:c,endHour:d,draggable:a,dragRef:u,onEventClick:_,onSlotClick:x,onEventDrop:k,categories:A,workHours:b,showCurrentTime:D,renderEvent:M,onHoverEvent:s,readOnly:v,t:S})=>{const o=[];for(let h=c;h<d;h++)o.push(h);ue(S);const l=ke(S),$=N.useRef(null),g=new Date,L=g.getHours()*60+g.getMinutes(),m=(d-c)*60,p=(L-c*60)/m*100,E=D&&L>=c*60&&L<d*60;return N.useEffect(()=>{const h=$.current;if(!h)return;const w=new Date,I=e.filter(T=>n.some(W=>B(W,new Date(T.start)))),P=I.filter(T=>B(new Date(T.start),w));let q;P.length>0?q=Math.min(...P.map(T=>new Date(T.start).getHours())):I.length>0?q=Math.min(...I.map(T=>new Date(T.start).getHours())):q=8,q=Math.max(c,Math.min(q,d-1));const i=q-c,y=h.children[i];if(y){const T=h.closest(".nice-scheduler__content")??h.closest(".nice-scheduler__timegrid");T&&(T.scrollTop=y.offsetTop-4)}},[]),t.jsxs("div",{className:"nice-scheduler__timegrid",children:[t.jsxs("div",{className:"nice-scheduler__timegrid-header",children:[t.jsx("div",{className:"nice-scheduler__time-gutter"}),n.map((h,w)=>{const I=h.getDay()===0||h.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(h,g)?"nice-scheduler__timegrid-day-header--today":""} ${I?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:l[h.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:h.getDate()})]},w)})]}),t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:$,style:{position:"relative"},children:[o.map(h=>{const w=b?h>=b[0]&&h<b[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${w?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${h.toString().padStart(2,"0")}:00`}),n.map((I,P)=>{const q=e.filter(i=>{const y=new Date(i.start);return B(y,I)&&y.getHours()===h});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:a&&!v?i=>i.preventDefault():void 0,onDrop:a&&!v?()=>{if(!u.current||!k)return;const i=u.current.event,y=new Date(i.end).getTime()-new Date(i.start).getTime(),T=new Date(I);T.setHours(h,0,0,0);const W=new Date(T.getTime()+y);k(i,T,W),u.current=null}:void 0,onClick:()=>!v&&(()=>{const i=new Date(I);i.setHours(h);const y=new Date(i);y.setHours(h+1),x?.(i,y)})(),children:q.map(i=>t.jsx(me,{ev:i,renderEvent:M,onClick:_,draggable:a&&!v,dragRef:u,onHover:s,categoryColor:te(i,A)},i.id))},P)})]},h)}),E&&n.some(h=>B(h,g))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${p}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})]})},xt=({events:e,curDate:n,onEventClick:c,categories:d,t:a})=>{const u=[...e].filter(_=>new Date(_.start)>=new Date(n.getFullYear(),n.getMonth(),n.getDate())).sort((_,x)=>new Date(_.start).getTime()-new Date(x.start).getTime()).slice(0,50);return t.jsxs("div",{className:"nice-scheduler__agenda",children:[u.map(_=>t.jsx(Nt,{ev:_,categories:d,onEventClick:c},_.id)),u.length===0&&t.jsx("div",{className:"nice-scheduler__agenda-empty",children:a("noEvents","No upcoming events")})]})},We=({parts:e})=>t.jsx("div",{className:"nice-scheduler__agenda-meta",children:e.map(([n,c],d)=>t.jsxs(N.Fragment,{children:[d>0&&" · ",t.jsx(ce.NiceIcon,{name:n,size:12,style:{verticalAlign:"-2px"}})," ",c]},n))}),Je=({ev:e})=>{if(e.eventType==="recipe"&&e.recipe){const n=Ue(e.recipe),c=[];return n!==void 0&&c.push(["clock",`${n} min`]),e.recipe.ingredients?.length&&c.push(["list",`${e.recipe.ingredients.length} ingredients`]),e.recipe.servings&&c.push(["utensils",`${e.recipe.servings} servings`]),c.length===0?null:t.jsx(We,{parts:c})}if(e.eventType==="service"&&e.service){const n=e.service,c=[];return n.serviceName&&c.push(["bell",n.serviceName]),n.providerName&&c.push(["user",n.providerName]),n.customerName&&c.push(["arrow-right",n.customerName]),typeof n.price=="number"&&c.push(["dollar",`${n.price}${n.currency?" "+n.currency:""}`]),c.length===0?null:t.jsx(We,{parts:c})}return null},Nt=({ev:e,categories:n,onEventClick:c})=>{const d=ce.useAccessibleClick({onClick:()=>c?.(e)});return t.jsxs("div",{className:"nice-scheduler__agenda-item","aria-label":`Event ${e.title}`,...d,children:[t.jsx("div",{className:"nice-scheduler__agenda-dot",style:{backgroundColor:te(e,n)||e.color||"var(--nice-color-primary, #3b82f6)"}}),t.jsxs("div",{className:"nice-scheduler__agenda-info",children:[t.jsx("div",{className:"nice-scheduler__agenda-title",children:e.title}),t.jsxs("div",{className:"nice-scheduler__agenda-time",children:[new Date(e.start).toLocaleString()," – ",new Date(e.end).toLocaleString()]}),e.description&&t.jsx("div",{className:"nice-scheduler__agenda-desc",children:e.description}),t.jsx(Je,{ev:e})]}),e.category&&n&&t.jsx("span",{className:"nice-scheduler__agenda-badge",style:{backgroundColor:te(e,n)||e.color},children:n.find(a=>a.key===e.category)?.label})]})},Dt=({events:e,curDate:n,timelineDays:c,resources:d,draggable:a,dragRef:u,onEventClick:_,onSlotClick:x,onEventDrop:k,categories:A,renderEvent:b,onHoverEvent:D,readOnly:M,t:s})=>{const v=Array.from({length:c},(l,$)=>F(n,$)),S=d??[{id:"__default",name:""}],o=ue(s);return t.jsxs("div",{className:"nice-scheduler__timeline",children:[t.jsxs("div",{className:"nice-scheduler__timeline-header",children:[t.jsx("div",{className:"nice-scheduler__timeline-res-label"}),v.map((l,$)=>t.jsxs("div",{className:`nice-scheduler__timeline-day ${B(l,new Date)?"nice-scheduler__timeline-day--today":""}`,children:[o[l.getDay()]," ",l.getDate()]},$))]}),t.jsx("div",{className:"nice-scheduler__timeline-body",children:S.map(l=>{const $=e.filter(g=>!d||g.resourceId===l.id);return t.jsxs("div",{className:"nice-scheduler__timeline-row",children:[t.jsx("div",{className:"nice-scheduler__timeline-res-label",children:l.name}),v.map((g,L)=>{const m=$.filter(p=>B(new Date(p.start),g));return t.jsx("div",{className:"nice-scheduler__timeline-cell",onDragOver:a&&!M?p=>p.preventDefault():void 0,onDrop:a&&!M?()=>{if(!u.current||!k)return;const p=u.current.event,E=new Date(p.end).getTime()-new Date(p.start).getTime(),h=new Date(g);h.setHours(new Date(p.start).getHours(),new Date(p.start).getMinutes()),k(p,h,new Date(h.getTime()+E),l.id),u.current=null}:void 0,onClick:()=>!M&&x?.(g,F(g,1),l.id),children:m.map(p=>t.jsx(me,{ev:p,renderEvent:b,onClick:_,draggable:a&&!M,dragRef:u,onHover:D,categoryColor:te(p,A)},p.id))},L)})]},l.id)})})]})},He=({categories:e,events:n,filteredCategories:c,onToggleCategory:d,t:a})=>t.jsxs("div",{className:"nice-scheduler__legend",children:[t.jsx("div",{className:"nice-scheduler__legend-title",children:a("legend","Legend")}),e.map(u=>{const _=n.filter(k=>k.category===u.key).length,x=!c.has(u.key);return t.jsxs("button",{className:`nice-scheduler__legend-item ${x?"":"nice-scheduler__legend-item--hidden"}`,onClick:()=>d(u.key),children:[t.jsx("span",{className:"nice-scheduler__legend-dot",style:{backgroundColor:x?u.color:"var(--nice-border-color, #ccc)"}}),t.jsx("span",{className:"nice-scheduler__legend-label",children:u.label}),t.jsx("span",{className:"nice-scheduler__legend-count",children:_})]},u.key)})]}),wt=({curDate:e,onDateSelect:n,firstDayOfWeek:c,t:d})=>{const[a,u]=N.useState(e.getMonth()),[_,x]=N.useState(e.getFullYear()),k=new Date(_,a,1),A=new Date(_,a+1,0),b=(k.getDay()-c+7)%7,D=[];for(let l=b-1;l>=0;l--)D.push(F(k,-l-1));for(let l=0;l<A.getDate();l++)D.push(new Date(_,a,l+1));const M=7-D.length%7;if(M<7)for(let l=1;l<=M;l++)D.push(new Date(_,a+1,l));const s=()=>{a===0?(u(11),x(l=>l-1)):u(l=>l-1)},v=()=>{a===11?(u(0),x(l=>l+1)):u(l=>l+1)},S=Be(d),o=ue(d);return t.jsxs("div",{className:"nice-scheduler__mini-cal",children:[t.jsxs("div",{className:"nice-scheduler__mini-cal-header",children:[t.jsx("button",{type:"button",className:"nice-btn nice-btn--xs",onClick:s,"aria-label":d("scheduler.prevMonth","Previous month"),children:t.jsx(ce.NiceIcon,{name:"chevron-left",size:"sm"})}),t.jsxs("span",{children:[S[a]," ",_]}),t.jsx("button",{type:"button",className:"nice-btn nice-btn--xs",onClick:v,"aria-label":d("scheduler.nextMonth","Next month"),children:t.jsx(ce.NiceIcon,{name:"chevron-right",size:"sm"})})]}),t.jsxs("div",{className:"nice-scheduler__mini-cal-grid",children:[o.map((l,$)=>t.jsx("div",{className:"nice-scheduler__mini-cal-dayname",children:o[(c+$)%7].charAt(0)},$)),D.map((l,$)=>{const g=B(l,new Date),L=B(l,e),m=l.getMonth()!==a;return t.jsx("button",{className:`nice-scheduler__mini-cal-day ${g?"nice-scheduler__mini-cal-day--today":""} ${L?"nice-scheduler__mini-cal-day--selected":""} ${m?"nice-scheduler__mini-cal-day--other":""}`,onClick:()=>n(l),children:l.getDate()},$)})]})]})},bt=({events:e,rangeStart:n,rangeEnd:c,startHour:d,endHour:a,draggable:u,dragRef:_,onEventClick:x,onSlotClick:k,onEventDrop:A,categories:b,workHours:D,showCurrentTime:M,renderEvent:s,onHoverEvent:v,readOnly:S,t:o})=>{const l=[];let $=new Date(n);for(;$<=c;)l.push(new Date($)),$=F($,1);const g=[];for(let y=d;y<a;y++)g.push(y);const L=ke(o),m=N.useRef(null),p=N.useRef(null),E=N.useRef(null),h=new Date,w=h.getHours()*60+h.getMinutes(),I=(a-d)*60,P=(w-d*60)/I*100,q=M&&w>=d*60&&w<a*60;N.useEffect(()=>{const y=m.current;if(!y)return;const T=new Date,W=e.filter(R=>l.some(j=>B(j,T)&&B(new Date(R.start),T)));let z=W.length>0?Math.min(...W.map(R=>new Date(R.start).getHours())):T.getHours();z=Math.max(d,Math.min(z,a-1));const U=y.children[z-d];if(U){const R=E.current??y.closest(".nice-scheduler__content")??y.closest(".nice-scheduler__timegrid");R&&(R.scrollTop=U.offsetTop-4)}},[]);const i=y=>{p.current&&(p.current.scrollLeft=y.currentTarget.scrollLeft)};return t.jsxs("div",{className:"nice-scheduler__timegrid nice-scheduler__timegrid--range",children:[t.jsx("div",{className:"nice-scheduler__timegrid-header-scroll",ref:p,"aria-hidden":"true",children:t.jsxs("div",{className:"nice-scheduler__timegrid-header",children:[t.jsx("div",{className:"nice-scheduler__time-gutter"}),l.map((y,T)=>{const W=y.getDay()===0||y.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(y,h)?"nice-scheduler__timegrid-day-header--today":""} ${W?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:L[y.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:y.getDate()})]},T)})]})}),t.jsx("div",{className:"nice-scheduler__timegrid-body-scroll",ref:E,onScroll:i,children:t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:m,style:{position:"relative"},children:[g.map(y=>{const T=D?y>=D[0]&&y<D[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${T?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${y.toString().padStart(2,"0")}:00`}),l.map((W,z)=>{const U=e.filter(R=>{const j=new Date(R.start);return B(j,W)&&j.getHours()===y});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:u&&!S?R=>R.preventDefault():void 0,onDrop:u&&!S?()=>{if(!_.current||!A)return;const R=_.current.event,j=new Date(R.end).getTime()-new Date(R.start).getTime(),X=new Date(W);X.setHours(y,0,0,0),A(R,X,new Date(X.getTime()+j)),_.current=null}:void 0,onClick:()=>!S&&(()=>{const R=new Date(W);R.setHours(y);const j=new Date(R);j.setHours(y+1),k?.(R,j)})(),children:U.map(R=>t.jsx(me,{ev:R,renderEvent:s,onClick:x,draggable:u&&!S,dragRef:_,onHover:v,categoryColor:te(R,b)},R.id))},z)})]},y)}),q&&l.some(y=>B(y,h))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${P}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})})]})},jt=({events:e,rangeStart:n,rangeEnd:c,firstDayOfWeek:d,onSlotClick:a,onEventClick:u,draggable:_,dragRef:x,categories:k,renderEvent:A,onHoverEvent:b,readOnly:D,t:M})=>{const s=ue(M);ke(M);const v=[];let S=new Date(n);for(;S<=c;)v.push(new Date(S)),S=F(S,1);const o=(v[0].getDay()-d+7)%7,l=[];for(let g=o-1;g>=0;g--)l.push({date:F(v[0],-g-1),inRange:!1});v.forEach(g=>l.push({date:g,inRange:!0}));const $=7-l.length%7;if($<7){const g=v[v.length-1];for(let L=1;L<=$;L++)l.push({date:F(g,L),inRange:!1})}return t.jsxs("div",{className:"nice-scheduler__month nice-scheduler__month--range",children:[t.jsx("div",{className:"nice-scheduler__month-header",children:Array.from({length:7},(g,L)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:s[(d+L)%7]},L))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:l.map((g,L)=>{const m=ze(e,g.date),p=B(g.date,new Date),E=g.date.getDay()===0||g.date.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${g.inRange?"":"nice-scheduler__month-cell--other"} ${p?"nice-scheduler__month-cell--today":""} ${E?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!D&&a?.(g.date,F(g.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:g.date.getDate()===1||L===0?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"nice-scheduler__month-monthname",children:Be(M)[g.date.getMonth()]})," ",g.date.getDate()]}):g.date.getDate()}),m.slice(0,3).map(h=>t.jsx(me,{ev:h,renderEvent:A,onClick:u,draggable:_&&!D,dragRef:x,onHover:b,categoryColor:te(h,k)},h.id)),m.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",m.length-3]})]},L)})})]})},St=({event:e,rect:n,categories:c,renderTooltip:d})=>{if(d)return t.jsx("div",{className:"nice-scheduler__tooltip",style:{position:"fixed",left:n.right+8,top:n.top,zIndex:1e4},children:d(e)});const a=c?.find(u=>u.key===e.category);return t.jsxs("div",{className:"nice-scheduler__tooltip",style:{position:"fixed",left:n.right+8,top:n.top,zIndex:1e4},children:[t.jsx("div",{className:"nice-scheduler__tooltip-title",children:e.title}),t.jsxs("div",{className:"nice-scheduler__tooltip-time",children:[new Date(e.start).toLocaleString()," – ",new Date(e.end).toLocaleString()]}),a&&t.jsxs("div",{className:"nice-scheduler__tooltip-cat",children:[t.jsx("span",{className:"nice-scheduler__tooltip-dot",style:{backgroundColor:a.color}}),a.label]}),e.description&&t.jsx("div",{className:"nice-scheduler__tooltip-desc",children:e.description}),t.jsx(Je,{ev:e})]})},Ct=({event:e,slotStart:n,slotEnd:c,categories:d,resources:a,formFields:u,formFieldsByType:_,eventTypes:x,renderEditor:k,saving:A,onSave:b,onDelete:D,onClose:M,t:s})=>{const v=!!e,S=N.useMemo(()=>({title:e?.title??"",description:e?.description??"",color:e?.color??"var(--nice-primary, #3b82f6)",category:e?.category??"",eventStyle:e?.eventStyle??"solid",start:e?.start??n??new Date,end:e?.end??c??new Date,allDay:e?.allDay??!1,resourceId:e?.resourceId??"",eventType:e?.eventType??"task",recurring:!!e?.recurrence,recurrenceFreq:e?.recurrence?.freq??"weekly",recurrenceInterval:e?.recurrence?.interval??1,recurrenceCount:e?.recurrence?.count,recipeTitle:e?.recipe?.title??"",recipeServings:e?.recipe?.servings??2,recipePrep:e?.recipe?.prepMinutes,recipeCook:e?.recipe?.cookMinutes,recipeIngredients:(e?.recipe?.ingredients??[]).map(m=>[m.quantity,m.unit,m.name].filter(p=>p!==void 0&&p!=="").join(" ")).join(`
|
|
2
|
+
`),recipeSteps:(e?.recipe?.steps??[]).map(m=>m.instruction).join(`
|
|
3
|
+
`),serviceName:e?.service?.serviceName??"",serviceProvider:e?.service?.providerName??"",serviceCustomer:e?.service?.customerName??"",serviceContact:e?.service?.customerContact??"",serviceLocation:e?.service?.location??"",servicePrice:e?.service?.price,serviceCurrency:e?.service?.currency??"PLN",serviceNotes:e?.service?.notes??""}),[e,n,c]),[o,l]=N.useState(S);N.useEffect(()=>{l(S)},[S]);const $=N.useCallback((m,p)=>{l(E=>({...E,[m]:p}))},[]),g=N.useMemo(()=>{if(u&&u.length>0)return u;const m=i=>i.toString().padStart(2,"0"),p=i=>`${i.getFullYear()}-${m(i.getMonth()+1)}-${m(i.getDate())}`,E=i=>`${m(i.getHours())}:${m(i.getMinutes())}`,h=(i,y)=>{const T=i instanceof Date?i:new Date(i),W=isNaN(T.getTime())?new Date:T,z=p(W),U=E(W),R=(j,X)=>{const[G,V,he]=j.split("-").map(ne=>parseInt(ne,10)),[ge,pe]=X.split(":").map(ne=>parseInt(ne,10)),ae=new Date(W);!isNaN(G)&&!isNaN(V)&&!isNaN(he)&&ae.setFullYear(G,V-1,he),!isNaN(ge)&&!isNaN(pe)&&ae.setHours(ge,pe,0,0),y(ae)};return t.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx("span",{style:{fontSize:"0.7rem",color:"var(--nice-text-muted, #888)"},children:s("date","Date")}),t.jsx(Se.NiceDateTimePicker,{value:z,onChange:j=>R(j,U),size:"sm"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx("span",{style:{fontSize:"0.7rem",color:"var(--nice-text-muted, #888)"},children:s("time","Time")}),t.jsx(Se.NiceDateTimePicker,{dateFormatPreset:"time",value:U,onChange:j=>R(z,j),size:"sm"})]})]})},w=[];x&&x.length>1&&w.push({field:"eventType",label:s("eventType","Type"),type:"select",group:s("common","Common"),options:x.map(i=>({label:i.icon?`${i.icon} ${i.label}`:i.label,value:i.type}))}),w.push({field:"title",label:s("title","Title"),type:"text",required:!0,group:s("common","Common")},{field:"start",label:s("start","Start"),render:h,group:s("common","Common")},{field:"end",label:s("end","End"),render:h,group:s("common","Common")},{field:"description",label:s("description","Description"),type:"textarea",group:s("common","Common")},{field:"color",label:s("color","Color"),group:s("common","Common"),render:(i,y)=>t.jsx(O.NiceColorPicker,{value:typeof i=="string"?i:"var(--nice-primary, #3b82f6)",onChange:y,showInput:!1,showRandom:!1})}),d&&d.length>0&&w.push({field:"category",label:s("category","Category"),type:"select",group:s("common","Common"),options:[{label:s("none","(none)"),value:""},...d.map(i=>({label:i.label,value:i.key}))]}),a&&a.length>0&&w.push({field:"resourceId",label:s("resource","Resource"),type:"select",group:s("common","Common"),options:[{label:s("none","(none)"),value:""},...a.map(i=>({label:i.name,value:String(i.id)}))]});const I=s("recurring","Recurring");w.push({field:"recurring",label:s("repeat","Repeat"),type:"checkbox",group:I}),w.push({field:"recurrenceFreq",label:s("frequency","Frequency"),type:"select",group:I,visibleWhen:i=>!!i.recurring,options:[{label:s("daily","Daily"),value:"daily"},{label:s("weekly","Weekly"),value:"weekly"},{label:s("monthly","Monthly"),value:"monthly"},{label:s("yearly","Yearly"),value:"yearly"}]}),w.push({field:"recurrenceInterval",label:s("interval","Interval"),type:"number",group:I,visibleWhen:i=>!!i.recurring}),w.push({field:"recurrenceCount",label:s("occurrences","Occurrences (optional)"),type:"number",group:I,visibleWhen:i=>!!i.recurring});const P=o.eventType??"task",q=_?.[P];if(q&&q.length>0)w.push(...q);else if(P==="recipe"){const i=s("recipe.section","Recipe");w.push({field:"recipeTitle",label:s("recipe.title","Recipe title"),type:"text",group:i},{field:"recipeServings",label:s("recipe.servings","Servings"),type:"number",group:i},{field:"recipePrep",label:s("recipe.prepMinutes","Prep (min)"),type:"number",group:i},{field:"recipeCook",label:s("recipe.cookMinutes","Cook (min)"),type:"number",group:i},{field:"recipeIngredients",label:s("recipe.ingredients","Ingredients (one per line)"),type:"textarea",group:i,hint:s("recipe.ingredients.hint",'Format: "200 g flour"')},{field:"recipeSteps",label:s("recipe.steps","Steps (one per line)"),type:"textarea",group:i})}else if(P==="service"){const i=s("service.section","Service");w.push({field:"serviceName",label:s("service.name","Service name"),type:"text",group:i,required:!0},{field:"serviceProvider",label:s("service.provider","Provider"),type:"text",group:i},{field:"serviceCustomer",label:s("service.customer","Customer"),type:"text",group:i},{field:"serviceContact",label:s("service.contact","Contact"),type:"text",group:i},{field:"serviceLocation",label:s("service.location","Location"),type:"text",group:i},{field:"servicePrice",label:s("service.price","Price"),type:"number",group:i},{field:"serviceCurrency",label:s("service.currency","Currency"),type:"text",group:i},{field:"serviceNotes",label:s("service.notes","Notes"),type:"textarea",group:i})}return w},[u,_,x,d,a,o.eventType,s]),L=()=>{const m=o.eventType??"task",p={title:o.title,description:o.description||void 0,color:o.color,category:o.category||void 0,eventStyle:o.eventStyle,allDay:o.allDay,start:o.start instanceof Date?o.start:new Date(o.start),end:o.end instanceof Date?o.end:new Date(o.end),resourceId:o.resourceId||void 0,eventType:m};if(o.recurring){const E={freq:o.recurrenceFreq||"weekly",interval:typeof o.recurrenceInterval=="number"&&o.recurrenceInterval>0?o.recurrenceInterval:1};typeof o.recurrenceCount=="number"&&o.recurrenceCount>0&&(E.count=o.recurrenceCount),p.recurrence=E}else p.recurrence=void 0;if(m==="recipe"){const E=String(o.recipeIngredients||"").split(`
|
|
4
|
+
`).map(P=>P.trim()).filter(Boolean).map((P,q)=>{const i=P.match(/^([\d.,/]+)\s*(\S+)?\s+(.+)$/);if(i){const y=parseFloat(i[1].replace(",","."));return{id:`ing-${q}`,name:i[3],quantity:isNaN(y)?void 0:y,unit:i[2]}}return{id:`ing-${q}`,name:P}}),h=String(o.recipeSteps||"").split(`
|
|
5
|
+
`).map(P=>P.trim()).filter(Boolean).map((P,q)=>({id:`step-${q}`,order:q+1,instruction:P})),w=e?.recipe??Ke(),I={...w,title:o.recipeTitle||o.title||w.title,servings:typeof o.recipeServings=="number"?o.recipeServings:w.servings,prepMinutes:typeof o.recipePrep=="number"?o.recipePrep:w.prepMinutes,cookMinutes:typeof o.recipeCook=="number"?o.recipeCook:w.cookMinutes,ingredients:E,steps:h};p.recipe=I,p.service=void 0}else if(m==="service"){const E={serviceName:String(o.serviceName||""),providerName:o.serviceProvider||void 0,customerName:o.serviceCustomer||void 0,customerContact:o.serviceContact||void 0,location:o.serviceLocation||void 0,price:typeof o.servicePrice=="number"?o.servicePrice:void 0,currency:o.serviceCurrency||void 0,notes:o.serviceNotes||void 0};p.service=E,p.recipe=void 0}else p.recipe=void 0,p.service=void 0;return v&&(p.id=e.id),p};return t.jsx(lt.NiceModal,{open:!0,onClose:M,title:v?s("editEvent","Edit Event"):s("newEvent","New Event"),size:"md",footer:k?null:t.jsxs(t.Fragment,{children:[v&&D&&t.jsx(O.NiceButton,{type:"button",variant:"error",size:"sm",onClick:()=>{D(e),M()},disabled:A,children:s("delete","Delete")}),t.jsx("div",{style:{flex:1}}),t.jsx(O.NiceButton,{type:"button",variant:"secondary",size:"sm",onClick:M,disabled:A,children:s("cancel","Cancel")}),t.jsx(O.NiceButton,{type:"button",variant:"primary",size:"sm",onClick:()=>{o.title&&b(L())},disabled:A||!o.title,children:A?s("saving","Saving…"):s("save","Save")})]}),children:t.jsx("div",{className:"nice-scheduler__form-body",onKeyDown:m=>{m.key==="Enter"&&m.target.tagName!=="TEXTAREA"&&(m.preventDefault(),o.title&&b(L()))},children:k?k({event:e,slotStart:n,slotEnd:c,save:b,cancel:M,remove:D}):t.jsx(Se.NiceForm,{items:g,data:o,onFieldChange:$,columns:1,gap:12,size:"sm"})})})},kt=["day","workWeek","week","dayRange","month","monthRange","timeline","agenda"],Me=({events:e,defaultEvents:n,resources:c,currentDate:d,view:a,onDateChange:u,onViewChange:_,onEventClick:x,onSlotClick:k,onEventDrop:A,draggable:b=!1,timelineDays:D=7,startHour:M=0,endHour:s=24,firstDayOfWeek:v=1,categories:S,showLegend:o,showTooltip:l,renderEvent:$,renderTooltip:g,workHours:L,showCurrentTime:m=!0,showMiniCalendar:p,onEventCreate:E,onEventEdit:h,onEventDelete:w,editable:I=!0,formFields:P,formFieldsByType:q,eventTypes:i,renderEventEditor:y,loadEvents:T,onEventsChange:W,accessMode:z="full",className:U,style:R})=>{const{t:j}=ce.useNiceTranslation(),X=z==="hidden",G=z==="readOnly"||z==="disabled",V=z==="disabled",[he,ge]=N.useState(d??new Date),[pe,ae]=N.useState(a??"week"),ne=d!==void 0&&u!==void 0,Te=a!==void 0&&_!==void 0,Y=ne?d:he,C=Te?a:pe;je.useIgnoredPropChangeWarning("NiceScheduler","currentDate","onDateChange",d,ne),je.useIgnoredPropChangeWarning("NiceScheduler","view","onViewChange",a,Te);const Ge=N.useRef(null),[K,_e]=N.useState(()=>{const r=new Date;return r.setHours(0,0,0,0),r}),[J,xe]=N.useState(()=>F(new Date,13)),[Ne,$e]=N.useState(null),Oe=N.useCallback((r,f)=>{l&&$e(r&&f?{event:r,rect:f}:null)},[l]),[se,oe]=N.useState(null),[Xe,ye]=N.useState(!1),De=e!==void 0&&W!==void 0,[Qe,Ee]=ce.useControllableState({value:De?e:void 0,defaultValue:n,fallbackValue:[],onChange:W,componentName:"NiceScheduler"}),[Re,Ze]=N.useState(!1),[Le,et]=N.useState(null),[Tt,Ie]=N.useState(!1),Q=Le??(De||Re||e===void 0?Qe:e);je.useIgnoredPropChangeWarning("NiceScheduler","events","onEventsChange",e,De||!(Re||Le!==null),"the built-in editor has taken over the list");const[le,tt]=N.useState(new Set),Fe=N.useCallback(r=>{tt(f=>{const H=new Set(f);return H.has(r)?H.delete(r):H.add(r),H})},[]),Z=N.useMemo(()=>{if(C==="month")return{start:new Date(Y.getFullYear(),Y.getMonth(),1),end:new Date(Y.getFullYear(),Y.getMonth()+2,0)};if(C==="timeline")return{start:new Date(Y),end:F(Y,D)};if(C==="dayRange"||C==="monthRange")return{start:new Date(K),end:F(J,1)};const r=(()=>{const f=new Date(Y),H=(f.getDay()-v+7)%7;return F(f,-H)})();return{start:F(r,-1),end:F(r,8)}},[Y,C,v,D,K,J]),we=N.useMemo(()=>{let r=ft(Q,Z.start,Z.end);return le.size>0&&(r=r.filter(f=>!f.category||!le.has(f.category))),r},[Q,Z,le]),re=r=>{ge(r),u?.(r)},nt=r=>{ae(r),_?.(r)},Ae=r=>{if(C==="day")re(F(Y,r));else if(C==="week"||C==="workWeek")re(F(Y,r*7));else if(C==="timeline")re(F(Y,r*D));else if(C==="dayRange"||C==="monthRange"){const f=Math.round((J.getTime()-K.getTime())/864e5)+1;_e(F(K,r*f)),xe(F(J,r*f))}else{const f=new Date(Y);f.setMonth(f.getMonth()+r),re(f)}},be=N.useMemo(()=>{const r=new Date(Y),f=(r.getDay()-v+7)%7;return F(r,-f)},[Y,v]),fe=N.useMemo(()=>{if(C==="day")return[Y];if(C==="workWeek"){const r=[];for(let f=0;f<7;f++){const H=F(be,f),ee=H.getDay();ee!==0&&ee!==6&&r.push(H)}return r}return Array.from({length:7},(r,f)=>F(be,f))},[C,Y,be]),st=C==="day"?Y.toLocaleDateString():C==="week"||C==="workWeek"?`${fe[0].toLocaleDateString()} – ${fe[fe.length-1].toLocaleDateString()}`:C==="timeline"?`${Y.toLocaleDateString()} – ${F(Y,D-1).toLocaleDateString()}`:C==="dayRange"||C==="monthRange"?`${K.toLocaleDateString()} – ${J.toLocaleDateString()}`:`${gt(j)[Y.getMonth()]} ${Y.getFullYear()}`,rt=N.useCallback((r,f,H)=>{G||(I&&oe({mode:"create",slotStart:r,slotEnd:f}),k?.(r,f,H))},[I,k,G]),it=N.useCallback(r=>{I&&!G&&oe({mode:"edit",event:r}),x?.(r)},[I,x,G]),de=N.useCallback(r=>{Ze(!0),Ee(r)},[Ee]),ct=N.useCallback(async r=>{const f=se?.mode==="create";try{if(ye(!0),f){const ee=(E?await E(r):void 0)??{...r,id:typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`evt_${Date.now()}_${Math.random().toString(36).slice(2,7)}`},ve=Q.slice();ve.push(ee),de(ve)}else{const ee=(h?await h(r):void 0)??r,ve=Q.map(qe=>qe.id===ee.id?ee:qe);de(ve)}oe(null)}finally{ye(!1)}},[se,E,h,Q,de]),at=N.useCallback(async r=>{try{ye(!0),w&&await w(r);const f=Q.filter(H=>H.id!==r.id);de(f),oe(null)}finally{ye(!1)}},[w,Q,de]);N.useEffect(()=>{if(!T)return;let r=!1;return Ie(!0),T({start:Z.start,end:Z.end}).then(f=>{r||et(f)}).finally(()=>{r||Ie(!1)}),()=>{r=!0}},[T,Z.start.getTime(),Z.end.getTime()]);const ot=r=>({day:j("day","Day"),week:j("week","Week"),workWeek:j("workWeek","Work Week"),month:j("month","Month"),timeline:j("timeline","Timeline"),agenda:j("agenda","Agenda"),dayRange:j("dayRange","Day Range"),monthRange:j("monthRange","Month Range")})[r],ie={events:we,curDate:Y,firstDayOfWeek:v,startHour:M,endHour:s,draggable:b,dragRef:Ge,onEventClick:it,onSlotClick:rt,onEventDrop:A,resources:c,timelineDays:D,categories:S,workHours:L,showCurrentTime:m,renderEvent:$,showTooltip:l,renderTooltip:g,onHoverEvent:Oe,readOnly:G,t:j},Pe=C==="dayRange"||C==="monthRange",Ye=r=>{const f=H=>H.toString().padStart(2,"0");return`${r.getFullYear()}-${f(r.getMonth()+1)}-${f(r.getDate())}`};return X?null:t.jsxs("div",{className:`nice-scheduler ${V?"nice-scheduler--disabled":""} ${U||""}`,style:R,children:[t.jsxs("div",{className:"nice-scheduler__toolbar",children:[t.jsxs("div",{className:"nice-scheduler__nav",children:[t.jsxs(Ce,{size:"sm",children:[t.jsx(O.NiceButton,{onClick:()=>Ae(-1),disabled:V,"aria-label":j("previous","Previous"),children:"‹"}),t.jsx(O.NiceButton,{onClick:()=>{if(Pe){const r=new Date;r.setHours(0,0,0,0);const f=Math.round((J.getTime()-K.getTime())/864e5);_e(r),xe(F(r,f))}else re(new Date)},disabled:V,children:j("today","Today")}),t.jsx(O.NiceButton,{onClick:()=>Ae(1),disabled:V,"aria-label":j("next","Next"),children:"›"})]}),Pe?t.jsxs("span",{className:"nice-scheduler__range-picker",children:[t.jsx("input",{type:"date",className:"nice-textinput nice-textinput--sm",value:Ye(K),disabled:V,onChange:r=>{const f=new Date(r.target.value+"T00:00:00");isNaN(f.getTime())||_e(f)}}),t.jsx("span",{style:{margin:"0 4px"},children:"–"}),t.jsx("input",{type:"date",className:"nice-textinput nice-textinput--sm",value:Ye(J),disabled:V,onChange:r=>{const f=new Date(r.target.value+"T00:00:00");!isNaN(f.getTime())&&f>=K&&xe(f)}})]}):t.jsx("span",{className:"nice-scheduler__title",children:st})]}),t.jsx("div",{className:"nice-scheduler__views",children:t.jsx(Ce,{size:"sm",children:kt.map(r=>t.jsx(O.NiceButton,{variant:r===C?"primary":"secondary",onClick:()=>nt(r),disabled:V,children:ot(r)},r))})})]}),t.jsxs("div",{className:"nice-scheduler__body",children:[p&&t.jsxs("div",{className:"nice-scheduler__sidebar",children:[t.jsx(wt,{curDate:Y,onDateSelect:r=>re(r),firstDayOfWeek:v,t:j}),o&&S&&t.jsx(He,{categories:S,events:we,filteredCategories:le,onToggleCategory:Fe,t:j})]}),t.jsxs("div",{className:"nice-scheduler__content",children:[C==="month"&&t.jsx(vt,{...ie}),(C==="week"||C==="day"||C==="workWeek")&&t.jsx(_t,{...ie,days:fe}),C==="dayRange"&&t.jsx(bt,{...ie,rangeStart:K,rangeEnd:J}),C==="monthRange"&&t.jsx(jt,{...ie,rangeStart:K,rangeEnd:J}),C==="timeline"&&t.jsx(Dt,{...ie}),C==="agenda"&&t.jsx(xt,{...ie})]}),!p&&o&&S&&t.jsx("div",{className:"nice-scheduler__sidebar nice-scheduler__sidebar--right",children:t.jsx(He,{categories:S,events:we,filteredCategories:le,onToggleCategory:Fe,t:j})})]}),Ne&&t.jsx(St,{event:Ne.event,rect:Ne.rect,categories:S,renderTooltip:g}),se&&I&&t.jsx(Ct,{event:se.event,slotStart:se.slotStart,slotEnd:se.slotEnd,categories:S,resources:c,formFields:P,formFieldsByType:q,eventTypes:i,renderEditor:y,saving:Xe,onSave:ct,onDelete:at,onClose:()=>oe(null),t:j})]})};Me.displayName="NiceScheduler";const Mt=Object.freeze(Object.defineProperty({__proto__:null,NiceScheduler:Me},Symbol.toStringTag,{value:"Module"}));exports.NiceButtonGroup=Ce;exports.NiceScheduler=Me;exports.NiceScheduler$1=Mt;exports.createEmptyRecipe=Ke;exports.newRecipeId=Ve;exports.recipeTotalMinutes=Ue;
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { jsxs as a, jsx as n, Fragment as Ne } from "react/jsx-runtime";
|
|
2
|
+
import { NiceThemeContext as je, useNiceAccessMode as He, useNiceTranslation as Ke, useComponentDisplayStyle as We, useComponentDisplayClass as qe, useControlId as Be, useDisplayModeEdit as Ue, useNiceLookupSource as Pe, COMMON_SHORTCUTS as ue, NiceKeyboardHint as Ve, DisplayModeView as Ge, NiceIcon as xe } from "@nice2dev/ui-core";
|
|
3
|
+
import Je, { useRef as se, useState as m, useContext as Qe, useLayoutEffect as he, useEffect as Xe, forwardRef as Ye, useMemo as W, useCallback as fe } from "react";
|
|
4
|
+
import { createPortal as Ze } from "react-dom";
|
|
5
|
+
function en(h) {
|
|
6
|
+
const i = h?.closest?.("[data-theme], .nice-dark, .nice-light, .dark");
|
|
7
|
+
if (!i)
|
|
8
|
+
return "";
|
|
9
|
+
const r = i.getAttribute("data-theme");
|
|
10
|
+
return r === "dark" || i.classList.contains("nice-dark") || i.classList.contains("dark") ? "nice-dark" : r === "light" || i.classList.contains("nice-light") ? "nice-light" : "";
|
|
11
|
+
}
|
|
12
|
+
function nn(h, i, r, q) {
|
|
13
|
+
const _ = q?.maxHeight ?? 320, B = q?.anchorKey, T = se(null), [U, ce] = m(null), [le, P] = m(!1), [I, re] = m(""), k = Qe(je)?.portalTarget ?? (typeof document < "u" ? document.body : null), v = se(r);
|
|
14
|
+
return v.current = r, he(() => {
|
|
15
|
+
if (!h || !i.current)
|
|
16
|
+
return;
|
|
17
|
+
re(en(i.current)), P(!1);
|
|
18
|
+
const c = () => {
|
|
19
|
+
const y = i.current;
|
|
20
|
+
if (!y)
|
|
21
|
+
return;
|
|
22
|
+
const l = y.getBoundingClientRect(), A = T.current?.offsetHeight ?? _;
|
|
23
|
+
let L = l.bottom;
|
|
24
|
+
L + A > window.innerHeight - 8 && l.top - A > 8 && (L = l.top - A);
|
|
25
|
+
let $ = l.left;
|
|
26
|
+
$ + l.width > window.innerWidth - 8 && ($ = Math.max(8, window.innerWidth - l.width - 8)), ce(
|
|
27
|
+
(d) => d && d.left === $ && d.top === L && d.width === l.width ? d : { left: $, top: L, width: l.width }
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
c();
|
|
31
|
+
const E = requestAnimationFrame(() => {
|
|
32
|
+
c(), P(!0);
|
|
33
|
+
}), g = (y) => {
|
|
34
|
+
const l = y.target;
|
|
35
|
+
l instanceof Node && (T.current?.contains(l) || i.current?.contains(l)) || v.current();
|
|
36
|
+
}, p = () => v.current();
|
|
37
|
+
return window.addEventListener("scroll", g, !0), window.addEventListener("resize", p), () => {
|
|
38
|
+
cancelAnimationFrame(E), window.removeEventListener("scroll", g, !0), window.removeEventListener("resize", p);
|
|
39
|
+
};
|
|
40
|
+
}, [h, i, _, B]), Xe(() => {
|
|
41
|
+
if (!h)
|
|
42
|
+
return;
|
|
43
|
+
const c = (g) => {
|
|
44
|
+
const p = g.target;
|
|
45
|
+
i.current?.contains(p) || T.current?.contains(p) || (p instanceof Element ? p : p?.parentElement ?? null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]') || v.current();
|
|
46
|
+
}, E = (g) => {
|
|
47
|
+
g.key === "Escape" && v.current();
|
|
48
|
+
};
|
|
49
|
+
return document.addEventListener("mousedown", c), document.addEventListener("keydown", E), () => {
|
|
50
|
+
document.removeEventListener("mousedown", c), document.removeEventListener("keydown", E);
|
|
51
|
+
};
|
|
52
|
+
}, [h, i]), { popupRef: T, coords: U, ready: le, themeClass: I, portalTarget: k };
|
|
53
|
+
}
|
|
54
|
+
const be = Ye(
|
|
55
|
+
({
|
|
56
|
+
label: h,
|
|
57
|
+
helperText: i,
|
|
58
|
+
error: r,
|
|
59
|
+
required: q,
|
|
60
|
+
disabled: _,
|
|
61
|
+
size: B = "md",
|
|
62
|
+
name: T,
|
|
63
|
+
id: U,
|
|
64
|
+
className: ce,
|
|
65
|
+
style: le,
|
|
66
|
+
accessMode: P,
|
|
67
|
+
displayStyle: I,
|
|
68
|
+
options: re,
|
|
69
|
+
value: b,
|
|
70
|
+
onChange: k,
|
|
71
|
+
placeholder: v,
|
|
72
|
+
multiple: c = !1,
|
|
73
|
+
searchable: E = !0,
|
|
74
|
+
clearable: g = !1,
|
|
75
|
+
emptyText: p,
|
|
76
|
+
maxHeight: y = 240,
|
|
77
|
+
optionsSource: l,
|
|
78
|
+
valueField: A,
|
|
79
|
+
labelField: L,
|
|
80
|
+
virtualScroll: $,
|
|
81
|
+
optionHeight: d = 36,
|
|
82
|
+
onSearch: O,
|
|
83
|
+
loading: w,
|
|
84
|
+
renderOption: V,
|
|
85
|
+
multipleAutosize: G = !1,
|
|
86
|
+
showKeyboardHints: ke,
|
|
87
|
+
labelPlacement: $e,
|
|
88
|
+
errorPlacement: J,
|
|
89
|
+
labelWidth: Q,
|
|
90
|
+
controlWidth: F,
|
|
91
|
+
displayMode: Ce
|
|
92
|
+
}, X) => {
|
|
93
|
+
const oe = He(P, U), Ee = oe === "hidden";
|
|
94
|
+
(oe === "disabled" || oe === "readOnly") && (_ = !0);
|
|
95
|
+
const { t: N } = Ke(), Le = We("input", I), Me = qe("input", I), M = Be(U), pe = Ue({ enabled: Ce, disabled: _ }), [x, S] = m(!1), [Y, Z] = m(""), [D, z] = m(-1), [me, Se] = m(0), _e = se(null), j = se(null), [ve, De] = m(null);
|
|
96
|
+
he(() => {
|
|
97
|
+
!w && j.current && De(j.current.offsetWidth);
|
|
98
|
+
}, [w, b, I]);
|
|
99
|
+
const [H, Re] = m(null);
|
|
100
|
+
he(() => {
|
|
101
|
+
c && !G && j.current && H == null && Re(j.current.offsetWidth);
|
|
102
|
+
}, [c, G, H]);
|
|
103
|
+
const Te = Pe(
|
|
104
|
+
l ?? null,
|
|
105
|
+
A ?? l?.keyField ?? "id",
|
|
106
|
+
L ?? "name"
|
|
107
|
+
), C = l ? Te.options : (re ?? []).map(
|
|
108
|
+
(e) => typeof e == "string" ? { value: e, label: e } : e
|
|
109
|
+
), { popupRef: Ie, coords: K, ready: ge, themeClass: ee, portalTarget: ye } = nn(
|
|
110
|
+
x,
|
|
111
|
+
_e,
|
|
112
|
+
() => {
|
|
113
|
+
S(!1), Z("");
|
|
114
|
+
}
|
|
115
|
+
), o = W(() => b ? Array.isArray(b) ? b : [b] : [], [b]), u = W(() => {
|
|
116
|
+
if (!Y && !O || O)
|
|
117
|
+
return C;
|
|
118
|
+
const e = Y.toLowerCase();
|
|
119
|
+
return C.filter(
|
|
120
|
+
(s) => s.label.toLowerCase().includes(e) || String(s.value).toLowerCase().includes(e)
|
|
121
|
+
);
|
|
122
|
+
}, [C, Y, O]), we = W(() => {
|
|
123
|
+
const e = /* @__PURE__ */ new Map();
|
|
124
|
+
for (const s of u) {
|
|
125
|
+
const t = s.group || "";
|
|
126
|
+
e.has(t) || e.set(t, []), e.get(t).push(s);
|
|
127
|
+
}
|
|
128
|
+
return e;
|
|
129
|
+
}, [u]), ne = fe(
|
|
130
|
+
(e) => {
|
|
131
|
+
if (c) {
|
|
132
|
+
const s = o.includes(e) ? o.filter((t) => t !== e) : [...o, e];
|
|
133
|
+
k?.(s);
|
|
134
|
+
} else
|
|
135
|
+
k?.(e), S(!1), Z("");
|
|
136
|
+
},
|
|
137
|
+
[c, o, k]
|
|
138
|
+
), Ae = fe(
|
|
139
|
+
(e) => {
|
|
140
|
+
if (e.key === "Escape") {
|
|
141
|
+
S(!1), Z("");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
145
|
+
if (!x) {
|
|
146
|
+
S(!0), e.preventDefault();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
D >= 0 && u[D] && (ne(u[D].value), e.preventDefault());
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
e.key === "ArrowDown" && (e.preventDefault(), z((s) => Math.min(s + 1, u.length - 1))), e.key === "ArrowUp" && (e.preventDefault(), z((s) => Math.max(s - 1, 0)));
|
|
153
|
+
},
|
|
154
|
+
[x, D, u, ne]
|
|
155
|
+
), ae = W(() => o.length === 0 ? null : c ? o.map((e) => C.find((s) => s.value === e)?.label || e).join(", ") : C.find((e) => e.value === o[0])?.label || o[0], [o, C, c]), Oe = fe(
|
|
156
|
+
(e) => {
|
|
157
|
+
e.stopPropagation(), k?.(c ? [] : "");
|
|
158
|
+
},
|
|
159
|
+
[k, c]
|
|
160
|
+
), Fe = W(
|
|
161
|
+
() => [
|
|
162
|
+
{ key: "Enter", description: N("shortcuts.select", "Select") },
|
|
163
|
+
{ key: "Space", description: N("shortcuts.openDropdown", "Open dropdown") },
|
|
164
|
+
ue.moveUp,
|
|
165
|
+
ue.moveDown,
|
|
166
|
+
ue.cancel
|
|
167
|
+
],
|
|
168
|
+
[N]
|
|
169
|
+
);
|
|
170
|
+
return Ee ? null : /* @__PURE__ */ a(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
className: `nice-field ${F == null ? "nice-field--select-auto" : ""} nice-field--${B} ${$e === "left" ? "nice-field--label-left" : ""} ${w ? "nice-field--loading" : ""} ${ce || ""}`,
|
|
174
|
+
style: {
|
|
175
|
+
...le,
|
|
176
|
+
...Q != null && {
|
|
177
|
+
"--nice-field-label-width": typeof Q == "number" ? `${Q}px` : Q
|
|
178
|
+
},
|
|
179
|
+
...F != null && {
|
|
180
|
+
"--nice-field-control-width": typeof F == "number" ? `${F}px` : F
|
|
181
|
+
},
|
|
182
|
+
...w && ve != null && { "--nice-select-locked-width": `${ve}px` }
|
|
183
|
+
},
|
|
184
|
+
"aria-busy": w || void 0,
|
|
185
|
+
children: [
|
|
186
|
+
h && /* @__PURE__ */ a(
|
|
187
|
+
"label",
|
|
188
|
+
{
|
|
189
|
+
htmlFor: M,
|
|
190
|
+
className: `nice-field__label ${q ? "nice-field__label--required" : ""}`,
|
|
191
|
+
children: [
|
|
192
|
+
h,
|
|
193
|
+
ke && /* @__PURE__ */ n(Ve, { shortcuts: Fe, size: "sm" })
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
),
|
|
197
|
+
/* @__PURE__ */ a("div", { className: "nice-field__control", children: [
|
|
198
|
+
pe.isDisplay ? /* @__PURE__ */ n(
|
|
199
|
+
Ge,
|
|
200
|
+
{
|
|
201
|
+
value: ae,
|
|
202
|
+
placeholder: v || N("controls.select", "Select..."),
|
|
203
|
+
disabled: _,
|
|
204
|
+
onActivate: () => {
|
|
205
|
+
pe.enterEdit(), S(!0);
|
|
206
|
+
},
|
|
207
|
+
ariaLabel: h
|
|
208
|
+
}
|
|
209
|
+
) : /* @__PURE__ */ a("div", { className: "nice-select", ref: _e, children: [
|
|
210
|
+
/* @__PURE__ */ a(
|
|
211
|
+
"button",
|
|
212
|
+
{
|
|
213
|
+
ref: (e) => {
|
|
214
|
+
j.current = e, typeof X == "function" ? X(e) : X && (X.current = e);
|
|
215
|
+
},
|
|
216
|
+
type: "button",
|
|
217
|
+
id: M,
|
|
218
|
+
role: "combobox",
|
|
219
|
+
"aria-expanded": x,
|
|
220
|
+
"aria-haspopup": "listbox",
|
|
221
|
+
"aria-invalid": !!r,
|
|
222
|
+
className: `nice-select__trigger nice-select__trigger--${B} nice-select--ds-${Me} ${x ? "nice-select__trigger--open" : ""} ${r ? "nice-select__trigger--error" : ""} ${_ ? "nice-select__trigger--disabled" : ""}`,
|
|
223
|
+
style: {
|
|
224
|
+
...Le,
|
|
225
|
+
...c && !G && H != null ? {
|
|
226
|
+
width: H,
|
|
227
|
+
maxWidth: H,
|
|
228
|
+
overflow: "hidden"
|
|
229
|
+
} : {}
|
|
230
|
+
},
|
|
231
|
+
disabled: _,
|
|
232
|
+
onClick: () => S(!x),
|
|
233
|
+
onKeyDown: Ae,
|
|
234
|
+
children: [
|
|
235
|
+
ae ? /* @__PURE__ */ n(
|
|
236
|
+
"span",
|
|
237
|
+
{
|
|
238
|
+
style: c && !G ? {
|
|
239
|
+
flex: 1,
|
|
240
|
+
minWidth: 0,
|
|
241
|
+
overflow: "hidden",
|
|
242
|
+
textOverflow: "ellipsis",
|
|
243
|
+
whiteSpace: "nowrap"
|
|
244
|
+
} : void 0,
|
|
245
|
+
children: ae
|
|
246
|
+
}
|
|
247
|
+
) : /* @__PURE__ */ n("span", { className: "nice-select__placeholder", children: v || N("controls.select", "Select...") }),
|
|
248
|
+
/* @__PURE__ */ a("span", { style: { display: "flex", alignItems: "center", gap: 4 }, children: [
|
|
249
|
+
g && o.length > 0 && /* @__PURE__ */ n(
|
|
250
|
+
"span",
|
|
251
|
+
{
|
|
252
|
+
className: "nice-input__clear",
|
|
253
|
+
onClick: Oe,
|
|
254
|
+
role: "button",
|
|
255
|
+
"aria-label": N("controls.clear", "Clear"),
|
|
256
|
+
children: /* @__PURE__ */ n(xe, { name: "close", size: 14 })
|
|
257
|
+
}
|
|
258
|
+
),
|
|
259
|
+
/* @__PURE__ */ n(
|
|
260
|
+
"span",
|
|
261
|
+
{
|
|
262
|
+
className: `nice-select__chevron ${x ? "nice-select__chevron--open" : ""}`,
|
|
263
|
+
children: /* @__PURE__ */ n(xe, { name: "chevron-down", size: 16 })
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
] })
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
x && K && ye && Ze(
|
|
271
|
+
/* @__PURE__ */ a(
|
|
272
|
+
"div",
|
|
273
|
+
{
|
|
274
|
+
ref: Ie,
|
|
275
|
+
className: `nice-select__dropdown${ee ? ` ${ee}` : ""}`,
|
|
276
|
+
"data-theme": ee === "nice-dark" ? "dark" : ee === "nice-light" ? "light" : void 0,
|
|
277
|
+
role: "listbox",
|
|
278
|
+
style: {
|
|
279
|
+
maxHeight: y,
|
|
280
|
+
position: "fixed",
|
|
281
|
+
left: K.left,
|
|
282
|
+
top: K.top,
|
|
283
|
+
width: K.width,
|
|
284
|
+
minWidth: K.width,
|
|
285
|
+
zIndex: 1e3,
|
|
286
|
+
// Hidden until measured so the estimate frame never paints above.
|
|
287
|
+
opacity: ge ? 1 : 0,
|
|
288
|
+
pointerEvents: ge ? void 0 : "none"
|
|
289
|
+
},
|
|
290
|
+
onScroll: $ ? (e) => Se(e.currentTarget.scrollTop) : void 0,
|
|
291
|
+
children: [
|
|
292
|
+
(E || O) && /* @__PURE__ */ n("div", { className: "nice-select__search", children: /* @__PURE__ */ n(
|
|
293
|
+
"input",
|
|
294
|
+
{
|
|
295
|
+
type: "text",
|
|
296
|
+
value: Y,
|
|
297
|
+
onChange: (e) => {
|
|
298
|
+
Z(e.target.value), z(0), O?.(e.target.value);
|
|
299
|
+
},
|
|
300
|
+
placeholder: N("controls.search", "Search..."),
|
|
301
|
+
autoFocus: !0
|
|
302
|
+
}
|
|
303
|
+
) }),
|
|
304
|
+
w && /* @__PURE__ */ n("div", { className: "nice-select__loading", children: /* @__PURE__ */ n(
|
|
305
|
+
"div",
|
|
306
|
+
{
|
|
307
|
+
className: "nice-spinner nice-spinner--sm",
|
|
308
|
+
style: { margin: "8px auto" }
|
|
309
|
+
}
|
|
310
|
+
) }),
|
|
311
|
+
!w && u.length === 0 ? /* @__PURE__ */ n("div", { className: "nice-select__empty", children: p || N("controls.noResults", "No results found") }) : $ && !Array.from(we.keys()).some((e) => e !== "") ? (() => {
|
|
312
|
+
const s = u.length * d, t = Math.max(
|
|
313
|
+
0,
|
|
314
|
+
Math.floor(me / d) - 3
|
|
315
|
+
), R = Math.min(
|
|
316
|
+
u.length,
|
|
317
|
+
Math.ceil((me + y) / d) + 3
|
|
318
|
+
), te = u.slice(t, R);
|
|
319
|
+
return /* @__PURE__ */ n("div", { style: { height: s, position: "relative" }, children: te.map((f, ze) => {
|
|
320
|
+
const de = t + ze, ie = o.includes(f.value);
|
|
321
|
+
return /* @__PURE__ */ n(
|
|
322
|
+
"div",
|
|
323
|
+
{
|
|
324
|
+
role: "option",
|
|
325
|
+
"aria-selected": ie,
|
|
326
|
+
className: `nice-select__option ${ie ? "nice-select__option--selected" : ""} ${de === D ? "nice-select__option--highlighted" : ""} ${f.disabled ? "nice-select__option--disabled" : ""}`,
|
|
327
|
+
style: {
|
|
328
|
+
position: "absolute",
|
|
329
|
+
top: de * d,
|
|
330
|
+
left: 0,
|
|
331
|
+
right: 0,
|
|
332
|
+
height: d,
|
|
333
|
+
display: "flex",
|
|
334
|
+
alignItems: "center",
|
|
335
|
+
padding: "0 12px"
|
|
336
|
+
},
|
|
337
|
+
onClick: () => !f.disabled && ne(String(f.value)),
|
|
338
|
+
onMouseEnter: () => z(de),
|
|
339
|
+
children: V ? V(f, ie) : /* @__PURE__ */ a(Ne, { children: [
|
|
340
|
+
f.icon && /* @__PURE__ */ n("span", { children: f.icon }),
|
|
341
|
+
/* @__PURE__ */ a("div", { style: { flex: 1 }, children: [
|
|
342
|
+
/* @__PURE__ */ n("div", { children: f.label }),
|
|
343
|
+
f.description && /* @__PURE__ */ n("div", { className: "nice-select__option-desc", children: f.description })
|
|
344
|
+
] }),
|
|
345
|
+
ie && /* @__PURE__ */ n(
|
|
346
|
+
"svg",
|
|
347
|
+
{
|
|
348
|
+
className: "nice-select__option-check",
|
|
349
|
+
viewBox: "0 0 20 20",
|
|
350
|
+
fill: "currentColor",
|
|
351
|
+
children: /* @__PURE__ */ n(
|
|
352
|
+
"path",
|
|
353
|
+
{
|
|
354
|
+
fillRule: "evenodd",
|
|
355
|
+
d: "M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",
|
|
356
|
+
clipRule: "evenodd"
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
)
|
|
361
|
+
] })
|
|
362
|
+
},
|
|
363
|
+
f.value
|
|
364
|
+
);
|
|
365
|
+
}) });
|
|
366
|
+
})() : Array.from(we.entries()).map(([e, s]) => /* @__PURE__ */ a(Je.Fragment, { children: [
|
|
367
|
+
e && /* @__PURE__ */ n("div", { className: "nice-select__group-label", children: e }),
|
|
368
|
+
s.map((t) => {
|
|
369
|
+
const R = o.includes(t.value), te = u.indexOf(t);
|
|
370
|
+
return /* @__PURE__ */ n(
|
|
371
|
+
"div",
|
|
372
|
+
{
|
|
373
|
+
role: "option",
|
|
374
|
+
"aria-selected": R,
|
|
375
|
+
className: `nice-select__option ${R ? "nice-select__option--selected" : ""} ${te === D ? "nice-select__option--highlighted" : ""} ${t.disabled ? "nice-select__option--disabled" : ""}`,
|
|
376
|
+
onClick: () => !t.disabled && ne(String(t.value)),
|
|
377
|
+
onMouseEnter: () => z(te),
|
|
378
|
+
children: V ? V(t, R) : /* @__PURE__ */ a(Ne, { children: [
|
|
379
|
+
t.icon && /* @__PURE__ */ n("span", { children: t.icon }),
|
|
380
|
+
/* @__PURE__ */ a("div", { style: { flex: 1 }, children: [
|
|
381
|
+
/* @__PURE__ */ n("div", { children: t.label }),
|
|
382
|
+
t.description && /* @__PURE__ */ n("div", { className: "nice-select__option-desc", children: t.description })
|
|
383
|
+
] }),
|
|
384
|
+
R && /* @__PURE__ */ n(
|
|
385
|
+
"svg",
|
|
386
|
+
{
|
|
387
|
+
className: "nice-select__option-check",
|
|
388
|
+
viewBox: "0 0 20 20",
|
|
389
|
+
fill: "currentColor",
|
|
390
|
+
children: /* @__PURE__ */ n(
|
|
391
|
+
"path",
|
|
392
|
+
{
|
|
393
|
+
fillRule: "evenodd",
|
|
394
|
+
d: "M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",
|
|
395
|
+
clipRule: "evenodd"
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
)
|
|
400
|
+
] })
|
|
401
|
+
},
|
|
402
|
+
t.value
|
|
403
|
+
);
|
|
404
|
+
})
|
|
405
|
+
] }, e))
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
),
|
|
409
|
+
ye
|
|
410
|
+
)
|
|
411
|
+
] }),
|
|
412
|
+
w && /* @__PURE__ */ n("span", { className: "nice-field__spinner", children: /* @__PURE__ */ n("span", { className: "nice-spinner nice-spinner--sm" }) }),
|
|
413
|
+
J === "right" && r && /* @__PURE__ */ n("div", { id: `${M}-error`, className: "nice-field__error", role: "alert", children: r }),
|
|
414
|
+
J === "right" && !r && i && /* @__PURE__ */ n("div", { id: `${M}-helper`, className: "nice-field__helper", children: i })
|
|
415
|
+
] }),
|
|
416
|
+
J !== "right" && r && /* @__PURE__ */ n("div", { id: `${M}-error`, className: "nice-field__error", role: "alert", children: r }),
|
|
417
|
+
J !== "right" && !r && i && /* @__PURE__ */ n("div", { id: `${M}-helper`, className: "nice-field__helper", children: i })
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
be.displayName = "NiceSelect";
|
|
424
|
+
const rn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
425
|
+
__proto__: null,
|
|
426
|
+
NiceSelect: be
|
|
427
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
428
|
+
export {
|
|
429
|
+
be as N,
|
|
430
|
+
rn as a,
|
|
431
|
+
en as s,
|
|
432
|
+
nn as u
|
|
433
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),o=require("@nice2dev/ui-core"),s=require("react"),Te=require("react-dom");function _e(p){const i=p?.closest?.("[data-theme], .nice-dark, .nice-light, .dark");if(!i)return"";const a=i.getAttribute("data-theme");return a==="dark"||i.classList.contains("nice-dark")||i.classList.contains("dark")?"nice-dark":a==="light"||i.classList.contains("nice-light")?"nice-light":""}function ve(p,i,a,K){const x=K?.maxHeight??320,U=K?.anchorKey,D=s.useRef(null),[W,ne]=s.useState(null),[ie,B]=s.useState(!1),[T,ce]=s.useState(""),b=s.useContext(o.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),_=s.useRef(a);return _.current=a,s.useLayoutEffect(()=>{if(!p||!i.current)return;ce(_e(i.current)),B(!1);const l=()=>{const g=i.current;if(!g)return;const r=g.getBoundingClientRect(),O=D.current?.offsetHeight??x;let M=r.bottom;M+O>window.innerHeight-8&&r.top-O>8&&(M=r.top-O);let k=r.left;k+r.width>window.innerWidth-8&&(k=Math.max(8,window.innerWidth-r.width-8)),ne(u=>u&&u.left===k&&u.top===M&&u.width===r.width?u:{left:k,top:M,width:r.width})};l();const S=requestAnimationFrame(()=>{l(),B(!0)}),v=g=>{const r=g.target;r instanceof Node&&(D.current?.contains(r)||i.current?.contains(r))||_.current()},m=()=>_.current();return window.addEventListener("scroll",v,!0),window.addEventListener("resize",m),()=>{cancelAnimationFrame(S),window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",m)}},[p,i,x,U]),s.useEffect(()=>{if(!p)return;const l=v=>{const m=v.target;i.current?.contains(m)||D.current?.contains(m)||(m instanceof Element?m:m?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||_.current()},S=v=>{v.key==="Escape"&&_.current()};return document.addEventListener("mousedown",l),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",S)}},[p,i]),{popupRef:D,coords:W,ready:ie,themeClass:T,portalTarget:b}}const ae=s.forwardRef(({label:p,helperText:i,error:a,required:K,disabled:x,size:U="md",name:D,id:W,className:ne,style:ie,accessMode:B,displayStyle:T,options:ce,value:N,onChange:b,placeholder:_,multiple:l=!1,searchable:S=!0,clearable:v=!1,emptyText:m,maxHeight:g=240,optionsSource:r,valueField:O,labelField:M,virtualScroll:k,optionHeight:u=36,onSearch:I,loading:y,renderOption:P,multipleAutosize:V=!1,showKeyboardHints:ge,labelPlacement:ye,errorPlacement:G,labelWidth:J,controlWidth:A,displayMode:we},Q)=>{const le=o.useNiceAccessMode(B,W),je=le==="hidden";(le==="disabled"||le==="readOnly")&&(x=!0);const{t:w}=o.useNiceTranslation(),Ne=o.useComponentDisplayStyle("input",T),be=o.useComponentDisplayClass("input",T),$=o.useControlId(W),de=o.useDisplayModeEdit({enabled:we,disabled:x}),[j,E]=s.useState(!1),[X,Y]=s.useState(""),[L,F]=s.useState(-1),[ue,ke]=s.useState(0),fe=s.useRef(null),q=s.useRef(null),[he,Ce]=s.useState(null);s.useLayoutEffect(()=>{!y&&q.current&&Ce(q.current.offsetWidth)},[y,N,T]);const[H,Se]=s.useState(null);s.useLayoutEffect(()=>{l&&!V&&q.current&&H==null&&Se(q.current.offsetWidth)},[l,V,H]);const Me=o.useNiceLookupSource(r??null,O??r?.keyField??"id",M??"name"),C=r?Me.options:(ce??[]).map(e=>typeof e=="string"?{value:e,label:e}:e),{popupRef:$e,coords:z,ready:pe,themeClass:Z,portalTarget:me}=ve(j,fe,()=>{E(!1),Y("")}),d=s.useMemo(()=>N?Array.isArray(N)?N:[N]:[],[N]),f=s.useMemo(()=>{if(!X&&!I||I)return C;const e=X.toLowerCase();return C.filter(c=>c.label.toLowerCase().includes(e)||String(c.value).toLowerCase().includes(e))},[C,X,I]),xe=s.useMemo(()=>{const e=new Map;for(const c of f){const n=c.group||"";e.has(n)||e.set(n,[]),e.get(n).push(c)}return e},[f]),ee=s.useCallback(e=>{if(l){const c=d.includes(e)?d.filter(n=>n!==e):[...d,e];b?.(c)}else b?.(e),E(!1),Y("")},[l,d,b]),Ee=s.useCallback(e=>{if(e.key==="Escape"){E(!1),Y("");return}if(e.key==="Enter"||e.key===" "){if(!j){E(!0),e.preventDefault();return}L>=0&&f[L]&&(ee(f[L].value),e.preventDefault());return}e.key==="ArrowDown"&&(e.preventDefault(),F(c=>Math.min(c+1,f.length-1))),e.key==="ArrowUp"&&(e.preventDefault(),F(c=>Math.max(c-1,0)))},[j,L,f,ee]),re=s.useMemo(()=>d.length===0?null:l?d.map(e=>C.find(c=>c.value===e)?.label||e).join(", "):C.find(e=>e.value===d[0])?.label||d[0],[d,C,l]),Le=s.useCallback(e=>{e.stopPropagation(),b?.(l?[]:"")},[b,l]),Re=s.useMemo(()=>[{key:"Enter",description:w("shortcuts.select","Select")},{key:"Space",description:w("shortcuts.openDropdown","Open dropdown")},o.COMMON_SHORTCUTS.moveUp,o.COMMON_SHORTCUTS.moveDown,o.COMMON_SHORTCUTS.cancel],[w]);return je?null:t.jsxs("div",{className:`nice-field ${A==null?"nice-field--select-auto":""} nice-field--${U} ${ye==="left"?"nice-field--label-left":""} ${y?"nice-field--loading":""} ${ne||""}`,style:{...ie,...J!=null&&{"--nice-field-label-width":typeof J=="number"?`${J}px`:J},...A!=null&&{"--nice-field-control-width":typeof A=="number"?`${A}px`:A},...y&&he!=null&&{"--nice-select-locked-width":`${he}px`}},"aria-busy":y||void 0,children:[p&&t.jsxs("label",{htmlFor:$,className:`nice-field__label ${K?"nice-field__label--required":""}`,children:[p,ge&&t.jsx(o.NiceKeyboardHint,{shortcuts:Re,size:"sm"})]}),t.jsxs("div",{className:"nice-field__control",children:[de.isDisplay?t.jsx(o.DisplayModeView,{value:re,placeholder:_||w("controls.select","Select..."),disabled:x,onActivate:()=>{de.enterEdit(),E(!0)},ariaLabel:p}):t.jsxs("div",{className:"nice-select",ref:fe,children:[t.jsxs("button",{ref:e=>{q.current=e,typeof Q=="function"?Q(e):Q&&(Q.current=e)},type:"button",id:$,role:"combobox","aria-expanded":j,"aria-haspopup":"listbox","aria-invalid":!!a,className:`nice-select__trigger nice-select__trigger--${U} nice-select--ds-${be} ${j?"nice-select__trigger--open":""} ${a?"nice-select__trigger--error":""} ${x?"nice-select__trigger--disabled":""}`,style:{...Ne,...l&&!V&&H!=null?{width:H,maxWidth:H,overflow:"hidden"}:{}},disabled:x,onClick:()=>E(!j),onKeyDown:Ee,children:[re?t.jsx("span",{style:l&&!V?{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}:void 0,children:re}):t.jsx("span",{className:"nice-select__placeholder",children:_||w("controls.select","Select...")}),t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[v&&d.length>0&&t.jsx("span",{className:"nice-input__clear",onClick:Le,role:"button","aria-label":w("controls.clear","Clear"),children:t.jsx(o.NiceIcon,{name:"close",size:14})}),t.jsx("span",{className:`nice-select__chevron ${j?"nice-select__chevron--open":""}`,children:t.jsx(o.NiceIcon,{name:"chevron-down",size:16})})]})]}),j&&z&&me&&Te.createPortal(t.jsxs("div",{ref:$e,className:`nice-select__dropdown${Z?` ${Z}`:""}`,"data-theme":Z==="nice-dark"?"dark":Z==="nice-light"?"light":void 0,role:"listbox",style:{maxHeight:g,position:"fixed",left:z.left,top:z.top,width:z.width,minWidth:z.width,zIndex:1e3,opacity:pe?1:0,pointerEvents:pe?void 0:"none"},onScroll:k?e=>ke(e.currentTarget.scrollTop):void 0,children:[(S||I)&&t.jsx("div",{className:"nice-select__search",children:t.jsx("input",{type:"text",value:X,onChange:e=>{Y(e.target.value),F(0),I?.(e.target.value)},placeholder:w("controls.search","Search..."),autoFocus:!0})}),y&&t.jsx("div",{className:"nice-select__loading",children:t.jsx("div",{className:"nice-spinner nice-spinner--sm",style:{margin:"8px auto"}})}),!y&&f.length===0?t.jsx("div",{className:"nice-select__empty",children:m||w("controls.noResults","No results found")}):k&&!Array.from(xe.keys()).some(e=>e!=="")?(()=>{const c=f.length*u,n=Math.max(0,Math.floor(ue/u)-3),R=Math.min(f.length,Math.ceil((ue+g)/u)+3),te=f.slice(n,R);return t.jsx("div",{style:{height:c,position:"relative"},children:te.map((h,De)=>{const oe=n+De,se=d.includes(h.value);return t.jsx("div",{role:"option","aria-selected":se,className:`nice-select__option ${se?"nice-select__option--selected":""} ${oe===L?"nice-select__option--highlighted":""} ${h.disabled?"nice-select__option--disabled":""}`,style:{position:"absolute",top:oe*u,left:0,right:0,height:u,display:"flex",alignItems:"center",padding:"0 12px"},onClick:()=>!h.disabled&&ee(String(h.value)),onMouseEnter:()=>F(oe),children:P?P(h,se):t.jsxs(t.Fragment,{children:[h.icon&&t.jsx("span",{children:h.icon}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{children:h.label}),h.description&&t.jsx("div",{className:"nice-select__option-desc",children:h.description})]}),se&&t.jsx("svg",{className:"nice-select__option-check",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})})]})},h.value)})})})():Array.from(xe.entries()).map(([e,c])=>t.jsxs(s.Fragment,{children:[e&&t.jsx("div",{className:"nice-select__group-label",children:e}),c.map(n=>{const R=d.includes(n.value),te=f.indexOf(n);return t.jsx("div",{role:"option","aria-selected":R,className:`nice-select__option ${R?"nice-select__option--selected":""} ${te===L?"nice-select__option--highlighted":""} ${n.disabled?"nice-select__option--disabled":""}`,onClick:()=>!n.disabled&&ee(String(n.value)),onMouseEnter:()=>F(te),children:P?P(n,R):t.jsxs(t.Fragment,{children:[n.icon&&t.jsx("span",{children:n.icon}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{children:n.label}),n.description&&t.jsx("div",{className:"nice-select__option-desc",children:n.description})]}),R&&t.jsx("svg",{className:"nice-select__option-check",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})})]})},n.value)})]},e))]}),me)]}),y&&t.jsx("span",{className:"nice-field__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),G==="right"&&a&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:a}),G==="right"&&!a&&i&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:i})]}),G!=="right"&&a&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:a}),G!=="right"&&!a&&i&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:i})]})});ae.displayName="NiceSelect";const Oe=Object.freeze(Object.defineProperty({__proto__:null,NiceSelect:ae},Symbol.toStringTag,{value:"Module"}));exports.NiceSelect=ae;exports.NiceSelect$1=Oe;exports.scopeThemeClass=_e;exports.useAnchoredPopup=ve;
|