@object-ui/plugin-calendar 0.3.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/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +946 -0
- package/dist/index.umd.cjs +6 -0
- package/dist/src/CalendarView.d.ts +29 -0
- package/dist/src/CalendarView.d.ts.map +1 -0
- package/dist/src/ObjectCalendar.d.ts +13 -0
- package/dist/src/ObjectCalendar.d.ts.map +1 -0
- package/dist/src/calendar-view-renderer.d.ts +9 -0
- package/dist/src/calendar-view-renderer.d.ts.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/package.json +53 -0
- package/src/CalendarView.tsx +504 -0
- package/src/ObjectCalendar.tsx +385 -0
- package/src/calendar-view-renderer.tsx +231 -0
- package/src/index.tsx +37 -0
- package/tsconfig.json +18 -0
- package/vite.config.ts +50 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(_,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react"),require("@object-ui/core"),require("lucide-react"),require("@object-ui/components")):typeof define=="function"&&define.amd?define(["exports","react","@object-ui/core","lucide-react","@object-ui/components"],p):(_=typeof globalThis<"u"?globalThis:_||self,p(_.ObjectUIPluginCalendar={},_.React,_.ObjectUICore,_.LucideReact,_.ObjectUIComponents))})(this,(function(_,p,ee,te,N){"use strict";function ue(e){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const f=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(l,n,f.get?f:{enumerable:!0,get:()=>e[n]})}}return l.default=e,Object.freeze(l)}const re=ue(p);var U={exports:{}},Y={};var ne;function fe(){if(ne)return Y;ne=1;var e=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function n(f,g,c){var m=null;if(c!==void 0&&(m=""+c),g.key!==void 0&&(m=""+g.key),"key"in g){c={};for(var a in g)a!=="key"&&(c[a]=g[a])}else c=g;return g=c.ref,{$$typeof:e,type:f,key:m,ref:g!==void 0?g:null,props:c}}return Y.Fragment=l,Y.jsx=n,Y.jsxs=n,Y}var $={};var ae;function me(){return ae||(ae=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===b?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case M:return"Fragment";case C:return"Profiler";case s:return"StrictMode";case X:return"Suspense";case q:return"SuspenseList";case D: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 A:return"Portal";case I:return t.displayName||"Context";case P:return(t._context.displayName||"Context")+".Consumer";case R:var d=t.render;return t=t.displayName,t||(t=d.displayName||d.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Q:return d=t.displayName||null,d!==null?d:e(t.type)||"Memo";case W:d=t._payload,t=t._init;try{return e(t(d))}catch{}}return null}function l(t){return""+t}function n(t){try{l(t);var d=!1}catch{d=!0}if(d){d=console;var h=d.error,y=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return h.call(d,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",y),l(t)}}function f(t){if(t===M)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===W)return"<...>";try{var d=e(t);return d?"<"+d+">":"<...>"}catch{return"<...>"}}function g(){var t=x.A;return t===null?null:t.getOwner()}function c(){return Error("react-stack-top-frame")}function m(t){if(k.call(t,"key")){var d=Object.getOwnPropertyDescriptor(t,"key").get;if(d&&d.isReactWarning)return!1}return t.key!==void 0}function a(t,d){function h(){O||(O=!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)",d))}h.isReactWarning=!0,Object.defineProperty(t,"key",{get:h,configurable:!0})}function o(){var t=e(this.type);return V[t]||(V[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 u(t,d,h,y,J,Z){var j=h.ref;return t={$$typeof:F,type:t,key:d,props:h,_owner:y},(j!==void 0?j:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:o}):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:Z}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function i(t,d,h,y,J,Z){var j=d.children;if(j!==void 0)if(y)if(v(j)){for(y=0;y<j.length;y++)T(j[y]);Object.freeze&&Object.freeze(j)}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 T(j);if(k.call(d,"key")){j=e(t);var L=Object.keys(d).filter(function(we){return we!=="key"});y=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",de[j+y]||(L=0<L.length?"{"+L.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,y,j,L,j),de[j+y]=!0)}if(j=null,h!==void 0&&(n(h),j=""+h),m(d)&&(n(d.key),j=""+d.key),"key"in d){h={};for(var K in d)K!=="key"&&(h[K]=d[K])}else h=d;return j&&a(h,typeof t=="function"?t.displayName||t.name||"Unknown":t),u(t,j,h,g(),J,Z)}function T(t){S(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===W&&(t._payload.status==="fulfilled"?S(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function S(t){return typeof t=="object"&&t!==null&&t.$$typeof===F}var w=p,F=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),M=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),I=Symbol.for("react.context"),R=Symbol.for("react.forward_ref"),X=Symbol.for("react.suspense"),q=Symbol.for("react.suspense_list"),Q=Symbol.for("react.memo"),W=Symbol.for("react.lazy"),D=Symbol.for("react.activity"),b=Symbol.for("react.client.reference"),x=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,k=Object.prototype.hasOwnProperty,v=Array.isArray,E=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(t){return t()}};var O,V={},H=w.react_stack_bottom_frame.bind(w,c)(),z=E(f(c)),de={};$.Fragment=M,$.jsx=function(t,d,h){var y=1e4>x.recentlyCreatedOwnerStacks++;return i(t,d,h,!1,y?Error("react-stack-top-frame"):H,y?E(f(t)):z)},$.jsxs=function(t,d,h){var y=1e4>x.recentlyCreatedOwnerStacks++;return i(t,d,h,!0,y?Error("react-stack-top-frame"):H,y?E(f(t)):z)}})()),$}var le;function ge(){return le||(le=1,process.env.NODE_ENV==="production"?U.exports=fe():U.exports=me()),U.exports}var r=ge();function pe(e){return e.data?e.data:e.staticData?{provider:"value",items:e.staticData}:e.objectName?{provider:"object",object:e.objectName}:null}function be(e){if(e){if(typeof e=="string"){const l=e.split(" "),n=l[0],f=l[1]?.toLowerCase()==="desc"?"desc":"asc";return{[n]:f}}if(Array.isArray(e))return e.reduce((l,n)=>(n.field&&n.order&&(l[n.field]=n.order),l),{})}}function xe(e){return e.filter&&typeof e.filter=="object"&&"calendar"in e.filter?e.filter.calendar:e.calendar?e.calendar:null}const oe=({schema:e,dataSource:l,className:n,onEventClick:f,onDateClick:g})=>{const[c,m]=p.useState([]),[a,o]=p.useState(!0),[u,i]=p.useState(null),[T,S]=p.useState(null),[w,F]=p.useState(new Date),[A,M]=p.useState("month"),s=pe(e),C=xe(e),P=s?.provider==="value";p.useEffect(()=>{(async()=>{try{if(o(!0),P&&s?.provider==="value"){m(s.items),o(!1);return}if(!l)throw new Error("DataSource required for object/api providers");if(s?.provider==="object"){const b=s.object,x=await l.find(b,{$filter:e.filter,$orderby:be(e.sort)});m(x?.data||[])}else s?.provider==="api"&&(console.warn("API provider not yet implemented for ObjectCalendar"),m([]));o(!1)}catch(b){i(b),o(!1)}})()},[s,l,P,e.filter,e.sort]),p.useEffect(()=>{!P&&l&&(async()=>{try{if(!l)return;const b=s?.provider==="object"?s.object:e.objectName;if(!b)return;const x=await l.getObjectSchema(b);S(x)}catch(b){console.error("Failed to fetch object schema:",b)}})()},[e.objectName,l,P,s]);const I=p.useMemo(()=>{if(!C||!c.length)return[];const{startDateField:D,endDateField:b,titleField:x,colorField:k}=C;return c.map((v,E)=>{const O=v[D],V=b?v[b]:null,H=v[x]||"Untitled",z=k?v[k]:void 0;return{id:v.id||v._id||`event-${E}`,title:H,start:O?new Date(O):new Date,end:V?new Date(V):void 0,color:z,allDay:!V,data:v}}).filter(v=>!isNaN(v.start.getTime()))},[c,C]),R=p.useMemo(()=>{const D=w.getFullYear(),b=w.getMonth(),x=new Date(D,b,1),k=new Date(x);k.setDate(k.getDate()-k.getDay());const v=[],E=new Date(k);for(let O=0;O<42;O++)v.push(new Date(E)),E.setDate(E.getDate()+1);return v},[w]),X=p.useCallback(D=>I.filter(b=>{const x=new Date(b.start);x.setHours(0,0,0,0);const k=b.end?new Date(b.end):x;k.setHours(23,59,59,999);const v=new Date(D);return v.setHours(0,0,0,0),v>=x&&v<=k}),[I]),q=p.useCallback(D=>{F(b=>{const x=new Date(b);return x.setMonth(x.getMonth()+(D==="next"?1:-1)),x})},[]);if(a)return r.jsx("div",{className:n,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsx("div",{className:"text-muted-foreground",children:"Loading calendar..."})})});if(u)return r.jsx("div",{className:n,children:r.jsx("div",{className:"flex items-center justify-center h-96",children:r.jsxs("div",{className:"text-destructive",children:["Error: ",u.message]})})});if(!C)return r.jsx("div",{className:n,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."})})});const Q=["January","February","March","April","May","June","July","August","September","October","November","December"],W=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return r.jsx("div",{className:n,children:r.jsxs("div",{className:"border rounded-lg bg-background",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[r.jsxs("h2",{className:"text-xl font-semibold",children:[Q[w.getMonth()]," ",w.getFullYear()]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>q("prev"),className:"px-3 py-1 border rounded hover:bg-muted",children:"Previous"}),r.jsx("button",{onClick:()=>F(new Date),className:"px-3 py-1 border rounded hover:bg-muted",children:"Today"}),r.jsx("button",{onClick:()=>q("next"),className:"px-3 py-1 border rounded hover:bg-muted",children:"Next"})]})]}),r.jsxs("div",{className:"p-4",children:[r.jsx("div",{className:"grid grid-cols-7 gap-px mb-px",children:W.map(D=>r.jsx("div",{className:"text-center text-sm font-medium text-muted-foreground py-2",children:D},D))}),r.jsx("div",{className:"grid grid-cols-7 gap-px bg-border",children:R.map((D,b)=>{const x=X(D),k=D.getMonth()===w.getMonth(),v=D.getDate()===new Date().getDate()&&D.getMonth()===new Date().getMonth()&&D.getFullYear()===new Date().getFullYear();return r.jsxs("div",{className:`min-h-24 bg-background p-2 ${k?"":"text-muted-foreground bg-muted/30"} ${v?"ring-2 ring-primary":""}`,onClick:()=>g?.(D),children:[r.jsx("div",{className:"text-sm font-medium mb-1",children:D.getDate()}),r.jsxs("div",{className:"space-y-1",children:[x.slice(0,3).map(E=>r.jsx("div",{className:"text-xs px-1 py-0.5 rounded bg-primary/10 hover:bg-primary/20 cursor-pointer truncate",onClick:O=>{O.stopPropagation(),f?.(E.data)},style:E.color?{borderLeft:`3px solid ${E.color}`}:void 0,children:E.title},E.id)),x.length>3&&r.jsxs("div",{className:"text-xs text-muted-foreground",children:["+",x.length-3," more"]})]})]},b)})})]})]})})},G="bg-blue-500 text-white";function ie({events:e=[],view:l="month",currentDate:n=new Date,onEventClick:f,onDateClick:g,onViewChange:c,onNavigate:m,className:a}){const[o,u]=re.useState(l),[i,T]=re.useState(n),S=()=>{const s=new Date(i);o==="month"?s.setMonth(s.getMonth()-1):o==="week"?s.setDate(s.getDate()-7):s.setDate(s.getDate()-1),T(s),m?.(s)},w=()=>{const s=new Date(i);o==="month"?s.setMonth(s.getMonth()+1):o==="week"?s.setDate(s.getDate()+7):s.setDate(s.getDate()+1),T(s),m?.(s)},F=()=>{const s=new Date;T(s),m?.(s)},A=s=>{u(s),c?.(s)},M=()=>{if(o==="month")return i.toLocaleDateString("default",{month:"long",year:"numeric"});if(o==="week"){const s=se(i),C=new Date(s);return C.setDate(C.getDate()+6),`${s.toLocaleDateString("default",{month:"short",day:"numeric"})} - ${C.toLocaleDateString("default",{month:"short",day:"numeric",year:"numeric"})}`}else return i.toLocaleDateString("default",{weekday:"long",month:"long",day:"numeric",year:"numeric"})};return r.jsxs("div",{className:N.cn("flex flex-col h-full bg-background",a),children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(N.Button,{variant:"outline",size:"sm",onClick:F,children:"Today"}),r.jsxs("div",{className:"flex items-center",children:[r.jsx(N.Button,{variant:"ghost",size:"icon",onClick:S,className:"h-8 w-8",children:r.jsx(te.ChevronLeftIcon,{className:"h-4 w-4"})}),r.jsx(N.Button,{variant:"ghost",size:"icon",onClick:w,className:"h-8 w-8",children:r.jsx(te.ChevronRightIcon,{className:"h-4 w-4"})})]}),r.jsx("h2",{className:"text-lg font-semibold ml-2",children:M()})]}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(N.Select,{value:o,onValueChange:A,children:[r.jsx(N.SelectTrigger,{className:"w-32",children:r.jsx(N.SelectValue,{})}),r.jsxs(N.SelectContent,{children:[r.jsx(N.SelectItem,{value:"day",children:"Day"}),r.jsx(N.SelectItem,{value:"week",children:"Week"}),r.jsx(N.SelectItem,{value:"month",children:"Month"})]})]})})]}),r.jsxs("div",{className:"flex-1 overflow-auto",children:[o==="month"&&r.jsx(he,{date:i,events:e,onEventClick:f,onDateClick:g}),o==="week"&&r.jsx(ve,{date:i,events:e,onEventClick:f,onDateClick:g}),o==="day"&&r.jsx(ye,{date:i,events:e,onEventClick:f})]})]})}function se(e){const l=new Date(e),n=l.getDay(),f=l.getDate()-n;return l.setDate(f),l}function De(e){const l=e.getFullYear(),n=e.getMonth(),f=new Date(l,n,1),g=new Date(l,n+1,0),c=f.getDay(),m=[];for(let o=c-1;o>=0;o--){const u=new Date(f.getTime());u.setDate(u.getDate()-(o+1)),m.push(u)}for(let o=1;o<=g.getDate();o++)m.push(new Date(l,n,o));const a=42-m.length;for(let o=1;o<=a;o++){const u=new Date(g.getTime());u.setDate(u.getDate()+o),m.push(u)}return m}function ce(e,l){return e.getFullYear()===l.getFullYear()&&e.getMonth()===l.getMonth()&&e.getDate()===l.getDate()}function B(e,l){return l.filter(n=>{const f=new Date(n.start),g=n.end?new Date(n.end):new Date(f),c=new Date(e);c.setHours(0,0,0,0);const m=new Date(e);m.setHours(23,59,59,999);const a=new Date(f);a.setHours(0,0,0,0);const o=new Date(g);return o.setHours(23,59,59,999),c<=o&&m>=a})}function he({date:e,events:l,onEventClick:n,onDateClick:f}){const g=De(e),c=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:g.map((a,o)=>{const u=B(a,l),i=a.getMonth()===e.getMonth(),T=ce(a,c);return r.jsxs("div",{className:N.cn("border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50",!i&&"bg-muted/30 text-muted-foreground"),onClick:()=>f?.(a),children:[r.jsx("div",{className:N.cn("text-sm font-medium mb-1",T&&"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:[u.slice(0,3).map(S=>r.jsx("div",{className:N.cn("text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80",S.color||G),style:S.color&&S.color.startsWith("#")?{backgroundColor:S.color}:void 0,onClick:w=>{w.stopPropagation(),n?.(S)},children:S.title},S.id)),u.length>3&&r.jsxs("div",{className:"text-xs text-muted-foreground px-2",children:["+",u.length-3," more"]})]})]},o)})})]})}function ve({date:e,events:l,onEventClick:n,onDateClick:f}){const g=se(e),c=Array.from({length:7},(a,o)=>{const u=new Date(g);return u.setDate(u.getDate()+o),u}),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:c.map(a=>{const o=ce(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:N.cn("text-lg font-semibold mt-1",o&&"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:c.map(a=>{const o=B(a,l);return r.jsx("div",{className:"border-r last:border-r-0 p-2 min-h-[400px] cursor-pointer hover:bg-accent/50",onClick:()=>f?.(a),children:r.jsx("div",{className:"space-y-2",children:o.map(u=>r.jsxs("div",{className:N.cn("text-sm px-3 py-2 rounded cursor-pointer hover:opacity-80",u.color||G),style:u.color&&u.color.startsWith("#")?{backgroundColor:u.color}:void 0,onClick:i=>{i.stopPropagation(),n?.(u)},children:[r.jsx("div",{className:"font-medium",children:u.title}),!u.allDay&&r.jsx("div",{className:"text-xs opacity-90 mt-1",children:u.start.toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"})})]},u.id))})},a.toISOString())})})]})}function ye({date:e,events:l,onEventClick:n}){const f=B(e,l),g=Array.from({length:24},(c,m)=>m);return r.jsx("div",{className:"flex flex-col h-full",children:r.jsx("div",{className:"flex-1 overflow-auto",children:g.map(c=>{const m=f.filter(a=>a.allDay?c===0:a.start.getHours()===c);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:c===0?"12 AM":c<12?`${c} AM`:c===12?"12 PM":`${c-12} PM`}),r.jsx("div",{className:"flex-1 p-2 space-y-2",children:m.map(a=>r.jsxs("div",{className:N.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:()=>n?.(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))})]},c)})})})}ee.ComponentRegistry.register("calendar-view",({schema:e,className:l,onAction:n,...f})=>{const g=p.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((i,T)=>{const S=e.titleField||"title",w=e.startDateField||"start",F=e.endDateField||"end",A=e.colorField||"color",M=e.allDayField||"allDay",s=i[S]||"Untitled",C=i[w]?new Date(i[w]):new Date,P=i[F]?new Date(i[F]):void 0,I=i[M]!==void 0?i[M]:!1;let R=i[A];return R&&e.colorMapping&&e.colorMapping[R]&&(R=e.colorMapping[R]),{id:String(i.id||i._id||T),title:s,start:C,end:P,allDay:I,color:R,data:i}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField,e.colorMapping]),c=p.useCallback(i=>{n&&n({type:"event_click",payload:{event:i.data,eventId:i.id}}),e.onEventClick&&e.onEventClick(i.data)},[n,e]),m=p.useCallback(i=>{n&&n({type:"date_click",payload:{date:i}}),e.onDateClick&&e.onDateClick(i)},[n,e]),a=p.useCallback(i=>{n&&n({type:"view_change",payload:{view:i}}),e.onViewChange&&e.onViewChange(i)},[n,e]),o=p.useCallback(i=>{n&&n({type:"navigate",payload:{date:i}}),e.onNavigate&&e.onNavigate(i)},[n,e]),u=e.view&&["month","week","day"].includes(e.view)?e.view:"month";return r.jsx(ie,{events:g,view:u,currentDate:e.currentDate?new Date(e.currentDate):void 0,onEventClick:c,onDateClick:e.allowCreate||e.onDateClick?m:void 0,onViewChange:a,onNavigate:o,className:l,...f})},{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 je=({schema:e})=>r.jsx(oe,{schema:e,dataSource:null});ee.ComponentRegistry.register("object-calendar",je,{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"}]}),_.CalendarView=ie,_.ObjectCalendar=oe,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export interface CalendarEvent {
|
|
9
|
+
id: string | number;
|
|
10
|
+
title: string;
|
|
11
|
+
start: Date;
|
|
12
|
+
end?: Date;
|
|
13
|
+
allDay?: boolean;
|
|
14
|
+
color?: string;
|
|
15
|
+
data?: any;
|
|
16
|
+
}
|
|
17
|
+
export interface CalendarViewProps {
|
|
18
|
+
events?: CalendarEvent[];
|
|
19
|
+
view?: "month" | "week" | "day";
|
|
20
|
+
currentDate?: Date;
|
|
21
|
+
onEventClick?: (event: CalendarEvent) => void;
|
|
22
|
+
onDateClick?: (date: Date) => void;
|
|
23
|
+
onViewChange?: (view: "month" | "week" | "day") => void;
|
|
24
|
+
onNavigate?: (date: Date) => void;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
declare function CalendarView({ events, view, currentDate, onEventClick, onDateClick, onViewChange, onNavigate, className, }: CalendarViewProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export { CalendarView };
|
|
29
|
+
//# sourceMappingURL=CalendarView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CalendarView.d.ts","sourceRoot":"","sources":["../../src/CalendarView.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,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,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,SAAS,GACV,EAAE,iBAAiB,2CA2InB;AA8TD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ObjectGridSchema, DataSource } from '@object-ui/types';
|
|
3
|
+
export interface ObjectCalendarProps {
|
|
4
|
+
schema: ObjectGridSchema;
|
|
5
|
+
dataSource?: DataSource;
|
|
6
|
+
className?: string;
|
|
7
|
+
onEventClick?: (record: any) => void;
|
|
8
|
+
onDateClick?: (date: Date) => void;
|
|
9
|
+
onEdit?: (record: any) => void;
|
|
10
|
+
onDelete?: (record: any) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const ObjectCalendar: React.FC<ObjectCalendarProps>;
|
|
13
|
+
//# sourceMappingURL=ObjectCalendar.d.ts.map
|
|
@@ -0,0 +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;AAE/F,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,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;CAClC;AAuED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAsRxD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=calendar-view-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-view-renderer.d.ts","sourceRoot":"","sources":["../../src/calendar-view-renderer.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ObjectCalendar, ObjectCalendarProps } from './ObjectCalendar';
|
|
2
|
+
export { ObjectCalendar };
|
|
3
|
+
export type { ObjectCalendarProps };
|
|
4
|
+
export { CalendarView } from './CalendarView';
|
|
5
|
+
export type { CalendarViewProps, CalendarEvent } from './CalendarView';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,0BAA0B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@object-ui/plugin-calendar",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Calendar view plugins for Object UI - includes both ObjectQL-integrated and standalone calendar components",
|
|
7
|
+
"homepage": "https://www.objectui.org",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/objectstack-ai/objectui.git",
|
|
11
|
+
"directory": "packages/plugin-calendar"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/objectstack-ai/objectui/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.umd.cjs",
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.umd.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"lucide-react": "^0.563.0",
|
|
28
|
+
"@object-ui/components": "0.3.0",
|
|
29
|
+
"@object-ui/core": "0.3.0",
|
|
30
|
+
"@object-ui/fields": "0.3.0",
|
|
31
|
+
"@object-ui/react": "0.3.0",
|
|
32
|
+
"@object-ui/types": "0.3.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
36
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.2.9",
|
|
40
|
+
"@types/react-dom": "^19.2.3",
|
|
41
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"vite": "^7.3.1",
|
|
44
|
+
"vite-plugin-dts": "^4.5.4"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "vite build",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"type-check": "tsc --noEmit",
|
|
51
|
+
"lint": "eslint ."
|
|
52
|
+
}
|
|
53
|
+
}
|