@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.1 → 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 +9 -6
- 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,72 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
+
import type { RefObject } from 'react'
|
|
3
|
+
import { supportsHighlighting } from './highlight.ts'
|
|
4
|
+
|
|
5
|
+
const noop = (): void => {}
|
|
6
|
+
|
|
7
|
+
/** One document-wide observer; activated elements leave it permanently. */
|
|
8
|
+
class HighlightViewport {
|
|
9
|
+
private observer: IntersectionObserver | undefined
|
|
10
|
+
private readonly activators = new Map<Element, () => void>()
|
|
11
|
+
|
|
12
|
+
observe(element: Element, activate: () => void): () => void {
|
|
13
|
+
if (typeof IntersectionObserver === 'undefined') {
|
|
14
|
+
activate()
|
|
15
|
+
return noop
|
|
16
|
+
}
|
|
17
|
+
this.observer ??= new IntersectionObserver((entries) => {
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (!entry.isIntersecting) continue
|
|
20
|
+
const current = this.activators.get(entry.target)
|
|
21
|
+
/* v8 ignore next -- the observer reports only elements still registered with it. */
|
|
22
|
+
if (current === undefined) continue
|
|
23
|
+
this.activators.delete(entry.target)
|
|
24
|
+
this.observer?.unobserve(entry.target)
|
|
25
|
+
current()
|
|
26
|
+
}
|
|
27
|
+
this.releaseEmptyObserver()
|
|
28
|
+
})
|
|
29
|
+
this.activators.set(element, activate)
|
|
30
|
+
this.observer.observe(element)
|
|
31
|
+
return () => {
|
|
32
|
+
this.activators.delete(element)
|
|
33
|
+
this.observer?.unobserve(element)
|
|
34
|
+
this.releaseEmptyObserver()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private releaseEmptyObserver(): void {
|
|
39
|
+
if (this.activators.size > 0) return
|
|
40
|
+
this.observer?.disconnect()
|
|
41
|
+
this.observer = undefined
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const highlightViewport = new HighlightViewport()
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Activate one supported code surface when it first intersects the viewport.
|
|
49
|
+
* Activation lasts for the component lifetime; browsers without
|
|
50
|
+
* IntersectionObserver activate immediately.
|
|
51
|
+
* @param target - Code surface whose plain rendering reserves its geometry.
|
|
52
|
+
* @param lang - Optional language hint.
|
|
53
|
+
* @returns Whether this component may build highlighted output.
|
|
54
|
+
*/
|
|
55
|
+
export function useViewportHighlighting(
|
|
56
|
+
target: RefObject<Element>,
|
|
57
|
+
lang: string | undefined,
|
|
58
|
+
): boolean {
|
|
59
|
+
const supported = supportsHighlighting(lang)
|
|
60
|
+
const [activated, setActivated] = useState(false)
|
|
61
|
+
const activate = useCallback(() => { setActivated(true) }, [])
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (activated || !supported) return
|
|
65
|
+
const element = target.current
|
|
66
|
+
/* v8 ignore next -- React attaches the host ref before running effects. */
|
|
67
|
+
if (element === null) return
|
|
68
|
+
return highlightViewport.observe(element, activate)
|
|
69
|
+
}, [activate, activated, supported, target])
|
|
70
|
+
|
|
71
|
+
return activated && supported
|
|
72
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Keep backslash separators in Markdown destinations written as Windows paths. */
|
|
2
|
+
import type { Definition, Image, Link } from 'mdast'
|
|
3
|
+
import type { CompileContext, Extension, Token } from 'mdast-util-from-markdown'
|
|
4
|
+
import { decodeString } from 'micromark-util-decode-string'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A raw destination is a Windows path when it has a backslash and no URL
|
|
8
|
+
* scheme, and either has no `/` or has a backslash before a letter or digit,
|
|
9
|
+
* which CommonMark cannot read as an escape. A drive letter is not a scheme.
|
|
10
|
+
*/
|
|
11
|
+
function isWindowsPath(raw: string): boolean {
|
|
12
|
+
return raw.includes('\\') && !/^[a-z][a-z\d+.-]+:/iu.test(raw)
|
|
13
|
+
&& (!raw.includes('/') || /\\[\p{L}\p{N}]/u.test(raw))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function exitDestination(this: CompileContext, token: Token): void {
|
|
17
|
+
const parsed = this.resume()
|
|
18
|
+
const raw = this.sliceSerialize(token)
|
|
19
|
+
const node = this.stack.at(-1) as Link | Image | Definition
|
|
20
|
+
// Doubling each backslash makes every one literal; character references still decode.
|
|
21
|
+
node.url = isWindowsPath(raw) ? decodeString(raw.replaceAll('\\', '\\\\')) : parsed
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* CommonMark reads `\.` or `\_` in a destination as an escaped character, so
|
|
26
|
+
* `D:\repo\.github` would parse as `D:\repo.github`. For a destination that
|
|
27
|
+
* is a Windows path, this `fromMarkdown` extension keeps every backslash
|
|
28
|
+
* literally, including one before punctuation such as `\(`, while character
|
|
29
|
+
* references such as `&` still decode; other destinations parse unchanged.
|
|
30
|
+
* @returns The mdast extension.
|
|
31
|
+
*/
|
|
32
|
+
export function windowsPathDestinations(): Extension {
|
|
33
|
+
return { exit: { resourceDestinationString: exitDestination, definitionDestinationString: exitDestination } }
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Choose between a side child card and a single-panel child page from layout-viewport space. */
|
|
2
|
+
|
|
3
|
+
/** Gap between the parent card and a side child card, matching `.submenu` in Menu.module.css. */
|
|
4
|
+
export const SUBMENU_GAP = 4
|
|
5
|
+
/** Layout-viewport inset shared with every portalled Menu card. */
|
|
6
|
+
export const SUBMENU_MARGIN = 12
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Report whether neither side of the parent card can hold the child card.
|
|
10
|
+
* CSS anchors place the side card and flip it; this decision only selects the page layout.
|
|
11
|
+
* @param parent - Parent card rectangle in client coordinates.
|
|
12
|
+
* @param width - Natural child card width.
|
|
13
|
+
* @param viewportWidth - Layout viewport width.
|
|
14
|
+
* @returns true when the child must replace the parent page.
|
|
15
|
+
*/
|
|
16
|
+
export function submenuNeedsPage(parent: DOMRect, width: number, viewportWidth: number): boolean {
|
|
17
|
+
const right = parent.right + SUBMENU_GAP + width <= viewportWidth - SUBMENU_MARGIN
|
|
18
|
+
const left = parent.left - SUBMENU_GAP - width >= SUBMENU_MARGIN
|
|
19
|
+
return !right && !left
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Shared viewport inset for overlays, derived from the desktop frame's reserved top strip. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the top margin an overlay keeps from the viewport edge.
|
|
5
|
+
* @param min - the overlay's own viewport margin in px, used as the floor.
|
|
6
|
+
* @param anchor - the overlay's anchor rect in viewport coordinates. While the anchor's top edge is inside the
|
|
7
|
+
* viewport, the margin never exceeds `anchor.bottom + gap`, so an overlay opened from a control inside the top strip
|
|
8
|
+
* stays next to it.
|
|
9
|
+
* @param gap - the distance the overlay keeps below `anchor`.
|
|
10
|
+
* @returns the frame clearance plus 20px (20px in fullscreen), capped by a visible `anchor`, but never below `min`.
|
|
11
|
+
*/
|
|
12
|
+
export function overlayTopMargin(min: number, anchor?: { readonly top: number; readonly bottom: number }, gap = 0): number {
|
|
13
|
+
const root = document.documentElement
|
|
14
|
+
const clearance = Number.parseFloat(getComputedStyle(root).getPropertyValue('--dsh-frame-top-clearance'))
|
|
15
|
+
if (Number.isNaN(clearance)) return min
|
|
16
|
+
const cap = anchor !== undefined && anchor.top >= 0 ? anchor.bottom + gap : Number.POSITIVE_INFINITY
|
|
17
|
+
return Math.max(min, Math.min((root.hasAttribute('data-fullscreen') ? 0 : clearance) + 20, cap))
|
|
18
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-palette plugin artwork for the plugin management surfaces. Unlike the
|
|
3
|
+
* ic_ds_* set these glyphs carry their own brand colors and gradients instead
|
|
4
|
+
* of riding currentColor; all draw on a 36×36 viewBox and take {size, className}.
|
|
5
|
+
*/
|
|
6
|
+
import { useId } from 'react'
|
|
7
|
+
import type { IconProps } from './icons/props.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A per-instance SVG def id prefix: the artwork repeats across cards and rows,
|
|
11
|
+
* and duplicate document ids would make every `url(#…)` resolve to the first instance.
|
|
12
|
+
*/
|
|
13
|
+
const useArtworkId = (): string => `dsh_plugin_art_${useId().replaceAll(':', '')}`
|
|
14
|
+
|
|
15
|
+
/** Light-blue terminal artwork shared by plugin cards and sidebar guide entries. */
|
|
16
|
+
export const PluginArtworkTerminal = ({ size = 36, className }: IconProps) => (
|
|
17
|
+
<svg width={size} height={size} className={className} viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
18
|
+
<path d="M10 11L16.606 17.606C16.6841 17.6841 16.6841 17.8107 16.606 17.8888L10 24.4948" stroke="#679EFE" strokeWidth="3.5" />
|
|
19
|
+
<path d="M20.1211 24.4946H26.8685" stroke="#679EFE" strokeWidth="3.5" />
|
|
20
|
+
</svg>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
/** Agent-loop plugin artwork (four leaves circling a center). */
|
|
24
|
+
export const PluginArtworkLoop = ({ size = 36, className }: IconProps) => {
|
|
25
|
+
const uid = useArtworkId()
|
|
26
|
+
return (
|
|
27
|
+
<svg width={size} height={size} className={className} viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
28
|
+
<path d="M18.0486 28.4901C12.0858 28.4901 7.25195 23.6562 7.25195 17.6934C13.2148 17.6934 18.0486 22.5272 18.0486 28.4901Z" fill="#A797FC" />
|
|
29
|
+
<path d="M18.0486 6.89667C12.0858 6.89667 7.25195 11.7305 7.25195 17.6934C13.2148 17.6934 18.0486 12.8595 18.0486 6.89667Z" fill={`url(#${uid}a)`} />
|
|
30
|
+
<path d="M18.0485 28.4901C24.0114 28.4901 28.8452 23.6562 28.8452 17.6934C22.8824 17.6934 18.0485 22.5272 18.0485 28.4901Z" fill="#4561EE" />
|
|
31
|
+
<path d="M18.0485 6.89667C24.0114 6.89667 28.8452 11.7305 28.8452 17.6934C22.8824 17.6934 18.0485 12.8595 18.0485 6.89667Z" fill="#658EFF" />
|
|
32
|
+
<defs>
|
|
33
|
+
<linearGradient id={`${uid}a`} x1="16.7911" y1="16.1655" x2="8.98192" y2="8.74289" gradientUnits="userSpaceOnUse">
|
|
34
|
+
<stop stopColor="#A23AE7" />
|
|
35
|
+
<stop offset="1" stopColor="#E2E2E2" />
|
|
36
|
+
</linearGradient>
|
|
37
|
+
</defs>
|
|
38
|
+
</svg>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Subagent plugin artwork (two stacked rounded squares); also marks every row inside a bundle. */
|
|
43
|
+
export const PluginArtworkSubagent = ({ size = 36, className }: IconProps) => {
|
|
44
|
+
const uid = useArtworkId()
|
|
45
|
+
return (
|
|
46
|
+
<svg width={size} height={size} className={className} viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
47
|
+
<rect x="14.9893" y="15.1877" width="12.2365" height="12.2365" rx="2" fill={`url(#${uid}a)`} fillOpacity="0.8" />
|
|
48
|
+
<rect x="8.87109" y="9.0697" width="12.2365" height="12.2365" rx="2" fill={`url(#${uid}b)`} fillOpacity="0.8" />
|
|
49
|
+
<defs>
|
|
50
|
+
<linearGradient id={`${uid}a`} x1="21.1075" y1="15.1877" x2="21.1075" y2="27.4243" gradientUnits="userSpaceOnUse">
|
|
51
|
+
<stop stopColor="#45E7A4" />
|
|
52
|
+
<stop offset="1" stopColor="#05909D" />
|
|
53
|
+
</linearGradient>
|
|
54
|
+
<linearGradient id={`${uid}b`} x1="14.9894" y1="9.0697" x2="14.9894" y2="21.3063" gradientUnits="userSpaceOnUse">
|
|
55
|
+
<stop stopColor="#69B9FF" />
|
|
56
|
+
<stop offset="1" stopColor="#324DE2" />
|
|
57
|
+
</linearGradient>
|
|
58
|
+
</defs>
|
|
59
|
+
</svg>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Web-search plugin artwork (conic-gradient ring and handle). SVG has no
|
|
65
|
+
* native conic gradient, so the ring clips an HTML div painted with CSS
|
|
66
|
+
* `conic-gradient` — the same emulation Figma exports; it renders inline in
|
|
67
|
+
* the browser UI but would stay empty in an `<img>` or mask context.
|
|
68
|
+
*/
|
|
69
|
+
export const PluginArtworkSearch = ({ size = 36, className }: IconProps) => {
|
|
70
|
+
const uid = useArtworkId()
|
|
71
|
+
return (
|
|
72
|
+
<svg width={size} height={size} className={className} viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
73
|
+
<path d="M26.5362 26.9865L22.3813 22.8317" stroke="#658EFF" strokeWidth="3" />
|
|
74
|
+
<g clipPath={`url(#${uid}ring)`}>
|
|
75
|
+
<g transform="matrix(0.0119394 -0.00173904 0.00173904 0.0119394 15.7661 16.2159)">
|
|
76
|
+
<foreignObject x="-958.94" y="-958.94" width="1917.88" height="1917.88">
|
|
77
|
+
<div
|
|
78
|
+
style={{
|
|
79
|
+
background: 'conic-gradient(from 90deg, rgb(65, 225, 172) 0deg, rgb(101, 142, 255) 62.0619deg, rgb(65, 225, 172) 360deg)',
|
|
80
|
+
height: '100%',
|
|
81
|
+
width: '100%',
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</foreignObject>
|
|
85
|
+
</g>
|
|
86
|
+
</g>
|
|
87
|
+
<defs>
|
|
88
|
+
<clipPath id={`${uid}ring`}>
|
|
89
|
+
<path d="M21.9717 16.2159H19.9717C19.9717 18.5386 18.0888 20.4215 15.7661 20.4215V22.4215V24.4215C20.2979 24.4215 23.9717 20.7478 23.9717 16.2159H21.9717ZM15.7661 22.4215V20.4215C13.4434 20.4215 11.5605 18.5386 11.5605 16.2159H9.56055H7.56055C7.56055 20.7478 11.2343 24.4215 15.7661 24.4215V22.4215ZM9.56055 16.2159H11.5605C11.5605 13.8933 13.4434 12.0104 15.7661 12.0104V10.0104V8.01038C11.2343 8.01038 7.56055 11.6841 7.56055 16.2159H9.56055ZM15.7661 10.0104V12.0104C18.0888 12.0104 19.9717 13.8933 19.9717 16.2159H21.9717H23.9717C23.9717 11.6841 20.2979 8.01038 15.7661 8.01038V10.0104Z" />
|
|
90
|
+
</clipPath>
|
|
91
|
+
</defs>
|
|
92
|
+
</svg>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Default plugin artwork for plugins without one of their own (connector blocks and a node). */
|
|
97
|
+
export const PluginArtworkDefault = ({ size = 36, className }: IconProps) => {
|
|
98
|
+
const uid = useArtworkId()
|
|
99
|
+
return (
|
|
100
|
+
<svg width={size} height={size} className={className} viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
101
|
+
<path d="M24.6294 8.63696C26.2862 8.63705 27.6294 9.98016 27.6294 11.637V12.7825C27.6292 14.4391 26.2861 15.7824 24.6294 15.7825H23.4839C22.6519 15.7825 21.5454 16.3459 21.5454 17.1778V18.1573C21.5454 18.7757 22.216 19.1966 22.8345 19.1965H24.6294C26.2861 19.1965 27.6292 20.5398 27.6294 22.1965V23.9924C27.6292 25.6491 26.2861 26.9924 24.6294 26.9924H22.8345C21.1778 26.9924 19.8347 25.649 19.8345 23.9924V22.1965C19.8345 21.7148 19.4957 21.2327 19.014 21.2327H16.4792C15.7975 21.2327 15.3374 22.0061 15.3374 22.6877V23.8333C15.3373 25.49 13.9942 26.8333 12.3374 26.8333H11.1919C9.53509 26.8333 8.19198 25.49 8.19189 23.8333V22.6877C8.19189 21.0309 9.53504 19.6877 11.1919 19.6877H12.3374C13.1964 19.6877 14.3999 19.0959 14.3999 18.2369V16.0185C14.3999 14.9518 15.2646 14.0872 16.3312 14.0872H19.435C20.0596 14.0872 20.484 13.4071 20.4839 12.7825V11.637C20.4839 9.98011 21.827 8.63696 23.4839 8.63696H24.6294ZM13.4116 11.2468C13.4116 12.6882 12.2431 13.8567 10.8018 13.8567C9.36037 13.8567 8.19189 12.6882 8.19189 11.2468C8.19189 9.80544 9.36037 8.63696 10.8018 8.63696C12.2431 8.63696 13.4116 9.80544 13.4116 11.2468Z" fill={`url(#${uid}a)`} />
|
|
102
|
+
<defs>
|
|
103
|
+
<linearGradient id={`${uid}a`} x1="15.1481" y1="9.94188" x2="15.1481" y2="13.6375" gradientUnits="userSpaceOnUse">
|
|
104
|
+
<stop stopColor="#54ECE7" />
|
|
105
|
+
<stop offset="1" stopColor="#658EFF" />
|
|
106
|
+
</linearGradient>
|
|
107
|
+
</defs>
|
|
108
|
+
</svg>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Grace before a pointer-dismissed popup closes. Covers the anchor->popup gap
|
|
5
|
+
* (8px for HoverCard, 4px for Menu) at a hand's travel speed without leaving a
|
|
6
|
+
* popup lingering once the pointer has genuinely moved on.
|
|
7
|
+
*/
|
|
8
|
+
export const POINTER_GRACE_MS = 200
|
|
9
|
+
|
|
10
|
+
/** Cancelable delayed close for a pointer-dismissed popup. */
|
|
11
|
+
export interface PointerGrace {
|
|
12
|
+
/** Schedule the close {@link POINTER_GRACE_MS} from now, replacing any pending one. */
|
|
13
|
+
arm: () => void
|
|
14
|
+
/** Abort a pending close (the pointer came back). */
|
|
15
|
+
cancel: () => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Delay a pointer-dismissed popup's close so the pointer can cross the gap
|
|
20
|
+
* between anchor and popup. A pending close is dropped on unmount.
|
|
21
|
+
* @param close - runs when the grace elapses with no re-entry; read at fire
|
|
22
|
+
* time, so callers may pass a fresh closure each render.
|
|
23
|
+
* @returns the {@link PointerGrace} handle.
|
|
24
|
+
*/
|
|
25
|
+
export function usePointerGrace(close: () => void): PointerGrace {
|
|
26
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
27
|
+
const closeRef = useRef(close)
|
|
28
|
+
closeRef.current = close
|
|
29
|
+
|
|
30
|
+
const cancel = useCallback(() => {
|
|
31
|
+
if (timerRef.current === null) return
|
|
32
|
+
clearTimeout(timerRef.current)
|
|
33
|
+
timerRef.current = null
|
|
34
|
+
}, [])
|
|
35
|
+
|
|
36
|
+
const arm = useCallback(() => {
|
|
37
|
+
cancel()
|
|
38
|
+
timerRef.current = setTimeout(() => {
|
|
39
|
+
timerRef.current = null
|
|
40
|
+
closeRef.current()
|
|
41
|
+
}, POINTER_GRACE_MS)
|
|
42
|
+
}, [cancel])
|
|
43
|
+
|
|
44
|
+
useEffect(() => cancel, [cancel])
|
|
45
|
+
|
|
46
|
+
return { arm, cancel }
|
|
47
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared ranking for `/` menu candidates: the query must be a
|
|
3
|
+
* case-insensitive ordered subsequence of the candidate name or, when the
|
|
4
|
+
* candidate carries one, of its display label (a localized title). Prefix
|
|
5
|
+
* hits rank first, then the strongest alignment score over either key, then
|
|
6
|
+
* the source order of the input. Decision record:
|
|
7
|
+
* .agents/notes/archived/feature/2026-08-04-web-slash-command-fuzzy-discovery.md
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** One match with its stable source position. */
|
|
11
|
+
interface Ranked<T> {
|
|
12
|
+
readonly item: T
|
|
13
|
+
readonly index: number
|
|
14
|
+
readonly prefix: boolean
|
|
15
|
+
readonly score: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Extra weight for name starts and separator boundaries. */
|
|
19
|
+
function boundaryBonus(name: string, index: number): number {
|
|
20
|
+
return index === 0 || name.charAt(index - 1) === '-' || name.charAt(index - 1) === '_' ? 8 : 0
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Score the strongest ordered-subsequence alignment in O(name × query).
|
|
25
|
+
* Boundary and adjacent matches earn weight; skipped and leading characters
|
|
26
|
+
* cost weight. Undefined when the query is not a subsequence of the name.
|
|
27
|
+
*/
|
|
28
|
+
function alignmentScore(name: string, query: string): number | undefined {
|
|
29
|
+
if (query.length > name.length) return undefined
|
|
30
|
+
const noMatch = Number.NEGATIVE_INFINITY
|
|
31
|
+
let previous = Array<number>(name.length).fill(noMatch)
|
|
32
|
+
for (let index = 0; index < name.length; index++) {
|
|
33
|
+
if (name.charAt(index) === query.charAt(0)) previous[index] = 1 + boundaryBonus(name, index) - index
|
|
34
|
+
}
|
|
35
|
+
for (let queryIndex = 1; queryIndex < query.length; queryIndex++) {
|
|
36
|
+
const current = Array<number>(name.length).fill(noMatch)
|
|
37
|
+
// Sweep the previous row once: `left` is its score one character back
|
|
38
|
+
// (the adjacent continuation), `leftLeft` two back (the earliest gapped one).
|
|
39
|
+
let left = noMatch
|
|
40
|
+
let leftLeft = noMatch
|
|
41
|
+
let bestGapped = noMatch
|
|
42
|
+
for (const [index, prior] of previous.entries()) {
|
|
43
|
+
if (leftLeft !== noMatch) bestGapped = Math.max(bestGapped, leftLeft + index - 2)
|
|
44
|
+
if (name.charAt(index) === query.charAt(queryIndex)) {
|
|
45
|
+
const bonus = 1 + boundaryBonus(name, index)
|
|
46
|
+
let score = noMatch
|
|
47
|
+
if (left !== noMatch) score = left + bonus + 4
|
|
48
|
+
if (bestGapped !== noMatch) score = Math.max(score, bestGapped + bonus + 1 - index)
|
|
49
|
+
current[index] = score
|
|
50
|
+
}
|
|
51
|
+
leftLeft = left
|
|
52
|
+
left = prior
|
|
53
|
+
}
|
|
54
|
+
previous = current
|
|
55
|
+
}
|
|
56
|
+
let best = noMatch
|
|
57
|
+
for (const score of previous) best = Math.max(best, score)
|
|
58
|
+
return best === noMatch ? undefined : best
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Rank named items by a menu query.
|
|
63
|
+
* @param items - candidates in source order (a host catalog, then client
|
|
64
|
+
* contributions); an item's optional `label` is a second search key beside
|
|
65
|
+
* its name.
|
|
66
|
+
* @param rawQuery - the text typed after the trigger, matched case-insensitively.
|
|
67
|
+
* @returns the matching items: prefix hits first, then by alignment score,
|
|
68
|
+
* then in source order. The input list itself for an empty query.
|
|
69
|
+
*/
|
|
70
|
+
export function rankByName<T extends { readonly name: string; readonly label?: string }>(
|
|
71
|
+
items: readonly T[],
|
|
72
|
+
rawQuery: string,
|
|
73
|
+
): readonly T[] {
|
|
74
|
+
const query = rawQuery.toLowerCase()
|
|
75
|
+
if (query === '') return items
|
|
76
|
+
const ranked: Ranked<T>[] = []
|
|
77
|
+
items.forEach((item, index) => {
|
|
78
|
+
const keys = item.label === undefined ? [item.name] : [item.name, item.label]
|
|
79
|
+
let prefix = false
|
|
80
|
+
let score: number | undefined
|
|
81
|
+
for (const key of keys) {
|
|
82
|
+
const lower = key.toLowerCase()
|
|
83
|
+
const keyScore = alignmentScore(lower, query)
|
|
84
|
+
if (keyScore === undefined) continue
|
|
85
|
+
prefix ||= lower.startsWith(query)
|
|
86
|
+
score = score === undefined ? keyScore : Math.max(score, keyScore)
|
|
87
|
+
}
|
|
88
|
+
if (score !== undefined) ranked.push({ item, index, prefix, score })
|
|
89
|
+
})
|
|
90
|
+
ranked.sort((left, right) =>
|
|
91
|
+
Number(right.prefix) - Number(left.prefix) || right.score - left.score || left.index - right.index)
|
|
92
|
+
return ranked.map(match => match.item)
|
|
93
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact relative-time bucketing shared by every surface that dates a
|
|
3
|
+
* session. Bucketing is here so two surfaces naming the same session agree;
|
|
4
|
+
* the words stay in each plugin's own dictionary, per locale-owned copy.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-client-ui-primitives/relative-time
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Relative-time bucket of a dated row's trailing label. */
|
|
10
|
+
export type RelativeTimeUnit = 'now' | 'minutes' | 'hours' | 'days' | 'months' | 'years'
|
|
11
|
+
|
|
12
|
+
/** Structured relative time: the bucket plus its magnitude (0 for 'now'). */
|
|
13
|
+
export interface RelativeTime {
|
|
14
|
+
unit: RelativeTimeUnit
|
|
15
|
+
n: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Compact relative time, as a structured bucket the renderer localizes
|
|
20
|
+
* ("now"/"5min"/"3h"/"2d"/"4mo"/"1y" in en).
|
|
21
|
+
* @param at - epoch ms of the dated moment.
|
|
22
|
+
* @param now - current epoch ms (injected for pure rendering).
|
|
23
|
+
* @returns the row's trailing time bucket and magnitude.
|
|
24
|
+
*/
|
|
25
|
+
export function relativeTime(at: number, now: number): RelativeTime {
|
|
26
|
+
const MIN = 60_000
|
|
27
|
+
const HOUR = 3_600_000
|
|
28
|
+
const DAY = 86_400_000
|
|
29
|
+
const diff = Math.max(0, now - at)
|
|
30
|
+
if (diff < MIN) return { unit: 'now', n: 0 }
|
|
31
|
+
if (diff < HOUR) return { unit: 'minutes', n: Math.floor(diff / MIN) }
|
|
32
|
+
if (diff < DAY) return { unit: 'hours', n: Math.floor(diff / HOUR) }
|
|
33
|
+
if (diff < 30 * DAY) return { unit: 'days', n: Math.floor(diff / DAY) }
|
|
34
|
+
if (diff < 365 * DAY) return { unit: 'months', n: Math.floor(diff / (30 * DAY)) }
|
|
35
|
+
return { unit: 'years', n: Math.floor(diff / (365 * DAY)) }
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* Settings form: the controls a page shows under a plugin's title, and the save that writes them. */
|
|
2
|
+
|
|
3
|
+
.form {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.readOnly,
|
|
9
|
+
.unavailable {
|
|
10
|
+
margin: 0 0 12px;
|
|
11
|
+
font-size: 12px;
|
|
12
|
+
line-height: 1.5;
|
|
13
|
+
color: var(--dsw-alias-label-tertiary);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.footer {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: 8px;
|
|
20
|
+
padding-top: 16px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.failed {
|
|
24
|
+
flex: 1;
|
|
25
|
+
min-width: 0;
|
|
26
|
+
margin: 0;
|
|
27
|
+
font-size: 12px;
|
|
28
|
+
line-height: 1.5;
|
|
29
|
+
color: var(--dsw-alias-label-error);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.save {
|
|
33
|
+
appearance: none;
|
|
34
|
+
border: 1px solid transparent;
|
|
35
|
+
border-radius: var(--dsw-radius-md);
|
|
36
|
+
padding: 5px 14px;
|
|
37
|
+
font: inherit;
|
|
38
|
+
font-size: 13px;
|
|
39
|
+
line-height: 1.5;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
background: var(--dsw-alias-label-primary);
|
|
42
|
+
color: var(--dsw-alias-bg-layer-3);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.save:disabled {
|
|
46
|
+
opacity: 0.4;
|
|
47
|
+
cursor: default;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.save:focus-visible {
|
|
51
|
+
outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
|
|
52
|
+
outline-offset: 1px;
|
|
53
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One plugin's settings form as its page on the Plugins page shows it: the
|
|
3
|
+
* read-only notice when the deployment stores settings read-only, the
|
|
4
|
+
* plugin's controls, and the save that writes every staged edit. The page
|
|
5
|
+
* draws the plugin's title and one-liner itself.
|
|
6
|
+
*
|
|
7
|
+
* Only a save writes. Leaving the page drops every staged edit, so the form
|
|
8
|
+
* discards on unmount and offers no discard control. A form whose namespace
|
|
9
|
+
* the Host stopped serving says so in place of its controls rather than
|
|
10
|
+
* showing fields nothing would accept.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useEffect, useRef, type ReactNode } from 'react'
|
|
14
|
+
import type { SettingsFormShell } from './form-model.ts'
|
|
15
|
+
import css from './SettingsForm.module.css'
|
|
16
|
+
|
|
17
|
+
/** The copy the form frame renders, from the owning plugin's dictionary. */
|
|
18
|
+
export interface SettingsFormLabels {
|
|
19
|
+
/** Shown in place of the controls while the namespace is not served. */
|
|
20
|
+
unavailable: string
|
|
21
|
+
/** Shown over the controls while the document is read-only. */
|
|
22
|
+
readOnly: string
|
|
23
|
+
/** Shown beside the save after a save the Host did not accept. */
|
|
24
|
+
saveFailed: string
|
|
25
|
+
/** The save control. */
|
|
26
|
+
save: string
|
|
27
|
+
/** The save control while a save is crossing the wire. */
|
|
28
|
+
saving: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Form chrome shared by every settings page. */
|
|
32
|
+
export interface SettingsFormProps {
|
|
33
|
+
/** The frame's copy. */
|
|
34
|
+
labels: SettingsFormLabels
|
|
35
|
+
/** The form state: availability, writability, and what a save would do. */
|
|
36
|
+
state: SettingsFormShell
|
|
37
|
+
/** Write every staged edit. */
|
|
38
|
+
onSave: () => void
|
|
39
|
+
/** Drop every staged edit; the form calls it when it leaves the page. */
|
|
40
|
+
onDiscard: () => void
|
|
41
|
+
/** The plugin's controls. */
|
|
42
|
+
children: ReactNode
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Render one plugin's settings form.
|
|
47
|
+
* @param props - the form's copy and state, its controls, and the save and discard actions.
|
|
48
|
+
* @returns the form, or the unavailable line while the namespace is not served.
|
|
49
|
+
*/
|
|
50
|
+
export function SettingsForm(props: SettingsFormProps) {
|
|
51
|
+
const { state, labels } = props
|
|
52
|
+
const discard = useRef(props.onDiscard)
|
|
53
|
+
discard.current = props.onDiscard
|
|
54
|
+
useEffect(() => () => { discard.current() }, [])
|
|
55
|
+
if (!state.available) return <p className={css.unavailable} role="status">{labels.unavailable}</p>
|
|
56
|
+
const blocked = !state.dirty || state.invalid || state.saving
|
|
57
|
+
return (
|
|
58
|
+
<div className={css.form}>
|
|
59
|
+
{!state.writable ? <p className={css.readOnly} role="status">{labels.readOnly}</p> : null}
|
|
60
|
+
{props.children}
|
|
61
|
+
<div className={css.footer}>
|
|
62
|
+
{state.failed ? <p className={css.failed} role="status">{labels.saveFailed}</p> : null}
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
className={css.save}
|
|
66
|
+
disabled={blocked}
|
|
67
|
+
onClick={props.onSave}
|
|
68
|
+
>
|
|
69
|
+
{state.saving ? labels.saving : labels.save}
|
|
70
|
+
</button>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
)
|
|
74
|
+
}
|