@acmekit/docs-ui 2.13.41
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/dist/Items-YPPZD6C6.mjs +312 -0
- package/dist/chunk-JD7BP7O5.mjs +13144 -0
- package/dist/index.d.mts +1550 -0
- package/dist/index.d.ts +1550 -0
- package/dist/index.js +15218 -0
- package/dist/index.mjs +366 -0
- package/package.json +58 -0
- package/src/components/Badge/index.tsx +74 -0
- package/src/components/BadgesList/index.tsx +18 -0
- package/src/components/BetaBadge/index.tsx +24 -0
- package/src/components/Bordered/index.tsx +21 -0
- package/src/components/BorderedIcon/index.tsx +60 -0
- package/src/components/Breadcrumbs/index.tsx +83 -0
- package/src/components/Button/index.tsx +100 -0
- package/src/components/Card/Layout/Default/index.tsx +124 -0
- package/src/components/Card/Layout/Filler/index.tsx +30 -0
- package/src/components/Card/Layout/Large/index.tsx +88 -0
- package/src/components/Card/Layout/Mini/index.tsx +142 -0
- package/src/components/Card/index.tsx +50 -0
- package/src/components/CardList/index.tsx +40 -0
- package/src/components/ChildDocs/index.tsx +9 -0
- package/src/components/CodeBlock/Actions/AskAi/index.tsx +10 -0
- package/src/components/CodeBlock/Actions/Copy/index.tsx +59 -0
- package/src/components/CodeBlock/Actions/index.tsx +137 -0
- package/src/components/CodeBlock/Collapsible/Button/index.tsx +58 -0
- package/src/components/CodeBlock/Collapsible/Fade/index.tsx +55 -0
- package/src/components/CodeBlock/Collapsible/Lines/index.tsx +22 -0
- package/src/components/CodeBlock/Header/Wrapper/index.tsx +46 -0
- package/src/components/CodeBlock/Header/index.tsx +67 -0
- package/src/components/CodeBlock/Inline/index.tsx +20 -0
- package/src/components/CodeBlock/Line/index.tsx +331 -0
- package/src/components/CodeBlock/index.tsx +510 -0
- package/src/components/CodeMdx/index.tsx +45 -0
- package/src/components/CodeTabs/Item/index.tsx +67 -0
- package/src/components/CodeTabs/index.tsx +319 -0
- package/src/components/ContentMenu/Actions/index.tsx +7 -0
- package/src/components/ContentMenu/Products/index.tsx +64 -0
- package/src/components/ContentMenu/Toc/index.tsx +148 -0
- package/src/components/ContentMenu/Version/index.tsx +77 -0
- package/src/components/ContentMenu/index.tsx +31 -0
- package/src/components/CopyButton/index.tsx +76 -0
- package/src/components/Details/Summary/index.tsx +75 -0
- package/src/components/Details/index.tsx +98 -0
- package/src/components/DetailsList/index.tsx +32 -0
- package/src/components/DottedSeparator/index.tsx +30 -0
- package/src/components/EditButton/index.tsx +32 -0
- package/src/components/EditDate/index.tsx +33 -0
- package/src/components/ErrorPage/Icon/index.tsx +428 -0
- package/src/components/ErrorPage/index.tsx +32 -0
- package/src/components/Feedback/Solutions/index.tsx +105 -0
- package/src/components/Feedback/index.tsx +304 -0
- package/src/components/Footer/index.tsx +23 -0
- package/src/components/Heading/H1/index.tsx +21 -0
- package/src/components/Heading/H2/index.tsx +47 -0
- package/src/components/Heading/H3/index.tsx +42 -0
- package/src/components/Heading/H4/index.tsx +14 -0
- package/src/components/Heading/index.tsx +4 -0
- package/src/components/IconHeadline/index.tsx +15 -0
- package/src/components/Icons/AiAssistant/index.tsx +462 -0
- package/src/components/Icons/ArrowRightDown/index.tsx +30 -0
- package/src/components/Icons/BundledProduct/index.tsx +72 -0
- package/src/components/Icons/CalendarRefresh/index.tsx +70 -0
- package/src/components/Icons/ChefHat/index.tsx +65 -0
- package/src/components/Icons/CircleDottedLine/index.tsx +60 -0
- package/src/components/Icons/CloudSolid/index.tsx +47 -0
- package/src/components/Icons/ColoredAcmeKit/index.tsx +13 -0
- package/src/components/Icons/DecisionProcess/index.tsx +58 -0
- package/src/components/Icons/Erp/index.tsx +92 -0
- package/src/components/Icons/Github/index.tsx +22 -0
- package/src/components/Icons/House/index.tsx +23 -0
- package/src/components/Icons/ImageBinary/index.tsx +69 -0
- package/src/components/Icons/Kapa/index.tsx +22 -0
- package/src/components/Icons/Markdown/index.tsx +25 -0
- package/src/components/Icons/NavigationDropdown/Admin/index.tsx +33 -0
- package/src/components/Icons/NavigationDropdown/Doc/index.tsx +41 -0
- package/src/components/Icons/NavigationDropdown/DocV1/index.tsx +37 -0
- package/src/components/Icons/NavigationDropdown/Modules/index.tsx +33 -0
- package/src/components/Icons/NavigationDropdown/Resources/index.tsx +37 -0
- package/src/components/Icons/NavigationDropdown/Store/index.tsx +37 -0
- package/src/components/Icons/NavigationDropdown/Ui/index.tsx +37 -0
- package/src/components/Icons/NavigationDropdown/User/index.tsx +37 -0
- package/src/components/Icons/PuzzleColored/index.tsx +35 -0
- package/src/components/Icons/QuestionMark/index.tsx +23 -0
- package/src/components/Icons/Restock/index.tsx +55 -0
- package/src/components/Icons/ScrollText/index.tsx +68 -0
- package/src/components/Icons/ShadedBg/index.tsx +334 -0
- package/src/components/Icons/Shop/index.tsx +68 -0
- package/src/components/Icons/SidebarLeft/index.tsx +42 -0
- package/src/components/Icons/StripeColored/index.tsx +60 -0
- package/src/components/Icons/ThumbDown/index.tsx +23 -0
- package/src/components/Icons/ThumbUp/index.tsx +23 -0
- package/src/components/Icons/WindowPaintbrush/index.tsx +57 -0
- package/src/components/Icons/index.tsx +20 -0
- package/src/components/InlineCode/index.tsx +42 -0
- package/src/components/InlineIcon/index.tsx +21 -0
- package/src/components/InlineThemeImage/index.tsx +14 -0
- package/src/components/Input/Search/index.tsx +64 -0
- package/src/components/Input/Text/index.tsx +39 -0
- package/src/components/Kbd/index.tsx +33 -0
- package/src/components/Label/index.tsx +19 -0
- package/src/components/Link/index.tsx +67 -0
- package/src/components/LinkButton/index.tsx +43 -0
- package/src/components/Loading/Dots/index.tsx +16 -0
- package/src/components/Loading/Spinner/index.tsx +19 -0
- package/src/components/Loading/index.tsx +43 -0
- package/src/components/MDXComponents/index.tsx +209 -0
- package/src/components/MainNav/DesktopMenu/ThemeMenu/index.tsx +76 -0
- package/src/components/MainNav/DesktopMenu/index.tsx +100 -0
- package/src/components/MainNav/Items/Dropdown/index.tsx +88 -0
- package/src/components/MainNav/Items/Link/index.tsx +34 -0
- package/src/components/MainNav/Items/index.tsx +61 -0
- package/src/components/MainNav/MobileMenu/Main/index.tsx +67 -0
- package/src/components/MainNav/MobileMenu/SubMenu/index.tsx +77 -0
- package/src/components/MainNav/MobileMenu/index.tsx +103 -0
- package/src/components/MainNav/Version/index.tsx +33 -0
- package/src/components/MainNav/index.tsx +153 -0
- package/src/components/MarkdownContent/index.tsx +41 -0
- package/src/components/Menu/Action/index.tsx +43 -0
- package/src/components/Menu/Divider/index.tsx +35 -0
- package/src/components/Menu/Dropdown/index.tsx +78 -0
- package/src/components/Menu/Item/index.tsx +36 -0
- package/src/components/Menu/SubMenu/index.tsx +47 -0
- package/src/components/Menu/index.tsx +44 -0
- package/src/components/Modal/Footer/index.tsx +29 -0
- package/src/components/Modal/Header/index.tsx +33 -0
- package/src/components/Modal/index.tsx +124 -0
- package/src/components/Note/Layout/index.tsx +139 -0
- package/src/components/Note/Types/checks.tsx +7 -0
- package/src/components/Note/Types/default.tsx +7 -0
- package/src/components/Note/Types/error.tsx +7 -0
- package/src/components/Note/Types/soon.tsx +7 -0
- package/src/components/Note/Types/sucess.tsx +7 -0
- package/src/components/Note/Types/warning.tsx +7 -0
- package/src/components/Note/index.tsx +32 -0
- package/src/components/Notices/DeprecatedNotice/index.tsx +33 -0
- package/src/components/Notices/ExpandableNotice/index.tsx +36 -0
- package/src/components/Notices/FeatureFlagNotice/index.tsx +36 -0
- package/src/components/Notices/VersionNotice/index.tsx +37 -0
- package/src/components/Notification/Item/Layout/Default/index.tsx +89 -0
- package/src/components/Notification/Item/index.tsx +88 -0
- package/src/components/Notification/index.tsx +65 -0
- package/src/components/Pagination/Card/index.tsx +80 -0
- package/src/components/Pagination/index.tsx +35 -0
- package/src/components/Prerequisites/Item/index.tsx +43 -0
- package/src/components/Prerequisites/index.tsx +94 -0
- package/src/components/RadioItem/index.tsx +38 -0
- package/src/components/Rating/index.tsx +133 -0
- package/src/components/RootProviders/index.tsx +31 -0
- package/src/components/Select/Badge/index.tsx +122 -0
- package/src/components/Select/Dropdown/index.tsx +188 -0
- package/src/components/Select/Input/index.tsx +123 -0
- package/src/components/Select/index.ts +13 -0
- package/src/components/Sidebar/Child/index.tsx +43 -0
- package/src/components/Sidebar/Item/Category/index.tsx +151 -0
- package/src/components/Sidebar/Item/Link/index.tsx +174 -0
- package/src/components/Sidebar/Item/Sidebar/index.tsx +67 -0
- package/src/components/Sidebar/Item/SubCategory/index.tsx +83 -0
- package/src/components/Sidebar/Item/index.tsx +41 -0
- package/src/components/Sidebar/Top/MobileClose/index.tsx +21 -0
- package/src/components/Sidebar/Top/index.tsx +33 -0
- package/src/components/Sidebar/index.tsx +153 -0
- package/src/components/SourceCodeLink/index.tsx +37 -0
- package/src/components/SplitLists/index.tsx +58 -0
- package/src/components/Table/index.tsx +87 -0
- package/src/components/Tabs/index.tsx +106 -0
- package/src/components/TextArea/index.tsx +30 -0
- package/src/components/ThemeImage/index.tsx +26 -0
- package/src/components/Toggle/index.tsx +28 -0
- package/src/components/Tooltip/index.tsx +65 -0
- package/src/components/TypeList/Items/index.tsx +337 -0
- package/src/components/TypeList/index.tsx +63 -0
- package/src/components/WideSection/index.tsx +25 -0
- package/src/components/ZoomImg/index.tsx +17 -0
- package/src/components/index.ts +75 -0
- package/src/constants.tsx +261 -0
- package/src/global-config.ts +11 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/use-active-on-scroll/index.tsx +223 -0
- package/src/hooks/use-click-outside/index.tsx +37 -0
- package/src/hooks/use-collapsible/index.tsx +128 -0
- package/src/hooks/use-collapsible-code-lines/index.tsx +149 -0
- package/src/hooks/use-copy/index.tsx +28 -0
- package/src/hooks/use-heading-url/index.tsx +32 -0
- package/src/hooks/use-is-external-link/index.tsx +19 -0
- package/src/hooks/use-keyboard-shortcut/index.tsx +71 -0
- package/src/hooks/use-mutation-observer/index.ts +32 -0
- package/src/hooks/use-page-scroll-manager/index.tsx +82 -0
- package/src/hooks/use-resize-observer/index.ts +20 -0
- package/src/hooks/use-scroll-utils/index.tsx +372 -0
- package/src/hooks/use-select/index.tsx +99 -0
- package/src/hooks/use-tabs/index.tsx +94 -0
- package/src/index.ts +8 -0
- package/src/layouts/barebone.tsx +18 -0
- package/src/layouts/index.ts +4 -0
- package/src/layouts/main-content.tsx +86 -0
- package/src/layouts/root.tsx +43 -0
- package/src/layouts/tight.tsx +29 -0
- package/src/layouts/wide.tsx +25 -0
- package/src/providers/AiAssistant/index.tsx +65 -0
- package/src/providers/BrowserProvider/index.tsx +40 -0
- package/src/providers/ColorMode/index.tsx +73 -0
- package/src/providers/Layout/index.tsx +52 -0
- package/src/providers/MainNav/index.tsx +134 -0
- package/src/providers/Mobile/index.tsx +62 -0
- package/src/providers/Modal/index.tsx +52 -0
- package/src/providers/Notification/index.tsx +149 -0
- package/src/providers/Pagination/index.tsx +230 -0
- package/src/providers/Search/index.tsx +91 -0
- package/src/providers/Sidebar/index.tsx +745 -0
- package/src/providers/SiteConfig/index.tsx +70 -0
- package/src/providers/index.ts +13 -0
- package/src/types/config.ts +34 -0
- package/src/types/frontmatter.ts +23 -0
- package/src/types/general.ts +1 -0
- package/src/types/index.ts +9 -0
- package/src/types/menu.ts +40 -0
- package/src/types/navigation-dropdown.ts +16 -0
- package/src/types/navigation.ts +21 -0
- package/src/types/sidebar.ts +109 -0
- package/src/types/toc.ts +19 -0
- package/src/types/ui.ts +9 -0
- package/src/utils/array-same-elms.ts +10 -0
- package/src/utils/capitalize.ts +3 -0
- package/src/utils/check-sidebar-item-visibility.ts +47 -0
- package/src/utils/decode-str.ts +8 -0
- package/src/utils/dom-utils.ts +29 -0
- package/src/utils/event-parser.ts +54 -0
- package/src/utils/get-link-with-base-path.ts +3 -0
- package/src/utils/get-navbar-items.ts +55 -0
- package/src/utils/get-scrolled-top.ts +8 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/is-elm-window.ts +3 -0
- package/src/utils/is-in-view.ts +10 -0
- package/src/utils/os-browser-utils.ts +39 -0
- package/src/utils/set-obj-value.ts +38 -0
- package/src/utils/sidebar-utils.ts +129 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { useEffect, useMemo, useRef, useState } from "react"
|
|
3
|
+
import clsx from "clsx"
|
|
4
|
+
import { Highlight, HighlightProps, themes, Token } from "prism-react-renderer"
|
|
5
|
+
import { useColorMode } from "../../providers/ColorMode"
|
|
6
|
+
import { CodeBlockHeader, CodeBlockHeaderMeta } from "./Header"
|
|
7
|
+
import { CodeBlockLine } from "./Line"
|
|
8
|
+
type ApiMethod = string
|
|
9
|
+
type ApiAuthType = string
|
|
10
|
+
type ApiDataOptions = Record<string, unknown>
|
|
11
|
+
// @ts-expect-error can't install the types package because it doesn't support React v19
|
|
12
|
+
import { CSSTransition } from "react-transition-group"
|
|
13
|
+
import { DocsTrackingEvents } from "../../constants"
|
|
14
|
+
import { useCollapsibleCodeLines } from "../../hooks/use-collapsible-code-lines"
|
|
15
|
+
import { HighlightProps as CollapsibleHighlightProps } from "../../hooks/use-collapsible-code-lines"
|
|
16
|
+
import { CodeBlockActions, CodeBlockActionsProps } from "./Actions"
|
|
17
|
+
import { CodeBlockCollapsibleButton } from "./Collapsible/Button"
|
|
18
|
+
import { CodeBlockCollapsibleFade } from "./Collapsible/Fade"
|
|
19
|
+
import { CodeBlockInline } from "./Inline"
|
|
20
|
+
|
|
21
|
+
export type Highlight = {
|
|
22
|
+
line: number
|
|
23
|
+
text?: string
|
|
24
|
+
tooltipText?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type CodeBlockMetaFields = {
|
|
28
|
+
title?: string
|
|
29
|
+
hasTabs?: boolean
|
|
30
|
+
npm2yarn?: boolean
|
|
31
|
+
npx2yarn?: boolean
|
|
32
|
+
npx2yarnExec?: boolean
|
|
33
|
+
highlights?: string[][]
|
|
34
|
+
apiTesting?: boolean
|
|
35
|
+
testApiMethod?: ApiMethod
|
|
36
|
+
testApiUrl?: string
|
|
37
|
+
testAuthType?: ApiAuthType
|
|
38
|
+
testPathParams?: ApiDataOptions
|
|
39
|
+
testQueryParams?: ApiDataOptions
|
|
40
|
+
testBodyParams?: ApiDataOptions
|
|
41
|
+
noCopy?: boolean
|
|
42
|
+
noReport?: boolean
|
|
43
|
+
noLineNumbers?: boolean
|
|
44
|
+
noAskAi?: boolean
|
|
45
|
+
collapsibleLines?: string
|
|
46
|
+
expandButtonLabel?: string
|
|
47
|
+
isTerminal?: boolean
|
|
48
|
+
forceNoTitle?: boolean
|
|
49
|
+
collapsed?: boolean
|
|
50
|
+
wrapperClassName?: string
|
|
51
|
+
} & CodeBlockHeaderMeta
|
|
52
|
+
|
|
53
|
+
export type CodeBlockStyle = "loud" | "subtle" | "inline"
|
|
54
|
+
|
|
55
|
+
export type CodeBlockProps = {
|
|
56
|
+
source: string
|
|
57
|
+
lang?: string
|
|
58
|
+
innerClassName?: string
|
|
59
|
+
className?: string
|
|
60
|
+
blockStyle?: CodeBlockStyle
|
|
61
|
+
children?: React.ReactNode
|
|
62
|
+
style?: React.HTMLAttributes<HTMLDivElement>["style"]
|
|
63
|
+
animateTokenHighlights?: boolean
|
|
64
|
+
overrideColors?: {
|
|
65
|
+
bg?: string
|
|
66
|
+
innerBg?: string
|
|
67
|
+
lineNumbersBg?: string
|
|
68
|
+
border?: string
|
|
69
|
+
innerBorder?: string
|
|
70
|
+
boxShadow?: string
|
|
71
|
+
}
|
|
72
|
+
} & CodeBlockMetaFields &
|
|
73
|
+
Omit<HighlightProps, "code" | "language" | "children">
|
|
74
|
+
|
|
75
|
+
export const CodeBlock = ({
|
|
76
|
+
source,
|
|
77
|
+
hasTabs = false,
|
|
78
|
+
lang = "",
|
|
79
|
+
wrapperClassName,
|
|
80
|
+
innerClassName,
|
|
81
|
+
className,
|
|
82
|
+
overrideColors = {},
|
|
83
|
+
collapsed = false,
|
|
84
|
+
title = "",
|
|
85
|
+
highlights = [],
|
|
86
|
+
apiTesting = false,
|
|
87
|
+
blockStyle = "loud",
|
|
88
|
+
noCopy = false,
|
|
89
|
+
noReport = false,
|
|
90
|
+
noLineNumbers = false,
|
|
91
|
+
children,
|
|
92
|
+
collapsibleLines,
|
|
93
|
+
expandButtonLabel,
|
|
94
|
+
isTerminal,
|
|
95
|
+
style,
|
|
96
|
+
forceNoTitle = false,
|
|
97
|
+
animateTokenHighlights,
|
|
98
|
+
noAskAi = false,
|
|
99
|
+
...rest
|
|
100
|
+
}: CodeBlockProps) => {
|
|
101
|
+
if (!source && typeof children === "string") {
|
|
102
|
+
source = children
|
|
103
|
+
}
|
|
104
|
+
if (blockStyle === "inline") {
|
|
105
|
+
return <CodeBlockInline source={source} />
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const { colorMode } = useColorMode()
|
|
109
|
+
const track = (..._args: any[]) => {}
|
|
110
|
+
const [showTesting, setShowTesting] = useState(false)
|
|
111
|
+
const codeContainerRef = useRef<HTMLDivElement>(null)
|
|
112
|
+
const codeRef = useRef<HTMLElement>(null)
|
|
113
|
+
const apiRunnerRef = useRef<HTMLDivElement>(null)
|
|
114
|
+
const [scrollable, setScrollable] = useState(false)
|
|
115
|
+
const isTerminalCode = useMemo(() => {
|
|
116
|
+
return isTerminal === undefined
|
|
117
|
+
? lang === "bash" && !source.startsWith("curl")
|
|
118
|
+
: isTerminal
|
|
119
|
+
}, [isTerminal, lang])
|
|
120
|
+
const codeTitle = useMemo(() => {
|
|
121
|
+
if (forceNoTitle) {
|
|
122
|
+
return ""
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (title) {
|
|
126
|
+
return title
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (hasTabs) {
|
|
130
|
+
return ""
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isTerminalCode) {
|
|
134
|
+
return "Terminal"
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return "Code"
|
|
138
|
+
}, [title, isTerminalCode, hasTabs, forceNoTitle])
|
|
139
|
+
const hasInnerCodeBlock = useMemo(
|
|
140
|
+
() => hasTabs || codeTitle.length > 0,
|
|
141
|
+
[hasTabs, codeTitle]
|
|
142
|
+
)
|
|
143
|
+
const canShowApiTesting = useMemo(
|
|
144
|
+
() =>
|
|
145
|
+
apiTesting !== undefined &&
|
|
146
|
+
rest.testApiMethod !== undefined &&
|
|
147
|
+
rest.testApiUrl !== undefined,
|
|
148
|
+
[apiTesting, rest]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
const bgColor = useMemo(
|
|
152
|
+
() =>
|
|
153
|
+
clsx(
|
|
154
|
+
overrideColors.bg,
|
|
155
|
+
!overrideColors.bg && [
|
|
156
|
+
blockStyle === "loud" && "bg-acmekit-contrast-bg-base",
|
|
157
|
+
blockStyle === "subtle" && [
|
|
158
|
+
colorMode === "light" && "bg-acmekit-bg-subtle",
|
|
159
|
+
colorMode === "dark" && "bg-acmekit-code-bg-base",
|
|
160
|
+
],
|
|
161
|
+
]
|
|
162
|
+
),
|
|
163
|
+
[blockStyle, colorMode, overrideColors]
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const lineNumbersColor = useMemo(
|
|
167
|
+
() =>
|
|
168
|
+
clsx(
|
|
169
|
+
overrideColors.lineNumbersBg,
|
|
170
|
+
!overrideColors.lineNumbersBg && [
|
|
171
|
+
blockStyle === "loud" && "text-acmekit-contrast-fg-secondary",
|
|
172
|
+
blockStyle === "subtle" && [
|
|
173
|
+
colorMode === "light" && "text-acmekit-fg-muted",
|
|
174
|
+
colorMode === "dark" && "text-acmekit-contrast-fg-secondary",
|
|
175
|
+
],
|
|
176
|
+
]
|
|
177
|
+
),
|
|
178
|
+
[blockStyle, colorMode, overrideColors]
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
const borderColor = useMemo(
|
|
182
|
+
() =>
|
|
183
|
+
clsx(
|
|
184
|
+
overrideColors.border,
|
|
185
|
+
!overrideColors.border && [
|
|
186
|
+
blockStyle === "loud" && "border-0",
|
|
187
|
+
blockStyle === "subtle" && [
|
|
188
|
+
colorMode === "light" && "border-acmekit-border-base",
|
|
189
|
+
colorMode === "dark" && "border-acmekit-code-border",
|
|
190
|
+
],
|
|
191
|
+
]
|
|
192
|
+
),
|
|
193
|
+
[blockStyle, colorMode, overrideColors]
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
const boxShadow = useMemo(
|
|
197
|
+
() =>
|
|
198
|
+
clsx(
|
|
199
|
+
overrideColors.boxShadow,
|
|
200
|
+
!overrideColors.boxShadow && [
|
|
201
|
+
blockStyle === "loud" &&
|
|
202
|
+
"shadow-elevation-code-block dark:shadow-elevation-code-block-dark",
|
|
203
|
+
blockStyle === "subtle" && "shadow-none",
|
|
204
|
+
]
|
|
205
|
+
),
|
|
206
|
+
[blockStyle, overrideColors]
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
const innerBgColor = useMemo(
|
|
210
|
+
() =>
|
|
211
|
+
clsx(
|
|
212
|
+
overrideColors.innerBg,
|
|
213
|
+
!overrideColors.innerBg && [
|
|
214
|
+
blockStyle === "loud" && [
|
|
215
|
+
hasInnerCodeBlock && "bg-acmekit-contrast-bg-subtle",
|
|
216
|
+
!hasInnerCodeBlock && "bg-acmekit-contrast-bg-base",
|
|
217
|
+
],
|
|
218
|
+
blockStyle === "subtle" && bgColor,
|
|
219
|
+
]
|
|
220
|
+
),
|
|
221
|
+
[blockStyle, bgColor, hasInnerCodeBlock, overrideColors]
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
const innerBorderClasses = useMemo(
|
|
225
|
+
() =>
|
|
226
|
+
clsx(
|
|
227
|
+
overrideColors.innerBorder,
|
|
228
|
+
!overrideColors.innerBorder && [
|
|
229
|
+
blockStyle === "loud" && [
|
|
230
|
+
hasInnerCodeBlock &&
|
|
231
|
+
"border border-solid border-acmekit-contrast-border-bot rounded-docs_DEFAULT",
|
|
232
|
+
!hasInnerCodeBlock && "border-transparent rounded-docs_DEFAULT",
|
|
233
|
+
],
|
|
234
|
+
blockStyle === "subtle" && "border-transparent rounded-docs_DEFAULT",
|
|
235
|
+
]
|
|
236
|
+
),
|
|
237
|
+
[blockStyle, hasInnerCodeBlock, overrideColors]
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
const language = useMemo(() => {
|
|
241
|
+
const lowerLang = lang.toLowerCase()
|
|
242
|
+
|
|
243
|
+
// due to a hydration error in json, for now we just assign it to plain
|
|
244
|
+
return lowerLang === "json" ? "plain" : lowerLang
|
|
245
|
+
}, [lang])
|
|
246
|
+
|
|
247
|
+
const transformedHighlights: Highlight[] = highlights
|
|
248
|
+
.filter((highlight) => highlight.length !== 0)
|
|
249
|
+
.map((highlight) => ({
|
|
250
|
+
line: parseInt(highlight[0]),
|
|
251
|
+
text: highlight.length >= 2 ? highlight[1] : undefined,
|
|
252
|
+
tooltipText: highlight.length >= 3 ? highlight[2] : undefined,
|
|
253
|
+
}))
|
|
254
|
+
|
|
255
|
+
const getLines = (
|
|
256
|
+
tokens: Token[][],
|
|
257
|
+
highlightProps: CollapsibleHighlightProps,
|
|
258
|
+
lineNumberOffset = 0
|
|
259
|
+
) =>
|
|
260
|
+
tokens.map((line, i) => {
|
|
261
|
+
const offsettedLineNumber = i + lineNumberOffset
|
|
262
|
+
const highlightedLines = transformedHighlights.filter(
|
|
263
|
+
(highlight) => highlight.line - 1 === offsettedLineNumber
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<CodeBlockLine
|
|
268
|
+
line={line}
|
|
269
|
+
lineNumber={offsettedLineNumber}
|
|
270
|
+
highlights={highlightedLines}
|
|
271
|
+
showLineNumber={!noLineNumbers && tokens.length > 1}
|
|
272
|
+
key={offsettedLineNumber}
|
|
273
|
+
lineNumberColorClassName={lineNumbersColor}
|
|
274
|
+
lineNumberBgClassName={innerBgColor}
|
|
275
|
+
isTerminal={isTerminalCode}
|
|
276
|
+
animateTokenHighlights={animateTokenHighlights}
|
|
277
|
+
{...highlightProps}
|
|
278
|
+
/>
|
|
279
|
+
)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
const {
|
|
283
|
+
getCollapsedLinesElm,
|
|
284
|
+
getNonCollapsedLinesElm,
|
|
285
|
+
type: collapsibleType,
|
|
286
|
+
isCollapsible,
|
|
287
|
+
...collapsibleResult
|
|
288
|
+
} = useCollapsibleCodeLines({
|
|
289
|
+
collapsibleLinesStr: collapsibleLines,
|
|
290
|
+
getLines,
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (!codeContainerRef.current || !codeRef.current) {
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
setScrollable(
|
|
299
|
+
codeContainerRef.current.scrollWidth < codeRef.current.clientWidth
|
|
300
|
+
)
|
|
301
|
+
}, [codeContainerRef.current, codeRef.current])
|
|
302
|
+
|
|
303
|
+
const trackCopy = () => {
|
|
304
|
+
track({
|
|
305
|
+
event: {
|
|
306
|
+
event: DocsTrackingEvents.CODE_BLOCK_COPY,
|
|
307
|
+
options: {
|
|
308
|
+
text: source.substring(0, 150),
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const actionsProps: Omit<CodeBlockActionsProps, "inHeader"> = useMemo(
|
|
315
|
+
() => ({
|
|
316
|
+
source,
|
|
317
|
+
canShowApiTesting,
|
|
318
|
+
onApiTesting: setShowTesting,
|
|
319
|
+
blockStyle,
|
|
320
|
+
noReport,
|
|
321
|
+
noCopy,
|
|
322
|
+
isCollapsed: collapsibleType !== undefined && collapsibleResult.collapsed,
|
|
323
|
+
inInnerCode: hasInnerCodeBlock,
|
|
324
|
+
showGradientBg: scrollable,
|
|
325
|
+
noAskAi,
|
|
326
|
+
}),
|
|
327
|
+
[
|
|
328
|
+
source,
|
|
329
|
+
canShowApiTesting,
|
|
330
|
+
setShowTesting,
|
|
331
|
+
noReport,
|
|
332
|
+
noCopy,
|
|
333
|
+
collapsibleType,
|
|
334
|
+
collapsibleResult,
|
|
335
|
+
hasInnerCodeBlock,
|
|
336
|
+
scrollable,
|
|
337
|
+
noAskAi,
|
|
338
|
+
]
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
const codeTheme = useMemo(() => {
|
|
342
|
+
const prismTheme =
|
|
343
|
+
blockStyle === "loud" || colorMode === "dark"
|
|
344
|
+
? themes.vsDark
|
|
345
|
+
: themes.vsLight
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
...prismTheme,
|
|
349
|
+
plain: {
|
|
350
|
+
...prismTheme,
|
|
351
|
+
color:
|
|
352
|
+
colorMode === "light"
|
|
353
|
+
? "rgba(255, 255, 255, 0.88)"
|
|
354
|
+
: "rgba(250, 250, 250, 1)",
|
|
355
|
+
},
|
|
356
|
+
}
|
|
357
|
+
}, [blockStyle, colorMode])
|
|
358
|
+
|
|
359
|
+
if (!source.length) {
|
|
360
|
+
return <></>
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<>
|
|
365
|
+
<div
|
|
366
|
+
className={clsx(
|
|
367
|
+
hasInnerCodeBlock && "rounded-docs_lg",
|
|
368
|
+
!hasInnerCodeBlock && "rounded-docs_DEFAULT",
|
|
369
|
+
!hasTabs && boxShadow,
|
|
370
|
+
blockStyle === "loud" && "code-block-highlight",
|
|
371
|
+
blockStyle === "subtle" &&
|
|
372
|
+
colorMode === "light" &&
|
|
373
|
+
"code-block-highlight-light",
|
|
374
|
+
wrapperClassName
|
|
375
|
+
)}
|
|
376
|
+
data-testid="code-block"
|
|
377
|
+
>
|
|
378
|
+
{codeTitle && (
|
|
379
|
+
<CodeBlockHeader
|
|
380
|
+
title={codeTitle}
|
|
381
|
+
blockStyle={blockStyle}
|
|
382
|
+
badgeLabel={rest.badgeLabel}
|
|
383
|
+
badgeColor={rest.badgeColor}
|
|
384
|
+
actionsProps={{
|
|
385
|
+
...actionsProps,
|
|
386
|
+
inHeader: true,
|
|
387
|
+
}}
|
|
388
|
+
hideActions={hasTabs}
|
|
389
|
+
/>
|
|
390
|
+
)}
|
|
391
|
+
<div
|
|
392
|
+
className={clsx(
|
|
393
|
+
"relative mb-docs_1",
|
|
394
|
+
"w-full max-w-full border code-block-elm",
|
|
395
|
+
bgColor,
|
|
396
|
+
borderColor,
|
|
397
|
+
collapsed && "max-h-[400px] overflow-auto",
|
|
398
|
+
hasInnerCodeBlock && "p-[5px] !pt-0 rounded-b-docs_lg",
|
|
399
|
+
!hasInnerCodeBlock && "rounded-docs_DEFAULT",
|
|
400
|
+
className
|
|
401
|
+
)}
|
|
402
|
+
style={style}
|
|
403
|
+
data-testid="code-block-inner"
|
|
404
|
+
>
|
|
405
|
+
<Highlight
|
|
406
|
+
theme={codeTheme}
|
|
407
|
+
code={source.trim()}
|
|
408
|
+
language={language}
|
|
409
|
+
{...rest}
|
|
410
|
+
>
|
|
411
|
+
{({
|
|
412
|
+
className: preClassName,
|
|
413
|
+
style: { backgroundColor: _, ...style },
|
|
414
|
+
tokens,
|
|
415
|
+
...rest
|
|
416
|
+
}) => (
|
|
417
|
+
<div
|
|
418
|
+
className={clsx(
|
|
419
|
+
innerBorderClasses,
|
|
420
|
+
innerBgColor,
|
|
421
|
+
"relative",
|
|
422
|
+
innerClassName
|
|
423
|
+
)}
|
|
424
|
+
ref={codeContainerRef}
|
|
425
|
+
>
|
|
426
|
+
{collapsibleType === "start" && (
|
|
427
|
+
<>
|
|
428
|
+
<CodeBlockCollapsibleButton
|
|
429
|
+
type={collapsibleType}
|
|
430
|
+
expandButtonLabel={expandButtonLabel}
|
|
431
|
+
className={innerBorderClasses}
|
|
432
|
+
{...collapsibleResult}
|
|
433
|
+
/>
|
|
434
|
+
<CodeBlockCollapsibleFade
|
|
435
|
+
type={collapsibleType}
|
|
436
|
+
collapsed={collapsibleResult.collapsed}
|
|
437
|
+
hasHeader={hasInnerCodeBlock}
|
|
438
|
+
/>
|
|
439
|
+
</>
|
|
440
|
+
)}
|
|
441
|
+
<pre
|
|
442
|
+
style={{ ...style, fontStretch: "100%" }}
|
|
443
|
+
className={clsx(
|
|
444
|
+
"relative !my-0 break-words bg-transparent !outline-none",
|
|
445
|
+
"overflow-auto break-words p-0 pr-docs_0.25",
|
|
446
|
+
"rounded-docs_DEFAULT",
|
|
447
|
+
!hasInnerCodeBlock &&
|
|
448
|
+
tokens.length <= 1 &&
|
|
449
|
+
"px-docs_1 py-[6px]",
|
|
450
|
+
(noLineNumbers ||
|
|
451
|
+
(tokens.length <= 1 && !isTerminalCode)) &&
|
|
452
|
+
"pl-docs_1",
|
|
453
|
+
preClassName
|
|
454
|
+
)}
|
|
455
|
+
onCopy={trackCopy}
|
|
456
|
+
>
|
|
457
|
+
<code
|
|
458
|
+
className={clsx(
|
|
459
|
+
"text-code-body font-monospace table min-w-full print:whitespace-pre-wrap",
|
|
460
|
+
"py-docs_0.75"
|
|
461
|
+
)}
|
|
462
|
+
ref={codeRef}
|
|
463
|
+
>
|
|
464
|
+
{collapsibleType === "start" &&
|
|
465
|
+
getCollapsedLinesElm({
|
|
466
|
+
tokens,
|
|
467
|
+
highlightProps: rest,
|
|
468
|
+
})}
|
|
469
|
+
{getNonCollapsedLinesElm({
|
|
470
|
+
tokens,
|
|
471
|
+
highlightProps: rest,
|
|
472
|
+
})}
|
|
473
|
+
{collapsibleType === "end" &&
|
|
474
|
+
getCollapsedLinesElm({
|
|
475
|
+
tokens,
|
|
476
|
+
highlightProps: rest,
|
|
477
|
+
})}
|
|
478
|
+
</code>
|
|
479
|
+
</pre>
|
|
480
|
+
{!hasInnerCodeBlock &&
|
|
481
|
+
(!noCopy || !noReport || canShowApiTesting || !noAskAi) && (
|
|
482
|
+
<CodeBlockActions
|
|
483
|
+
{...actionsProps}
|
|
484
|
+
inHeader={false}
|
|
485
|
+
isSingleLine={tokens.length <= 1}
|
|
486
|
+
/>
|
|
487
|
+
)}
|
|
488
|
+
{collapsibleType === "end" && isCollapsible(tokens) && (
|
|
489
|
+
<>
|
|
490
|
+
<CodeBlockCollapsibleFade
|
|
491
|
+
type={collapsibleType}
|
|
492
|
+
collapsed={collapsibleResult.collapsed}
|
|
493
|
+
hasHeader={hasInnerCodeBlock}
|
|
494
|
+
/>
|
|
495
|
+
<CodeBlockCollapsibleButton
|
|
496
|
+
type={collapsibleType}
|
|
497
|
+
expandButtonLabel={expandButtonLabel}
|
|
498
|
+
className={innerBorderClasses}
|
|
499
|
+
{...collapsibleResult}
|
|
500
|
+
/>
|
|
501
|
+
</>
|
|
502
|
+
)}
|
|
503
|
+
</div>
|
|
504
|
+
)}
|
|
505
|
+
</Highlight>
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
</>
|
|
509
|
+
)
|
|
510
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import {
|
|
3
|
+
CodeBlock,
|
|
4
|
+
CodeBlockMetaFields,
|
|
5
|
+
CodeBlockProps,
|
|
6
|
+
} from "../../components/CodeBlock"
|
|
7
|
+
import { InlineCode, InlineCodeProps } from "../../components/InlineCode"
|
|
8
|
+
|
|
9
|
+
export type CodeMdxProps = {
|
|
10
|
+
className?: string
|
|
11
|
+
children?: React.ReactNode
|
|
12
|
+
inlineCodeProps?: Partial<InlineCodeProps>
|
|
13
|
+
codeBlockProps?: Partial<CodeBlockProps>
|
|
14
|
+
} & CodeBlockMetaFields
|
|
15
|
+
|
|
16
|
+
export const CodeMdx = ({
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
inlineCodeProps = {},
|
|
20
|
+
codeBlockProps = {},
|
|
21
|
+
...rest
|
|
22
|
+
}: CodeMdxProps) => {
|
|
23
|
+
if (!children) {
|
|
24
|
+
return <></>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const match = /language-(\w+)/.exec(className || "")
|
|
28
|
+
|
|
29
|
+
const codeContent = Array.isArray(children)
|
|
30
|
+
? (children[0] as string)
|
|
31
|
+
: (children as string)
|
|
32
|
+
|
|
33
|
+
if (match) {
|
|
34
|
+
return (
|
|
35
|
+
<CodeBlock
|
|
36
|
+
source={codeContent}
|
|
37
|
+
lang={match[1]}
|
|
38
|
+
{...codeBlockProps}
|
|
39
|
+
{...rest}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return <InlineCode {...inlineCodeProps}>{codeContent}</InlineCode>
|
|
45
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
import React from "react"
|
|
3
|
+
import { useColorMode } from "../../../providers/ColorMode"
|
|
4
|
+
import clsx from "clsx"
|
|
5
|
+
import { BaseTabType } from "../../../hooks/use-tabs"
|
|
6
|
+
import { useScrollPositionBlocker } from "../../../hooks/use-scroll-utils"
|
|
7
|
+
|
|
8
|
+
type CodeTabProps = BaseTabType & {
|
|
9
|
+
// Children are handled in MDX to allow for code blocks and inline code to be rendered
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
isSelected?: boolean
|
|
12
|
+
blockStyle?: string
|
|
13
|
+
changeSelectedTab?: (tab: BaseTabType) => void
|
|
14
|
+
pushRef?: (tabButton: HTMLButtonElement | null) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const CodeTab = ({
|
|
18
|
+
label,
|
|
19
|
+
value,
|
|
20
|
+
isSelected = false,
|
|
21
|
+
blockStyle = "loud",
|
|
22
|
+
changeSelectedTab,
|
|
23
|
+
pushRef,
|
|
24
|
+
}: CodeTabProps) => {
|
|
25
|
+
const { colorMode } = useColorMode()
|
|
26
|
+
const { blockElementScrollPositionUntilNextRender } =
|
|
27
|
+
useScrollPositionBlocker()
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<li>
|
|
31
|
+
<button
|
|
32
|
+
className={clsx(
|
|
33
|
+
"text-compact-x-small-plus font-base xs:border-0 pb-docs_0.5 relative",
|
|
34
|
+
!isSelected && [
|
|
35
|
+
blockStyle === "loud" && "text-acmekit-contrast-fg-secondary",
|
|
36
|
+
blockStyle === "subtle" && [
|
|
37
|
+
colorMode === "light" &&
|
|
38
|
+
"text-acmekit-fg-subtle hover:bg-acmekit-bg-base",
|
|
39
|
+
colorMode === "dark" &&
|
|
40
|
+
"text-acmekit-contrast-fg-secondary hover:bg-acmekit-code-bg-base",
|
|
41
|
+
],
|
|
42
|
+
],
|
|
43
|
+
isSelected && [
|
|
44
|
+
blockStyle === "loud" && "text-acmekit-contrast-fg-primary",
|
|
45
|
+
blockStyle === "subtle" && [
|
|
46
|
+
colorMode === "light" &&
|
|
47
|
+
"xs:border-acmekit-border-base text-acmekit-contrast-fg-primary",
|
|
48
|
+
colorMode === "dark" &&
|
|
49
|
+
"xs:border-acmekit-code-border text-acmekit-contrast-fg-primary",
|
|
50
|
+
],
|
|
51
|
+
]
|
|
52
|
+
)}
|
|
53
|
+
ref={(tabButton) => pushRef?.(tabButton)}
|
|
54
|
+
onClick={(e) => {
|
|
55
|
+
blockElementScrollPositionUntilNextRender(
|
|
56
|
+
e.target as HTMLButtonElement
|
|
57
|
+
)
|
|
58
|
+
changeSelectedTab?.({ label, value })
|
|
59
|
+
}}
|
|
60
|
+
aria-selected={isSelected}
|
|
61
|
+
role="tab"
|
|
62
|
+
>
|
|
63
|
+
{label}
|
|
64
|
+
</button>
|
|
65
|
+
</li>
|
|
66
|
+
)
|
|
67
|
+
}
|