@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
@@ -0,0 +1,95 @@
1
+ import { isActionableTask, isPlanCompleted, parseTaskRepeat } from '@tano/protocol';
2
+ import type { WorkspaceObject } from '@tano/protocol';
3
+ import type { ObjectRecord } from '../objects/workspace-objects';
4
+ import type { PlanScope } from '../stores/plans';
5
+
6
+ const STRIPPED_KEYS = [
7
+ 'syncConnection',
8
+ 'syncRemoteId',
9
+ 'syncReadOnly',
10
+ 'syncConflictCopy',
11
+ 'deliveryReview',
12
+ 'repeatSourceId',
13
+ 'repeatOccurrence',
14
+ 'repeatVirtual',
15
+ ] as const;
16
+
17
+ export interface PlanMigrationResult {
18
+ created: ObjectRecord;
19
+ archivedSource: boolean;
20
+ warning?: string;
21
+ }
22
+
23
+ export function prepareMigratedObject(
24
+ source: WorkspaceObject,
25
+ targetScope: PlanScope,
26
+ ): Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'> {
27
+ const properties: Record<string, unknown> = JSON.parse(JSON.stringify(source.properties));
28
+ for (const key of STRIPPED_KEYS) delete properties[key];
29
+
30
+ // Canonicalize legacy `task` -> `event` with `checkable: true` on migration.
31
+ const checkable = isActionableTask(source);
32
+ const completed = isPlanCompleted(source);
33
+ properties.checkable = checkable;
34
+ properties.completed = completed;
35
+
36
+ // Personal scope only runs calendar schedule recurrence, not workspace after_complete instances.
37
+ if (targetScope === 'personal' && properties.repeat !== undefined) {
38
+ try {
39
+ const rule = parseTaskRepeat(properties.repeat);
40
+ if (rule.mode !== 'schedule') {
41
+ properties.repeat = { ...rule, mode: 'schedule' };
42
+ }
43
+ } catch {
44
+ delete properties.repeat;
45
+ }
46
+ }
47
+
48
+ return {
49
+ type: 'event',
50
+ name: source.name,
51
+ description: source.description,
52
+ archived: false,
53
+ properties,
54
+ };
55
+ }
56
+
57
+ /**
58
+ * Moves a plan item between Personal and Workspace safely:
59
+ * 1. Create the cleaned copy in the destination scope.
60
+ * 2. Archive the original record only after creation succeeds.
61
+ * If archiving fails, the newly created copy is preserved and a warning is returned.
62
+ */
63
+ export async function movePlanBetweenScopes(
64
+ record: ObjectRecord,
65
+ targetScope: PlanScope,
66
+ ports: {
67
+ workspaceId?: string;
68
+ create: (
69
+ value: Pick<WorkspaceObject, 'type' | 'name' | 'description' | 'archived' | 'properties'>,
70
+ scope: PlanScope,
71
+ workspaceId?: string,
72
+ ) => Promise<ObjectRecord>;
73
+ archive: (source: ObjectRecord) => Promise<unknown>;
74
+ },
75
+ ): Promise<PlanMigrationResult> {
76
+ const currentScope: PlanScope = record.source?.scope === 'personal' ? 'personal' : 'workspace';
77
+ if (currentScope === targetScope) {
78
+ throw new Error('事项已在目标空间中');
79
+ }
80
+ if (targetScope === 'workspace' && !ports.workspaceId) {
81
+ throw new Error('请先打开目标工作区');
82
+ }
83
+ const payload = prepareMigratedObject(record.object, targetScope);
84
+ const created = await ports.create(payload, targetScope, ports.workspaceId);
85
+ try {
86
+ await ports.archive(record);
87
+ return { created, archivedSource: true };
88
+ } catch (reason) {
89
+ return {
90
+ created,
91
+ archivedSource: false,
92
+ warning: `已复制到目标空间,但原记录归档失败:${String(reason)}`,
93
+ };
94
+ }
95
+ }
@@ -0,0 +1,95 @@
1
+ import ICAL from 'ical.js';
2
+ import { parseTaskRepeat, validEventDate, validEventTime } from '@tano/protocol';
3
+ import type { ObjectRecord } from '../objects/workspace-objects';
4
+ import { localDayKey } from './calendar';
5
+ import { moveRecordToDay } from './calendar-interaction';
6
+
7
+ const MAX_OCCURRENCES_PER_SERIES = 400;
8
+
9
+ function baseDayKey(record: ObjectRecord): string | null {
10
+ const p = record.object.properties;
11
+ if (validEventDate(p.date)) return p.date;
12
+ if (validEventTime(p.start)) return localDayKey(new Date(p.start));
13
+ if (validEventDate(p.due)) return p.due;
14
+ return null;
15
+ }
16
+
17
+ export function isVirtualOccurrence(record: ObjectRecord): boolean {
18
+ return record.object.properties.repeatVirtual === true;
19
+ }
20
+
21
+ /**
22
+ * Expands `repeat.mode === 'schedule'` series within `[windowStart, windowEnd]`
23
+ * into lightweight virtual occurrence records without duplicating files on disk.
24
+ */
25
+ export function expandRecurringPlans(
26
+ records: readonly ObjectRecord[],
27
+ windowStart: Date,
28
+ windowEnd: Date,
29
+ ): ObjectRecord[] {
30
+ const startKey = localDayKey(windowStart);
31
+ const endKey = localDayKey(windowEnd);
32
+ if (endKey < startKey) return [...records];
33
+
34
+ const materializedOverrides = new Set<string>();
35
+ for (const record of records) {
36
+ const src = record.object.properties.repeatSourceId;
37
+ const occ = record.object.properties.repeatOccurrence;
38
+ if (typeof src === 'string' && validEventDate(occ)) {
39
+ materializedOverrides.add(`${record.source?.scope ?? 'workspace'}:${record.source?.id ?? ''}:${src}:${occ}`);
40
+ }
41
+ }
42
+
43
+ const expanded: ObjectRecord[] = [...records];
44
+
45
+ for (const record of records) {
46
+ if (record.object.archived) continue;
47
+ if (record.object.properties.repeat === undefined) continue;
48
+ if (record.object.properties.repeatSourceId !== undefined) continue;
49
+ let rule;
50
+ try {
51
+ rule = parseTaskRepeat(record.object.properties.repeat);
52
+ } catch {
53
+ continue;
54
+ }
55
+ if (rule.mode !== 'schedule') continue;
56
+
57
+ const originKey = baseDayKey(record);
58
+ const exdates = new Set(rule.exdates ?? []);
59
+ const frequency = { daily: 'DAILY', weekly: 'WEEKLY', monthly: 'MONTHLY' }[rule.frequency];
60
+ const recur = ICAL.Recur.fromString(`FREQ=${frequency};INTERVAL=${rule.interval}`);
61
+ const iterator = recur.iterator(ICAL.Time.fromDateString(rule.anchor));
62
+ const scopePrefix = `${record.source?.scope ?? 'workspace'}:${record.source?.id ?? ''}:${record.object.id}:`;
63
+
64
+ let produced = 0;
65
+ for (let step = 0; step < 20_000 && produced < MAX_OCCURRENCES_PER_SERIES; step++) {
66
+ const next = iterator.next();
67
+ if (!next) break;
68
+ const dateKey = next.toString();
69
+ if (rule.until && dateKey > rule.until) break;
70
+ if (dateKey > endKey) break;
71
+ if (dateKey < startKey) continue;
72
+ if (dateKey === originKey) continue;
73
+ if (exdates.has(dateKey)) continue;
74
+ if (materializedOverrides.has(`${scopePrefix}${dateKey}`)) continue;
75
+
76
+ const targetDate = new Date(`${dateKey}T00:00:00`);
77
+ const moved = moveRecordToDay(record.object, targetDate);
78
+ expanded.push({
79
+ ...record,
80
+ object: {
81
+ ...moved,
82
+ properties: {
83
+ ...moved.properties,
84
+ repeatSourceId: record.object.id,
85
+ repeatOccurrence: dateKey,
86
+ repeatVirtual: true,
87
+ },
88
+ },
89
+ });
90
+ produced++;
91
+ }
92
+ }
93
+
94
+ return expanded;
95
+ }
@@ -1,5 +1,5 @@
1
1
  import ICAL from 'ical.js';
2
- import { parseTaskRepeat, referenceKey, validateObjectProperties, validEventDate } from '@tano/protocol';
2
+ import { isPlanCompleted, parseTaskRepeat, referenceKey, validateObjectProperties, validEventDate, withPlanCompleted } from '@tano/protocol';
3
3
  import type { WorkspaceObject, WorkspaceRelation } from '@tano/protocol';
4
4
  import type { ObjectRecord } from '../objects/workspace-objects';
5
5
  import { assistantHash } from '../assistant/hash';
@@ -27,20 +27,20 @@ export async function previewTaskRepeat(record: ObjectRecord, relations: Workspa
27
27
  if (series.object.archived || series.object.properties.repeat === undefined) throw new Error('来源任务已停止重复或归档');
28
28
  const base: WorkspaceObject = { ...record.object, properties: { ...record.object.properties, repeat: series.object.properties.repeat } };
29
29
  validateObjectProperties(base.type, base.properties);
30
- if (base.archived || base.properties.syncReadOnly === true || base.properties.completed !== true) throw new Error('请先完成当前任务,再创建下一次');
30
+ if (base.archived || base.properties.syncReadOnly === true || !isPlanCompleted(base)) throw new Error('请先完成当前任务,再创建下一次');
31
31
  const date = nextRepeatDate(base);
32
32
  if (!date) return null;
33
33
  const sourceId = String(base.properties.repeatSourceId ?? base.id);
34
34
  const id = (await assistantHash(`tano-repeat:${sourceId}:${date}`)).slice(0, 6);
35
- const properties = { ...base.properties, completed: false, repeatSourceId: sourceId, repeatOccurrence: date };
36
- for (const key of ['syncConnection', 'syncRemoteId', 'syncReadOnly', 'syncConflictCopy', 'deliveryReview', 'start', 'end']) delete (properties as Record<string, unknown>)[key];
37
- if (base.properties.date) (properties as Record<string, unknown>).date = date;
38
- else (properties as Record<string, unknown>).due = date;
35
+ const reset = withPlanCompleted({ ...base, properties: { ...base.properties, deliveryReview: undefined } }, false);
36
+ const properties: Record<string, unknown> = { ...reset.properties, repeatSourceId: sourceId, repeatOccurrence: date };
37
+ for (const key of ['syncConnection', 'syncRemoteId', 'syncReadOnly', 'syncConflictCopy', 'deliveryReview', 'start', 'end']) delete properties[key];
38
+ if (base.properties.date) properties.date = date;
39
+ else properties.due = date;
39
40
  if (base.properties.date && base.properties.due) {
40
41
  const offset = Date.parse(`${base.properties.due}T00:00:00Z`) - Date.parse(`${base.properties.date}T00:00:00Z`);
41
- (properties as Record<string, unknown>).due = new Date(Date.parse(`${date}T00:00:00Z`) + offset).toISOString().slice(0, 10);
42
+ properties.due = new Date(Date.parse(`${date}T00:00:00Z`) + offset).toISOString().slice(0, 10);
42
43
  }
43
- if (base.type === 'task') (properties as Record<string, unknown>).status = 'todo';
44
44
  const object = { ...base, id, properties };
45
45
  validateObjectProperties(object.type, object.properties);
46
46
  const linked = repeatRelations(base, relations);
@@ -0,0 +1,92 @@
1
+ import type { ObjectRecord } from '../objects/workspace-objects';
2
+ import { eventsOnDay } from './calendar';
3
+
4
+ export interface TimedEventBlock {
5
+ record: ObjectRecord;
6
+ top: number;
7
+ height: number;
8
+ point: boolean;
9
+ column: number;
10
+ columnCount: number;
11
+ visibleStart: number;
12
+ visibleEnd: number;
13
+ }
14
+
15
+ const MIN_COLLISION_MS = 30 * 60_000;
16
+
17
+ /**
18
+ * Assigns non-overlapping horizontal columns to concurrent timed events on one day.
19
+ * Events are grouped into connected overlap clusters so non-overlapping slots keep full width.
20
+ */
21
+ export function layoutDayTimedEvents(
22
+ records: readonly ObjectRecord[],
23
+ day: Date,
24
+ hourHeight: number,
25
+ ): TimedEventBlock[] {
26
+ const dayStart = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime();
27
+ const dayEnd = new Date(day.getFullYear(), day.getMonth(), day.getDate() + 1).getTime();
28
+
29
+ const items = eventsOnDay(records, day)
30
+ .filter((record) => record.object.properties.allDay !== true)
31
+ .map((record) => {
32
+ const from = Date.parse(String(record.object.properties.start));
33
+ const to = Date.parse(String(record.object.properties.end));
34
+ const point = from === to;
35
+ const visibleStart = Math.max(from, dayStart);
36
+ const visibleEnd = Math.min(Math.max(to, from + MIN_COLLISION_MS), dayEnd);
37
+ const layoutEnd = Math.max(visibleEnd, visibleStart + MIN_COLLISION_MS);
38
+ const top = ((visibleStart - dayStart) / 3_600_000) * hourHeight;
39
+ const height = point
40
+ ? 24
41
+ : Math.max(22, ((visibleEnd - visibleStart) / 3_600_000) * hourHeight);
42
+ return { record, top, height, point, visibleStart, visibleEnd, layoutEnd };
43
+ })
44
+ .sort(
45
+ (a, b) =>
46
+ a.visibleStart - b.visibleStart ||
47
+ b.layoutEnd - a.layoutEnd ||
48
+ a.record.object.id.localeCompare(b.record.object.id),
49
+ );
50
+
51
+ const result: TimedEventBlock[] = [];
52
+ let cluster: { item: (typeof items)[number]; column: number }[] = [];
53
+ let columnEnds: number[] = [];
54
+ let clusterEnd = -Infinity;
55
+
56
+ const flushCluster = () => {
57
+ if (!cluster.length) return;
58
+ const columnCount = columnEnds.length;
59
+ for (const entry of cluster) {
60
+ result.push({
61
+ record: entry.item.record,
62
+ top: entry.item.top,
63
+ height: entry.item.height,
64
+ point: entry.item.point,
65
+ column: entry.column,
66
+ columnCount,
67
+ visibleStart: entry.item.visibleStart,
68
+ visibleEnd: entry.item.visibleEnd,
69
+ });
70
+ }
71
+ cluster = [];
72
+ columnEnds = [];
73
+ clusterEnd = -Infinity;
74
+ };
75
+
76
+ for (const item of items) {
77
+ if (cluster.length > 0 && item.visibleStart >= clusterEnd) {
78
+ flushCluster();
79
+ }
80
+ let column = columnEnds.findIndex((end) => end <= item.visibleStart);
81
+ if (column < 0) {
82
+ column = columnEnds.length;
83
+ columnEnds.push(item.layoutEnd);
84
+ } else {
85
+ columnEnds[column] = item.layoutEnd;
86
+ }
87
+ clusterEnd = Math.max(clusterEnd, item.layoutEnd);
88
+ cluster.push({ item, column });
89
+ }
90
+ flushCluster();
91
+ return result;
92
+ }