@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,331 @@
|
|
|
1
|
+
import React, { useMemo } from "react"
|
|
2
|
+
import { Highlight } from "../../CodeBlock"
|
|
3
|
+
import { RenderProps, Token } from "prism-react-renderer"
|
|
4
|
+
import clsx from "clsx"
|
|
5
|
+
import { Tooltip } from "../../../components/Tooltip"
|
|
6
|
+
import { MarkdownContent } from "../../MarkdownContent"
|
|
7
|
+
|
|
8
|
+
type HighlightedTokens = {
|
|
9
|
+
start: number
|
|
10
|
+
end: number
|
|
11
|
+
highlight: Highlight
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type TokensWithHighlights = {
|
|
15
|
+
tokens: Token[]
|
|
16
|
+
type: "default" | "highlighted"
|
|
17
|
+
highlight?: Highlight
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type CodeBlockLineProps = {
|
|
21
|
+
line: Token[]
|
|
22
|
+
highlights?: Highlight[]
|
|
23
|
+
lineNumber: number
|
|
24
|
+
showLineNumber: boolean
|
|
25
|
+
lineNumberColorClassName: string
|
|
26
|
+
lineNumberBgClassName: string
|
|
27
|
+
isTerminal: boolean
|
|
28
|
+
animateTokenHighlights?: boolean
|
|
29
|
+
} & Pick<RenderProps, "getLineProps" | "getTokenProps">
|
|
30
|
+
|
|
31
|
+
export const CodeBlockLine = ({
|
|
32
|
+
line,
|
|
33
|
+
highlights = [],
|
|
34
|
+
lineNumber,
|
|
35
|
+
getLineProps,
|
|
36
|
+
getTokenProps,
|
|
37
|
+
showLineNumber,
|
|
38
|
+
lineNumberColorClassName,
|
|
39
|
+
lineNumberBgClassName,
|
|
40
|
+
isTerminal,
|
|
41
|
+
animateTokenHighlights = false,
|
|
42
|
+
}: CodeBlockLineProps) => {
|
|
43
|
+
const { key: _lineKey, ...lineProps } = getLineProps({ line, key: lineNumber })
|
|
44
|
+
|
|
45
|
+
// collect highlighted tokens, if there are any
|
|
46
|
+
const highlightedTokens: HighlightedTokens[] = useMemo(() => {
|
|
47
|
+
const highlightedTokensArr: HighlightedTokens[] = []
|
|
48
|
+
highlights.forEach((highlight) => {
|
|
49
|
+
if (!highlight.text) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
let startIndex: number | undefined = undefined
|
|
53
|
+
let currentPositionInHighlightedText = 0
|
|
54
|
+
let endIndex = 0
|
|
55
|
+
const found = line.some((token, tokenIndex) => {
|
|
56
|
+
if (token.empty || !token.content.length) {
|
|
57
|
+
startIndex = undefined
|
|
58
|
+
currentPositionInHighlightedText = 0
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
const startNotSet = startIndex === undefined
|
|
62
|
+
// trim the start of the script if the start
|
|
63
|
+
// of the highlight hasn't been found yet
|
|
64
|
+
const tokenContent = startNotSet
|
|
65
|
+
? token.content.trimStart()
|
|
66
|
+
: token.content
|
|
67
|
+
if (!tokenContent.length && startNotSet) {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
const comparisonLength = Math.min(
|
|
71
|
+
tokenContent.length,
|
|
72
|
+
highlight.text!.substring(currentPositionInHighlightedText).length
|
|
73
|
+
)
|
|
74
|
+
const nextPositionInHighlightedText =
|
|
75
|
+
currentPositionInHighlightedText + comparisonLength
|
|
76
|
+
|
|
77
|
+
const canHighlight =
|
|
78
|
+
!highlightedTokensArr.length ||
|
|
79
|
+
!highlightedTokensArr.some(
|
|
80
|
+
(token) => tokenIndex >= token.start && tokenIndex <= token.end
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const isMatching =
|
|
84
|
+
tokenContent.substring(0, comparisonLength) ===
|
|
85
|
+
highlight.text?.substring(
|
|
86
|
+
currentPositionInHighlightedText,
|
|
87
|
+
nextPositionInHighlightedText
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if (isMatching && canHighlight) {
|
|
91
|
+
if (startNotSet) {
|
|
92
|
+
startIndex = tokenIndex
|
|
93
|
+
}
|
|
94
|
+
currentPositionInHighlightedText = nextPositionInHighlightedText
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (currentPositionInHighlightedText === highlight.text!.length) {
|
|
98
|
+
// matching text was found, break loop
|
|
99
|
+
endIndex = tokenIndex
|
|
100
|
+
const trimmedContent = token.content.trimEnd()
|
|
101
|
+
const endingSpacesLength =
|
|
102
|
+
token.content.length - trimmedContent.length
|
|
103
|
+
if (endingSpacesLength) {
|
|
104
|
+
line.splice(tokenIndex + 1, 0, {
|
|
105
|
+
content: new Array(endingSpacesLength).fill(" ").join(""),
|
|
106
|
+
types: ["plain"],
|
|
107
|
+
})
|
|
108
|
+
token.content = trimmedContent
|
|
109
|
+
}
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
if (found && startIndex !== undefined) {
|
|
115
|
+
highlightedTokensArr.push({
|
|
116
|
+
start: startIndex,
|
|
117
|
+
end: endIndex,
|
|
118
|
+
highlight,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// sort highlighted tokens by their start position
|
|
124
|
+
highlightedTokensArr.sort((tokensA, tokensB) => {
|
|
125
|
+
if (tokensA.start < tokensB.start) {
|
|
126
|
+
return -1
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return tokensA.start > tokensB.start ? 1 : 0
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
return highlightedTokensArr
|
|
133
|
+
}, [highlights, line])
|
|
134
|
+
|
|
135
|
+
// if there are highlighted tokens, split tokens in the
|
|
136
|
+
// line by segments of not highlighted and highlighted token
|
|
137
|
+
// if there are no highlighted tokens, the line is used as-is.
|
|
138
|
+
const transformedLine: TokensWithHighlights[] = useMemo(() => {
|
|
139
|
+
if (!highlightedTokens.length) {
|
|
140
|
+
return [
|
|
141
|
+
{
|
|
142
|
+
tokens: line,
|
|
143
|
+
type: "default",
|
|
144
|
+
},
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
const transformedLineArr: TokensWithHighlights[] = []
|
|
148
|
+
|
|
149
|
+
let lastIndex = 0
|
|
150
|
+
// go through highlighted tokens to add the segments before/after to the
|
|
151
|
+
// transformLineArr array
|
|
152
|
+
highlightedTokens.forEach((highlightedTokensItem, index) => {
|
|
153
|
+
if (lastIndex < highlightedTokensItem.start) {
|
|
154
|
+
transformedLineArr.push({
|
|
155
|
+
tokens: line.slice(lastIndex, highlightedTokensItem.start),
|
|
156
|
+
type: "default",
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
// check if the start text should be trimmed
|
|
160
|
+
const token = Object.assign({}, line[highlightedTokensItem.start])
|
|
161
|
+
if (
|
|
162
|
+
token.content.startsWith(" ") &&
|
|
163
|
+
!highlightedTokensItem.highlight.text?.startsWith(" ")
|
|
164
|
+
) {
|
|
165
|
+
const originalLength = token.content.length
|
|
166
|
+
token.content = token.content.trimStart()
|
|
167
|
+
// push the spaces as a separate token
|
|
168
|
+
// so that they won't be highlighted.
|
|
169
|
+
transformedLineArr.push({
|
|
170
|
+
tokens: [
|
|
171
|
+
{
|
|
172
|
+
content: " ".repeat(originalLength - token.content.length),
|
|
173
|
+
types: ["plain"],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
type: "default",
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
transformedLineArr.push({
|
|
180
|
+
tokens: [
|
|
181
|
+
token,
|
|
182
|
+
...line.slice(
|
|
183
|
+
highlightedTokensItem.start + 1,
|
|
184
|
+
highlightedTokensItem.end + 1
|
|
185
|
+
),
|
|
186
|
+
],
|
|
187
|
+
type: "highlighted",
|
|
188
|
+
highlight: highlightedTokensItem.highlight,
|
|
189
|
+
})
|
|
190
|
+
lastIndex = highlightedTokensItem.end + 1
|
|
191
|
+
|
|
192
|
+
// if this is the last item in `highlightedTokens` and
|
|
193
|
+
// its end index is less than the line's length, that means
|
|
194
|
+
// there are tokens at the end of the line that aren't highlighted
|
|
195
|
+
// and should be pushed as-is to the `transformLineArr` array.
|
|
196
|
+
if (
|
|
197
|
+
index === highlightedTokens.length - 1 &&
|
|
198
|
+
lastIndex < line.length - 1
|
|
199
|
+
) {
|
|
200
|
+
transformedLineArr.push({
|
|
201
|
+
tokens: line.slice(lastIndex),
|
|
202
|
+
type: "default",
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
return transformedLineArr
|
|
208
|
+
}, [highlightedTokens])
|
|
209
|
+
|
|
210
|
+
const getTokensElm = ({
|
|
211
|
+
tokens,
|
|
212
|
+
isTokenHighlighted,
|
|
213
|
+
offset,
|
|
214
|
+
}: {
|
|
215
|
+
tokens: Token[]
|
|
216
|
+
isTokenHighlighted: boolean
|
|
217
|
+
offset: number
|
|
218
|
+
}) => (
|
|
219
|
+
<span
|
|
220
|
+
className={clsx(isTokenHighlighted && "relative")}
|
|
221
|
+
data-testid="code-block-line-tokens"
|
|
222
|
+
>
|
|
223
|
+
{isTokenHighlighted && (
|
|
224
|
+
<span
|
|
225
|
+
className={clsx(
|
|
226
|
+
animateTokenHighlights && [
|
|
227
|
+
"animate-fast animate-growWidth animation-fill-forwards",
|
|
228
|
+
],
|
|
229
|
+
!animateTokenHighlights && "w-full",
|
|
230
|
+
"absolute left-0 top-0 h-full z-0",
|
|
231
|
+
"lg:bg-acmekit-alpha-white-alpha-6 lg:border lg:border-acmekit-alpha-white-alpha-12",
|
|
232
|
+
"lg:rounded-docs_xs scale-x-[1.05]"
|
|
233
|
+
)}
|
|
234
|
+
data-testid="code-block-line-highlight"
|
|
235
|
+
/>
|
|
236
|
+
)}
|
|
237
|
+
{tokens.map((token, key) => {
|
|
238
|
+
const tokenKey = offset + key
|
|
239
|
+
const { className: tokenClassName, key: _tokenKey, ...rest } = getTokenProps({
|
|
240
|
+
token,
|
|
241
|
+
key: tokenKey,
|
|
242
|
+
})
|
|
243
|
+
return (
|
|
244
|
+
<span
|
|
245
|
+
key={tokenKey}
|
|
246
|
+
className={clsx(
|
|
247
|
+
tokenClassName,
|
|
248
|
+
isTokenHighlighted && "relative z-[1]"
|
|
249
|
+
)}
|
|
250
|
+
data-testid="code-block-line-token"
|
|
251
|
+
{...rest}
|
|
252
|
+
/>
|
|
253
|
+
)
|
|
254
|
+
})}
|
|
255
|
+
</span>
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
const isHighlightedLine = useMemo(
|
|
259
|
+
() => highlights.length !== 0 && highlightedTokens.length === 0,
|
|
260
|
+
[highlights, highlightedTokens]
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<span
|
|
265
|
+
key={lineNumber}
|
|
266
|
+
{...lineProps}
|
|
267
|
+
className={clsx(
|
|
268
|
+
"table-row",
|
|
269
|
+
isHighlightedLine && "bg-acmekit-alpha-white-alpha-6",
|
|
270
|
+
lineProps.className
|
|
271
|
+
)}
|
|
272
|
+
data-testid="code-block-line"
|
|
273
|
+
>
|
|
274
|
+
{(showLineNumber || isTerminal) && (
|
|
275
|
+
<span
|
|
276
|
+
className={clsx(
|
|
277
|
+
"mr-docs_1 table-cell select-none",
|
|
278
|
+
"sticky left-0 w-[1%] px-docs_1 text-right",
|
|
279
|
+
lineNumberColorClassName,
|
|
280
|
+
lineNumberBgClassName
|
|
281
|
+
)}
|
|
282
|
+
data-testid="line-number"
|
|
283
|
+
>
|
|
284
|
+
{isTerminal ? "❯" : showLineNumber ? lineNumber + 1 : ""}
|
|
285
|
+
</span>
|
|
286
|
+
)}
|
|
287
|
+
<span>
|
|
288
|
+
{transformedLine.map(({ tokens, type, highlight }, index) => {
|
|
289
|
+
const offset =
|
|
290
|
+
index === 0 ? 0 : transformedLine[index - 1].tokens.length
|
|
291
|
+
const tooltipText =
|
|
292
|
+
highlight?.tooltipText ||
|
|
293
|
+
(isHighlightedLine
|
|
294
|
+
? highlights.find((h) => h.tooltipText !== undefined)?.tooltipText
|
|
295
|
+
: undefined)
|
|
296
|
+
const isHighlighted = type === "highlighted"
|
|
297
|
+
return (
|
|
298
|
+
<React.Fragment key={index}>
|
|
299
|
+
{tooltipText && (
|
|
300
|
+
<Tooltip
|
|
301
|
+
text={tooltipText}
|
|
302
|
+
tooltipClassName="font-base"
|
|
303
|
+
render={({ content }) => (
|
|
304
|
+
<MarkdownContent
|
|
305
|
+
allowedElements={["a", "strong", "code", "br"]}
|
|
306
|
+
unwrapDisallowed={true}
|
|
307
|
+
>
|
|
308
|
+
{content || ""}
|
|
309
|
+
</MarkdownContent>
|
|
310
|
+
)}
|
|
311
|
+
>
|
|
312
|
+
{getTokensElm({
|
|
313
|
+
tokens,
|
|
314
|
+
isTokenHighlighted: isHighlighted,
|
|
315
|
+
offset,
|
|
316
|
+
})}
|
|
317
|
+
</Tooltip>
|
|
318
|
+
)}
|
|
319
|
+
{!tooltipText &&
|
|
320
|
+
getTokensElm({
|
|
321
|
+
tokens,
|
|
322
|
+
isTokenHighlighted: isHighlighted,
|
|
323
|
+
offset,
|
|
324
|
+
})}
|
|
325
|
+
</React.Fragment>
|
|
326
|
+
)
|
|
327
|
+
})}
|
|
328
|
+
</span>
|
|
329
|
+
</span>
|
|
330
|
+
)
|
|
331
|
+
}
|