@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.
- package/package.json +50 -16
- package/src/App.vue +82 -752
- package/src/appearance/appearance.ts +14 -4
- package/src/appearance/components/ThemePresetPreview.vue +52 -8
- package/src/appearance/interface-font.ts +99 -0
- package/src/appearance/theme.ts +26 -10
- package/src/appearance/use-interface-font.ts +30 -0
- package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
- package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
- package/src/assets/mail-provider-icons/gmail.svg +1 -0
- package/src/assets/mail-provider-icons/icloud.svg +12 -0
- package/src/assets/mail-provider-icons/netease-126.svg +5 -0
- package/src/assets/mail-provider-icons/netease-163.svg +5 -0
- package/src/assets/mail-provider-icons/qq.svg +9 -0
- package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
- package/src/assistant/agent-identities.ts +1 -97
- package/src/assistant/agent-task-context.ts +1 -54
- package/src/assistant/attachments.ts +1 -1
- package/src/assistant/completion.ts +1 -61
- package/src/assistant/components/AssistantChangeList.vue +98 -21
- package/src/assistant/components/AssistantPanel.vue +425 -8
- package/src/assistant/components/PluginToolProposalCard.vue +235 -0
- package/src/assistant/connection-actions.ts +237 -0
- package/src/assistant/document-mentions.ts +1 -33
- package/src/assistant/engine.ts +1 -532
- package/src/assistant/execution.ts +6 -33
- package/src/assistant/files.ts +5 -13
- package/src/assistant/hash.ts +1 -4
- package/src/assistant/inbox.ts +1 -148
- package/src/assistant/language.ts +10 -37
- package/src/assistant/mention-autocomplete.ts +69 -0
- package/src/assistant/plugin-bridge-builder.ts +146 -0
- package/src/assistant/prompts.ts +1 -58
- package/src/assistant/proposal-actions.ts +336 -0
- package/src/assistant/results.ts +20 -86
- package/src/assistant/store.ts +167 -327
- package/src/assistant/structures.ts +1 -155
- package/src/assistant/tasks.ts +8 -96
- package/src/assistant/tool-rules.ts +1 -7
- package/src/assistant/workspace-bridge.ts +1 -1
- package/src/composables/use-document-actions.ts +38 -20
- package/src/composables/use-file-tree-controller.ts +7 -12
- package/src/composables/use-workbench-help.ts +177 -0
- package/src/composables/use-workbench-history.ts +2 -4
- package/src/composables/use-workbench-lifecycle.ts +249 -0
- package/src/composables/use-workbench-modals.ts +6 -1
- package/src/composables/use-workbench-outline.ts +0 -5
- package/src/composables/use-workbench-settings.ts +185 -0
- package/src/composables/use-workbench-shortcuts.ts +40 -1021
- package/src/composables/use-workbench-views.ts +325 -0
- package/src/data-tables/data-tables.ts +1 -2
- package/src/documents/components/DocumentActionMenu.vue +279 -0
- package/src/documents/components/DocumentHistoryPanel.vue +3 -1
- package/src/documents/components/DocumentInspector.vue +168 -0
- package/src/documents/components/DocumentPane.vue +482 -0
- package/src/documents/description-merge.ts +1 -9
- package/src/features.ts +1 -0
- package/src/files/components/FileMetadataPanel.vue +49 -15
- package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
- package/src/fonts/Inter-Latin.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
- package/src/help/help-milestones.ts +3 -5
- package/src/i18n/locale-catalogs.ts +7 -6
- package/src/i18n/locale-registry.ts +8 -6
- package/src/i18n/locales/de-DE.json +371 -3
- package/src/i18n/locales/en-US.json +371 -2
- package/src/i18n/locales/es-ES.json +371 -3
- package/src/i18n/locales/ja-JP.json +370 -2
- package/src/i18n/locales/zh-TW.json +370 -2
- package/src/mail/components/MailAccountDialog.vue +450 -0
- package/src/mail/components/MailComposerDialog.vue +326 -0
- package/src/mail/components/MailProviderIcon.vue +30 -0
- package/src/mail/components/MailWorkspaceView.vue +821 -0
- package/src/mail/components/SidebarMail.vue +134 -0
- package/src/mail/mail-avatar.ts +17 -0
- package/src/mail/mail-bridge.ts +68 -0
- package/src/mail/mail-calendar.ts +208 -0
- package/src/mail/mail-markdown.ts +195 -0
- package/src/mail/types.ts +226 -0
- package/src/objects/components/ObjectDetailModal.vue +1001 -0
- package/src/objects/content-references.ts +6 -56
- package/src/objects/wiki-links.ts +1 -48
- package/src/objects/workspace-objects.ts +3 -4
- package/src/plan-sync/types.ts +6 -3
- package/src/plans/calendar-interaction.ts +194 -0
- package/src/plans/calendar.ts +65 -9
- package/src/plans/components/CalendarAgendaView.vue +165 -0
- package/src/plans/components/CalendarDayPopover.vue +172 -39
- package/src/plans/components/CalendarFilterBar.vue +128 -0
- package/src/plans/components/CalendarMonthView.vue +224 -0
- package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
- package/src/plans/components/CalendarTimelineView.vue +517 -0
- package/src/plans/components/CalendarTopbarControls.vue +101 -0
- package/src/plans/components/CalendarView.vue +264 -748
- package/src/plans/components/CalendarYearView.vue +138 -0
- package/src/plans/components/PlanArchiveDialog.vue +295 -0
- package/src/plans/components/PlanConnectionsDialog.vue +1 -1
- package/src/plans/components/PlanDateField.vue +6 -4
- package/src/plans/components/PlanDetailPanel.vue +227 -32
- package/src/plans/components/PlanEventList.vue +16 -4
- package/src/plans/components/SidebarPlan.vue +22 -15
- package/src/plans/components/TaskRepeatControls.vue +169 -30
- package/src/plans/components/calendar-shared.css +192 -0
- package/src/plans/composables/use-calendar-interactions.ts +396 -0
- package/src/plans/composables/use-calendar-scroll.ts +420 -0
- package/src/plans/local-reminders.ts +149 -0
- package/src/plans/personal-plans.ts +10 -1
- package/src/plans/plan-date.ts +8 -1
- package/src/plans/plan-migration.ts +95 -0
- package/src/plans/recurrence.ts +95 -0
- package/src/plans/task-repeat.ts +8 -8
- package/src/plans/timeline-layout.ts +92 -0
- package/src/plugins/assistant-bridge.ts +520 -0
- package/src/plugins/attachment-reader.ts +3 -1
- package/src/plugins/cache-storage.ts +42 -2
- package/src/plugins/components/PluginAutomations.vue +3 -3
- package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
- package/src/plugins/components/PluginChangeSummary.vue +16 -3
- package/src/plugins/components/PluginConnections.vue +1 -1
- package/src/plugins/components/PluginCustomView.vue +2 -2
- package/src/plugins/components/PluginDetailPage.vue +136 -57
- package/src/plugins/components/PluginDeveloperArea.vue +192 -0
- package/src/plugins/components/PluginDocumentSlot.vue +63 -0
- package/src/plugins/components/PluginExplorer.vue +21 -25
- package/src/plugins/components/PluginImportDialog.vue +410 -0
- package/src/plugins/components/PluginInstaller.vue +273 -288
- package/src/plugins/components/PluginListItem.vue +3 -0
- package/src/plugins/components/PluginMaintenance.vue +37 -34
- package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
- package/src/plugins/components/PluginRuntimePanel.vue +3 -3
- package/src/plugins/components/PluginSettingsForm.vue +112 -0
- package/src/plugins/components/PluginStatusBar.vue +161 -0
- package/src/plugins/components/PluginSurface.vue +18 -6
- package/src/plugins/components/PluginUiDialog.vue +452 -0
- package/src/plugins/components/PluginsTabPage.vue +61 -0
- package/src/plugins/components/plugin-center.css +5 -0
- package/src/plugins/data.ts +9 -86
- package/src/plugins/editor-plugin-adapters.ts +169 -0
- package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
- package/src/plugins/excalidraw/manifest.json +12 -1
- package/src/plugins/host.ts +662 -43
- package/src/plugins/native.ts +2 -10
- package/src/plugins/overlay-mapping.ts +125 -0
- package/src/plugins/packages.ts +73 -1
- package/src/plugins/plugin-data.ts +2 -3
- package/src/plugins/plugin-permissions.ts +57 -0
- package/src/plugins/plugin-rpc-router.ts +558 -0
- package/src/plugins/plugin-sdk.ts +1 -94
- package/src/plugins/plugin-ui-dialogs.ts +167 -0
- package/src/plugins/policy.ts +53 -3
- package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/presentation-preview/manifest.json +2 -1
- package/src/plugins/queries.ts +1 -73
- package/src/plugins/sandbox.ts +15 -1
- package/src/plugins/use-plugin-actions.ts +67 -20
- package/src/plugins/user-plugins.ts +254 -0
- package/src/plugins/view-header.ts +2 -7
- package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/word-preview/manifest.json +13 -1
- package/src/plugins/workbench.ts +175 -2
- package/src/plugins/worker.js +105 -8
- package/src/plugins/workspace-plugin-runtime.ts +23 -7
- package/src/plugins/workspace-plugins.ts +212 -21
- package/src/runtime.ts +103 -4
- package/src/settings/components/SettingsAppearancePage.vue +46 -0
- package/src/settings/components/SettingsDocumentsPage.vue +0 -1
- package/src/settings/components/SettingsPanel.vue +8 -3
- package/src/settings/components/WorkbenchSettings.vue +20 -7
- package/src/settings/components/settings-context.ts +1 -1
- package/src/settings/components/settings-search.ts +2 -3
- package/src/settings/settings-tab.ts +1 -0
- package/src/shell/command-palette.ts +3 -3
- package/src/shell/components/EditorToolbar.vue +8 -9
- package/src/shell/components/EditorTools.vue +1 -5
- package/src/shell/components/PaneTopbar.vue +393 -0
- package/src/shell/components/SelectionToolbar.vue +0 -2
- package/src/shell/components/SidebarNavigation.vue +22 -2
- package/src/shell/components/WorkbenchContextMenus.vue +58 -34
- package/src/shell/components/WorkbenchModals.vue +47 -62
- package/src/shell/components/WorkbenchPanes.vue +371 -1342
- package/src/shell/components/WorkbenchSidebar.vue +486 -0
- package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
- package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
- package/src/shell/pane-registry.ts +69 -0
- package/src/shell/use-surface-dismissal.ts +219 -0
- package/src/shell/use-workbench-commands.ts +599 -0
- package/src/shell/use-workbench-keybindings.ts +337 -0
- package/src/shell/use-workbench.ts +531 -1153
- package/src/shell/workbench-async-components.ts +14 -5
- package/src/shell/workbench-context.ts +30 -3
- package/src/stores/mail.ts +414 -0
- package/src/stores/plan-sync.ts +2 -1
- package/src/stores/plans.ts +2 -9
- package/src/stores/workspace-document-io.ts +807 -0
- package/src/stores/workspace-file-ops.ts +1 -1
- package/src/stores/workspace-knowledge.ts +2 -114
- package/src/stores/workspace-lifecycle.ts +459 -0
- package/src/stores/workspace-plugins-state.ts +254 -259
- package/src/stores/workspace-session.ts +287 -0
- package/src/stores/workspace-tabs-layout.ts +6 -44
- package/src/stores/workspace-types.ts +50 -0
- package/src/stores/workspace.ts +184 -1363
- package/src/styles/agent-diff-modals.css +0 -7
- package/src/styles/dark-theme.css +3 -3
- package/src/styles/inspector.css +0 -59
- package/src/styles/layout-themes.css +346 -0
- package/src/styles/mail.css +1568 -0
- package/src/styles/mobile.css +2 -2
- package/src/styles/recent-and-media.css +0 -17
- package/src/styles/theme-contract.css +3 -3
- package/src/styles/workbench-shell.css +110 -17
- package/src/styles/workspace-states.css +9 -33
- package/src/styles.css +0 -1
- package/src/tabs/components/DesktopTabs.vue +19 -14
- package/src/tabs/components/NewTabPicker.vue +10 -4
- package/src/tabs/tab-label.ts +0 -1
- package/src/windows/AuxiliaryWindows.vue +2 -2
- package/src/windows/use-window-event-bridge.ts +152 -0
- package/src/workspace/components/TemplateLibrary.vue +1 -1
- package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
- package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
- package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
- package/src/workspace/workspace-comments.ts +11 -151
- package/src/workspace/workspace-welcome.ts +1 -1
- package/src/assistant/locales/de-DE.json +0 -126
- package/src/assistant/locales/en-US.json +0 -126
- package/src/assistant/locales/es-ES.json +0 -126
- package/src/assistant/locales/ja-JP.json +0 -126
- package/src/assistant/locales/zh-CN.json +0 -126
- package/src/assistant/locales/zh-TW.json +0 -126
- package/src/assistant/task-prompts.json +0 -39
- package/src/documents/components/FormulaMenu.vue +0 -50
- package/src/files/components/FileDatabasePage.vue +0 -152
- package/src/files/components/FolderHomeIcon.vue +0 -12
- package/src/objects/components/ObjectDatabasePage.vue +0 -100
- package/src/objects/components/ObjectPanel.vue +0 -554
- package/src/plans/components/PersonalPlanDialog.vue +0 -105
- package/src/shell/components/WorkspaceViewPage.vue +0 -127
- package/src/shell/components/WorkspaceViewTab.vue +0 -24
- package/src/styles/object-panel.css +0 -163
- package/src/workspace/components/GitInspectionPanel.vue +0 -35
- package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
- package/src/workspace/welcome-slogans.ts +0 -11
- package/src/workspace/workspace-git.ts +0 -35
- package/src/workspace/workspace-sync.ts +0 -46
- package/src/workspace/workspace-views.ts +0 -48
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { computed, nextTick, onMounted, onUnmounted, ref, watch, type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
localDayKey,
|
|
4
|
+
shiftCalendarDate,
|
|
5
|
+
visibleCalendarDays,
|
|
6
|
+
weekDays,
|
|
7
|
+
type CalendarViewMode,
|
|
8
|
+
} from '../calendar';
|
|
9
|
+
|
|
10
|
+
export const CALENDAR_HOUR_HEIGHT = 56;
|
|
11
|
+
|
|
12
|
+
const ZOOM_MODES: CalendarViewMode[] = ['day', 'four-days', 'week', 'month', 'year'];
|
|
13
|
+
|
|
14
|
+
export interface CalendarScrollOptions {
|
|
15
|
+
date: () => Date;
|
|
16
|
+
mode: () => CalendarViewMode;
|
|
17
|
+
scroll: Ref<HTMLElement | undefined>;
|
|
18
|
+
window: Window;
|
|
19
|
+
onVisibleMonth: (date: Date) => void;
|
|
20
|
+
onVisibleYear: (date: Date) => void;
|
|
21
|
+
onVisibleTimeline: (date: Date) => void;
|
|
22
|
+
onSelectMode: (mode: CalendarViewMode) => void;
|
|
23
|
+
onBeforeViewChange: () => void;
|
|
24
|
+
onScrolled: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CalendarScrollState {
|
|
28
|
+
timeline: ComputedRef<boolean>;
|
|
29
|
+
timelineDays: Ref<Date[]>;
|
|
30
|
+
timelineDayWidth: Ref<number>;
|
|
31
|
+
timelineVisibleCount: ComputedRef<number>;
|
|
32
|
+
scrollingWeeks: Ref<Date[]>;
|
|
33
|
+
scrollingYears: Ref<number[]>;
|
|
34
|
+
visibleWindow: ComputedRef<[Date, Date]>;
|
|
35
|
+
onCalendarScroll: () => void;
|
|
36
|
+
onCalendarWheel: (event: WheelEvent) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useCalendarScroll(options: CalendarScrollOptions): CalendarScrollState {
|
|
40
|
+
const { date: getDate, mode: getMode, scroll, window } = options;
|
|
41
|
+
const ResizeObserverCtor = (window as Window & typeof globalThis).ResizeObserver;
|
|
42
|
+
|
|
43
|
+
const timeline = computed(() => {
|
|
44
|
+
const mode = getMode();
|
|
45
|
+
return mode === 'day' || mode === 'four-days' || mode === 'week';
|
|
46
|
+
});
|
|
47
|
+
const timelineDays = ref<Date[]>([]);
|
|
48
|
+
const timelineDayWidth = ref(120);
|
|
49
|
+
const timelineVisibleCount = computed(() => {
|
|
50
|
+
const mode = getMode();
|
|
51
|
+
return mode === 'week' ? 7 : mode === 'four-days' ? 4 : 1;
|
|
52
|
+
});
|
|
53
|
+
const scrollingWeeks = ref<Date[]>([]);
|
|
54
|
+
const scrollingYears = ref<number[]>([]);
|
|
55
|
+
|
|
56
|
+
const visibleWindow = computed<[Date, Date]>(() => {
|
|
57
|
+
if (timeline.value && timelineDays.value.length) {
|
|
58
|
+
return [timelineDays.value[0]!, timelineDays.value.at(-1)!];
|
|
59
|
+
}
|
|
60
|
+
if (getMode() === 'month' && scrollingWeeks.value.length) {
|
|
61
|
+
const last = scrollingWeeks.value.at(-1)!;
|
|
62
|
+
return [scrollingWeeks.value[0]!, new Date(last.getFullYear(), last.getMonth(), last.getDate() + 6)];
|
|
63
|
+
}
|
|
64
|
+
if (getMode() === 'year' && scrollingYears.value.length) {
|
|
65
|
+
return [new Date(scrollingYears.value[0]!, 0, 1), new Date(scrollingYears.value.at(-1)!, 11, 31)];
|
|
66
|
+
}
|
|
67
|
+
const current = getDate();
|
|
68
|
+
return [
|
|
69
|
+
new Date(current.getFullYear(), current.getMonth(), 1),
|
|
70
|
+
new Date(current.getFullYear(), current.getMonth() + 1, 0),
|
|
71
|
+
];
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const monthKey = (d: Date) => `${d.getFullYear()}-${d.getMonth()}`;
|
|
75
|
+
const weekKey = localDayKey;
|
|
76
|
+
const weekOffset = (d: Date, weeks: number) =>
|
|
77
|
+
new Date(d.getFullYear(), d.getMonth(), d.getDate() + weeks * 7);
|
|
78
|
+
const dayOffset = (d: Date, days: number) =>
|
|
79
|
+
new Date(d.getFullYear(), d.getMonth(), d.getDate() + days);
|
|
80
|
+
|
|
81
|
+
let reportedMonthKey = '';
|
|
82
|
+
let extendingWeeks = false;
|
|
83
|
+
let reportedYear: number | undefined;
|
|
84
|
+
let extendingYears = false;
|
|
85
|
+
let positioningYear = false;
|
|
86
|
+
let reportedTimelineKey = '';
|
|
87
|
+
let extendingTimeline = false;
|
|
88
|
+
let positioningTimeline = false;
|
|
89
|
+
let timelineResizeObserver: ResizeObserver | undefined;
|
|
90
|
+
|
|
91
|
+
let zoomDelta = 0;
|
|
92
|
+
let lastZoomWheel = -Infinity;
|
|
93
|
+
let lastZoomChange = -Infinity;
|
|
94
|
+
|
|
95
|
+
function fillTimelineDays(d: Date) {
|
|
96
|
+
const first = visibleCalendarDays(d, getMode())[0]!;
|
|
97
|
+
timelineDays.value = Array.from({ length: 42 }, (_, index) => dayOffset(first, index - 14));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function scrollToTimelineDate(d: Date) {
|
|
101
|
+
positioningTimeline = true;
|
|
102
|
+
const first = visibleCalendarDays(d, getMode())[0]!;
|
|
103
|
+
let index = timelineDays.value.findIndex((day) => localDayKey(day) === localDayKey(first));
|
|
104
|
+
if (index < 0) {
|
|
105
|
+
fillTimelineDays(d);
|
|
106
|
+
index = 14;
|
|
107
|
+
}
|
|
108
|
+
await nextTick();
|
|
109
|
+
if (scroll.value) scroll.value.scrollLeft = index * timelineDayWidth.value;
|
|
110
|
+
positioningTimeline = false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function extendTimelineDays(direction: -1 | 1) {
|
|
114
|
+
const container = scroll.value;
|
|
115
|
+
if (extendingTimeline || !container || !timelineDays.value.length) return;
|
|
116
|
+
extendingTimeline = true;
|
|
117
|
+
const width = timelineDayWidth.value;
|
|
118
|
+
const anchorIndex = Math.min(timelineDays.value.length - 1, Math.floor(container.scrollLeft / width));
|
|
119
|
+
const anchorKey = localDayKey(timelineDays.value[anchorIndex]!);
|
|
120
|
+
const anchorOffset = container.scrollLeft - anchorIndex * width;
|
|
121
|
+
const edge = direction < 0 ? timelineDays.value[0]! : timelineDays.value.at(-1)!;
|
|
122
|
+
const additions = Array.from({ length: 14 }, (_, index) => dayOffset(edge, direction * (index + 1)));
|
|
123
|
+
const expanded = direction < 0
|
|
124
|
+
? [...additions.reverse(), ...timelineDays.value]
|
|
125
|
+
: [...timelineDays.value, ...additions];
|
|
126
|
+
timelineDays.value = direction < 0 ? expanded.slice(0, 70) : expanded.slice(-70);
|
|
127
|
+
await nextTick();
|
|
128
|
+
const retainedIndex = timelineDays.value.findIndex((day) => localDayKey(day) === anchorKey);
|
|
129
|
+
if (retainedIndex >= 0) container.scrollLeft = retainedIndex * width + anchorOffset;
|
|
130
|
+
extendingTimeline = false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function onTimelineScroll() {
|
|
134
|
+
const container = scroll.value;
|
|
135
|
+
if (!timeline.value || !container || !timelineDays.value.length || positioningTimeline || extendingTimeline) return;
|
|
136
|
+
const width = timelineDayWidth.value;
|
|
137
|
+
const index = Math.min(timelineDays.value.length - 1, Math.max(0, Math.round(container.scrollLeft / width)));
|
|
138
|
+
const visible = timelineDays.value[index]!;
|
|
139
|
+
const mode = getMode();
|
|
140
|
+
const d = visibleCalendarDays(visible, mode)[0]!;
|
|
141
|
+
const key = localDayKey(d);
|
|
142
|
+
if (key !== localDayKey(visibleCalendarDays(getDate(), mode)[0]!)) {
|
|
143
|
+
reportedTimelineKey = key;
|
|
144
|
+
options.onVisibleTimeline(d);
|
|
145
|
+
}
|
|
146
|
+
const edgeDistance = Math.max(container.clientWidth, width * 2);
|
|
147
|
+
if (container.scrollLeft < edgeDistance)
|
|
148
|
+
void extendTimelineDays(-1);
|
|
149
|
+
else if (container.scrollWidth - container.scrollLeft - container.clientWidth < edgeDistance)
|
|
150
|
+
void extendTimelineDays(1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function onCalendarWheel(event: WheelEvent) {
|
|
154
|
+
const mode = getMode();
|
|
155
|
+
if (event.ctrlKey) {
|
|
156
|
+
// Keep browser zoom disabled here, even at the smallest/largest calendar scale.
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
event.stopPropagation();
|
|
159
|
+
if (!event.deltaY || Math.abs(event.deltaX) > Math.abs(event.deltaY)) return;
|
|
160
|
+
const now = performance.now();
|
|
161
|
+
if (now - lastZoomWheel > 200 || Math.sign(zoomDelta) !== Math.sign(event.deltaY)) zoomDelta = 0;
|
|
162
|
+
lastZoomWheel = now;
|
|
163
|
+
if (now - lastZoomChange < 200) return;
|
|
164
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? scroll.value?.clientHeight || 800 : 1;
|
|
165
|
+
zoomDelta += event.deltaY * unit;
|
|
166
|
+
if (Math.abs(zoomDelta) < 40) return;
|
|
167
|
+
// The agenda lists one month, so zoom from the same scale as the month grid.
|
|
168
|
+
const index = ZOOM_MODES.indexOf(mode === 'agenda' ? 'month' : mode);
|
|
169
|
+
const nextMode = ZOOM_MODES[Math.max(0, Math.min(ZOOM_MODES.length - 1, index + Math.sign(zoomDelta)))]!;
|
|
170
|
+
zoomDelta = 0;
|
|
171
|
+
if (nextMode !== mode) {
|
|
172
|
+
lastZoomChange = now;
|
|
173
|
+
options.onSelectMode(nextMode);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
zoomDelta = 0;
|
|
178
|
+
if (!timeline.value || !event.shiftKey || !scroll.value) return;
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
|
|
181
|
+
scroll.value.scrollLeft += delta * Math.max(1, timelineDayWidth.value / 360);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function resizeTimeline() {
|
|
185
|
+
const container = scroll.value;
|
|
186
|
+
if (!timeline.value || !container) return;
|
|
187
|
+
const width = Math.max(90, (container.clientWidth - 64) / timelineVisibleCount.value);
|
|
188
|
+
if (Math.abs(width - timelineDayWidth.value) < 0.5) return;
|
|
189
|
+
const dayPosition = container.scrollLeft / timelineDayWidth.value;
|
|
190
|
+
positioningTimeline = true;
|
|
191
|
+
timelineDayWidth.value = width;
|
|
192
|
+
await nextTick();
|
|
193
|
+
container.scrollLeft = dayPosition * width;
|
|
194
|
+
positioningTimeline = false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function fillWeeks(d: Date) {
|
|
198
|
+
const monday = weekDays(d)[0]!;
|
|
199
|
+
scrollingWeeks.value = Array.from({ length: 37 }, (_, index) => weekOffset(monday, index - 18));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function weekRow(d: Date) {
|
|
203
|
+
const key = weekKey(weekDays(d)[0]!);
|
|
204
|
+
return [...(scroll.value?.querySelectorAll<HTMLElement>('.calendar-month-week') ?? [])]
|
|
205
|
+
.find((row) => row.dataset.week === key);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function scrollToWeek(d: Date) {
|
|
209
|
+
// Month navigation lands on the week holding the 1st, so the whole month is
|
|
210
|
+
// in view and the dominant-month check in onMonthScroll agrees with it.
|
|
211
|
+
const monthStart = new Date(d.getFullYear(), d.getMonth(), 1);
|
|
212
|
+
const key = weekKey(weekDays(monthStart)[0]!);
|
|
213
|
+
if (!scrollingWeeks.value.some((week) => weekKey(week) === key)) fillWeeks(monthStart);
|
|
214
|
+
await nextTick();
|
|
215
|
+
const container = scroll.value;
|
|
216
|
+
const row = weekRow(monthStart);
|
|
217
|
+
if (!container || !row) return;
|
|
218
|
+
container.scrollTop += row.getBoundingClientRect().top - container.getBoundingClientRect().top - 40;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function extendWeeks(direction: -1 | 1) {
|
|
222
|
+
if (extendingWeeks || !scroll.value || !scrollingWeeks.value.length) return;
|
|
223
|
+
extendingWeeks = true;
|
|
224
|
+
const container = scroll.value;
|
|
225
|
+
const anchor = [...container.querySelectorAll<HTMLElement>('.calendar-month-week')]
|
|
226
|
+
.find((row) => row.getBoundingClientRect().bottom > container.getBoundingClientRect().top + 80);
|
|
227
|
+
const anchorKey = anchor?.dataset.week;
|
|
228
|
+
const anchorTop = anchor?.getBoundingClientRect().top;
|
|
229
|
+
const edge = direction < 0 ? scrollingWeeks.value[0]! : scrollingWeeks.value.at(-1)!;
|
|
230
|
+
const additions = Array.from({ length: 8 }, (_, index) => weekOffset(edge, direction * (index + 1)));
|
|
231
|
+
const expanded = direction < 0
|
|
232
|
+
? [...additions.reverse(), ...scrollingWeeks.value]
|
|
233
|
+
: [...scrollingWeeks.value, ...additions];
|
|
234
|
+
scrollingWeeks.value = direction < 0 ? expanded.slice(0, 85) : expanded.slice(-85);
|
|
235
|
+
await nextTick();
|
|
236
|
+
const retained = [...container.querySelectorAll<HTMLElement>('.calendar-month-week')]
|
|
237
|
+
.find((row) => row.dataset.week === anchorKey);
|
|
238
|
+
if (retained && anchorTop !== undefined)
|
|
239
|
+
container.scrollTop += retained.getBoundingClientRect().top - anchorTop;
|
|
240
|
+
extendingWeeks = false;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function onMonthScroll() {
|
|
244
|
+
const container = scroll.value;
|
|
245
|
+
if (getMode() !== 'month' || !container || !scrollingWeeks.value.length || extendingWeeks) return;
|
|
246
|
+
const bounds = container.getBoundingClientRect();
|
|
247
|
+
const viewTop = bounds.top + (container.querySelector<HTMLElement>('.calendar-month-weekdays')?.offsetHeight ?? 0);
|
|
248
|
+
const area = new Map<string, { month: Date; size: number }>();
|
|
249
|
+
for (const row of container.querySelectorAll<HTMLElement>('.calendar-month-week')) {
|
|
250
|
+
const rect = row.getBoundingClientRect();
|
|
251
|
+
const size = Math.min(rect.bottom, bounds.bottom) - Math.max(rect.top, viewTop);
|
|
252
|
+
if (size <= 0) continue;
|
|
253
|
+
const week = scrollingWeeks.value.find((item) => weekKey(item) === row.dataset.week);
|
|
254
|
+
if (!week) continue;
|
|
255
|
+
for (const day of weekDays(week)) {
|
|
256
|
+
const key = monthKey(day);
|
|
257
|
+
const entry = area.get(key) ?? { month: day, size: 0 };
|
|
258
|
+
entry.size += size;
|
|
259
|
+
area.set(key, entry);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const current = getDate();
|
|
263
|
+
let visibleMonth: Date | undefined;
|
|
264
|
+
let best = (area.get(monthKey(current))?.size ?? 0) * 1.15;
|
|
265
|
+
for (const { month, size } of area.values())
|
|
266
|
+
if (size > best) { best = size; visibleMonth = month; }
|
|
267
|
+
if (visibleMonth && monthKey(visibleMonth) !== monthKey(current)) {
|
|
268
|
+
reportedMonthKey = monthKey(visibleMonth);
|
|
269
|
+
options.onVisibleMonth(new Date(visibleMonth.getFullYear(), visibleMonth.getMonth(), 1));
|
|
270
|
+
}
|
|
271
|
+
if (container.scrollTop < container.clientHeight)
|
|
272
|
+
void extendWeeks(-1);
|
|
273
|
+
else if (container.scrollHeight - container.scrollTop - container.clientHeight < container.clientHeight)
|
|
274
|
+
void extendWeeks(1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function fillYears(d: Date) {
|
|
278
|
+
const year = d.getFullYear();
|
|
279
|
+
scrollingYears.value = [year - 1, year, year + 1];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function yearSection(year: number) {
|
|
283
|
+
return [...(scroll.value?.querySelectorAll<HTMLElement>('.calendar-year-section') ?? [])]
|
|
284
|
+
.find((section) => Number(section.dataset.year) === year);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function scrollToYear(d: Date) {
|
|
288
|
+
const year = d.getFullYear();
|
|
289
|
+
positioningYear = true;
|
|
290
|
+
if (!scrollingYears.value.includes(year)) fillYears(d);
|
|
291
|
+
await nextTick();
|
|
292
|
+
const container = scroll.value;
|
|
293
|
+
const section = yearSection(year);
|
|
294
|
+
if (container && section)
|
|
295
|
+
container.scrollTop += section.getBoundingClientRect().top - container.getBoundingClientRect().top - 12;
|
|
296
|
+
positioningYear = false;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function extendYears(direction: -1 | 1) {
|
|
300
|
+
if (extendingYears || !scroll.value || !scrollingYears.value.length) return;
|
|
301
|
+
extendingYears = true;
|
|
302
|
+
const container = scroll.value;
|
|
303
|
+
const anchor = [...container.querySelectorAll<HTMLElement>('.calendar-year-section')]
|
|
304
|
+
.find((section) => section.getBoundingClientRect().bottom > container.getBoundingClientRect().top + 60);
|
|
305
|
+
const anchorYear = Number(anchor?.dataset.year);
|
|
306
|
+
const anchorTop = anchor?.getBoundingClientRect().top;
|
|
307
|
+
const nextYear = direction < 0 ? scrollingYears.value[0]! - 1 : scrollingYears.value.at(-1)! + 1;
|
|
308
|
+
const expanded = direction < 0
|
|
309
|
+
? [nextYear, ...scrollingYears.value]
|
|
310
|
+
: [...scrollingYears.value, nextYear];
|
|
311
|
+
scrollingYears.value = direction < 0 ? expanded.slice(0, 5) : expanded.slice(-5);
|
|
312
|
+
await nextTick();
|
|
313
|
+
const retained = yearSection(anchorYear);
|
|
314
|
+
if (retained && anchorTop !== undefined)
|
|
315
|
+
container.scrollTop += retained.getBoundingClientRect().top - anchorTop;
|
|
316
|
+
extendingYears = false;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function onYearScroll() {
|
|
320
|
+
const container = scroll.value;
|
|
321
|
+
if (getMode() !== 'year' || !container || !scrollingYears.value.length || extendingYears || positioningYear) return;
|
|
322
|
+
const marker = container.getBoundingClientRect().top + 60;
|
|
323
|
+
const section = [...container.querySelectorAll<HTMLElement>('.calendar-year-section')]
|
|
324
|
+
.find((element) => element.getBoundingClientRect().bottom > marker);
|
|
325
|
+
const year = Number(section?.dataset.year);
|
|
326
|
+
const current = getDate();
|
|
327
|
+
if (section && year !== current.getFullYear()) {
|
|
328
|
+
reportedYear = year;
|
|
329
|
+
options.onVisibleYear(shiftCalendarDate(current, 'year', year - current.getFullYear()));
|
|
330
|
+
}
|
|
331
|
+
const edgeDistance = Math.min(400, container.clientHeight / 2);
|
|
332
|
+
if (container.scrollTop < edgeDistance)
|
|
333
|
+
void extendYears(-1);
|
|
334
|
+
else if (container.scrollHeight - container.scrollTop - container.clientHeight < edgeDistance)
|
|
335
|
+
void extendYears(1);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function onCalendarScroll() {
|
|
339
|
+
options.onScrolled();
|
|
340
|
+
if (timeline.value) onTimelineScroll();
|
|
341
|
+
else if (getMode() === 'month') onMonthScroll();
|
|
342
|
+
else if (getMode() === 'year') onYearScroll();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function positionTimeline() {
|
|
346
|
+
await nextTick();
|
|
347
|
+
if (!timeline.value && scroll.value) scroll.value.scrollLeft = 0;
|
|
348
|
+
const current = getDate();
|
|
349
|
+
if (timeline.value) {
|
|
350
|
+
const container = scroll.value;
|
|
351
|
+
if (!container) return;
|
|
352
|
+
timelineDayWidth.value = Math.max(90, (container.clientWidth - 64) / timelineVisibleCount.value);
|
|
353
|
+
fillTimelineDays(current);
|
|
354
|
+
await scrollToTimelineDate(current);
|
|
355
|
+
container.scrollTop = CALENDAR_HOUR_HEIGHT * 7;
|
|
356
|
+
} else if (getMode() === 'month') {
|
|
357
|
+
fillWeeks(current);
|
|
358
|
+
await scrollToWeek(current);
|
|
359
|
+
} else if (getMode() === 'year') {
|
|
360
|
+
fillYears(current);
|
|
361
|
+
await scrollToYear(current);
|
|
362
|
+
} else if (scroll.value) {
|
|
363
|
+
scroll.value.scrollTop = 0;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
onMounted(() => {
|
|
368
|
+
void positionTimeline();
|
|
369
|
+
if (scroll.value && typeof ResizeObserverCtor !== 'undefined') {
|
|
370
|
+
timelineResizeObserver = new ResizeObserverCtor(() => { void resizeTimeline(); });
|
|
371
|
+
timelineResizeObserver.observe(scroll.value);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
onUnmounted(() => {
|
|
376
|
+
timelineResizeObserver?.disconnect();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
watch(getMode, () => {
|
|
380
|
+
options.onBeforeViewChange();
|
|
381
|
+
void positionTimeline();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
watch(getDate, (nextDate) => {
|
|
385
|
+
options.onBeforeViewChange();
|
|
386
|
+
const mode = getMode();
|
|
387
|
+
if (mode === 'month') {
|
|
388
|
+
if (reportedMonthKey === monthKey(nextDate)) {
|
|
389
|
+
reportedMonthKey = '';
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
void scrollToWeek(nextDate);
|
|
393
|
+
} else if (mode === 'year') {
|
|
394
|
+
if (reportedYear === nextDate.getFullYear()) {
|
|
395
|
+
reportedYear = undefined;
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
void scrollToYear(nextDate);
|
|
399
|
+
} else if (timeline.value) {
|
|
400
|
+
const key = localDayKey(visibleCalendarDays(nextDate, mode)[0]!);
|
|
401
|
+
if (reportedTimelineKey === key) {
|
|
402
|
+
reportedTimelineKey = '';
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
void scrollToTimelineDate(nextDate);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
timeline,
|
|
411
|
+
timelineDays,
|
|
412
|
+
timelineDayWidth,
|
|
413
|
+
timelineVisibleCount,
|
|
414
|
+
scrollingWeeks,
|
|
415
|
+
scrollingYears,
|
|
416
|
+
visibleWindow,
|
|
417
|
+
onCalendarScroll,
|
|
418
|
+
onCalendarWheel,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { validEventDate, validEventTime } from '@tano/protocol';
|
|
2
|
+
import type { ObjectRecord } from '../objects/workspace-objects';
|
|
3
|
+
import { isEventCompleted } from './calendar';
|
|
4
|
+
import { planKey } from './personal-plans';
|
|
5
|
+
|
|
6
|
+
export const REMINDER_STORAGE_KEY = 'tano.plan-reminders.fired.v1';
|
|
7
|
+
export const REMINDER_PRESETS = [0, 10, 30, 60, 1440] as const;
|
|
8
|
+
const DEFAULT_GRACE_MS = 5 * 60_000;
|
|
9
|
+
const RETENTION_MS = 30 * 86_400_000;
|
|
10
|
+
|
|
11
|
+
export interface PendingReminder {
|
|
12
|
+
key: string;
|
|
13
|
+
record: ObjectRecord;
|
|
14
|
+
offsetMinutes: number;
|
|
15
|
+
fireAt: number;
|
|
16
|
+
anchorMs: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function extractReminders(properties: Record<string, unknown>): number[] {
|
|
20
|
+
if (!Array.isArray(properties.reminders)) return [];
|
|
21
|
+
return [...new Set(
|
|
22
|
+
properties.reminders.filter(
|
|
23
|
+
(item): item is number => typeof item === 'number' && Number.isInteger(item) && item >= 0 && item <= 43200,
|
|
24
|
+
),
|
|
25
|
+
)].sort((a, b) => a - b);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function reminderAnchorMs(record: ObjectRecord): number | null {
|
|
29
|
+
const p = record.object.properties;
|
|
30
|
+
if (validEventTime(p.start)) {
|
|
31
|
+
if (p.allDay === true) {
|
|
32
|
+
const d = new Date(p.start);
|
|
33
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 9, 0, 0).getTime();
|
|
34
|
+
}
|
|
35
|
+
return Date.parse(p.start);
|
|
36
|
+
}
|
|
37
|
+
if (validEventDate(p.date)) {
|
|
38
|
+
return new Date(`${p.date}T09:00:00`).getTime();
|
|
39
|
+
}
|
|
40
|
+
if (validEventDate(p.due)) {
|
|
41
|
+
return new Date(`${p.due}T09:00:00`).getTime();
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function computePendingReminders(
|
|
47
|
+
records: readonly ObjectRecord[],
|
|
48
|
+
nowMs: number,
|
|
49
|
+
firedKeys: ReadonlySet<string>,
|
|
50
|
+
graceWindowMs = DEFAULT_GRACE_MS,
|
|
51
|
+
): PendingReminder[] {
|
|
52
|
+
const due: PendingReminder[] = [];
|
|
53
|
+
for (const record of records) {
|
|
54
|
+
if (record.object.archived || isEventCompleted(record)) continue;
|
|
55
|
+
const offsets = extractReminders(record.object.properties);
|
|
56
|
+
if (!offsets.length) continue;
|
|
57
|
+
const anchorMs = reminderAnchorMs(record);
|
|
58
|
+
if (anchorMs === null) continue;
|
|
59
|
+
const baseKey = planKey(record);
|
|
60
|
+
for (const offsetMinutes of offsets) {
|
|
61
|
+
const fireAt = anchorMs - offsetMinutes * 60_000;
|
|
62
|
+
if (fireAt > nowMs || nowMs - fireAt > graceWindowMs) continue;
|
|
63
|
+
const key = `${baseKey}:${anchorMs}:${offsetMinutes}`;
|
|
64
|
+
if (firedKeys.has(key)) continue;
|
|
65
|
+
due.push({ key, record, offsetMinutes, fireAt, anchorMs });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return due.sort((a, b) => a.fireAt - b.fireAt);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface LocalReminderOptions {
|
|
72
|
+
storage?: Pick<Storage, 'getItem' | 'setItem'>;
|
|
73
|
+
onRemind?: (item: PendingReminder) => void;
|
|
74
|
+
notify?: (title: string, body: string) => void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* In-app/app-data local reminder tracker. Fired history stays in localStorage
|
|
79
|
+
* (application data) and never writes back to workspace files.
|
|
80
|
+
*/
|
|
81
|
+
export class LocalReminderScheduler {
|
|
82
|
+
private fired = new Map<string, number>();
|
|
83
|
+
private storage?: Pick<Storage, 'getItem' | 'setItem'>;
|
|
84
|
+
private onRemind?: (item: PendingReminder) => void;
|
|
85
|
+
private notify?: (title: string, body: string) => void;
|
|
86
|
+
|
|
87
|
+
constructor(options: LocalReminderOptions = {}) {
|
|
88
|
+
this.storage = options.storage ?? (typeof localStorage !== 'undefined' ? localStorage : undefined);
|
|
89
|
+
this.onRemind = options.onRemind;
|
|
90
|
+
this.notify = options.notify;
|
|
91
|
+
this.load();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private load() {
|
|
95
|
+
if (!this.storage) return;
|
|
96
|
+
try {
|
|
97
|
+
const raw = this.storage.getItem(REMINDER_STORAGE_KEY);
|
|
98
|
+
if (!raw) return;
|
|
99
|
+
const parsed = JSON.parse(raw) as Record<string, number>;
|
|
100
|
+
if (parsed && typeof parsed === 'object') {
|
|
101
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
102
|
+
if (typeof v === 'number' && Number.isFinite(v)) this.fired.set(k, v);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch {
|
|
106
|
+
/* ignore corrupt reminder cache */
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private save(nowMs: number) {
|
|
111
|
+
for (const [key, firedAt] of this.fired) {
|
|
112
|
+
if (nowMs - firedAt > RETENTION_MS) this.fired.delete(key);
|
|
113
|
+
}
|
|
114
|
+
if (!this.storage) return;
|
|
115
|
+
try {
|
|
116
|
+
this.storage.setItem(REMINDER_STORAGE_KEY, JSON.stringify(Object.fromEntries(this.fired)));
|
|
117
|
+
} catch {
|
|
118
|
+
/* storage quota full — keep in-memory dedupe */
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
check(records: readonly ObjectRecord[], nowMs = Date.now()): PendingReminder[] {
|
|
123
|
+
const items = computePendingReminders(records, nowMs, new Set(this.fired.keys()));
|
|
124
|
+
if (!items.length) return [];
|
|
125
|
+
for (const item of items) {
|
|
126
|
+
this.fired.set(item.key, nowMs);
|
|
127
|
+
this.onRemind?.(item);
|
|
128
|
+
const body =
|
|
129
|
+
item.offsetMinutes === 0
|
|
130
|
+
? '现在开始'
|
|
131
|
+
: item.offsetMinutes >= 1440
|
|
132
|
+
? `提前 ${Math.round(item.offsetMinutes / 1440)} 天提醒`
|
|
133
|
+
: item.offsetMinutes >= 60
|
|
134
|
+
? `提前 ${Math.round(item.offsetMinutes / 60)} 小时提醒`
|
|
135
|
+
: `提前 ${item.offsetMinutes} 分钟提醒`;
|
|
136
|
+
if (this.notify) {
|
|
137
|
+
this.notify(item.record.object.name, body);
|
|
138
|
+
} else if (typeof Notification !== 'undefined' && Notification.permission === 'granted') {
|
|
139
|
+
try {
|
|
140
|
+
new Notification(item.record.object.name, { body });
|
|
141
|
+
} catch {
|
|
142
|
+
/* ignore notification delivery failure */
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.save(nowMs);
|
|
147
|
+
return items;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -6,10 +6,19 @@ import type { ObjectRecord, ObjectStorage } from '../objects/workspace-objects';
|
|
|
6
6
|
import { t } from '../i18n/i18n';
|
|
7
7
|
|
|
8
8
|
export const PERSONAL_PLANS_KEY = 'tano.personal-plans.v1';
|
|
9
|
-
export const
|
|
9
|
+
export const sourcePlanKey = (record: ObjectRecord) =>
|
|
10
10
|
record.source?.scope === 'personal'
|
|
11
11
|
? `personal:${record.source.id}:${record.object.id}`
|
|
12
12
|
: record.object.id;
|
|
13
|
+
export const planKey = (record: ObjectRecord) => {
|
|
14
|
+
const base = sourcePlanKey(record);
|
|
15
|
+
const occurrence =
|
|
16
|
+
record.object.properties.repeatVirtual === true &&
|
|
17
|
+
typeof record.object.properties.repeatOccurrence === 'string'
|
|
18
|
+
? record.object.properties.repeatOccurrence
|
|
19
|
+
: '';
|
|
20
|
+
return occurrence ? `${base}@${occurrence}` : base;
|
|
21
|
+
};
|
|
13
22
|
export const planSourceLabel = (record: ObjectRecord) =>
|
|
14
23
|
record.source?.scope === 'personal' ? t('个人') : (record.source?.name ?? t('工作区'));
|
|
15
24
|
|
package/src/plans/plan-date.ts
CHANGED
|
@@ -9,7 +9,13 @@ export interface PlanDateValue {
|
|
|
9
9
|
end: string;
|
|
10
10
|
}
|
|
11
11
|
export function readPlanDate(properties: Record<string, unknown>): PlanDateValue {
|
|
12
|
-
if (validEventDate(properties.date))
|
|
12
|
+
if (validEventDate(properties.date)) {
|
|
13
|
+
return {
|
|
14
|
+
date: properties.date,
|
|
15
|
+
time: '',
|
|
16
|
+
end: validEventDate(properties.endDate) ? properties.endDate : '',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
13
19
|
if (validEventTime(properties.start)) {
|
|
14
20
|
const start = localDateTime(new Date(properties.start));
|
|
15
21
|
if (properties.allDay === true && validEventTime(properties.end)) {
|
|
@@ -29,6 +35,7 @@ export function readPlanDate(properties: Record<string, unknown>): PlanDateValue
|
|
|
29
35
|
export function writePlanDate(properties: Record<string, unknown>, value: PlanDateValue) {
|
|
30
36
|
const result = { ...properties };
|
|
31
37
|
delete result.date;
|
|
38
|
+
delete result.endDate;
|
|
32
39
|
delete result.start;
|
|
33
40
|
delete result.end;
|
|
34
41
|
delete result.allDay;
|