@object-ui/plugin-calendar 0.5.0 → 2.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 +10 -5
- package/CHANGELOG.md +15 -0
- package/dist/index.js +257 -247
- package/dist/index.umd.cjs +2 -2
- package/dist/src/CalendarView.d.ts +2 -1
- package/dist/src/CalendarView.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/CalendarView.test.tsx +6 -6
- package/src/CalendarView.tsx +7 -5
- package/src/ObjectCalendar.msw.test.tsx +8 -4
- package/src/index.tsx +11 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(N,j){typeof exports=="object"&&typeof module<"u"?j(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"],j):(N=typeof globalThis<"u"?globalThis:N||self,j(N.ObjectUIPluginCalendar={},N.React,N.ObjectUICore,N.ObjectUIReact,N.LucideReact,N.ObjectUIComponents))})(this,(function(N,j,B,fe,$,p){"use strict";function me(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const u=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(n,l,u.get?u:{enumerable:!0,get:()=>e[l]})}}return n.default=e,Object.freeze(n)}const W=me(j);var U={exports:{}},P={};var ne;function ge(){if(ne)return P;ne=1;var e=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function l(u,f,s){var m=null;if(s!==void 0&&(m=""+s),f.key!==void 0&&(m=""+f.key),"key"in f){s={};for(var a in f)a!=="key"&&(s[a]=f[a])}else s=f;return f=s.ref,{$$typeof:e,type:u,key:m,ref:f!==void 0?f:null,props:s}}return P.Fragment=n,P.jsx=l,P.jsxs=l,P}var M={};var le;function pe(){return le||(le=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===C?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case k:return"Fragment";case q:return"Profiler";case L:return"StrictMode";case T:return"Suspense";case K:return"SuspenseList";case _:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case V:return"Portal";case i:return t.displayName||"Context";case Y:return(t._context.displayName||"Context")+".Consumer";case F:var o=t.render;return t=t.displayName,t||(t=o.displayName||o.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ee:return o=t.displayName||null,o!==null?o:e(t.type)||"Memo";case b:o=t._payload,t=t._init;try{return e(t(o))}catch{}}return null}function n(t){return""+t}function l(t){try{n(t);var o=!1}catch{o=!0}if(o){o=console;var x=o.error,D=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return x.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",D),n(t)}}function u(t){if(t===k)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===b)return"<...>";try{var o=e(t);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function f(){var t=E.A;return t===null?null:t.getOwner()}function s(){return Error("react-stack-top-frame")}function m(t){if(h.call(t,"key")){var o=Object.getOwnPropertyDescriptor(t,"key").get;if(o&&o.isReactWarning)return!1}return t.key!==void 0}function a(t,o){function x(){A||(A=!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)",o))}x.isReactWarning=!0,Object.defineProperty(t,"key",{get:x,configurable:!0})}function d(){var t=e(this.type);return z[t]||(z[t]=!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.")),t=this.props.ref,t!==void 0?t:null}function c(t,o,x,D,J,re){var v=x.ref;return t={$$typeof:I,type:t,key:o,props:x,_owner:D},(v!==void 0?v:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:d}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:re}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function y(t,o,x,D,J,re){var v=o.children;if(v!==void 0)if(D)if(te(v)){for(D=0;D<v.length;D++)w(v[D]);Object.freeze&&Object.freeze(v)}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 w(v);if(h.call(o,"key")){v=e(t);var R=Object.keys(o).filter(function(Se){return Se!=="key"});D=0<R.length?"{key: someKey, "+R.join(": ..., ")+": ...}":"{key: someKey}",ue[v+D]||(R=0<R.length?"{"+R.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} />`,D,v,R,v),ue[v+D]=!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 ae in o)ae!=="key"&&(x[ae]=o[ae])}else x=o;return v&&a(x,typeof t=="function"?t.displayName||t.name||"Unknown":t),c(t,v,x,f(),J,re)}function w(t){g(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===b&&(t._payload.status==="fulfilled"?g(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function g(t){return typeof t=="object"&&t!==null&&t.$$typeof===I}var S=j,I=Symbol.for("react.transitional.element"),V=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),L=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),Y=Symbol.for("react.consumer"),i=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),K=Symbol.for("react.suspense_list"),ee=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),_=Symbol.for("react.activity"),C=Symbol.for("react.client.reference"),E=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,h=Object.prototype.hasOwnProperty,te=Array.isArray,O=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(t){return t()}};var A,z={},H=S.react_stack_bottom_frame.bind(S,s)(),de=O(u(s)),ue={};M.Fragment=k,M.jsx=function(t,o,x){var D=1e4>E.recentlyCreatedOwnerStacks++;return y(t,o,x,!1,D?Error("react-stack-top-frame"):H,D?O(u(t)):de)},M.jsxs=function(t,o,x){var D=1e4>E.recentlyCreatedOwnerStacks++;return y(t,o,x,!0,D?Error("react-stack-top-frame"):H,D?O(u(t)):de)}})()),M}var ie;function be(){return ie||(ie=1,process.env.NODE_ENV==="production"?U.exports=ge():U.exports=pe()),U.exports}var r=be();const G="bg-blue-500 text-white";function X({events:e=[],view:n="month",currentDate:l=new Date,locale:u="default",onEventClick:f,onDateClick:s,onViewChange:m,onNavigate:a,onAddClick:d,className:c}){const[y,w]=W.useState(n),[g,S]=W.useState(l);W.useEffect(()=>{S(l)},[l]),W.useEffect(()=>{w(n)},[n]);const I=()=>{const i=new Date(g);y==="month"?i.setMonth(i.getMonth()-1):y==="week"?i.setDate(i.getDate()-7):i.setDate(i.getDate()-1),S(i),a?.(i)},V=()=>{const i=new Date(g);y==="month"?i.setMonth(i.getMonth()+1):y==="week"?i.setDate(i.getDate()+7):i.setDate(i.getDate()+1),S(i),a?.(i)},k=()=>{const i=new Date;S(i),a?.(i)},L=i=>{w(i),m?.(i)},q=()=>{if(y==="month")return g.toLocaleDateString(u,{month:"long",year:"numeric"});if(y==="week"){const i=oe(g),F=new Date(i);return F.setDate(F.getDate()+6),`${i.toLocaleDateString(u,{month:"short",day:"numeric"})} - ${F.toLocaleDateString(u,{month:"short",day:"numeric",year:"numeric"})}`}else return g.toLocaleDateString(u,{weekday:"long",month:"long",day:"numeric",year:"numeric"})},Y=i=>{i&&(S(i),a?.(i))};return r.jsxs("div",{className:p.cn("flex flex-col h-full bg-background",c),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(p.Button,{variant:"ghost",size:"sm",onClick:k,className:"h-8",children:"Today"}),r.jsx("div",{className:"h-4 w-px bg-border mx-1"}),r.jsx(p.Button,{variant:"ghost",size:"icon",onClick:I,className:"h-8 w-8",children:r.jsx($.ChevronLeftIcon,{className:"h-4 w-4"})}),r.jsx(p.Button,{variant:"ghost",size:"icon",onClick:V,className:"h-8 w-8",children:r.jsx($.ChevronRightIcon,{className:"h-4 w-4"})})]}),r.jsxs(p.Popover,{children:[r.jsx(p.PopoverTrigger,{asChild:!0,children:r.jsxs(p.Button,{variant:"ghost",className:p.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:q()})]})}),r.jsx(p.PopoverContent,{className:"w-auto p-0",align:"start",children:r.jsx(p.Calendar,{mode:"single",selected:g,onSelect:Y,initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(p.Select,{value:y,onValueChange:L,children:[r.jsx(p.SelectTrigger,{className:"w-32 bg-background",children:r.jsx(p.SelectValue,{})}),r.jsxs(p.SelectContent,{children:[r.jsx(p.SelectItem,{value:"day",children:"Day"}),r.jsx(p.SelectItem,{value:"week",children:"Week"}),r.jsx(p.SelectItem,{value:"month",children:"Month"})]})]}),d&&r.jsxs(p.Button,{onClick:d,size:"sm",className:"gap-1",children:[r.jsx($.PlusIcon,{className:"h-4 w-4"}),"New"]})]})]}),r.jsxs("div",{className:"flex-1 overflow-auto",children:[y==="month"&&r.jsx(ye,{date:g,events:e,onEventClick:f,onDateClick:s}),y==="week"&&r.jsx(je,{date:g,events:e,onEventClick:f,onDateClick:s}),y==="day"&&r.jsx(De,{date:g,events:e,onEventClick:f})]})]})}function oe(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 c=new Date(u.getTime());c.setDate(c.getDate()-(d+1)),m.push(c)}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 c=new Date(f.getTime());c.setDate(c.getDate()+d),m.push(c)}return m}function se(e,n){return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function Q(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 c=Q(a,n),y=a.getMonth()===e.getMonth(),w=se(a,s);return r.jsxs("div",{className:p.cn("border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50",!y&&"bg-muted/30 text-muted-foreground"),onClick:()=>u?.(a),children:[r.jsx("div",{className:p.cn("text-sm font-medium mb-1",w&&"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:[c.slice(0,3).map(g=>r.jsx("div",{className:p.cn("text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80",g.color||G),style:g.color&&g.color.startsWith("#")?{backgroundColor:g.color}:void 0,onClick:S=>{S.stopPropagation(),l?.(g)},children:g.title},g.id)),c.length>3&&r.jsxs("div",{className:"text-xs text-muted-foreground px-2",children:["+",c.length-3," more"]})]})]},d)})})]})}function je({date:e,events:n,onEventClick:l,onDateClick:u}){const f=oe(e),s=Array.from({length:7},(a,d)=>{const c=new Date(f);return c.setDate(c.getDate()+d),c}),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=se(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(locale,{weekday:"short"})}),r.jsx("div",{className:p.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=Q(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(c=>r.jsxs("div",{className:p.cn("text-sm px-3 py-2 rounded cursor-pointer hover:opacity-80",c.color||G),style:c.color&&c.color.startsWith("#")?{backgroundColor:c.color}:void 0,onClick:y=>{y.stopPropagation(),l?.(c)},children:[r.jsx("div",{className:"font-medium",children:c.title}),!c.allDay&&r.jsx("div",{className:"text-xs opacity-90 mt-1",children:c.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})})]},c.id))})},a.toISOString())})})]})}function De({date:e,events:n,onEventClick:l}){const u=Q(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:p.cn("px-3 py-2 rounded cursor-pointer hover:opacity-80",a.color||G),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 ce=({schema:e,dataSource:n,className:l,onEventClick:u,onDateClick:f,onNavigate:s,onViewChange:m,...a})=>{const[d,c]=j.useState([]),[y,w]=j.useState(!0),[g,S]=j.useState(null),[I,V]=j.useState(null),[k,L]=j.useState(new Date),[q,Y]=j.useState("month"),i=j.useMemo(()=>ve(e),[e.data,e.staticData,e.objectName]),F=j.useMemo(()=>we(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),T=i?.provider==="value";j.useEffect(()=>{let b=!0;return(async()=>{try{if(!b)return;if(w(!0),T&&i?.provider==="value"){b&&(c(i.items),w(!1));return}if(e.data||a.data){const C=e.data||a.data;if(Array.isArray(C)){c(C),w(!1);return}}if(!n)throw new Error("DataSource required for object/api providers");if(i?.provider==="object"){const C=i.object,E=await n.find(C,{$filter:e.filter,$orderby:he(e.sort)});let h=[];Array.isArray(E)?h=E:E&&typeof E=="object"&&(Array.isArray(E.data)?h=E.data:Array.isArray(E.value)&&(h=E.value)),b&&c(h)}else i?.provider==="api"&&(console.warn("API provider not yet implemented for ObjectCalendar"),b&&c([]));b&&w(!1)}catch(C){console.error("[ObjectCalendar] Error fetching data:",C),b&&(S(C),w(!1))}})(),()=>{b=!1}},[i,n,T,e.filter,e.sort]),j.useEffect(()=>{!T&&n&&(async()=>{try{if(!n)return;const _=i?.provider==="object"?i.object:e.objectName;if(!_)return;const C=await n.getObjectSchema(_);V(C)}catch(_){console.error("Failed to fetch object schema:",_)}})()},[e.objectName,n,T,i]);const K=j.useMemo(()=>{if(!F||!d.length)return[];const{startDateField:b,endDateField:_,titleField:C,colorField:E}=F;return d.map((h,te)=>{const O=h[b],A=_?h[_]:null,z=h[C]||"Untitled",H=E?h[E]:void 0;return{id:h.id||h._id||`event-${te}`,title:z,start:O?new Date(O):new Date,end:A?new Date(A):void 0,color:H,allDay:!A,data:h}}).filter(h=>!isNaN(h.start.getTime()))},[d,F]),ee=j.useCallback(()=>{f?.(new Date)},[f]);return y?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..."})})}):g?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: ",g.message]})})}):F?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(X,{events:K,currentDate:k,view:e.defaultView||"month",onEventClick:b=>u?.(b.data),onDateClick:f,onNavigate:b=>{L(b),s?.(b)},onViewChange:b=>{Y(b),m?.(b)},onAddClick:ee})})}):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."})})})};B.ComponentRegistry.register("calendar-view",({schema:e,className:n,onAction:l,...u})=>{const f=j.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((a,d)=>{const c=e.titleField||"title",y=e.startDateField||"start",w=e.endDateField||"end",g=e.colorField||"color",S=e.allDayField||"allDay";return{id:a._id||a.id||d,title:a[c]||"Untitled Event",start:new Date(a[y]),end:a[w]?new Date(a[w]):void 0,allDay:a[S],color:a[g],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(X,{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 Z=({schema:e})=>{const{dataSource:n}=fe.useSchemaContext();return r.jsx(ce,{schema:e,dataSource:n})};B.ComponentRegistry.register("object-calendar",Z,{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"}]}),B.ComponentRegistry.register("calendar",Z,{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"}]}),N.CalendarView=X,N.ObjectCalendar=ce,N.ObjectCalendarRenderer=Z,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -18,6 +18,7 @@ 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;
|
|
@@ -25,6 +26,6 @@ export interface CalendarViewProps {
|
|
|
25
26
|
onAddClick?: () => void;
|
|
26
27
|
className?: string;
|
|
27
28
|
}
|
|
28
|
-
declare function CalendarView({ events, view, currentDate, onEventClick, onDateClick, onViewChange, onNavigate, onAddClick, className, }: CalendarViewProps): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
declare function CalendarView({ events, view, currentDate, locale, onEventClick, onDateClick, onViewChange, onNavigate, onAddClick, className, }: CalendarViewProps): import("react/jsx-runtime").JSX.Element;
|
|
29
30
|
export { CalendarView };
|
|
30
31
|
//# 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,2CA4LnB;AA8TD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
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,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,SAAS,GACV,EAAE,iBAAiB,2CA4LnB;AA8TD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-calendar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.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,24 @@
|
|
|
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/react": "0.
|
|
32
|
-
"@object-ui/types": "0.
|
|
28
|
+
"@object-ui/components": "2.0.0",
|
|
29
|
+
"@object-ui/core": "2.0.0",
|
|
30
|
+
"@object-ui/fields": "2.0.0",
|
|
31
|
+
"@object-ui/react": "2.0.0",
|
|
32
|
+
"@object-ui/types": "2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^18.0.0 || ^19.0.0",
|
|
36
36
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/react": "^19.2.
|
|
39
|
+
"@types/react": "^19.2.13",
|
|
40
40
|
"@types/react-dom": "^19.2.3",
|
|
41
41
|
"@vitejs/plugin-react": "^5.1.3",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
43
|
"vite": "^7.3.1",
|
|
44
44
|
"vite-plugin-dts": "^4.5.4",
|
|
45
|
-
"@object-ui/data-objectstack": "0.
|
|
45
|
+
"@object-ui/data-objectstack": "2.0.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"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
|
});
|
package/src/CalendarView.tsx
CHANGED
|
@@ -40,6 +40,7 @@ export interface CalendarViewProps {
|
|
|
40
40
|
events?: CalendarEvent[]
|
|
41
41
|
view?: "month" | "week" | "day"
|
|
42
42
|
currentDate?: Date
|
|
43
|
+
locale?: string
|
|
43
44
|
onEventClick?: (event: CalendarEvent) => void
|
|
44
45
|
onDateClick?: (date: Date) => void
|
|
45
46
|
onViewChange?: (view: "month" | "week" | "day") => void
|
|
@@ -52,6 +53,7 @@ function CalendarView({
|
|
|
52
53
|
events = [],
|
|
53
54
|
view = "month",
|
|
54
55
|
currentDate = new Date(),
|
|
56
|
+
locale = "default",
|
|
55
57
|
onEventClick,
|
|
56
58
|
onDateClick,
|
|
57
59
|
onViewChange,
|
|
@@ -110,7 +112,7 @@ function CalendarView({
|
|
|
110
112
|
|
|
111
113
|
const getDateLabel = () => {
|
|
112
114
|
if (selectedView === "month") {
|
|
113
|
-
return selectedDate.toLocaleDateString(
|
|
115
|
+
return selectedDate.toLocaleDateString(locale, {
|
|
114
116
|
month: "long",
|
|
115
117
|
year: "numeric",
|
|
116
118
|
})
|
|
@@ -118,16 +120,16 @@ function CalendarView({
|
|
|
118
120
|
const weekStart = getWeekStart(selectedDate)
|
|
119
121
|
const weekEnd = new Date(weekStart)
|
|
120
122
|
weekEnd.setDate(weekEnd.getDate() + 6)
|
|
121
|
-
return `${weekStart.toLocaleDateString(
|
|
123
|
+
return `${weekStart.toLocaleDateString(locale, {
|
|
122
124
|
month: "short",
|
|
123
125
|
day: "numeric",
|
|
124
|
-
})} - ${weekEnd.toLocaleDateString(
|
|
126
|
+
})} - ${weekEnd.toLocaleDateString(locale, {
|
|
125
127
|
month: "short",
|
|
126
128
|
day: "numeric",
|
|
127
129
|
year: "numeric",
|
|
128
130
|
})}`
|
|
129
131
|
} else {
|
|
130
|
-
return selectedDate.toLocaleDateString(
|
|
132
|
+
return selectedDate.toLocaleDateString(locale, {
|
|
131
133
|
weekday: "long",
|
|
132
134
|
month: "long",
|
|
133
135
|
day: "numeric",
|
|
@@ -429,7 +431,7 @@ function WeekView({ date, events, onEventClick, onDateClick }: WeekViewProps) {
|
|
|
429
431
|
className="p-3 text-center border-r last:border-r-0"
|
|
430
432
|
>
|
|
431
433
|
<div className="text-sm font-medium text-muted-foreground">
|
|
432
|
-
{day.toLocaleDateString(
|
|
434
|
+
{day.toLocaleDateString(locale, { weekday: "short" })}
|
|
433
435
|
</div>
|
|
434
436
|
<div
|
|
435
437
|
className={cn(
|
|
@@ -11,19 +11,23 @@ const BASE_URL = 'http://localhost';
|
|
|
11
11
|
|
|
12
12
|
// --- Mock Data ---
|
|
13
13
|
|
|
14
|
+
// Create a stable date at noon to avoid day-spanning issues when tests run late at night
|
|
15
|
+
const todayAtNoon = new Date();
|
|
16
|
+
todayAtNoon.setHours(12, 0, 0, 0);
|
|
17
|
+
|
|
14
18
|
const mockEvents = {
|
|
15
19
|
value: [
|
|
16
20
|
{
|
|
17
21
|
_id: '1',
|
|
18
22
|
title: 'Meeting with Client',
|
|
19
|
-
start:
|
|
20
|
-
end: new Date(
|
|
23
|
+
start: todayAtNoon.toISOString(),
|
|
24
|
+
end: new Date(todayAtNoon.getTime() + 3600000).toISOString(),
|
|
21
25
|
type: 'business'
|
|
22
26
|
},
|
|
23
27
|
{
|
|
24
28
|
_id: '2',
|
|
25
29
|
title: 'Team Lunch',
|
|
26
|
-
start: new Date(
|
|
30
|
+
start: new Date(todayAtNoon.getTime() + 86400000).toISOString(), // Tomorrow
|
|
27
31
|
type: 'personal'
|
|
28
32
|
}
|
|
29
33
|
]
|
|
@@ -46,7 +50,7 @@ const handlers = [
|
|
|
46
50
|
}),
|
|
47
51
|
|
|
48
52
|
// Metadata Query
|
|
49
|
-
http.get(`${BASE_URL}/api/v1/
|
|
53
|
+
http.get(`${BASE_URL}/api/v1/metadata/object/events`, () => {
|
|
50
54
|
return HttpResponse.json({ fields: {} });
|
|
51
55
|
})
|
|
52
56
|
];
|
package/src/index.tsx
CHANGED
|
@@ -32,7 +32,17 @@ export const ObjectCalendarRenderer: React.FC<{ schema: any }> = ({ schema }) =>
|
|
|
32
32
|
ComponentRegistry.register('object-calendar', ObjectCalendarRenderer, {
|
|
33
33
|
namespace: 'plugin-calendar',
|
|
34
34
|
label: 'Object Calendar',
|
|
35
|
-
category: '
|
|
35
|
+
category: 'view',
|
|
36
|
+
inputs: [
|
|
37
|
+
{ name: 'objectName', type: 'string', label: 'Object Name', required: true },
|
|
38
|
+
{ name: 'calendar', type: 'object', label: 'Calendar Config', description: 'startDateField, endDateField, titleField, colorField' },
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
ComponentRegistry.register('calendar', ObjectCalendarRenderer, {
|
|
43
|
+
namespace: 'view',
|
|
44
|
+
label: 'Calendar View',
|
|
45
|
+
category: 'view',
|
|
36
46
|
inputs: [
|
|
37
47
|
{ name: 'objectName', type: 'string', label: 'Object Name', required: true },
|
|
38
48
|
{ name: 'calendar', type: 'object', label: 'Calendar Config', description: 'startDateField, endDateField, titleField, colorField' },
|