@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,37 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { useCallback, useEffect } from "react"
|
|
3
|
+
import { useIsBrowser } from "../../providers/BrowserProvider"
|
|
4
|
+
|
|
5
|
+
export type UseClickOutsideProps = {
|
|
6
|
+
elmRef: React.RefObject<HTMLElement | null>
|
|
7
|
+
onClickOutside: (e: MouseEvent) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useClickOutside = ({
|
|
11
|
+
elmRef,
|
|
12
|
+
onClickOutside,
|
|
13
|
+
}: UseClickOutsideProps) => {
|
|
14
|
+
const { isBrowser } = useIsBrowser()
|
|
15
|
+
|
|
16
|
+
const checkClickOutside = useCallback(
|
|
17
|
+
(e: MouseEvent) => {
|
|
18
|
+
const node = e.target as Node
|
|
19
|
+
if (!elmRef.current?.contains(node) && node.isConnected) {
|
|
20
|
+
onClickOutside(e)
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[elmRef.current, onClickOutside]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isBrowser) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
window.document.addEventListener("click", checkClickOutside)
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
window.document.removeEventListener("click", checkClickOutside)
|
|
35
|
+
}
|
|
36
|
+
}, [isBrowser, checkClickOutside])
|
|
37
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { useState } from "react"
|
|
3
|
+
// @ts-expect-error can't install the types package because it doesn't support React v19
|
|
4
|
+
import { CSSTransition } from "react-transition-group"
|
|
5
|
+
|
|
6
|
+
export type CollapsibleProps = {
|
|
7
|
+
initialValue?: boolean
|
|
8
|
+
heightAnimation?: boolean
|
|
9
|
+
translateEnabled?: boolean
|
|
10
|
+
onClose?: () => void
|
|
11
|
+
unmountOnExit?: boolean
|
|
12
|
+
childrenRef?: React.RefObject<HTMLElement | null>
|
|
13
|
+
useChild?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type CollapsibleReturn = {
|
|
17
|
+
getCollapsibleElms: (children: React.ReactNode) => React.JSX.Element
|
|
18
|
+
collapsed: boolean
|
|
19
|
+
setCollapsed: React.Dispatch<React.SetStateAction<boolean>>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const useCollapsible = ({
|
|
23
|
+
initialValue = true,
|
|
24
|
+
heightAnimation = false,
|
|
25
|
+
translateEnabled = true,
|
|
26
|
+
onClose,
|
|
27
|
+
unmountOnExit = true,
|
|
28
|
+
childrenRef,
|
|
29
|
+
useChild = true,
|
|
30
|
+
}: CollapsibleProps): CollapsibleReturn => {
|
|
31
|
+
const [collapsed, setCollapsed] = useState(initialValue)
|
|
32
|
+
|
|
33
|
+
const getNodeFromChildrenRef = () => {
|
|
34
|
+
if (!useChild) {
|
|
35
|
+
return childrenRef?.current
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
(childrenRef?.current?.firstElementChild as HTMLElement) ||
|
|
40
|
+
childrenRef?.current
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const getCollapsibleElms = (children: React.ReactNode) => {
|
|
45
|
+
return (
|
|
46
|
+
<CSSTransition
|
|
47
|
+
unmountOnExit={unmountOnExit}
|
|
48
|
+
in={!collapsed}
|
|
49
|
+
timeout={150}
|
|
50
|
+
nodeRef={childrenRef}
|
|
51
|
+
onEnter={() => {
|
|
52
|
+
const node = getNodeFromChildrenRef()
|
|
53
|
+
if (!node) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (heightAnimation) {
|
|
58
|
+
node.classList.add("transition-[height]")
|
|
59
|
+
node.style.height = `0px`
|
|
60
|
+
} else {
|
|
61
|
+
node.classList.add("!mb-docs_2", "!mt-0")
|
|
62
|
+
if (translateEnabled) {
|
|
63
|
+
node.classList.add("translate-y-docs_1", "transition-transform")
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}}
|
|
67
|
+
onEntering={() => {
|
|
68
|
+
const node = getNodeFromChildrenRef()
|
|
69
|
+
if (!node) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (heightAnimation) {
|
|
74
|
+
node.style.height = `${node.scrollHeight}px`
|
|
75
|
+
}
|
|
76
|
+
}}
|
|
77
|
+
onEntered={() => {
|
|
78
|
+
const node = getNodeFromChildrenRef()
|
|
79
|
+
if (!node) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (heightAnimation) {
|
|
84
|
+
node.style.height = `auto`
|
|
85
|
+
}
|
|
86
|
+
}}
|
|
87
|
+
onExit={() => {
|
|
88
|
+
const node = getNodeFromChildrenRef()
|
|
89
|
+
if (!node) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (heightAnimation) {
|
|
94
|
+
node.style.height = `${node.scrollHeight}px`
|
|
95
|
+
} else {
|
|
96
|
+
if (translateEnabled) {
|
|
97
|
+
node.classList.add("transition-transform", "!-translate-y-docs_1")
|
|
98
|
+
}
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
onClose?.()
|
|
101
|
+
}, 100)
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onExiting={() => {
|
|
105
|
+
const node = getNodeFromChildrenRef()
|
|
106
|
+
if (!node) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (heightAnimation) {
|
|
111
|
+
node.style.height = `0px`
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
onClose?.()
|
|
114
|
+
}, 100)
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</CSSTransition>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
getCollapsibleElms,
|
|
125
|
+
collapsed,
|
|
126
|
+
setCollapsed,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
LineInputProps,
|
|
4
|
+
LineOutputProps,
|
|
5
|
+
Token,
|
|
6
|
+
TokenInputProps,
|
|
7
|
+
TokenOutputProps,
|
|
8
|
+
} from "prism-react-renderer"
|
|
9
|
+
import React, { useCallback, useMemo, useRef } from "react"
|
|
10
|
+
import { CodeBlockCollapsibleLines } from "../../components/CodeBlock/Collapsible/Lines"
|
|
11
|
+
import { useCollapsible } from "../use-collapsible"
|
|
12
|
+
|
|
13
|
+
export type HighlightProps = {
|
|
14
|
+
getLineProps: (input: LineInputProps) => LineOutputProps
|
|
15
|
+
getTokenProps: (input: TokenInputProps) => TokenOutputProps
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CollapsibleCodeLines = {
|
|
19
|
+
collapsibleLinesStr?: string
|
|
20
|
+
getLines: (
|
|
21
|
+
token: Token[][],
|
|
22
|
+
highlightProps: HighlightProps,
|
|
23
|
+
lineNumberOffset?: number
|
|
24
|
+
) => React.JSX.Element[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type CollapsedCodeLinesPosition = "start" | "end"
|
|
28
|
+
|
|
29
|
+
export const useCollapsibleCodeLines = ({
|
|
30
|
+
collapsibleLinesStr,
|
|
31
|
+
getLines,
|
|
32
|
+
}: CollapsibleCodeLines) => {
|
|
33
|
+
const collapsedRange:
|
|
34
|
+
| {
|
|
35
|
+
start: number
|
|
36
|
+
end: number | undefined
|
|
37
|
+
}
|
|
38
|
+
| undefined = useMemo(() => {
|
|
39
|
+
if (!collapsibleLinesStr) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const splitCollapsedLines = collapsibleLinesStr
|
|
44
|
+
.split("-")
|
|
45
|
+
.map((lineNumber) => parseInt(lineNumber))
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
!splitCollapsedLines.length ||
|
|
49
|
+
(splitCollapsedLines.length >= 2 &&
|
|
50
|
+
splitCollapsedLines[0] !== 1 &&
|
|
51
|
+
splitCollapsedLines[1] < 2)
|
|
52
|
+
) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
start: splitCollapsedLines[0],
|
|
58
|
+
end: splitCollapsedLines[1],
|
|
59
|
+
}
|
|
60
|
+
}, [collapsibleLinesStr])
|
|
61
|
+
|
|
62
|
+
const isCollapsible = useCallback(
|
|
63
|
+
(tokens: Token[][]) => {
|
|
64
|
+
return collapsedRange && collapsedRange.start < tokens.length
|
|
65
|
+
},
|
|
66
|
+
[collapsedRange]
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const type: CollapsedCodeLinesPosition | undefined = useMemo(() => {
|
|
70
|
+
if (!collapsedRange) {
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
return collapsedRange.start === 1 ? "start" : "end"
|
|
74
|
+
}, [collapsedRange])
|
|
75
|
+
|
|
76
|
+
const ref = useRef(null)
|
|
77
|
+
const collapsibleHookResult = useCollapsible({
|
|
78
|
+
unmountOnExit: false,
|
|
79
|
+
translateEnabled: false,
|
|
80
|
+
heightAnimation: true,
|
|
81
|
+
childrenRef: ref,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const getCollapsedLinesElm = useCallback(
|
|
85
|
+
({
|
|
86
|
+
tokens,
|
|
87
|
+
highlightProps,
|
|
88
|
+
}: {
|
|
89
|
+
tokens: Token[][]
|
|
90
|
+
highlightProps: HighlightProps
|
|
91
|
+
}) => {
|
|
92
|
+
if (!collapsedRange || !type || !isCollapsible(tokens)) {
|
|
93
|
+
return <></>
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const startIndex =
|
|
97
|
+
type === "start" ? collapsedRange.start - 1 : collapsedRange.start
|
|
98
|
+
|
|
99
|
+
const lines = tokens.slice(
|
|
100
|
+
startIndex,
|
|
101
|
+
collapsedRange.end
|
|
102
|
+
? Math.min(collapsedRange.end, tokens.length)
|
|
103
|
+
: tokens.length
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<CodeBlockCollapsibleLines {...collapsibleHookResult} type={type}>
|
|
108
|
+
{getLines(lines, highlightProps, startIndex)}
|
|
109
|
+
</CodeBlockCollapsibleLines>
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
[collapsedRange, collapsibleHookResult, isCollapsible, type]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const getNonCollapsedLinesElm = useCallback(
|
|
116
|
+
({
|
|
117
|
+
tokens,
|
|
118
|
+
highlightProps,
|
|
119
|
+
}: {
|
|
120
|
+
tokens: Token[][]
|
|
121
|
+
highlightProps: HighlightProps
|
|
122
|
+
}) => {
|
|
123
|
+
if (!collapsedRange || !isCollapsible(tokens)) {
|
|
124
|
+
return getLines(tokens, highlightProps)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const isCollapseBeginning = collapsedRange.start === 1
|
|
128
|
+
const lines = tokens.slice(
|
|
129
|
+
isCollapseBeginning ? collapsedRange.end || tokens.length : 0,
|
|
130
|
+
isCollapseBeginning ? undefined : collapsedRange.start
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return getLines(
|
|
134
|
+
lines,
|
|
135
|
+
highlightProps,
|
|
136
|
+
isCollapseBeginning ? collapsedRange.end : 0
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
[collapsedRange, collapsibleHookResult, isCollapsible]
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
getCollapsedLinesElm,
|
|
144
|
+
getNonCollapsedLinesElm,
|
|
145
|
+
type,
|
|
146
|
+
isCollapsible,
|
|
147
|
+
...collapsibleHookResult,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react"
|
|
3
|
+
|
|
4
|
+
type useCopyReturnType = {
|
|
5
|
+
isCopied: boolean
|
|
6
|
+
handleCopy: () => void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useCopy = (text: string): useCopyReturnType => {
|
|
10
|
+
const [isCopied, setIsCopied] = useState(false)
|
|
11
|
+
const copyTimeout = useRef<number>(0)
|
|
12
|
+
|
|
13
|
+
const handleCopy = useCallback(() => {
|
|
14
|
+
navigator.clipboard
|
|
15
|
+
.writeText(text.trim())
|
|
16
|
+
.then(() => {
|
|
17
|
+
setIsCopied(true)
|
|
18
|
+
copyTimeout.current = window.setTimeout(() => {
|
|
19
|
+
setIsCopied(false)
|
|
20
|
+
}, 1000)
|
|
21
|
+
})
|
|
22
|
+
.catch(console.error)
|
|
23
|
+
}, [text])
|
|
24
|
+
|
|
25
|
+
useEffect(() => () => window.clearTimeout(copyTimeout.current), [])
|
|
26
|
+
|
|
27
|
+
return { isCopied, handleCopy }
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import { useLocation } from "react-router-dom"
|
|
3
|
+
import { useIsBrowser } from "../../providers/BrowserProvider"
|
|
4
|
+
import { useSiteConfig } from "../../providers/SiteConfig"
|
|
5
|
+
import { useMemo } from "react"
|
|
6
|
+
|
|
7
|
+
type useHeadingUrlProps = {
|
|
8
|
+
id: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const useHeadingUrl = ({ id }: useHeadingUrlProps) => {
|
|
12
|
+
const { isBrowser } = useIsBrowser()
|
|
13
|
+
const {
|
|
14
|
+
config: { basePath },
|
|
15
|
+
} = useSiteConfig()
|
|
16
|
+
const { pathname } = useLocation()
|
|
17
|
+
const headingUrl = useMemo(() => {
|
|
18
|
+
const hash = `#${id}`
|
|
19
|
+
if (!isBrowser) {
|
|
20
|
+
return hash
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const url = `${window.location.origin}${basePath}${pathname}`.replace(
|
|
24
|
+
/\/$/,
|
|
25
|
+
""
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
return `${url}${hash}`
|
|
29
|
+
}, [id, isBrowser, pathname])
|
|
30
|
+
|
|
31
|
+
return headingUrl
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
|
|
3
|
+
type UseIsExternalLinkProps = {
|
|
4
|
+
href?: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const useIsExternalLink = ({ href }: UseIsExternalLinkProps) => {
|
|
8
|
+
const isExternal = useMemo(() => {
|
|
9
|
+
return (
|
|
10
|
+
href &&
|
|
11
|
+
!href.startsWith("/") &&
|
|
12
|
+
!href.startsWith("https://docs.acmekit.com") &&
|
|
13
|
+
!href.startsWith("http://localhost:") &&
|
|
14
|
+
!href.startsWith("#")
|
|
15
|
+
)
|
|
16
|
+
}, [href])
|
|
17
|
+
|
|
18
|
+
return isExternal
|
|
19
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback, useEffect } from "react"
|
|
3
|
+
|
|
4
|
+
export type useKeyboardShortcutOptions = {
|
|
5
|
+
metakey?: boolean
|
|
6
|
+
shortcutKeys: string[]
|
|
7
|
+
action: (e: KeyboardEvent) => void
|
|
8
|
+
checkEditing?: boolean
|
|
9
|
+
preventDefault?: boolean
|
|
10
|
+
isLoading?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const useKeyboardShortcut = ({
|
|
14
|
+
metakey = true,
|
|
15
|
+
shortcutKeys,
|
|
16
|
+
action,
|
|
17
|
+
checkEditing = true,
|
|
18
|
+
preventDefault = true,
|
|
19
|
+
isLoading = false,
|
|
20
|
+
}: useKeyboardShortcutOptions) => {
|
|
21
|
+
function isEditingContent(event: KeyboardEvent) {
|
|
22
|
+
const element = event.target as HTMLElement
|
|
23
|
+
const tagName = element.tagName
|
|
24
|
+
return (
|
|
25
|
+
element.isContentEditable ||
|
|
26
|
+
tagName === "INPUT" ||
|
|
27
|
+
tagName === "SELECT" ||
|
|
28
|
+
tagName === "TEXTAREA"
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const checkKeysPressed = useCallback(
|
|
33
|
+
(pressedKey: string) => {
|
|
34
|
+
const lowerPressedKey = pressedKey.toLowerCase()
|
|
35
|
+
return shortcutKeys.some(
|
|
36
|
+
(value) => lowerPressedKey === value.toLowerCase()
|
|
37
|
+
)
|
|
38
|
+
},
|
|
39
|
+
[shortcutKeys]
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const onKeyDown = useCallback(
|
|
43
|
+
(e: KeyboardEvent) => {
|
|
44
|
+
// the event is triggered when an input
|
|
45
|
+
// autocompletes, and in that case
|
|
46
|
+
// e.key will be empty
|
|
47
|
+
if (isLoading || !e.key) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
if (
|
|
51
|
+
(!metakey || e.metaKey || e.ctrlKey) &&
|
|
52
|
+
checkKeysPressed(e.key) &&
|
|
53
|
+
(!checkEditing || !isEditingContent(e))
|
|
54
|
+
) {
|
|
55
|
+
if (preventDefault) {
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
}
|
|
58
|
+
action(e)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[isLoading, metakey, checkKeysPressed, checkEditing, action, preventDefault]
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
window.addEventListener("keydown", onKeyDown)
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
window.removeEventListener("keydown", onKeyDown)
|
|
69
|
+
}
|
|
70
|
+
}, [onKeyDown])
|
|
71
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import { useEffect } from "react"
|
|
3
|
+
|
|
4
|
+
type UseMutationObserverProps = {
|
|
5
|
+
elm: Document | HTMLElement | undefined
|
|
6
|
+
callback: () => void
|
|
7
|
+
options?: {
|
|
8
|
+
attributes?: boolean
|
|
9
|
+
characterData?: boolean
|
|
10
|
+
childList?: boolean
|
|
11
|
+
subtree?: boolean
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useMutationObserver = ({
|
|
16
|
+
elm,
|
|
17
|
+
callback,
|
|
18
|
+
options = {
|
|
19
|
+
attributes: true,
|
|
20
|
+
characterData: true,
|
|
21
|
+
childList: true,
|
|
22
|
+
subtree: true,
|
|
23
|
+
},
|
|
24
|
+
}: UseMutationObserverProps) => {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (elm) {
|
|
27
|
+
const observer = new MutationObserver(callback)
|
|
28
|
+
observer.observe(elm, options)
|
|
29
|
+
return () => observer.disconnect()
|
|
30
|
+
}
|
|
31
|
+
}, [callback, options])
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { useLocation } from "react-router-dom"
|
|
3
|
+
import { useScrollController } from "../use-scroll-utils"
|
|
4
|
+
import { useEffect, useState } from "react"
|
|
5
|
+
import { getScrolledTop, isElmWindow } from "../../utils"
|
|
6
|
+
|
|
7
|
+
export const usePageScrollManager = () => {
|
|
8
|
+
const { pathname } = useLocation()
|
|
9
|
+
const { scrollableElement } = useScrollController()
|
|
10
|
+
const [checkedPageReload, setCheckedPageReload] = useState(false)
|
|
11
|
+
|
|
12
|
+
const isPageReloaded = () =>
|
|
13
|
+
(window.performance.navigation &&
|
|
14
|
+
window.performance.navigation.type === 1) ||
|
|
15
|
+
window.performance
|
|
16
|
+
.getEntriesByType("navigation")
|
|
17
|
+
.map((nav) => (nav as PerformanceNavigationTiming).type)
|
|
18
|
+
.includes("reload")
|
|
19
|
+
|
|
20
|
+
const tryToScroll = () => {
|
|
21
|
+
if (getScrolledTop(scrollableElement) !== 0 && !location.hash) {
|
|
22
|
+
scrollableElement?.scrollTo({
|
|
23
|
+
top: 0,
|
|
24
|
+
})
|
|
25
|
+
} else if (location.hash) {
|
|
26
|
+
// retrieve and scroll to element
|
|
27
|
+
const targetElm =
|
|
28
|
+
scrollableElement && typeof document !== "undefined"
|
|
29
|
+
? document.getElementById(location.hash.replace("#", ""))
|
|
30
|
+
: undefined
|
|
31
|
+
|
|
32
|
+
scrollableElement?.scrollTo({
|
|
33
|
+
top: targetElm ? targetElm.offsetTop : 0,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (checkedPageReload) {
|
|
40
|
+
setCheckedPageReload(false)
|
|
41
|
+
}
|
|
42
|
+
}, [pathname])
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!scrollableElement || checkedPageReload) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isPageReloaded()) {
|
|
50
|
+
const loadedScrollPosition = localStorage.getItem("scrollPos")
|
|
51
|
+
if (loadedScrollPosition) {
|
|
52
|
+
scrollableElement?.scrollTo({
|
|
53
|
+
top: parseInt(loadedScrollPosition),
|
|
54
|
+
})
|
|
55
|
+
localStorage.removeItem("scrollPos")
|
|
56
|
+
} else {
|
|
57
|
+
tryToScroll()
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
tryToScroll()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setCheckedPageReload(true)
|
|
64
|
+
|
|
65
|
+
window.addEventListener("beforeunload", () => {
|
|
66
|
+
const scrollPos = isElmWindow(scrollableElement)
|
|
67
|
+
? scrollableElement.screenY
|
|
68
|
+
: scrollableElement?.scrollTop
|
|
69
|
+
|
|
70
|
+
if (scrollPos) {
|
|
71
|
+
localStorage.setItem(
|
|
72
|
+
"scrollPos",
|
|
73
|
+
`${
|
|
74
|
+
isElmWindow(scrollableElement)
|
|
75
|
+
? scrollableElement.screenY
|
|
76
|
+
: scrollableElement?.scrollTop
|
|
77
|
+
}`
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}, [scrollableElement, checkedPageReload])
|
|
82
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from "react"
|
|
2
|
+
|
|
3
|
+
export function useResizeObserver(
|
|
4
|
+
ref: React.RefObject<HTMLElement | null>,
|
|
5
|
+
callback: (entry: ResizeObserverEntry) => void
|
|
6
|
+
) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const el = ref.current
|
|
9
|
+
if (!el) return
|
|
10
|
+
|
|
11
|
+
const observer = new ResizeObserver((entries) => {
|
|
12
|
+
if (entries[0]) {
|
|
13
|
+
callback(entries[0])
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
observer.observe(el)
|
|
18
|
+
return () => observer.disconnect()
|
|
19
|
+
}, [ref, callback])
|
|
20
|
+
}
|