@deepseek-ai/dsh-client-ui-primitives 0.2.2-alpha.3 → 0.2.2-rc.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/README.i18n.yaml +16 -16
- package/README.md +21 -14
- package/README.zh.md +21 -14
- package/lib/HoverCard.module.css +8 -3
- package/lib/JsonTree.module.css +7 -17
- package/lib/Menu.module.css +157 -37
- package/lib/Modal.module.css +16 -0
- package/lib/QuotePreview.module.css +37 -0
- package/lib/RiskConfirmation.module.css +11 -37
- package/lib/Toast.module.css +2 -3
- package/lib/Tooltip.module.css +2 -1
- package/lib/index.js +1447 -776
- package/lib/index.js.map +1 -0
- package/lib/markdown/CodeBlock.module.css +64 -0
- package/lib/markdown/MarkdownText.module.css +20 -1
- package/lib/types/AnimatedRows.d.ts +3 -0
- package/lib/types/AnimatedRows.d.ts.map +1 -0
- package/lib/types/AnimatedRows.js.map +1 -0
- package/lib/types/BrandWordmark.d.ts.map +1 -0
- package/lib/types/BrandWordmark.js.map +1 -0
- package/lib/types/Button.d.ts.map +1 -0
- package/lib/types/Button.js.map +1 -0
- package/lib/types/Checkbox.d.ts +3 -1
- package/lib/types/Checkbox.d.ts.map +1 -0
- package/lib/types/Checkbox.js.map +1 -0
- package/lib/types/CodeFileIcon.d.ts.map +1 -0
- package/lib/types/CodeFileIcon.js.map +1 -0
- package/lib/types/CodeToolbar.d.ts.map +1 -0
- package/lib/types/CodeToolbar.js.map +1 -0
- package/lib/types/CommandText.d.ts.map +1 -0
- package/lib/types/CommandText.js.map +1 -0
- package/lib/types/ConfigField.d.ts.map +1 -0
- package/lib/types/ConfigField.js.map +1 -0
- package/lib/types/ConnectionIndicator.d.ts.map +1 -0
- package/lib/types/ConnectionIndicator.js.map +1 -0
- package/lib/types/DetailDocument.d.ts.map +1 -0
- package/lib/types/DetailDocument.js.map +1 -0
- package/lib/types/DiffBlock.d.ts.map +1 -0
- package/lib/types/DiffBlock.js.map +1 -0
- package/lib/types/DisclosureRow.d.ts.map +1 -0
- package/lib/types/DisclosureRow.js.map +1 -0
- package/lib/types/DraggableImage.d.ts.map +1 -0
- package/lib/types/DraggableImage.js.map +1 -0
- package/lib/types/FileTypeIcon.d.ts.map +1 -0
- package/lib/types/FileTypeIcon.js.map +1 -0
- package/lib/types/FishLogo.d.ts.map +1 -0
- package/lib/types/FishLogo.js.map +1 -0
- package/lib/types/FoldToggle.d.ts.map +1 -0
- package/lib/types/FoldToggle.js.map +1 -0
- package/lib/types/HoverCard.d.ts.map +1 -0
- package/lib/types/HoverCard.js.map +1 -0
- package/lib/types/HoverCardGroup.d.ts.map +1 -0
- package/lib/types/HoverCardGroup.js.map +1 -0
- package/lib/types/ImageLightbox.d.ts.map +1 -0
- package/lib/types/ImageLightbox.js.map +1 -0
- package/lib/types/ImagePreview.d.ts.map +1 -0
- package/lib/types/ImagePreview.js.map +1 -0
- package/lib/types/InlineEditor.d.ts.map +1 -0
- package/lib/types/InlineEditor.js.map +1 -0
- package/lib/types/Input.d.ts.map +1 -0
- package/lib/types/Input.js.map +1 -0
- package/lib/types/JsonTree.d.ts.map +1 -0
- package/lib/types/JsonTree.js.map +1 -0
- package/lib/types/LinkIcon.d.ts.map +1 -0
- package/lib/types/LinkIcon.js.map +1 -0
- package/lib/types/Menu.d.ts +26 -14
- package/lib/types/Menu.d.ts.map +1 -0
- package/lib/types/Menu.js.map +1 -0
- package/lib/types/MenuGroup.d.ts.map +1 -0
- package/lib/types/MenuGroup.js.map +1 -0
- package/lib/types/MenuRow.d.ts +37 -0
- package/lib/types/MenuRow.d.ts.map +1 -0
- package/lib/types/MenuRow.js.map +1 -0
- package/lib/types/MenuSurface.d.ts.map +1 -0
- package/lib/types/MenuSurface.js.map +1 -0
- package/lib/types/Modal.d.ts +3 -1
- package/lib/types/Modal.d.ts.map +1 -0
- package/lib/types/Modal.js.map +1 -0
- package/lib/types/PathLabel.d.ts.map +1 -0
- package/lib/types/PathLabel.js.map +1 -0
- package/lib/types/PermissionIcon.d.ts.map +1 -0
- package/lib/types/PermissionIcon.js.map +1 -0
- package/lib/types/Pill.d.ts.map +1 -0
- package/lib/types/Pill.js.map +1 -0
- package/lib/types/QuotePreview.d.ts +17 -4
- package/lib/types/QuotePreview.d.ts.map +1 -0
- package/lib/types/QuotePreview.js.map +1 -0
- package/lib/types/ReadBlock.d.ts.map +1 -0
- package/lib/types/ReadBlock.js.map +1 -0
- package/lib/types/ReferenceIcon.d.ts.map +1 -0
- package/lib/types/ReferenceIcon.js.map +1 -0
- package/lib/types/RiskConfirmation.d.ts.map +1 -0
- package/lib/types/RiskConfirmation.js.map +1 -0
- package/lib/types/SearchBlock.d.ts.map +1 -0
- package/lib/types/SearchBlock.js.map +1 -0
- package/lib/types/SegmentedControl.d.ts.map +1 -0
- package/lib/types/SegmentedControl.js.map +1 -0
- package/lib/types/SegmentedTabs.d.ts.map +1 -0
- package/lib/types/SegmentedTabs.js.map +1 -0
- package/lib/types/ShortcutKeys.d.ts.map +1 -0
- package/lib/types/ShortcutKeys.js.map +1 -0
- package/lib/types/SiteGlyph.d.ts.map +1 -0
- package/lib/types/SiteGlyph.js.map +1 -0
- package/lib/types/StateDot.d.ts.map +1 -0
- package/lib/types/StateDot.js.map +1 -0
- package/lib/types/SubmenuPanel.d.ts +19 -0
- package/lib/types/SubmenuPanel.d.ts.map +1 -0
- package/lib/types/SubmenuPanel.js.map +1 -0
- package/lib/types/Switch.d.ts.map +1 -0
- package/lib/types/Switch.js.map +1 -0
- package/lib/types/Tag.d.ts.map +1 -0
- package/lib/types/Tag.js.map +1 -0
- package/lib/types/TerminalBlock.d.ts.map +1 -0
- package/lib/types/TerminalBlock.js.map +1 -0
- package/lib/types/TextShimmer.d.ts.map +1 -0
- package/lib/types/TextShimmer.js.map +1 -0
- package/lib/types/Toast.d.ts.map +1 -0
- package/lib/types/Toast.js.map +1 -0
- package/lib/types/Tooltip.d.ts.map +1 -0
- package/lib/types/Tooltip.js.map +1 -0
- package/lib/types/UserMessageBubble.d.ts.map +1 -0
- package/lib/types/UserMessageBubble.js.map +1 -0
- package/lib/types/WebBlock.d.ts.map +1 -0
- package/lib/types/WebBlock.js.map +1 -0
- package/lib/types/ZoomControls.d.ts.map +1 -0
- package/lib/types/ZoomControls.js.map +1 -0
- package/lib/types/ansi.d.ts.map +1 -0
- package/lib/types/ansi.js.map +1 -0
- package/lib/types/clipboard.d.ts.map +1 -0
- package/lib/types/clipboard.js.map +1 -0
- package/lib/types/code-file-icon-artwork.d.ts.map +1 -0
- package/lib/types/code-file-icon-artwork.js.map +1 -0
- package/lib/types/code-file-types.d.ts.map +1 -0
- package/lib/types/code-file-types.js.map +1 -0
- package/lib/types/code-highlighting.d.ts.map +1 -0
- package/lib/types/code-highlighting.js.map +1 -0
- package/lib/types/darwin-desktop.d.ts.map +1 -0
- package/lib/types/darwin-desktop.js.map +1 -0
- package/lib/types/document-zoom.d.ts.map +1 -0
- package/lib/types/document-zoom.js.map +1 -0
- package/lib/types/file-drag-actions.d.ts.map +1 -0
- package/lib/types/file-drag-actions.js.map +1 -0
- package/lib/types/file-size.d.ts.map +1 -0
- package/lib/types/file-size.js.map +1 -0
- package/lib/types/focus.d.ts.map +1 -0
- package/lib/types/focus.js.map +1 -0
- package/lib/types/guide-artwork.d.ts.map +1 -0
- package/lib/types/guide-artwork.js.map +1 -0
- package/lib/types/head-tail-cap.d.ts.map +1 -0
- package/lib/types/head-tail-cap.js.map +1 -0
- package/lib/types/icons/artwork.d.ts +12 -0
- package/lib/types/icons/artwork.d.ts.map +1 -0
- package/lib/types/icons/artwork.js.map +1 -0
- package/lib/types/icons/index.d.ts +12 -0
- package/lib/types/icons/index.d.ts.map +1 -0
- package/lib/types/icons/index.js.map +1 -0
- package/lib/types/icons/props.d.ts.map +1 -0
- package/lib/types/icons/props.js.map +1 -0
- package/lib/types/icons/shared-artwork.d.ts.map +1 -0
- package/lib/types/icons/shared-artwork.js.map +1 -0
- package/lib/types/image-drag.d.ts.map +1 -0
- package/lib/types/image-drag.js.map +1 -0
- package/lib/types/index.d.ts +5 -4
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/input-modality.d.ts.map +1 -0
- package/lib/types/input-modality.js.map +1 -0
- package/lib/types/keyboard-composition.d.ts.map +1 -0
- package/lib/types/keyboard-composition.js.map +1 -0
- package/lib/types/markdown/CodeBlock.d.ts +8 -1
- package/lib/types/markdown/CodeBlock.d.ts.map +1 -0
- package/lib/types/markdown/CodeBlock.js.map +1 -0
- package/lib/types/markdown/FenceBlocks.d.ts +31 -0
- package/lib/types/markdown/FenceBlocks.d.ts.map +1 -0
- package/lib/types/markdown/FenceBlocks.js.map +1 -0
- package/lib/types/markdown/JsonBlock.d.ts.map +1 -0
- package/lib/types/markdown/JsonBlock.js.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.d.ts +23 -1
- package/lib/types/markdown/MarkdownDelegate.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.js.map +1 -0
- package/lib/types/markdown/MarkdownText.d.ts +2 -0
- package/lib/types/markdown/MarkdownText.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownText.js.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -0
- package/lib/types/markdown/copy-tex.d.ts +14 -0
- package/lib/types/markdown/copy-tex.d.ts.map +1 -0
- package/lib/types/markdown/copy-tex.js.map +1 -0
- package/lib/types/markdown/diff-fence.d.ts +58 -0
- package/lib/types/markdown/diff-fence.d.ts.map +1 -0
- package/lib/types/markdown/diff-fence.js.map +1 -0
- package/lib/types/markdown/file-link.d.ts.map +1 -0
- package/lib/types/markdown/file-link.js.map +1 -0
- package/lib/types/markdown/highlight.d.ts +18 -0
- package/lib/types/markdown/highlight.d.ts.map +1 -0
- package/lib/types/markdown/highlight.js.map +1 -0
- package/lib/types/markdown/incremental.d.ts.map +1 -0
- package/lib/types/markdown/incremental.js.map +1 -0
- package/lib/types/markdown/katex.d.ts.map +1 -0
- package/lib/types/markdown/katex.js.map +1 -0
- package/lib/types/markdown/local-image-syntax.d.ts.map +1 -0
- package/lib/types/markdown/local-image-syntax.js.map +1 -0
- package/lib/types/markdown/mathCompatibility.d.ts.map +1 -0
- package/lib/types/markdown/mathCompatibility.js.map +1 -0
- package/lib/types/markdown/parse.d.ts.map +1 -0
- package/lib/types/markdown/parse.js.map +1 -0
- package/lib/types/markdown/plain-text.d.ts.map +1 -0
- package/lib/types/markdown/plain-text.js.map +1 -0
- package/lib/types/markdown/quote-text.d.ts.map +1 -0
- package/lib/types/markdown/quote-text.js.map +1 -0
- package/lib/types/markdown/render.d.ts.map +1 -0
- package/lib/types/markdown/render.js.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.d.ts.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.js.map +1 -0
- package/lib/types/markdown/windows-path-destinations.d.ts.map +1 -0
- package/lib/types/markdown/windows-path-destinations.js.map +1 -0
- package/lib/types/menu-submenu-position.d.ts +15 -0
- package/lib/types/menu-submenu-position.d.ts.map +1 -0
- package/lib/types/menu-submenu-position.js.map +1 -0
- package/lib/types/overlay-top-margin.d.ts.map +1 -0
- package/lib/types/overlay-top-margin.js.map +1 -0
- package/lib/types/plugin-artwork.d.ts.map +1 -0
- package/lib/types/plugin-artwork.js.map +1 -0
- package/lib/types/pointer-grace.d.ts.map +1 -0
- package/lib/types/pointer-grace.js.map +1 -0
- package/lib/types/rank-by-name.d.ts.map +1 -0
- package/lib/types/rank-by-name.js.map +1 -0
- package/lib/types/relative-time.d.ts.map +1 -0
- package/lib/types/relative-time.js.map +1 -0
- package/lib/types/settings-form/SettingsForm.d.ts.map +1 -0
- package/lib/types/settings-form/SettingsForm.js.map +1 -0
- package/lib/types/settings-form/fields.d.ts.map +1 -0
- package/lib/types/settings-form/fields.js.map +1 -0
- package/lib/types/settings-form/form-model.d.ts.map +1 -0
- package/lib/types/settings-form/form-model.js.map +1 -0
- package/lib/types/tooltip-placement.d.ts.map +1 -0
- package/lib/types/tooltip-placement.js.map +1 -0
- package/lib/types/use-clipboard-copy.d.ts.map +1 -0
- package/lib/types/use-clipboard-copy.js.map +1 -0
- package/lib/types/useAnchoredMaxHeight.d.ts.map +1 -0
- package/lib/types/useAnchoredMaxHeight.js.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.d.ts.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.js.map +1 -0
- package/lib/types/useMenuSubmenu.d.ts +43 -0
- package/lib/types/useMenuSubmenu.d.ts.map +1 -0
- package/lib/types/useMenuSubmenu.js.map +1 -0
- package/lib/types/useModalLayer.d.ts.map +1 -0
- package/lib/types/useModalLayer.js.map +1 -0
- package/lib/types/useRowDragPreview.d.ts.map +1 -0
- package/lib/types/useRowDragPreview.js.map +1 -0
- package/lib/types/user-text.d.ts.map +1 -0
- package/lib/types/user-text.js.map +1 -0
- package/package.json +11 -8
- package/src/AnimatedRows.module.css +7 -0
- package/src/AnimatedRows.tsx +195 -0
- package/src/BrandWordmark.tsx +59 -0
- package/src/Button.module.css +84 -0
- package/src/Button.tsx +36 -0
- package/src/Checkbox.module.css +28 -0
- package/src/Checkbox.tsx +34 -0
- package/src/CodeCard.module.css +85 -0
- package/src/CodeFileIcon.tsx +28 -0
- package/src/CodeToolbar.tsx +62 -0
- package/src/CommandText.module.css +12 -0
- package/src/CommandText.tsx +46 -0
- package/src/ConfigField.module.css +12 -0
- package/src/ConfigField.tsx +53 -0
- package/src/ConnectionIndicator.module.css +120 -0
- package/src/ConnectionIndicator.tsx +103 -0
- package/src/DetailDocument.module.css +67 -0
- package/src/DetailDocument.tsx +120 -0
- package/src/DiffBlock.module.css +82 -0
- package/src/DiffBlock.tsx +221 -0
- package/src/DisclosureRow.module.css +115 -0
- package/src/DisclosureRow.tsx +124 -0
- package/src/DraggableImage.tsx +26 -0
- package/src/FileTypeIcon.module.css +50 -0
- package/src/FileTypeIcon.tsx +285 -0
- package/src/FishLogo.tsx +28 -0
- package/src/FoldToggle.tsx +33 -0
- package/src/HoverCard.module.css +108 -0
- package/src/HoverCard.tsx +356 -0
- package/src/HoverCardGroup.tsx +77 -0
- package/src/ImageLightbox.module.css +54 -0
- package/src/ImageLightbox.tsx +72 -0
- package/src/ImagePreview.module.css +24 -0
- package/src/ImagePreview.tsx +36 -0
- package/src/InlineEditor.module.css +23 -0
- package/src/InlineEditor.tsx +69 -0
- package/src/Input.module.css +38 -0
- package/src/Input.tsx +24 -0
- package/src/JsonTree.module.css +371 -0
- package/src/JsonTree.tsx +850 -0
- package/src/LinkIcon.tsx +118 -0
- package/src/Menu.module.css +443 -0
- package/src/Menu.tsx +553 -0
- package/src/MenuGroup.module.css +37 -0
- package/src/MenuGroup.tsx +103 -0
- package/src/MenuRow.tsx +89 -0
- package/src/MenuSurface.module.css +65 -0
- package/src/MenuSurface.tsx +54 -0
- package/src/Modal.module.css +147 -0
- package/src/Modal.tsx +96 -0
- package/src/PathLabel.module.css +28 -0
- package/src/PathLabel.tsx +41 -0
- package/src/PermissionIcon.tsx +119 -0
- package/src/Pill.module.css +30 -0
- package/src/Pill.tsx +36 -0
- package/src/QuotePreview.module.css +138 -0
- package/src/QuotePreview.tsx +133 -0
- package/src/ReadBlock.module.css +45 -0
- package/src/ReadBlock.tsx +151 -0
- package/src/ReferenceIcon.tsx +49 -0
- package/src/RiskConfirmation.module.css +47 -0
- package/src/RiskConfirmation.tsx +79 -0
- package/src/RowDragPreview.module.css +12 -0
- package/src/SearchBlock.module.css +114 -0
- package/src/SearchBlock.tsx +281 -0
- package/src/SegmentedControl.module.css +81 -0
- package/src/SegmentedControl.tsx +140 -0
- package/src/SegmentedTabs.module.css +77 -0
- package/src/SegmentedTabs.tsx +84 -0
- package/src/ShortcutKeys.module.css +33 -0
- package/src/ShortcutKeys.tsx +12 -0
- package/src/SiteGlyph.tsx +149 -0
- package/src/StateDot.module.css +100 -0
- package/src/StateDot.tsx +77 -0
- package/src/SubmenuPanel.tsx +51 -0
- package/src/Switch.module.css +49 -0
- package/src/Switch.tsx +42 -0
- package/src/Tag.module.css +57 -0
- package/src/Tag.tsx +42 -0
- package/src/TerminalBlock.module.css +207 -0
- package/src/TerminalBlock.tsx +294 -0
- package/src/TextShimmer.module.css +88 -0
- package/src/TextShimmer.tsx +58 -0
- package/src/Toast.module.css +102 -0
- package/src/Toast.tsx +101 -0
- package/src/Tooltip.module.css +68 -0
- package/src/Tooltip.tsx +273 -0
- package/src/UserMessageBubble.module.css +11 -0
- package/src/UserMessageBubble.tsx +16 -0
- package/src/WebBlock.module.css +153 -0
- package/src/WebBlock.tsx +196 -0
- package/src/ZoomControls.module.css +54 -0
- package/src/ZoomControls.tsx +92 -0
- package/src/ansi.ts +447 -0
- package/src/clipboard.ts +47 -0
- package/src/code-file-icon-artwork.manifest.json +71 -0
- package/src/code-file-icon-artwork.ts +60 -0
- package/src/code-file-types.ts +340 -0
- package/src/code-highlighting.ts +25 -0
- package/src/css-modules.d.ts +6 -0
- package/src/darwin-desktop.ts +11 -0
- package/src/document-zoom.ts +12 -0
- package/src/file-drag-actions.ts +29 -0
- package/src/file-size.ts +16 -0
- package/src/focus.ts +44 -0
- package/src/guide-artwork.tsx +32 -0
- package/src/head-tail-cap.ts +27 -0
- package/src/icons/artwork.ts +156 -0
- package/src/icons/index.tsx +634 -0
- package/src/icons/props.ts +8 -0
- package/src/icons/shared-artwork.tsx +71 -0
- package/src/image-drag.ts +84 -0
- package/src/index.ts +142 -0
- package/src/input-modality.ts +59 -0
- package/src/keyboard-composition.ts +36 -0
- package/src/markdown/CodeBlock.module.css +209 -0
- package/src/markdown/CodeBlock.tsx +268 -0
- package/src/markdown/FenceBlocks.tsx +51 -0
- package/src/markdown/JsonBlock.module.css +34 -0
- package/src/markdown/JsonBlock.tsx +36 -0
- package/src/markdown/MarkdownDelegate.tsx +102 -0
- package/src/markdown/MarkdownText.module.css +511 -0
- package/src/markdown/MarkdownText.tsx +218 -0
- package/src/markdown/cjkFriendlyStrong.ts +83 -0
- package/src/markdown/copy-tex.ts +53 -0
- package/src/markdown/diff-fence.ts +212 -0
- package/src/markdown/file-link.ts +45 -0
- package/src/markdown/highlight.ts +689 -0
- package/src/markdown/incremental.ts +360 -0
- package/src/markdown/katex.tsx +90 -0
- package/src/markdown/local-image-syntax.ts +29 -0
- package/src/markdown/mathCompatibility.ts +349 -0
- package/src/markdown/parse.ts +49 -0
- package/src/markdown/plain-text.ts +121 -0
- package/src/markdown/quote-text.ts +10 -0
- package/src/markdown/render.tsx +834 -0
- package/src/markdown/useViewportHighlighting.ts +72 -0
- package/src/markdown/windows-path-destinations.ts +34 -0
- package/src/menu-submenu-position.ts +20 -0
- package/src/overlay-top-margin.ts +18 -0
- package/src/plugin-artwork.tsx +110 -0
- package/src/pointer-grace.ts +47 -0
- package/src/rank-by-name.ts +93 -0
- package/src/relative-time.ts +36 -0
- package/src/settings-form/SettingsForm.module.css +53 -0
- package/src/settings-form/SettingsForm.tsx +74 -0
- package/src/settings-form/fields.module.css +153 -0
- package/src/settings-form/fields.tsx +151 -0
- package/src/settings-form/form-model.ts +393 -0
- package/src/tooltip-placement.ts +60 -0
- package/src/use-clipboard-copy.ts +44 -0
- package/src/useAnchoredMaxHeight.ts +45 -0
- package/src/useDismissOnOutsidePointer.ts +34 -0
- package/src/useMenuSubmenu.ts +182 -0
- package/src/useModalLayer.ts +108 -0
- package/src/useRowDragPreview.ts +76 -0
- package/src/user-text.module.css +46 -0
- package/src/user-text.tsx +67 -0
- package/lib/types/useAnchoredPosition.d.ts +0 -36
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { IconCheckOutlineRegular, IconRefreshOutlineRegular } from './icons/index.tsx'
|
|
3
|
+
import { StateDot } from './StateDot.tsx'
|
|
4
|
+
import css from './ConnectionIndicator.module.css'
|
|
5
|
+
|
|
6
|
+
/** Visual state rendered by {@link ConnectionIndicator}. */
|
|
7
|
+
export type ConnectionIndicatorState =
|
|
8
|
+
| 'disconnected'
|
|
9
|
+
| 'connecting'
|
|
10
|
+
| 'recovered'
|
|
11
|
+
|
|
12
|
+
/** Exit-transition length; keep equal to the `.leaving` transition duration in the stylesheet. */
|
|
13
|
+
const EXIT_MS = 150
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Render an inline connection-recovery control. The outage and retry-attempt
|
|
17
|
+
* states are one button whose static label already names the retry action;
|
|
18
|
+
* clicking it requests an immediate reconnect. The indicator animates in on
|
|
19
|
+
* appearance and fades out for {@link EXIT_MS} before unmounting.
|
|
20
|
+
* @param props.state - visible outage, retry-attempt, or recovered state.
|
|
21
|
+
* @param props.disconnectedLabel - localized outage text naming the retry action.
|
|
22
|
+
* @param props.connectingLabel - localized retry text followed by the attempt dots.
|
|
23
|
+
* @param props.recoveredLabel - localized recovery confirmation.
|
|
24
|
+
* @param props.reconnectActionLabel - accessible label for the outage action.
|
|
25
|
+
* @param props.restartActionLabel - accessible label for replacing an active attempt.
|
|
26
|
+
* @param props.onReconnect - request an immediate reconnect attempt.
|
|
27
|
+
* @returns the indicator, or null when no connection feedback is active.
|
|
28
|
+
*/
|
|
29
|
+
export function ConnectionIndicator({
|
|
30
|
+
state,
|
|
31
|
+
disconnectedLabel,
|
|
32
|
+
connectingLabel,
|
|
33
|
+
recoveredLabel,
|
|
34
|
+
reconnectActionLabel,
|
|
35
|
+
restartActionLabel,
|
|
36
|
+
onReconnect,
|
|
37
|
+
}: {
|
|
38
|
+
state: ConnectionIndicatorState | undefined
|
|
39
|
+
disconnectedLabel: string
|
|
40
|
+
connectingLabel: string
|
|
41
|
+
recoveredLabel: string
|
|
42
|
+
reconnectActionLabel: string
|
|
43
|
+
restartActionLabel: string
|
|
44
|
+
onReconnect: () => void
|
|
45
|
+
}) {
|
|
46
|
+
const [rendered, setRendered] = useState(state)
|
|
47
|
+
const leaving = state === undefined && rendered !== undefined
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (state !== undefined) {
|
|
50
|
+
setRendered(state)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
if (rendered === undefined) return
|
|
54
|
+
const timeout = window.setTimeout(() => { setRendered(undefined) }, EXIT_MS)
|
|
55
|
+
return () => { window.clearTimeout(timeout) }
|
|
56
|
+
}, [state, rendered])
|
|
57
|
+
|
|
58
|
+
if (rendered === undefined) return null
|
|
59
|
+
const leavingClass = leaving ? ` ${css.leaving}` : ''
|
|
60
|
+
if (rendered === 'recovered') {
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
className={`${css.indicator} ${css.success}${leavingClass}`}
|
|
64
|
+
role="status"
|
|
65
|
+
aria-label={recoveredLabel}
|
|
66
|
+
>
|
|
67
|
+
<span className={css.icon} aria-hidden="true"><IconCheckOutlineRegular size={14} /></span>
|
|
68
|
+
<span className={css.label}>{recoveredLabel}</span>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const connecting = rendered === 'connecting'
|
|
74
|
+
return (
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
className={`${css.indicator} ${css.warning}${leavingClass}`}
|
|
78
|
+
data-phase={rendered}
|
|
79
|
+
aria-label={connecting ? restartActionLabel : reconnectActionLabel}
|
|
80
|
+
onClick={onReconnect}
|
|
81
|
+
>
|
|
82
|
+
<span className={css.icon} aria-hidden="true">
|
|
83
|
+
{connecting
|
|
84
|
+
? <StateDot state="ongoing" />
|
|
85
|
+
: <IconRefreshOutlineRegular size={14} />}
|
|
86
|
+
</span>
|
|
87
|
+
<span className={css.label}>
|
|
88
|
+
{connecting
|
|
89
|
+
? (
|
|
90
|
+
<>
|
|
91
|
+
{connectingLabel}
|
|
92
|
+
<span className={css.dots} aria-hidden="true">
|
|
93
|
+
<span>.</span>
|
|
94
|
+
<span className={css.secondDot}>.</span>
|
|
95
|
+
<span className={css.thirdDot}>.</span>
|
|
96
|
+
</span>
|
|
97
|
+
</>
|
|
98
|
+
)
|
|
99
|
+
: disconnectedLabel}
|
|
100
|
+
</span>
|
|
101
|
+
</button>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.section {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 12px;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.document {
|
|
9
|
+
min-width: 0;
|
|
10
|
+
/* A long README scrolls inside the section instead of pushing the page's later sections out of reach. */
|
|
11
|
+
max-height: min(560px, 60vh);
|
|
12
|
+
overflow-y: auto;
|
|
13
|
+
/* Horizontal rules separate the document from its neighbors; a full frame would clash with the images' own corners. */
|
|
14
|
+
border-block: 0.5px solid var(--dsw-alias-border-l1);
|
|
15
|
+
/* Keep the scrollbar off the text and the text width independent of overflow. */
|
|
16
|
+
scrollbar-gutter: stable;
|
|
17
|
+
padding: 12px 0;
|
|
18
|
+
overflow-wrap: anywhere;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.document:focus-visible {
|
|
22
|
+
outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
|
|
23
|
+
outline-offset: 3px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.failure {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 10px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.error {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 6px;
|
|
36
|
+
margin: 0;
|
|
37
|
+
font-size: 13px;
|
|
38
|
+
line-height: 20px;
|
|
39
|
+
color: var(--dsw-alias-state-error-primary);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.skeleton {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: 10px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.bar {
|
|
49
|
+
display: block;
|
|
50
|
+
height: 12px;
|
|
51
|
+
border-radius: var(--dsw-radius-xs);
|
|
52
|
+
background: var(--dsw-alias-bg-skeleton);
|
|
53
|
+
animation: dsh-plugin-detail-skeleton 2s cubic-bezier(0.36, 0, 0.64, 1) infinite;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.long { width: min(480px, 90%); }
|
|
57
|
+
.short { width: min(240px, 50%); }
|
|
58
|
+
|
|
59
|
+
@keyframes dsh-plugin-detail-skeleton {
|
|
60
|
+
0% { opacity: 1; }
|
|
61
|
+
40% { opacity: 0.6; }
|
|
62
|
+
80%, 100% { opacity: 1; }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@media (prefers-reduced-motion: reduce) {
|
|
66
|
+
.bar { animation: none; }
|
|
67
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useMemo, type ReactNode } from 'react'
|
|
2
|
+
import { Button } from './Button.tsx'
|
|
3
|
+
import { MarkdownText, type MarkdownLabels, type MarkdownPathImages } from './markdown/MarkdownText.tsx'
|
|
4
|
+
import { StateDot } from './StateDot.tsx'
|
|
5
|
+
import css from './DetailDocument.module.css'
|
|
6
|
+
|
|
7
|
+
/** One read of a long Markdown description, such as a plugin's detail document. */
|
|
8
|
+
export type DetailDocumentState =
|
|
9
|
+
| { readonly status: 'loading' }
|
|
10
|
+
| { readonly status: 'found'; readonly markdown: string }
|
|
11
|
+
| { readonly status: 'none' }
|
|
12
|
+
| { readonly status: 'error'; readonly message: string }
|
|
13
|
+
|
|
14
|
+
/** A read as owners track it: in flight, settled with a document or none, or failed with a localized message. */
|
|
15
|
+
export type DetailDocumentRead =
|
|
16
|
+
| undefined
|
|
17
|
+
| { readonly status: 'loading' }
|
|
18
|
+
| { readonly status: 'ready'; readonly markdown: string | undefined }
|
|
19
|
+
| { readonly status: 'error'; readonly message: string }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The state {@link DetailDocument} shows for an owner's read: loading until it settles, then the document, none, or the
|
|
23
|
+
* failure.
|
|
24
|
+
* @param read - the owner's read; undefined before it starts.
|
|
25
|
+
* @returns the state to show.
|
|
26
|
+
*/
|
|
27
|
+
export function detailDocumentState(read: DetailDocumentRead): DetailDocumentState {
|
|
28
|
+
if (read?.status === 'ready') return read.markdown === undefined ? { status: 'none' } : { status: 'found', markdown: read.markdown }
|
|
29
|
+
return read?.status === 'error' ? read : { status: 'loading' }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Translated strings of a detail document's chrome, as an owner's dictionary supplies them. */
|
|
33
|
+
export interface DetailDocumentCopy {
|
|
34
|
+
readonly title: string
|
|
35
|
+
readonly loading: string
|
|
36
|
+
readonly retry: string
|
|
37
|
+
readonly copy: string
|
|
38
|
+
readonly copied: string
|
|
39
|
+
readonly codeBlock: string
|
|
40
|
+
readonly wrap: string
|
|
41
|
+
readonly unwrap: string
|
|
42
|
+
readonly footnotes: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Assemble reference-stable labels for {@link DetailDocument} from translated strings.
|
|
47
|
+
* @param copy - the translated strings.
|
|
48
|
+
* @returns labels that keep their identity while the strings stay equal.
|
|
49
|
+
*/
|
|
50
|
+
export function useDetailDocumentLabels(copy: DetailDocumentCopy): DetailDocumentLabels {
|
|
51
|
+
const { title, loading, retry, footnotes } = copy
|
|
52
|
+
const { copy: copyLabel, copied: copiedLabel, codeBlock: codeLabel, wrap: wrapLabel, unwrap: unwrapLabel } = copy
|
|
53
|
+
const markdown = useMemo(() => ({ code: { copyLabel, copiedLabel, toolbarLabels: { codeLabel, wrapLabel, unwrapLabel } }, footnotes }),
|
|
54
|
+
[copyLabel, copiedLabel, codeLabel, wrapLabel, unwrapLabel, footnotes])
|
|
55
|
+
return useMemo(() => ({ title, loading, retry, markdown }), [title, loading, retry, markdown])
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Localized chrome of a detail document. */
|
|
59
|
+
export interface DetailDocumentLabels {
|
|
60
|
+
/** Accessible name of the scrollable document region; the section shows no heading of its own. */
|
|
61
|
+
readonly title: string
|
|
62
|
+
/** Accessible name of the loading placeholder. */
|
|
63
|
+
readonly loading: string
|
|
64
|
+
/** Retry button text. */
|
|
65
|
+
readonly retry: string
|
|
66
|
+
readonly markdown: MarkdownLabels
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A section showing a long Markdown description, without a heading of its own: three skeleton lines while it loads, the
|
|
71
|
+
* document once found, or the owner's failure message with a retry. Nothing renders for `none`. A document taller than
|
|
72
|
+
* the section's height limit scrolls inside it, and the scroll region, named by `labels.title`, takes keyboard focus.
|
|
73
|
+
* Raw HTML is omitted, relative links stay text, and only images the owner's `images` resolver accepts, or absolute
|
|
74
|
+
* HTTP(S) images, load.
|
|
75
|
+
* @param props.state - the read to show.
|
|
76
|
+
* @param props.labels - localized region name, placeholder name, retry text, and Markdown chrome; keep `markdown` reference-stable.
|
|
77
|
+
* @param props.images - resolves the document's relative image destinations to displayable URLs.
|
|
78
|
+
* @param props.onRetry - reads the document again after a failure.
|
|
79
|
+
* @returns the section, or null.
|
|
80
|
+
*/
|
|
81
|
+
export function DetailDocument({ state, labels, images, onRetry }: {
|
|
82
|
+
readonly state: DetailDocumentState
|
|
83
|
+
readonly labels: DetailDocumentLabels
|
|
84
|
+
readonly images?: MarkdownPathImages | undefined
|
|
85
|
+
readonly onRetry: () => void
|
|
86
|
+
}): ReactNode {
|
|
87
|
+
if (state.status === 'none') return null
|
|
88
|
+
let body: ReactNode
|
|
89
|
+
switch (state.status) {
|
|
90
|
+
case 'found':
|
|
91
|
+
body = (
|
|
92
|
+
<div className={css.document} role="region" aria-label={labels.title} tabIndex={0}>
|
|
93
|
+
<MarkdownText text={state.markdown} labels={labels.markdown} pathImages={images} omitHtml />
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
break
|
|
97
|
+
case 'error':
|
|
98
|
+
body = (
|
|
99
|
+
<div className={css.failure}>
|
|
100
|
+
<p className={css.error} role="alert"><StateDot state="error" />{state.message}</p>
|
|
101
|
+
<Button variant="outline" size="sm" onClick={onRetry}>{labels.retry}</Button>
|
|
102
|
+
</div>
|
|
103
|
+
)
|
|
104
|
+
break
|
|
105
|
+
case 'loading':
|
|
106
|
+
body = (
|
|
107
|
+
<div className={css.skeleton} role="status" aria-label={labels.loading} aria-busy="true">
|
|
108
|
+
<span className={`${css.bar} ${css.long}`} />
|
|
109
|
+
<span className={`${css.bar} ${css.long}`} />
|
|
110
|
+
<span className={`${css.bar} ${css.short}`} />
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
break
|
|
114
|
+
}
|
|
115
|
+
return (
|
|
116
|
+
<section className={css.section} data-detail-document>
|
|
117
|
+
{body}
|
|
118
|
+
</section>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
.block {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.body {
|
|
6
|
+
display: grid;
|
|
7
|
+
grid-template-columns: minmax(max-content, 1fr);
|
|
8
|
+
padding: 6px 0 20px;
|
|
9
|
+
font: var(--dsw-font-markdown-code-block);
|
|
10
|
+
overflow-x: auto;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.line {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
min-height: 1lh;
|
|
16
|
+
padding: 0 22px;
|
|
17
|
+
white-space: pre;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.block[data-code-wrap='true'] .body {
|
|
21
|
+
grid-template-columns: minmax(0, 1fr);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.block[data-code-wrap='true'] .line {
|
|
25
|
+
white-space: pre-wrap;
|
|
26
|
+
overflow-wrap: anywhere;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.path {
|
|
30
|
+
color: var(--dsw-alias-label-secondary);
|
|
31
|
+
font-weight: 500;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.gap {
|
|
35
|
+
color: var(--dsw-alias-label-tertiary);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.del::before {
|
|
39
|
+
content: '- ';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.del {
|
|
43
|
+
color: var(--dsw-alias-state-error-primary);
|
|
44
|
+
background: var(--dsw-alias-code-diff-deleted);
|
|
45
|
+
box-shadow: inset 3px 0 0 var(--dsw-alias-state-error-primary);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.add::before {
|
|
49
|
+
content: '+ ';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.add {
|
|
53
|
+
color: var(--dsw-alias-state-success-primary);
|
|
54
|
+
background: var(--dsw-alias-code-diff-added);
|
|
55
|
+
box-shadow: inset 3px 0 0 var(--dsw-alias-state-success-primary);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.context {
|
|
59
|
+
color: var(--dsw-alias-label-secondary);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.context::before {
|
|
63
|
+
content: ' ';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.expand {
|
|
67
|
+
display: block;
|
|
68
|
+
width: 100%;
|
|
69
|
+
padding: 0 22px;
|
|
70
|
+
border: none;
|
|
71
|
+
background: transparent;
|
|
72
|
+
color: var(--dsw-alias-label-tertiary);
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
font: inherit;
|
|
75
|
+
text-align: left;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@media (hover: hover) {
|
|
79
|
+
.expand:hover {
|
|
80
|
+
color: var(--dsw-alias-label-secondary);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import { structuredPatch } from 'diff'
|
|
4
|
+
import { FoldToggle } from './FoldToggle.tsx'
|
|
5
|
+
import { writeClipboard } from './clipboard.ts'
|
|
6
|
+
import { CodeToolbar, type CodeToolbarLabels } from './CodeToolbar.tsx'
|
|
7
|
+
import { languageForPath } from './code-highlighting.ts'
|
|
8
|
+
import cardCss from './CodeCard.module.css'
|
|
9
|
+
import css from './DiffBlock.module.css'
|
|
10
|
+
|
|
11
|
+
/** Output lines shown before the height cap collapses the middle. */
|
|
12
|
+
export const DEFAULT_DIFF_MAX_LINES = 16
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One file change in the form {@link DiffBlock} renders. It is declared here
|
|
16
|
+
* so this primitive stays independent of the tool contract.
|
|
17
|
+
*/
|
|
18
|
+
export interface DiffHunk {
|
|
19
|
+
/** The changed file's path, drawn verbatim as the hunk's header (the tool's model-facing path). */
|
|
20
|
+
path: string
|
|
21
|
+
/** Prior content including context, or `null` when no prior content is available. */
|
|
22
|
+
oldText: string | null
|
|
23
|
+
/** Content after the change, including any shared context. */
|
|
24
|
+
newText: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DiffBlockProps {
|
|
28
|
+
/** One entry per applied hunk, in file order; empty renders nothing. */
|
|
29
|
+
diffs: DiffHunk[]
|
|
30
|
+
/** Localized chrome supplied by the owning render site. */
|
|
31
|
+
labels: DiffBlockLabels
|
|
32
|
+
/** Height cap in body lines before the middle collapses (default {@link DEFAULT_DIFF_MAX_LINES}). */
|
|
33
|
+
maxLines?: number | undefined
|
|
34
|
+
/** Extra class merged onto the wrapper (callers position; this component draws). */
|
|
35
|
+
className?: string | undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Localized chrome for {@link DiffBlock}. */
|
|
39
|
+
export interface DiffBlockLabels extends CodeToolbarLabels {
|
|
40
|
+
copy: string
|
|
41
|
+
copied: string
|
|
42
|
+
collapseAria: string
|
|
43
|
+
expandAria: (hidden: number) => string
|
|
44
|
+
collapse: string
|
|
45
|
+
expand: (hidden: number) => string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A single rendered body line and its role, so the height cap slices a flat list. */
|
|
49
|
+
interface DiffRow {
|
|
50
|
+
kind: 'path' | 'del' | 'add' | 'context' | 'gap'
|
|
51
|
+
text: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Local exhaustiveness helper — this package does not depend on `dsh-llm`. */
|
|
55
|
+
/* v8 ignore next 3 -- closed-union backstop; only reached if a row kind is forged */
|
|
56
|
+
function assertNever(value: never): never {
|
|
57
|
+
throw new Error(`unreachable diff row kind: ${String(value)}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The dim class per row kind (path/gap chrome vs the diff's own +/- colors). */
|
|
61
|
+
const ROW_CLASS: Record<DiffRow['kind'], string | undefined> = {
|
|
62
|
+
path: css.path,
|
|
63
|
+
del: css.del,
|
|
64
|
+
add: css.add,
|
|
65
|
+
context: css.context,
|
|
66
|
+
gap: css.gap,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Bound synchronous edit-graph search; one replacement consumes two edits. */
|
|
70
|
+
const MAX_DIFF_EDIT_LENGTH = 256
|
|
71
|
+
|
|
72
|
+
/** Derive exact local patches or a whole-fragment replacement when search exceeds the limit. */
|
|
73
|
+
function localHunks(diff: DiffHunk) {
|
|
74
|
+
const oldLines = contentLines(diff.oldText ?? '')
|
|
75
|
+
const newLines = contentLines(diff.newText)
|
|
76
|
+
const normalize = (lines: string[]): string => lines.map(line => `${line}\n`).join('')
|
|
77
|
+
return structuredPatch('', '', normalize(oldLines), normalize(newLines),
|
|
78
|
+
undefined, undefined, { context: 3, maxEditLength: MAX_DIFF_EDIT_LENGTH })?.hunks
|
|
79
|
+
?? [{ lines: [...oldLines.map(line => `-${line}`), ...newLines.map(line => `+${line}`)] }]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Count displayed additions and deletions. Exact patches exclude shared context;
|
|
84
|
+
* comparisons exceeding the edit limit count both complete fragments as replaced.
|
|
85
|
+
* Text follows {@link contentLines}'s terminator rule.
|
|
86
|
+
* @param diffs - the hunks to count.
|
|
87
|
+
* @returns the +/- totals for tool summaries.
|
|
88
|
+
*/
|
|
89
|
+
export function diffTotals(diffs: DiffHunk[]): { added: number; removed: number } {
|
|
90
|
+
let added = 0
|
|
91
|
+
let removed = 0
|
|
92
|
+
for (const diff of diffs) {
|
|
93
|
+
for (const hunk of localHunks(diff)) {
|
|
94
|
+
for (const line of hunk.lines) {
|
|
95
|
+
if (line.startsWith('+')) added++
|
|
96
|
+
if (line.startsWith('-')) removed++
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { added, removed }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Flatten local patches into rows.
|
|
105
|
+
* A path header opens each new file. A `⋯` gap separates consecutive same-file
|
|
106
|
+
* fragments and distant patches within a fragment.
|
|
107
|
+
* @param diffs - the hunks to render.
|
|
108
|
+
* @returns the body rows.
|
|
109
|
+
*/
|
|
110
|
+
function buildRows(diffs: DiffHunk[]): DiffRow[] {
|
|
111
|
+
const rows: DiffRow[] = []
|
|
112
|
+
let prevPath: string | undefined
|
|
113
|
+
for (const diff of diffs) {
|
|
114
|
+
if (diff.path !== prevPath) rows.push({ kind: 'path', text: diff.path })
|
|
115
|
+
else rows.push({ kind: 'gap', text: '⋯' })
|
|
116
|
+
prevPath = diff.path
|
|
117
|
+
for (const [index, hunk] of localHunks(diff).entries()) {
|
|
118
|
+
if (index > 0) rows.push({ kind: 'gap', text: '⋯' })
|
|
119
|
+
for (const line of hunk.lines) {
|
|
120
|
+
const kind = line.startsWith('-') ? 'del' : line.startsWith('+') ? 'add' : 'context'
|
|
121
|
+
rows.push({ kind, text: line.slice(1) })
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return rows
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Split a side's text into its content lines. Empty text is zero lines (a full
|
|
130
|
+
* deletion's `newText` or a create's absent `oldText` side draws nothing), and a
|
|
131
|
+
* single trailing newline is a line terminator rather than an extra empty line —
|
|
132
|
+
* the same terminator rule TerminalBlock applies to command output. An interior
|
|
133
|
+
* blank line (a genuine `\n\n`) survives.
|
|
134
|
+
* @param text - the removed or added side's text.
|
|
135
|
+
* @returns the content lines, without the terminating newline.
|
|
136
|
+
*/
|
|
137
|
+
function contentLines(text: string): string[] {
|
|
138
|
+
if (text === '') return []
|
|
139
|
+
const body = text.endsWith('\n') ? text.slice(0, -1) : text
|
|
140
|
+
return body.split('\n')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Copy the full local diff, including folded rows: removed/added lines have
|
|
145
|
+
* `- `/`+ ` prefixes, context has two spaces, and paths and gaps stay verbatim.
|
|
146
|
+
* @param rows - the flattened body rows.
|
|
147
|
+
* @returns the diff as plain text.
|
|
148
|
+
*/
|
|
149
|
+
function copyText(rows: DiffRow[]): string {
|
|
150
|
+
return rows.map((row) => {
|
|
151
|
+
switch (row.kind) {
|
|
152
|
+
case 'del': return `- ${row.text}`
|
|
153
|
+
case 'add': return `+ ${row.text}`
|
|
154
|
+
case 'context': return ` ${row.text}`
|
|
155
|
+
case 'path': return row.text
|
|
156
|
+
case 'gap': return row.text
|
|
157
|
+
/* v8 ignore next -- closed-union backstop; only reached if a row kind is forged */
|
|
158
|
+
default: return assertNever(row.kind)
|
|
159
|
+
}
|
|
160
|
+
}).join('\n')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Render a file mutation as an inline diff surface.
|
|
165
|
+
* @param props - see {@link DiffBlockProps}.
|
|
166
|
+
* @returns the diff block element.
|
|
167
|
+
*/
|
|
168
|
+
export function DiffBlock({ diffs, labels, maxLines = DEFAULT_DIFF_MAX_LINES, className }: DiffBlockProps) {
|
|
169
|
+
const rows = useMemo(() => buildRows(diffs), [diffs])
|
|
170
|
+
const [expanded, setExpanded] = useState(false)
|
|
171
|
+
const [copied, setCopied] = useState(false)
|
|
172
|
+
const [wrapped, setWrapped] = useState(false)
|
|
173
|
+
const firstLanguage = diffs[0] === undefined ? undefined : languageForPath(diffs[0].path)
|
|
174
|
+
const language = diffs.every(diff => languageForPath(diff.path) === firstLanguage) ? firstLanguage : undefined
|
|
175
|
+
|
|
176
|
+
const onCopy = useCallback(() => {
|
|
177
|
+
if (copied) return
|
|
178
|
+
void writeClipboard(copyText(rows)).then((ok) => {
|
|
179
|
+
if (!ok) return
|
|
180
|
+
setCopied(true)
|
|
181
|
+
window.setTimeout(() => { setCopied(false) }, 1000)
|
|
182
|
+
})
|
|
183
|
+
}, [copied, rows])
|
|
184
|
+
|
|
185
|
+
const onToggle = useCallback(() => { setExpanded(value => !value) }, [])
|
|
186
|
+
|
|
187
|
+
if (rows.length === 0) return null
|
|
188
|
+
|
|
189
|
+
const hidden = rows.length - maxLines
|
|
190
|
+
const capped = hidden > 0 && !expanded
|
|
191
|
+
// Same split arithmetic as TerminalBlock and the TUI transcript's collapsed
|
|
192
|
+
// card, so a body's head and tail slices agree across the front ends.
|
|
193
|
+
const headLines = Math.ceil(maxLines / 2)
|
|
194
|
+
const tailLines = maxLines - headLines
|
|
195
|
+
const head = capped ? rows.slice(0, headLines) : rows
|
|
196
|
+
const tail = capped ? rows.slice(rows.length - tailLines) : []
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div className={clsx(cardCss.card, css.block, className)} data-diff="" data-code-wrap={wrapped}>
|
|
200
|
+
<CodeToolbar lang={language} labels={labels} copyLabel={labels.copy} copiedLabel={labels.copied}
|
|
201
|
+
copied={copied} wrapped={wrapped} onCopy={onCopy} onWrap={() => { setWrapped(value => !value) }} />
|
|
202
|
+
<div className={css.body}>
|
|
203
|
+
{head.map((row, index) => (
|
|
204
|
+
<div key={index} className={clsx(css.line, ROW_CLASS[row.kind])}>{row.text}</div>
|
|
205
|
+
))}
|
|
206
|
+
{hidden > 0 && (
|
|
207
|
+
<FoldToggle
|
|
208
|
+
className={css.expand}
|
|
209
|
+
expanded={expanded}
|
|
210
|
+
hidden={hidden}
|
|
211
|
+
labels={labels}
|
|
212
|
+
onToggle={onToggle}
|
|
213
|
+
/>
|
|
214
|
+
)}
|
|
215
|
+
{tail.map((row, index) => (
|
|
216
|
+
<div key={index} className={clsx(css.line, ROW_CLASS[row.kind])}>{row.text}</div>
|
|
217
|
+
))}
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
)
|
|
221
|
+
}
|