@vetta-org/theme-ui 0.1.1 → 0.1.2
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 +733 -5
- package/src/action-approval/AppearanceActionPickerView.tsx +2 -78
- package/src/action-approval/AppearanceApprovalDrawerView.tsx +2 -9
- package/src/action-approval/BatchTasksApprovalFrameView.tsx +4 -1
- package/src/action-approval/GenericActionApprovalView.tsx +2 -9
- package/src/action-approval/ManageActionApprovalFrameView.tsx +4 -1
- package/src/action-approval/NavigationOpenApprovalView.tsx +2 -9
- package/src/action-approval/SchedulerActionApprovalDialogView.tsx +3 -1
- package/src/action-approval/SchedulerEditApprovalDrawerView.tsx +3 -10
- package/src/action-approval/index.ts +0 -1
- package/src/activity/ActivityPanel.tsx +13 -10
- package/src/activity/ActivityPanelFrame.test.tsx +32 -0
- package/src/activity/ActivityPanelFrame.tsx +3 -2
- package/src/activity/BackgroundTasksTabPanelView.tsx +1 -1
- package/src/activity/BrowserPanelView.tsx +48 -49
- package/src/activity/DebugTabPanelView.tsx +1 -1
- package/src/activity/MarkdownPreviewView.tsx +56 -59
- package/src/activity/PluginTabPickerView.tsx +5 -3
- package/src/activity/PortsTabPanelView.tsx +911 -0
- package/src/activity/ToolCallsSubTabView.tsx +1 -1
- package/src/activity/WorkflowTabPanelView.tsx +1 -1
- package/src/activity/index.ts +9 -0
- package/src/app/AppBackground.tsx +1 -1
- package/src/app/AppBootLoadingView.tsx +4 -2
- package/src/app-shell/DefaultWindowControls.tsx +1 -1
- package/src/app-shell/PageHeaderActionGroup.tsx +1 -1
- package/src/app-shell/PageHeaderContent.tsx +36 -7
- package/src/app-shell/PageHeaderFrame.tsx +15 -3
- package/src/app-shell/PageHeaderSidebarTrigger.tsx +1 -1
- package/src/app-shell/PageHeaderTitle.tsx +1 -1
- package/src/app-shell/WindowControlButton.tsx +1 -1
- package/src/app-shell/header-crowding.test.ts +62 -0
- package/src/app-shell/header-crowding.tsx +137 -0
- package/src/appearance/BackgroundImageFrame.tsx +1 -1
- package/src/appearance/CenterSliceImageFrame.tsx +1 -1
- package/src/appearance/CornerImageFrame.tsx +1 -1
- package/src/appearance/HorizontalSliceImageFrame.tsx +1 -1
- package/src/appearance/NineSliceImageFrame.tsx +1 -1
- package/src/appearance/ThemeSurface.tsx +1 -1
- package/src/batch-tasks/BatchProjectFoldersFieldView.tsx +2 -1
- package/src/batch-tasks/BatchTaskProjectActionsView.test.tsx +97 -0
- package/src/batch-tasks/BatchTaskProjectActionsView.tsx +45 -35
- package/src/batch-tasks/batchTaskUi.tsx +0 -29
- package/src/bottom-panel/BottomPanelView.test.tsx +43 -0
- package/src/bottom-panel/BottomPanelView.tsx +222 -0
- package/src/bottom-panel/index.ts +26 -0
- package/src/chat/AgentAvatarView.tsx +1 -1
- package/src/chat/AnnotationViews.tsx +107 -0
- package/src/chat/AskUserQuestionView.tsx +18 -11
- package/src/chat/AssistantMessageView.tsx +48 -13
- package/src/chat/AtPanelView.test.tsx +61 -0
- package/src/chat/AtPanelView.tsx +63 -38
- package/src/chat/BashTerminalCard.tsx +1 -2
- package/src/chat/ChatHeaderActionsView.tsx +74 -18
- package/src/chat/CompactionStepView.test.tsx +34 -0
- package/src/chat/CompactionStepView.tsx +85 -0
- package/src/chat/ExecutionModeSelectorView.tsx +20 -5
- package/src/chat/HeaderActionBarView.tsx +731 -0
- package/src/chat/HeaderActionOverflowMenu.tsx +137 -0
- package/src/chat/InlineModelPicker.test.tsx +81 -0
- package/src/chat/InlineModelPicker.tsx +201 -0
- package/src/chat/InlineTokenChip.tsx +2 -68
- package/src/chat/InputBarBackground.tsx +1 -1
- package/src/chat/InputBarPlaceholder.tsx +26 -3
- package/src/chat/LiveThinkingView.tsx +51 -37
- package/src/chat/MessageBoundaryViews.tsx +21 -0
- package/src/chat/MessageFeedContext.tsx +13 -5
- package/src/chat/MessageFeedLayoutView.tsx +28 -3
- package/src/chat/MessageFeedView.test.tsx +81 -0
- package/src/chat/MessageFeedView.tsx +72 -152
- package/src/chat/MessageInputView.tsx +1 -1
- package/src/chat/MessageLayoutView.tsx +1 -1
- package/src/chat/MessageSelectionContextMenuView.tsx +4 -1
- package/src/chat/MessageTimelineView.tsx +1 -1
- package/src/chat/MessageView.tsx +1 -1
- package/src/chat/MessageVisualView.tsx +1 -1
- package/src/chat/ModelConfiguration.tsx +283 -0
- package/src/chat/ModelSelectorTrigger.tsx +63 -0
- package/src/chat/ModelSelectorView.tsx +1037 -223
- package/src/chat/NewSession.ts +1 -37
- package/src/chat/NewSessionPicker.tsx +3 -2
- package/src/chat/ProjectSelectorView.tsx +3 -2
- package/src/chat/ReasoningStepSlider.tsx +61 -0
- package/src/chat/RemoteSessionBadgeView.tsx +24 -0
- package/src/chat/SkillPromptAreaView.tsx +5 -19
- package/src/chat/TeamMemberReplyCardView.test.tsx +33 -0
- package/src/chat/TeamMemberReplyCardView.tsx +133 -0
- package/src/chat/TextBlockView.tsx +7 -770
- package/src/chat/TodoProgress.tsx +25 -53
- package/src/chat/TodoStatusBarView.tsx +14 -5
- package/src/chat/UserMessageView.tsx +113 -33
- package/src/chat/header-action-narrow.test.ts +21 -0
- package/src/chat/header-action-narrow.ts +38 -0
- package/src/chat/index.ts +32 -27
- package/src/chat/markdown-link.ts +7 -279
- package/src/chat/send-button.css +4 -22
- package/src/chat/streaming-reveal.test.ts +218 -0
- package/src/chat/streaming-reveal.ts +13 -0
- package/src/file-explorer/ConfirmDeleteDialogView.tsx +2 -1
- package/src/file-explorer/FileContextMenuView.tsx +44 -11
- package/src/file-explorer/FileExplorerSettingsView.tsx +97 -0
- package/src/file-explorer/FileTreeCreateRow.tsx +1 -1
- package/src/file-explorer/FileTreeNodeView.tsx +59 -18
- package/src/file-explorer/FileTreeView.tsx +236 -129
- package/src/file-explorer/file-tree-dom.ts +23 -0
- package/src/file-explorer/file-tree-rows.test.ts +74 -0
- package/src/file-explorer/file-tree-rows.ts +168 -0
- package/src/file-explorer/index.ts +17 -0
- package/src/file-explorer/types.ts +3 -0
- package/src/file-explorer/useFileTreeMarqueeSelection.ts +24 -16
- package/src/file-preview/FilePreviewDialogView.tsx +2 -2
- package/src/file-preview/FilePreviewView.tsx +12 -2
- package/src/file-preview/TextFileEditorView.tsx +2 -1
- package/src/index.ts +1 -0
- package/src/knowledge/KnowledgeHowItWorksDialogView.tsx +1 -1
- package/src/layout/AppFrame.tsx +3 -2
- package/src/layout/MainContentFrame.tsx +7 -2
- package/src/layout/ResizeHandle.tsx +68 -17
- package/src/layout/SidebarDock.tsx +75 -19
- package/src/layout/SidebarOverlay.tsx +1 -1
- package/src/layout/index.ts +1 -1
- package/src/layout/resize-handle-axis.test.ts +51 -0
- package/src/live-indicators.test.ts +43 -0
- package/src/markdown/CodeBlock.tsx +123 -0
- package/src/markdown/InlineTokenChip.tsx +68 -0
- package/src/markdown/MarkdownContent.tsx +411 -0
- package/src/markdown/MarkdownImage.tsx +51 -0
- package/src/markdown/MathFormula.tsx +46 -0
- package/src/markdown/MermaidBlock.tsx +43 -0
- package/src/markdown/RichCodeBlock.tsx +127 -0
- package/src/markdown/SvgPreview.tsx +45 -0
- package/src/markdown/WebsiteIcon.tsx +94 -0
- package/src/markdown/builtin-renderers.tsx +43 -0
- package/src/markdown/definition.tsx +49 -0
- package/src/markdown/host.tsx +18 -0
- package/src/markdown/index.ts +11 -0
- package/src/markdown/inline-tokens.ts +187 -0
- package/src/markdown/markdown-link.ts +279 -0
- package/src/markdown/math-client.ts +116 -0
- package/src/markdown/math-render.ts +23 -0
- package/src/markdown/math-syntax.ts +80 -0
- package/src/markdown/math.worker.ts +16 -0
- package/src/markdown/nodes.ts +15 -0
- package/src/markdown/preview-policy.ts +43 -0
- package/src/markdown/rich-labels.ts +49 -0
- package/src/markdown/rich-syntax.ts +93 -0
- package/src/markdown/stable-blocks.test.ts +90 -0
- package/src/markdown/stable-blocks.ts +124 -0
- package/src/markdown/streaming-reveal.ts +297 -0
- package/src/markdown/streaming.test.ts +57 -0
- package/src/markdown/streaming.ts +211 -0
- package/src/markdown/use-render-snapshot.ts +24 -0
- package/src/markdown/use-rich-visibility.ts +24 -0
- package/src/overlays/CommandMenuRow.tsx +38 -9
- package/src/overlays/CommandMenuView.tsx +77 -117
- package/src/overlays/ConfirmDialogView.tsx +25 -20
- package/src/overlays/ReleaseNoteMarkdown.tsx +29 -0
- package/src/overlays/SplashOptionRow.tsx +46 -0
- package/src/overlays/SplashPanel.tsx +85 -0
- package/src/overlays/SplashParts.tsx +213 -0
- package/src/overlays/UpdateCheckerView.tsx +34 -18
- package/src/overlays/UpdateRestartDialogView.tsx +139 -54
- package/src/overlays/command-menu-types.ts +2 -0
- package/src/overlays/command-menu.css +1 -20
- package/src/overlays/index.ts +14 -1
- package/src/plugin-ui/index.ts +8 -0
- package/src/project/ConversationTagDotsView.tsx +1 -1
- package/src/project/ConversationTagEditorDialogView.tsx +4 -1
- package/src/project/DefaultConversationSectionView.tsx +4 -4
- package/src/project/DefaultSessionListView.tsx +5 -31
- package/src/project/DefaultSessionRowView.tsx +106 -55
- package/src/project/ManageSessionsSplashView.tsx +439 -0
- package/src/project/NewProjectDialogView.tsx +3 -10
- package/src/project/ProjectContextMenuView.tsx +30 -139
- package/src/project/ProjectDetailPageView.test.tsx +140 -0
- package/src/project/ProjectDetailPageView.tsx +372 -165
- package/src/project/ProjectGroupView.tsx +1 -1
- package/src/project/ProjectRowView.tsx +29 -12
- package/src/project/ProjectSessionsView.tsx +25 -47
- package/src/project/QuickScrollOverlay.tsx +1 -1
- package/src/project/SessionContextMenuView.tsx +15 -7
- package/src/project/SessionRowMoreButton.tsx +50 -0
- package/src/project/SessionRowView.tsx +106 -63
- package/src/project/SessionTitleMarquee.tsx +54 -0
- package/src/project/SidebarProjectDisclosure.tsx +60 -0
- package/src/project/SidebarProjectsSectionView.tsx +6 -1
- package/src/project/index.ts +12 -0
- package/src/project/session-row-transition.ts +9 -0
- package/src/project/types.ts +4 -2
- package/src/project/useActiveSessionAutoScroll.ts +10 -4
- package/src/registry.ts +0 -2
- package/src/scheduler/AutomationDetailPaneView.tsx +68 -0
- package/src/scheduler/AutomationPageView.tsx +118 -121
- package/src/scheduler/ExecutionHistoryView.tsx +7 -5
- package/src/scheduler/TaskListView.tsx +52 -201
- package/src/scheduler/index.ts +7 -12
- package/src/settings/AchievementSettingsView.tsx +0 -1
- package/src/settings/AppshotSettingsView.tsx +0 -1
- package/src/settings/BuiltinMcpSectionView.tsx +1 -1
- package/src/settings/EnvironmentGitRowView.tsx +156 -0
- package/src/settings/EnvironmentSettingsView.tsx +25 -3
- package/src/settings/GeneralSettingsView.tsx +17 -20
- package/src/settings/ImChannelGuideDialogView.tsx +2 -2
- package/src/settings/ImFeishuDialogView.tsx +1 -1
- package/src/settings/ImLegacyImportBannerView.tsx +1 -1
- package/src/settings/ImLogDrawerView.tsx +2 -1
- package/src/settings/JsonConfigInputView.tsx +171 -0
- package/src/settings/ModelsFetchedModelsDrawerView.tsx +292 -0
- package/src/settings/ModelsProvidersSectionView.tsx +26 -23
- package/src/settings/MotionSelect.tsx +9 -7
- package/src/settings/NotificationSettingsView.tsx +79 -0
- package/src/settings/PermissionsSettingsView.tsx +3 -7
- package/src/settings/PresetProviderModelsListView.tsx +141 -24
- package/src/settings/PresetProviderRowView.tsx +205 -182
- package/src/settings/ProxySettingsSectionView.tsx +182 -0
- package/src/settings/QrBindDialogView.tsx +1 -1
- package/src/settings/QuickPanelSettingsSectionView.tsx +0 -2
- package/src/settings/RemoteMcpSectionView.tsx +1 -1
- package/src/settings/SettingChrome.tsx +2 -2
- package/src/settings/SettingsAiAssistButtonView.tsx +9 -119
- package/src/settings/SettingsFormFields.tsx +4 -7
- package/src/settings/SettingsSidebarView.tsx +64 -3
- package/src/settings/ShortcutRecorderView.test.tsx +108 -0
- package/src/settings/ShortcutRecorderView.tsx +15 -9
- package/src/settings/ShortcutsSettingsView.tsx +1 -1
- package/src/settings/SpaceEditorDialogView.tsx +120 -0
- package/src/settings/SpacesSettingsView.tsx +105 -0
- package/src/settings/WebhookEndpointListView.tsx +4 -5
- package/src/settings/index.ts +41 -29
- package/src/shared/ActivityStatusDot.tsx +69 -0
- package/src/shared/AvatarStackView.tsx +13 -13
- package/src/shared/BotAvatar.tsx +11 -9
- package/src/shared/CodeBlockCopyButton.tsx +1 -1
- package/src/shared/ContextMenuView.tsx +4 -11
- package/src/shared/MarkdownTable.tsx +2 -2
- package/src/shared/SyntaxHighlightedCode.tsx +0 -0
- package/src/shared/TabBar.outline.test.tsx +59 -0
- package/src/shared/TabBar.tsx +22 -17
- package/src/shared/VettaKbd.test.tsx +52 -0
- package/src/shared/VettaKbd.tsx +81 -0
- package/src/shared/connected-tab-outline.test.ts +2 -2
- package/src/shared/connected-tab-outline.ts +2 -1
- package/src/shared/index.ts +6 -0
- package/src/shared/kbd-keys.test.ts +61 -0
- package/src/shared/kbd-keys.ts +253 -0
- package/src/shared/provider-icon/icons.ts +4 -2
- package/src/shared/provider-icon/index.tsx +1 -1
- package/src/shared/provider-icon/magpie.svg +1 -0
- package/src/sidebar/AddProjectMenuTriggerView.tsx +25 -15
- package/src/sidebar/DefaultSidebar.tsx +3 -1
- package/src/sidebar/MessageCenterDialogView.tsx +3 -2
- package/src/sidebar/MessageCenterEmptyState.tsx +1 -1
- package/src/sidebar/MessageCenterTabs.tsx +1 -1
- package/src/sidebar/MessageCenterToolbarButton.tsx +1 -1
- package/src/sidebar/MessageCenterTriggerView.tsx +2 -2
- package/src/sidebar/ProjectsPanelEmptyState.tsx +26 -7
- package/src/sidebar/SessionStatusIcon.tsx +16 -1
- package/src/sidebar/SettingsMenuThemeSection.tsx +1 -1
- package/src/sidebar/SettingsMenuTriggerView.test.tsx +42 -0
- package/src/sidebar/SettingsMenuTriggerView.tsx +28 -50
- package/src/sidebar/ShowMoreSessionsButton.tsx +1 -1
- package/src/sidebar/SidebarFilterSelectView.tsx +8 -16
- package/src/sidebar/SidebarNavBadgeView.tsx +1 -1
- package/src/sidebar/SidebarNavIcon.tsx +1 -1
- package/src/sidebar/SidebarNavItemButton.tsx +1 -1
- package/src/sidebar/SidebarNavMorePanel.tsx +19 -7
- package/src/sidebar/SidebarNavigation.tsx +24 -15
- package/src/sidebar/SidebarPanel.tsx +11 -2
- package/src/sidebar/SidebarSectionTriggerLabel.tsx +20 -0
- package/src/sidebar/SidebarTopBar.tsx +10 -7
- package/src/sidebar/WaitingPulseBadge.tsx +19 -0
- package/src/sidebar/index.ts +1 -16
- package/src/skills/index.ts +0 -19
- package/src/skills/skill-icon.tsx +4 -8
- package/src/styles.css +24 -6
- package/src/chat/DefaultSceneCarousel.tsx +0 -113
- package/src/chat/SceneCard.tsx +0 -138
- package/src/scheduler/HistoryDrawerView.tsx +0 -149
- package/src/scheduler/TaskFormDialogView.tsx +0 -60
- package/src/settings/SubscriptionActionsView.tsx +0 -63
- package/src/settings/SubscriptionCardsView.tsx +0 -212
- package/src/settings/TeamDetailView.tsx +0 -148
- package/src/settings/TeamDialogsView.tsx +0 -151
- package/src/settings/TeamListView.tsx +0 -57
- package/src/settings/TeamSettingsView.tsx +0 -51
- package/src/settings/TokenActivityChartView.tsx +0 -286
- package/src/settings/UsageStatsView.tsx +0 -101
- package/src/settings/shouldCloseEmptyApiKeyEditor.test.ts +0 -135
- package/src/settings/shouldCloseEmptyApiKeyEditor.ts +0 -40
- package/src/settings/token-activity.test.ts +0 -195
- package/src/settings/token-activity.ts +0 -320
- package/src/sidebar/AddProjectMenuItem.tsx +0 -21
- package/src/sidebar/AddProjectMenuPopoverView.tsx +0 -52
- package/src/sidebar/NotificationMessageListView.tsx +0 -136
- package/src/sidebar/SettingsMenuAccountSection.tsx +0 -32
- package/src/sidebar/SettingsMenuQuotaSection.tsx +0 -45
- package/src/skills/SceneCardView.tsx +0 -194
- package/src/skills/SkillCardView.tsx +0 -186
- package/src/skills/SkillDetailDialogView.tsx +0 -138
- package/src/skills/SkillTagGroupView.tsx +0 -56
- package/src/skills/SkillToggleSwitch.tsx +0 -31
|
@@ -1,279 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Also: `react-markdown`'s `defaultUrlTransform` treats `C:` as an unknown
|
|
10
|
-
* protocol and blanks the href — Windows paths must be allowlisted via
|
|
11
|
-
* {@link chatUrlTransform}. Models also occasionally omit CommonMark's angle
|
|
12
|
-
* brackets around local destinations that contain whitespace. The normalizer
|
|
13
|
-
* repairs those legacy forms before parse and standardizes local destinations.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { defaultUrlTransform } from "react-markdown";
|
|
17
|
-
|
|
18
|
-
export type MarkdownLinkKind =
|
|
19
|
-
| { type: "file"; path: string }
|
|
20
|
-
| { type: "url"; url: string }
|
|
21
|
-
| { type: "other"; href: string };
|
|
22
|
-
|
|
23
|
-
function safeDecode(raw: string): string {
|
|
24
|
-
try {
|
|
25
|
-
return decodeURIComponent(raw);
|
|
26
|
-
} catch {
|
|
27
|
-
return raw;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function toPosixSeparators(path: string): string {
|
|
32
|
-
return path.replace(/\\/g, "/");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Allow local filesystem hrefs that `defaultUrlTransform` would strip because
|
|
37
|
-
* it sees `C:` / `file:` as unsafe protocols. Everything else keeps the
|
|
38
|
-
* library default (blocks `javascript:` etc.).
|
|
39
|
-
*/
|
|
40
|
-
export function chatUrlTransform(url: string): string {
|
|
41
|
-
// Windows drive: C:\… C:/… or rehype-encoded C:%5C…
|
|
42
|
-
if (/^[A-Za-z]:[\\/]/.test(url) || /^[A-Za-z]:%5[Cc]/i.test(url)) {
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
// file:// local URLs
|
|
46
|
-
if (/^file:/i.test(url)) {
|
|
47
|
-
return url;
|
|
48
|
-
}
|
|
49
|
-
return defaultUrlTransform(url);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface MarkdownFence {
|
|
53
|
-
character: "`" | "~";
|
|
54
|
-
length: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const STANDARD_LINK_TITLE = /^(\S+)(\s+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\([^()]*\)))$/;
|
|
58
|
-
|
|
59
|
-
function splitStandardLinkTitle(destination: string): { path: string; title: string } {
|
|
60
|
-
const match = STANDARD_LINK_TITLE.exec(destination);
|
|
61
|
-
return match ? { path: match[1], title: match[2] } : { path: destination, title: "" };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function normalizeAbsoluteLocalDestination(path: string): string | null {
|
|
65
|
-
if (!path || /[<>\r\n]/.test(path)) return null;
|
|
66
|
-
if (/^\\\\[^\\]/.test(path)) {
|
|
67
|
-
return `file://${path.slice(2).replace(/\\/g, "/")}`;
|
|
68
|
-
}
|
|
69
|
-
if (/^file:/i.test(path)) return path.replace(/\\/g, "/");
|
|
70
|
-
if (/^\/?[A-Za-z]:[\\/]/.test(path)) return path.replace(/\\/g, "/");
|
|
71
|
-
if (path.startsWith("/") && !path.startsWith("//")) return path;
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function normalizeBareDestination(destination: string): string | null {
|
|
76
|
-
const { path, title } = splitStandardLinkTitle(destination);
|
|
77
|
-
const normalized = normalizeAbsoluteLocalDestination(path);
|
|
78
|
-
return normalized ? `<${normalized}>${title}` : null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function findBareDestinationEnd(line: string, start: number): number {
|
|
82
|
-
let parenthesesDepth = 0;
|
|
83
|
-
for (let index = start; index < line.length; index++) {
|
|
84
|
-
if (line[index] === "(") {
|
|
85
|
-
parenthesesDepth++;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (line[index] !== ")") continue;
|
|
89
|
-
if (parenthesesDepth === 0) return index;
|
|
90
|
-
parenthesesDepth--;
|
|
91
|
-
}
|
|
92
|
-
return -1;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function normalizeMarkdownLine(line: string): string {
|
|
96
|
-
if (/^(?: {4}|\t)/.test(line)) return line;
|
|
97
|
-
|
|
98
|
-
let result = "";
|
|
99
|
-
let cursor = 0;
|
|
100
|
-
let codeDelimiterLength = 0;
|
|
101
|
-
for (let index = 0; index < line.length; ) {
|
|
102
|
-
if (line[index] === "`") {
|
|
103
|
-
let end = index + 1;
|
|
104
|
-
while (line[end] === "`") end++;
|
|
105
|
-
const runLength = end - index;
|
|
106
|
-
if (codeDelimiterLength === 0) codeDelimiterLength = runLength;
|
|
107
|
-
else if (runLength === codeDelimiterLength) codeDelimiterLength = 0;
|
|
108
|
-
index = end;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (codeDelimiterLength !== 0 || line[index] !== "]" || line[index + 1] !== "(") {
|
|
113
|
-
index++;
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const destinationStart = index + 2;
|
|
118
|
-
if (line[destinationStart] === "<") {
|
|
119
|
-
const angleEnd = line.indexOf(">)", destinationStart + 1);
|
|
120
|
-
if (angleEnd === -1) {
|
|
121
|
-
index++;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
const normalized = normalizeAbsoluteLocalDestination(line.slice(destinationStart + 1, angleEnd));
|
|
125
|
-
if (!normalized) {
|
|
126
|
-
index = angleEnd + 2;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
result += `${line.slice(cursor, destinationStart)}<${normalized}>)`;
|
|
130
|
-
cursor = angleEnd + 2;
|
|
131
|
-
index = cursor;
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const destinationEnd = findBareDestinationEnd(line, destinationStart);
|
|
136
|
-
if (destinationEnd === -1) {
|
|
137
|
-
index++;
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const normalized = normalizeBareDestination(line.slice(destinationStart, destinationEnd));
|
|
141
|
-
if (!normalized) {
|
|
142
|
-
index = destinationEnd + 1;
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
result += `${line.slice(cursor, destinationStart)}${normalized})`;
|
|
146
|
-
cursor = destinationEnd + 1;
|
|
147
|
-
index = cursor;
|
|
148
|
-
}
|
|
149
|
-
return result + line.slice(cursor);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Standardize absolute local link destinations as CommonMark angle-bracket
|
|
154
|
-
* destinations before parsing. This makes whitespace and balanced parentheses
|
|
155
|
-
* unambiguous, converts Windows separators, and repairs already persisted model
|
|
156
|
-
* output such as `[file](/C:/Users/name/My Files/file.md)`.
|
|
157
|
-
*
|
|
158
|
-
*/
|
|
159
|
-
export function normalizeLocalFileLinksInMarkdown(markdown: string): string {
|
|
160
|
-
const parts = markdown.split(/(\r\n|\n|\r)/);
|
|
161
|
-
let fence: MarkdownFence | null = null;
|
|
162
|
-
return parts
|
|
163
|
-
.map((part) => {
|
|
164
|
-
if (part === "\n" || part === "\r" || part === "\r\n") return part;
|
|
165
|
-
const marker = /^ {0,3}(`{3,}|~{3,})/.exec(part)?.[1];
|
|
166
|
-
if (marker) {
|
|
167
|
-
const character = marker[0] as MarkdownFence["character"];
|
|
168
|
-
if (!fence) fence = { character, length: marker.length };
|
|
169
|
-
else if (
|
|
170
|
-
character === fence.character &&
|
|
171
|
-
marker.length >= fence.length &&
|
|
172
|
-
part.slice(part.indexOf(marker) + marker.length).trim() === ""
|
|
173
|
-
) {
|
|
174
|
-
fence = null;
|
|
175
|
-
}
|
|
176
|
-
return part;
|
|
177
|
-
}
|
|
178
|
-
return fence ? part : normalizeMarkdownLine(part);
|
|
179
|
-
})
|
|
180
|
-
.join("");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Convert a `file://` URL to an OS path (POSIX absolute or Windows drive/UNC).
|
|
185
|
-
* Returns null when the input is not a usable file URL.
|
|
186
|
-
*/
|
|
187
|
-
export function fileUrlToPath(href: string): string | null {
|
|
188
|
-
try {
|
|
189
|
-
const url = new URL(href);
|
|
190
|
-
if (url.protocol !== "file:") return null;
|
|
191
|
-
let path = safeDecode(url.pathname);
|
|
192
|
-
// Windows drive: /C:/Users → C:/Users
|
|
193
|
-
if (/^\/[A-Za-z]:/.test(path)) {
|
|
194
|
-
path = path.slice(1);
|
|
195
|
-
}
|
|
196
|
-
// UNC: file://server/share/path → //server/share/path
|
|
197
|
-
if (url.hostname && url.hostname !== "localhost") {
|
|
198
|
-
const body = path.startsWith("/") ? path : `/${path}`;
|
|
199
|
-
path = `//${url.hostname}${body}`;
|
|
200
|
-
}
|
|
201
|
-
return toPosixSeparators(path) || null;
|
|
202
|
-
} catch {
|
|
203
|
-
const stripped = safeDecode(href.replace(/^file:\/\//i, ""));
|
|
204
|
-
if (!stripped) return null;
|
|
205
|
-
if (/^\/[A-Za-z]:/.test(stripped)) {
|
|
206
|
-
return toPosixSeparators(stripped.slice(1));
|
|
207
|
-
}
|
|
208
|
-
return toPosixSeparators(stripped);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Bare names like `readme.md` should open as files; bare domains like
|
|
214
|
-
* `www.example.com` must not. Prefer path separators / relative prefixes;
|
|
215
|
-
* fall back to a conservative extension allowlist (not generic TLDs).
|
|
216
|
-
*/
|
|
217
|
-
const LIKELY_FILE_EXT =
|
|
218
|
-
/\.(?:tsx?|jsx?|mjs|cjs|json|mdx?|txt|pdf|png|jpe?g|gif|webp|svg|html?|css|scss|less|py|rs|go|java|kt|swift|c|cc|cpp|h|hpp|cs|rb|php|sh|bash|zsh|ya?ml|toml|xml|csv|tsv|xlsx?|docx?|pptx?|zip|gz|tgz|7z|rar|mp3|mp4|wav|webm|ico|woff2?|ttf|otf|map|sql|vue|svelte|astro|wasm|log|conf|cfg|ini|plist|ipynb|rtf|lock|env)$/i;
|
|
219
|
-
|
|
220
|
-
function looksLikeRelativeFilePath(value: string): boolean {
|
|
221
|
-
if (/^[.]{1,2}[\\/]/.test(value)) return true;
|
|
222
|
-
if (/[\\/]/.test(value)) return true;
|
|
223
|
-
return LIKELY_FILE_EXT.test(value);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Classify a markdown link href into file / external URL / other.
|
|
228
|
-
* File paths are returned with `/` separators; relative paths are left relative
|
|
229
|
-
* for the host to resolve against the project cwd.
|
|
230
|
-
*/
|
|
231
|
-
export function classifyMarkdownLink(href: string | undefined): MarkdownLinkKind {
|
|
232
|
-
if (!href) return { type: "other", href: "" };
|
|
233
|
-
const trimmed = href.trim();
|
|
234
|
-
if (!trimmed || trimmed.startsWith("#")) {
|
|
235
|
-
return { type: "other", href: trimmed };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (/^(mailto|tel|javascript|data|blob|vetta):/i.test(trimmed)) {
|
|
239
|
-
return { type: "other", href: trimmed };
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (/^https?:\/\//i.test(trimmed)) {
|
|
243
|
-
return { type: "url", url: trimmed };
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Protocol-relative URL (//cdn.example.com/x) — not a Windows UNC path.
|
|
247
|
-
if (trimmed.startsWith("//") && !trimmed.startsWith("\\\\")) {
|
|
248
|
-
return { type: "url", url: `https:${trimmed}` };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (/^file:\/\//i.test(trimmed)) {
|
|
252
|
-
const path = fileUrlToPath(trimmed);
|
|
253
|
-
if (path) return { type: "file", path };
|
|
254
|
-
return { type: "other", href: trimmed };
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const decoded = safeDecode(trimmed);
|
|
258
|
-
|
|
259
|
-
// Windows drive absolute: C:\… or C:/… (after decode of %5C)
|
|
260
|
-
if (/^[A-Za-z]:[\\/]/.test(decoded)) {
|
|
261
|
-
return { type: "file", path: toPosixSeparators(decoded) };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Windows UNC: \\server\share
|
|
265
|
-
if (decoded.startsWith("\\\\")) {
|
|
266
|
-
return { type: "file", path: toPosixSeparators(decoded) };
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// POSIX absolute
|
|
270
|
-
if (decoded.startsWith("/")) {
|
|
271
|
-
return { type: "file", path: decoded };
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (looksLikeRelativeFilePath(decoded)) {
|
|
275
|
-
return { type: "file", path: toPosixSeparators(decoded) };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return { type: "other", href: trimmed };
|
|
279
|
-
}
|
|
1
|
+
export type { MarkdownLinkKind } from "../markdown/markdown-link";
|
|
2
|
+
export {
|
|
3
|
+
chatUrlTransform,
|
|
4
|
+
classifyMarkdownLink,
|
|
5
|
+
fileUrlToPath,
|
|
6
|
+
normalizeLocalFileLinksInMarkdown,
|
|
7
|
+
} from "../markdown/markdown-link";
|
package/src/chat/send-button.css
CHANGED
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
|
|
20
20
|
/* Streaming-state ripple: two staggered rings expand outward from the
|
|
21
21
|
button. Sits in the wrapper (not the button) so it isn't clipped by
|
|
22
|
-
the button's overflow-hidden.
|
|
22
|
+
the button's overflow-hidden.
|
|
23
|
+
两圈不在这里写关键帧:扩散动画由宿主的 live-animations 用 steps(16) 挂上并与其它
|
|
24
|
+
「进行中」指示器锁同一相位(第二圈错开半周),流式全程整页因此每秒只多 10 帧。
|
|
25
|
+
没有宿主动画时保持不可见,不会留下两圈静止的描边。 */
|
|
23
26
|
.send-button-ripple {
|
|
24
27
|
position: absolute;
|
|
25
28
|
inset: 0;
|
|
@@ -28,31 +31,10 @@
|
|
|
28
31
|
pointer-events: none;
|
|
29
32
|
opacity: 0;
|
|
30
33
|
transform: scale(1);
|
|
31
|
-
animation: send-button-ripple 1.8s ease-out infinite;
|
|
32
|
-
will-change: transform, opacity;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.send-button-ripple-2 {
|
|
36
|
-
animation-delay: 0.9s;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@keyframes send-button-ripple {
|
|
40
|
-
0% {
|
|
41
|
-
transform: scale(1);
|
|
42
|
-
opacity: 0.55;
|
|
43
|
-
}
|
|
44
|
-
80% {
|
|
45
|
-
opacity: 0.05;
|
|
46
|
-
}
|
|
47
|
-
100% {
|
|
48
|
-
transform: scale(1.35);
|
|
49
|
-
opacity: 0;
|
|
50
|
-
}
|
|
51
34
|
}
|
|
52
35
|
|
|
53
36
|
@media (prefers-reduced-motion: reduce) {
|
|
54
37
|
.send-button-ripple {
|
|
55
|
-
animation: none;
|
|
56
38
|
display: none;
|
|
57
39
|
}
|
|
58
40
|
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
HOLD_MAX_MS,
|
|
4
|
+
holdBackUnclosedInline,
|
|
5
|
+
nextPhraseEnd,
|
|
6
|
+
planReveal,
|
|
7
|
+
snapToTokenBoundary,
|
|
8
|
+
splitStreamingSegments,
|
|
9
|
+
} from "./streaming-reveal";
|
|
10
|
+
|
|
11
|
+
describe("nextPhraseEnd", () => {
|
|
12
|
+
test("ends a phrase after latin punctuation followed by whitespace", () => {
|
|
13
|
+
expect(nextPhraseEnd("Hello there, world", 0, false)).toBe("Hello there,".length);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("keeps trailing latin punctuation pending until the next character arrives", () => {
|
|
17
|
+
expect(nextPhraseEnd("Hello there,", 0, false)).toBeNull();
|
|
18
|
+
expect(nextPhraseEnd("Hello there,", 0, true)).toBe("Hello there,".length);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("does not break inside numbers or dotted words", () => {
|
|
22
|
+
expect(nextPhraseEnd("pi is 3.14 and more", 0, false)).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("ends a phrase after CJK punctuation including closing quotes", () => {
|
|
26
|
+
expect(nextPhraseEnd("他说:“秋天到了。”然后走了", 0, false)).toBe("他说:".length);
|
|
27
|
+
expect(nextPhraseEnd("他说:“秋天到了。”然后走了", 3, false)).toBe("他说:“秋天到了。”".length);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("ends a phrase at a newline", () => {
|
|
31
|
+
expect(nextPhraseEnd("const a = 1\nconst b", 0, false)).toBe("const a = 1\n".length);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("treats an unfinished tail as pending unless final", () => {
|
|
35
|
+
expect(nextPhraseEnd("still typing", 0, false)).toBeNull();
|
|
36
|
+
expect(nextPhraseEnd("still typing", 0, true)).toBe("still typing".length);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("caps long unpunctuated runs, preferring whitespace", () => {
|
|
40
|
+
const latin = "word ".repeat(30);
|
|
41
|
+
const end = nextPhraseEnd(latin, 0, false);
|
|
42
|
+
expect(end).not.toBeNull();
|
|
43
|
+
expect(end).toBeLessThanOrEqual(48);
|
|
44
|
+
expect(latin[end as number]).toBe(" ");
|
|
45
|
+
|
|
46
|
+
const cjk = "秋".repeat(100);
|
|
47
|
+
expect(nextPhraseEnd(cjk, 0, false)).toBe(48);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("does not split a surrogate pair when capping", () => {
|
|
51
|
+
const text = `${"秋".repeat(47)}😀tail`;
|
|
52
|
+
expect(nextPhraseEnd(text, 0, false)).toBe(49);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("splitStreamingSegments", () => {
|
|
57
|
+
test("round-trips the source text", () => {
|
|
58
|
+
const text = "Hello, world! 你好世界,这是流式输出。\n indented 3.14 and more";
|
|
59
|
+
expect(splitStreamingSegments(text).join("")).toBe(text);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("splits into phrases with leading whitespace attached", () => {
|
|
63
|
+
expect(splitStreamingSegments("As twilight falls, the city wakes. Lights flicker")).toEqual([
|
|
64
|
+
"As twilight falls,",
|
|
65
|
+
" the city wakes.",
|
|
66
|
+
" Lights flicker",
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("keeps earlier segments stable as text grows by whole phrases", () => {
|
|
71
|
+
const before = splitStreamingSegments("秋天来了,天气凉了,");
|
|
72
|
+
const after = splitStreamingSegments("秋天来了,天气凉了,树叶黄了。");
|
|
73
|
+
expect(after.slice(0, before.length)).toEqual(before);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("snapToTokenBoundary", () => {
|
|
78
|
+
test("never splits a latin word or a number", () => {
|
|
79
|
+
expect(snapToTokenBoundary("hello world", 3)).toBe("hello".length);
|
|
80
|
+
expect(snapToTokenBoundary("pi is 3.14159 ok", 9)).toBe("pi is 3.14159".length);
|
|
81
|
+
expect(snapToTokenBoundary("hello world", 5)).toBe(5);
|
|
82
|
+
expect(snapToTokenBoundary("hello world", 6)).toBe(6);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("treats every CJK character as a boundary", () => {
|
|
86
|
+
expect(snapToTokenBoundary("你好世界", 2)).toBe(2);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("does not split a surrogate pair", () => {
|
|
90
|
+
expect(snapToTokenBoundary("a😀b", 2)).toBe(3);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("holdBackUnclosedInline", () => {
|
|
95
|
+
test("holds inline math and matching backtick runs without interpreting their content as links", () => {
|
|
96
|
+
for (const text of ["Value $x + y", "Value $$x + y", "Use ``a`b"]) {
|
|
97
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.indexOf(" ") + 1);
|
|
98
|
+
}
|
|
99
|
+
for (const text of ["Value $x + y$", "Value $$x + y$$", "Use ``a`b``", "Cost \\$5", "Use `[$x]` now"]) {
|
|
100
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.length);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("keeps nested link destinations and a just-arrived closing bracket pending", () => {
|
|
105
|
+
for (const text of [
|
|
106
|
+
"See [page]",
|
|
107
|
+
"See [page](https://example.test/a(b)",
|
|
108
|
+
"See ",
|
|
109
|
+
]) {
|
|
110
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(4);
|
|
111
|
+
}
|
|
112
|
+
const text = "See [page](https://example.test/a(b)) now";
|
|
113
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.length);
|
|
114
|
+
});
|
|
115
|
+
test("holds an open link until its url closes", () => {
|
|
116
|
+
const text = "See [report](/tmp/report.md) now";
|
|
117
|
+
expect(holdBackUnclosedInline(text, "See [rep".length)).toBe("See ".length);
|
|
118
|
+
expect(holdBackUnclosedInline(text, "See [report](/tmp/re".length)).toBe("See ".length);
|
|
119
|
+
expect(holdBackUnclosedInline(text, "See [report](/tmp/report.md)".length)).toBe(
|
|
120
|
+
"See [report](/tmp/report.md)".length,
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("brackets that are not followed by a url are not a link", () => {
|
|
125
|
+
const text = "array[0] is fine";
|
|
126
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.length);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("holds open inline code and bold", () => {
|
|
130
|
+
expect(holdBackUnclosedInline("run `npm te", "run `npm te".length)).toBe("run ".length);
|
|
131
|
+
expect(holdBackUnclosedInline("run `npm test` now", "run `npm test` now".length)).toBe(
|
|
132
|
+
"run `npm test` now".length,
|
|
133
|
+
);
|
|
134
|
+
expect(holdBackUnclosedInline("a **bold wo", "a **bold wo".length)).toBe("a ".length);
|
|
135
|
+
expect(holdBackUnclosedInline("a **bold** b", "a **bold** b".length)).toBe("a **bold** b".length);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("only looks at the current line", () => {
|
|
139
|
+
const text = "[broken\nnext line";
|
|
140
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.length);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("planReveal", () => {
|
|
145
|
+
const base = { final: false, ratePerMs: 0.1, elapsedMs: 100, stalled: false, heldMs: 0 };
|
|
146
|
+
|
|
147
|
+
test("reveals an already complete inline construct atomically even when its closing token exceeds the character budget", () => {
|
|
148
|
+
for (const text of [
|
|
149
|
+
"See [page](https://example.test/a(b))",
|
|
150
|
+
"See $x + y$",
|
|
151
|
+
"See **bold words**",
|
|
152
|
+
"See ``a`b``",
|
|
153
|
+
]) {
|
|
154
|
+
expect(planReveal({ ...base, text, revealed: 4, ratePerMs: 0.02 })?.end).toBe(text.length);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("does not use an unrelated next line as an inline closing delimiter", () => {
|
|
159
|
+
expect(planReveal({ ...base, text: "See [broken\nNext paragraph", revealed: 4, ratePerMs: 0.02 })).toEqual({
|
|
160
|
+
end: 4,
|
|
161
|
+
held: true,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("returns null when everything is already shown", () => {
|
|
166
|
+
expect(planReveal({ ...base, text: "done", revealed: 4 })).toBeNull();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("reveals a rate-sized slice aligned to a word boundary", () => {
|
|
170
|
+
// 0.1 字/ms × 100ms × 1.15 ≈ 12 字,落在 "sentence" 中间,向后推到词尾。
|
|
171
|
+
const text = "A short sentence that keeps going on and on";
|
|
172
|
+
expect(planReveal({ ...base, text, revealed: 0 })?.end).toBe("A short sentence".length);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("keeps an unfinished trailing word until it completes or the stream stalls", () => {
|
|
176
|
+
const text = "Hello there, gene";
|
|
177
|
+
expect(planReveal({ ...base, text, revealed: 0, ratePerMs: 1 })?.end).toBe("Hello there, ".length);
|
|
178
|
+
expect(planReveal({ ...base, text, revealed: 0, ratePerMs: 1, stalled: true })?.end).toBe(text.length);
|
|
179
|
+
expect(planReveal({ ...base, text, revealed: 0, ratePerMs: 1, final: true })?.end).toBe(text.length);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("catches up when the backlog exceeds the allowed lag and snaps when it is huge", () => {
|
|
183
|
+
const text = "word ".repeat(100);
|
|
184
|
+
const slow = planReveal({ ...base, text, revealed: 0, ratePerMs: 0.02 });
|
|
185
|
+
expect(slow?.end).toBeGreaterThan(0.02 * 100 * 1.15 + 5);
|
|
186
|
+
const huge = planReveal({ ...base, text: "x ".repeat(1000), revealed: 0 });
|
|
187
|
+
expect(huge?.end).toBe(2000);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("reveals everything at once when the stream is final, ignoring holds", () => {
|
|
191
|
+
const text = `${"a ".repeat(100)}[open](/tmp/li`;
|
|
192
|
+
const step = planReveal({ ...base, text, revealed: 0, final: true, ratePerMs: 0.01, elapsedMs: 1 });
|
|
193
|
+
expect(step).toEqual({ end: text.length, held: false });
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("holds back an open link and reports it, then releases after the hold timeout", () => {
|
|
197
|
+
const text = "See [report](/tmp/rep";
|
|
198
|
+
const held = planReveal({ ...base, text, revealed: 0, ratePerMs: 1 });
|
|
199
|
+
expect(held).toEqual({ end: "See ".length, held: true });
|
|
200
|
+
const waiting = planReveal({ ...base, text, revealed: "See ".length, ratePerMs: 1 });
|
|
201
|
+
expect(waiting).toEqual({ end: "See ".length, held: true });
|
|
202
|
+
const released = planReveal({ ...base, text, revealed: "See ".length, ratePerMs: 1, heldMs: HOLD_MAX_MS });
|
|
203
|
+
expect(released?.held).toBe(false);
|
|
204
|
+
expect(released?.end).toBeGreaterThan("See ".length);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("TeX delimiter streaming", () => {
|
|
209
|
+
test.each([String.raw`before \(x^2`, String.raw`before \[x^2`])("holds unclosed formula %s", (text) => {
|
|
210
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(7);
|
|
211
|
+
});
|
|
212
|
+
test.each([String.raw`before \(x^2\) after`, String.raw`before \[x^2\] after`, String.raw`before \\(literal`])(
|
|
213
|
+
"releases complete or escaped formula %s",
|
|
214
|
+
(text) => {
|
|
215
|
+
expect(holdBackUnclosedInline(text, text.length)).toBe(text.length);
|
|
216
|
+
},
|
|
217
|
+
);
|
|
218
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { RevealPlanInput, RevealStep } from "../markdown/streaming-reveal";
|
|
2
|
+
export {
|
|
3
|
+
DEFAULT_RATE_PER_MS,
|
|
4
|
+
HOLD_MAX_MS,
|
|
5
|
+
holdBackUnclosedInline,
|
|
6
|
+
nextPhraseEnd,
|
|
7
|
+
planReveal,
|
|
8
|
+
REVEAL_TICK_MS,
|
|
9
|
+
STREAMING_SETTLE_MS,
|
|
10
|
+
STREAMING_STALL_FLUSH_MS,
|
|
11
|
+
snapToTokenBoundary,
|
|
12
|
+
splitStreamingSegments,
|
|
13
|
+
} from "../markdown/streaming-reveal";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { motion } from "motion/react";
|
|
2
2
|
import { useEffect, type JSX, type ReactNode } from "react";
|
|
3
|
+
import { cn, OVERLAY_BACKDROP_CLASS } from "@vetta-org/ui/utils";
|
|
3
4
|
|
|
4
5
|
export interface ConfirmDeleteDialogViewLabels {
|
|
5
6
|
title: string;
|
|
@@ -35,7 +36,7 @@ export function ConfirmDeleteDialogView({
|
|
|
35
36
|
|
|
36
37
|
return (
|
|
37
38
|
<div
|
|
38
|
-
className="fixed inset-0 z-50 flex items-center justify-center
|
|
39
|
+
className={cn("fixed inset-0 z-50 flex items-center justify-center", OVERLAY_BACKDROP_CLASS)}
|
|
39
40
|
onClick={onCancel}
|
|
40
41
|
onKeyDown={(e) => {
|
|
41
42
|
if (e.key === "Escape") onCancel();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnimatePresence, motion } from "motion/react";
|
|
2
|
-
import { useEffect, useRef, type JSX, type ReactNode } from "react";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState, type JSX, type ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
export interface FileContextMenuViewLabels {
|
|
5
5
|
newFile: string;
|
|
@@ -31,6 +31,11 @@ export interface FileContextMenuViewProps {
|
|
|
31
31
|
showEntryActions: boolean;
|
|
32
32
|
canPaste: boolean;
|
|
33
33
|
canRename: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* False when the entry has no counterpart on this computer (a file in a remote project):
|
|
36
|
+
* there is nothing for the system file manager to show. Defaults to true.
|
|
37
|
+
*/
|
|
38
|
+
canOpenInFolder?: boolean;
|
|
34
39
|
pluginActions?: readonly FileContextMenuPluginAction[];
|
|
35
40
|
}
|
|
36
41
|
|
|
@@ -41,6 +46,14 @@ export interface FileContextMenuPluginAction {
|
|
|
41
46
|
onSelect: () => void;
|
|
42
47
|
}
|
|
43
48
|
|
|
49
|
+
const VIEWPORT_MARGIN = 8;
|
|
50
|
+
|
|
51
|
+
/** 超出视口就翻到光标另一侧;两侧都放不下时贴住起始边,宁可裁尾也别裁头。 */
|
|
52
|
+
function clampToViewport(start: number, size: number, viewport: number): number {
|
|
53
|
+
if (start + size <= viewport - VIEWPORT_MARGIN) return start;
|
|
54
|
+
return Math.max(VIEWPORT_MARGIN, Math.min(start - size, viewport - VIEWPORT_MARGIN - size));
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
/**
|
|
45
58
|
* File tree context menu shell. Host wires IPC / rename atom / i18n.
|
|
46
59
|
*
|
|
@@ -55,6 +68,7 @@ export function FileContextMenuView({
|
|
|
55
68
|
onCreateFile,
|
|
56
69
|
onCreateFolder,
|
|
57
70
|
onOpenInFolder,
|
|
71
|
+
canOpenInFolder = true,
|
|
58
72
|
onCopy,
|
|
59
73
|
onPaste,
|
|
60
74
|
onCopyPath,
|
|
@@ -67,6 +81,22 @@ export function FileContextMenuView({
|
|
|
67
81
|
pluginActions = [],
|
|
68
82
|
}: FileContextMenuViewProps): JSX.Element {
|
|
69
83
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
84
|
+
const [position, setPosition] = useState({ left: x, top: y });
|
|
85
|
+
|
|
86
|
+
// 光标贴近面板右/下边缘时,菜单按原始坐标铺开会伸出窗口外被裁掉,
|
|
87
|
+
// 这里量完实际尺寸再朝内翻转,保证整份菜单始终落在视口内。
|
|
88
|
+
useLayoutEffect(() => {
|
|
89
|
+
const el = menuRef.current;
|
|
90
|
+
if (!el) return;
|
|
91
|
+
// offsetWidth/Height 不受入场动画的 scale 影响,拿到的是真实布局尺寸。
|
|
92
|
+
const width = el.offsetWidth;
|
|
93
|
+
const height = el.offsetHeight;
|
|
94
|
+
const next = {
|
|
95
|
+
left: clampToViewport(x, width, window.innerWidth),
|
|
96
|
+
top: clampToViewport(y, height, window.innerHeight),
|
|
97
|
+
};
|
|
98
|
+
setPosition((prev) => (prev.left === next.left && prev.top === next.top ? prev : next));
|
|
99
|
+
}, [x, y, showEntryActions, canPaste, canRename, canOpenInFolder, pluginActions.length]);
|
|
70
100
|
|
|
71
101
|
useEffect(() => {
|
|
72
102
|
function handleClick(e: MouseEvent) {
|
|
@@ -95,9 +125,10 @@ export function FileContextMenuView({
|
|
|
95
125
|
exit={{ opacity: 0, scale: 0.95 }}
|
|
96
126
|
transition={{ duration: 0.12, ease: [0.25, 0.1, 0.25, 1] }}
|
|
97
127
|
className="fixed z-50 w-[180px] overflow-hidden rounded-lg border border-border bg-popover p-1 shadow-lg"
|
|
128
|
+
data-testid="file-context-menu"
|
|
98
129
|
style={{
|
|
99
|
-
left: `${
|
|
100
|
-
top: `${
|
|
130
|
+
left: `${position.left}px`,
|
|
131
|
+
top: `${position.top}px`,
|
|
101
132
|
}}
|
|
102
133
|
>
|
|
103
134
|
<button
|
|
@@ -117,14 +148,16 @@ export function FileContextMenuView({
|
|
|
117
148
|
{labels.newFolder}
|
|
118
149
|
</button>
|
|
119
150
|
<div className="mx-1.5 my-1 h-px bg-border" />
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
{canOpenInFolder ? (
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
onClick={onOpenInFolder}
|
|
155
|
+
className="flex w-full items-center gap-2 rounded-md px-2 py-[5px] text-[12px] font-medium text-foreground transition-colors hover:bg-accent"
|
|
156
|
+
>
|
|
157
|
+
<span className="icon-[solar--folder-open-linear] h-3.5 w-3.5" />
|
|
158
|
+
{labels.openInFolder}
|
|
159
|
+
</button>
|
|
160
|
+
) : null}
|
|
128
161
|
{showEntryActions ? (
|
|
129
162
|
<button
|
|
130
163
|
type="button"
|