@nice2dev/ui 1.4.5 → 1.4.7

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/dist/{NiceDataGrid-mrnaLHQk.cjs → NiceDataGrid-D3qRQSjy.cjs} +1 -1
  3. package/dist/NiceForm-BWb4LTQJ.cjs +1 -0
  4. package/dist/{NiceHtmlEditor-C1OVtLQ6.cjs → NiceHtmlEditor-BzECmDO3.cjs} +1 -1
  5. package/dist/{NiceMention-tgJKS8PH.cjs → NiceMention-CYRqPKGU.cjs} +19 -19
  6. package/dist/NiceModuleLifecyclePanel-CiYbPcHV.cjs +1 -0
  7. package/dist/{NicePagination-D7XxeNFz.cjs → NicePagination-BAxwqeEd.cjs} +1 -1
  8. package/dist/{NicePivotGrid-Cnkr9WkC.cjs → NicePivotGrid-Cxu5PECg.cjs} +1 -1
  9. package/dist/{NiceSavedQueryPanel-U1-yaw-Q.cjs → NiceSavedQueryPanel-BSZhE-_l.cjs} +6 -6
  10. package/dist/{NiceScheduler-Boo-D1S-.cjs → NiceScheduler-BqYiHPvz.cjs} +1 -1
  11. package/dist/{core-lazy-C_qnVGxE.cjs → core-lazy-BQexApr7.cjs} +1 -1
  12. package/dist/data.cjs +1 -1
  13. package/dist/database/NiceDataSourceEditor.mjs +370 -0
  14. package/dist/database/NiceQueryDesigner.mjs +958 -0
  15. package/dist/database/moduleDataSource.mjs +151 -0
  16. package/dist/database/queryDesign.mjs +396 -0
  17. package/dist/database/queryDesignerPanels.mjs +1214 -0
  18. package/dist/database/querySql.mjs +481 -0
  19. package/dist/editors.cjs +1 -1
  20. package/dist/index.cjs +188 -181
  21. package/dist/index.d.ts +674 -0
  22. package/dist/index.mjs +774 -720
  23. package/dist/lazy.cjs +1 -1
  24. package/dist/navigation.cjs +1 -1
  25. package/dist/no-code/NiceNoCodeScriptEditor.mjs +584 -0
  26. package/dist/no-code/noCodeScript.mjs +326 -0
  27. package/dist/no-code-B1jzfUF5.cjs +331 -0
  28. package/dist/no-code.cjs +1 -1
  29. package/dist/no-code.d.ts +177 -0
  30. package/dist/no-code.mjs +26 -16
  31. package/dist/style.css +2 -2
  32. package/package.json +4 -4
  33. package/dist/NiceForm-O3sv-DNX.cjs +0 -1
  34. package/dist/NiceModuleLifecyclePanel-DKlqKPy2.cjs +0 -1
  35. package/dist/NiceSelect-BNPXs6FQ.cjs +0 -1
  36. package/dist/no-code-B3BHeyG-.cjs +0 -331
@@ -1,4 +1,4 @@
1
- "use strict";const t=require("react/jsx-runtime"),H=require("@nice2dev/ui-core"),D=require("react"),re=require("./NiceButton-DzCqkG5a.cjs"),Q=require("./NiceForm-O3sv-DNX.cjs"),Te=require("./devops-cgRBnZVX.cjs"),_t=require("./NiceColorPicker-BLwYNSXJ.cjs"),xt=require("./NiceModal-BRVzjuUN.cjs"),$e=({children:e,className:n,style:c,"data-testid":d,direction:a="horizontal",size:o,disabled:x,readOnly:_,loading:b,error:E,errorPlacement:w="bottom"})=>{const f=t.jsxs("div",{className:`nice-btn-group ${a==="vertical"?"nice-btn-group--vertical":""} ${b?"nice-btn-group--loading":""} ${_?"nice-btn-group--readonly":""} ${n||""}`,style:c,role:"group","data-testid":d,"aria-busy":b||void 0,children:[D.Children.map(e,s=>{if(!D.isValidElement(s))return s;const N={};return x&&(N.disabled=!0),_&&(N.disabled=!0),b&&(N.disabled=!0),o&&(N.size=o),D.cloneElement(s,N)}),b&&t.jsx("span",{className:"nice-btn-group__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]});if(!E)return f;const C=t.jsx("div",{className:"nice-field__error",role:"alert",children:E});return w==="right"?t.jsxs("span",{className:`nice-btn-field nice-btn-field--right ${o?`nice-field--${o}`:""}`,children:[f,C]}):t.jsxs("span",{className:`nice-btn-field nice-btn-field--bottom ${o?`nice-field--${o}`:""}`,children:[f,C]})},Ke=new Map;function Qe(e){if(!e)return"en";try{return Intl.DateTimeFormat.supportedLocalesOf(e).length>0?e:"en"}catch{return"en"}}function we(e,n){const c=Qe(e),d=`${c}|${JSON.stringify(n)}`;let a=Ke.get(d);return a||(a=new Intl.DateTimeFormat(c,n),Ke.set(d,a)),a}const Ze=(e,n)=>e.charAt(0).toLocaleUpperCase(Qe(n))+e.slice(1);function Z(e,n="short"){const c=we(e,{weekday:n});return Array.from({length:7},(d,a)=>Ze(c.format(new Date(2023,0,1+a)),e))}function Ee(e,n="long"){const c=we(e,{month:n});return Array.from({length:12},(d,a)=>Ze(c.format(new Date(2023,a,1)),e))}function se(e,n){return we(e,{year:"numeric",month:"2-digit",day:"2-digit"}).format(n)}function De(e,n){return we(e,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(n)}const L=(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();function Oe(e,n,c,d=1/0){const a=[],o=Math.max(1,Math.floor(e.interval??1)),x=e.until?new Date(e.until):void 0,_=x&&x<c?x:c,b=Math.min(e.count&&e.count>0?e.count:1/0,d),E=e.freq==="weekly"&&e.byDay?.length?[...new Set(e.byDay.filter(f=>Number.isInteger(f)&&f>=0&&f<=6))].sort((f,C)=>f-C):[];if(E.length>0){const f=new Date(n);f.setDate(n.getDate()-n.getDay());for(let C=0;a.length<b;C+=o){const s=new Date(f);if(s.setDate(f.getDate()+C*7),s>_)break;for(const N of E){const j=new Date(s);if(j.setDate(s.getDate()+N),!(j<n)){if(j>_||a.length>=b)break;a.push(j)}}}return a}let w=new Date(n);for(;w<=_&&a.length<b;){a.push(new Date(w));const f=new Date(w);e.freq==="daily"?f.setDate(f.getDate()+o):e.freq==="weekly"?f.setDate(f.getDate()+7*o):e.freq==="monthly"?f.setMonth(f.getMonth()+o):f.setFullYear(f.getFullYear()+o),w=f}return a}function Nt(e,n,c){const d=[];for(const a of e){if(!a.recurrence){d.push(a);continue}const o=new Date(a.end).getTime()-new Date(a.start).getTime();Oe(a.recurrence,new Date(a.start),c).forEach((x,_)=>{const b=new Date(x.getTime()+o);b>=n&&d.push({...a,id:`${a.id}_${_}`,start:x,end:b})})}return d}function et(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 tt(e="r"){return`${e}_${Math.random().toString(36).slice(2,9)}`}function nt(e={}){return{id:e.id??tt(),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 st(e){const n=(e.prepMinutes??0)+(e.cookMinutes??0);return n>0?n:void 0}const pe=({ev:e,renderEvent:n,onClick:c,draggable:d,dragRef:a,onHover:o,categoryColor:x})=>{const _=x||e.color||"var(--nice-color-primary, #3b82f6)",E={solid:{backgroundColor:_,color:"var(--nice-color-white, #fff)"},striped:{background:`repeating-linear-gradient(45deg, ${_}, ${_} 4px, transparent 4px, transparent 8px)`,border:`1px solid ${_}`,color:"var(--nice-text-primary, #333)"},outlined:{backgroundColor:"transparent",border:`2px solid ${_}`,color:_},dashed:{backgroundColor:"transparent",border:`2px dashed ${_}`,color:_}}[e.eventStyle||"solid"];return t.jsx("div",{className:`nice-scheduler__event nice-scheduler__event--${e.eventStyle||"solid"}`,style:E,role:"button",tabIndex:0,"aria-label":e.title,draggable:d,onDragStart:()=>{a.current={event:e}},onDragEnd:()=>{a.current=null},onClick:w=>{w.stopPropagation(),c?.(e)},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),w.stopPropagation(),c?.(e))},onMouseEnter:w=>o(e,w.currentTarget.getBoundingClientRect()),onMouseLeave:()=>o(null),onFocus:w=>o(e,w.currentTarget.getBoundingClientRect()),onBlur:()=>o(null),children:n?n(e):e.title})};function ie(e,n){if(!(!e.category||!n))return n.find(c=>c.key===e.category)?.color}const Dt=({events:e,curDate:n,firstDayOfWeek:c,onSlotClick:d,onEventClick:a,draggable:o,dragRef:x,categories:_,renderEvent:b,onHoverEvent:E,readOnly:w})=>{const{lang:f}=H.useNiceTranslation(),C=Z(f,"short"),s=n.getFullYear(),N=n.getMonth(),j=new Date(s,N,1),l=new Date(s,N+1,0),k=(j.getDay()-c+7)%7,h=l.getDate(),m=[];for(let u=k-1;u>=0;u--)m.push({date:L(j,-u-1),isCurrentMonth:!1});for(let u=0;u<h;u++)m.push({date:new Date(s,N,u+1),isCurrentMonth:!0});let P=1;for(;m.length<42;)m.push({date:new Date(s,N+1,P++),isCurrentMonth:!1});return t.jsxs("div",{className:"nice-scheduler__month",children:[t.jsx("div",{className:"nice-scheduler__month-header",children:Array.from({length:7},(u,g)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:C[(c+g)%7]},g))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:m.map((u,g)=>{const R=et(e,u.date),p=B(u.date,new Date),S=u.date.getDay(),F=S===0||S===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${u.isCurrentMonth?"":"nice-scheduler__month-cell--other"} ${p?"nice-scheduler__month-cell--today":""} ${F?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!w&&d?.(u.date,L(u.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:u.date.getDate()}),R.slice(0,3).map(q=>t.jsx(pe,{ev:q,renderEvent:b,onClick:a,draggable:o&&!w,dragRef:x,onHover:E,categoryColor:ie(q,_)},q.id)),R.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",R.length-3]})]},g)})})]})},wt=({events:e,days:n,startHour:c,endHour:d,draggable:a,dragRef:o,onEventClick:x,onSlotClick:_,onEventDrop:b,categories:E,workHours:w,showCurrentTime:f,renderEvent:C,onHoverEvent:s,readOnly:N})=>{const{lang:j}=H.useNiceTranslation(),l=[];for(let p=c;p<d;p++)l.push(p);Z(j,"short");const k=Z(j,"long"),h=D.useRef(null),m=new Date,P=m.getHours()*60+m.getMinutes(),u=(d-c)*60,g=(P-c*60)/u*100,R=f&&P>=c*60&&P<d*60;return D.useEffect(()=>{const p=h.current;if(!p)return;const S=new Date,F=e.filter($=>n.some(Y=>B(Y,new Date($.start)))),q=F.filter($=>B(new Date($.start),S));let W;q.length>0?W=Math.min(...q.map($=>new Date($.start).getHours())):F.length>0?W=Math.min(...F.map($=>new Date($.start).getHours())):W=8,W=Math.max(c,Math.min(W,d-1));const i=W-c,y=p.children[i];if(y){const $=p.closest(".nice-scheduler__content")??p.closest(".nice-scheduler__timegrid");$&&($.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((p,S)=>{const F=p.getDay()===0||p.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(p,m)?"nice-scheduler__timegrid-day-header--today":""} ${F?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:k[p.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:p.getDate()})]},S)})]}),t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:h,style:{position:"relative"},children:[l.map(p=>{const S=w?p>=w[0]&&p<w[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${S?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${p.toString().padStart(2,"0")}:00`}),n.map((F,q)=>{const W=e.filter(i=>{const y=new Date(i.start);return B(y,F)&&y.getHours()===p});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:a&&!N?i=>i.preventDefault():void 0,onDrop:a&&!N?()=>{if(!o.current||!b)return;const i=o.current.event,y=new Date(i.end).getTime()-new Date(i.start).getTime(),$=new Date(F);$.setHours(p,0,0,0);const Y=new Date($.getTime()+y);b(i,$,Y),o.current=null}:void 0,onClick:()=>!N&&(()=>{const i=new Date(F);i.setHours(p);const y=new Date(i);y.setHours(p+1),_?.(i,y)})(),children:W.map(i=>t.jsx(pe,{ev:i,renderEvent:C,onClick:x,draggable:a&&!N,dragRef:o,onHover:s,categoryColor:ie(i,E)},i.id))},q)})]},p)}),R&&n.some(p=>B(p,m))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${g}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})]})},bt=({events:e,curDate:n,onEventClick:c,categories:d,t:a})=>{const o=[...e].filter(x=>new Date(x.start)>=new Date(n.getFullYear(),n.getMonth(),n.getDate())).sort((x,_)=>new Date(x.start).getTime()-new Date(_.start).getTime()).slice(0,50);return t.jsxs("div",{className:"nice-scheduler__agenda",children:[o.map(x=>t.jsx(jt,{ev:x,categories:d,onEventClick:c},x.id)),o.length===0&&t.jsx("div",{className:"nice-scheduler__agenda-empty",children:a("noEvents","No upcoming events")})]})},Je=({parts:e})=>t.jsx("div",{className:"nice-scheduler__agenda-meta",children:e.map(([n,c],d)=>t.jsxs(D.Fragment,{children:[d>0&&" · ",t.jsx(H.NiceIcon,{name:n,size:12,style:{verticalAlign:"-2px"}})," ",c]},n))}),rt=({ev:e})=>{if(e.eventType==="recipe"&&e.recipe){const n=st(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(Je,{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(Je,{parts:c})}return null},jt=({ev:e,categories:n,onEventClick:c})=>{const{t:d}=H.useNiceTranslation(),a=H.useAccessibleClick({onClick:()=>c?.(e)});return t.jsxs("div",{className:"nice-scheduler__agenda-item","aria-label":d("service.event","Event {title}").replace("{title}",String(e.title)),...a,children:[t.jsx("div",{className:"nice-scheduler__agenda-dot",style:{backgroundColor:ie(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:[De(Q.getDefaultLocale(),new Date(e.start))," –"," ",De(Q.getDefaultLocale(),new Date(e.end))]}),e.description&&t.jsx("div",{className:"nice-scheduler__agenda-desc",children:e.description}),t.jsx(rt,{ev:e})]}),e.category&&n&&t.jsx("span",{className:"nice-scheduler__agenda-badge",style:{backgroundColor:ie(e,n)||e.color},children:n.find(o=>o.key===e.category)?.label})]})},kt=({events:e,curDate:n,timelineDays:c,resources:d,draggable:a,dragRef:o,onEventClick:x,onSlotClick:_,onEventDrop:b,categories:E,renderEvent:w,onHoverEvent:f,readOnly:C})=>{const{lang:s}=H.useNiceTranslation(),N=Array.from({length:c},(k,h)=>L(n,h)),j=d??[{id:"__default",name:""}],l=Z(s,"short");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"}),N.map((k,h)=>t.jsxs("div",{className:`nice-scheduler__timeline-day ${B(k,new Date)?"nice-scheduler__timeline-day--today":""}`,children:[l[k.getDay()]," ",k.getDate()]},h))]}),t.jsx("div",{className:"nice-scheduler__timeline-body",children:j.map(k=>{const h=e.filter(m=>!d||m.resourceId===k.id);return t.jsxs("div",{className:"nice-scheduler__timeline-row",children:[t.jsx("div",{className:"nice-scheduler__timeline-res-label",children:k.name}),N.map((m,P)=>{const u=h.filter(g=>B(new Date(g.start),m));return t.jsx("div",{className:"nice-scheduler__timeline-cell",onDragOver:a&&!C?g=>g.preventDefault():void 0,onDrop:a&&!C?()=>{if(!o.current||!b)return;const g=o.current.event,R=new Date(g.end).getTime()-new Date(g.start).getTime(),p=new Date(m);p.setHours(new Date(g.start).getHours(),new Date(g.start).getMinutes()),b(g,p,new Date(p.getTime()+R),k.id),o.current=null}:void 0,onClick:()=>!C&&_?.(m,L(m,1),k.id),children:u.map(g=>t.jsx(pe,{ev:g,renderEvent:w,onClick:x,draggable:a&&!C,dragRef:o,onHover:f,categoryColor:ie(g,E)},g.id))},P)})]},k.id)})})]})},Xe=({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(o=>{const x=n.filter(b=>b.category===o.key).length,_=!c.has(o.key);return t.jsxs("button",{className:`nice-scheduler__legend-item ${_?"":"nice-scheduler__legend-item--hidden"}`,onClick:()=>d(o.key),children:[t.jsx("span",{className:"nice-scheduler__legend-dot",style:{backgroundColor:_?o.color:"var(--nice-border-color, #ccc)"}}),t.jsx("span",{className:"nice-scheduler__legend-label",children:o.label}),t.jsx("span",{className:"nice-scheduler__legend-count",children:x})]},o.key)})]}),Ct=({curDate:e,onDateSelect:n,firstDayOfWeek:c,t:d})=>{const{lang:a}=H.useNiceTranslation(),[o,x]=D.useState(e.getMonth()),[_,b]=D.useState(e.getFullYear()),E=new Date(_,o,1),w=new Date(_,o+1,0),f=(E.getDay()-c+7)%7,C=[];for(let h=f-1;h>=0;h--)C.push(L(E,-h-1));for(let h=0;h<w.getDate();h++)C.push(new Date(_,o,h+1));const s=7-C.length%7;if(s<7)for(let h=1;h<=s;h++)C.push(new Date(_,o+1,h));const N=()=>{o===0?(x(11),b(h=>h-1)):x(h=>h-1)},j=()=>{o===11?(x(0),b(h=>h+1)):x(h=>h+1)},l=Ee(a,"short"),k=Z(a,"short");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:N,"aria-label":d("scheduler.prevMonth","Previous month"),children:t.jsx(H.NiceIcon,{name:"chevron-left",size:"sm"})}),t.jsxs("span",{children:[l[o]," ",_]}),t.jsx("button",{type:"button",className:"nice-btn nice-btn--xs",onClick:j,"aria-label":d("scheduler.nextMonth","Next month"),children:t.jsx(H.NiceIcon,{name:"chevron-right",size:"sm"})})]}),t.jsxs("div",{className:"nice-scheduler__mini-cal-grid",children:[k.map((h,m)=>t.jsx("div",{className:"nice-scheduler__mini-cal-dayname",children:k[(c+m)%7].charAt(0)},m)),C.map((h,m)=>{const P=B(h,new Date),u=B(h,e),g=h.getMonth()!==o;return t.jsx("button",{className:`nice-scheduler__mini-cal-day ${P?"nice-scheduler__mini-cal-day--today":""} ${u?"nice-scheduler__mini-cal-day--selected":""} ${g?"nice-scheduler__mini-cal-day--other":""}`,onClick:()=>n(h),children:h.getDate()},m)})]})]})},St=({events:e,rangeStart:n,rangeEnd:c,startHour:d,endHour:a,draggable:o,dragRef:x,onEventClick:_,onSlotClick:b,onEventDrop:E,categories:w,workHours:f,showCurrentTime:C,renderEvent:s,onHoverEvent:N,readOnly:j})=>{const{lang:l}=H.useNiceTranslation(),k=[];let h=new Date(n);for(;h<=c;)k.push(new Date(h)),h=L(h,1);const m=[];for(let y=d;y<a;y++)m.push(y);const P=Z(l,"long"),u=D.useRef(null),g=D.useRef(null),R=D.useRef(null),p=new Date,S=p.getHours()*60+p.getMinutes(),F=(a-d)*60,q=(S-d*60)/F*100,W=C&&S>=d*60&&S<a*60;D.useEffect(()=>{const y=u.current;if(!y)return;const $=new Date,Y=e.filter(I=>k.some(M=>B(M,$)&&B(new Date(I.start),$)));let V=Y.length>0?Math.min(...Y.map(I=>new Date(I.start).getHours())):$.getHours();V=Math.max(d,Math.min(V,a-1));const K=y.children[V-d];if(K){const I=R.current??y.closest(".nice-scheduler__content")??y.closest(".nice-scheduler__timegrid");I&&(I.scrollTop=K.offsetTop-4)}},[]);const i=y=>{g.current&&(g.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:g,"aria-hidden":"true",children:t.jsxs("div",{className:"nice-scheduler__timegrid-header",children:[t.jsx("div",{className:"nice-scheduler__time-gutter"}),k.map((y,$)=>{const Y=y.getDay()===0||y.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(y,p)?"nice-scheduler__timegrid-day-header--today":""} ${Y?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:P[y.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:y.getDate()})]},$)})]})}),t.jsx("div",{className:"nice-scheduler__timegrid-body-scroll",ref:R,onScroll:i,children:t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:u,style:{position:"relative"},children:[m.map(y=>{const $=f?y>=f[0]&&y<f[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${$?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${y.toString().padStart(2,"0")}:00`}),k.map((Y,V)=>{const K=e.filter(I=>{const M=new Date(I.start);return B(M,Y)&&M.getHours()===y});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:o&&!j?I=>I.preventDefault():void 0,onDrop:o&&!j?()=>{if(!x.current||!E)return;const I=x.current.event,M=new Date(I.end).getTime()-new Date(I.start).getTime(),O=new Date(Y);O.setHours(y,0,0,0),E(I,O,new Date(O.getTime()+M)),x.current=null}:void 0,onClick:()=>!j&&(()=>{const I=new Date(Y);I.setHours(y);const M=new Date(I);M.setHours(y+1),b?.(I,M)})(),children:K.map(I=>t.jsx(pe,{ev:I,renderEvent:s,onClick:_,draggable:o&&!j,dragRef:x,onHover:N,categoryColor:ie(I,w)},I.id))},V)})]},y)}),W&&k.some(y=>B(y,p))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${q}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})})]})},Mt=({events:e,rangeStart:n,rangeEnd:c,firstDayOfWeek:d,onSlotClick:a,onEventClick:o,draggable:x,dragRef:_,categories:b,renderEvent:E,onHoverEvent:w,readOnly:f})=>{const{lang:C}=H.useNiceTranslation(),s=Z(C,"short");Z(C,"long");const N=[];let j=new Date(n);for(;j<=c;)N.push(new Date(j)),j=L(j,1);const l=(N[0].getDay()-d+7)%7,k=[];for(let m=l-1;m>=0;m--)k.push({date:L(N[0],-m-1),inRange:!1});N.forEach(m=>k.push({date:m,inRange:!0}));const h=7-k.length%7;if(h<7){const m=N[N.length-1];for(let P=1;P<=h;P++)k.push({date:L(m,P),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},(m,P)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:s[(d+P)%7]},P))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:k.map((m,P)=>{const u=et(e,m.date),g=B(m.date,new Date),R=m.date.getDay()===0||m.date.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${m.inRange?"":"nice-scheduler__month-cell--other"} ${g?"nice-scheduler__month-cell--today":""} ${R?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!f&&a?.(m.date,L(m.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:m.date.getDate()===1||P===0?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"nice-scheduler__month-monthname",children:Ee(C,"short")[m.date.getMonth()]})," ",m.date.getDate()]}):m.date.getDate()}),u.slice(0,3).map(p=>t.jsx(pe,{ev:p,renderEvent:E,onClick:o,draggable:x&&!f,dragRef:_,onHover:w,categoryColor:ie(p,b)},p.id)),u.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",u.length-3]})]},P)})})]})},Tt=({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(o=>o.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:[De(Q.getDefaultLocale(),new Date(e.start))," –"," ",De(Q.getDefaultLocale(),new Date(e.end))]}),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(rt,{ev:e})]})},$t=({event:e,slotStart:n,slotEnd:c,categories:d,resources:a,formFields:o,formFieldsByType:x,eventTypes:_,renderEditor:b,saving:E,onSave:w,onDelete:f,onClose:C,t:s})=>{const N=!!e,j=D.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(u=>[u.quantity,u.unit,u.name].filter(g=>g!==void 0&&g!=="").join(" ")).join(`
1
+ "use strict";const t=require("react/jsx-runtime"),H=require("@nice2dev/ui-core"),D=require("react"),re=require("./NiceButton-DzCqkG5a.cjs"),Q=require("./NiceForm-BWb4LTQJ.cjs"),Te=require("./devops-cgRBnZVX.cjs"),_t=require("./NiceColorPicker-BLwYNSXJ.cjs"),xt=require("./NiceModal-BRVzjuUN.cjs"),$e=({children:e,className:n,style:c,"data-testid":d,direction:a="horizontal",size:o,disabled:x,readOnly:_,loading:b,error:E,errorPlacement:w="bottom"})=>{const f=t.jsxs("div",{className:`nice-btn-group ${a==="vertical"?"nice-btn-group--vertical":""} ${b?"nice-btn-group--loading":""} ${_?"nice-btn-group--readonly":""} ${n||""}`,style:c,role:"group","data-testid":d,"aria-busy":b||void 0,children:[D.Children.map(e,s=>{if(!D.isValidElement(s))return s;const N={};return x&&(N.disabled=!0),_&&(N.disabled=!0),b&&(N.disabled=!0),o&&(N.size=o),D.cloneElement(s,N)}),b&&t.jsx("span",{className:"nice-btn-group__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]});if(!E)return f;const C=t.jsx("div",{className:"nice-field__error",role:"alert",children:E});return w==="right"?t.jsxs("span",{className:`nice-btn-field nice-btn-field--right ${o?`nice-field--${o}`:""}`,children:[f,C]}):t.jsxs("span",{className:`nice-btn-field nice-btn-field--bottom ${o?`nice-field--${o}`:""}`,children:[f,C]})},Ke=new Map;function Qe(e){if(!e)return"en";try{return Intl.DateTimeFormat.supportedLocalesOf(e).length>0?e:"en"}catch{return"en"}}function we(e,n){const c=Qe(e),d=`${c}|${JSON.stringify(n)}`;let a=Ke.get(d);return a||(a=new Intl.DateTimeFormat(c,n),Ke.set(d,a)),a}const Ze=(e,n)=>e.charAt(0).toLocaleUpperCase(Qe(n))+e.slice(1);function Z(e,n="short"){const c=we(e,{weekday:n});return Array.from({length:7},(d,a)=>Ze(c.format(new Date(2023,0,1+a)),e))}function Ee(e,n="long"){const c=we(e,{month:n});return Array.from({length:12},(d,a)=>Ze(c.format(new Date(2023,a,1)),e))}function se(e,n){return we(e,{year:"numeric",month:"2-digit",day:"2-digit"}).format(n)}function De(e,n){return we(e,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(n)}const L=(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();function Oe(e,n,c,d=1/0){const a=[],o=Math.max(1,Math.floor(e.interval??1)),x=e.until?new Date(e.until):void 0,_=x&&x<c?x:c,b=Math.min(e.count&&e.count>0?e.count:1/0,d),E=e.freq==="weekly"&&e.byDay?.length?[...new Set(e.byDay.filter(f=>Number.isInteger(f)&&f>=0&&f<=6))].sort((f,C)=>f-C):[];if(E.length>0){const f=new Date(n);f.setDate(n.getDate()-n.getDay());for(let C=0;a.length<b;C+=o){const s=new Date(f);if(s.setDate(f.getDate()+C*7),s>_)break;for(const N of E){const j=new Date(s);if(j.setDate(s.getDate()+N),!(j<n)){if(j>_||a.length>=b)break;a.push(j)}}}return a}let w=new Date(n);for(;w<=_&&a.length<b;){a.push(new Date(w));const f=new Date(w);e.freq==="daily"?f.setDate(f.getDate()+o):e.freq==="weekly"?f.setDate(f.getDate()+7*o):e.freq==="monthly"?f.setMonth(f.getMonth()+o):f.setFullYear(f.getFullYear()+o),w=f}return a}function Nt(e,n,c){const d=[];for(const a of e){if(!a.recurrence){d.push(a);continue}const o=new Date(a.end).getTime()-new Date(a.start).getTime();Oe(a.recurrence,new Date(a.start),c).forEach((x,_)=>{const b=new Date(x.getTime()+o);b>=n&&d.push({...a,id:`${a.id}_${_}`,start:x,end:b})})}return d}function et(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 tt(e="r"){return`${e}_${Math.random().toString(36).slice(2,9)}`}function nt(e={}){return{id:e.id??tt(),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 st(e){const n=(e.prepMinutes??0)+(e.cookMinutes??0);return n>0?n:void 0}const pe=({ev:e,renderEvent:n,onClick:c,draggable:d,dragRef:a,onHover:o,categoryColor:x})=>{const _=x||e.color||"var(--nice-color-primary, #3b82f6)",E={solid:{backgroundColor:_,color:"var(--nice-color-white, #fff)"},striped:{background:`repeating-linear-gradient(45deg, ${_}, ${_} 4px, transparent 4px, transparent 8px)`,border:`1px solid ${_}`,color:"var(--nice-text-primary, #333)"},outlined:{backgroundColor:"transparent",border:`2px solid ${_}`,color:_},dashed:{backgroundColor:"transparent",border:`2px dashed ${_}`,color:_}}[e.eventStyle||"solid"];return t.jsx("div",{className:`nice-scheduler__event nice-scheduler__event--${e.eventStyle||"solid"}`,style:E,role:"button",tabIndex:0,"aria-label":e.title,draggable:d,onDragStart:()=>{a.current={event:e}},onDragEnd:()=>{a.current=null},onClick:w=>{w.stopPropagation(),c?.(e)},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),w.stopPropagation(),c?.(e))},onMouseEnter:w=>o(e,w.currentTarget.getBoundingClientRect()),onMouseLeave:()=>o(null),onFocus:w=>o(e,w.currentTarget.getBoundingClientRect()),onBlur:()=>o(null),children:n?n(e):e.title})};function ie(e,n){if(!(!e.category||!n))return n.find(c=>c.key===e.category)?.color}const Dt=({events:e,curDate:n,firstDayOfWeek:c,onSlotClick:d,onEventClick:a,draggable:o,dragRef:x,categories:_,renderEvent:b,onHoverEvent:E,readOnly:w})=>{const{lang:f}=H.useNiceTranslation(),C=Z(f,"short"),s=n.getFullYear(),N=n.getMonth(),j=new Date(s,N,1),l=new Date(s,N+1,0),k=(j.getDay()-c+7)%7,h=l.getDate(),m=[];for(let u=k-1;u>=0;u--)m.push({date:L(j,-u-1),isCurrentMonth:!1});for(let u=0;u<h;u++)m.push({date:new Date(s,N,u+1),isCurrentMonth:!0});let P=1;for(;m.length<42;)m.push({date:new Date(s,N+1,P++),isCurrentMonth:!1});return t.jsxs("div",{className:"nice-scheduler__month",children:[t.jsx("div",{className:"nice-scheduler__month-header",children:Array.from({length:7},(u,g)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:C[(c+g)%7]},g))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:m.map((u,g)=>{const R=et(e,u.date),p=B(u.date,new Date),S=u.date.getDay(),F=S===0||S===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${u.isCurrentMonth?"":"nice-scheduler__month-cell--other"} ${p?"nice-scheduler__month-cell--today":""} ${F?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!w&&d?.(u.date,L(u.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:u.date.getDate()}),R.slice(0,3).map(q=>t.jsx(pe,{ev:q,renderEvent:b,onClick:a,draggable:o&&!w,dragRef:x,onHover:E,categoryColor:ie(q,_)},q.id)),R.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",R.length-3]})]},g)})})]})},wt=({events:e,days:n,startHour:c,endHour:d,draggable:a,dragRef:o,onEventClick:x,onSlotClick:_,onEventDrop:b,categories:E,workHours:w,showCurrentTime:f,renderEvent:C,onHoverEvent:s,readOnly:N})=>{const{lang:j}=H.useNiceTranslation(),l=[];for(let p=c;p<d;p++)l.push(p);Z(j,"short");const k=Z(j,"long"),h=D.useRef(null),m=new Date,P=m.getHours()*60+m.getMinutes(),u=(d-c)*60,g=(P-c*60)/u*100,R=f&&P>=c*60&&P<d*60;return D.useEffect(()=>{const p=h.current;if(!p)return;const S=new Date,F=e.filter($=>n.some(Y=>B(Y,new Date($.start)))),q=F.filter($=>B(new Date($.start),S));let W;q.length>0?W=Math.min(...q.map($=>new Date($.start).getHours())):F.length>0?W=Math.min(...F.map($=>new Date($.start).getHours())):W=8,W=Math.max(c,Math.min(W,d-1));const i=W-c,y=p.children[i];if(y){const $=p.closest(".nice-scheduler__content")??p.closest(".nice-scheduler__timegrid");$&&($.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((p,S)=>{const F=p.getDay()===0||p.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(p,m)?"nice-scheduler__timegrid-day-header--today":""} ${F?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:k[p.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:p.getDate()})]},S)})]}),t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:h,style:{position:"relative"},children:[l.map(p=>{const S=w?p>=w[0]&&p<w[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${S?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${p.toString().padStart(2,"0")}:00`}),n.map((F,q)=>{const W=e.filter(i=>{const y=new Date(i.start);return B(y,F)&&y.getHours()===p});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:a&&!N?i=>i.preventDefault():void 0,onDrop:a&&!N?()=>{if(!o.current||!b)return;const i=o.current.event,y=new Date(i.end).getTime()-new Date(i.start).getTime(),$=new Date(F);$.setHours(p,0,0,0);const Y=new Date($.getTime()+y);b(i,$,Y),o.current=null}:void 0,onClick:()=>!N&&(()=>{const i=new Date(F);i.setHours(p);const y=new Date(i);y.setHours(p+1),_?.(i,y)})(),children:W.map(i=>t.jsx(pe,{ev:i,renderEvent:C,onClick:x,draggable:a&&!N,dragRef:o,onHover:s,categoryColor:ie(i,E)},i.id))},q)})]},p)}),R&&n.some(p=>B(p,m))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${g}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})]})},bt=({events:e,curDate:n,onEventClick:c,categories:d,t:a})=>{const o=[...e].filter(x=>new Date(x.start)>=new Date(n.getFullYear(),n.getMonth(),n.getDate())).sort((x,_)=>new Date(x.start).getTime()-new Date(_.start).getTime()).slice(0,50);return t.jsxs("div",{className:"nice-scheduler__agenda",children:[o.map(x=>t.jsx(jt,{ev:x,categories:d,onEventClick:c},x.id)),o.length===0&&t.jsx("div",{className:"nice-scheduler__agenda-empty",children:a("noEvents","No upcoming events")})]})},Je=({parts:e})=>t.jsx("div",{className:"nice-scheduler__agenda-meta",children:e.map(([n,c],d)=>t.jsxs(D.Fragment,{children:[d>0&&" · ",t.jsx(H.NiceIcon,{name:n,size:12,style:{verticalAlign:"-2px"}})," ",c]},n))}),rt=({ev:e})=>{if(e.eventType==="recipe"&&e.recipe){const n=st(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(Je,{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(Je,{parts:c})}return null},jt=({ev:e,categories:n,onEventClick:c})=>{const{t:d}=H.useNiceTranslation(),a=H.useAccessibleClick({onClick:()=>c?.(e)});return t.jsxs("div",{className:"nice-scheduler__agenda-item","aria-label":d("service.event","Event {title}").replace("{title}",String(e.title)),...a,children:[t.jsx("div",{className:"nice-scheduler__agenda-dot",style:{backgroundColor:ie(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:[De(Q.getDefaultLocale(),new Date(e.start))," –"," ",De(Q.getDefaultLocale(),new Date(e.end))]}),e.description&&t.jsx("div",{className:"nice-scheduler__agenda-desc",children:e.description}),t.jsx(rt,{ev:e})]}),e.category&&n&&t.jsx("span",{className:"nice-scheduler__agenda-badge",style:{backgroundColor:ie(e,n)||e.color},children:n.find(o=>o.key===e.category)?.label})]})},kt=({events:e,curDate:n,timelineDays:c,resources:d,draggable:a,dragRef:o,onEventClick:x,onSlotClick:_,onEventDrop:b,categories:E,renderEvent:w,onHoverEvent:f,readOnly:C})=>{const{lang:s}=H.useNiceTranslation(),N=Array.from({length:c},(k,h)=>L(n,h)),j=d??[{id:"__default",name:""}],l=Z(s,"short");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"}),N.map((k,h)=>t.jsxs("div",{className:`nice-scheduler__timeline-day ${B(k,new Date)?"nice-scheduler__timeline-day--today":""}`,children:[l[k.getDay()]," ",k.getDate()]},h))]}),t.jsx("div",{className:"nice-scheduler__timeline-body",children:j.map(k=>{const h=e.filter(m=>!d||m.resourceId===k.id);return t.jsxs("div",{className:"nice-scheduler__timeline-row",children:[t.jsx("div",{className:"nice-scheduler__timeline-res-label",children:k.name}),N.map((m,P)=>{const u=h.filter(g=>B(new Date(g.start),m));return t.jsx("div",{className:"nice-scheduler__timeline-cell",onDragOver:a&&!C?g=>g.preventDefault():void 0,onDrop:a&&!C?()=>{if(!o.current||!b)return;const g=o.current.event,R=new Date(g.end).getTime()-new Date(g.start).getTime(),p=new Date(m);p.setHours(new Date(g.start).getHours(),new Date(g.start).getMinutes()),b(g,p,new Date(p.getTime()+R),k.id),o.current=null}:void 0,onClick:()=>!C&&_?.(m,L(m,1),k.id),children:u.map(g=>t.jsx(pe,{ev:g,renderEvent:w,onClick:x,draggable:a&&!C,dragRef:o,onHover:f,categoryColor:ie(g,E)},g.id))},P)})]},k.id)})})]})},Xe=({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(o=>{const x=n.filter(b=>b.category===o.key).length,_=!c.has(o.key);return t.jsxs("button",{className:`nice-scheduler__legend-item ${_?"":"nice-scheduler__legend-item--hidden"}`,onClick:()=>d(o.key),children:[t.jsx("span",{className:"nice-scheduler__legend-dot",style:{backgroundColor:_?o.color:"var(--nice-border-color, #ccc)"}}),t.jsx("span",{className:"nice-scheduler__legend-label",children:o.label}),t.jsx("span",{className:"nice-scheduler__legend-count",children:x})]},o.key)})]}),Ct=({curDate:e,onDateSelect:n,firstDayOfWeek:c,t:d})=>{const{lang:a}=H.useNiceTranslation(),[o,x]=D.useState(e.getMonth()),[_,b]=D.useState(e.getFullYear()),E=new Date(_,o,1),w=new Date(_,o+1,0),f=(E.getDay()-c+7)%7,C=[];for(let h=f-1;h>=0;h--)C.push(L(E,-h-1));for(let h=0;h<w.getDate();h++)C.push(new Date(_,o,h+1));const s=7-C.length%7;if(s<7)for(let h=1;h<=s;h++)C.push(new Date(_,o+1,h));const N=()=>{o===0?(x(11),b(h=>h-1)):x(h=>h-1)},j=()=>{o===11?(x(0),b(h=>h+1)):x(h=>h+1)},l=Ee(a,"short"),k=Z(a,"short");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:N,"aria-label":d("scheduler.prevMonth","Previous month"),children:t.jsx(H.NiceIcon,{name:"chevron-left",size:"sm"})}),t.jsxs("span",{children:[l[o]," ",_]}),t.jsx("button",{type:"button",className:"nice-btn nice-btn--xs",onClick:j,"aria-label":d("scheduler.nextMonth","Next month"),children:t.jsx(H.NiceIcon,{name:"chevron-right",size:"sm"})})]}),t.jsxs("div",{className:"nice-scheduler__mini-cal-grid",children:[k.map((h,m)=>t.jsx("div",{className:"nice-scheduler__mini-cal-dayname",children:k[(c+m)%7].charAt(0)},m)),C.map((h,m)=>{const P=B(h,new Date),u=B(h,e),g=h.getMonth()!==o;return t.jsx("button",{className:`nice-scheduler__mini-cal-day ${P?"nice-scheduler__mini-cal-day--today":""} ${u?"nice-scheduler__mini-cal-day--selected":""} ${g?"nice-scheduler__mini-cal-day--other":""}`,onClick:()=>n(h),children:h.getDate()},m)})]})]})},St=({events:e,rangeStart:n,rangeEnd:c,startHour:d,endHour:a,draggable:o,dragRef:x,onEventClick:_,onSlotClick:b,onEventDrop:E,categories:w,workHours:f,showCurrentTime:C,renderEvent:s,onHoverEvent:N,readOnly:j})=>{const{lang:l}=H.useNiceTranslation(),k=[];let h=new Date(n);for(;h<=c;)k.push(new Date(h)),h=L(h,1);const m=[];for(let y=d;y<a;y++)m.push(y);const P=Z(l,"long"),u=D.useRef(null),g=D.useRef(null),R=D.useRef(null),p=new Date,S=p.getHours()*60+p.getMinutes(),F=(a-d)*60,q=(S-d*60)/F*100,W=C&&S>=d*60&&S<a*60;D.useEffect(()=>{const y=u.current;if(!y)return;const $=new Date,Y=e.filter(I=>k.some(M=>B(M,$)&&B(new Date(I.start),$)));let V=Y.length>0?Math.min(...Y.map(I=>new Date(I.start).getHours())):$.getHours();V=Math.max(d,Math.min(V,a-1));const K=y.children[V-d];if(K){const I=R.current??y.closest(".nice-scheduler__content")??y.closest(".nice-scheduler__timegrid");I&&(I.scrollTop=K.offsetTop-4)}},[]);const i=y=>{g.current&&(g.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:g,"aria-hidden":"true",children:t.jsxs("div",{className:"nice-scheduler__timegrid-header",children:[t.jsx("div",{className:"nice-scheduler__time-gutter"}),k.map((y,$)=>{const Y=y.getDay()===0||y.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__timegrid-day-header ${B(y,p)?"nice-scheduler__timegrid-day-header--today":""} ${Y?"nice-scheduler__timegrid-day-header--weekend":""}`,children:[t.jsx("div",{className:"nice-scheduler__timegrid-day-name",children:P[y.getDay()]}),t.jsx("div",{className:"nice-scheduler__timegrid-day-num",children:y.getDate()})]},$)})]})}),t.jsx("div",{className:"nice-scheduler__timegrid-body-scroll",ref:R,onScroll:i,children:t.jsxs("div",{className:"nice-scheduler__timegrid-body",ref:u,style:{position:"relative"},children:[m.map(y=>{const $=f?y>=f[0]&&y<f[1]:!1;return t.jsxs("div",{className:`nice-scheduler__timegrid-row ${$?"nice-scheduler__timegrid-row--work":""}`,children:[t.jsx("div",{className:"nice-scheduler__time-gutter",children:`${y.toString().padStart(2,"0")}:00`}),k.map((Y,V)=>{const K=e.filter(I=>{const M=new Date(I.start);return B(M,Y)&&M.getHours()===y});return t.jsx("div",{className:"nice-scheduler__timegrid-cell",onDragOver:o&&!j?I=>I.preventDefault():void 0,onDrop:o&&!j?()=>{if(!x.current||!E)return;const I=x.current.event,M=new Date(I.end).getTime()-new Date(I.start).getTime(),O=new Date(Y);O.setHours(y,0,0,0),E(I,O,new Date(O.getTime()+M)),x.current=null}:void 0,onClick:()=>!j&&(()=>{const I=new Date(Y);I.setHours(y);const M=new Date(I);M.setHours(y+1),b?.(I,M)})(),children:K.map(I=>t.jsx(pe,{ev:I,renderEvent:s,onClick:_,draggable:o&&!j,dragRef:x,onHover:N,categoryColor:ie(I,w)},I.id))},V)})]},y)}),W&&k.some(y=>B(y,p))&&t.jsx("div",{className:"nice-scheduler__now-line",style:{top:`${q}%`},children:t.jsx("div",{className:"nice-scheduler__now-dot"})})]})})]})},Mt=({events:e,rangeStart:n,rangeEnd:c,firstDayOfWeek:d,onSlotClick:a,onEventClick:o,draggable:x,dragRef:_,categories:b,renderEvent:E,onHoverEvent:w,readOnly:f})=>{const{lang:C}=H.useNiceTranslation(),s=Z(C,"short");Z(C,"long");const N=[];let j=new Date(n);for(;j<=c;)N.push(new Date(j)),j=L(j,1);const l=(N[0].getDay()-d+7)%7,k=[];for(let m=l-1;m>=0;m--)k.push({date:L(N[0],-m-1),inRange:!1});N.forEach(m=>k.push({date:m,inRange:!0}));const h=7-k.length%7;if(h<7){const m=N[N.length-1];for(let P=1;P<=h;P++)k.push({date:L(m,P),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},(m,P)=>t.jsx("div",{className:"nice-scheduler__month-dayname",children:s[(d+P)%7]},P))}),t.jsx("div",{className:"nice-scheduler__month-grid",children:k.map((m,P)=>{const u=et(e,m.date),g=B(m.date,new Date),R=m.date.getDay()===0||m.date.getDay()===6;return t.jsxs("div",{className:`nice-scheduler__month-cell ${m.inRange?"":"nice-scheduler__month-cell--other"} ${g?"nice-scheduler__month-cell--today":""} ${R?"nice-scheduler__month-cell--weekend":""}`,onClick:()=>!f&&a?.(m.date,L(m.date,1)),children:[t.jsx("div",{className:"nice-scheduler__month-date",children:m.date.getDate()===1||P===0?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"nice-scheduler__month-monthname",children:Ee(C,"short")[m.date.getMonth()]})," ",m.date.getDate()]}):m.date.getDate()}),u.slice(0,3).map(p=>t.jsx(pe,{ev:p,renderEvent:E,onClick:o,draggable:x&&!f,dragRef:_,onHover:w,categoryColor:ie(p,b)},p.id)),u.length>3&&t.jsxs("div",{className:"nice-scheduler__month-more",children:["+",u.length-3]})]},P)})})]})},Tt=({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(o=>o.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:[De(Q.getDefaultLocale(),new Date(e.start))," –"," ",De(Q.getDefaultLocale(),new Date(e.end))]}),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(rt,{ev:e})]})},$t=({event:e,slotStart:n,slotEnd:c,categories:d,resources:a,formFields:o,formFieldsByType:x,eventTypes:_,renderEditor:b,saving:E,onSave:w,onDelete:f,onClose:C,t:s})=>{const N=!!e,j=D.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(u=>[u.quantity,u.unit,u.name].filter(g=>g!==void 0&&g!=="").join(" ")).join(`
2
2
  `),recipeSteps:(e?.recipe?.steps??[]).map(u=>u.instruction).join(`
3
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]),[l,k]=D.useState(j);D.useEffect(()=>{k(j)},[j]);const h=D.useCallback((u,g)=>{k(R=>({...R,[u]:g}))},[]),m=D.useMemo(()=>{if(o&&o.length>0)return o;const u=i=>i.toString().padStart(2,"0"),g=i=>`${i.getFullYear()}-${u(i.getMonth()+1)}-${u(i.getDate())}`,R=i=>`${u(i.getHours())}:${u(i.getMinutes())}`,p=(i,y)=>{const $=i instanceof Date?i:new Date(i),Y=isNaN($.getTime())?new Date:$,V=g(Y),K=R(Y),I=(M,O)=>{const[fe,X,U]=M.split("-").map(de=>parseInt(de,10)),[ye,ve]=O.split(":").map(de=>parseInt(de,10)),le=new Date(Y);!isNaN(fe)&&!isNaN(X)&&!isNaN(U)&&le.setFullYear(fe,X-1,U),!isNaN(ye)&&!isNaN(ve)&&le.setHours(ye,ve,0,0),y(le)};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(Q.NiceDateTimePicker,{dateFormatPreset:"date-local",value:V,onChange:M=>I(M,K),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(Q.NiceDateTimePicker,{dateFormatPreset:"time",value:K,onChange:M=>I(V,M),size:"sm"})]})]})},S=[];_&&_.length>1&&S.push({field:"eventType",label:s("eventType","Type"),type:"select",group:s("common","Common"),options:_.map(i=>({label:i.icon?`${i.icon} ${i.label}`:i.label,value:i.type}))}),S.push({field:"title",label:s("title","Title"),type:"text",required:!0,group:s("common","Common")},{field:"start",label:s("start","Start"),render:p,group:s("common","Common")},{field:"end",label:s("end","End"),render:p,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(_t.NiceColorPicker,{value:typeof i=="string"?i:"var(--nice-primary, #3b82f6)",onChange:y,showInput:!1,showRandom:!1})}),d&&d.length>0&&S.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&&S.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 F=s("recurring","Recurring");S.push({field:"recurring",label:s("repeat","Repeat"),type:"checkbox",group:F}),S.push({field:"recurrenceFreq",label:s("frequency","Frequency"),type:"select",group:F,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"}]}),S.push({field:"recurrenceInterval",label:s("interval","Interval"),type:"number",group:F,visibleWhen:i=>!!i.recurring}),S.push({field:"recurrenceCount",label:s("occurrences","Occurrences (optional)"),type:"number",group:F,visibleWhen:i=>!!i.recurring});const q=l.eventType??"task",W=x?.[q];if(W&&W.length>0)S.push(...W);else if(q==="recipe"){const i=s("recipe.section","Recipe");S.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(q==="service"){const i=s("service.section","Service");S.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 S},[o,x,_,d,a,l.eventType,s]),P=()=>{const u=l.eventType??"task",g={title:l.title,description:l.description||void 0,color:l.color,category:l.category||void 0,eventStyle:l.eventStyle,allDay:l.allDay,start:l.start instanceof Date?l.start:new Date(l.start),end:l.end instanceof Date?l.end:new Date(l.end),resourceId:l.resourceId||void 0,eventType:u};if(l.recurring){const R={freq:l.recurrenceFreq||"weekly",interval:typeof l.recurrenceInterval=="number"&&l.recurrenceInterval>0?l.recurrenceInterval:1};typeof l.recurrenceCount=="number"&&l.recurrenceCount>0&&(R.count=l.recurrenceCount),g.recurrence=R}else g.recurrence=void 0;if(u==="recipe"){const R=String(l.recipeIngredients||"").split(`
4
4
  `).map(q=>q.trim()).filter(Boolean).map((q,W)=>{const i=q.match(/^([\d.,/]+)\s*(\S+)?\s+(.+)$/);if(i){const y=parseFloat(i[1].replace(",","."));return{id:`ing-${W}`,name:i[3],quantity:isNaN(y)?void 0:y,unit:i[2]}}return{id:`ing-${W}`,name:q}}),p=String(l.recipeSteps||"").split(`
@@ -1 +1 @@
1
- "use strict";const r=require("react/jsx-runtime"),C=require("@nice2dev/ui-core"),o=require("react"),f=({height:e=200})=>r.jsx("div",{className:"ntd-lazy-loading",style:{display:"flex",alignItems:"center",justifyContent:"center",height:e,background:"var(--ntd-color-surface, #f5f5f5)",borderRadius:"var(--ntd-radius, 8px)",animation:"ntd-pulse 1.5s ease-in-out infinite"},children:r.jsx("div",{className:"ntd-lazy-loading-spinner",style:{width:24,height:24,border:"2px solid var(--ntd-color-border, #ddd)",borderTopColor:"var(--ntd-color-primary, #6366f1)",borderRadius:"50%",animation:"ntd-spin 0.8s linear infinite"}})}),L=(e,t)=>{const{t:a}=C.useNiceTranslation();return r.jsxs("div",{className:"ntd-lazy-error",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:24,background:"var(--ntd-color-error-bg, #fee2e2)",borderRadius:"var(--ntd-radius, 8px)",color:"var(--ntd-color-error, #dc2626)"},children:[r.jsx(C.NiceIcon,{name:"error",size:32}),r.jsx("p",{style:{margin:"12px 0 8px",fontWeight:500},children:a("lazy.failedToLoadComponent","Failed to load component")}),r.jsx("p",{style:{margin:0,fontSize:"0.875em",opacity:.8},children:e.message}),r.jsx("button",{onClick:t,style:{marginTop:16,padding:"8px 16px",border:"none",borderRadius:"var(--ntd-radius, 8px)",background:"var(--ntd-color-error, #dc2626)",color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:"0.875em"},children:a("lazy.retry","Retry")})]})};class D extends o.Component{constructor(){super(...arguments),this.state={error:null},this.handleRetry=()=>{this.setState({error:null})}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?this.props.fallback(this.state.error,this.handleRetry):this.props.children}}function i(e,t={}){const{fallback:a=r.jsx(f,{}),preloadOnMount:l=!1,preloadOnHover:p=!1,preloadAfterIdle:n,minLoadingTime:m=0,ssrFallback:c,errorFallback:S=L,displayName:P}=t;let b=null,h=!1;const y=async()=>{if(b)return b;const x=Date.now();b=e();const v=await b;if(m>0){const w=Date.now()-x;w<m&&await new Promise(u=>setTimeout(u,m-w))}return h=!0,v},I=o.lazy(y),q=x=>{const v=o.useRef(null);return o.useEffect(()=>{l&&!h&&y()},[]),o.useEffect(()=>{if(n&&!h){const u="requestIdleCallback"in window?window.requestIdleCallback(()=>y(),{timeout:n}):setTimeout(()=>y(),n);return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(u):clearTimeout(u)}}},[]),o.useEffect(()=>{if(!p||h)return;const u=v.current;if(!u)return;const N=()=>{h||y()};return u.addEventListener("mouseenter",N,{once:!0}),()=>u.removeEventListener("mouseenter",N)},[]),typeof window>"u"&&c?r.jsx(r.Fragment,{children:c}):r.jsx("div",{ref:v,className:"ntd-lazy-wrapper",children:r.jsx(D,{fallback:S,children:r.jsx(o.Suspense,{fallback:a,children:r.jsx(I,{...x})})})})},R=async()=>{h||await y()},k=q;return k.preload=R,k.displayName=P||"LazyComponent",k}function G(e=.1,t="100px"){const a=o.useRef(null),[l,p]=o.useState(!1);return o.useEffect(()=>{if(!a.current||l)return;const n=new IntersectionObserver(([m])=>{m.isIntersecting&&(p(!0),n.disconnect())},{threshold:e,rootMargin:t});return n.observe(a.current),()=>n.disconnect()},[e,t,l]),[a,l]}function V(e,t=2e3){o.useEffect(()=>{if("requestIdleCallback"in window){const a=window.requestIdleCallback(()=>{e.forEach(l=>l())},{timeout:t});return()=>window.cancelIdleCallback(a)}else{const a=setTimeout(()=>{e.forEach(l=>l())},t);return()=>clearTimeout(a)}},[])}function T(e,t){const a=o.useRef(new Set);o.useEffect(()=>{const l=document.querySelectorAll("a[href]"),p=n=>{const c=n.currentTarget.getAttribute("href");c&&e[c]&&!a.current.has(c)&&(e[c](),a.current.add(c))};return l.forEach(n=>{n.addEventListener("mouseenter",p)}),()=>{l.forEach(n=>{n.removeEventListener("mouseenter",p)})}},[t,e])}const z=()=>r.jsx(f,{height:400}),g=()=>r.jsx(f,{height:300}),j=()=>r.jsx(f,{height:500}),E=()=>r.jsx(f,{height:600}),d=e=>e,s={CodeEditor:i(d(()=>Promise.resolve().then(()=>require("./NiceCodeEditor-DhdjnDLV.cjs")).then(e=>({default:e.NiceCodeEditor}))),{fallback:r.jsx(z,{}),preloadOnHover:!0,displayName:"LazyCodeEditor"}),HtmlEditor:i(d(()=>Promise.resolve().then(()=>require("./NiceHtmlEditor-C1OVtLQ6.cjs")).then(e=>({default:e.NiceHtmlEditor}))),{fallback:r.jsx(z,{}),preloadOnHover:!0,displayName:"LazyHtmlEditor"}),DocumentViewer:i(d(()=>Promise.resolve().then(()=>require("./NiceDocumentViewer-CDXAmPp7.cjs")).then(e=>({default:e.NiceDocumentViewer}))),{fallback:r.jsx(f,{height:600}),displayName:"LazyDocumentViewer"}),Chart:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceChart$1).then(e=>({default:e.NiceChart}))),{fallback:r.jsx(g,{}),preloadAfterIdle:3e3,displayName:"LazyChart"}),VectorMap:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceVectorMap$1).then(e=>({default:e.NiceVectorMap}))),{fallback:r.jsx(f,{height:400}),displayName:"LazyVectorMap"}),Sankey:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceSankey$1).then(e=>({default:e.NiceSankey}))),{fallback:r.jsx(g,{}),displayName:"LazySankey"}),Scheduler:i(d(()=>Promise.resolve().then(()=>require("./NiceScheduler-Boo-D1S-.cjs")).then(e=>e.NiceScheduler$1).then(e=>({default:e.NiceScheduler}))),{fallback:r.jsx(E,{}),displayName:"LazyScheduler"}),Gantt:i(d(()=>Promise.resolve().then(()=>require("./NiceGantt-BygumlaY.cjs")).then(e=>({default:e.NiceGantt}))),{fallback:r.jsx(E,{}),displayName:"LazyGantt"}),PivotGrid:i(d(()=>Promise.resolve().then(()=>require("./NicePivotGrid-Cnkr9WkC.cjs")).then(e=>e.NicePivotGrid$1).then(e=>({default:e.NicePivotGrid}))),{fallback:r.jsx(j,{}),displayName:"LazyPivotGrid"}),DataGrid:i(d(()=>Promise.resolve().then(()=>require("./NiceDataGrid-mrnaLHQk.cjs")).then(e=>e.NiceDataGrid$1).then(e=>({default:e.NiceDataGrid}))),{fallback:r.jsx(j,{}),preloadAfterIdle:2e3,displayName:"LazyDataGrid"})};async function H(){await Promise.all([s.CodeEditor.preload(),s.HtmlEditor.preload(),s.DocumentViewer.preload(),s.Chart.preload(),s.VectorMap.preload(),s.Sankey.preload(),s.Scheduler.preload(),s.Gantt.preload(),s.PivotGrid.preload()])}async function O(e){await Promise.all(e.map(t=>s[t].preload()))}exports.DefaultErrorFallback=L;exports.DefaultLoadingFallback=f;exports.LazyComponents=s;exports.createLazyComponent=i;exports.preloadAllHeavyComponents=H;exports.preloadComponents=O;exports.useLazyOnVisible=G;exports.usePreloadOnIdle=V;exports.usePreloadOnRouteHint=T;
1
+ "use strict";const r=require("react/jsx-runtime"),C=require("@nice2dev/ui-core"),o=require("react"),f=({height:e=200})=>r.jsx("div",{className:"ntd-lazy-loading",style:{display:"flex",alignItems:"center",justifyContent:"center",height:e,background:"var(--ntd-color-surface, #f5f5f5)",borderRadius:"var(--ntd-radius, 8px)",animation:"ntd-pulse 1.5s ease-in-out infinite"},children:r.jsx("div",{className:"ntd-lazy-loading-spinner",style:{width:24,height:24,border:"2px solid var(--ntd-color-border, #ddd)",borderTopColor:"var(--ntd-color-primary, #6366f1)",borderRadius:"50%",animation:"ntd-spin 0.8s linear infinite"}})}),L=(e,t)=>{const{t:a}=C.useNiceTranslation();return r.jsxs("div",{className:"ntd-lazy-error",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:24,background:"var(--ntd-color-error-bg, #fee2e2)",borderRadius:"var(--ntd-radius, 8px)",color:"var(--ntd-color-error, #dc2626)"},children:[r.jsx(C.NiceIcon,{name:"error",size:32}),r.jsx("p",{style:{margin:"12px 0 8px",fontWeight:500},children:a("lazy.failedToLoadComponent","Failed to load component")}),r.jsx("p",{style:{margin:0,fontSize:"0.875em",opacity:.8},children:e.message}),r.jsx("button",{onClick:t,style:{marginTop:16,padding:"8px 16px",border:"none",borderRadius:"var(--ntd-radius, 8px)",background:"var(--ntd-color-error, #dc2626)",color:"var(--nice-color-white, #fff)",cursor:"pointer",fontSize:"0.875em"},children:a("lazy.retry","Retry")})]})};class D extends o.Component{constructor(){super(...arguments),this.state={error:null},this.handleRetry=()=>{this.setState({error:null})}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?this.props.fallback(this.state.error,this.handleRetry):this.props.children}}function i(e,t={}){const{fallback:a=r.jsx(f,{}),preloadOnMount:l=!1,preloadOnHover:p=!1,preloadAfterIdle:n,minLoadingTime:m=0,ssrFallback:c,errorFallback:S=L,displayName:P}=t;let b=null,h=!1;const y=async()=>{if(b)return b;const x=Date.now();b=e();const v=await b;if(m>0){const w=Date.now()-x;w<m&&await new Promise(u=>setTimeout(u,m-w))}return h=!0,v},I=o.lazy(y),q=x=>{const v=o.useRef(null);return o.useEffect(()=>{l&&!h&&y()},[]),o.useEffect(()=>{if(n&&!h){const u="requestIdleCallback"in window?window.requestIdleCallback(()=>y(),{timeout:n}):setTimeout(()=>y(),n);return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(u):clearTimeout(u)}}},[]),o.useEffect(()=>{if(!p||h)return;const u=v.current;if(!u)return;const N=()=>{h||y()};return u.addEventListener("mouseenter",N,{once:!0}),()=>u.removeEventListener("mouseenter",N)},[]),typeof window>"u"&&c?r.jsx(r.Fragment,{children:c}):r.jsx("div",{ref:v,className:"ntd-lazy-wrapper",children:r.jsx(D,{fallback:S,children:r.jsx(o.Suspense,{fallback:a,children:r.jsx(I,{...x})})})})},R=async()=>{h||await y()},k=q;return k.preload=R,k.displayName=P||"LazyComponent",k}function G(e=.1,t="100px"){const a=o.useRef(null),[l,p]=o.useState(!1);return o.useEffect(()=>{if(!a.current||l)return;const n=new IntersectionObserver(([m])=>{m.isIntersecting&&(p(!0),n.disconnect())},{threshold:e,rootMargin:t});return n.observe(a.current),()=>n.disconnect()},[e,t,l]),[a,l]}function V(e,t=2e3){o.useEffect(()=>{if("requestIdleCallback"in window){const a=window.requestIdleCallback(()=>{e.forEach(l=>l())},{timeout:t});return()=>window.cancelIdleCallback(a)}else{const a=setTimeout(()=>{e.forEach(l=>l())},t);return()=>clearTimeout(a)}},[])}function T(e,t){const a=o.useRef(new Set);o.useEffect(()=>{const l=document.querySelectorAll("a[href]"),p=n=>{const c=n.currentTarget.getAttribute("href");c&&e[c]&&!a.current.has(c)&&(e[c](),a.current.add(c))};return l.forEach(n=>{n.addEventListener("mouseenter",p)}),()=>{l.forEach(n=>{n.removeEventListener("mouseenter",p)})}},[t,e])}const z=()=>r.jsx(f,{height:400}),g=()=>r.jsx(f,{height:300}),j=()=>r.jsx(f,{height:500}),E=()=>r.jsx(f,{height:600}),d=e=>e,s={CodeEditor:i(d(()=>Promise.resolve().then(()=>require("./NiceCodeEditor-DhdjnDLV.cjs")).then(e=>({default:e.NiceCodeEditor}))),{fallback:r.jsx(z,{}),preloadOnHover:!0,displayName:"LazyCodeEditor"}),HtmlEditor:i(d(()=>Promise.resolve().then(()=>require("./NiceHtmlEditor-BzECmDO3.cjs")).then(e=>({default:e.NiceHtmlEditor}))),{fallback:r.jsx(z,{}),preloadOnHover:!0,displayName:"LazyHtmlEditor"}),DocumentViewer:i(d(()=>Promise.resolve().then(()=>require("./NiceDocumentViewer-CDXAmPp7.cjs")).then(e=>({default:e.NiceDocumentViewer}))),{fallback:r.jsx(f,{height:600}),displayName:"LazyDocumentViewer"}),Chart:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceChart$1).then(e=>({default:e.NiceChart}))),{fallback:r.jsx(g,{}),preloadAfterIdle:3e3,displayName:"LazyChart"}),VectorMap:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceVectorMap$1).then(e=>({default:e.NiceVectorMap}))),{fallback:r.jsx(f,{height:400}),displayName:"LazyVectorMap"}),Sankey:i(d(()=>Promise.resolve().then(()=>require("./charts-BzlvCCg9.cjs")).then(e=>e.NiceSankey$1).then(e=>({default:e.NiceSankey}))),{fallback:r.jsx(g,{}),displayName:"LazySankey"}),Scheduler:i(d(()=>Promise.resolve().then(()=>require("./NiceScheduler-BqYiHPvz.cjs")).then(e=>e.NiceScheduler$1).then(e=>({default:e.NiceScheduler}))),{fallback:r.jsx(E,{}),displayName:"LazyScheduler"}),Gantt:i(d(()=>Promise.resolve().then(()=>require("./NiceGantt-BygumlaY.cjs")).then(e=>({default:e.NiceGantt}))),{fallback:r.jsx(E,{}),displayName:"LazyGantt"}),PivotGrid:i(d(()=>Promise.resolve().then(()=>require("./NicePivotGrid-Cxu5PECg.cjs")).then(e=>e.NicePivotGrid$1).then(e=>({default:e.NicePivotGrid}))),{fallback:r.jsx(j,{}),displayName:"LazyPivotGrid"}),DataGrid:i(d(()=>Promise.resolve().then(()=>require("./NiceDataGrid-D3qRQSjy.cjs")).then(e=>e.NiceDataGrid$1).then(e=>({default:e.NiceDataGrid}))),{fallback:r.jsx(j,{}),preloadAfterIdle:2e3,displayName:"LazyDataGrid"})};async function H(){await Promise.all([s.CodeEditor.preload(),s.HtmlEditor.preload(),s.DocumentViewer.preload(),s.Chart.preload(),s.VectorMap.preload(),s.Sankey.preload(),s.Scheduler.preload(),s.Gantt.preload(),s.PivotGrid.preload()])}async function O(e){await Promise.all(e.map(t=>s[t].preload()))}exports.DefaultErrorFallback=L;exports.DefaultLoadingFallback=f;exports.LazyComponents=s;exports.createLazyComponent=i;exports.preloadAllHeavyComponents=H;exports.preloadComponents=O;exports.useLazyOnVisible=G;exports.usePreloadOnIdle=V;exports.usePreloadOnRouteHint=T;
package/dist/data.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./NiceDataGrid-mrnaLHQk.cjs"),e=require("./NiceSavedQueryPanel-U1-yaw-Q.cjs"),r=require("./NicePivotGrid-Cnkr9WkC.cjs");exports.NiceDataGrid=i.NiceDataGrid;exports.applyColumnOrder=i.applyColumnOrder;exports.buildColumnGroupSegments=i.buildColumnGroupSegments;exports.buildGridState=i.buildGridState;exports.computeAggregate=i.computeAggregate;exports.escapeCsvField=i.escapeCsvField;exports.formatNumberPattern=i.formatNumberPattern;exports.measureColumnContentWidth=i.measureColumnContentWidth;exports.readStoredGridState=i.readStoredGridState;exports.writeStoredGridState=i.writeStoredGridState;exports.NiceDataGridAI=e.NiceDataGridAI;exports.NiceKanbanBoard=e.NiceKanbanBoard;exports.NiceList=e.NiceList;exports.NiceModuleGrid=e.NiceModuleGrid;exports.NiceReconciliationView=e.NiceReconciliationView;exports.NiceSavedQueryPanel=e.NiceSavedQueryPanel;exports.NiceSpreadsheet=e.NiceSpreadsheet;exports.NiceTable=e.NiceTable;exports.NiceTileView=e.NiceTileView;exports.NiceTreeGrid=e.NiceTreeGrid;exports.NiceTreeList=e.NiceTreeList;exports.NiceTreeView=e.NiceTreeView;exports.NicePivotGrid=r.NicePivotGrid;exports.NicePivotGridFieldChooser=r.NicePivotGridFieldChooser;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./NiceDataGrid-D3qRQSjy.cjs"),e=require("./NiceSavedQueryPanel-BSZhE-_l.cjs"),r=require("./NicePivotGrid-Cxu5PECg.cjs");exports.NiceDataGrid=i.NiceDataGrid;exports.applyColumnOrder=i.applyColumnOrder;exports.buildColumnGroupSegments=i.buildColumnGroupSegments;exports.buildGridState=i.buildGridState;exports.computeAggregate=i.computeAggregate;exports.escapeCsvField=i.escapeCsvField;exports.formatNumberPattern=i.formatNumberPattern;exports.measureColumnContentWidth=i.measureColumnContentWidth;exports.readStoredGridState=i.readStoredGridState;exports.writeStoredGridState=i.writeStoredGridState;exports.NiceDataGridAI=e.NiceDataGridAI;exports.NiceKanbanBoard=e.NiceKanbanBoard;exports.NiceList=e.NiceList;exports.NiceModuleGrid=e.NiceModuleGrid;exports.NiceReconciliationView=e.NiceReconciliationView;exports.NiceSavedQueryPanel=e.NiceSavedQueryPanel;exports.NiceSpreadsheet=e.NiceSpreadsheet;exports.NiceTable=e.NiceTable;exports.NiceTileView=e.NiceTileView;exports.NiceTreeGrid=e.NiceTreeGrid;exports.NiceTreeList=e.NiceTreeList;exports.NiceTreeView=e.NiceTreeView;exports.NicePivotGrid=r.NicePivotGrid;exports.NicePivotGridFieldChooser=r.NicePivotGridFieldChooser;
@@ -0,0 +1,370 @@
1
+ import { jsx as a, jsxs as m, Fragment as D } from "react/jsx-runtime";
2
+ import { useNiceTranslation as C, useControllableState as J, NiceIcon as w } from "@nice2dev/ui-core";
3
+ import { useMemo as z, useState as E } from "react";
4
+ import { NiceCheckbox as $ } from "../editors/inputs/NiceCheckbox.mjs";
5
+ import { NiceSelect as v } from "../editors/inputs/NiceSelect.mjs";
6
+ import { NiceTextInput as k } from "../editors/inputs/NiceTextInput.mjs";
7
+ import { NiceSimpleCodeEditor as R } from "../editors/rich/NiceCodeEditor.mjs";
8
+ import { newModuleDataSource as A, moduleDataSourceColumns as x, NICE_MODULE_DATA_SOURCE_KINDS as K, moduleDataSourceParameters as U } from "./moduleDataSource.mjs";
9
+ import { NiceQueryDesigner as B } from "./NiceQueryDesigner.mjs";
10
+ /* empty css */
11
+ const Q = ["", "postgresql", "sqlserver", "mysql", "sqlite", "oracle"], j = [], F = [], W = 50, Y = (i, b) => {
12
+ switch (b) {
13
+ case "query":
14
+ return i("dataSourceEditor.kind.query", "Visual query");
15
+ case "sql":
16
+ return i("dataSourceEditor.kind.sql", "SQL");
17
+ case "union":
18
+ return i("dataSourceEditor.kind.union", "Union of sources");
19
+ case "static":
20
+ return i("dataSourceEditor.kind.static", "Fixed rows");
21
+ }
22
+ };
23
+ function P({
24
+ legend: i,
25
+ rows: b,
26
+ onChange: S,
27
+ extra: h,
28
+ readOnly: d,
29
+ fresh: g
30
+ }) {
31
+ const { t: l } = C(), p = (s, t) => S(b.map((n, r) => r === s ? t : n));
32
+ return /* @__PURE__ */ m("fieldset", { className: "nice-data-source-editor__rows", children: [
33
+ /* @__PURE__ */ a("legend", { children: i }),
34
+ b.map((s, t) => /* @__PURE__ */ m("div", { className: "nice-data-source-editor__row", children: [
35
+ /* @__PURE__ */ a(
36
+ k,
37
+ {
38
+ label: l("dataSourceEditor.name", "Name"),
39
+ labelPlacement: "inside",
40
+ value: s.name,
41
+ onChange: (n) => p(t, { ...s, name: n }),
42
+ readOnly: d,
43
+ size: "sm"
44
+ }
45
+ ),
46
+ /* @__PURE__ */ a(
47
+ k,
48
+ {
49
+ label: l("dataSourceEditor.type", "Type"),
50
+ labelPlacement: "inside",
51
+ value: s.dataType ?? "",
52
+ onChange: (n) => p(t, { ...s, dataType: n || void 0 }),
53
+ readOnly: d,
54
+ size: "sm"
55
+ }
56
+ ),
57
+ h && /* @__PURE__ */ a(
58
+ k,
59
+ {
60
+ label: h.label,
61
+ labelPlacement: "inside",
62
+ value: h.get(s),
63
+ onChange: (n) => p(t, h.set(s, n)),
64
+ readOnly: d,
65
+ size: "sm"
66
+ }
67
+ ),
68
+ !d && /* @__PURE__ */ a(
69
+ "button",
70
+ {
71
+ type: "button",
72
+ className: "nice-data-source-editor__icon-btn",
73
+ "aria-label": l("dataSourceEditor.remove", "Remove"),
74
+ onClick: () => S(b.filter((n, r) => r !== t)),
75
+ children: /* @__PURE__ */ a(w, { name: "trash", size: 14 })
76
+ }
77
+ )
78
+ ] }, t)),
79
+ !d && /* @__PURE__ */ m(
80
+ "button",
81
+ {
82
+ type: "button",
83
+ className: "nice-data-source-editor__add",
84
+ onClick: () => S([...b, g(b.length + 1)]),
85
+ children: [
86
+ /* @__PURE__ */ a(w, { name: "plus", size: 14 }),
87
+ l("dataSourceEditor.add", "Add")
88
+ ]
89
+ }
90
+ )
91
+ ] });
92
+ }
93
+ function ce({
94
+ value: i,
95
+ defaultValue: b,
96
+ onChange: S,
97
+ schemas: h = j,
98
+ extraSchemas: d = j,
99
+ sources: g = F,
100
+ kinds: l = K,
101
+ dialects: p = Q,
102
+ onPreview: s,
103
+ readOnly: t = !1,
104
+ height: n,
105
+ className: r,
106
+ style: c,
107
+ id: f,
108
+ "data-testid": V
109
+ }) {
110
+ const { t: u } = C(), [o, I] = J({
111
+ value: i,
112
+ defaultValue: b ?? A("query", "source1"),
113
+ onChange: S
114
+ }), q = z(() => g.filter((e) => e.key !== o.key), [g, o.key]);
115
+ z(() => [...h, ...d], [h, d]);
116
+ const y = (e) => I(e), _ = (e) => y({ ...o, ...e }), L = (e) => {
117
+ e !== o.kind && y(A(e, o.key, { label: o.label, description: o.description }));
118
+ };
119
+ let N;
120
+ switch (o.kind) {
121
+ case "query":
122
+ N = /* @__PURE__ */ a(
123
+ B,
124
+ {
125
+ value: o,
126
+ onChange: (e) => y({ ...e, key: o.key, label: o.label }),
127
+ schemas: h,
128
+ extraSchemas: d,
129
+ sources: q,
130
+ onPreview: s,
131
+ readOnly: t,
132
+ height: n
133
+ }
134
+ );
135
+ break;
136
+ case "sql":
137
+ N = /* @__PURE__ */ m(D, { children: [
138
+ /* @__PURE__ */ a(
139
+ v,
140
+ {
141
+ label: u("dataSourceEditor.dialect", "Dialect"),
142
+ value: o.dialect ?? "",
143
+ options: p.map((e) => ({
144
+ value: e,
145
+ label: e || u("dataSourceEditor.dialect.portable", "Portable SQL")
146
+ })),
147
+ onChange: (e) => _({ dialect: String(e) || void 0 }),
148
+ disabled: t,
149
+ size: "sm"
150
+ }
151
+ ),
152
+ /* @__PURE__ */ a("div", { className: "nice-data-source-editor__code", children: /* @__PURE__ */ a(
153
+ R,
154
+ {
155
+ value: o.sql,
156
+ onChange: (e) => _({ sql: e }),
157
+ language: "sql",
158
+ height: 220,
159
+ lineNumbers: !0,
160
+ readOnly: t
161
+ }
162
+ ) }),
163
+ /* @__PURE__ */ a(
164
+ P,
165
+ {
166
+ legend: u("dataSourceEditor.parameters", "Parameters"),
167
+ rows: o.parameters ?? [],
168
+ onChange: (e) => _({ parameters: e }),
169
+ extra: {
170
+ label: u("dataSourceEditor.default", "Default"),
171
+ get: (e) => e.defaultValue ?? "",
172
+ set: (e, M) => ({ ...e, defaultValue: M || void 0 })
173
+ },
174
+ readOnly: t,
175
+ fresh: (e) => ({ name: `param${e}`, dataType: "string" })
176
+ }
177
+ ),
178
+ /* @__PURE__ */ a(
179
+ P,
180
+ {
181
+ legend: u("dataSourceEditor.columns", "Columns it returns"),
182
+ rows: o.columns ?? [],
183
+ onChange: (e) => _({ columns: e }),
184
+ readOnly: t,
185
+ fresh: (e) => ({ name: `column${e}`, dataType: "string" })
186
+ }
187
+ )
188
+ ] });
189
+ break;
190
+ case "union":
191
+ N = /* @__PURE__ */ m(D, { children: [
192
+ /* @__PURE__ */ a(
193
+ v,
194
+ {
195
+ label: u("dataSourceEditor.sources", "Sources, in order"),
196
+ value: o.sources,
197
+ options: q.map((e) => ({ value: e.key, label: e.label || e.key })),
198
+ onChange: (e) => _({ sources: (Array.isArray(e) ? e : [e]).filter(Boolean) }),
199
+ multiple: !0,
200
+ disabled: t,
201
+ size: "sm"
202
+ }
203
+ ),
204
+ /* @__PURE__ */ a(
205
+ $,
206
+ {
207
+ label: u("dataSourceEditor.distinct", "Drop rows that repeat"),
208
+ checked: !!o.distinct,
209
+ onChange: (e) => _({ distinct: e || void 0 }),
210
+ disabled: t
211
+ }
212
+ )
213
+ ] });
214
+ break;
215
+ case "static":
216
+ N = /* @__PURE__ */ a(
217
+ G,
218
+ {
219
+ rows: o.rows,
220
+ onChange: (e) => _({ rows: e }),
221
+ readOnly: t,
222
+ label: u("dataSourceEditor.rows", "Rows (JSON)"),
223
+ invalid: u("dataSourceEditor.rowsInvalid", "Rows must be a JSON list of objects.")
224
+ }
225
+ );
226
+ break;
227
+ }
228
+ const T = x(o, { sources: g });
229
+ return /* @__PURE__ */ m(
230
+ "div",
231
+ {
232
+ id: f,
233
+ className: `nice-data-source-editor${r ? ` ${r}` : ""}`,
234
+ style: c,
235
+ "data-testid": V,
236
+ children: [
237
+ /* @__PURE__ */ m("div", { className: "nice-data-source-editor__head", children: [
238
+ /* @__PURE__ */ a(
239
+ k,
240
+ {
241
+ label: u("dataSourceEditor.key", "Key"),
242
+ value: o.key,
243
+ onChange: (e) => _({ key: e }),
244
+ readOnly: t,
245
+ size: "sm"
246
+ }
247
+ ),
248
+ /* @__PURE__ */ a(
249
+ k,
250
+ {
251
+ label: u("dataSourceEditor.label", "Name"),
252
+ value: o.label ?? "",
253
+ onChange: (e) => _({ label: e || void 0 }),
254
+ readOnly: t,
255
+ size: "sm"
256
+ }
257
+ ),
258
+ /* @__PURE__ */ a(
259
+ v,
260
+ {
261
+ label: u("dataSourceEditor.kind", "Kind"),
262
+ value: o.kind,
263
+ options: l.map((e) => ({ value: e, label: Y(u, e) })),
264
+ onChange: (e) => L(String(e)),
265
+ disabled: t,
266
+ size: "sm"
267
+ }
268
+ )
269
+ ] }),
270
+ /* @__PURE__ */ a("div", { className: `nice-data-source-editor__body nice-data-source-editor__body--${o.kind}`, children: N }),
271
+ T.length > 0 && o.kind !== "query" && /* @__PURE__ */ m("p", { className: "nice-data-source-editor__columns", children: [
272
+ /* @__PURE__ */ a("strong", { children: u("dataSourceEditor.gives", "Gives:") }),
273
+ " ",
274
+ T.map((e) => e.name).join(", ")
275
+ ] }),
276
+ s && o.kind !== "query" && /* @__PURE__ */ a(X, { def: o, onPreview: s })
277
+ ]
278
+ }
279
+ );
280
+ }
281
+ function G({
282
+ rows: i,
283
+ onChange: b,
284
+ readOnly: S,
285
+ label: h,
286
+ invalid: d
287
+ }) {
288
+ const [g, l] = E(() => JSON.stringify(i, null, 2)), [p, s] = E(!1);
289
+ return /* @__PURE__ */ m("div", { className: "nice-data-source-editor__code", children: [
290
+ /* @__PURE__ */ a("span", { className: "nice-data-source-editor__label", children: h }),
291
+ /* @__PURE__ */ a(
292
+ R,
293
+ {
294
+ value: g,
295
+ onChange: (t) => {
296
+ l(t);
297
+ try {
298
+ const n = JSON.parse(t), r = Array.isArray(n) && n.every((c) => typeof c == "object" && c !== null && !Array.isArray(c));
299
+ s(!r), r && b(n);
300
+ } catch {
301
+ s(!0);
302
+ }
303
+ },
304
+ language: "json",
305
+ height: 220,
306
+ lineNumbers: !0,
307
+ readOnly: S
308
+ }
309
+ ),
310
+ p && /* @__PURE__ */ a("p", { className: "nice-data-source-editor__error", role: "status", children: d })
311
+ ] });
312
+ }
313
+ const H = (i) => i == null ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
314
+ function X({
315
+ def: i,
316
+ onPreview: b
317
+ }) {
318
+ const { t: S } = C(), h = U(i), [d, g] = E({}), [l, p] = E({ kind: "idle" }), s = async () => {
319
+ p({ kind: "running" });
320
+ const r = Object.fromEntries(
321
+ h.map((c) => [c.name, d[c.name] ?? c.defaultValue ?? ""])
322
+ );
323
+ try {
324
+ p({ kind: "rows", rows: await b(i, r) });
325
+ } catch (c) {
326
+ p({ kind: "error", message: c instanceof Error ? c.message : String(c) });
327
+ }
328
+ }, t = l.kind === "rows" ? l.rows.slice(0, W) : [], n = [...new Set(t.flatMap((r) => Object.keys(r)))];
329
+ return /* @__PURE__ */ m("section", { className: "nice-data-source-editor__preview", children: [
330
+ /* @__PURE__ */ m("div", { className: "nice-data-source-editor__row", children: [
331
+ h.map((r) => /* @__PURE__ */ a(
332
+ k,
333
+ {
334
+ label: r.name,
335
+ value: d[r.name] ?? r.defaultValue ?? "",
336
+ onChange: (c) => g((f) => ({ ...f, [r.name]: c })),
337
+ size: "sm"
338
+ },
339
+ r.name
340
+ )),
341
+ /* @__PURE__ */ m(
342
+ "button",
343
+ {
344
+ type: "button",
345
+ className: "nice-data-source-editor__run",
346
+ onClick: () => void s(),
347
+ disabled: l.kind === "running",
348
+ children: [
349
+ /* @__PURE__ */ a(w, { name: "play", size: 14 }),
350
+ S("dataSourceEditor.preview", "Preview")
351
+ ]
352
+ }
353
+ )
354
+ ] }),
355
+ l.kind === "error" && /* @__PURE__ */ a("p", { className: "nice-data-source-editor__error", role: "status", children: l.message }),
356
+ l.kind === "rows" && /* @__PURE__ */ m("div", { className: "nice-data-source-editor__result", role: "status", children: [
357
+ /* @__PURE__ */ a("span", { className: "nice-data-source-editor__label", children: S("dataSourceEditor.rowsCount", "{count} rows").replace(
358
+ "{count}",
359
+ String(l.rows.length)
360
+ ) }),
361
+ t.length > 0 && /* @__PURE__ */ m("table", { className: "nice-data-source-editor__table", children: [
362
+ /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: n.map((r) => /* @__PURE__ */ a("th", { scope: "col", children: r }, r)) }) }),
363
+ /* @__PURE__ */ a("tbody", { children: t.map((r, c) => /* @__PURE__ */ a("tr", { children: n.map((f) => /* @__PURE__ */ a("td", { children: H(r[f]) }, f)) }, c)) })
364
+ ] })
365
+ ] })
366
+ ] });
367
+ }
368
+ export {
369
+ ce as NiceDataSourceEditor
370
+ };