@tano.page/workbench 0.14.0 → 0.16.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.
Files changed (248) hide show
  1. package/package.json +50 -16
  2. package/src/App.vue +82 -752
  3. package/src/appearance/appearance.ts +14 -4
  4. package/src/appearance/components/ThemePresetPreview.vue +52 -8
  5. package/src/appearance/interface-font.ts +99 -0
  6. package/src/appearance/theme.ts +26 -10
  7. package/src/appearance/use-interface-font.ts +30 -0
  8. package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
  9. package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
  10. package/src/assets/mail-provider-icons/gmail.svg +1 -0
  11. package/src/assets/mail-provider-icons/icloud.svg +12 -0
  12. package/src/assets/mail-provider-icons/netease-126.svg +5 -0
  13. package/src/assets/mail-provider-icons/netease-163.svg +5 -0
  14. package/src/assets/mail-provider-icons/qq.svg +9 -0
  15. package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
  16. package/src/assistant/agent-identities.ts +1 -97
  17. package/src/assistant/agent-task-context.ts +1 -54
  18. package/src/assistant/attachments.ts +1 -1
  19. package/src/assistant/completion.ts +1 -61
  20. package/src/assistant/components/AssistantChangeList.vue +98 -21
  21. package/src/assistant/components/AssistantPanel.vue +425 -8
  22. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  23. package/src/assistant/connection-actions.ts +237 -0
  24. package/src/assistant/document-mentions.ts +1 -33
  25. package/src/assistant/engine.ts +1 -532
  26. package/src/assistant/execution.ts +6 -33
  27. package/src/assistant/files.ts +5 -13
  28. package/src/assistant/hash.ts +1 -4
  29. package/src/assistant/inbox.ts +1 -148
  30. package/src/assistant/language.ts +10 -37
  31. package/src/assistant/mention-autocomplete.ts +69 -0
  32. package/src/assistant/plugin-bridge-builder.ts +146 -0
  33. package/src/assistant/prompts.ts +1 -58
  34. package/src/assistant/proposal-actions.ts +336 -0
  35. package/src/assistant/results.ts +20 -86
  36. package/src/assistant/store.ts +167 -327
  37. package/src/assistant/structures.ts +1 -155
  38. package/src/assistant/tasks.ts +8 -96
  39. package/src/assistant/tool-rules.ts +1 -7
  40. package/src/assistant/workspace-bridge.ts +1 -1
  41. package/src/composables/use-document-actions.ts +38 -20
  42. package/src/composables/use-file-tree-controller.ts +7 -12
  43. package/src/composables/use-workbench-help.ts +177 -0
  44. package/src/composables/use-workbench-history.ts +2 -4
  45. package/src/composables/use-workbench-lifecycle.ts +249 -0
  46. package/src/composables/use-workbench-modals.ts +6 -1
  47. package/src/composables/use-workbench-outline.ts +0 -5
  48. package/src/composables/use-workbench-settings.ts +185 -0
  49. package/src/composables/use-workbench-shortcuts.ts +40 -1021
  50. package/src/composables/use-workbench-views.ts +325 -0
  51. package/src/data-tables/data-tables.ts +1 -2
  52. package/src/documents/components/DocumentActionMenu.vue +279 -0
  53. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  54. package/src/documents/components/DocumentInspector.vue +168 -0
  55. package/src/documents/components/DocumentPane.vue +482 -0
  56. package/src/documents/description-merge.ts +1 -9
  57. package/src/features.ts +1 -0
  58. package/src/files/components/FileMetadataPanel.vue +49 -15
  59. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  60. package/src/fonts/Inter-Latin.woff2 +0 -0
  61. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  62. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  63. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  64. package/src/help/help-milestones.ts +3 -5
  65. package/src/i18n/locale-catalogs.ts +7 -6
  66. package/src/i18n/locale-registry.ts +8 -6
  67. package/src/i18n/locales/de-DE.json +371 -3
  68. package/src/i18n/locales/en-US.json +371 -2
  69. package/src/i18n/locales/es-ES.json +371 -3
  70. package/src/i18n/locales/ja-JP.json +370 -2
  71. package/src/i18n/locales/zh-TW.json +370 -2
  72. package/src/mail/components/MailAccountDialog.vue +450 -0
  73. package/src/mail/components/MailComposerDialog.vue +326 -0
  74. package/src/mail/components/MailProviderIcon.vue +30 -0
  75. package/src/mail/components/MailWorkspaceView.vue +821 -0
  76. package/src/mail/components/SidebarMail.vue +134 -0
  77. package/src/mail/mail-avatar.ts +17 -0
  78. package/src/mail/mail-bridge.ts +68 -0
  79. package/src/mail/mail-calendar.ts +208 -0
  80. package/src/mail/mail-markdown.ts +195 -0
  81. package/src/mail/types.ts +226 -0
  82. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  83. package/src/objects/content-references.ts +6 -56
  84. package/src/objects/wiki-links.ts +1 -48
  85. package/src/objects/workspace-objects.ts +3 -4
  86. package/src/plan-sync/types.ts +6 -3
  87. package/src/plans/calendar-interaction.ts +194 -0
  88. package/src/plans/calendar.ts +65 -9
  89. package/src/plans/components/CalendarAgendaView.vue +165 -0
  90. package/src/plans/components/CalendarDayPopover.vue +172 -39
  91. package/src/plans/components/CalendarFilterBar.vue +128 -0
  92. package/src/plans/components/CalendarMonthView.vue +224 -0
  93. package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
  94. package/src/plans/components/CalendarTimelineView.vue +517 -0
  95. package/src/plans/components/CalendarTopbarControls.vue +101 -0
  96. package/src/plans/components/CalendarView.vue +264 -748
  97. package/src/plans/components/CalendarYearView.vue +138 -0
  98. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  99. package/src/plans/components/PlanConnectionsDialog.vue +1 -1
  100. package/src/plans/components/PlanDateField.vue +6 -4
  101. package/src/plans/components/PlanDetailPanel.vue +227 -32
  102. package/src/plans/components/PlanEventList.vue +16 -4
  103. package/src/plans/components/SidebarPlan.vue +22 -15
  104. package/src/plans/components/TaskRepeatControls.vue +169 -30
  105. package/src/plans/components/calendar-shared.css +192 -0
  106. package/src/plans/composables/use-calendar-interactions.ts +396 -0
  107. package/src/plans/composables/use-calendar-scroll.ts +420 -0
  108. package/src/plans/local-reminders.ts +149 -0
  109. package/src/plans/personal-plans.ts +10 -1
  110. package/src/plans/plan-date.ts +8 -1
  111. package/src/plans/plan-migration.ts +95 -0
  112. package/src/plans/recurrence.ts +95 -0
  113. package/src/plans/task-repeat.ts +8 -8
  114. package/src/plans/timeline-layout.ts +92 -0
  115. package/src/plugins/assistant-bridge.ts +520 -0
  116. package/src/plugins/attachment-reader.ts +3 -1
  117. package/src/plugins/cache-storage.ts +42 -2
  118. package/src/plugins/components/PluginAutomations.vue +3 -3
  119. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  120. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  121. package/src/plugins/components/PluginConnections.vue +1 -1
  122. package/src/plugins/components/PluginCustomView.vue +2 -2
  123. package/src/plugins/components/PluginDetailPage.vue +136 -57
  124. package/src/plugins/components/PluginDeveloperArea.vue +192 -0
  125. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  126. package/src/plugins/components/PluginExplorer.vue +21 -25
  127. package/src/plugins/components/PluginImportDialog.vue +410 -0
  128. package/src/plugins/components/PluginInstaller.vue +273 -288
  129. package/src/plugins/components/PluginListItem.vue +3 -0
  130. package/src/plugins/components/PluginMaintenance.vue +37 -34
  131. package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
  132. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  133. package/src/plugins/components/PluginSettingsForm.vue +112 -0
  134. package/src/plugins/components/PluginStatusBar.vue +161 -0
  135. package/src/plugins/components/PluginSurface.vue +18 -6
  136. package/src/plugins/components/PluginUiDialog.vue +452 -0
  137. package/src/plugins/components/PluginsTabPage.vue +61 -0
  138. package/src/plugins/components/plugin-center.css +5 -0
  139. package/src/plugins/data.ts +9 -86
  140. package/src/plugins/editor-plugin-adapters.ts +169 -0
  141. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  142. package/src/plugins/excalidraw/manifest.json +12 -1
  143. package/src/plugins/host.ts +662 -43
  144. package/src/plugins/native.ts +2 -10
  145. package/src/plugins/overlay-mapping.ts +125 -0
  146. package/src/plugins/packages.ts +73 -1
  147. package/src/plugins/plugin-data.ts +2 -3
  148. package/src/plugins/plugin-permissions.ts +57 -0
  149. package/src/plugins/plugin-rpc-router.ts +558 -0
  150. package/src/plugins/plugin-sdk.ts +1 -94
  151. package/src/plugins/plugin-ui-dialogs.ts +167 -0
  152. package/src/plugins/policy.ts +53 -3
  153. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  154. package/src/plugins/presentation-preview/manifest.json +2 -1
  155. package/src/plugins/queries.ts +1 -73
  156. package/src/plugins/sandbox.ts +15 -1
  157. package/src/plugins/use-plugin-actions.ts +67 -20
  158. package/src/plugins/user-plugins.ts +254 -0
  159. package/src/plugins/view-header.ts +2 -7
  160. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  161. package/src/plugins/word-preview/manifest.json +13 -1
  162. package/src/plugins/workbench.ts +175 -2
  163. package/src/plugins/worker.js +105 -8
  164. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  165. package/src/plugins/workspace-plugins.ts +212 -21
  166. package/src/runtime.ts +103 -4
  167. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  168. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  169. package/src/settings/components/SettingsPanel.vue +8 -3
  170. package/src/settings/components/WorkbenchSettings.vue +20 -7
  171. package/src/settings/components/settings-context.ts +1 -1
  172. package/src/settings/components/settings-search.ts +2 -3
  173. package/src/settings/settings-tab.ts +1 -0
  174. package/src/shell/command-palette.ts +3 -3
  175. package/src/shell/components/EditorToolbar.vue +8 -9
  176. package/src/shell/components/EditorTools.vue +1 -5
  177. package/src/shell/components/PaneTopbar.vue +393 -0
  178. package/src/shell/components/SelectionToolbar.vue +0 -2
  179. package/src/shell/components/SidebarNavigation.vue +22 -2
  180. package/src/shell/components/WorkbenchContextMenus.vue +58 -34
  181. package/src/shell/components/WorkbenchModals.vue +47 -62
  182. package/src/shell/components/WorkbenchPanes.vue +371 -1342
  183. package/src/shell/components/WorkbenchSidebar.vue +486 -0
  184. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  185. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  186. package/src/shell/pane-registry.ts +69 -0
  187. package/src/shell/use-surface-dismissal.ts +219 -0
  188. package/src/shell/use-workbench-commands.ts +599 -0
  189. package/src/shell/use-workbench-keybindings.ts +337 -0
  190. package/src/shell/use-workbench.ts +531 -1153
  191. package/src/shell/workbench-async-components.ts +14 -5
  192. package/src/shell/workbench-context.ts +30 -3
  193. package/src/stores/mail.ts +414 -0
  194. package/src/stores/plan-sync.ts +2 -1
  195. package/src/stores/plans.ts +2 -9
  196. package/src/stores/workspace-document-io.ts +807 -0
  197. package/src/stores/workspace-file-ops.ts +1 -1
  198. package/src/stores/workspace-knowledge.ts +2 -114
  199. package/src/stores/workspace-lifecycle.ts +459 -0
  200. package/src/stores/workspace-plugins-state.ts +254 -259
  201. package/src/stores/workspace-session.ts +287 -0
  202. package/src/stores/workspace-tabs-layout.ts +6 -44
  203. package/src/stores/workspace-types.ts +50 -0
  204. package/src/stores/workspace.ts +184 -1363
  205. package/src/styles/agent-diff-modals.css +0 -7
  206. package/src/styles/dark-theme.css +3 -3
  207. package/src/styles/inspector.css +0 -59
  208. package/src/styles/layout-themes.css +346 -0
  209. package/src/styles/mail.css +1568 -0
  210. package/src/styles/mobile.css +2 -2
  211. package/src/styles/recent-and-media.css +0 -17
  212. package/src/styles/theme-contract.css +3 -3
  213. package/src/styles/workbench-shell.css +110 -17
  214. package/src/styles/workspace-states.css +9 -33
  215. package/src/styles.css +0 -1
  216. package/src/tabs/components/DesktopTabs.vue +19 -14
  217. package/src/tabs/components/NewTabPicker.vue +10 -4
  218. package/src/tabs/tab-label.ts +0 -1
  219. package/src/windows/AuxiliaryWindows.vue +2 -2
  220. package/src/windows/use-window-event-bridge.ts +152 -0
  221. package/src/workspace/components/TemplateLibrary.vue +1 -1
  222. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  223. package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
  224. package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
  225. package/src/workspace/workspace-comments.ts +11 -151
  226. package/src/workspace/workspace-welcome.ts +1 -1
  227. package/src/assistant/locales/de-DE.json +0 -126
  228. package/src/assistant/locales/en-US.json +0 -126
  229. package/src/assistant/locales/es-ES.json +0 -126
  230. package/src/assistant/locales/ja-JP.json +0 -126
  231. package/src/assistant/locales/zh-CN.json +0 -126
  232. package/src/assistant/locales/zh-TW.json +0 -126
  233. package/src/assistant/task-prompts.json +0 -39
  234. package/src/documents/components/FormulaMenu.vue +0 -50
  235. package/src/files/components/FileDatabasePage.vue +0 -152
  236. package/src/files/components/FolderHomeIcon.vue +0 -12
  237. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  238. package/src/objects/components/ObjectPanel.vue +0 -554
  239. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  240. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  241. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  242. package/src/styles/object-panel.css +0 -163
  243. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  244. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  245. package/src/workspace/welcome-slogans.ts +0 -11
  246. package/src/workspace/workspace-git.ts +0 -35
  247. package/src/workspace/workspace-sync.ts +0 -46
  248. package/src/workspace/workspace-views.ts +0 -48
@@ -1,16 +1,32 @@
1
1
  <script setup lang="ts">
2
- import { useWindowContext } from '../../windows/context';
3
- const { window, document } = useWindowContext();
4
- const ResizeObserver = (window as Window & typeof globalThis).ResizeObserver;
2
+ import './calendar-shared.css';
3
+ import { computed, onMounted, onUnmounted, ref, shallowRef, useId } from 'vue';
4
+ import { X } from 'lucide-vue-next';
5
5
  import LoadingSkeleton from '../../shell/components/LoadingSkeleton.vue';
6
6
  import { t, uiLocale } from '../../i18n/i18n';
7
- import { computed, nextTick, onMounted, onUnmounted, ref, shallowRef, useId, watch } from 'vue';
8
- import { calendarEvents, eventsOnDay, hasEventTime, localDayKey, monthDays, plannedEventsOnDay, planningEvents, shiftCalendarDate, visibleCalendarDays, weekDays } from '../calendar';
9
- import type { CalendarViewMode } from '../calendar';
7
+ import { useWindowContext } from '../../windows/context';
10
8
  import type { ObjectRecord } from '../../objects/workspace-objects';
11
- import { usePlanStore } from '../../stores/plans';
12
- import { planKey, planSourceLabel } from '../personal-plans';
9
+ import { usePlanStore, type PlanScope } from '../../stores/plans';
10
+ import {
11
+ calendarDayEntries,
12
+ calendarEvents,
13
+ filterCalendarRecords,
14
+ localDayKey,
15
+ planningEvents,
16
+ type CalendarFilter,
17
+ type CalendarViewMode,
18
+ } from '../calendar';
19
+ import { expandRecurringPlans } from '../recurrence';
20
+ import { writePlanDate, type PlanDateValue } from '../plan-date';
21
+ import { useCalendarScroll } from '../composables/use-calendar-scroll';
22
+ import { useCalendarInteractions } from '../composables/use-calendar-interactions';
13
23
  import CalendarDayPopover from './CalendarDayPopover.vue';
24
+ import CalendarFilterBar from './CalendarFilterBar.vue';
25
+ import CalendarQuickCreateDialog, { type QuickCreateDraft } from './CalendarQuickCreateDialog.vue';
26
+ import CalendarTimelineView from './CalendarTimelineView.vue';
27
+ import CalendarMonthView from './CalendarMonthView.vue';
28
+ import CalendarYearView from './CalendarYearView.vue';
29
+ import CalendarAgendaView from './CalendarAgendaView.vue';
14
30
 
15
31
  const props = defineProps<{ date: Date; mode: CalendarViewMode; records?: ObjectRecord[]; loading?: boolean }>();
16
32
  const emit = defineEmits<{
@@ -22,781 +38,281 @@ const emit = defineEmits<{
22
38
  'visible-year': [date: Date];
23
39
  'visible-timeline': [date: Date];
24
40
  }>();
41
+
42
+ const { window } = useWindowContext();
25
43
  const plans = usePlanStore();
26
44
  const scroll = ref<HTMLElement>();
27
- const events = computed(() => calendarEvents(props.records ?? plans.records));
28
- const planned = computed(() => planningEvents(props.records ?? plans.records));
29
- const dateOnly = computed(() => planned.value.filter(record => record.object.properties.allDay === true || (!hasEventTime(record) && record.object.properties.date)));
30
- const dateOnlyEvents = (day: Date) => plannedEventsOnDay(dateOnly.value, day);
31
- const hasVisibleDateOnly = computed(() => visibleCalendarDays(props.date, props.mode).some(day => dateOnlyEvents(day).length > 0));
32
- const yearDay = shallowRef<{ date: Date; anchor: HTMLElement; scrollTop: number; scrollLeft: number }>();
33
- const dayPopoverId = useId();
34
- const yearDayKey = computed(() => yearDay.value && localDayKey(yearDay.value.date));
35
- const yearDayRecords = (day: Date) => plannedEventsOnDay(planned.value, day);
36
- function openYearDay(day: Date, event: MouseEvent) {
37
- yearDay.value = yearDayKey.value === localDayKey(day)
38
- ? undefined : {
39
- date: day, anchor: event.currentTarget as HTMLElement,
40
- scrollTop: scroll.value?.scrollTop ?? 0, scrollLeft: scroll.value?.scrollLeft ?? 0,
41
- };
45
+ const filter = ref<CalendarFilter>({ kind: 'all', showCompleted: true, query: '' });
46
+ const nowMinutes = ref(currentMinutes());
47
+ let nowTimer: ReturnType<typeof setInterval> | undefined;
48
+
49
+ function currentMinutes() {
50
+ const now = new Date();
51
+ return now.getHours() * 60 + now.getMinutes();
42
52
  }
43
- const timeline = computed(() => props.mode === 'day' || props.mode === 'four-days' || props.mode === 'week');
44
- const timelineDays = ref<Date[]>([]);
45
- const timelineDayWidth = ref(120);
46
- const timelineVisibleCount = computed(() => props.mode === 'week' ? 7 : props.mode === 'four-days' ? 4 : 1);
47
- const scrollingWeeks = ref<Date[]>([]);
48
- const scrollingYears = ref<number[]>([]);
49
- const monthsForYear = (year: number) => Array.from({ length: 12 }, (_, month) => {
50
- const date = new Date(year, month, 1);
51
- return { date, days: monthDays(date) };
52
- });
53
- const agendaDates = computed(() => {
54
- const year = props.date.getFullYear();
55
- const month = props.date.getMonth();
56
- const length = new Date(year, month + 1, 0).getDate();
57
- return Array.from({ length }, (_, index) => new Date(year, month, index + 1))
58
- .filter(day => dayRecords(day).length > 0);
53
+
54
+ const dayPopover = shallowRef<{ date: Date; anchor: HTMLElement; scrollTop: number; scrollLeft: number }>();
55
+ const dayPopoverId = useId();
56
+ const dayPopoverKey = computed(() => dayPopover.value && localDayKey(dayPopover.value.date));
57
+
58
+ const {
59
+ timeline,
60
+ timelineDays,
61
+ timelineDayWidth,
62
+ scrollingWeeks,
63
+ scrollingYears,
64
+ visibleWindow,
65
+ onCalendarScroll,
66
+ onCalendarWheel,
67
+ } = useCalendarScroll({
68
+ date: () => props.date,
69
+ mode: () => props.mode,
70
+ scroll,
71
+ window,
72
+ onVisibleMonth: (value) => emit('visible-month', value),
73
+ onVisibleYear: (value) => emit('visible-year', value),
74
+ onVisibleTimeline: (value) => emit('visible-timeline', value),
75
+ onSelectMode: (value) => emit('select-mode', value),
76
+ onBeforeViewChange: () => { dayPopover.value = undefined; },
77
+ onScrolled: () => {
78
+ if (
79
+ dayPopover.value &&
80
+ scroll.value &&
81
+ (dayPopover.value.scrollTop !== scroll.value.scrollTop ||
82
+ dayPopover.value.scrollLeft !== scroll.value.scrollLeft)
83
+ ) {
84
+ dayPopover.value = undefined;
85
+ }
86
+ },
59
87
  });
60
- const weekdays = computed(() => uiLocale.value === 'zh-CN' ? ['一', '二', '三', '四', '五', '六', '日']
61
- : Array.from({ length: 7 }, (_, index) => new Intl.DateTimeFormat(uiLocale.value, { weekday: 'short' }).format(new Date(2024, 0, 1 + index))));
62
- const hours = Array.from({ length: 24 }, (_, hour) => hour);
63
- const hourHeight = 56;
88
+
89
+ const rawPlanned = computed(() => planningEvents(props.records ?? plans.records));
90
+ const expandedPlanned = computed(() =>
91
+ expandRecurringPlans(rawPlanned.value, visibleWindow.value[0], visibleWindow.value[1]),
92
+ );
93
+ const planned = computed(() => filterCalendarRecords(expandedPlanned.value, filter.value));
94
+ const events = computed(() => calendarEvents(planned.value));
95
+
96
+ const canCreateWorkspace = computed(() => Boolean(plans.workspaceWritable));
97
+ const canCreatePersonal = computed(() => Boolean(plans.personalWritable));
98
+ const canCreate = computed(
99
+ () => typeof plans.create === 'function' && (canCreateWorkspace.value || canCreatePersonal.value),
100
+ );
101
+
64
102
  const today = computed(() => localDayKey(new Date()));
65
- const viewLabel = computed(() => ({
66
- day: t('日视图'), 'four-days': t('4 天视图'), week: t('周视图'),
67
- month: t('月视图'), year: t('年视图'), agenda: t('日程视图'),
68
- })[props.mode]);
69
- const monthKey = (date: Date) => `${date.getFullYear()}-${date.getMonth()}`;
70
- const weekKey = localDayKey;
71
- const weekOffset = (date: Date, weeks: number) =>
72
- new Date(date.getFullYear(), date.getMonth(), date.getDate() + weeks * 7);
73
- let reportedMonthKey = '';
74
- let extendingWeeks = false;
75
- let reportedYear: number | undefined;
76
- let extendingYears = false;
77
- let positioningYear = false;
78
- let reportedTimelineKey = '';
79
- let extendingTimeline = false;
80
- let positioningTimeline = false;
81
- let timelineResizeObserver: ResizeObserver | undefined;
103
+ const weekdays = computed(() =>
104
+ uiLocale.value === 'zh-CN'
105
+ ? ['一', '二', '三', '四', '五', '六', '日']
106
+ : Array.from({ length: 7 }, (_, index) =>
107
+ new Intl.DateTimeFormat(uiLocale.value, { weekday: 'short' }).format(new Date(2024, 0, 1 + index)),
108
+ ),
109
+ );
110
+ const viewLabel = computed(
111
+ () =>
112
+ ({
113
+ day: t('日视图'),
114
+ 'four-days': t('4 天视图'),
115
+ week: t('周视图'),
116
+ month: t('月视图'),
117
+ year: t('年视图'),
118
+ agenda: t('日程视图'),
119
+ })[props.mode],
120
+ );
82
121
 
83
- const dayOffset = (date: Date, days: number) =>
84
- new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);
122
+ // --- Quick-Create State ---
123
+ const createDraft = ref<QuickCreateDraft>();
124
+ const createSaving = ref(false);
125
+ const createError = ref('');
85
126
 
86
- function fillTimelineDays(date: Date) {
87
- const first = visibleCalendarDays(date, props.mode)[0]!;
88
- timelineDays.value = Array.from({ length: 42 }, (_, index) => dayOffset(first, index - 14));
89
- }
90
- async function scrollToTimelineDate(date: Date) {
91
- positioningTimeline = true;
92
- const first = visibleCalendarDays(date, props.mode)[0]!;
93
- let index = timelineDays.value.findIndex(day => localDayKey(day) === localDayKey(first));
94
- if (index < 0) {
95
- fillTimelineDays(date);
96
- index = 14;
97
- }
98
- await nextTick();
99
- if (scroll.value) scroll.value.scrollLeft = index * timelineDayWidth.value;
100
- positioningTimeline = false;
101
- }
102
- async function extendTimelineDays(direction: -1 | 1) {
103
- const container = scroll.value;
104
- if (extendingTimeline || !container || !timelineDays.value.length) return;
105
- extendingTimeline = true;
106
- const width = timelineDayWidth.value;
107
- const anchorIndex = Math.min(timelineDays.value.length - 1, Math.floor(container.scrollLeft / width));
108
- const anchorKey = localDayKey(timelineDays.value[anchorIndex]!);
109
- const anchorOffset = container.scrollLeft - anchorIndex * width;
110
- const edge = direction < 0 ? timelineDays.value[0]! : timelineDays.value.at(-1)!;
111
- const additions = Array.from({ length: 14 }, (_, index) => dayOffset(edge, direction * (index + 1)));
112
- const expanded = direction < 0
113
- ? [...additions.reverse(), ...timelineDays.value]
114
- : [...timelineDays.value, ...additions];
115
- timelineDays.value = direction < 0 ? expanded.slice(0, 70) : expanded.slice(-70);
116
- await nextTick();
117
- const retainedIndex = timelineDays.value.findIndex(day => localDayKey(day) === anchorKey);
118
- if (retainedIndex >= 0) container.scrollLeft = retainedIndex * width + anchorOffset;
119
- extendingTimeline = false;
120
- }
121
- function onTimelineScroll() {
122
- const container = scroll.value;
123
- if (!timeline.value || !container || !timelineDays.value.length || positioningTimeline || extendingTimeline) return;
124
- const width = timelineDayWidth.value;
125
- const index = Math.min(timelineDays.value.length - 1, Math.max(0, Math.round(container.scrollLeft / width)));
126
- const visible = timelineDays.value[index]!;
127
- const date = visibleCalendarDays(visible, props.mode)[0]!;
128
- const key = localDayKey(date);
129
- if (key !== localDayKey(visibleCalendarDays(props.date, props.mode)[0]!)) {
130
- reportedTimelineKey = key;
131
- emit('visible-timeline', date);
132
- }
133
- const edgeDistance = Math.max(container.clientWidth, width * 2);
134
- if (container.scrollLeft < edgeDistance)
135
- void extendTimelineDays(-1);
136
- else if (container.scrollWidth - container.scrollLeft - container.clientWidth < edgeDistance)
137
- void extendTimelineDays(1);
138
- }
139
- const zoomModes: CalendarViewMode[] = ['day', 'four-days', 'week', 'month', 'year'];
140
- let zoomDelta = 0;
141
- let lastZoomWheel = -Infinity;
142
- let lastZoomChange = -Infinity;
143
- function onCalendarWheel(event: WheelEvent) {
144
- if (event.ctrlKey) {
145
- // Keep browser zoom disabled here, even at the smallest/largest calendar scale.
146
- event.preventDefault();
147
- event.stopPropagation();
148
- if (!event.deltaY || Math.abs(event.deltaX) > Math.abs(event.deltaY)) return;
149
- const now = performance.now();
150
- if (now - lastZoomWheel > 200 || Math.sign(zoomDelta) !== Math.sign(event.deltaY)) zoomDelta = 0;
151
- lastZoomWheel = now;
152
- if (now - lastZoomChange < 200) return;
153
- const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? scroll.value?.clientHeight || 800 : 1;
154
- zoomDelta += event.deltaY * unit;
155
- if (Math.abs(zoomDelta) < 40) return;
156
- // The agenda lists one month, so zoom from the same scale as the month grid.
157
- const index = zoomModes.indexOf(props.mode === 'agenda' ? 'month' : props.mode);
158
- const mode = zoomModes[Math.max(0, Math.min(zoomModes.length - 1, index + Math.sign(zoomDelta)))]!;
159
- zoomDelta = 0;
160
- if (mode !== props.mode) {
161
- lastZoomChange = now;
162
- emit('select-mode', mode);
163
- }
164
- return;
165
- }
166
- zoomDelta = 0;
167
- if (!timeline.value || !event.shiftKey || !scroll.value) return;
168
- event.preventDefault();
169
- const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
170
- scroll.value.scrollLeft += delta * Math.max(1, timelineDayWidth.value / 360);
171
- }
172
- async function resizeTimeline() {
173
- const container = scroll.value;
174
- if (!timeline.value || !container) return;
175
- const width = Math.max(90, (container.clientWidth - 64) / timelineVisibleCount.value);
176
- if (Math.abs(width - timelineDayWidth.value) < 0.5) return;
177
- const dayPosition = container.scrollLeft / timelineDayWidth.value;
178
- positioningTimeline = true;
179
- timelineDayWidth.value = width;
180
- await nextTick();
181
- container.scrollLeft = dayPosition * width;
182
- positioningTimeline = false;
127
+ function openQuickCreate(planDate: PlanDateValue, checkable = false) {
128
+ if (!canCreate.value || createSaving.value) return;
129
+ const preferred: PlanScope = plans.defaultScope === 'personal' ? 'personal' : 'workspace';
130
+ const scope: PlanScope =
131
+ preferred === 'personal'
132
+ ? (canCreatePersonal.value ? 'personal' : 'workspace')
133
+ : (canCreateWorkspace.value ? 'workspace' : 'personal');
134
+ createError.value = '';
135
+ createDraft.value = { name: '', checkable, planDate, scope };
183
136
  }
184
137
 
185
- function fillWeeks(date: Date) {
186
- const monday = weekDays(date)[0]!;
187
- scrollingWeeks.value = Array.from({ length: 37 }, (_, index) => weekOffset(monday, index - 18));
188
- }
189
- function weekRow(date: Date) {
190
- const key = weekKey(weekDays(date)[0]!);
191
- return [...scroll.value?.querySelectorAll<HTMLElement>('.calendar-month-week') ?? []]
192
- .find(row => row.dataset.week === key);
193
- }
194
- async function scrollToWeek(date: Date) {
195
- const key = weekKey(weekDays(date)[0]!);
196
- if (!scrollingWeeks.value.some(week => weekKey(week) === key)) fillWeeks(date);
197
- await nextTick();
198
- const container = scroll.value;
199
- const row = weekRow(date);
200
- if (!container || !row) return;
201
- container.scrollTop += row.getBoundingClientRect().top - container.getBoundingClientRect().top - 40;
202
- }
203
- async function extendWeeks(direction: -1 | 1) {
204
- if (extendingWeeks || !scroll.value || !scrollingWeeks.value.length) return;
205
- extendingWeeks = true;
206
- const container = scroll.value;
207
- const anchor = [...container.querySelectorAll<HTMLElement>('.calendar-month-week')]
208
- .find(row => row.getBoundingClientRect().bottom > container.getBoundingClientRect().top + 80);
209
- const anchorKey = anchor?.dataset.week;
210
- const anchorTop = anchor?.getBoundingClientRect().top;
211
- const edge = direction < 0 ? scrollingWeeks.value[0]! : scrollingWeeks.value.at(-1)!;
212
- const additions = Array.from({ length: 8 }, (_, index) => weekOffset(edge, direction * (index + 1)));
213
- const expanded = direction < 0
214
- ? [...additions.reverse(), ...scrollingWeeks.value]
215
- : [...scrollingWeeks.value, ...additions];
216
- scrollingWeeks.value = direction < 0 ? expanded.slice(0, 85) : expanded.slice(-85);
217
- await nextTick();
218
- const retained = [...container.querySelectorAll<HTMLElement>('.calendar-month-week')]
219
- .find(row => row.dataset.week === anchorKey);
220
- if (retained && anchorTop !== undefined)
221
- container.scrollTop += retained.getBoundingClientRect().top - anchorTop;
222
- extendingWeeks = false;
223
- }
224
- function onMonthScroll() {
225
- const container = scroll.value;
226
- if (props.mode !== 'month' || !container || !scrollingWeeks.value.length || extendingWeeks) return;
227
- const marker = container.getBoundingClientRect().top + 45;
228
- const row = [...container.querySelectorAll<HTMLElement>('.calendar-month-week')]
229
- .find(element => element.getBoundingClientRect().bottom > marker);
230
- const visible = scrollingWeeks.value.find(week => weekKey(week) === row?.dataset.week);
231
- const visibleMonth = visible && weekDays(visible).some(day => monthKey(day) === monthKey(props.date))
232
- ? props.date : visible;
233
- if (visibleMonth && monthKey(visibleMonth) !== monthKey(props.date)) {
234
- reportedMonthKey = monthKey(visibleMonth);
235
- emit('visible-month', new Date(visibleMonth.getFullYear(), visibleMonth.getMonth(), 1));
236
- }
237
- if (container.scrollTop < container.clientHeight)
238
- void extendWeeks(-1);
239
- else if (container.scrollHeight - container.scrollTop - container.clientHeight < container.clientHeight)
240
- void extendWeeks(1);
138
+ function closeQuickCreate() {
139
+ if (createSaving.value) return;
140
+ createDraft.value = undefined;
141
+ createError.value = '';
241
142
  }
242
- function fillYears(date: Date) {
243
- const year = date.getFullYear();
244
- scrollingYears.value = [year - 1, year, year + 1];
245
- }
246
- function yearSection(year: number) {
247
- return [...scroll.value?.querySelectorAll<HTMLElement>('.calendar-year-section') ?? []]
248
- .find(section => Number(section.dataset.year) === year);
249
- }
250
- async function scrollToYear(date: Date) {
251
- const year = date.getFullYear();
252
- positioningYear = true;
253
- if (!scrollingYears.value.includes(year)) fillYears(date);
254
- await nextTick();
255
- const container = scroll.value;
256
- const section = yearSection(year);
257
- if (container && section)
258
- container.scrollTop += section.getBoundingClientRect().top - container.getBoundingClientRect().top - 12;
259
- positioningYear = false;
260
- }
261
- async function extendYears(direction: -1 | 1) {
262
- if (extendingYears || !scroll.value || !scrollingYears.value.length) return;
263
- extendingYears = true;
264
- const container = scroll.value;
265
- const anchor = [...container.querySelectorAll<HTMLElement>('.calendar-year-section')]
266
- .find(section => section.getBoundingClientRect().bottom > container.getBoundingClientRect().top + 60);
267
- const anchorYear = Number(anchor?.dataset.year);
268
- const anchorTop = anchor?.getBoundingClientRect().top;
269
- const nextYear = direction < 0 ? scrollingYears.value[0]! - 1 : scrollingYears.value.at(-1)! + 1;
270
- const expanded = direction < 0
271
- ? [nextYear, ...scrollingYears.value]
272
- : [...scrollingYears.value, nextYear];
273
- scrollingYears.value = direction < 0 ? expanded.slice(0, 5) : expanded.slice(-5);
274
- await nextTick();
275
- const retained = yearSection(anchorYear);
276
- if (retained && anchorTop !== undefined)
277
- container.scrollTop += retained.getBoundingClientRect().top - anchorTop;
278
- extendingYears = false;
279
- }
280
- function onYearScroll() {
281
- const container = scroll.value;
282
- if (props.mode !== 'year' || !container || !scrollingYears.value.length || extendingYears || positioningYear) return;
283
- const marker = container.getBoundingClientRect().top + 60;
284
- const section = [...container.querySelectorAll<HTMLElement>('.calendar-year-section')]
285
- .find(element => element.getBoundingClientRect().bottom > marker);
286
- const year = Number(section?.dataset.year);
287
- if (section && year !== props.date.getFullYear()) {
288
- reportedYear = year;
289
- emit('visible-year', shiftCalendarDate(props.date, 'year', year - props.date.getFullYear()));
143
+
144
+ async function submitQuickCreate() {
145
+ const draft = createDraft.value;
146
+ if (!draft || createSaving.value || !draft.name.trim() || typeof plans.create !== 'function') return;
147
+ createSaving.value = true;
148
+ createError.value = '';
149
+ try {
150
+ const properties = writePlanDate({ checkable: draft.checkable, completed: false }, draft.planDate);
151
+ await plans.create(
152
+ {
153
+ type: 'event',
154
+ name: draft.name.trim(),
155
+ description: '',
156
+ archived: false,
157
+ properties,
158
+ },
159
+ draft.scope,
160
+ plans.workspaceId,
161
+ );
162
+ createDraft.value = undefined;
163
+ } catch (reason) {
164
+ createError.value = String(reason);
165
+ } finally {
166
+ createSaving.value = false;
290
167
  }
291
- const edgeDistance = Math.min(400, container.clientHeight / 2);
292
- if (container.scrollTop < edgeDistance)
293
- void extendYears(-1);
294
- else if (container.scrollHeight - container.scrollTop - container.clientHeight < edgeDistance)
295
- void extendYears(1);
296
- }
297
- function onCalendarScroll() {
298
- // Focusing a date can queue a scroll event before its click opens the panel.
299
- // Only dismiss for a scroll that actually moves the calendar after opening.
300
- if (yearDay.value && scroll.value && (
301
- yearDay.value.scrollTop !== scroll.value.scrollTop || yearDay.value.scrollLeft !== scroll.value.scrollLeft
302
- )) yearDay.value = undefined;
303
- if (timeline.value) onTimelineScroll();
304
- else if (props.mode === 'month') onMonthScroll();
305
- else if (props.mode === 'year') onYearScroll();
306
- }
307
- function monthShade(day: Date) {
308
- return (day.getFullYear() * 12 + day.getMonth()) % 2 === 1;
309
168
  }
310
169
 
311
- function dayRecords(day: Date) {
312
- return plannedEventsOnDay(planned.value, day);
313
- }
314
- function timedEvents(day: Date) {
315
- const start = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime();
316
- const end = new Date(day.getFullYear(), day.getMonth(), day.getDate() + 1).getTime();
317
- return eventsOnDay(events.value, day).filter(record => !record.object.properties.allDay).map((record) => {
318
- const from = Date.parse(String(record.object.properties.start));
319
- const to = Date.parse(String(record.object.properties.end));
320
- const visibleStart = Math.max(from, start);
321
- const visibleEnd = Math.min(Math.max(to, from + 30 * 60_000), end);
322
- const top = (visibleStart - start) / 3_600_000 * hourHeight;
323
- const point = from === to;
324
- const height = point ? 24 : Math.max(22, (visibleEnd - visibleStart) / 3_600_000 * hourHeight);
325
- return { record, top, height, point, time: eventTime(record) };
326
- });
327
- }
328
- function eventTime(record: ObjectRecord) {
329
- if (record.object.properties.allDay === true) return t('全天');
330
- if (!hasEventTime(record)) return t('仅日期');
331
- return new Date(String(record.object.properties.start)).toLocaleTimeString(uiLocale.value, {
332
- hour: '2-digit', minute: '2-digit', hour12: false,
333
- });
334
- }
335
- function weekday(day: Date) {
336
- return weekdays.value[(day.getDay() + 6) % 7];
337
- }
338
- async function positionTimeline() {
339
- await nextTick();
340
- if (!timeline.value && scroll.value) scroll.value.scrollLeft = 0;
341
- if (timeline.value) {
342
- const container = scroll.value;
343
- if (!container) return;
344
- timelineDayWidth.value = Math.max(90, (container.clientWidth - 64) / timelineVisibleCount.value);
345
- fillTimelineDays(props.date);
346
- await scrollToTimelineDate(props.date);
347
- container.scrollTop = hourHeight * 7;
348
- } else if (props.mode === 'month') {
349
- fillWeeks(props.date);
350
- await scrollToWeek(props.date);
351
- } else if (props.mode === 'year') {
352
- fillYears(props.date);
353
- await scrollToYear(props.date);
354
- } else if (scroll.value) scroll.value.scrollTop = 0;
170
+ const interactions = useCalendarInteractions({
171
+ plans,
172
+ records: () => props.records,
173
+ today,
174
+ canCreate,
175
+ window,
176
+ openQuickCreate,
177
+ });
178
+
179
+ const dayPopoverEntries = (day: Date) => calendarDayEntries(planned.value, day);
180
+ function openDayPopover(day: Date, event: MouseEvent) {
181
+ dayPopover.value =
182
+ dayPopoverKey.value === localDayKey(day)
183
+ ? undefined
184
+ : {
185
+ date: day,
186
+ anchor: event.currentTarget as HTMLElement,
187
+ scrollTop: scroll.value?.scrollTop ?? 0,
188
+ scrollLeft: scroll.value?.scrollLeft ?? 0,
189
+ };
355
190
  }
191
+
356
192
  onMounted(() => {
357
- void positionTimeline();
358
- if (scroll.value && typeof ResizeObserver !== 'undefined') {
359
- timelineResizeObserver = new ResizeObserver(() => { void resizeTimeline(); });
360
- timelineResizeObserver.observe(scroll.value);
361
- }
193
+ nowTimer = setInterval(() => { nowMinutes.value = currentMinutes(); }, 60_000);
362
194
  });
363
- onUnmounted(() => timelineResizeObserver?.disconnect());
364
- watch(() => props.mode, () => {
365
- yearDay.value = undefined;
366
- void positionTimeline();
195
+ onUnmounted(() => {
196
+ if (nowTimer) clearInterval(nowTimer);
367
197
  });
368
- watch(() => props.date, (date) => {
369
- yearDay.value = undefined;
370
- if (props.mode === 'month') {
371
- if (reportedMonthKey === monthKey(date)) {
372
- reportedMonthKey = '';
373
- return;
374
- }
375
- void scrollToWeek(date);
376
- } else if (props.mode === 'year') {
377
- if (reportedYear === date.getFullYear()) {
378
- reportedYear = undefined;
379
- return;
380
- }
381
- void scrollToYear(date);
382
- } else if (timeline.value) {
383
- const key = localDayKey(visibleCalendarDays(date, props.mode)[0]!);
384
- if (reportedTimelineKey === key) {
385
- reportedTimelineKey = '';
386
- return;
387
- }
388
- void scrollToTimelineDate(date);
389
- }
390
- });
391
-
392
198
  </script>
393
199
 
394
200
  <template>
395
- <main
396
- ref="scroll"
397
- class="calendar-view"
398
- :class="{ 'calendar-view-timeline': timeline, 'calendar-view-month': mode === 'month', 'calendar-view-year': mode === 'year' }"
399
- :aria-label="t('日历{0}', [viewLabel])"
400
- @scroll.passive="onCalendarScroll"
401
- @wheel="onCalendarWheel"
402
- >
403
- <LoadingSkeleton v-if="loading" variant="document" :rows="6" />
404
- <div v-show="!loading" class="component-loading-content">
405
- <div
406
- v-if="timeline"
407
- class="calendar-view-inner"
408
- :style="{
409
- '--calendar-day-count': timelineDays.length,
410
- '--calendar-day-width': `${timelineDayWidth}px`,
411
- width: `${64 + timelineDays.length * timelineDayWidth}px`,
412
- }"
201
+ <div class="calendar-shell">
202
+ <CalendarFilterBar v-model="filter" />
203
+ <p v-if="interactions.interactionError.value" class="calendar-error-banner" role="alert">
204
+ <span>{{ interactions.interactionError.value }}</span>
205
+ <button type="button" :aria-label="t('关闭')" @click="interactions.interactionError.value = ''"><X :size="14" /></button>
206
+ </p>
207
+ <main
208
+ ref="scroll"
209
+ class="calendar-view"
210
+ :class="{ 'calendar-view-timeline': timeline, 'calendar-view-month': mode === 'month', 'calendar-view-year': mode === 'year' }"
211
+ :aria-label="t('日历{0}', [viewLabel])"
212
+ @scroll.passive="onCalendarScroll"
213
+ @wheel="onCalendarWheel"
413
214
  >
414
- <div class="calendar-view-days">
415
- <span class="calendar-view-zone">GMT{{ -new Date().getTimezoneOffset() / 60 >= 0 ? '+' : '' }}{{ -new Date().getTimezoneOffset() / 60 }}</span>
416
- <div
417
- v-for="day in timelineDays"
418
- :key="localDayKey(day)"
419
- class="calendar-view-day-heading"
420
- :class="{ today: localDayKey(day) === today }"
421
- >
422
- <span>{{ uiLocale === 'zh-CN' ? t('周') : '' }}{{ weekday(day) }}</span>
423
- <strong>{{ day.getDate() }}</strong>
424
- </div>
425
- <template v-if="hasVisibleDateOnly">
426
- <span class="calendar-view-date-label">{{ t('全天') }}</span>
427
- <div v-for="day in timelineDays" :key="`date-${localDayKey(day)}`" class="calendar-view-date-events">
428
- <button
429
- v-for="record in dateOnlyEvents(day)"
430
- :key="planKey(record)"
431
- type="button"
432
- class="calendar-view-date-event"
433
- :data-tooltip="`${planSourceLabel(record)} · ${record.object.name} · ${eventTime(record)}`"
434
- @click="emit('select-event', planKey(record))"
435
- >{{ record.object.name }}</button>
436
- </div>
437
- </template>
215
+ <LoadingSkeleton v-if="loading" variant="document" :rows="6" />
216
+ <div v-show="!loading" class="component-loading-content">
217
+ <CalendarTimelineView
218
+ v-if="timeline"
219
+ :date="date"
220
+ :mode="mode"
221
+ :timeline-days="timelineDays"
222
+ :timeline-day-width="timelineDayWidth"
223
+ :planned="planned"
224
+ :events="events"
225
+ :today="today"
226
+ :now-minutes="nowMinutes"
227
+ :weekdays="weekdays"
228
+ :can-create="canCreate"
229
+ :interactions="interactions"
230
+ @select-event="emit('select-event', $event)"
231
+ />
232
+ <CalendarMonthView
233
+ v-else-if="mode === 'month'"
234
+ :scrolling-weeks="scrollingWeeks"
235
+ :planned="planned"
236
+ :today="today"
237
+ :weekdays="weekdays"
238
+ :can-create="canCreate"
239
+ :day-popover-key="dayPopoverKey"
240
+ :day-popover-id="dayPopoverId"
241
+ :interactions="interactions"
242
+ @select-date="emit('select-date', $event)"
243
+ @select-event="emit('select-event', $event)"
244
+ @open-day-popover="openDayPopover"
245
+ @open-quick-create="openQuickCreate"
246
+ />
247
+ <CalendarYearView
248
+ v-else-if="mode === 'year'"
249
+ :scrolling-years="scrollingYears"
250
+ :planned="planned"
251
+ :today="today"
252
+ :weekdays="weekdays"
253
+ :day-popover-key="dayPopoverKey"
254
+ :day-popover-id="dayPopoverId"
255
+ @select-month="emit('select-month', $event)"
256
+ @open-day-popover="openDayPopover"
257
+ />
258
+ <CalendarAgendaView
259
+ v-else
260
+ :date="date"
261
+ :planned="planned"
262
+ :today="today"
263
+ :weekdays="weekdays"
264
+ :interactions="interactions"
265
+ @select-event="emit('select-event', $event)"
266
+ />
438
267
  </div>
439
- <div class="calendar-view-grid">
440
- <div class="calendar-view-hours" aria-hidden="true">
441
- <span v-for="hour in hours" :key="hour" :style="{ top: `${hour * hourHeight}px` }">{{ String(hour).padStart(2, '0') }}:00</span>
442
- </div>
443
- <div v-for="day in timelineDays" :key="localDayKey(day)" class="calendar-view-day-column">
444
- <button
445
- v-for="item in timedEvents(day)"
446
- :key="planKey(item.record)"
447
- type="button"
448
- class="calendar-view-event"
449
- :class="{ 'calendar-view-point': item.point }"
450
- :style="{ top: `${item.top}px`, height: `${item.height}px` }"
451
- :data-tooltip="`${planSourceLabel(item.record)} · ${item.record.object.name} · ${item.time}`"
452
- @click="emit('select-event', planKey(item.record))"
453
- >
454
- <strong>{{ item.record.object.name }}</strong>
455
- <span>{{ planSourceLabel(item.record) }} · {{ item.time }}</span>
456
- </button>
457
- </div>
458
- </div>
459
- </div>
460
-
461
- <div v-else-if="mode === 'month'" class="calendar-month-view">
462
- <div class="calendar-month-weekdays" aria-hidden="true">
463
- <span v-for="name in weekdays" :key="name">{{ uiLocale === 'zh-CN' ? t('周') : '' }}{{ name }}</span>
464
- </div>
465
- <div
466
- v-for="week in scrollingWeeks"
467
- :key="weekKey(week)"
468
- class="calendar-month-week"
469
- :data-week="weekKey(week)"
470
- >
471
- <div
472
- v-for="day in weekDays(week)"
473
- :key="localDayKey(day)"
474
- class="calendar-month-cell"
475
- :class="{ shaded: monthShade(day) }"
476
- >
477
- <button
478
- type="button"
479
- class="calendar-month-date"
480
- :class="{ today: localDayKey(day) === today, 'month-start': day.getDate() === 1 }"
481
- :aria-label="t('{0},查看日视图', [localDayKey(day)])"
482
- @click="emit('select-date', day)"
483
- >{{ day.getDate() === 1 ? t('{0} 月 1 日', [day.getMonth() + 1]) : day.getDate() }}</button>
484
- <button
485
- v-for="record in dayRecords(day).slice(0, 3)"
486
- :key="planKey(record)"
487
- type="button"
488
- class="calendar-month-event"
489
- :data-tooltip="`${planSourceLabel(record)} · ${record.object.name} · ${eventTime(record)}`"
490
- @click="emit('select-event', planKey(record))"
491
- >{{ planSourceLabel(record) }} · {{ eventTime(record) }} {{ record.object.name }}</button>
492
- <span v-if="dayRecords(day).length > 3" class="calendar-month-more">{{ t('另有 {0} 项', [dayRecords(day).length - 3]) }}</span>
493
- </div>
494
- </div>
495
- </div>
496
-
497
- <div v-else-if="mode === 'year'" class="calendar-year-view">
498
- <section v-for="year in scrollingYears" :key="year" class="calendar-year-section" :data-year="year">
499
- <h2 class="calendar-year-heading">{{ new Date(year, 0, 1).toLocaleDateString(uiLocale, { year: 'numeric' }) }}</h2>
500
- <div class="calendar-year-grid">
501
- <section v-for="month in monthsForYear(year)" :key="month.date.getMonth()" class="calendar-year-month">
502
- <button type="button" class="calendar-year-month-title" @click="emit('select-month', month.date)">
503
- {{ month.date.toLocaleDateString(uiLocale, { month: 'long' }) }}
504
- </button>
505
- <div class="calendar-year-weekdays" aria-hidden="true">
506
- <span v-for="name in weekdays" :key="name">{{ name }}</span>
507
- </div>
508
- <div class="calendar-year-days">
509
- <template v-for="day in month.days" :key="localDayKey(day)">
510
- <span v-if="day.getMonth() !== month.date.getMonth()" aria-hidden="true" />
511
- <button
512
- v-else
513
- type="button"
514
- :class="{ today: localDayKey(day) === today, selected: localDayKey(day) === yearDayKey }"
515
- :aria-label="t('{0},{1} 个事件', [localDayKey(day), yearDayRecords(day).length])"
516
- aria-haspopup="dialog"
517
- :aria-expanded="localDayKey(day) === yearDayKey"
518
- :aria-controls="localDayKey(day) === yearDayKey ? dayPopoverId : undefined"
519
- @click="openYearDay(day, $event)"
520
- >
521
- <span class="calendar-year-date">{{ day.getDate() }}</span>
522
- <i v-if="yearDayRecords(day).length" class="calendar-year-event-dot" aria-hidden="true" />
523
- </button>
524
- </template>
525
- </div>
526
- </section>
527
- </div>
528
- </section>
529
- </div>
530
-
531
- <div v-else class="calendar-agenda-view">
532
- <p v-if="!agendaDates.length" class="calendar-agenda-empty">{{ t('本月没有日程') }}</p>
533
- <section v-for="day in agendaDates" :key="localDayKey(day)" class="calendar-agenda-day">
534
- <time class="calendar-agenda-date" :datetime="localDayKey(day)">
535
- {{ day.toLocaleDateString(uiLocale, { month: 'short', day: 'numeric' }) }}
536
- </time>
537
- <div class="calendar-agenda-events">
538
- <button
539
- v-for="record in dayRecords(day)"
540
- :key="planKey(record)"
541
- type="button"
542
- @click="emit('select-event', planKey(record))"
543
- >
544
- <time>{{ eventTime(record) }}</time>
545
- <span>{{ record.object.name }} <small>{{ planSourceLabel(record) }}</small></span>
546
- </button>
547
- </div>
548
- </section>
549
- </div>
550
- </div>
551
- </main>
268
+ </main>
269
+ </div>
270
+ <CalendarQuickCreateDialog
271
+ :draft="createDraft"
272
+ :saving="createSaving"
273
+ :error="createError"
274
+ :default-date="localDayKey(date)"
275
+ :can-create-workspace="canCreateWorkspace"
276
+ :can-create-personal="canCreatePersonal"
277
+ @close="closeQuickCreate"
278
+ @submit="submitQuickCreate"
279
+ />
552
280
  <CalendarDayPopover
553
- v-if="mode === 'year' && yearDay"
281
+ v-if="(mode === 'year' || mode === 'month') && dayPopover"
554
282
  :id="dayPopoverId"
555
- :date="yearDay.date"
556
- :anchor="yearDay.anchor"
557
- :records="yearDayRecords(yearDay.date)"
558
- @close="yearDay = undefined"
283
+ :date="dayPopover.date"
284
+ :anchor="dayPopover.anchor"
285
+ :records="dayPopoverEntries(dayPopover.date).map(entry => entry.record)"
286
+ :entries="dayPopoverEntries(dayPopover.date)"
287
+ :can-edit="interactions.canEditRecord"
288
+ :pending="interactions.pending.value"
289
+ @close="dayPopover = undefined"
559
290
  @select-event="emit('select-event', $event)"
291
+ @toggle-complete="interactions.toggleComplete"
560
292
  />
561
293
  </template>
562
294
 
563
295
  <style scoped>
564
- .calendar-view {
565
- flex: 1;
566
- min-height: 0;
567
- overflow: auto;
568
- background: var(--paper);
569
- }
570
- .calendar-view-timeline { overflow-anchor: none; }
571
- .calendar-view-month,
572
- .calendar-view-year { overflow-anchor: none; }
573
- .calendar-view-days,
574
- .calendar-view-grid {
575
- display: grid;
576
- grid-template-columns: 64px repeat(var(--calendar-day-count), var(--calendar-day-width));
577
- }
578
- .calendar-view-days {
579
- position: sticky;
580
- top: 0;
581
- z-index: 2;
582
- grid-template-rows: 70px;
583
- min-height: 70px;
584
- align-items: center;
585
- background: var(--paper);
586
- border-bottom: 1px solid var(--line);
587
- }
588
- .calendar-view-zone {
589
- position: sticky;
590
- left: 0;
591
- z-index: 3;
592
- align-self: stretch;
593
- display: flex;
594
- align-items: flex-end;
595
- padding: 0 0 10px 9px;
596
- background: var(--paper);
597
- font-size: 10px;
598
- color: var(--muted);
599
- }
600
- .calendar-view-day-heading {
296
+ .calendar-error-banner {
601
297
  display: flex;
602
298
  align-items: center;
603
- justify-content: center;
604
- gap: 7px;
605
- color: var(--text-secondary);
606
- }
607
- .calendar-view-day-heading span { font-size: 12px; }
608
- .calendar-view-day-heading strong {
609
- display: grid;
610
- place-items: center;
611
- width: 30px;
612
- height: 30px;
613
- border-radius: 50%;
614
- font-size: 18px;
615
- font-weight: 500;
616
- }
617
- .calendar-view-day-heading.today { color: var(--green); }
618
- .calendar-view-date-label {
619
- position: sticky;
620
- left: 0;
621
- z-index: 3;
622
- align-self: stretch;
623
- padding: 10px 9px;
624
- border-top: 1px solid var(--line);
625
- background: var(--paper);
626
- color: var(--muted);
627
- font-size: 10px;
628
- }
629
- .calendar-view-date-events {
630
- display: flex;
631
- flex-direction: column;
632
- align-self: stretch;
633
- gap: 4px;
634
- max-height: 104px;
635
- overflow: auto;
636
- padding: 6px 4px;
637
- border-top: 1px solid var(--line);
638
- border-left: 1px solid var(--line);
639
- }
640
- .calendar-view-date-event {
641
- flex-shrink: 0;
642
- padding: 4px 6px;
643
- overflow: hidden;
644
- text-overflow: ellipsis;
645
- white-space: nowrap;
646
- border-radius: 4px;
647
- background: var(--accent);
648
- color: var(--text);
649
- text-align: left;
650
- font-size: 11px;
651
- }
652
- .calendar-view-date-event:hover { background: var(--hover); }
653
- .calendar-view-date-event:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
654
- .calendar-view-day-heading.today strong,
655
- .calendar-month-date.today,
656
- .calendar-year-days button.today > .calendar-year-date { color: var(--on-accent, white); background: var(--green-fill); }
657
- .calendar-view-grid { height: 1344px; }
658
- .calendar-view-hours { position: sticky; left: 0; z-index: 1; background: var(--paper); }
659
- .calendar-view-hours span {
660
- position: absolute;
661
- right: 9px;
662
- transform: translateY(-8px);
663
- font-size: 11px;
664
- color: var(--muted);
665
- font-variant-numeric: tabular-nums;
666
- }
667
- .calendar-view-day-column {
668
- position: relative;
669
- border-left: 1px solid var(--line);
670
- background: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent 56px);
671
- }
672
- .calendar-view-event {
673
- position: absolute;
674
- z-index: 1;
675
- left: 3px;
676
- width: calc(100% - 6px);
677
- display: flex;
678
- flex-direction: column;
679
- align-items: flex-start;
680
- gap: 2px;
681
- overflow: hidden;
682
- padding: 4px 6px;
683
- border-left: 3px solid var(--green);
684
- border-radius: 4px;
685
- background: color-mix(in srgb, var(--green) 17%, var(--paper));
686
- color: var(--text);
687
- text-align: left;
688
- font-size: 11px;
689
- }
690
- .calendar-view-event:hover,
691
- .calendar-view-event:focus-visible { background: color-mix(in srgb, var(--green) 27%, var(--paper)); }
692
- .calendar-view-event strong,
693
- .calendar-view-event span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
694
- .calendar-view-event strong { font-size: 12px; font-weight: 500; }
695
- .calendar-view-point { flex-direction: row; align-items: center; gap: 5px; padding: 2px 4px 2px 13px; border-left: 0; background: transparent; }
696
- .calendar-view-point::before { content: ''; position: absolute; left: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
697
- .calendar-view-point span { color: var(--muted); }
698
- .calendar-month-view { min-width: 630px; }
699
- .calendar-month-weekdays,
700
- .calendar-month-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
701
- .calendar-month-weekdays {
702
- position: sticky;
703
- top: 0;
704
- z-index: 2;
705
- background: var(--paper);
299
+ justify-content: space-between;
300
+ gap: 10px;
301
+ margin: 0;
302
+ padding: 6px 14px;
706
303
  border-bottom: 1px solid var(--line);
707
- }
708
- .calendar-month-weekdays span {
709
- padding: 12px 8px;
710
- color: var(--muted);
304
+ background: color-mix(in srgb, var(--danger, #c24141) 10%, var(--paper));
305
+ color: var(--danger, #c24141);
711
306
  font-size: 12px;
712
- text-align: center;
307
+ animation: tano-rise-in var(--motion-spring) var(--ease-spring-smooth);
713
308
  }
714
- .calendar-month-cell {
715
- min-height: 100px;
716
- padding: 7px 6px;
717
- border-right: 1px solid var(--line);
718
- border-bottom: 1px solid var(--line);
719
- overflow: hidden;
720
- }
721
- .calendar-month-cell.shaded { background: var(--surface); }
722
- .calendar-month-date,
723
- .calendar-year-days button {
309
+ .calendar-error-banner button {
724
310
  display: grid;
725
311
  place-items: center;
726
- width: 27px;
727
- height: 27px;
728
- border-radius: 50%;
729
- font-variant-numeric: tabular-nums;
730
- }
731
- .calendar-month-date { margin: 0 0 5px auto; font-size: 12px; }
732
- .calendar-month-date.month-start { width: auto; min-width: 27px; padding: 0 5px; font-weight: 500; }
733
- .calendar-month-date:hover,
734
- .calendar-year-days button:hover { background: var(--hover); }
735
- .calendar-month-event {
736
- display: block;
737
- width: 100%;
738
- overflow: hidden;
739
- margin-top: 3px;
740
- padding: 3px 5px;
741
- border-radius: 4px;
742
- background: var(--accent);
743
- color: var(--text);
744
- font-size: 11px;
745
- text-align: left;
746
- text-overflow: ellipsis;
747
- white-space: nowrap;
748
- }
749
- .calendar-month-event:hover { background: var(--hover); }
750
- .calendar-month-more { display: block; padding: 4px; color: var(--muted); font-size: 11px; }
751
- .calendar-year-heading {
752
- max-width: 1200px;
753
- margin: 0 auto;
754
- padding: 22px 28px 0;
755
- color: var(--text);
756
- font-size: 16px;
757
- font-weight: 600;
758
- }
759
- .calendar-year-grid {
760
- display: grid;
761
- grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
762
- gap: 28px 22px;
763
- max-width: 1200px;
764
- margin: 0 auto;
765
- padding: 28px;
766
- }
767
- .calendar-year-month { min-width: 0; }
768
- .calendar-year-month-title { margin-bottom: 11px; color: var(--text); font-size: 15px; font-weight: 600; }
769
- .calendar-year-month-title:hover { color: var(--text); }
770
- .calendar-year-weekdays,
771
- .calendar-year-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; }
772
- .calendar-year-weekdays span { padding-bottom: 4px; color: var(--muted); font-size: 10px; }
773
- .calendar-year-days button,
774
- .calendar-year-days > span { width: 28px; height: 28px; margin: auto; font-size: 11px; }
775
- .calendar-year-days button { position: relative; padding: 0; }
776
- .calendar-year-date { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; }
777
- .calendar-year-event-dot {
778
- position: absolute;
779
- bottom: 1px;
780
- width: 3px;
781
- height: 3px;
782
- border-radius: 50%;
783
- background: var(--green);
784
- }
785
- .calendar-year-days button.selected { color: var(--green); background: var(--accent); }
786
- .calendar-year-days button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
787
- .calendar-agenda-view { max-width: 900px; margin: 0 auto; padding: 28px 32px; }
788
- .calendar-agenda-empty { padding: 60px 0; color: var(--muted); text-align: center; }
789
- .calendar-agenda-day { display: flex; gap: 24px; padding: 18px 0; border-bottom: 1px solid var(--line); line-height: 20px; }
790
- .calendar-agenda-date { display: flex; align-items: center; width: 120px; flex-shrink: 0; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
791
- .calendar-agenda-events { flex: 1; min-width: 0; }
792
- .calendar-agenda-events button { display: flex; align-items: center; gap: 20px; width: 100%; padding: 10px 12px; border-radius: 6px; color: var(--text); text-align: left; }
793
- .calendar-agenda-events button:hover { background: var(--hover); }
794
- .calendar-agenda-events time { width: 46px; flex-shrink: 0; color: var(--muted); font-size: 12px; }
795
- @media (max-width: 700px) {
796
- .calendar-year-heading { padding: 18px 18px 0; }
797
- .calendar-year-grid { padding: 18px; }
798
- .calendar-agenda-view { padding: 18px; }
799
- .calendar-agenda-day { gap: 10px; }
800
- .calendar-agenda-date { width: 88px; }
312
+ width: 22px;
313
+ height: 22px;
314
+ border-radius: 5px;
315
+ color: inherit;
801
316
  }
317
+ .calendar-error-banner button:hover { background: color-mix(in srgb, var(--danger, #c24141) 14%, transparent); color: inherit; }
802
318
  </style>