remons-calendar 1.0.0-beta.2 → 1.0.0-beta.4

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.
@@ -21,6 +21,6 @@ export interface DayCellProps {
21
21
  icons?: IconItem[];
22
22
  }
23
23
  /** 农历展示:节日 > 节气 > 当月月份名(初一)> 农历日 */
24
- export declare function getLunarText(dateStr: string): string;
24
+ export declare function getLunarText(dateStr: string, showMonth?: boolean): string;
25
25
  export declare function DayCell(props: DayCellProps): import("react").JSX.Element;
26
26
  //# sourceMappingURL=DayCell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DayCell.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/DayCell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,wBAAwB,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,cAAc,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa;IACb,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW;IACX,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAID,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYpD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,+BAwD1C"}
1
+ {"version":3,"file":"DayCell.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/DayCell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,wBAAwB,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,cAAc,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa;IACb,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW;IACX,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAID,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAezE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,+BAwD1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"DayPanel.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/DayPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,yBAAyB,CAAC;AAYjC,UAAU,aAAa;IACrB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iBAAiB;IACjB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,eAAe;IACf,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,UAAU,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EACP,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,aAAa,+BAgFf"}
1
+ {"version":3,"file":"DayPanel.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/DayPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,yBAAyB,CAAC;AAUjC,UAAU,aAAa;IACrB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iBAAiB;IACjB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,eAAe;IACf,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,UAAU,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EACP,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,aAAa,+BAkFf"}
@@ -1 +1 @@
1
- {"version":3,"file":"TodoLanes.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/TodoLanes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,wBAAwB,CAAC;AAEhC,UAAU,cAAc;IACtB,gBAAgB;IAChB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC;AAED,mBAAmB;AACnB,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc,+BAgC7D"}
1
+ {"version":3,"file":"TodoLanes.d.ts","sourceRoot":"","sources":["../../../src/components/Calendar/TodoLanes.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,wBAAwB,CAAC;AAEhC,UAAU,cAAc;IACtB,gBAAgB;IAChB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC;AAED,mBAAmB;AACnB,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc,+BAoC7D"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("react"),c=require("antd"),E=require("dayjs"),pe=require("lunar-javascript"),oe=require("@ant-design/icons"),xe="holiday_cache_v2_",ye=n=>`${xe}${n}`;async function je(n){const t=ye(n),s=localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch{localStorage.removeItem(t)}localStorage.removeItem(`holiday_cache_${n}`);const l=await fetch(`https://timor.tech/api/holiday/year/${n}`);if(!l.ok)throw new Error(`节假日接口请求失败: ${l.status}`);const a=await l.json(),u=(a==null?void 0:a.holiday)??(a==null?void 0:a.data)??{},i={};return Object.entries(u).forEach(([d,p])=>{if(!p||typeof p!="object")return;const[x,h]=d.split("-"),j=x==null?void 0:x.padStart(2,"0"),r=h==null?void 0:h.padStart(2,"0");!j||!r||j.length!==2||r.length!==2||(i[`${n}-${j}-${r}`]={holiday:!!p.holiday,name:String(p.name??""),target:p.target!=null?String(p.target):void 0})}),Object.keys(i).length>0?localStorage.setItem(t,JSON.stringify(i)):localStorage.removeItem(t),i}const F=n=>n.format("YYYY-MM-DD"),le=n=>n.startTime??"00:00";function J(n){return n.startTime&&n.endTime?`${n.startTime}-${n.endTime}`:n.startTime??n.endTime??""}function ge(n,t){const l=E(`${n}-${t+1}-01`).startOf("week");return Array.from({length:42},(a,u)=>{const i=l.add(u,"day");return{date:i,inMonth:i.month()===t}})}function Se(n,t){const s=new Date(`${n}T00:00:00`);s.setDate(s.getDate()+t);const l=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${l}-${a}-${u}`}function Te(n){const t=Object.keys(n).sort(),s=u=>n[u],l=u=>{const i=Se(u,-1),d=s(i);if(d)return!d.holiday;const p=n[u].target??"";return p?!t.some(x=>{if(x>=u)return!1;const h=s(x);return!!h&&h.holiday&&(h.target??"")===p}):!0},a={};return t.forEach(u=>{const i=n[u];if(i){if(!i.holiday){a[u]={name:"",off:!1};return}a[u]={name:l(u)?i.name:"",off:!0}}}),a}function Ee(n,t){const[s,l]=v.useState(()=>{try{const a=localStorage.getItem(n);return a?JSON.parse(a):t}catch{return t}});return v.useEffect(()=>{try{localStorage.setItem(n,JSON.stringify(s))}catch{}},[n,s]),[s,l]}const U=["#f5222d","#fa8c16","#fadb14","#52c41a","#13c2c2","#1677ff","#722ed1","#eb2f96"];function ve({value:n=U[5],onChange:t}){return e.jsx("div",{className:"color-swatches",children:U.map(s=>e.jsx("span",{className:`swatch ${n===s?"active":""}`,style:{background:s},onClick:()=>t==null?void 0:t(s)},s))})}function Me({open:n,editing:t,initialStart:s,initialEnd:l,onClose:a,onSave:u,onDelete:i}){const[d]=c.Form.useForm(),p=!!t;v.useEffect(()=>{n&&setTimeout(()=>{t?d.setFieldsValue({name:t.name,start:E(t.start),end:E(t.end),startTime:t.startTime?E(t.startTime,"HH:mm"):null,endTime:t.endTime?E(t.endTime,"HH:mm"):null,color:t.color}):(d.setFieldsValue({color:U[5],start:s?E(s):E(),end:l?E(l):E().add(1,"day"),startTime:null,endTime:null}),d.resetFields(["name"]))},100)},[n,t,s,l,d]);const x={validator:(f,g)=>{const M=d.getFieldValue("start");return!g||!M||!g.isBefore(M,"day")?Promise.resolve():Promise.reject(new Error("结束日期不能早于开始日期"))}},h={validator:()=>{const f=d.getFieldValue("start"),g=d.getFieldValue("end");return!f||!g?Promise.resolve():g.isSame(f,"day")?Promise.reject(new Error("待办必须跨天(结束日期需晚于开始日期);单日事件请创建日程")):Promise.resolve()}},j={validator:(f,g)=>{var O;const M=d.getFieldValue("start"),T=d.getFieldValue("end");if(!M||!T||!T.isSame(M,"day"))return Promise.resolve();const D=((O=d.getFieldValue("startTime"))==null?void 0:O.format("HH:mm"))??"00:00";return((g==null?void 0:g.format("HH:mm"))??"24:00")<D?Promise.reject(new Error("结束时间不能早于开始时间")):Promise.resolve()}},r=async()=>{const f=await d.validateFields(),g=f.startTime,M=f.endTime;u({id:(t==null?void 0:t.id)??crypto.randomUUID(),name:f.name.trim(),start:f.start.format("YYYY-MM-DD"),end:f.end.format("YYYY-MM-DD"),startTime:g?g.format("HH:mm"):void 0,endTime:M?M.format("HH:mm"):void 0,color:f.color}),a()},m=()=>{t&&i(t.id),a()};return e.jsx(c.Modal,{title:p?"编辑待办":"添加待办",open:n,onCancel:a,okText:"保存",cancelText:"取消",destroyOnClose:!0,footer:e.jsxs(c.Space,{children:[p&&e.jsx(c.Button,{danger:!0,onClick:m,children:"删除"}),e.jsx(c.Button,{onClick:a,children:"取消"}),e.jsx(c.Button,{type:"primary",onClick:r,children:"保存"})]}),children:e.jsxs(c.Form,{form:d,layout:"vertical",preserve:!1,children:[e.jsx(c.Form.Item,{label:"事件名称",name:"name",rules:[{required:!0,message:"请输入事件名称"},{max:30}],children:e.jsx(c.Input,{placeholder:"如:年度项目冲刺",maxLength:30})}),e.jsxs(c.Row,{gutter:8,children:[e.jsx(c.Col,{span:12,children:e.jsx(c.Form.Item,{label:"开始日期",name:"start",dependencies:["end"],rules:[{required:!0,message:"请选择开始日期"},h],children:e.jsx(c.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})})}),e.jsx(c.Col,{span:12,children:e.jsx(c.Form.Item,{label:"开始时间",name:"startTime",children:e.jsx(c.TimePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:"首日开始时间,可选",allowClear:!0})})})]}),e.jsxs(c.Row,{gutter:8,children:[e.jsx(c.Col,{span:12,children:e.jsx(c.Form.Item,{label:"结束日期",name:"end",dependencies:["start"],rules:[{required:!0,message:"请选择结束日期"},x,h],children:e.jsx(c.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})})}),e.jsx(c.Col,{span:12,children:e.jsx(c.Form.Item,{label:"结束时间",name:"endTime",rules:[j],children:e.jsx(c.TimePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:"末日结束时间,可选",allowClear:!0})})})]}),e.jsx(c.Form.Item,{label:"颜色标记",name:"color",initialValue:U[5],children:e.jsx(ve,{})})]})})}function ke({icons:n,value:t,onChange:s}){return e.jsx("div",{className:"emoji-grid",children:n.map(({key:l,icon:a,tip:u})=>e.jsx("span",{className:t===l?"emoji-item active":"emoji-item",onClick:()=>s==null?void 0:s(l),title:u,children:a},l))})}function Ne({open:n,editing:t,initialDate:s,icons:l,onClose:a,onSave:u,onDelete:i}){const[d]=c.Form.useForm(),p=!!t,x=l.map(r=>r.key);v.useEffect(()=>{n&&setTimeout(()=>{t?d.setFieldsValue({icon:t.icon,date:E(t.date),name:t.name,timeRange:t.startTime&&t.endTime?[E(t.startTime,"HH:mm"),E(t.endTime,"HH:mm")]:null}):(d.setFieldsValue({icon:x[0],date:s?E(s):E(),timeRange:null}),d.resetFields(["name"]))},100)},[n,t,s,d,l]);const h=async()=>{const r=await d.validateFields(),m=r.timeRange;u({id:(t==null?void 0:t.id)??crypto.randomUUID(),icon:r.icon,date:r.date.format("YYYY-MM-DD"),name:r.name.trim(),startTime:m!=null&&m[0]?m[0].format("HH:mm"):void 0,endTime:m!=null&&m[1]?m[1].format("HH:mm"):void 0}),a()},j=()=>{t&&i(t.id),a()};return e.jsx(c.Modal,{title:p?"编辑日程":"添加日程",open:n,onOk:h,onCancel:a,okText:"保存",cancelText:"取消",destroyOnClose:!0,footer:e.jsxs(c.Space,{children:[p&&e.jsx(c.Button,{danger:!0,onClick:j,children:"删除"}),e.jsx(c.Button,{onClick:a,children:"取消"}),e.jsx(c.Button,{type:"primary",onClick:h,children:"保存"})]}),children:e.jsxs(c.Form,{form:d,layout:"vertical",preserve:!1,children:[e.jsx(c.Form.Item,{label:"图标",name:"icon",initialValue:x[0],rules:[{required:!0}],children:e.jsx(ke,{icons:l})}),e.jsx(c.Form.Item,{label:"日期",name:"date",rules:[{required:!0,message:"请选择日期"}],children:e.jsx(c.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})}),e.jsx(c.Form.Item,{label:"时间范围",name:"timeRange",children:e.jsx(c.TimePicker.RangePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:["开始时间","结束时间"],allowClear:!0})}),e.jsx(c.Form.Item,{label:"名称",name:"name",rules:[{required:!0,message:"请输入名称"},{max:30}],children:e.jsx(c.Input,{placeholder:"如:牙医复诊",maxLength:30})})]})})}const $e=2;function de(n){try{const[t,s,l]=n.split("-").map(Number),a=pe.Solar.fromYmd(t,s,l).getLunar(),u=a.getFestivals();if(u.length>0)return u[0];const i=a.getJieQi();return i||(a.getDay()===1?`${a.getMonthInChinese()}月初一`:a.getDayInChinese())}catch{return""}}function De(n){const{dateStr:t,day:s,inMonth:l,isToday:a,isWeekend:u,holiday:i,todoLanes:d,schedules:p,onEditSchedule:x,selected:h,onSelect:j,icons:r}=n,m=["day-cell"];l||m.push("out"),a&&m.push("today"),u&&m.push("weekend"),h&&m.push("selected"),i&&m.push(i!=null&&i.off?"holiday-off":"holiday-work");const f=p.slice(0,$e),g=p.length-f.length;return e.jsxs("div",{className:m.join(" "),onClick:M=>{M.stopPropagation(),j==null||j(t)},children:[e.jsxs("div",{className:"day-top",children:[e.jsx("span",{className:"day-num",children:s}),e.jsxs("span",{className:"day-lunar",children:[(i==null?void 0:i.name)||de(t),i&&e.jsx("div",{className:`day-holiday ${i.off?"off":"work"}`,children:i.off?"休":"班"})]})]}),d>0&&e.jsx("div",{className:"todo-spacer",style:{height:d*22}}),e.jsxs("div",{className:"schedule-list",children:[f.map(M=>{var T;return e.jsx(c.Tooltip,{title:[M.name,J(M)].filter(Boolean).join(" "),children:e.jsxs("span",{className:"schedule-item",onClick:D=>{D.stopPropagation(),x(M,t)},children:[e.jsx("span",{className:"schedule-icon",children:(T=r==null?void 0:r.find(D=>D.key===M.icon))==null?void 0:T.icon}),e.jsx("span",{className:"schedule-name",children:M.name})]})},M.id)}),g>0&&e.jsxs("span",{className:"schedule-more",children:["+",g," 更多"]})]})]})}function we({year:n,month:t,viewMode:s,loading:l,onViewModeChange:a,onToday:u,onPrevMonth:i,onNextMonth:d,isPreview:p}){return e.jsxs("div",{className:"calendar-header",children:[e.jsxs("span",{className:"calendar-title",children:[n,"年",t+1,"月"]}),e.jsx(c.Segmented,{size:"small",options:[{label:"日历",value:"all"},{label:"事项",value:"items"}],value:s,onChange:x=>a(x)}),!p&&e.jsxs(c.Space,{children:[e.jsx(c.Button,{shape:"circle",size:"small",onClick:u,children:"今"}),e.jsx(c.Button,{shape:"circle",size:"small",onClick:i,children:e.jsx(oe.LeftOutlined,{})}),e.jsx(c.Button,{shape:"circle",size:"small",onClick:d,children:e.jsx(oe.RightOutlined,{})}),l&&e.jsx(c.Spin,{size:"small"})]})]})}function be({segs:n,onEditTodo:t}){return e.jsx("div",{className:"todo-lanes",children:n.map((s,l)=>{const a=s.todo,u=`${a.start}${a.startTime?` ${a.startTime}`:""} ~ ${a.end}${a.endTime?` ${a.endTime}`:""}`,i=a.start===a.end?J(a):"";return e.jsx("span",{className:`todo-bar${s.roundLeft?" round-left":""}${s.roundRight?" round-right":""}`,title:`${a.name}(${u})`,style:{top:54+s.lane*22,left:`${s.leftEdge/7*100}%`,width:`${(Math.max(s.rightEdge,s.leftEdge)-s.leftEdge)/7*100}%`,background:a.color},onClick:d=>{d.stopPropagation(),t(a)},children:s.showLabel&&e.jsx("span",{className:"todo-bar-label",children:i?`${a.name} ${i}`:a.name})},`${a.id}-${l}`)})})}const Ie=["周日","周一","周二","周三","周四","周五","周六"];function ce(n,t){const s=E(n);return s.year()===t?`${s.month()+1}月${s.date()}日`:`${s.year()}年${s.month()+1}月${s.date()}日`}function Ye({dateStr:n,holiday:t,todos:s,schedules:l,onEditTodo:a,onEditSchedule:u,onAddTodo:i,onAddSchedule:d,isPreview:p,icons:x}){const h=E(n),j=h.year();return e.jsxs("div",{className:"day-panel",children:[e.jsxs("div",{className:"day-panel-header",children:[e.jsxs("div",{className:"day-panel-title",children:[h.year(),"年",h.month()+1,"月",h.date(),"日 ",Ie[h.day()],!p&&e.jsxs("div",{className:"day-panel-actions",children:[e.jsx(c.Button,{size:"small",onClick:i,children:"添加待办"}),e.jsx(c.Button,{size:"small",onClick:d,children:"添加日程"})]})]}),e.jsx("span",{className:"day-panel-sub",children:t!=null&&t.name?t.name:de(n)||" "})]}),!!(s!=null&&s.length)&&e.jsxs("div",{className:"day-panel-section",children:[e.jsxs("div",{className:"day-panel-subtitle",children:["待办(",s.length,")"]}),s.map(r=>e.jsxs("div",{className:"day-panel-todo",onClick:()=>a(r),title:"点击编辑",children:[e.jsx("span",{className:"day-panel-todo-dot",style:{background:r.color}}),e.jsx("span",{className:"day-panel-todo-name",children:r.name}),e.jsxs("span",{className:"day-panel-todo-range",children:[ce(r.start,j),r.startTime?` ${r.startTime}`:""," ~ ",ce(r.end,j),r.endTime?` ${r.endTime}`:""]})]},r.id))]}),!!l.length&&e.jsxs("div",{className:"day-panel-section",children:[e.jsxs("div",{className:"day-panel-subtitle",children:["日程(",l.length,")"]}),l.map(r=>{var m;return e.jsxs("div",{className:"day-panel-schedule",onClick:()=>u(r),title:"点击编辑",children:[e.jsx("span",{className:"day-panel-schedule-icon",children:(m=x==null?void 0:x.find(f=>f.key===r.icon))==null?void 0:m.icon}),e.jsx("span",{className:"day-panel-schedule-name",children:r.name}),J(r)&&e.jsx("span",{className:"day-panel-schedule-time",children:J(r)})]},r.id)})]}),l.length===0&&e.jsx(c.Empty,{image:c.Empty.PRESENTED_IMAGE_SIMPLE,description:"本月暂无待办和日程"})]})}function ie(n){const[t,s]=n.split(":").map(Number);return t*60+s}function Ce(n,t){const s=n.startTime?ie(n.startTime):0,l=n.endTime?ie(n.endTime):1440,a=F(t);return n.start===n.end?[s,l]:a===n.start?[s,1440]:a===n.end?[0,l]:[0,1440]}function Fe(n,t){const s={};t.forEach((r,m)=>{s[F(r.date)]=m});const l=F(t[0].date),a=F(t[t.length-1].date),u=Array.isArray(n)?n:[],i=new Array(t.length).fill(0),d=[],x=[...u].sort((r,m)=>{if(r.start!==m.start)return r.start.localeCompare(m.start);const f=r.startTime??"00:00",g=m.startTime??"00:00";return f!==g?f.localeCompare(g):r.end!==m.end?r.end.localeCompare(m.end):(r.endTime??"23:59").localeCompare(m.endTime??"23:59")}).filter(r=>!(r.end<l||r.start>a)).map(r=>({original:r,cs:r.start<l?l:r.start,ce:r.end>a?a:r.end})).filter(r=>{const m=s[r.cs],f=s[r.ce];return m!==void 0&&f!==void 0}),h=Math.ceil(t.length/7);for(let r=0;r<h;r++){const m=r*7,f=Math.min(m+6,t.length-1),g=Array.from({length:7},()=>[[],[],[]]),M=x.filter(T=>{const D=s[T.cs];return s[T.ce]>=m&&D<=f});for(const{original:T,cs:D,ce:N}of M){const O=s[D],$=s[N],I=Math.max(O,m)-m,w=Math.min($,f)-m,Y=[];for(let k=I;k<=w;k++)Y.push(Ce(T,t[m+k].date));let H=-1;for(let k=0;k<3;k++){let A=!0;for(let C=I;C<=w&&A;C++){const[P,b]=Y[C-I];P>=b||(A=!g[C][k].some(L=>L.s<b&&P<L.e))}if(A){H=k;break}}if(H===-1)continue;const R=O>=m&&D===T.start,q=$<=f&&N===T.end,[z]=Y[0],[,K]=Y[Y.length-1],G=I+(R?z/1440:0),V=q?w+K/1440:w+1;d.push({todo:T,weekRow:r,startCol:I,endCol:w,leftEdge:G,rightEdge:V,lane:H,showLabel:R,roundLeft:R,roundRight:q});for(let k=I;k<=w;k++){const[A,C]=Y[k-I];A<C&&g[k][H].push({s:A,e:C})}for(let k=I;k<=w;k++){const[A,C]=Y[k-I];if(A<C){const P=m+k;i[P]<H+1&&(i[P]=H+1)}}}}const j={};return t.forEach((r,m)=>{i[m]>0&&(j[F(r.date)]=i[m])}),{todoSegs:d,todoLanesByDate:j}}function He(n,t,s,l,a){const u=Array.isArray(n)?n:[],i=Array.isArray(t)?t:[],d=`${l}-${String(a+1).padStart(2,"0")}-01`,p=E(new Date(l,a+1,0)),x=`${p.year()}-${String(p.month()+1).padStart(2,"0")}-${String(p.date()).padStart(2,"0")}`,h=new Set;return u==null||u.forEach(j=>{const r=j.start<d?d:j.start,m=j.end>x?x:j.end;if(m<r)return;let f=E(r);for(;F(f)<=m;){const g=s[F(f)];g!==void 0&&h.add(Math.floor(g/7)),f=f.add(1,"day")}}),i.forEach(j=>{if(j.date>=d&&j.date<=x){const r=s[j.date];r!==void 0&&h.add(Math.floor(r/7))}}),h.size===0?null:{min:Math.min(...h),max:Math.max(...h)}}function Ae(n,t,s){if(t==="all")return n.map((a,u)=>({week:a,rowIndex:u}));if(!s)return[];const l=[];for(let a=s.min;a<=s.max;a++)l.push({week:n[a],rowIndex:a});return l}const Le=["日","一","二","三","四","五","六"];function Oe({todos:n,schedules:t,onChange:s,onSaveTodo:l,onDeleteTodo:a,onSaveSchedule:u,onDeleteSchedule:i,isPreview:d,icons:p}){const[x,h]=v.useState(E()),[j,r]=v.useState({}),[m,f]=v.useState(!1),[g,M]=Ee("calendar_view_mode",d?"items":"all"),[T,D]=v.useState(F(E())),[N,O]=v.useState(n??[]),[$,I]=v.useState(t??[]),[w,Y]=v.useState({open:!1,editing:null}),[H,R]=v.useState({open:!1,editing:null}),q=o=>{d||Y({open:!0,editing:o})},z=(o,y)=>{d||R({open:!0,editing:o})},K=o=>{d||Y({open:!0,editing:null,initialStart:o,initialEnd:E(o).add(1,"day").format("YYYY-MM-DD")})},G=o=>{d||R({open:!0,editing:null,initialDate:o})},V=(o,y)=>{O(o),I(y),s==null||s(o,y)},k=o=>{const y=N.some(S=>S.id===o.id)?N.map(S=>S.id===o.id?o:S):[...N,o];V(y,$),l==null||l(o)},A=o=>{const y=N.filter(S=>S.id!==o);V(y,$),a==null||a(o)},C=o=>{const y=$.some(S=>S.id===o.id)?$.map(S=>S.id===o.id?o:S):[...$,o];V(N,y),u==null||u(o)},P=o=>{const y=$.filter(S=>S.id!==o);V(N,y),i==null||i(o)},b=x.year(),L=x.month();v.useEffect(()=>{let o=!1;return f(!0),je(b).then(y=>{o||r(y)}).catch(()=>{o||r({})}).finally(()=>{o||f(!1)}),()=>{o=!0}},[b]);const _=v.useMemo(()=>ge(b,L),[b,L]),Q=v.useMemo(()=>Te(j),[j]),Z=v.useMemo(()=>{const o={};return $==null||$.forEach(y=>{var S;(o[S=y.date]??(o[S]=[])).push(y)}),Object.values(o).forEach(y=>y.sort((S,X)=>le(S).localeCompare(le(X)))),o},[$]),ee=v.useMemo(()=>{const o=[];for(let y=0;y<_.length;y+=7)o.push(_.slice(y,y+7));return o},[_]),{todoSegs:me,todoLanesByDate:ue}=v.useMemo(()=>Fe(N,_),[N,_]),te=F(E()),W=v.useMemo(()=>{const o={};return _.forEach((y,S)=>{o[F(y.date)]=S}),o},[_]),se=`${b}-${String(L+1).padStart(2,"0")}-01`;v.useEffect(()=>{if(!T||W[T]!==void 0)return;const o=te;D(W[o]!==void 0&&o.startsWith(se.slice(0,8))?o:se)},[b,L]);const he=o=>{D(y=>y===o?null:o)},ne=v.useMemo(()=>He(N,$,W,b,L),[N,$,b,L,W]),ae=v.useMemo(()=>Ae(ee,g,ne),[ee,g,ne]);return e.jsxs("div",{className:"calendar-container",children:[e.jsxs("div",{className:"calendar",children:[e.jsx(we,{isPreview:d,year:b,month:L,viewMode:g,loading:m,onViewModeChange:M,onToday:()=>h(E()),onPrevMonth:()=>h(x.subtract(1,"month")),onNextMonth:()=>h(x.add(1,"month"))}),e.jsx("div",{className:"week-row",children:Le.map(o=>e.jsx("div",{className:"week-cell",children:o},o))}),e.jsx("div",{className:"day-grid",children:ae.length===0?e.jsx("div",{className:"calendar-empty",children:e.jsx(c.Empty,{image:c.Empty.PRESENTED_IMAGE_SIMPLE,description:"本月暂无待办和日程"})}):ae.map(({week:o,rowIndex:y})=>e.jsxs("div",{className:"day-week",children:[o.map(({date:S,inMonth:X})=>{const B=F(S),re=S.day(),fe=re===0||re===6;return e.jsx(De,{dateStr:B,day:S.date(),inMonth:X,isToday:B===te,isWeekend:fe,holiday:Q[B],todoLanes:ue[B]??0,schedules:Z[B]??[],onEditSchedule:z,icons:p,selected:T===B,onSelect:he},B)}),e.jsx(be,{segs:me.filter(S=>S.weekRow===y),onEditTodo:q})]},y))})]}),T&&e.jsx(Ye,{dateStr:T,holiday:Q[T],todos:N==null?void 0:N.filter(o=>o.start<=T&&T<=o.end),schedules:Z[T]??[],onEditTodo:q,onEditSchedule:o=>z(o),onAddTodo:()=>K(T),onAddSchedule:()=>G(T),isPreview:d,icons:p}),e.jsx(Me,{open:w.open,editing:w.editing,initialStart:w.initialStart,initialEnd:w.initialEnd,onClose:()=>Y({open:!1,editing:null}),onSave:k,onDelete:A}),e.jsx(Ne,{open:H.open,editing:H.editing,initialDate:H.initialDate,icons:p||[],onClose:()=>R({open:!1,editing:null}),onSave:C,onDelete:P})]})}exports.Calendar=Oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("react"),i=require("antd"),E=require("dayjs"),pe=require("lunar-javascript"),oe=require("@ant-design/icons"),xe="holiday_cache_v2_",ye=n=>`${xe}${n}`;async function je(n){const t=ye(n),s=localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch{localStorage.removeItem(t)}localStorage.removeItem(`holiday_cache_${n}`);const l=await fetch(`https://timor.tech/api/holiday/year/${n}`);if(!l.ok)throw new Error(`节假日接口请求失败: ${l.status}`);const a=await l.json(),d=(a==null?void 0:a.holiday)??(a==null?void 0:a.data)??{},m={};return Object.entries(d).forEach(([c,p])=>{if(!p||typeof p!="object")return;const[x,h]=c.split("-"),j=x==null?void 0:x.padStart(2,"0"),r=h==null?void 0:h.padStart(2,"0");!j||!r||j.length!==2||r.length!==2||(m[`${n}-${j}-${r}`]={holiday:!!p.holiday,name:String(p.name??""),target:p.target!=null?String(p.target):void 0})}),Object.keys(m).length>0?localStorage.setItem(t,JSON.stringify(m)):localStorage.removeItem(t),m}const F=n=>n.format("YYYY-MM-DD"),le=n=>n.startTime??"00:00";function J(n){return n.startTime&&n.endTime?`${n.startTime}-${n.endTime}`:n.startTime??n.endTime??""}function ge(n,t){const l=E(`${n}-${t+1}-01`).startOf("week");return Array.from({length:42},(a,d)=>{const m=l.add(d,"day");return{date:m,inMonth:m.month()===t}})}function Se(n,t){const s=new Date(`${n}T00:00:00`);s.setDate(s.getDate()+t);const l=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${l}-${a}-${d}`}function Te(n){const t=Object.keys(n).sort(),s=d=>n[d],l=d=>{const m=Se(d,-1),c=s(m);if(c)return!c.holiday;const p=n[d].target??"";return p?!t.some(x=>{if(x>=d)return!1;const h=s(x);return!!h&&h.holiday&&(h.target??"")===p}):!0},a={};return t.forEach(d=>{const m=n[d];if(m){if(!m.holiday){a[d]={name:"",off:!1};return}a[d]={name:l(d)?m.name:"",off:!0}}}),a}function Ee(n,t){const[s,l]=v.useState(()=>{try{const a=localStorage.getItem(n);return a?JSON.parse(a):t}catch{return t}});return v.useEffect(()=>{try{localStorage.setItem(n,JSON.stringify(s))}catch{}},[n,s]),[s,l]}const U=["#f5222d","#fa8c16","#fadb14","#52c41a","#13c2c2","#1677ff","#722ed1","#eb2f96"];function ve({value:n=U[5],onChange:t}){return e.jsx("div",{className:"color-swatches",children:U.map(s=>e.jsx("span",{className:`swatch ${n===s?"active":""}`,style:{background:s},onClick:()=>t==null?void 0:t(s)},s))})}function Me({open:n,editing:t,initialStart:s,initialEnd:l,onClose:a,onSave:d,onDelete:m}){const[c]=i.Form.useForm(),p=!!t;v.useEffect(()=>{n&&setTimeout(()=>{t?c.setFieldsValue({name:t.name,start:E(t.start),end:E(t.end),startTime:t.startTime?E(t.startTime,"HH:mm"):null,endTime:t.endTime?E(t.endTime,"HH:mm"):null,color:t.color}):(c.setFieldsValue({color:U[5],start:s?E(s):E(),end:l?E(l):E().add(1,"day"),startTime:null,endTime:null}),c.resetFields(["name"]))},100)},[n,t,s,l,c]);const x={validator:(f,g)=>{const M=c.getFieldValue("start");return!g||!M||!g.isBefore(M,"day")?Promise.resolve():Promise.reject(new Error("结束日期不能早于开始日期"))}},h={validator:()=>{const f=c.getFieldValue("start"),g=c.getFieldValue("end");return!f||!g?Promise.resolve():g.isSame(f,"day")?Promise.reject(new Error("待办必须跨天(结束日期需晚于开始日期);单日事件请创建日程")):Promise.resolve()}},j={validator:(f,g)=>{var O;const M=c.getFieldValue("start"),T=c.getFieldValue("end");if(!M||!T||!T.isSame(M,"day"))return Promise.resolve();const w=((O=c.getFieldValue("startTime"))==null?void 0:O.format("HH:mm"))??"00:00";return((g==null?void 0:g.format("HH:mm"))??"24:00")<w?Promise.reject(new Error("结束时间不能早于开始时间")):Promise.resolve()}},r=async()=>{const f=await c.validateFields(),g=f.startTime,M=f.endTime;d({id:(t==null?void 0:t.id)??crypto.randomUUID(),name:f.name.trim(),start:f.start.format("YYYY-MM-DD"),end:f.end.format("YYYY-MM-DD"),startTime:g?g.format("HH:mm"):void 0,endTime:M?M.format("HH:mm"):void 0,color:f.color}),a()},u=()=>{t&&m(t.id),a()};return e.jsx(i.Modal,{title:p?"编辑待办":"添加待办",open:n,onCancel:a,okText:"保存",cancelText:"取消",destroyOnClose:!0,footer:e.jsxs(i.Space,{children:[p&&e.jsx(i.Button,{danger:!0,onClick:u,children:"删除"}),e.jsx(i.Button,{onClick:a,children:"取消"}),e.jsx(i.Button,{type:"primary",onClick:r,children:"保存"})]}),children:e.jsxs(i.Form,{form:c,layout:"vertical",preserve:!1,children:[e.jsx(i.Form.Item,{label:"事件名称",name:"name",rules:[{required:!0,message:"请输入事件名称"},{max:30}],children:e.jsx(i.Input,{placeholder:"如:年度项目冲刺",maxLength:30})}),e.jsxs(i.Row,{gutter:8,children:[e.jsx(i.Col,{span:12,children:e.jsx(i.Form.Item,{label:"开始日期",name:"start",dependencies:["end"],rules:[{required:!0,message:"请选择开始日期"},h],children:e.jsx(i.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})})}),e.jsx(i.Col,{span:12,children:e.jsx(i.Form.Item,{label:"开始时间",name:"startTime",children:e.jsx(i.TimePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:"首日开始时间,可选",allowClear:!0})})})]}),e.jsxs(i.Row,{gutter:8,children:[e.jsx(i.Col,{span:12,children:e.jsx(i.Form.Item,{label:"结束日期",name:"end",dependencies:["start"],rules:[{required:!0,message:"请选择结束日期"},x,h],children:e.jsx(i.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})})}),e.jsx(i.Col,{span:12,children:e.jsx(i.Form.Item,{label:"结束时间",name:"endTime",rules:[j],children:e.jsx(i.TimePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:"末日结束时间,可选",allowClear:!0})})})]}),e.jsx(i.Form.Item,{label:"颜色标记",name:"color",initialValue:U[5],children:e.jsx(ve,{})})]})})}function ke({icons:n,value:t,onChange:s}){return e.jsx("div",{className:"emoji-grid",children:n.map(({key:l,icon:a,tip:d})=>e.jsx("span",{className:t===l?"emoji-item active":"emoji-item",onClick:()=>s==null?void 0:s(l),title:d,children:a},l))})}function Ne({open:n,editing:t,initialDate:s,icons:l,onClose:a,onSave:d,onDelete:m}){const[c]=i.Form.useForm(),p=!!t,x=l.map(r=>r.key);v.useEffect(()=>{n&&setTimeout(()=>{t?c.setFieldsValue({icon:t.icon,date:E(t.date),name:t.name,timeRange:t.startTime&&t.endTime?[E(t.startTime,"HH:mm"),E(t.endTime,"HH:mm")]:null}):(c.setFieldsValue({icon:x[0],date:s?E(s):E(),timeRange:null}),c.resetFields(["name"]))},100)},[n,t,s,c,l]);const h=async()=>{const r=await c.validateFields(),u=r.timeRange;d({id:(t==null?void 0:t.id)??crypto.randomUUID(),icon:r.icon,date:r.date.format("YYYY-MM-DD"),name:r.name.trim(),startTime:u!=null&&u[0]?u[0].format("HH:mm"):void 0,endTime:u!=null&&u[1]?u[1].format("HH:mm"):void 0}),a()},j=()=>{t&&m(t.id),a()};return e.jsx(i.Modal,{title:p?"编辑日程":"添加日程",open:n,onOk:h,onCancel:a,okText:"保存",cancelText:"取消",destroyOnClose:!0,footer:e.jsxs(i.Space,{children:[p&&e.jsx(i.Button,{danger:!0,onClick:j,children:"删除"}),e.jsx(i.Button,{onClick:a,children:"取消"}),e.jsx(i.Button,{type:"primary",onClick:h,children:"保存"})]}),children:e.jsxs(i.Form,{form:c,layout:"vertical",preserve:!1,children:[e.jsx(i.Form.Item,{label:"图标",name:"icon",initialValue:x[0],rules:[{required:!0}],children:e.jsx(ke,{icons:l})}),e.jsx(i.Form.Item,{label:"日期",name:"date",rules:[{required:!0,message:"请选择日期"}],children:e.jsx(i.DatePicker,{style:{width:"100%"},format:"YYYY-MM-DD"})}),e.jsx(i.Form.Item,{label:"时间范围",name:"timeRange",children:e.jsx(i.TimePicker.RangePicker,{style:{width:"100%"},format:"HH:mm",minuteStep:30,placeholder:["开始时间","结束时间"],allowClear:!0})}),e.jsx(i.Form.Item,{label:"名称",name:"name",rules:[{required:!0,message:"请输入名称"},{max:30}],children:e.jsx(i.Input,{placeholder:"如:牙医复诊",maxLength:30})})]})})}const De=2;function de(n,t){try{const[s,l,a]=n.split("-").map(Number),d=pe.Solar.fromYmd(s,l,a).getLunar(),m=d.getFestivals();if(m.length>0)return m[0];const c=d.getJieQi();return c||(t?`${d.getMonthInChinese()}月${d.getDayInChinese()}`:d.getDay()===1?`${d.getMonthInChinese()}月`:d.getDayInChinese())}catch{return""}}function we(n){const{dateStr:t,day:s,inMonth:l,isToday:a,isWeekend:d,holiday:m,todoLanes:c,schedules:p,onEditSchedule:x,selected:h,onSelect:j,icons:r}=n,u=["day-cell"];l||u.push("out"),a&&u.push("today"),d&&u.push("weekend"),h&&u.push("selected"),m&&u.push(m!=null&&m.off?"holiday-off":"holiday-work");const f=p.slice(0,De),g=p.length-f.length;return e.jsxs("div",{className:u.join(" "),onClick:M=>{M.stopPropagation(),j==null||j(t)},children:[e.jsxs("div",{className:"day-top",children:[e.jsx("span",{className:"day-num",children:s}),e.jsxs("span",{className:"day-lunar",children:[(m==null?void 0:m.name)||de(t),m&&e.jsx("div",{className:`day-holiday ${m.off?"off":"work"}`,children:m.off?"休":"班"})]})]}),c>0&&e.jsx("div",{className:"todo-spacer",style:{height:c*20}}),e.jsxs("div",{className:"schedule-list",children:[f.map(M=>{var T;return e.jsx(i.Tooltip,{title:[M.name,J(M)].filter(Boolean).join(" "),children:e.jsxs("span",{className:"schedule-item",onClick:w=>{w.stopPropagation(),x(M,t)},children:[e.jsx("span",{className:"schedule-icon",children:(T=r==null?void 0:r.find(w=>w.key===M.icon))==null?void 0:T.icon}),e.jsx("span",{className:"schedule-name",children:M.name})]})},M.id)}),g>0&&e.jsxs("span",{className:"schedule-more",children:["+",g," 更多"]})]})]})}function $e({year:n,month:t,viewMode:s,loading:l,onViewModeChange:a,onToday:d,onPrevMonth:m,onNextMonth:c,isPreview:p}){return e.jsxs("div",{className:"calendar-header",children:[e.jsxs("span",{className:"calendar-title",children:[n,"年",t+1,"月"]}),e.jsx(i.Segmented,{size:"small",options:[{label:"日历",value:"all"},{label:"事项",value:"items"}],value:s,onChange:x=>a(x)}),!p&&e.jsxs(i.Space,{children:[e.jsx(i.Button,{shape:"circle",size:"small",onClick:d,children:"今"}),e.jsx(i.Button,{shape:"circle",size:"small",onClick:m,children:e.jsx(oe.LeftOutlined,{})}),e.jsx(i.Button,{shape:"circle",size:"small",onClick:c,children:e.jsx(oe.RightOutlined,{})}),l&&e.jsx(i.Spin,{size:"small"})]})]})}function be({segs:n,onEditTodo:t}){return e.jsx("div",{className:"todo-lanes",children:n.map((s,l)=>{const a=s.todo,d=`${a.start}${a.startTime?` ${a.startTime}`:""} ~ ${a.end}${a.endTime?` ${a.endTime}`:""}`,m=a.start===a.end?J(a):"";return e.jsx(i.Tooltip,{title:`${a.name}(${d})`,overlayInnerStyle:{maxWidth:320,wordBreak:"break-word"},children:e.jsx("span",{className:`todo-bar${s.roundLeft?" round-left":""}${s.roundRight?" round-right":""}`,style:{top:50+s.lane*22,left:`${s.leftEdge/7*100}%`,width:`${(Math.max(s.rightEdge,s.leftEdge)-s.leftEdge)/7*100}%`,background:a.color},onClick:c=>{c.stopPropagation(),t(a)},children:s.showLabel&&e.jsx("span",{className:"todo-bar-label",children:m?`${a.name} ${m}`:a.name})})},`${a.id}-${l}`)})})}const Ye=["周日","周一","周二","周三","周四","周五","周六"];function ce(n,t){const s=E(n);return s.format(s.year()===t?"MM.DD ":"YYYY.MM.DD ")}function Ie({dateStr:n,holiday:t,todos:s,schedules:l,onEditTodo:a,onEditSchedule:d,onAddTodo:m,onAddSchedule:c,isPreview:p,icons:x}){const h=E(n),j=h.year();return e.jsxs("div",{className:"day-panel",children:[e.jsxs("div",{className:"day-panel-header",children:[e.jsxs("div",{className:"day-panel-title",children:[h.year(),"年",h.month()+1,"月",h.date(),"日 ",Ye[h.day()],e.jsx("span",{className:"day-panel-sub",children:t!=null&&t.name?t.name:de(n,!0)||" "})]}),!p&&e.jsxs("div",{className:"day-panel-actions",children:[e.jsx(i.Button,{size:"small",onClick:m,children:"待办"}),e.jsx(i.Button,{size:"small",onClick:c,children:"日程"})]})]}),!!(s!=null&&s.length)&&e.jsxs("div",{className:"day-panel-section",children:[e.jsxs("div",{className:"day-panel-subtitle",children:["待办(",s.length,")"]}),s.map(r=>e.jsxs("div",{className:"day-panel-todo",onClick:()=>a(r),title:"点击编辑",children:[e.jsx("span",{className:"day-panel-todo-dot",style:{background:r.color}}),e.jsx("span",{className:"day-panel-todo-name",children:r.name}),e.jsxs("span",{className:"day-panel-todo-range",children:[ce(r.start,j),r.startTime?` ${r.startTime}`:""," ~ ",ce(r.end,j),r.endTime?` ${r.endTime}`:""]})]},r.id))]}),!!l.length&&e.jsxs("div",{className:"day-panel-section",children:[e.jsxs("div",{className:"day-panel-subtitle",children:["日程(",l.length,")"]}),l.map(r=>{var u;return e.jsxs("div",{className:"day-panel-schedule",onClick:()=>d(r),title:"点击编辑",children:[e.jsx("span",{className:"day-panel-schedule-icon",children:(u=x==null?void 0:x.find(f=>f.key===r.icon))==null?void 0:u.icon}),e.jsx("span",{className:"day-panel-schedule-name",children:r.name}),J(r)&&e.jsx("span",{className:"day-panel-schedule-time",children:J(r)})]},r.id)})]}),l.length===0&&s.length===0&&(p?e.jsx("div",{className:"day-panel-empty",children:"暂无待办和日程"}):e.jsx(i.Empty,{image:i.Empty.PRESENTED_IMAGE_SIMPLE,description:"暂无待办和日程"}))]})}function ie(n){const[t,s]=n.split(":").map(Number);return t*60+s}function Ce(n,t){const s=n.startTime?ie(n.startTime):0,l=n.endTime?ie(n.endTime):1440,a=F(t);return n.start===n.end?[s,l]:a===n.start?[s,1440]:a===n.end?[0,l]:[0,1440]}function Fe(n,t){const s={};t.forEach((r,u)=>{s[F(r.date)]=u});const l=F(t[0].date),a=F(t[t.length-1].date),d=Array.isArray(n)?n:[],m=new Array(t.length).fill(0),c=[],x=[...d].sort((r,u)=>{if(r.start!==u.start)return r.start.localeCompare(u.start);const f=r.startTime??"00:00",g=u.startTime??"00:00";return f!==g?f.localeCompare(g):r.end!==u.end?r.end.localeCompare(u.end):(r.endTime??"23:59").localeCompare(u.endTime??"23:59")}).filter(r=>!(r.end<l||r.start>a)).map(r=>({original:r,cs:r.start<l?l:r.start,ce:r.end>a?a:r.end})).filter(r=>{const u=s[r.cs],f=s[r.ce];return u!==void 0&&f!==void 0}),h=Math.ceil(t.length/7);for(let r=0;r<h;r++){const u=r*7,f=Math.min(u+6,t.length-1),g=Array.from({length:7},()=>[[],[],[]]),M=x.filter(T=>{const w=s[T.cs];return s[T.ce]>=u&&w<=f});for(const{original:T,cs:w,ce:N}of M){const O=s[w],D=s[N],Y=Math.max(O,u)-u,$=Math.min(D,f)-u,I=[];for(let k=Y;k<=$;k++)I.push(Ce(T,t[u+k].date));let H=-1;for(let k=0;k<3;k++){let A=!0;for(let C=Y;C<=$&&A;C++){const[_,b]=I[C-Y];_>=b||(A=!g[C][k].some(L=>L.s<b&&_<L.e))}if(A){H=k;break}}if(H===-1)continue;const R=O>=u&&w===T.start,q=D<=f&&N===T.end,[W]=I[0],[,K]=I[I.length-1],G=Y+(R?W/1440:0),V=q?$+K/1440:$+1;c.push({todo:T,weekRow:r,startCol:Y,endCol:$,leftEdge:G,rightEdge:V,lane:H,showLabel:R,roundLeft:R,roundRight:q});for(let k=Y;k<=$;k++){const[A,C]=I[k-Y];A<C&&g[k][H].push({s:A,e:C})}for(let k=Y;k<=$;k++){const[A,C]=I[k-Y];if(A<C){const _=u+k;m[_]<H+1&&(m[_]=H+1)}}}}const j={};return t.forEach((r,u)=>{m[u]>0&&(j[F(r.date)]=m[u])}),{todoSegs:c,todoLanesByDate:j}}function He(n,t,s,l,a){const d=Array.isArray(n)?n:[],m=Array.isArray(t)?t:[],c=`${l}-${String(a+1).padStart(2,"0")}-01`,p=E(new Date(l,a+1,0)),x=`${p.year()}-${String(p.month()+1).padStart(2,"0")}-${String(p.date()).padStart(2,"0")}`,h=new Set;return d==null||d.forEach(j=>{const r=j.start<c?c:j.start,u=j.end>x?x:j.end;if(u<r)return;let f=E(r);for(;F(f)<=u;){const g=s[F(f)];g!==void 0&&h.add(Math.floor(g/7)),f=f.add(1,"day")}}),m.forEach(j=>{if(j.date>=c&&j.date<=x){const r=s[j.date];r!==void 0&&h.add(Math.floor(r/7))}}),h.size===0?null:{min:Math.min(...h),max:Math.max(...h)}}function Ae(n,t,s){if(t==="all")return n.map((a,d)=>({week:a,rowIndex:d}));if(!s)return[];const l=[];for(let a=s.min;a<=s.max;a++)l.push({week:n[a],rowIndex:a});return l}const Le=["日","一","二","三","四","五","六"];function Oe({todos:n,schedules:t,onChange:s,onSaveTodo:l,onDeleteTodo:a,onSaveSchedule:d,onDeleteSchedule:m,isPreview:c,icons:p}){const[x,h]=v.useState(E()),[j,r]=v.useState({}),[u,f]=v.useState(!1),[g,M]=Ee(c?"calendar_view_preview_mode":"calendar_view_mode",c?"items":"all"),[T,w]=v.useState(F(E())),[N,O]=v.useState(n??[]),[D,Y]=v.useState(t??[]),[$,I]=v.useState({open:!1,editing:null}),[H,R]=v.useState({open:!1,editing:null}),q=o=>{c||I({open:!0,editing:o})},W=(o,y)=>{c||R({open:!0,editing:o})},K=o=>{c||I({open:!0,editing:null,initialStart:o,initialEnd:E(o).add(1,"day").format("YYYY-MM-DD")})},G=o=>{c||R({open:!0,editing:null,initialDate:o})},V=(o,y)=>{O(o),Y(y),s==null||s(o,y)},k=o=>{const y=N.some(S=>S.id===o.id)?N.map(S=>S.id===o.id?o:S):[...N,o];V(y,D),l==null||l(o)},A=o=>{const y=N.filter(S=>S.id!==o);V(y,D),a==null||a(o)},C=o=>{const y=D.some(S=>S.id===o.id)?D.map(S=>S.id===o.id?o:S):[...D,o];V(N,y),d==null||d(o)},_=o=>{const y=D.filter(S=>S.id!==o);V(N,y),m==null||m(o)},b=x.year(),L=x.month();v.useEffect(()=>{let o=!1;return f(!0),je(b).then(y=>{o||r(y)}).catch(()=>{o||r({})}).finally(()=>{o||f(!1)}),()=>{o=!0}},[b]);const P=v.useMemo(()=>ge(b,L),[b,L]),Q=v.useMemo(()=>Te(j),[j]),Z=v.useMemo(()=>{const o={};return D==null||D.forEach(y=>{var S;(o[S=y.date]??(o[S]=[])).push(y)}),Object.values(o).forEach(y=>y.sort((S,X)=>le(S).localeCompare(le(X)))),o},[D]),ee=v.useMemo(()=>{const o=[];for(let y=0;y<P.length;y+=7)o.push(P.slice(y,y+7));return o},[P]),{todoSegs:me,todoLanesByDate:ue}=v.useMemo(()=>Fe(N,P),[N,P]),te=F(E()),z=v.useMemo(()=>{const o={};return P.forEach((y,S)=>{o[F(y.date)]=S}),o},[P]),se=`${b}-${String(L+1).padStart(2,"0")}-01`;v.useEffect(()=>{if(!T||z[T]!==void 0)return;const o=te;w(z[o]!==void 0&&o.startsWith(se.slice(0,8))?o:se)},[b,L]);const he=o=>{w(y=>y===o?null:o)},ne=v.useMemo(()=>He(N,D,z,b,L),[N,D,b,L,z]),ae=v.useMemo(()=>Ae(ee,g,ne),[ee,g,ne]);return e.jsxs("div",{className:"calendar-container",children:[e.jsxs("div",{className:"calendar",children:[e.jsx($e,{isPreview:c,year:b,month:L,viewMode:g,loading:u,onViewModeChange:M,onToday:()=>h(E()),onPrevMonth:()=>h(x.subtract(1,"month")),onNextMonth:()=>h(x.add(1,"month"))}),e.jsx("div",{className:"week-row",children:Le.map(o=>e.jsx("div",{className:"week-cell",children:o},o))}),e.jsx("div",{className:"day-grid",children:ae.length===0?e.jsx("div",{className:"calendar-empty",children:e.jsx(i.Empty,{image:i.Empty.PRESENTED_IMAGE_SIMPLE,description:"本月暂无待办和日程"})}):ae.map(({week:o,rowIndex:y})=>e.jsxs("div",{className:"day-week",children:[o.map(({date:S,inMonth:X})=>{const B=F(S),re=S.day(),fe=re===0||re===6;return e.jsx(we,{dateStr:B,day:S.date(),inMonth:X,isToday:B===te,isWeekend:fe,holiday:Q[B],todoLanes:ue[B]??0,schedules:Z[B]??[],onEditSchedule:W,icons:p,selected:T===B,onSelect:he},B)}),e.jsx(be,{segs:me.filter(S=>S.weekRow===y),onEditTodo:q})]},y))})]}),T&&e.jsx(Ie,{dateStr:T,holiday:Q[T],todos:N==null?void 0:N.filter(o=>o.start<=T&&T<=o.end),schedules:Z[T]??[],onEditTodo:q,onEditSchedule:o=>W(o),onAddTodo:()=>K(T),onAddSchedule:()=>G(T),isPreview:c,icons:p}),e.jsx(Me,{open:$.open,editing:$.editing,initialStart:$.initialStart,initialEnd:$.initialEnd,onClose:()=>I({open:!1,editing:null}),onSave:k,onDelete:A}),e.jsx(Ne,{open:H.open,editing:H.editing,initialDate:H.initialDate,icons:p||[],onClose:()=>R({open:!1,editing:null}),onSave:C,onDelete:_})]})}exports.Calendar=Oe;