/** * 事件模型工厂与辅助函数。 * * EventModel 是应用内通用的纯 JS 数据结构 (见 docs/superpowers/specs/... * §4.2)。本模块集中管理事件的创建与克隆, 使 useCalendar.js 专注于状态管理。 */ import { todayISO, nowCompactTimestamp } from './date.js' import { genUUID } from './uuid.js' /** * 创建一个具有合理默认值的单次事件。 * @param {object} [overrides] - 需覆盖的部分字段 * @returns {object} 一个全新的 EventModel */ export function createEvent(overrides = {}) { return { uid: genUUID(), summary: '新日程', location: '', description: '', dtstartDate: todayISO(), dtstartTime: '09:00', dtendTime: '10:00', tzid: 'UTC', rrule: null, exdates: [], _raw: { dtstamp: nowCompactTimestamp() }, ...overrides, } } /** * 深拷贝一个事件 (或任意纯数据对象)。 * * 使用 JSON 往返而非 structuredClone, 因为事件可能被 Vue 响应式代理包裹, * structuredClone 无法处理。EventModel 仅含纯数据 (字符串、数组、嵌套对象), * 因此 JSON 拷贝在此是安全且无损的。 */ export function cloneEvent(ev) { return JSON.parse(JSON.stringify(ev)) }