@object-ui/plugin-calendar 0.5.0 → 3.0.0
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/.turbo/turbo-build.log +11 -6
- package/CHANGELOG.md +37 -0
- package/dist/index.js +640 -485
- package/dist/index.umd.cjs +2 -2
- package/dist/src/CalendarView.d.ts +3 -1
- package/dist/src/CalendarView.d.ts.map +1 -1
- package/dist/src/ObjectCalendar.d.ts +1 -0
- package/dist/src/ObjectCalendar.d.ts.map +1 -1
- package/dist/src/ObjectCalendar.stories.d.ts +23 -0
- package/dist/src/ObjectCalendar.stories.d.ts.map +1 -0
- package/package.json +11 -10
- package/src/CalendarView.test.tsx +6 -6
- package/src/CalendarView.tsx +185 -23
- package/src/ObjectCalendar.msw.test.tsx +8 -4
- package/src/ObjectCalendar.stories.tsx +82 -0
- package/src/ObjectCalendar.tsx +54 -4
- package/src/__tests__/accessibility.test.tsx +290 -0
- package/src/__tests__/performance-benchmark.test.tsx +227 -0
- package/src/__tests__/view-states.test.tsx +377 -0
- package/src/index.tsx +11 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(A,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("lucide-react"),require("@object-ui/components")):typeof define=="function"&&define.amd?define(["exports","react","@object-ui/core","@object-ui/react","lucide-react","@object-ui/components"],p):(A=typeof globalThis<"u"?globalThis:A||self,p(A.ObjectUIPluginCalendar={},A.React,A.ObjectUICore,A.ObjectUIReact,A.LucideReact,A.ObjectUIComponents))})(this,(function(A,p,K,oe,Q,v){"use strict";function me(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const l in t)if(l!=="default"){const s=Object.getOwnPropertyDescriptor(t,l);Object.defineProperty(n,l,s.get?s:{enumerable:!0,get:()=>t[l]})}}return n.default=t,Object.freeze(n)}const L=me(p);var Z={exports:{}},J={};var ie;function ge(){if(ie)return J;ie=1;var t=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function l(s,m,c){var g=null;if(c!==void 0&&(g=""+c),m.key!==void 0&&(g=""+m.key),"key"in m){c={};for(var u in m)u!=="key"&&(c[u]=m[u])}else c=m;return m=c.ref,{$$typeof:t,type:s,key:g,ref:m!==void 0?m:null,props:c}}return J.Fragment=n,J.jsx=l,J.jsxs=l,J}var B={};var se;function he(){return se||(se=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===j?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case V:return"Fragment";case F:return"Profiler";case x:return"StrictMode";case S:return"Suspense";case I:return"SuspenseList";case T:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case $:return"Portal";case _:return e.displayName||"Context";case P:return(e._context.displayName||"Context")+".Consumer";case M:var f=e.render;return e=e.displayName,e||(e=f.displayName||f.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Y:return f=e.displayName||null,f!==null?f:t(e.type)||"Memo";case i:f=e._payload,e=e._init;try{return t(e(f))}catch{}}return null}function n(e){return""+e}function l(e){try{n(e);var f=!1}catch{f=!0}if(f){f=console;var w=f.error,E=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return w.call(f,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",E),n(e)}}function s(e){if(e===V)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===i)return"<...>";try{var f=t(e);return f?"<"+f+">":"<...>"}catch{return"<...>"}}function m(){var e=W.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function g(e){if(q.call(e,"key")){var f=Object.getOwnPropertyDescriptor(e,"key").get;if(f&&f.isReactWarning)return!1}return e.key!==void 0}function u(e,f){function w(){U||(U=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",f))}w.isReactWarning=!0,Object.defineProperty(e,"key",{get:w,configurable:!0})}function h(){var e=t(this.type);return D[e]||(D[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function d(e,f,w,E,H,X){var C=w.ref;return e={$$typeof:N,type:e,key:f,props:w,_owner:E},(C!==void 0?C:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:h}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:H}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function y(e,f,w,E,H,X){var C=f.children;if(C!==void 0)if(E)if(ne(C)){for(E=0;E<C.length;E++)a(C[E]);Object.freeze&&Object.freeze(C)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else a(C);if(q.call(f,"key")){C=t(e);var z=Object.keys(f).filter(function(Te){return Te!=="key"});E=0<z.length?"{key: someKey, "+z.join(": ..., ")+": ...}":"{key: someKey}",R[C+E]||(z=0<z.length?"{"+z.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,j,v,P,v),ue[v+j]=!0)}if(v=null,x!==void 0&&(l(x),v=""+x),m(o)&&(l(o.key),v=""+o.key),"key"in o){x={};for(var te in o)te!=="key"&&(x[te]=o[te])}else x=o;return v&&a(x,typeof t=="function"?t.displayName||t.name||"Unknown":t),i(t,v,x,f(),J,ee)}function p(t){y(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===b&&(t._payload.status==="fulfilled"?y(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function y(t){return typeof t=="object"&&t!==null&&t.$$typeof===V}var F=D,V=Symbol.for("react.transitional.element"),L=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),Y=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),w=Symbol.for("react.context"),T=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),Q=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),_=Symbol.for("react.activity"),C=Symbol.for("react.client.reference"),S=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,h=Object.prototype.hasOwnProperty,K=Array.isArray,A=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var R,z={},H=F.react_stack_bottom_frame.bind(F,s)(),de=A(u(s)),ue={};I.Fragment=k,I.jsx=function(t,o,x){var j=1e4>S.recentlyCreatedOwnerStacks++;return N(t,o,x,!1,j?Error("react-stack-top-frame"):H,j?A(u(t)):de)},I.jsxs=function(t,o,x){var j=1e4>S.recentlyCreatedOwnerStacks++;return N(t,o,x,!0,j?Error("react-stack-top-frame"):H,j?A(u(t)):de)}})()),I}var le;function be(){return le||(le=1,process.env.NODE_ENV==="production"?U.exports=ge():U.exports=pe()),U.exports}var r=be();const B="bg-blue-500 text-white";function G({events:e=[],view:n="month",currentDate:l=new Date,onEventClick:u,onDateClick:f,onViewChange:s,onNavigate:m,onAddClick:a,className:d}){const[i,N]=W.useState(n),[p,y]=W.useState(l);W.useEffect(()=>{y(l)},[l]),W.useEffect(()=>{N(n)},[n]);const F=()=>{const c=new Date(p);i==="month"?c.setMonth(c.getMonth()-1):i==="week"?c.setDate(c.getDate()-7):c.setDate(c.getDate()-1),y(c),m?.(c)},V=()=>{const c=new Date(p);i==="month"?c.setMonth(c.getMonth()+1):i==="week"?c.setDate(c.getDate()+7):c.setDate(c.getDate()+1),y(c),m?.(c)},L=()=>{const c=new Date;y(c),m?.(c)},k=c=>{N(c),s?.(c)},Y=()=>{if(i==="month")return p.toLocaleDateString("default",{month:"long",year:"numeric"});if(i==="week"){const c=ie(p),w=new Date(c);return w.setDate(w.getDate()+6),`${c.toLocaleDateString("default",{month:"short",day:"numeric"})} - ${w.toLocaleDateString("default",{month:"short",day:"numeric",year:"numeric"})}`}else return p.toLocaleDateString("default",{weekday:"long",month:"long",day:"numeric",year:"numeric"})},q=c=>{c&&(y(c),m?.(c))};return r.jsxs("div",{className:g.cn("flex flex-col h-full bg-background",d),children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[r.jsxs("div",{className:"flex items-center gap-4",children:[r.jsxs("div",{className:"flex items-center bg-muted/50 rounded-lg p-1 gap-1",children:[r.jsx(g.Button,{variant:"ghost",size:"sm",onClick:L,className:"h-8",children:"Today"}),r.jsx("div",{className:"h-4 w-px bg-border mx-1"}),r.jsx(g.Button,{variant:"ghost",size:"icon",onClick:F,className:"h-8 w-8",children:r.jsx($.ChevronLeftIcon,{className:"h-4 w-4"})}),r.jsx(g.Button,{variant:"ghost",size:"icon",onClick:V,className:"h-8 w-8",children:r.jsx($.ChevronRightIcon,{className:"h-4 w-4"})})]}),r.jsxs(g.Popover,{children:[r.jsx(g.PopoverTrigger,{asChild:!0,children:r.jsxs(g.Button,{variant:"ghost",className:g.cn("text-xl font-semibold h-auto px-3 py-1 hover:bg-muted/50 transition-colors","flex items-center gap-2"),children:[r.jsx($.CalendarIcon,{className:"h-5 w-5 text-muted-foreground"}),r.jsx("span",{children:Y()})]})}),r.jsx(g.PopoverContent,{className:"w-auto p-0",align:"start",children:r.jsx(g.Calendar,{mode:"single",selected:p,onSelect:q,initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(g.Select,{value:i,onValueChange:k,children:[r.jsx(g.SelectTrigger,{className:"w-32 bg-background",children:r.jsx(g.SelectValue,{})}),r.jsxs(g.SelectContent,{children:[r.jsx(g.SelectItem,{value:"day",children:"Day"}),r.jsx(g.SelectItem,{value:"week",children:"Week"}),r.jsx(g.SelectItem,{value:"month",children:"Month"})]})]}),a&&r.jsxs(g.Button,{onClick:a,size:"sm",className:"gap-1",children:[r.jsx($.PlusIcon,{className:"h-4 w-4"}),"New"]})]})]}),r.jsxs("div",{className:"flex-1 overflow-auto",children:[i==="month"&&r.jsx(ye,{date:p,events:e,onEventClick:u,onDateClick:f}),i==="week"&&r.jsx(De,{date:p,events:e,onEventClick:u,onDateClick:f}),i==="day"&&r.jsx(je,{date:p,events:e,onEventClick:u})]})]})}function ie(e){const n=new Date(e),l=n.getDay(),u=n.getDate()-l;return n.setDate(u),n}function xe(e){const n=e.getFullYear(),l=e.getMonth(),u=new Date(n,l,1),f=new Date(n,l+1,0),s=u.getDay(),m=[];for(let d=s-1;d>=0;d--){const i=new Date(u.getTime());i.setDate(i.getDate()-(d+1)),m.push(i)}for(let d=1;d<=f.getDate();d++)m.push(new Date(n,l,d));const a=42-m.length;for(let d=1;d<=a;d++){const i=new Date(f.getTime());i.setDate(i.getDate()+d),m.push(i)}return m}function oe(e,n){return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function X(e,n){return n.filter(l=>{const u=new Date(l.start),f=l.end?new Date(l.end):new Date(u),s=new Date(e);s.setHours(0,0,0,0);const m=new Date(e);m.setHours(23,59,59,999);const a=new Date(u);a.setHours(0,0,0,0);const d=new Date(f);return d.setHours(23,59,59,999),s<=d&&m>=a})}function ye({date:e,events:n,onEventClick:l,onDateClick:u}){const f=xe(e),s=new Date,m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"grid grid-cols-7 border-b",children:m.map(a=>r.jsx("div",{className:"p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0",children:a},a))}),r.jsx("div",{className:"grid grid-cols-7 flex-1 auto-rows-fr",children:f.map((a,d)=>{const i=X(a,n),N=a.getMonth()===e.getMonth(),p=oe(a,s);return r.jsxs("div",{className:g.cn("border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50",!N&&"bg-muted/30 text-muted-foreground"),onClick:()=>u?.(a),children:[r.jsx("div",{className:g.cn("text-sm font-medium mb-1",p&&"inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6"),children:a.getDate()}),r.jsxs("div",{className:"space-y-1",children:[i.slice(0,3).map(y=>r.jsx("div",{className:g.cn("text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80",y.color||B),style:y.color&&y.color.startsWith("#")?{backgroundColor:y.color}:void 0,onClick:F=>{F.stopPropagation(),l?.(y)},children:y.title},y.id)),i.length>3&&r.jsxs("div",{className:"text-xs text-muted-foreground px-2",children:["+",i.length-3," more"]})]})]},d)})})]})}function De({date:e,events:n,onEventClick:l,onDateClick:u}){const f=ie(e),s=Array.from({length:7},(a,d)=>{const i=new Date(f);return i.setDate(i.getDate()+d),i}),m=new Date;return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"grid grid-cols-7 border-b",children:s.map(a=>{const d=oe(a,m);return r.jsxs("div",{className:"p-3 text-center border-r last:border-r-0",children:[r.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:a.toLocaleDateString("default",{weekday:"short"})}),r.jsx("div",{className:g.cn("text-lg font-semibold mt-1",d&&"inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-8 w-8"),children:a.getDate()})]},a.toISOString())})}),r.jsx("div",{className:"grid grid-cols-7 flex-1",children:s.map(a=>{const d=X(a,n);return r.jsx("div",{className:"border-r last:border-r-0 p-2 min-h-[400px] cursor-pointer hover:bg-accent/50",onClick:()=>u?.(a),children:r.jsx("div",{className:"space-y-2",children:d.map(i=>r.jsxs("div",{className:g.cn("text-sm px-3 py-2 rounded cursor-pointer hover:opacity-80",i.color||B),style:i.color&&i.color.startsWith("#")?{backgroundColor:i.color}:void 0,onClick:N=>{N.stopPropagation(),l?.(i)},children:[r.jsx("div",{className:"font-medium",children:i.title}),!i.allDay&&r.jsx("div",{className:"text-xs opacity-90 mt-1",children:i.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})})]},i.id))})},a.toISOString())})})]})}function je({date:e,events:n,onEventClick:l}){const u=X(e,n),f=Array.from({length:24},(s,m)=>m);return r.jsx("div",{className:"flex flex-col h-full",children:r.jsx("div",{className:"flex-1 overflow-auto",children:f.map(s=>{const m=u.filter(a=>a.allDay?s===0:a.start.getHours()===s);return r.jsxs("div",{className:"flex border-b min-h-[60px]",children:[r.jsx("div",{className:"w-20 p-2 text-sm text-muted-foreground border-r",children:s===0?"12 AM":s<12?`${s} AM`:s===12?"12 PM":`${s-12} PM`}),r.jsx("div",{className:"flex-1 p-2 space-y-2",children:m.map(a=>r.jsxs("div",{className:g.cn("px-3 py-2 rounded cursor-pointer hover:opacity-80",a.color||B),style:a.color&&a.color.startsWith("#")?{backgroundColor:a.color}:void 0,onClick:()=>l?.(a),children:[r.jsx("div",{className:"font-medium",children:a.title}),!a.allDay&&r.jsxs("div",{className:"text-xs opacity-90 mt-1",children:[a.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"}),a.end&&` - ${a.end.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})}`]})]},a.id))})]},s)})})})}function ve(e){return"data"in e&&e.data?e.data:"staticData"in e&&e.staticData?{provider:"value",items:e.staticData}:e.objectName?{provider:"object",object:e.objectName}:null}function he(e){if(e){if(typeof e=="string"){const n=e.split(" "),l=n[0],u=n[1]?.toLowerCase()==="desc"?"desc":"asc";return{[l]:u}}if(Array.isArray(e))return e.reduce((n,l)=>(l.field&&l.order&&(n[l.field]=l.order),n),{})}}function we(e){return"filter"in e&&e.filter&&typeof e.filter=="object"&&"calendar"in e.filter?e.filter.calendar:e.calendar?e.calendar:e.startDateField||e.dateField?{startDateField:e.startDateField||e.dateField,endDateField:e.endDateField||e.endField,titleField:e.titleField||"name",colorField:e.colorField,allDayField:e.allDayField}:null}const se=({schema:e,dataSource:n,className:l,onEventClick:u,onDateClick:f,onNavigate:s,onViewChange:m,...a})=>{const[d,i]=D.useState([]),[N,p]=D.useState(!0),[y,F]=D.useState(null),[V,L]=D.useState(null),[k,Y]=D.useState(new Date),[q,c]=D.useState("month"),w=D.useMemo(()=>ve(e),[e.data,e.staticData,e.objectName]),T=D.useMemo(()=>we(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),O=w?.provider==="value";D.useEffect(()=>{let b=!0;return(async()=>{try{if(!b)return;if(p(!0),O&&w?.provider==="value"){b&&(i(w.items),p(!1));return}if(e.data||a.data){const C=e.data||a.data;if(Array.isArray(C)){i(C),p(!1);return}}if(!n)throw new Error("DataSource required for object/api providers");if(w?.provider==="object"){const C=w.object,S=await n.find(C,{$filter:e.filter,$orderby:he(e.sort)});let h=[];Array.isArray(S)?h=S:S&&typeof S=="object"&&(Array.isArray(S.data)?h=S.data:Array.isArray(S.value)&&(h=S.value)),b&&i(h)}else w?.provider==="api"&&(console.warn("API provider not yet implemented for ObjectCalendar"),b&&i([]));b&&p(!1)}catch(C){console.error("[ObjectCalendar] Error fetching data:",C),b&&(F(C),p(!1))}})(),()=>{b=!1}},[w,n,O,e.filter,e.sort]),D.useEffect(()=>{!O&&n&&(async()=>{try{if(!n)return;const _=w?.provider==="object"?w.object:e.objectName;if(!_)return;const C=await n.getObjectSchema(_);L(C)}catch(_){console.error("Failed to fetch object schema:",_)}})()},[e.objectName,n,O,w]);const Q=D.useMemo(()=>{if(!T||!d.length)return[];const{startDateField:b,endDateField:_,titleField:C,colorField:S}=T;return d.map((h,K)=>{const A=h[b],R=_?h[_]:null,z=h[C]||"Untitled",H=S?h[S]:void 0;return{id:h.id||h._id||`event-${K}`,title:z,start:A?new Date(A):new Date,end:R?new Date(R):void 0,color:H,allDay:!R,data:h}}).filter(h=>!isNaN(h.start.getTime()))},[d,T]),Z=D.useCallback(()=>{f?.(new Date)},[f]);return N?r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsx("div",{className:"text-muted-foreground",children:"Loading calendar..."})})}):y?r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsxs("div",{className:"text-destructive",children:["Error: ",y.message]})})}):T?r.jsx("div",{className:l,children:r.jsx("div",{className:"border rounded-lg bg-background h-[calc(100vh-200px)] min-h-[600px]",children:r.jsx(G,{events:Q,currentDate:k,view:e.defaultView||"month",onEventClick:b=>u?.(b.data),onDateClick:f,onNavigate:b=>{Y(b),s?.(b)},onViewChange:b=>{c(b),m?.(b)},onAddClick:Z})})}):r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsx("div",{className:"text-muted-foreground",children:"Calendar configuration required. Please specify startDateField and titleField."})})})};re.ComponentRegistry.register("calendar-view",({schema:e,className:n,onAction:l,...u})=>{const f=D.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((a,d)=>{const i=e.titleField||"title",N=e.startDateField||"start",p=e.endDateField||"end",y=e.colorField||"color",F=e.allDayField||"allDay";return{id:a._id||a.id||d,title:a[i]||"Untitled Event",start:new Date(a[N]),end:a[p]?new Date(a[p]):void 0,allDay:a[F],color:a[y],data:a}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField]),s=a=>{e.onEventClick&&l?.({type:"event-click",payload:a})},m=()=>{l?.({type:"create",payload:{}})};return r.jsx(G,{className:n,events:f,onEventClick:s,onAddClick:m,...u})},{namespace:"plugin-calendar",label:"Calendar View",inputs:[{name:"data",type:"array",label:"Data",description:"Array of record objects to display as events"},{name:"titleField",type:"string",label:"Title Field",defaultValue:"title",description:"Field name to use for event title"},{name:"startDateField",type:"string",label:"Start Date Field",defaultValue:"start",description:"Field name for event start date"},{name:"endDateField",type:"string",label:"End Date Field",defaultValue:"end",description:"Field name for event end date (optional)"},{name:"allDayField",type:"string",label:"All Day Field",defaultValue:"allDay",description:"Field name for all-day flag"},{name:"colorField",type:"string",label:"Color Field",defaultValue:"color",description:"Field name for event color"},{name:"colorMapping",type:"object",label:"Color Mapping",description:'Map field values to colors (e.g., {meeting: "blue", deadline: "red"})'},{name:"view",type:"enum",enum:["month","week","day"],defaultValue:"month",label:"View Mode",description:"Calendar view mode (month, week, or day)"},{name:"currentDate",type:"string",label:"Current Date",description:"ISO date string for initial calendar date"},{name:"allowCreate",type:"boolean",label:"Allow Create",defaultValue:!1,description:"Allow creating events by clicking on dates"},{name:"className",type:"string",label:"CSS Class"}],defaultProps:{view:"month",titleField:"title",startDateField:"start",endDateField:"end",allDayField:"allDay",colorField:"color",allowCreate:!1,data:[{id:1,title:"Team Meeting",start:new Date(new Date().setHours(10,0,0,0)).toISOString(),end:new Date(new Date().setHours(11,0,0,0)).toISOString(),color:"#3b82f6",allDay:!1},{id:2,title:"Project Deadline",start:new Date(new Date().setDate(new Date().getDate()+3)).toISOString(),color:"#ef4444",allDay:!0},{id:3,title:"Conference",start:new Date(new Date().setDate(new Date().getDate()+7)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()+9)).toISOString(),color:"#10b981",allDay:!0}],className:"h-[600px] border rounded-lg"}});const ce=({schema:e})=>{const{dataSource:n}=fe.useSchemaContext();return r.jsx(se,{schema:e,dataSource:n})};re.ComponentRegistry.register("object-calendar",ce,{namespace:"plugin-calendar",label:"Object Calendar",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"calendar",type:"object",label:"Calendar Config",description:"startDateField, endDateField, titleField, colorField"}]}),E.CalendarView=G,E.ObjectCalendar=se,E.ObjectCalendarRenderer=ce,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
<%s key={someKey} {...props} />`,E,C,z,C),R[C+E]=!0)}if(C=null,w!==void 0&&(l(w),C=""+w),g(f)&&(l(f.key),C=""+f.key),"key"in f){w={};for(var le in f)le!=="key"&&(w[le]=f[le])}else w=f;return C&&u(w,typeof e=="function"?e.displayName||e.name||"Unknown":e),d(e,C,w,m(),H,X)}function a(e){b(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===i&&(e._payload.status==="fulfilled"?b(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function b(e){return typeof e=="object"&&e!==null&&e.$$typeof===N}var o=p,N=Symbol.for("react.transitional.element"),$=Symbol.for("react.portal"),V=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),_=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),I=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),i=Symbol.for("react.lazy"),T=Symbol.for("react.activity"),j=Symbol.for("react.client.reference"),W=o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,q=Object.prototype.hasOwnProperty,ne=Array.isArray,G=console.createTask?console.createTask:function(){return null};o={react_stack_bottom_frame:function(e){return e()}};var U,D={},O=o.react_stack_bottom_frame.bind(o,c)(),k=G(s(c)),R={};B.Fragment=V,B.jsx=function(e,f,w){var E=1e4>W.recentlyCreatedOwnerStacks++;return y(e,f,w,!1,E?Error("react-stack-top-frame"):O,E?G(s(e)):k)},B.jsxs=function(e,f,w){var E=1e4>W.recentlyCreatedOwnerStacks++;return y(e,f,w,!0,E?Error("react-stack-top-frame"):O,E?G(s(e)):k)}})()),B}var ce;function pe(){return ce||(ce=1,process.env.NODE_ENV==="production"?Z.exports=ge():Z.exports=he()),Z.exports}var r=pe();const ee="bg-blue-500 text-white";function te({events:t=[],view:n="month",currentDate:l=new Date,locale:s="default",onEventClick:m,onDateClick:c,onViewChange:g,onNavigate:u,onAddClick:h,onEventDrop:d,className:y}){const[a,b]=L.useState(n),[o,N]=L.useState(l);L.useEffect(()=>{N(l)},[l]),L.useEffect(()=>{b(n)},[n]);const $=L.useRef(g);$.current=g,L.useEffect(()=>{const i=window.matchMedia("(max-width: 639px)"),T=j=>{j.matches&&(b("day"),$.current?.("day"))};return T(i),i.addEventListener("change",T),()=>i.removeEventListener("change",T)},[]);const V=()=>{const i=new Date(o);a==="month"?i.setMonth(i.getMonth()-1):a==="week"?i.setDate(i.getDate()-7):i.setDate(i.getDate()-1),N(i),u?.(i)},x=()=>{const i=new Date(o);a==="month"?i.setMonth(i.getMonth()+1):a==="week"?i.setDate(i.getDate()+7):i.setDate(i.getDate()+1),N(i),u?.(i)},F=()=>{const i=new Date;N(i),u?.(i)},P=i=>{b(i),g?.(i)},_=()=>{if(a==="month")return o.toLocaleDateString(s,{month:"long",year:"numeric"});if(a==="week"){const i=de(o),T=new Date(i);return T.setDate(T.getDate()+6),`${i.toLocaleDateString(s,{month:"short",day:"numeric"})} - ${T.toLocaleDateString(s,{month:"short",day:"numeric",year:"numeric"})}`}else return o.toLocaleDateString(s,{weekday:"long",month:"long",day:"numeric",year:"numeric"})},M=L.useRef(0),S=i=>{M.current=i.touches[0].clientX},I=i=>{const T=M.current-i.changedTouches[0].clientX;if(Math.abs(T)>50){const j=new Date(o);a==="day"?j.setDate(j.getDate()+(T>0?1:-1)):a==="week"?j.setDate(j.getDate()+(T>0?7:-7)):j.setMonth(j.getMonth()+(T>0?1:-1)),N(j),u?.(j)}},Y=i=>{i&&(N(i),u?.(i))};return r.jsxs("div",{role:"region","aria-label":"Calendar",className:v.cn("flex flex-col h-full bg-background",y),children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[r.jsxs("div",{className:"flex items-center gap-4",children:[r.jsxs("div",{className:"flex items-center bg-muted/50 rounded-lg p-1 gap-1",children:[r.jsx(v.Button,{variant:"ghost",size:"sm",onClick:F,className:"h-8","aria-label":"Go to today",children:"Today"}),r.jsx("div",{className:"h-4 w-px bg-border mx-1"}),r.jsx(v.Button,{variant:"ghost",size:"icon","aria-label":"Previous period",onClick:V,className:"h-8 w-8",children:r.jsx(Q.ChevronLeftIcon,{className:"h-4 w-4"})}),r.jsx(v.Button,{variant:"ghost",size:"icon","aria-label":"Next period",onClick:x,className:"h-8 w-8",children:r.jsx(Q.ChevronRightIcon,{className:"h-4 w-4"})})]}),r.jsxs(v.Popover,{children:[r.jsx(v.PopoverTrigger,{asChild:!0,children:r.jsxs(v.Button,{variant:"ghost","aria-label":`Current date: ${_()}`,className:v.cn("text-xl font-semibold h-auto px-3 py-1 hover:bg-muted/50 transition-colors","flex items-center gap-2"),children:[r.jsx(Q.CalendarIcon,{className:"h-5 w-5 text-muted-foreground"}),r.jsx("span",{children:_()})]})}),r.jsx(v.PopoverContent,{className:"w-auto p-0",align:"start",children:r.jsx(v.Calendar,{mode:"single",selected:o,onSelect:Y,initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(v.Select,{value:a,onValueChange:P,children:[r.jsx(v.SelectTrigger,{className:"w-32 bg-background",children:r.jsx(v.SelectValue,{})}),r.jsxs(v.SelectContent,{children:[r.jsx(v.SelectItem,{value:"day",children:"Day"}),r.jsx(v.SelectItem,{value:"week",children:"Week"}),r.jsx(v.SelectItem,{value:"month",children:"Month"})]})]}),h&&r.jsxs(v.Button,{onClick:h,size:"sm",className:"gap-1",children:[r.jsx(Q.PlusIcon,{className:"h-4 w-4"}),"New"]})]})]}),r.jsxs("div",{className:"flex-1 overflow-auto",onTouchStart:S,onTouchEnd:I,children:[a==="month"&&r.jsx(xe,{date:o,events:t,onEventClick:m,onDateClick:c,onEventDrop:d}),a==="week"&&r.jsx(De,{date:o,events:t,locale:s,onEventClick:m,onDateClick:c}),a==="day"&&r.jsx(ye,{date:o,events:t,onEventClick:m,onDateClick:c})]})]})}function de(t){const n=new Date(t),l=n.getDay(),s=n.getDate()-l;return n.setDate(s),n}function be(t){const n=t.getFullYear(),l=t.getMonth(),s=new Date(n,l,1),m=new Date(n,l+1,0),c=s.getDay(),g=[];for(let h=c-1;h>=0;h--){const d=new Date(s.getTime());d.setDate(d.getDate()-(h+1)),g.push(d)}for(let h=1;h<=m.getDate();h++)g.push(new Date(n,l,h));const u=42-g.length;for(let h=1;h<=u;h++){const d=new Date(m.getTime());d.setDate(d.getDate()+h),g.push(d)}return g}function ue(t,n){return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}function re(t,n){return n.filter(l=>{const s=new Date(l.start),m=l.end?new Date(l.end):new Date(s),c=new Date(t);c.setHours(0,0,0,0);const g=new Date(t);g.setHours(23,59,59,999);const u=new Date(s);u.setHours(0,0,0,0);const h=new Date(m);return h.setHours(23,59,59,999),c<=h&&g>=u})}function xe({date:t,events:n,onEventClick:l,onDateClick:s,onEventDrop:m}){const c=be(t),g=new Date,u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],[h,d]=L.useState(null),[y,a]=L.useState(null),b=(x,F)=>{d(F.id),x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/plain",String(F.id))},o=()=>{d(null),a(null)},N=(x,F)=>{x.preventDefault(),x.dataTransfer.dropEffect="move",a(F)},$=x=>{x.currentTarget.contains(x.relatedTarget)||a(null)},V=(x,F)=>{if(x.preventDefault(),a(null),d(null),!m)return;const P=x.dataTransfer.getData("text/plain"),_=n.find(j=>String(j.id)===P);if(!_)return;const M=new Date(_.start),S=new Date(M);S.setHours(0,0,0,0);const I=new Date(F);I.setHours(0,0,0,0);const Y=I.getTime()-S.getTime();if(Y===0)return;const i=new Date(M.getTime()+Y);let T;_.end&&(T=new Date(new Date(_.end).getTime()+Y)),m(_,i,T)};return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{role:"row",className:"grid grid-cols-7 border-b",children:u.map(x=>r.jsx("div",{role:"columnheader",className:"p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0",children:x},x))}),r.jsx("div",{role:"grid","aria-label":"Calendar grid",className:"grid grid-cols-7 flex-1 auto-rows-fr",children:c.map((x,F)=>{const P=re(x,n),_=x.getMonth()===t.getMonth(),M=ue(x,g);return r.jsxs("div",{role:"gridcell","aria-label":`${x.toLocaleDateString("default",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}${P.length>0?`, ${P.length} event${P.length>1?"s":""}`:""}`,className:v.cn("border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50",!_&&"bg-muted/30 text-muted-foreground",y===F&&"ring-2 ring-primary"),onClick:()=>s?.(x),onDragOver:S=>N(S,F),onDragLeave:$,onDrop:S=>V(S,x),children:[r.jsx("div",{className:v.cn("text-sm font-medium mb-1",M&&"inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6"),...M?{"aria-current":"date"}:{},children:x.getDate()}),r.jsxs("div",{className:"space-y-1",children:[P.slice(0,3).map(S=>r.jsx("div",{role:"button","aria-label":S.title,draggable:!!m,onDragStart:I=>b(I,S),onDragEnd:o,className:v.cn("text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80",S.color||ee,h===S.id&&"opacity-50"),style:S.color&&S.color.startsWith("#")?{backgroundColor:S.color}:void 0,onClick:I=>{I.stopPropagation(),l?.(S)},children:S.title},S.id)),P.length>3&&r.jsxs("div",{className:"text-xs text-muted-foreground px-2",children:["+",P.length-3," more"]})]})]},F)})})]})}function De({date:t,events:n,locale:l="default",onEventClick:s,onDateClick:m}){const c=L.useRef(null),g=a=>{m&&(c.current=setTimeout(()=>{m(a)},500))},u=()=>{c.current&&(clearTimeout(c.current),c.current=null)},h=de(t),d=Array.from({length:7},(a,b)=>{const o=new Date(h);return o.setDate(o.getDate()+b),o}),y=new Date;return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"grid grid-cols-7 border-b",children:d.map(a=>{const b=ue(a,y);return r.jsxs("div",{className:"p-3 text-center border-r last:border-r-0",children:[r.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:a.toLocaleDateString(l,{weekday:"short"})}),r.jsx("div",{className:v.cn("text-lg font-semibold mt-1",b&&"inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-8 w-8"),children:a.getDate()})]},a.toISOString())})}),r.jsx("div",{role:"grid",className:"grid grid-cols-7 flex-1",children:d.map(a=>{const b=re(a,n);return r.jsx("div",{role:"gridcell","aria-label":`${a.toLocaleDateString("default",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}${b.length>0?`, ${b.length} event${b.length>1?"s":""}`:""}`,className:"border-r last:border-r-0 p-2 min-h-[400px] cursor-pointer hover:bg-accent/50",onClick:()=>m?.(a),onTouchStart:()=>g(a),onTouchEnd:u,children:r.jsx("div",{className:"space-y-2",children:b.map(o=>r.jsxs("div",{role:"button","aria-label":o.title,className:v.cn("text-xs sm:text-sm px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80",o.color||ee),style:o.color&&o.color.startsWith("#")?{backgroundColor:o.color}:void 0,onClick:N=>{N.stopPropagation(),s?.(o)},children:[r.jsx("div",{className:"font-medium truncate",children:o.title}),!o.allDay&&r.jsx("div",{className:"text-xs opacity-90 mt-1",children:o.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})})]},o.id))})},a.toISOString())})})]})}function ye({date:t,events:n,onEventClick:l,onDateClick:s}){const m=re(t,n),c=Array.from({length:24},(d,y)=>y),g=L.useRef(null),u=d=>{s&&(g.current=setTimeout(()=>{const y=new Date(t);y.setHours(d,0,0,0),s(y)},500))},h=()=>{g.current&&(clearTimeout(g.current),g.current=null)};return r.jsx("div",{className:"flex flex-col h-full",children:r.jsx("div",{role:"list",className:"flex-1 overflow-auto",children:c.map(d=>{const y=m.filter(a=>a.allDay?d===0:a.start.getHours()===d);return r.jsxs("div",{role:"listitem",className:"flex border-b min-h-[60px]",children:[r.jsx("div",{className:"w-20 p-2 text-sm text-muted-foreground border-r",children:d===0?"12 AM":d<12?`${d} AM`:d===12?"12 PM":`${d-12} PM`}),r.jsx("div",{className:"flex-1 p-2 space-y-2",onTouchStart:()=>u(d),onTouchEnd:h,children:y.map(a=>r.jsxs("div",{"aria-label":a.title,className:v.cn("px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80",a.color||ee),style:a.color&&a.color.startsWith("#")?{backgroundColor:a.color}:void 0,onClick:()=>l?.(a),children:[r.jsx("div",{className:"font-medium truncate",children:a.title}),!a.allDay&&r.jsxs("div",{className:"text-xs opacity-90 mt-1",children:[a.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"}),a.end&&` - ${a.end.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})}`]})]},a.id))})]},d)})})})}function ve(t){const{onRefresh:n,threshold:l=80,enabled:s=!0}=t,m=p.useRef(null),[c,g]=p.useState(!1),[u,h]=p.useState(0),d=p.useRef(0),y=p.useCallback(o=>{if(!s||c)return;const N=m.current;N&&N.scrollTop===0&&(d.current=o.touches[0].clientY)},[s,c]),a=p.useCallback(o=>{if(!s||c||!d.current)return;const $=o.touches[0].clientY-d.current;$>0&&h(Math.min($,l*1.5))},[s,c,l]),b=p.useCallback(async()=>{if(!(!s||c)){if(u>=l){g(!0);try{await n()}finally{g(!1)}}h(0),d.current=0}},[s,c,u,l,n]);return p.useEffect(()=>{const o=m.current;if(!(!o||!s))return o.addEventListener("touchstart",y,{passive:!0}),o.addEventListener("touchmove",a,{passive:!0}),o.addEventListener("touchend",b,{passive:!0}),()=>{o.removeEventListener("touchstart",y),o.removeEventListener("touchmove",a),o.removeEventListener("touchend",b)}},[y,a,b,s]),{ref:m,isRefreshing:c,pullDistance:u}}const je=p.createContext(null);je.displayName="MobileContext";function we(t){return"data"in t&&t.data?t.data:"staticData"in t&&t.staticData?{provider:"value",items:t.staticData}:t.objectName?{provider:"object",object:t.objectName}:null}function Se(t){if(t){if(typeof t=="string"){const n=t.split(" "),l=n[0],s=n[1]?.toLowerCase()==="desc"?"desc":"asc";return{[l]:s}}if(Array.isArray(t))return t.reduce((n,l)=>(l.field&&l.order&&(n[l.field]=l.order),n),{})}}function Ee(t){return"filter"in t&&t.filter&&typeof t.filter=="object"&&"calendar"in t.filter?t.filter.calendar:t.calendar?t.calendar:t.startDateField||t.dateField?{startDateField:t.startDateField||t.dateField,endDateField:t.endDateField||t.endField,titleField:t.titleField||"name",colorField:t.colorField,allDayField:t.allDayField}:null}const fe=({schema:t,dataSource:n,className:l,onEventClick:s,onRowClick:m,onDateClick:c,onNavigate:g,onViewChange:u,...h})=>{const[d,y]=p.useState([]),[a,b]=p.useState(!0),[o,N]=p.useState(null),[$,V]=p.useState(null),[x,F]=p.useState(new Date),[P,_]=p.useState("month"),[M,S]=p.useState(0),I=p.useCallback(async()=>{S(D=>D+1)},[]),{ref:Y,isRefreshing:i,pullDistance:T}=ve({onRefresh:I,enabled:!!n&&!!t.objectName}),j=p.useMemo(()=>we(t),[t.data,t.staticData,t.objectName]),W=p.useMemo(()=>Ee(t),[t.filter,t.calendar,t.dateField,t.endField,t.titleField,t.colorField]),q=j?.provider==="value";p.useEffect(()=>{let D=!0;return(async()=>{try{if(!D)return;if(b(!0),q&&j?.provider==="value"){D&&(y(j.items),b(!1));return}if(t.data||h.data){const k=t.data||h.data;if(Array.isArray(k)){y(k),b(!1);return}}if(!n)throw new Error("DataSource required for object/api providers");if(j?.provider==="object"){const k=j.object,R=await n.find(k,{$filter:t.filter,$orderby:Se(t.sort)});let e=[];Array.isArray(R)?e=R:R&&typeof R=="object"&&(Array.isArray(R.data)?e=R.data:Array.isArray(R.value)&&(e=R.value)),D&&y(e)}else j?.provider==="api"&&(console.warn("API provider not yet implemented for ObjectCalendar"),D&&y([]));D&&b(!1)}catch(k){console.error("[ObjectCalendar] Error fetching data:",k),D&&(N(k),b(!1))}})(),()=>{D=!1}},[j,n,q,t.filter,t.sort,M]),p.useEffect(()=>{!q&&n&&(async()=>{try{if(!n)return;const O=j?.provider==="object"?j.object:t.objectName;if(!O)return;const k=await n.getObjectSchema(O);V(k)}catch(O){console.error("Failed to fetch object schema:",O)}})()},[t.objectName,n,q,j]);const ne=p.useMemo(()=>{if(!W||!d.length)return[];const{startDateField:D,endDateField:O,titleField:k,colorField:R}=W;return d.map((e,f)=>{const w=e[D],E=O?e[O]:null,H=e[k]||"Untitled",X=R?e[R]:void 0;return{id:e.id||e._id||`event-${f}`,title:H,start:w?new Date(w):new Date,end:E?new Date(E):void 0,color:X,allDay:!E,data:e}}).filter(e=>!isNaN(e.start.getTime()))},[d,W]),G=p.useCallback(()=>{c?.(new Date)},[c]),U=oe.useNavigationOverlay({navigation:t.navigation,objectName:t.objectName,onRowClick:m});return a?r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsx("div",{className:"text-muted-foreground",children:"Loading calendar..."})})}):o?r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsxs("div",{className:"text-destructive",children:["Error: ",o.message]})})}):W?r.jsxs("div",{ref:Y,className:l,children:[T>0&&r.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:T},children:i?"Refreshing…":"Pull to refresh"}),r.jsx("div",{className:"border rounded-lg bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]",children:r.jsx(te,{events:ne,currentDate:x,view:t.defaultView||"month",onEventClick:D=>{U.handleClick(D.data),s?.(D.data)},onDateClick:c,onNavigate:D=>{F(D),g?.(D)},onViewChange:D=>{_(D),u?.(D)},onAddClick:G})}),U.isOverlay&&r.jsx(v.NavigationOverlay,{...U,title:"Event Details",children:D=>r.jsx("div",{className:"space-y-3",children:Object.entries(D).map(([O,k])=>r.jsxs("div",{className:"flex flex-col",children:[r.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:O.replace(/_/g," ")}),r.jsx("span",{className:"text-sm",children:String(k??"—")})]},O))})})]}):r.jsx("div",{className:l,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsx("div",{className:"text-muted-foreground",children:"Calendar configuration required. Please specify startDateField and titleField."})})})};K.ComponentRegistry.register("calendar-view",({schema:t,className:n,onAction:l,...s})=>{const m=p.useMemo(()=>!t.data||!Array.isArray(t.data)?[]:t.data.map((u,h)=>{const d=t.titleField||"title",y=t.startDateField||"start",a=t.endDateField||"end",b=t.colorField||"color",o=t.allDayField||"allDay";return{id:u._id||u.id||h,title:u[d]||"Untitled Event",start:new Date(u[y]),end:u[a]?new Date(u[a]):void 0,allDay:u[o],color:u[b],data:u}}),[t.data,t.titleField,t.startDateField,t.endDateField,t.colorField,t.allDayField]),c=u=>{t.onEventClick&&l?.({type:"event-click",payload:u})},g=()=>{l?.({type:"create",payload:{}})};return r.jsx(te,{className:n,events:m,onEventClick:c,onAddClick:g,...s})},{namespace:"plugin-calendar",label:"Calendar View",inputs:[{name:"data",type:"array",label:"Data",description:"Array of record objects to display as events"},{name:"titleField",type:"string",label:"Title Field",defaultValue:"title",description:"Field name to use for event title"},{name:"startDateField",type:"string",label:"Start Date Field",defaultValue:"start",description:"Field name for event start date"},{name:"endDateField",type:"string",label:"End Date Field",defaultValue:"end",description:"Field name for event end date (optional)"},{name:"allDayField",type:"string",label:"All Day Field",defaultValue:"allDay",description:"Field name for all-day flag"},{name:"colorField",type:"string",label:"Color Field",defaultValue:"color",description:"Field name for event color"},{name:"colorMapping",type:"object",label:"Color Mapping",description:'Map field values to colors (e.g., {meeting: "blue", deadline: "red"})'},{name:"view",type:"enum",enum:["month","week","day"],defaultValue:"month",label:"View Mode",description:"Calendar view mode (month, week, or day)"},{name:"currentDate",type:"string",label:"Current Date",description:"ISO date string for initial calendar date"},{name:"allowCreate",type:"boolean",label:"Allow Create",defaultValue:!1,description:"Allow creating events by clicking on dates"},{name:"className",type:"string",label:"CSS Class"}],defaultProps:{view:"month",titleField:"title",startDateField:"start",endDateField:"end",allDayField:"allDay",colorField:"color",allowCreate:!1,data:[{id:1,title:"Team Meeting",start:new Date(new Date().setHours(10,0,0,0)).toISOString(),end:new Date(new Date().setHours(11,0,0,0)).toISOString(),color:"#3b82f6",allDay:!1},{id:2,title:"Project Deadline",start:new Date(new Date().setDate(new Date().getDate()+3)).toISOString(),color:"#ef4444",allDay:!0},{id:3,title:"Conference",start:new Date(new Date().setDate(new Date().getDate()+7)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()+9)).toISOString(),color:"#10b981",allDay:!0}],className:"h-[600px] border rounded-lg"}});const ae=({schema:t})=>{const{dataSource:n}=oe.useSchemaContext();return r.jsx(fe,{schema:t,dataSource:n})};K.ComponentRegistry.register("object-calendar",ae,{namespace:"plugin-calendar",label:"Object Calendar",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"calendar",type:"object",label:"Calendar Config",description:"startDateField, endDateField, titleField, colorField"}]}),K.ComponentRegistry.register("calendar",ae,{namespace:"view",label:"Calendar View",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"calendar",type:"object",label:"Calendar Config",description:"startDateField, endDateField, titleField, colorField"}]}),A.CalendarView=te,A.ObjectCalendar=fe,A.ObjectCalendarRenderer=ae,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -18,13 +18,15 @@ export interface CalendarViewProps {
|
|
|
18
18
|
events?: CalendarEvent[];
|
|
19
19
|
view?: "month" | "week" | "day";
|
|
20
20
|
currentDate?: Date;
|
|
21
|
+
locale?: string;
|
|
21
22
|
onEventClick?: (event: CalendarEvent) => void;
|
|
22
23
|
onDateClick?: (date: Date) => void;
|
|
23
24
|
onViewChange?: (view: "month" | "week" | "day") => void;
|
|
24
25
|
onNavigate?: (date: Date) => void;
|
|
25
26
|
onAddClick?: () => void;
|
|
27
|
+
onEventDrop?: (event: CalendarEvent, newStart: Date, newEnd?: Date) => void;
|
|
26
28
|
className?: string;
|
|
27
29
|
}
|
|
28
|
-
declare function CalendarView({ events, view, currentDate, onEventClick, onDateClick, onViewChange, onNavigate, onAddClick, className, }: CalendarViewProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
declare function CalendarView({ events, view, currentDate, locale, onEventClick, onDateClick, onViewChange, onNavigate, onAddClick, onEventDrop, className, }: CalendarViewProps): import("react/jsx-runtime").JSX.Element;
|
|
29
31
|
export { CalendarView };
|
|
30
32
|
//# sourceMappingURL=CalendarView.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalendarView.d.ts","sourceRoot":"","sources":["../../src/CalendarView.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,GAAG,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAA;IAC/B,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC7C,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAClC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,KAAK,IAAI,CAAA;IACvD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IACjC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,iBAAS,YAAY,CAAC,EACpB,MAAW,EACX,IAAc,EACd,WAAwB,EACxB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACV,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"CalendarView.d.ts","sourceRoot":"","sources":["../../src/CalendarView.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,GAAG,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAA;IAC/B,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC7C,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAClC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,KAAK,IAAI,CAAA;IACvD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IACjC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;IACvB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,iBAAS,YAAY,CAAC,EACpB,MAAW,EACX,IAAc,EACd,WAAwB,EACxB,MAAkB,EAClB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,GACV,EAAE,iBAAiB,2CAoOnB;AAobD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -17,6 +17,7 @@ export interface ObjectCalendarProps {
|
|
|
17
17
|
dataSource?: DataSource;
|
|
18
18
|
className?: string;
|
|
19
19
|
onEventClick?: (record: any) => void;
|
|
20
|
+
onRowClick?: (record: any) => void;
|
|
20
21
|
onDateClick?: (date: Date) => void;
|
|
21
22
|
onEdit?: (record: any) => void;
|
|
22
23
|
onDelete?: (record: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectCalendar.d.ts","sourceRoot":"","sources":["../../src/ObjectCalendar.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAA4B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObjectCalendar.d.ts","sourceRoot":"","sources":["../../src/ObjectCalendar.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAA4B,MAAM,kBAAkB,CAAC;AAM/F,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,wBAAwB;IACxB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAAC;IAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC;CACzD;AAkFD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAqQxD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
declare const meta: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: import('react').ForwardRefExoticComponent<Omit<{
|
|
5
|
+
schema: import('@object-ui/core').SchemaNode;
|
|
6
|
+
} & Record<string, any>, "ref"> & import('react').RefAttributes<any>>;
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: string;
|
|
9
|
+
};
|
|
10
|
+
tags: string[];
|
|
11
|
+
argTypes: {
|
|
12
|
+
schema: {
|
|
13
|
+
table: {
|
|
14
|
+
disable: true;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
export declare const Default: Story;
|
|
22
|
+
export declare const MonthlyEvents: Story;
|
|
23
|
+
//# sourceMappingURL=ObjectCalendar.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectCalendar.stories.d.ts","sourceRoot":"","sources":["../../src/ObjectCalendar.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAKvD,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;CAUW,CAAC;AAEtB,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAUnC,eAAO,MAAM,OAAO,EAAE,KA0BrB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAyB3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-calendar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Calendar view plugins for Object UI - includes both ObjectQL-integrated and standalone calendar components",
|
|
@@ -25,24 +25,25 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"lucide-react": "^0.563.0",
|
|
28
|
-
"@object-ui/components": "0.
|
|
29
|
-
"@object-ui/core": "0.
|
|
30
|
-
"@object-ui/fields": "0.
|
|
31
|
-
"@object-ui/
|
|
32
|
-
"@object-ui/
|
|
28
|
+
"@object-ui/components": "3.0.0",
|
|
29
|
+
"@object-ui/core": "3.0.0",
|
|
30
|
+
"@object-ui/fields": "3.0.0",
|
|
31
|
+
"@object-ui/mobile": "3.0.0",
|
|
32
|
+
"@object-ui/react": "3.0.0",
|
|
33
|
+
"@object-ui/types": "3.0.0"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
36
37
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@types/react": "
|
|
40
|
-
"@types/react-dom": "
|
|
41
|
-
"@vitejs/plugin-react": "^5.1.
|
|
40
|
+
"@types/react": "19.2.13",
|
|
41
|
+
"@types/react-dom": "19.2.3",
|
|
42
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
42
43
|
"typescript": "^5.9.3",
|
|
43
44
|
"vite": "^7.3.1",
|
|
44
45
|
"vite-plugin-dts": "^4.5.4",
|
|
45
|
-
"@object-ui/data-objectstack": "0.
|
|
46
|
+
"@object-ui/data-objectstack": "3.0.0"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "vite build",
|
|
@@ -50,14 +50,14 @@ describe('CalendarView', () => {
|
|
|
50
50
|
const defaultDate = new Date(2024, 0, 15); // Jan 15, 2024
|
|
51
51
|
|
|
52
52
|
it('renders the header correctly', () => {
|
|
53
|
-
render(<CalendarView currentDate={defaultDate} />);
|
|
53
|
+
render(<CalendarView currentDate={defaultDate} locale="en-US" />);
|
|
54
54
|
|
|
55
55
|
// Check for month label
|
|
56
56
|
expect(screen.getByText('January 2024')).toBeInTheDocument();
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('renders navigation buttons', () => {
|
|
60
|
-
render(<CalendarView currentDate={defaultDate} />);
|
|
60
|
+
render(<CalendarView currentDate={defaultDate} locale="en-US" />);
|
|
61
61
|
|
|
62
62
|
expect(screen.getByText('Today')).toBeInTheDocument();
|
|
63
63
|
|
|
@@ -77,7 +77,7 @@ describe('CalendarView', () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
it('renders the view switcher dropdown trigger', () => {
|
|
80
|
-
render(<CalendarView currentDate={defaultDate} view="month" />);
|
|
80
|
+
render(<CalendarView currentDate={defaultDate} view="month" locale="en-US" />);
|
|
81
81
|
// The SelectValue should display "Month"
|
|
82
82
|
const selectTrigger = screen.getByText('Month');
|
|
83
83
|
expect(selectTrigger).toBeInTheDocument();
|
|
@@ -88,7 +88,7 @@ describe('CalendarView', () => {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
it('renders the date picker trigger', () => {
|
|
91
|
-
render(<CalendarView currentDate={defaultDate} />);
|
|
91
|
+
render(<CalendarView currentDate={defaultDate} locale="en-US" />);
|
|
92
92
|
// The date label (e.g. "January 2024") is now inside a PopoverTrigger button
|
|
93
93
|
const dateLabel = screen.getByText('January 2024');
|
|
94
94
|
expect(dateLabel).toBeInTheDocument();
|
|
@@ -100,7 +100,7 @@ describe('CalendarView', () => {
|
|
|
100
100
|
|
|
101
101
|
it('opens date picker on click', () => {
|
|
102
102
|
// We need to mock pointer interactions for Popover usually, but let's try basic click
|
|
103
|
-
render(<CalendarView currentDate={defaultDate} />);
|
|
103
|
+
render(<CalendarView currentDate={defaultDate} locale="en-US" />);
|
|
104
104
|
const dateTrigger = screen.getByText('January 2024');
|
|
105
105
|
|
|
106
106
|
fireEvent.click(dateTrigger);
|
|
@@ -112,7 +112,7 @@ describe('CalendarView', () => {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
it('renders events in month view', () => {
|
|
115
|
-
render(<CalendarView currentDate={defaultDate} events={mockEvents} />);
|
|
115
|
+
render(<CalendarView currentDate={defaultDate} events={mockEvents} locale="en-US" />);
|
|
116
116
|
expect(screen.getByText('Test Event 1')).toBeInTheDocument();
|
|
117
117
|
});
|
|
118
118
|
});
|