@speakeasy-api/moonshine 1.33.4 → 2.0.0-alpha.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.md +26 -10
- package/package.json +12 -23
- package/scripts/generate-utility-docs.js +324 -0
- package/src/assets/icons/external/github.svg +3 -0
- package/src/assets/icons/external/maven.svg +152 -0
- package/src/assets/icons/external/npm.svg +4 -0
- package/src/assets/icons/external/nuget.svg +5 -0
- package/src/assets/icons/external/packagist.svg +1 -0
- package/src/assets/icons/external/pypi.svg +182 -0
- package/src/assets/icons/external/rubygems.svg +14 -0
- package/src/assets/icons/external/terraform.svg +1 -0
- package/src/assets/icons/languages/csharp.svg +1 -0
- package/src/assets/icons/languages/go.svg +1 -0
- package/src/assets/icons/languages/java.svg +1 -0
- package/src/assets/icons/languages/json.svg +2 -0
- package/src/assets/icons/languages/php.svg +1 -0
- package/src/assets/icons/languages/postman.svg +3 -0
- package/src/assets/icons/languages/python.svg +1 -0
- package/src/assets/icons/languages/ruby.svg +1 -0
- package/src/assets/icons/languages/swift.svg +1 -0
- package/src/assets/icons/languages/terraform.svg +1 -0
- package/src/assets/icons/languages/typescript.svg +1 -0
- package/src/assets/icons/languages/unity.svg +1 -0
- package/src/components/AIChat/AIChatContainer.tsx +71 -0
- package/src/components/AIChat/AIChatMessage.tsx +135 -0
- package/src/components/AIChat/AIChatMessageComposer.tsx +175 -0
- package/src/components/AIChat/AIChatMessageList.tsx +34 -0
- package/src/components/AIChat/AIChatModelSelector.tsx +159 -0
- package/src/components/AIChat/componentsTypes.ts +36 -0
- package/src/components/AIChat/context.ts +15 -0
- package/src/components/AIChat/index.ts +12 -0
- package/src/components/AIChat/parts/AIChatMessageFilePart.tsx +129 -0
- package/src/components/AIChat/parts/AIChatMessageReasoningPart.tsx +23 -0
- package/src/components/AIChat/parts/AIChatMessageSourcePart.tsx +58 -0
- package/src/components/AIChat/parts/AIChatMessageTextPart.tsx +33 -0
- package/src/components/AIChat/parts/AIChatMessageToolInvocationPart.tsx +53 -0
- package/src/components/AIChat/parts/AIChatMessageToolPart.tsx +395 -0
- package/src/components/AIChat/parts/AIChatMessageToolResultPart.tsx +46 -0
- package/src/components/AIChat/toolCallApproval.ts +61 -0
- package/src/components/AIChat/types.ts +97 -0
- package/src/components/ActionBar/index.tsx +184 -0
- package/src/components/Alert/index.tsx +118 -0
- package/src/components/Alert/types.ts +12 -0
- package/src/components/AppLayout/context.tsx +31 -0
- package/src/components/AppLayout/index.tsx +550 -0
- package/src/components/AppLayout/provider.tsx +40 -0
- package/src/components/AppLayout/useAppLayoutKeys.ts +26 -0
- package/src/components/Badge/index.tsx +227 -0
- package/src/components/Button/index.tsx +531 -0
- package/src/components/Card/index.tsx +193 -0
- package/src/components/CodeEditorLayout/index.tsx +394 -0
- package/src/components/CodeEditorLayout/styles.module.css +8 -0
- package/src/components/CodeHighlight/Pre.tsx +63 -0
- package/src/components/CodePlayground/index.tsx +411 -0
- package/src/components/CodeSnippet/codeSnippet.css +97 -0
- package/src/components/CodeSnippet/index.tsx +224 -0
- package/src/components/Combobox/index.tsx +193 -0
- package/src/components/Command/index.tsx +152 -0
- package/src/components/Container/index.tsx +31 -0
- package/src/components/ContextDropdown/index.tsx +150 -0
- package/src/components/Dialog/index.tsx +123 -0
- package/src/components/DragNDrop/DragNDropArea.tsx +30 -0
- package/src/components/DragNDrop/DragOverlay.tsx +4 -0
- package/src/components/DragNDrop/Draggable.tsx +97 -0
- package/src/components/DragNDrop/Droppable.tsx +51 -0
- package/src/components/Dropdown/index.tsx +201 -0
- package/src/components/ExternalPill/index.tsx +58 -0
- package/src/components/Facepile/index.tsx +309 -0
- package/src/components/GradientCircle/gradientCircle.css +34 -0
- package/src/components/GradientCircle/index.tsx +143 -0
- package/src/components/Grid/index.tsx +150 -0
- package/src/components/Heading/index.tsx +54 -0
- package/src/components/HighlightedText/index.tsx +152 -0
- package/src/components/Icon/customIcons/createCustomLucideIcon.ts +25 -0
- package/src/components/Icon/customIcons/gems.ts +26 -0
- package/{dist/go-DsW1bFpz.mjs → src/components/Icon/customIcons/go.ts} +21 -19
- package/src/components/Icon/customIcons/index.ts +11 -0
- package/{dist/maven-Dub5liK1.mjs → src/components/Icon/customIcons/maven.ts} +17 -15
- package/src/components/Icon/customIcons/npm.ts +19 -0
- package/{dist/nuget-D86y5HDl.mjs → src/components/Icon/customIcons/nuget.ts} +17 -15
- package/src/components/Icon/customIcons/packagist.ts +124 -0
- package/{dist/pypi-2SUX-2OR.mjs → src/components/Icon/customIcons/pypi.ts} +16 -14
- package/src/components/Icon/index.tsx +83 -0
- package/src/components/Icon/isIconName.ts +10 -0
- package/src/components/Icon/names.ts +14 -0
- package/src/components/IconButton/index.tsx +51 -0
- package/src/components/Input/index.tsx +98 -0
- package/src/components/KeyHint/index.tsx +118 -0
- package/src/components/LanguageIndicator/index.tsx +68 -0
- package/src/components/Link/index.tsx +153 -0
- package/src/components/LoggedInUserMenu/index.tsx +116 -0
- package/src/components/Logo/Animated.tsx +191 -0
- package/src/components/Logo/index.tsx +17 -0
- package/src/components/Logo/speakeasy-logo.riv +0 -0
- package/src/components/Logo/svgs/index.tsx +126 -0
- package/src/components/Modal/index.tsx +104 -0
- package/src/components/PageHeader/index.tsx +227 -0
- package/src/components/PageHeader/styles.module.css +27 -0
- package/src/components/Popover/index.tsx +35 -0
- package/src/components/PromptInput/index.tsx +372 -0
- package/src/components/PullRequestLink/index.tsx +64 -0
- package/src/components/ResizablePanel/index.tsx +119 -0
- package/src/components/Score/index.module.css +32 -0
- package/src/components/Score/index.tsx +268 -0
- package/src/components/ScrollArea/index.tsx +48 -0
- package/src/components/SegmentedButton/index.module.css +19 -0
- package/src/components/SegmentedButton/index.tsx +101 -0
- package/src/components/Select/index.tsx +159 -0
- package/src/components/Separator/index.tsx +23 -0
- package/src/components/Skeleton/index.tsx +61 -0
- package/src/components/Skeleton/skeleton.css +52 -0
- package/src/components/Stack/index.tsx +137 -0
- package/src/components/Subnav/index.tsx +315 -0
- package/src/components/Switch/index.tsx +29 -0
- package/src/components/Table/context/context.tsx +19 -0
- package/src/components/Table/context/tableProvider.tsx +39 -0
- package/src/components/Table/index.tsx +707 -0
- package/src/components/Table/styles.module.css +25 -0
- package/src/components/Tabs/index.tsx +87 -0
- package/src/components/TargetLanguageIcon/index.tsx +84 -0
- package/src/components/Text/index.tsx +59 -0
- package/src/components/ThemeSwitcher/index.tsx +118 -0
- package/src/components/Timeline/index.tsx +290 -0
- package/src/components/Tooltip/index.tsx +41 -0
- package/src/components/UserAvatar/index.tsx +87 -0
- package/src/components/UserAvatar/sizeMap.ts +12 -0
- package/src/components/Wizard/index.tsx +208 -0
- package/src/components/Wizard/types.ts +17 -0
- package/src/components/WorkspaceSelector/CreateOrg.tsx +95 -0
- package/src/components/WorkspaceSelector/CreateWorkspace.tsx +196 -0
- package/src/components/WorkspaceSelector/OrgList.tsx +115 -0
- package/src/components/WorkspaceSelector/OrgSelector.tsx +207 -0
- package/src/components/WorkspaceSelector/RecentWorkspaces.tsx +83 -0
- package/src/components/WorkspaceSelector/ScrollingList.tsx +84 -0
- package/src/components/WorkspaceSelector/SearchBox.tsx +40 -0
- package/src/components/WorkspaceSelector/WorkspaceItem.tsx +37 -0
- package/src/components/WorkspaceSelector/WorkspaceList.tsx +107 -0
- package/src/components/WorkspaceSelector/index.tsx +400 -0
- package/src/components/WorkspaceSelector/styles.css +74 -0
- package/src/components/__beta__/CLIWizard/index.tsx +357 -0
- package/src/components/__beta__/CLIWizard/terminal-command.tsx +108 -0
- package/src/components/__beta__/CLIWizard/terminal.tsx +83 -0
- package/src/components/__beta__/README.md +3 -0
- package/src/components/index.mdx +38 -0
- package/src/context/ConfigContext.tsx +43 -0
- package/src/context/ModalContext.tsx +118 -0
- package/src/context/theme.ts +1 -0
- package/src/hooks/useAppLayout.ts +10 -0
- package/src/hooks/useConfig.ts +10 -0
- package/src/hooks/useIsMounted.ts +13 -0
- package/src/hooks/useModal.tsx +10 -0
- package/src/hooks/useTailwindBreakpoint.ts +47 -0
- package/src/hooks/useTheme.ts +13 -0
- package/src/index.ts +234 -0
- package/src/lib/assert.ts +9 -0
- package/src/lib/codeUtils.ts +177 -0
- package/src/lib/debounce.ts +9 -0
- package/src/lib/responsiveMappers.ts +69 -0
- package/src/lib/responsiveUtils.ts +23 -0
- package/src/lib/storybookUtils.tsx +26 -0
- package/src/lib/typeUtils.ts +109 -0
- package/src/lib/utils.ts +85 -0
- package/src/styles/codeSyntax.css +59 -0
- package/src/styles/globals.css +51 -0
- package/src/types.ts +200 -0
- package/src/vite-env.d.ts +6 -0
- package/types/utilities.d.ts +1 -1
- package/dist/components/AIChat/AIChatContainer.d.ts +0 -26
- package/dist/components/AIChat/AIChatMessage.d.ts +0 -19
- package/dist/components/AIChat/AIChatMessageComposer.d.ts +0 -22
- package/dist/components/AIChat/AIChatMessageList.d.ts +0 -6
- package/dist/components/AIChat/AIChatModelSelector.d.ts +0 -14
- package/dist/components/AIChat/componentsTypes.d.ts +0 -11
- package/dist/components/AIChat/context.d.ts +0 -3
- package/dist/components/AIChat/index.d.ts +0 -12
- package/dist/components/AIChat/parts/AIChatMessageFilePart.d.ts +0 -7
- package/dist/components/AIChat/parts/AIChatMessageReasoningPart.d.ts +0 -5
- package/dist/components/AIChat/parts/AIChatMessageSourcePart.d.ts +0 -9
- package/dist/components/AIChat/parts/AIChatMessageTextPart.d.ts +0 -5
- package/dist/components/AIChat/parts/AIChatMessageToolInvocationPart.d.ts +0 -6
- package/dist/components/AIChat/parts/AIChatMessageToolPart.d.ts +0 -33
- package/dist/components/AIChat/parts/AIChatMessageToolResultPart.d.ts +0 -5
- package/dist/components/AIChat/toolCallApproval.d.ts +0 -15
- package/dist/components/AIChat/types.d.ts +0 -79
- package/dist/components/ActionBar/index.d.ts +0 -36
- package/dist/components/Alert/index.d.ts +0 -18
- package/dist/components/Alert/types.d.ts +0 -4
- package/dist/components/AppLayout/context.d.ts +0 -16
- package/dist/components/AppLayout/index.d.ts +0 -131
- package/dist/components/AppLayout/provider.d.ts +0 -8
- package/dist/components/AppLayout/useAppLayoutKeys.d.ts +0 -1
- package/dist/components/Badge/index.d.ts +0 -21
- package/dist/components/Button/index.d.ts +0 -22
- package/dist/components/Card/index.d.ts +0 -47
- package/dist/components/CodeEditorLayout/index.d.ts +0 -101
- package/dist/components/CodeHighlight/Pre.d.ts +0 -8
- package/dist/components/CodePlayground/index.d.ts +0 -102
- package/dist/components/CodeSnippet/index.d.ts +0 -49
- package/dist/components/Combobox/index.d.ts +0 -35
- package/dist/components/Command/index.d.ts +0 -80
- package/dist/components/Container/index.d.ts +0 -9
- package/dist/components/ContextDropdown/index.d.ts +0 -7
- package/dist/components/Dialog/index.d.ts +0 -21
- package/dist/components/DragNDrop/DragNDropArea.d.ts +0 -8
- package/dist/components/DragNDrop/DragOverlay.d.ts +0 -1
- package/dist/components/DragNDrop/Draggable.d.ts +0 -29
- package/dist/components/DragNDrop/Droppable.d.ts +0 -28
- package/dist/components/Dropdown/index.d.ts +0 -27
- package/dist/components/ExternalPill/index.d.ts +0 -12
- package/dist/components/Facepile/index.d.ts +0 -16
- package/dist/components/GradientCircle/index.d.ts +0 -10
- package/dist/components/Grid/index.d.ts +0 -80
- package/dist/components/Heading/index.d.ts +0 -12
- package/dist/components/HighlightedText/index.d.ts +0 -19
- package/dist/components/Icon/customIcons/createCustomLucideIcon.d.ts +0 -3
- package/dist/components/Icon/customIcons/gems.d.ts +0 -2
- package/dist/components/Icon/customIcons/go.d.ts +0 -2
- package/dist/components/Icon/customIcons/index.d.ts +0 -10
- package/dist/components/Icon/customIcons/maven.d.ts +0 -2
- package/dist/components/Icon/customIcons/npm.d.ts +0 -2
- package/dist/components/Icon/customIcons/nuget.d.ts +0 -2
- package/dist/components/Icon/customIcons/packagist.d.ts +0 -2
- package/dist/components/Icon/customIcons/pypi.d.ts +0 -2
- package/dist/components/Icon/index.d.ts +0 -10
- package/dist/components/Icon/isIconName.d.ts +0 -2
- package/dist/components/Icon/names.d.ts +0 -6
- package/dist/components/IconButton/index.d.ts +0 -14
- package/dist/components/Input/index.d.ts +0 -8
- package/dist/components/KeyHint/index.d.ts +0 -16
- package/dist/components/LanguageIndicator/index.d.ts +0 -7
- package/dist/components/Link/index.d.ts +0 -15
- package/dist/components/LoggedInUserMenu/index.d.ts +0 -17
- package/dist/components/Logo/Animated.d.ts +0 -7
- package/dist/components/Logo/index.d.ts +0 -7
- package/dist/components/Logo/svgs/index.d.ts +0 -6
- package/dist/components/Modal/index.d.ts +0 -8
- package/dist/components/PageHeader/index.d.ts +0 -45
- package/dist/components/Popover/index.d.ts +0 -8
- package/dist/components/PromptInput/index.d.ts +0 -55
- package/dist/components/PullRequestLink/index.d.ts +0 -10
- package/dist/components/ResizablePanel/index.d.ts +0 -26
- package/dist/components/Score/index.d.ts +0 -37
- package/dist/components/ScrollArea/index.d.ts +0 -5
- package/dist/components/SegmentedButton/index.d.ts +0 -23
- package/dist/components/Select/index.d.ts +0 -13
- package/dist/components/Separator/index.d.ts +0 -6
- package/dist/components/Skeleton/index.d.ts +0 -27
- package/dist/components/Stack/index.d.ts +0 -33
- package/dist/components/Subnav/index.d.ts +0 -12
- package/dist/components/Switch/index.d.ts +0 -4
- package/dist/components/Table/context/context.d.ts +0 -8
- package/dist/components/Table/context/tableProvider.d.ts +0 -6
- package/dist/components/Table/index.d.ts +0 -94
- package/dist/components/Tabs/index.d.ts +0 -21
- package/dist/components/TargetLanguageIcon/index.d.ts +0 -7
- package/dist/components/Text/index.d.ts +0 -19
- package/dist/components/ThemeSwitcher/index.d.ts +0 -6
- package/dist/components/Timeline/index.d.ts +0 -49
- package/dist/components/Tooltip/index.d.ts +0 -9
- package/dist/components/UserAvatar/index.d.ts +0 -9
- package/dist/components/UserAvatar/sizeMap.d.ts +0 -3
- package/dist/components/Wizard/index.d.ts +0 -19
- package/dist/components/Wizard/types.d.ts +0 -15
- package/dist/components/WorkspaceSelector/CreateOrg.d.ts +0 -6
- package/dist/components/WorkspaceSelector/CreateWorkspace.d.ts +0 -17
- package/dist/components/WorkspaceSelector/OrgList.d.ts +0 -12
- package/dist/components/WorkspaceSelector/OrgSelector.d.ts +0 -13
- package/dist/components/WorkspaceSelector/RecentWorkspaces.d.ts +0 -11
- package/dist/components/WorkspaceSelector/ScrollingList.d.ts +0 -21
- package/dist/components/WorkspaceSelector/SearchBox.d.ts +0 -9
- package/dist/components/WorkspaceSelector/WorkspaceItem.d.ts +0 -9
- package/dist/components/WorkspaceSelector/WorkspaceList.d.ts +0 -11
- package/dist/components/WorkspaceSelector/index.d.ts +0 -36
- package/dist/components/__beta__/CLIWizard/index.d.ts +0 -19
- package/dist/components/__beta__/CLIWizard/terminal-command.d.ts +0 -19
- package/dist/components/__beta__/CLIWizard/terminal.d.ts +0 -26
- package/dist/context/ConfigContext.d.ts +0 -18
- package/dist/context/ModalContext.d.ts +0 -22
- package/dist/context/theme.d.ts +0 -1
- package/dist/createCustomLucideIcon-CatlpFc0.mjs +0 -19
- package/dist/createCustomLucideIcon-CatlpFc0.mjs.map +0 -1
- package/dist/gems-DQ7pOLLr.mjs +0 -24
- package/dist/gems-DQ7pOLLr.mjs.map +0 -1
- package/dist/github-kgjMtfE7.mjs +0 -11
- package/dist/github-kgjMtfE7.mjs.map +0 -1
- package/dist/go-DsW1bFpz.mjs.map +0 -1
- package/dist/hooks/useAppLayout.d.ts +0 -1
- package/dist/hooks/useConfig.d.ts +0 -2
- package/dist/hooks/useIsMounted.d.ts +0 -1
- package/dist/hooks/useModal.d.ts +0 -11
- package/dist/hooks/useTailwindBreakpoint.d.ts +0 -3
- package/dist/hooks/useTheme.d.ts +0 -6
- package/dist/index-C9bJtuJ5.mjs +0 -16347
- package/dist/index-C9bJtuJ5.mjs.map +0 -1
- package/dist/index.d.ts +0 -80
- package/dist/lib/assert.d.ts +0 -2
- package/dist/lib/codeUtils.d.ts +0 -36
- package/dist/lib/debounce.d.ts +0 -1
- package/dist/lib/responsiveMappers.d.ts +0 -10
- package/dist/lib/responsiveUtils.d.ts +0 -3
- package/dist/lib/storybookUtils.d.ts +0 -5
- package/dist/lib/typeUtils.d.ts +0 -24
- package/dist/lib/utils.d.ts +0 -24
- package/dist/maven-Dub5liK1.mjs.map +0 -1
- package/dist/maven-W_nkSDNW.mjs +0 -107
- package/dist/maven-W_nkSDNW.mjs.map +0 -1
- package/dist/moonshine.es.js +0 -125
- package/dist/moonshine.es.js.map +0 -1
- package/dist/npm-BWTcVvFH.mjs +0 -11
- package/dist/npm-BWTcVvFH.mjs.map +0 -1
- package/dist/npm-BYcG5_q9.mjs +0 -17
- package/dist/npm-BYcG5_q9.mjs.map +0 -1
- package/dist/nuget-CV5HU1JR.mjs +0 -11
- package/dist/nuget-CV5HU1JR.mjs.map +0 -1
- package/dist/nuget-D86y5HDl.mjs.map +0 -1
- package/dist/packagist-BFSSrw4p.mjs +0 -118
- package/dist/packagist-BFSSrw4p.mjs.map +0 -1
- package/dist/packagist-D01fn9N_.mjs +0 -11
- package/dist/packagist-D01fn9N_.mjs.map +0 -1
- package/dist/pypi-2SUX-2OR.mjs.map +0 -1
- package/dist/pypi-DLh6kIJe.mjs +0 -11
- package/dist/pypi-DLh6kIJe.mjs.map +0 -1
- package/dist/rubygems-DeiNjcDV.mjs +0 -11
- package/dist/rubygems-DeiNjcDV.mjs.map +0 -1
- package/dist/speakeasy-logo-ByBTXLWb.mjs +0 -5
- package/dist/speakeasy-logo-ByBTXLWb.mjs.map +0 -1
- package/dist/style.css +0 -1
- package/dist/terraform-C4aktQ0o.mjs +0 -11
- package/dist/terraform-C4aktQ0o.mjs.map +0 -1
- package/dist/types.d.ts +0 -85
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createContext, useState, type ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type Screen = {
|
|
4
|
+
id: string
|
|
5
|
+
title: string
|
|
6
|
+
component: ReactNode
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ModalContextType = {
|
|
10
|
+
screens: Screen[]
|
|
11
|
+
currentIndex: number
|
|
12
|
+
isOpen: boolean
|
|
13
|
+
openScreen: (screen: Screen) => void
|
|
14
|
+
close: () => void
|
|
15
|
+
navigateTo: (index: number) => void
|
|
16
|
+
pushScreen: (screen: Screen) => void
|
|
17
|
+
popScreen: () => void
|
|
18
|
+
navigationDirection: 'forward' | 'backward'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
22
|
+
export const ModalContext = createContext<ModalContextType | undefined>(
|
|
23
|
+
undefined
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export function ModalProvider({
|
|
27
|
+
children,
|
|
28
|
+
}: {
|
|
29
|
+
children: ReactNode | ((props: ModalContextType) => ReactNode)
|
|
30
|
+
}) {
|
|
31
|
+
const [screens, setScreens] = useState<Screen[]>([])
|
|
32
|
+
const [currentIndex, setCurrentIndex] = useState(0)
|
|
33
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
34
|
+
const [navigationDirection, setNavigationDirection] = useState<
|
|
35
|
+
'forward' | 'backward'
|
|
36
|
+
>('forward')
|
|
37
|
+
|
|
38
|
+
const openScreen = (screen: Screen) => {
|
|
39
|
+
// Don't reopen if already open to prevent infinite loops
|
|
40
|
+
if (!isOpen) {
|
|
41
|
+
setScreens([screen])
|
|
42
|
+
setCurrentIndex(0)
|
|
43
|
+
setIsOpen(true)
|
|
44
|
+
setNavigationDirection('forward')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const close = () => {
|
|
49
|
+
setIsOpen(false)
|
|
50
|
+
// Reset after animation completes
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
setScreens([])
|
|
53
|
+
setCurrentIndex(0)
|
|
54
|
+
}, 200)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const navigateTo = (index: number) => {
|
|
58
|
+
setScreens((prevScreens) => {
|
|
59
|
+
if (index >= 0 && index < prevScreens.length) {
|
|
60
|
+
setNavigationDirection(index > currentIndex ? 'forward' : 'backward')
|
|
61
|
+
setCurrentIndex(index)
|
|
62
|
+
}
|
|
63
|
+
return prevScreens
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const pushScreen = (screen: Screen) => {
|
|
68
|
+
setScreens((prev) => {
|
|
69
|
+
const newScreens = [...prev, screen]
|
|
70
|
+
setCurrentIndex(newScreens.length - 1)
|
|
71
|
+
return newScreens
|
|
72
|
+
})
|
|
73
|
+
setNavigationDirection('forward')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const popScreen = () => {
|
|
77
|
+
setScreens((prev) => {
|
|
78
|
+
if (prev.length > 1) {
|
|
79
|
+
setNavigationDirection('backward')
|
|
80
|
+
setCurrentIndex((idx) => idx - 1)
|
|
81
|
+
return prev.slice(0, prev.length - 1)
|
|
82
|
+
} else {
|
|
83
|
+
close()
|
|
84
|
+
return prev
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<ModalContext.Provider
|
|
91
|
+
value={{
|
|
92
|
+
screens,
|
|
93
|
+
currentIndex,
|
|
94
|
+
isOpen,
|
|
95
|
+
openScreen,
|
|
96
|
+
close,
|
|
97
|
+
navigateTo,
|
|
98
|
+
pushScreen,
|
|
99
|
+
popScreen,
|
|
100
|
+
navigationDirection,
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{typeof children === 'function'
|
|
104
|
+
? children({
|
|
105
|
+
screens,
|
|
106
|
+
currentIndex,
|
|
107
|
+
isOpen,
|
|
108
|
+
openScreen,
|
|
109
|
+
close,
|
|
110
|
+
navigateTo,
|
|
111
|
+
pushScreen,
|
|
112
|
+
popScreen,
|
|
113
|
+
navigationDirection,
|
|
114
|
+
})
|
|
115
|
+
: children}
|
|
116
|
+
</ModalContext.Provider>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Theme = 'light' | 'dark'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { AppLayoutContext } from '../components/AppLayout/context'
|
|
3
|
+
|
|
4
|
+
export const useAppLayout = () => {
|
|
5
|
+
const context = useContext(AppLayoutContext)
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error('useAppLayout must be used within an AppLayoutProvider')
|
|
8
|
+
}
|
|
9
|
+
return context
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ConfigContext, ConfigContextType } from '../context/ConfigContext'
|
|
3
|
+
|
|
4
|
+
export function useConfig(): ConfigContextType {
|
|
5
|
+
const context = useContext(ConfigContext)
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error('useConfig must be used within a MoonshineConfigProvider')
|
|
8
|
+
}
|
|
9
|
+
return context
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ModalContext } from '../context/ModalContext'
|
|
3
|
+
|
|
4
|
+
export function useModal() {
|
|
5
|
+
const context = useContext(ModalContext)
|
|
6
|
+
if (context === undefined) {
|
|
7
|
+
throw new Error('useModal must be used within a ModalProvider')
|
|
8
|
+
}
|
|
9
|
+
return context
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from 'react'
|
|
2
|
+
import { Breakpoint } from '../types.js'
|
|
3
|
+
import debounce from '../lib/debounce'
|
|
4
|
+
|
|
5
|
+
// Define breakpoints in pixels matching Tailwind's default breakpoints
|
|
6
|
+
const breakpointValues = {
|
|
7
|
+
xs: 0, // Default/mobile first
|
|
8
|
+
sm: 640, // @media (min-width: 640px)
|
|
9
|
+
md: 768, // @media (min-width: 768px)
|
|
10
|
+
lg: 1024, // @media (min-width: 1024px)
|
|
11
|
+
xl: 1280, // @media (min-width: 1280px)
|
|
12
|
+
'2xl': 1536, // @media (min-width: 1536px)
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
const getBreakpoint = (width: number): Breakpoint => {
|
|
16
|
+
const breakpoints = Object.entries(breakpointValues).sort(
|
|
17
|
+
(a, b) => b[1] - a[1]
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
for (const [key, minWidth] of breakpoints) {
|
|
21
|
+
if (width >= minWidth) {
|
|
22
|
+
return key as Breakpoint
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return 'xs'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const useTailwindBreakpoint = (): Breakpoint => {
|
|
30
|
+
const [breakpoint, setBreakpoint] = useState<Breakpoint>(
|
|
31
|
+
getBreakpoint(window.innerWidth)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
const handleResize = debounce(() => {
|
|
36
|
+
const newBreakpoint = getBreakpoint(window.innerWidth)
|
|
37
|
+
setBreakpoint(newBreakpoint)
|
|
38
|
+
}, 100)
|
|
39
|
+
window.addEventListener('resize', handleResize)
|
|
40
|
+
handleResize()
|
|
41
|
+
return () => window.removeEventListener('resize', handleResize)
|
|
42
|
+
}, [])
|
|
43
|
+
|
|
44
|
+
return breakpoint
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default useTailwindBreakpoint
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useConfig } from './useConfig'
|
|
2
|
+
|
|
3
|
+
export type Theme = 'dark' | 'light'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to get the current theme (light or dark) from the tailwind class element.
|
|
7
|
+
* @deprecated get the theme from useMoonshineConfig
|
|
8
|
+
*/
|
|
9
|
+
export function useTheme() {
|
|
10
|
+
const { theme } = useConfig()
|
|
11
|
+
|
|
12
|
+
return theme
|
|
13
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import './global.css'
|
|
2
|
+
|
|
3
|
+
export { isGroupOf } from './lib/typeUtils'
|
|
4
|
+
export { Grid, type GridProps } from './components/Grid'
|
|
5
|
+
export { Stack, type StackProps } from './components/Stack'
|
|
6
|
+
export { Button, type ButtonProps } from './components/Button'
|
|
7
|
+
export { Card, type CardProps } from './components/Card'
|
|
8
|
+
export { Icon, type IconProps } from './components/Icon'
|
|
9
|
+
export { isIconName } from './components/Icon/isIconName'
|
|
10
|
+
export { type IconName } from './components/Icon/names'
|
|
11
|
+
export { Separator, type SeparatorProps } from './components/Separator'
|
|
12
|
+
export { Skeleton, type SkeletonProps } from './components/Skeleton'
|
|
13
|
+
export { Badge, type BadgeProps } from './components/Badge'
|
|
14
|
+
export { Heading, type HeadingProps } from './components/Heading'
|
|
15
|
+
export { Text, type TextProps } from './components/Text'
|
|
16
|
+
export { Score, type ScoreValue } from './components/Score'
|
|
17
|
+
export { Logo, type LogoProps } from './components/Logo'
|
|
18
|
+
export { AnimatedLogo } from './components/Logo/Animated'
|
|
19
|
+
export { Container, type ContainerProps } from './components/Container'
|
|
20
|
+
export { Combobox, type ComboboxProps } from './components/Combobox'
|
|
21
|
+
export {
|
|
22
|
+
TargetLanguageIcon,
|
|
23
|
+
type TargetLanguageIconProps,
|
|
24
|
+
} from './components/TargetLanguageIcon'
|
|
25
|
+
export { UserAvatar, type UserAvatarProps } from './components/UserAvatar'
|
|
26
|
+
export { Subnav, type SubnavItem, type SubnavProps } from './components/Subnav'
|
|
27
|
+
export { CodeSnippet, type CodeSnippetProps } from './components/CodeSnippet'
|
|
28
|
+
export { Pre, type PreProps } from './components/CodeHighlight/Pre'
|
|
29
|
+
export {
|
|
30
|
+
highlightCode,
|
|
31
|
+
getMappedLanguage,
|
|
32
|
+
isProgrammingLanguage,
|
|
33
|
+
removeCodeHikeAnnotations,
|
|
34
|
+
LIGHT_THEME,
|
|
35
|
+
DARK_THEME,
|
|
36
|
+
type HighlightedCode,
|
|
37
|
+
type CodeLine,
|
|
38
|
+
type CodeToken,
|
|
39
|
+
} from './lib/codeUtils'
|
|
40
|
+
export {
|
|
41
|
+
LoggedInUserMenu,
|
|
42
|
+
type LoggedInUserProps,
|
|
43
|
+
} from './components/LoggedInUserMenu'
|
|
44
|
+
export {
|
|
45
|
+
PromptInput,
|
|
46
|
+
type PromptInputProps,
|
|
47
|
+
type Suggestion,
|
|
48
|
+
type Attachment,
|
|
49
|
+
} from './components/PromptInput'
|
|
50
|
+
export {
|
|
51
|
+
WorkspaceSelector,
|
|
52
|
+
type Org,
|
|
53
|
+
type Workspace,
|
|
54
|
+
type WorkspaceSelectorProps,
|
|
55
|
+
} from './components/WorkspaceSelector'
|
|
56
|
+
export { Wizard, type WizardProps } from './components/Wizard'
|
|
57
|
+
export { type WizardStep, type WizardCommand } from './components/Wizard/types'
|
|
58
|
+
export {
|
|
59
|
+
MoonshineConfigProvider,
|
|
60
|
+
type MoonshineConfigProviderProps,
|
|
61
|
+
} from './context/ConfigContext'
|
|
62
|
+
export { useConfig as useMoonshineConfig } from './hooks/useConfig'
|
|
63
|
+
export { useTheme as useMoonshineTheme, type Theme } from './hooks/useTheme'
|
|
64
|
+
export { default as useTailwindBreakpoint } from './hooks/useTailwindBreakpoint'
|
|
65
|
+
export {
|
|
66
|
+
GradientCircle,
|
|
67
|
+
type GradientCircleProps,
|
|
68
|
+
} from './components/GradientCircle'
|
|
69
|
+
export { Alert, type AlertProps } from './components/Alert'
|
|
70
|
+
export { Tabs, type TabProps } from './components/Tabs'
|
|
71
|
+
export {
|
|
72
|
+
Table,
|
|
73
|
+
type TableProps,
|
|
74
|
+
type Column,
|
|
75
|
+
type Group,
|
|
76
|
+
} from './components/Table'
|
|
77
|
+
export { Input, type InputProps } from './components/Input'
|
|
78
|
+
export {
|
|
79
|
+
type SupportedLanguage,
|
|
80
|
+
supportedLanguages,
|
|
81
|
+
isSupportedLanguage,
|
|
82
|
+
} from './types'
|
|
83
|
+
export { PageHeader, type PageHeaderProps } from './components/PageHeader'
|
|
84
|
+
|
|
85
|
+
export { ExternalPill, type ExternalPillProps } from './components/ExternalPill'
|
|
86
|
+
export {
|
|
87
|
+
LanguageIndicator,
|
|
88
|
+
type LanguageIndicatorProps,
|
|
89
|
+
} from './components/LanguageIndicator'
|
|
90
|
+
export {
|
|
91
|
+
PullRequestLink,
|
|
92
|
+
type PullRequestLinkProps,
|
|
93
|
+
} from './components/PullRequestLink'
|
|
94
|
+
export {
|
|
95
|
+
Select,
|
|
96
|
+
SelectGroup,
|
|
97
|
+
SelectItem,
|
|
98
|
+
SelectContent,
|
|
99
|
+
SelectTrigger,
|
|
100
|
+
SelectValue,
|
|
101
|
+
SelectScrollDownButton,
|
|
102
|
+
SelectScrollUpButton,
|
|
103
|
+
SelectSeparator,
|
|
104
|
+
} from './components/Select'
|
|
105
|
+
export {
|
|
106
|
+
Tooltip,
|
|
107
|
+
TooltipTrigger,
|
|
108
|
+
TooltipContent,
|
|
109
|
+
TooltipProvider,
|
|
110
|
+
TooltipPortal,
|
|
111
|
+
} from './components/Tooltip'
|
|
112
|
+
export {
|
|
113
|
+
Popover,
|
|
114
|
+
PopoverContent,
|
|
115
|
+
PopoverTrigger,
|
|
116
|
+
PopoverAnchor,
|
|
117
|
+
PopoverPortal,
|
|
118
|
+
} from './components/Popover'
|
|
119
|
+
export { Facepile, type FacepileProps } from './components/Facepile'
|
|
120
|
+
export { Link, type LinkProps } from './components/Link'
|
|
121
|
+
export { Dialog } from './components/Dialog'
|
|
122
|
+
export { Switch, type SwitchProps } from './components/Switch'
|
|
123
|
+
export { SegmentedButton } from './components/SegmentedButton'
|
|
124
|
+
// AppLayout
|
|
125
|
+
export {
|
|
126
|
+
AppLayout,
|
|
127
|
+
type AppLayoutNavItemProps,
|
|
128
|
+
type AppLayoutNavItemGroupProps,
|
|
129
|
+
type AppLayoutBreadcrumbItemProps,
|
|
130
|
+
} from './components/AppLayout'
|
|
131
|
+
export { AppLayoutProvider } from './components/AppLayout/provider'
|
|
132
|
+
export { useAppLayout } from './hooks/useAppLayout'
|
|
133
|
+
|
|
134
|
+
export { ActionBar, type ActionBarProps } from './components/ActionBar'
|
|
135
|
+
export {
|
|
136
|
+
Key,
|
|
137
|
+
type KeyProps,
|
|
138
|
+
KeyHint,
|
|
139
|
+
type KeyHintProps,
|
|
140
|
+
} from './components/KeyHint'
|
|
141
|
+
export {
|
|
142
|
+
HighlightedText,
|
|
143
|
+
type HighlightedTextProps,
|
|
144
|
+
} from './components/HighlightedText'
|
|
145
|
+
export {
|
|
146
|
+
DragNDropArea,
|
|
147
|
+
type DragNDropAreaProps,
|
|
148
|
+
} from './components/DragNDrop/DragNDropArea'
|
|
149
|
+
export { DragOverlay } from './components/DragNDrop/DragOverlay'
|
|
150
|
+
export {
|
|
151
|
+
Draggable,
|
|
152
|
+
type DraggableProps,
|
|
153
|
+
} from './components/DragNDrop/Draggable'
|
|
154
|
+
export {
|
|
155
|
+
Droppable,
|
|
156
|
+
type DroppableProps,
|
|
157
|
+
} from './components/DragNDrop/Droppable'
|
|
158
|
+
export {
|
|
159
|
+
ResizablePanel,
|
|
160
|
+
type ResizablePanelProps,
|
|
161
|
+
} from './components/ResizablePanel'
|
|
162
|
+
export {
|
|
163
|
+
CodePlayground,
|
|
164
|
+
type CodePlaygroundProps,
|
|
165
|
+
type CodePlaygroundSnippets,
|
|
166
|
+
} from './components/CodePlayground'
|
|
167
|
+
export {
|
|
168
|
+
CodeEditor,
|
|
169
|
+
type CodeEditorLayoutProps,
|
|
170
|
+
} from './components/CodeEditorLayout'
|
|
171
|
+
export {
|
|
172
|
+
Command,
|
|
173
|
+
CommandGroup,
|
|
174
|
+
CommandItem,
|
|
175
|
+
CommandEmpty,
|
|
176
|
+
CommandInput,
|
|
177
|
+
CommandList,
|
|
178
|
+
CommandSeparator,
|
|
179
|
+
CommandShortcut,
|
|
180
|
+
CommandDialog,
|
|
181
|
+
} from './components/Command'
|
|
182
|
+
export {
|
|
183
|
+
DropdownMenu,
|
|
184
|
+
DropdownMenuCheckboxItem,
|
|
185
|
+
DropdownMenuContent,
|
|
186
|
+
DropdownMenuItem,
|
|
187
|
+
DropdownMenuLabel,
|
|
188
|
+
DropdownMenuRadioGroup,
|
|
189
|
+
DropdownMenuGroup,
|
|
190
|
+
DropdownMenuTrigger,
|
|
191
|
+
DropdownMenuPortal,
|
|
192
|
+
DropdownMenuSub,
|
|
193
|
+
DropdownMenuSubTrigger,
|
|
194
|
+
DropdownMenuSubContent,
|
|
195
|
+
DropdownMenuRadioItem,
|
|
196
|
+
DropdownMenuSeparator,
|
|
197
|
+
DropdownMenuShortcut,
|
|
198
|
+
} from './components/Dropdown'
|
|
199
|
+
|
|
200
|
+
// ContextDropdown
|
|
201
|
+
export { ContextDropdown } from './components/ContextDropdown'
|
|
202
|
+
export { ModalProvider } from './context/ModalContext'
|
|
203
|
+
export { useModal } from './hooks/useModal'
|
|
204
|
+
|
|
205
|
+
// Modal
|
|
206
|
+
export { Modal, type ModalProps } from './components/Modal'
|
|
207
|
+
|
|
208
|
+
export {
|
|
209
|
+
ThemeSwitcher,
|
|
210
|
+
type ThemeSwitcherProps,
|
|
211
|
+
} from './components/ThemeSwitcher'
|
|
212
|
+
|
|
213
|
+
export { cn } from './lib/utils'
|
|
214
|
+
|
|
215
|
+
// Timeline
|
|
216
|
+
export { Timeline } from './components/Timeline'
|
|
217
|
+
|
|
218
|
+
/** START BETA COMPONENTS */
|
|
219
|
+
import { CLIWizard } from './components/__beta__/CLIWizard'
|
|
220
|
+
|
|
221
|
+
export const beta = {
|
|
222
|
+
// TODO: This component is not yet reusable, it's only for use on the SDK Overview page right now
|
|
223
|
+
// TODO: needs light mode tweaks too.
|
|
224
|
+
CLIWizard,
|
|
225
|
+
}
|
|
226
|
+
// DO NOT USE: EXPORTED TO UNBLOCK GRAM
|
|
227
|
+
export {
|
|
228
|
+
AIChatContainer,
|
|
229
|
+
AIChatMessage,
|
|
230
|
+
AIChatMessageComposer,
|
|
231
|
+
} from './components/AIChat'
|
|
232
|
+
export { useToolCallApproval } from './components/AIChat/toolCallApproval'
|
|
233
|
+
|
|
234
|
+
/** END BETA COMPONENTS */
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { codeToTokens, BundledLanguage, BundledTheme } from 'shiki'
|
|
2
|
+
import { ProgrammingLanguage, SupportedLanguage } from '../types'
|
|
3
|
+
|
|
4
|
+
export const LIGHT_THEME = 'github-light' as const
|
|
5
|
+
export const DARK_THEME = 'github-dark' as const
|
|
6
|
+
|
|
7
|
+
export interface CodeToken {
|
|
8
|
+
content: string
|
|
9
|
+
color?: string
|
|
10
|
+
fontStyle?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CodeLine {
|
|
14
|
+
tokens: CodeToken[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface HighlightedCode {
|
|
18
|
+
lines: CodeLine[]
|
|
19
|
+
code: string
|
|
20
|
+
lang: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Highlights code using Shiki
|
|
25
|
+
*/
|
|
26
|
+
export async function highlightCode(
|
|
27
|
+
code: string,
|
|
28
|
+
language: SupportedLanguage | string,
|
|
29
|
+
theme: BundledTheme = LIGHT_THEME
|
|
30
|
+
): Promise<HighlightedCode> {
|
|
31
|
+
// Clean the code by removing annotations
|
|
32
|
+
const cleanCode = removeCodeHikeAnnotations(code)
|
|
33
|
+
|
|
34
|
+
const lang = isProgrammingLanguage(language)
|
|
35
|
+
? getMappedLanguage(language)
|
|
36
|
+
: (language as BundledLanguage)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const tokens = await codeToTokens(cleanCode, {
|
|
40
|
+
lang,
|
|
41
|
+
theme,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const lines: CodeLine[] = tokens.tokens.map((line) => ({
|
|
45
|
+
tokens: line.map((token) => ({
|
|
46
|
+
content: token.content,
|
|
47
|
+
color: token.color,
|
|
48
|
+
fontStyle: token.fontStyle,
|
|
49
|
+
})),
|
|
50
|
+
}))
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
lines,
|
|
54
|
+
code: cleanCode,
|
|
55
|
+
lang,
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Only log errors outside of test environment
|
|
59
|
+
if (!process.env.VITEST && !process.env.NODE_ENV?.includes('test')) {
|
|
60
|
+
console.error('Error highlighting code:', error)
|
|
61
|
+
}
|
|
62
|
+
// Fallback to plain text
|
|
63
|
+
return {
|
|
64
|
+
lines: cleanCode.split('\n').map((line) => ({
|
|
65
|
+
tokens: [{ content: line || '\n' }],
|
|
66
|
+
})),
|
|
67
|
+
code: cleanCode,
|
|
68
|
+
lang,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Maps language identifiers to their proper syntax highlighting aliases
|
|
75
|
+
*/
|
|
76
|
+
export function getMappedLanguage(
|
|
77
|
+
language: ProgrammingLanguage | SupportedLanguage
|
|
78
|
+
): BundledLanguage {
|
|
79
|
+
switch (language) {
|
|
80
|
+
case 'javascript':
|
|
81
|
+
return 'js'
|
|
82
|
+
case 'typescript':
|
|
83
|
+
return 'ts'
|
|
84
|
+
case 'python':
|
|
85
|
+
return 'py'
|
|
86
|
+
case 'bash':
|
|
87
|
+
return 'bash'
|
|
88
|
+
case 'json':
|
|
89
|
+
return 'json'
|
|
90
|
+
case 'go':
|
|
91
|
+
return 'go'
|
|
92
|
+
case 'dotnet':
|
|
93
|
+
case 'csharp':
|
|
94
|
+
return 'csharp'
|
|
95
|
+
case 'java':
|
|
96
|
+
return 'java'
|
|
97
|
+
case 'ruby':
|
|
98
|
+
return 'ruby'
|
|
99
|
+
case 'php':
|
|
100
|
+
return 'php'
|
|
101
|
+
case 'swift':
|
|
102
|
+
return 'swift'
|
|
103
|
+
case 'terraform':
|
|
104
|
+
return 'hcl'
|
|
105
|
+
default:
|
|
106
|
+
return language as BundledLanguage
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Helper to check if a language is in our supported set
|
|
112
|
+
*/
|
|
113
|
+
export function isProgrammingLanguage(
|
|
114
|
+
language: string
|
|
115
|
+
): language is ProgrammingLanguage {
|
|
116
|
+
return [
|
|
117
|
+
'javascript',
|
|
118
|
+
'typescript',
|
|
119
|
+
'python',
|
|
120
|
+
'bash',
|
|
121
|
+
'json',
|
|
122
|
+
'go',
|
|
123
|
+
'dotnet',
|
|
124
|
+
'csharp',
|
|
125
|
+
'java',
|
|
126
|
+
'ruby',
|
|
127
|
+
'php',
|
|
128
|
+
'swift',
|
|
129
|
+
'terraform',
|
|
130
|
+
].includes(language)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const ANNOTATION_TYPES = [
|
|
134
|
+
'callout',
|
|
135
|
+
'className',
|
|
136
|
+
'hover',
|
|
137
|
+
'collapse',
|
|
138
|
+
'diff',
|
|
139
|
+
'focus',
|
|
140
|
+
'fold',
|
|
141
|
+
'link',
|
|
142
|
+
'mark',
|
|
143
|
+
'tooltip',
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
const ANNOTATION_REGEX = new RegExp(
|
|
147
|
+
`^\\s*#\\s*!(${ANNOTATION_TYPES.join('|')})(\\s*$begin:math:text$[^)]*\\$end:math:text$)?.*$`
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Removes CodeHike annotations from the code
|
|
152
|
+
* Useful for copying code / excluding annotations from clipboard
|
|
153
|
+
* @param code - The code string containing CodeHike annotations
|
|
154
|
+
* @returns Clean code string without annotations
|
|
155
|
+
*/
|
|
156
|
+
export function removeCodeHikeAnnotations(code: string): string {
|
|
157
|
+
const lines = code.split('\n')
|
|
158
|
+
const result: string[] = []
|
|
159
|
+
let skipEmpty = false
|
|
160
|
+
|
|
161
|
+
for (const line of lines) {
|
|
162
|
+
if (ANNOTATION_REGEX.test(line)) {
|
|
163
|
+
skipEmpty = true
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (line.trim() === '' && skipEmpty) {
|
|
168
|
+
skipEmpty = false
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
result.push(line)
|
|
173
|
+
skipEmpty = false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return result.join('\n')
|
|
177
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
2
|
+
export default function debounce(func: Function, wait: number) {
|
|
3
|
+
let timeout: ReturnType<typeof setTimeout>
|
|
4
|
+
|
|
5
|
+
return (...args: unknown[]) => {
|
|
6
|
+
clearTimeout(timeout)
|
|
7
|
+
timeout = setTimeout(() => func(...args), wait)
|
|
8
|
+
}
|
|
9
|
+
}
|