@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,43 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import clsx from "clsx"
|
|
3
|
+
import { RootProviders, Sidebar, SidebarProps } from "../components"
|
|
4
|
+
import { MainContentLayout, MainContentLayoutProps } from "./main-content"
|
|
5
|
+
|
|
6
|
+
export type RootLayoutProps = {
|
|
7
|
+
bodyClassName?: string
|
|
8
|
+
sidebarProps?: SidebarProps
|
|
9
|
+
showBreadcrumbs?: boolean
|
|
10
|
+
ProvidersComponent: React.FC<{ children: React.ReactNode }>
|
|
11
|
+
footerComponent?: React.ReactNode
|
|
12
|
+
} & MainContentLayoutProps
|
|
13
|
+
|
|
14
|
+
export const RootLayout = ({
|
|
15
|
+
bodyClassName,
|
|
16
|
+
sidebarProps,
|
|
17
|
+
ProvidersComponent,
|
|
18
|
+
...mainProps
|
|
19
|
+
}: RootLayoutProps) => {
|
|
20
|
+
return (
|
|
21
|
+
<div className={clsx("h-screen w-full overflow-hidden")}>
|
|
22
|
+
<div
|
|
23
|
+
className={clsx(
|
|
24
|
+
"bg-acmekit-bg-subtle font-base text-medium w-full",
|
|
25
|
+
"text-acmekit-fg-base",
|
|
26
|
+
"h-full overflow-hidden",
|
|
27
|
+
"grid grid-cols-1 lg:mx-auto lg:grid-cols-[221px_1fr]",
|
|
28
|
+
bodyClassName
|
|
29
|
+
)}
|
|
30
|
+
id="root-layout"
|
|
31
|
+
>
|
|
32
|
+
<RootProviders>
|
|
33
|
+
<ProvidersComponent>
|
|
34
|
+
<Sidebar {...sidebarProps} />
|
|
35
|
+
<div className={clsx("relative", "h-screen", "flex")}>
|
|
36
|
+
<MainContentLayout {...mainProps} />
|
|
37
|
+
</div>
|
|
38
|
+
</ProvidersComponent>
|
|
39
|
+
</RootProviders>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { RootLayout, RootLayoutProps } from "./root"
|
|
3
|
+
import clsx from "clsx"
|
|
4
|
+
import { Breadcrumbs } from ".."
|
|
5
|
+
|
|
6
|
+
export const TightLayout = ({
|
|
7
|
+
children,
|
|
8
|
+
footerComponent,
|
|
9
|
+
showBreadcrumbs = true,
|
|
10
|
+
...props
|
|
11
|
+
}: RootLayoutProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<RootLayout {...props}>
|
|
14
|
+
<div
|
|
15
|
+
className={clsx(
|
|
16
|
+
"w-full h-fit",
|
|
17
|
+
"max-w-inner-content-xs sm:max-w-inner-content-sm md:max-w-inner-content-md",
|
|
18
|
+
"lg:max-w-inner-content-lg xl:max-w-inner-content-xl xxl:max-w-inner-content-xxl",
|
|
19
|
+
"xxxl:max-w-inner-content-xxxl",
|
|
20
|
+
"px-docs_1 md:px-docs_4 lg:px-0"
|
|
21
|
+
)}
|
|
22
|
+
>
|
|
23
|
+
{showBreadcrumbs && <Breadcrumbs />}
|
|
24
|
+
{children}
|
|
25
|
+
{footerComponent}
|
|
26
|
+
</div>
|
|
27
|
+
</RootLayout>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { RootLayout, RootLayoutProps } from "./root"
|
|
3
|
+
import clsx from "clsx"
|
|
4
|
+
import { Breadcrumbs } from ".."
|
|
5
|
+
|
|
6
|
+
export const WideLayout = ({
|
|
7
|
+
children,
|
|
8
|
+
footerComponent,
|
|
9
|
+
showBreadcrumbs = true,
|
|
10
|
+
...props
|
|
11
|
+
}: RootLayoutProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<RootLayout
|
|
14
|
+
{...props}
|
|
15
|
+
mainWrapperClasses={clsx(props.mainWrapperClasses, "mx-auto flex")}
|
|
16
|
+
contentClassName="w-full"
|
|
17
|
+
>
|
|
18
|
+
<main className={clsx("relative mt-4 w-full flex-1 lg:mt-7")}>
|
|
19
|
+
{showBreadcrumbs && <Breadcrumbs />}
|
|
20
|
+
{children}
|
|
21
|
+
{footerComponent}
|
|
22
|
+
</main>
|
|
23
|
+
</RootLayout>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { createContext, useContext, useRef, useState } from "react"
|
|
2
|
+
|
|
3
|
+
export type AiAssistantChatType = "default" | "popover"
|
|
4
|
+
|
|
5
|
+
export type AiAssistantContextType = {
|
|
6
|
+
chatOpened: boolean
|
|
7
|
+
setChatOpened: React.Dispatch<React.SetStateAction<boolean>>
|
|
8
|
+
chatType: AiAssistantChatType
|
|
9
|
+
inputRef: React.RefObject<HTMLInputElement | HTMLTextAreaElement | null>
|
|
10
|
+
contentRef: React.RefObject<HTMLDivElement | null>
|
|
11
|
+
loading: boolean
|
|
12
|
+
isCaptchaLoaded: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type AiAssistantThreadItem = {
|
|
16
|
+
type: "question" | "answer" | "error"
|
|
17
|
+
content: string
|
|
18
|
+
question_id?: string | null
|
|
19
|
+
sources?: any[]
|
|
20
|
+
isGenerationAborted?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const AiAssistantContext = createContext<AiAssistantContextType | null>(null)
|
|
24
|
+
|
|
25
|
+
export type AiAssistantProviderProps = {
|
|
26
|
+
children?: React.ReactNode
|
|
27
|
+
integrationId?: string
|
|
28
|
+
chatType?: AiAssistantChatType
|
|
29
|
+
type?: "search" | "chat"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const AiAssistantProvider = ({
|
|
33
|
+
children,
|
|
34
|
+
chatType = "default",
|
|
35
|
+
}: AiAssistantProviderProps) => {
|
|
36
|
+
const [chatOpened, setChatOpened] = useState(false)
|
|
37
|
+
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)
|
|
38
|
+
const contentRef = useRef<HTMLDivElement>(null)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<AiAssistantContext.Provider
|
|
42
|
+
value={{
|
|
43
|
+
chatOpened,
|
|
44
|
+
setChatOpened,
|
|
45
|
+
chatType,
|
|
46
|
+
inputRef,
|
|
47
|
+
contentRef,
|
|
48
|
+
loading: false,
|
|
49
|
+
isCaptchaLoaded: false,
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</AiAssistantContext.Provider>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const useAiAssistant = () => {
|
|
58
|
+
const context = useContext(AiAssistantContext)
|
|
59
|
+
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error("useAiAssistant must be used within a AiAssistantProvider")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return context
|
|
65
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { useContext, useEffect, useState } from "react"
|
|
3
|
+
|
|
4
|
+
type BrowserContextType = {
|
|
5
|
+
isBrowser: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const BrowserContext = React.createContext<BrowserContextType | null>(null)
|
|
9
|
+
|
|
10
|
+
type BrowserProviderProps = {
|
|
11
|
+
children: React.ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const BrowserProvider = ({ children }: BrowserProviderProps) => {
|
|
15
|
+
const [isBrowser, setIsBrowser] = useState(false)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setIsBrowser(typeof window !== "undefined")
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<BrowserContext.Provider
|
|
23
|
+
value={{
|
|
24
|
+
isBrowser,
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
{children}
|
|
28
|
+
</BrowserContext.Provider>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const useIsBrowser = () => {
|
|
33
|
+
const context = useContext(BrowserContext)
|
|
34
|
+
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useIsBrowser must be used within a BrowserProvider")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return context
|
|
40
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState } from "react"
|
|
3
|
+
|
|
4
|
+
export type ColorMode = "light" | "dark"
|
|
5
|
+
|
|
6
|
+
export type ColorModeContextType = {
|
|
7
|
+
colorMode: ColorMode
|
|
8
|
+
setColorMode: (value: ColorMode) => void
|
|
9
|
+
toggleColorMode: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ColorModeContext = createContext<ColorModeContextType | null>(null)
|
|
13
|
+
|
|
14
|
+
export type ColorModeProviderProps = {
|
|
15
|
+
children: React.ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ColorModeProvider = ({ children }: ColorModeProviderProps) => {
|
|
19
|
+
const [colorMode, setColorMode] = useState<ColorMode>("light")
|
|
20
|
+
const [loaded, setLoaded] = useState(false)
|
|
21
|
+
|
|
22
|
+
const toggleColorMode = () =>
|
|
23
|
+
setColorMode(colorMode === "light" ? "dark" : "light")
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (loaded) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const theme = localStorage.getItem("theme")
|
|
31
|
+
if (theme && (theme === "light" || theme === "dark")) {
|
|
32
|
+
setColorMode(theme)
|
|
33
|
+
}
|
|
34
|
+
setLoaded(true)
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
document.querySelector("html")?.setAttribute("data-theme", colorMode)
|
|
39
|
+
}, [colorMode])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!loaded) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const theme = localStorage.getItem("theme")
|
|
47
|
+
if (theme !== colorMode) {
|
|
48
|
+
localStorage.setItem("theme", colorMode)
|
|
49
|
+
}
|
|
50
|
+
}, [loaded, colorMode])
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<ColorModeContext.Provider
|
|
54
|
+
value={{
|
|
55
|
+
colorMode,
|
|
56
|
+
setColorMode,
|
|
57
|
+
toggleColorMode,
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</ColorModeContext.Provider>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const useColorMode = (): ColorModeContextType => {
|
|
66
|
+
const context = useContext(ColorModeContext)
|
|
67
|
+
|
|
68
|
+
if (!context) {
|
|
69
|
+
throw new Error("useColorMode must be used inside a ColorModeProvider")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return context
|
|
73
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import { useResizeObserver } from "../../hooks/use-resize-observer"
|
|
3
|
+
import React, { createContext, createRef, useContext, useState } from "react"
|
|
4
|
+
|
|
5
|
+
export type LayoutProviderContextType = {
|
|
6
|
+
mainContentRef: React.RefObject<HTMLDivElement | null>
|
|
7
|
+
showCollapsedNavbar: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const LayoutProviderContext =
|
|
11
|
+
createContext<LayoutProviderContextType | null>(null)
|
|
12
|
+
|
|
13
|
+
export type LayoutProviderProps = {
|
|
14
|
+
children: React.ReactNode
|
|
15
|
+
disableResizeObserver?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const LayoutProvider = ({
|
|
19
|
+
children,
|
|
20
|
+
disableResizeObserver = false,
|
|
21
|
+
}: LayoutProviderProps) => {
|
|
22
|
+
const mainContentRef = createRef<HTMLDivElement>()
|
|
23
|
+
const [showCollapsedNavbar, setShowCollapsedNavbar] = useState(false)
|
|
24
|
+
|
|
25
|
+
useResizeObserver(mainContentRef as React.RefObject<HTMLDivElement>, () => {
|
|
26
|
+
if (disableResizeObserver || window.innerWidth < 1024) {
|
|
27
|
+
setShowCollapsedNavbar(false)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
if (mainContentRef.current) {
|
|
31
|
+
setShowCollapsedNavbar(mainContentRef.current.clientWidth < 1100)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<LayoutProviderContext.Provider
|
|
37
|
+
value={{ mainContentRef, showCollapsedNavbar }}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</LayoutProviderContext.Provider>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const useLayout = (): LayoutProviderContextType => {
|
|
45
|
+
const context = useContext(LayoutProviderContext)
|
|
46
|
+
|
|
47
|
+
if (!context) {
|
|
48
|
+
throw new Error("useLayout must be used inside a LayoutProvider")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return context
|
|
52
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
|
|
2
|
+
import { useLocation } from "react-router-dom"
|
|
3
|
+
import React, { createContext, useContext, useMemo } from "react"
|
|
4
|
+
import { MenuItem, NavigationItem, NavigationItemDropdown } from "../../types"
|
|
5
|
+
import { useSiteConfig } from "../SiteConfig"
|
|
6
|
+
|
|
7
|
+
export type MainNavContext = {
|
|
8
|
+
navItems: NavigationItem[]
|
|
9
|
+
activeItemIndex?: number
|
|
10
|
+
activeItem?: NavigationItem
|
|
11
|
+
editDate?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const MainNavContext = createContext<MainNavContext | null>(null)
|
|
15
|
+
|
|
16
|
+
export type MainNavProviderProps = {
|
|
17
|
+
navItems: NavigationItem[]
|
|
18
|
+
children?: React.ReactNode
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const MainNavProvider = ({
|
|
22
|
+
navItems,
|
|
23
|
+
children,
|
|
24
|
+
}: MainNavProviderProps) => {
|
|
25
|
+
const { pathname } = useLocation()
|
|
26
|
+
const { config } = useSiteConfig()
|
|
27
|
+
|
|
28
|
+
const baseUrl = `${config.baseUrl}${config.basePath}`
|
|
29
|
+
|
|
30
|
+
const findActiveItem = (
|
|
31
|
+
items: NavigationItemDropdown["children"],
|
|
32
|
+
currentUrl: string
|
|
33
|
+
) => {
|
|
34
|
+
let item: MenuItem | undefined
|
|
35
|
+
let fallbackIndex: number | undefined
|
|
36
|
+
items.some((childItem, index) => {
|
|
37
|
+
if (childItem.type !== "link" && childItem.type !== "sub-menu") {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (childItem.type === "sub-menu") {
|
|
42
|
+
const activeChildRes = findActiveItem(childItem.items, currentUrl)
|
|
43
|
+
item = activeChildRes.item
|
|
44
|
+
fallbackIndex = activeChildRes.fallbackIndex
|
|
45
|
+
return !!item
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isItemActive = currentUrl.startsWith(childItem.link)
|
|
49
|
+
|
|
50
|
+
if (!isItemActive) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (childItem.useAsFallback && fallbackIndex === undefined) {
|
|
55
|
+
fallbackIndex = index
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
item = childItem
|
|
60
|
+
|
|
61
|
+
return true
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
item,
|
|
66
|
+
fallbackIndex,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const activeItemIndex = useMemo(() => {
|
|
71
|
+
const currentUrl = `${baseUrl}${pathname}`.replace(/\/$/, "")
|
|
72
|
+
|
|
73
|
+
let fallbackIndex: number | undefined
|
|
74
|
+
|
|
75
|
+
const index = navItems.findIndex((item, index) => {
|
|
76
|
+
if (item.type === "dropdown") {
|
|
77
|
+
const { item: activeChild, fallbackIndex: childFallbackIndex } =
|
|
78
|
+
findActiveItem(item.children, currentUrl)
|
|
79
|
+
|
|
80
|
+
if (activeChild) {
|
|
81
|
+
fallbackIndex = childFallbackIndex
|
|
82
|
+
return true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return item.link && currentUrl.startsWith(item.link)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (item.project && item.project !== config.project.key) {
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const isItemActive = currentUrl.startsWith(item.link)
|
|
93
|
+
|
|
94
|
+
if (isItemActive && item.useAsFallback && fallbackIndex === undefined) {
|
|
95
|
+
fallbackIndex = index
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return isItemActive
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
return index !== -1 ? index : fallbackIndex
|
|
103
|
+
}, [navItems, pathname, baseUrl, config])
|
|
104
|
+
|
|
105
|
+
const activeItem = useMemo(() => {
|
|
106
|
+
if (activeItemIndex === undefined) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return navItems[activeItemIndex]
|
|
111
|
+
}, [navItems, activeItemIndex])
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<MainNavContext.Provider
|
|
115
|
+
value={{
|
|
116
|
+
navItems,
|
|
117
|
+
activeItemIndex,
|
|
118
|
+
activeItem,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{children}
|
|
122
|
+
</MainNavContext.Provider>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const useMainNav = () => {
|
|
127
|
+
const context = useContext(MainNavContext)
|
|
128
|
+
|
|
129
|
+
if (!context) {
|
|
130
|
+
throw new Error("useMainNav must be used within a MainNavProvider")
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return context
|
|
134
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
import React, {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react"
|
|
9
|
+
|
|
10
|
+
export type MobileContextType = {
|
|
11
|
+
isMobile?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const MobileContext = createContext<MobileContextType | null>(null)
|
|
15
|
+
|
|
16
|
+
export type MobileProviderProps = {
|
|
17
|
+
children: React.ReactNode
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const MobileProvider = ({ children }: MobileProviderProps) => {
|
|
21
|
+
const [isMobile, setIsMobile] = useState(false)
|
|
22
|
+
|
|
23
|
+
const handleResize = useCallback(() => {
|
|
24
|
+
if (window.innerWidth < 1024 && !isMobile) {
|
|
25
|
+
setIsMobile(true)
|
|
26
|
+
} else if (window.innerWidth >= 1024 && isMobile) {
|
|
27
|
+
setIsMobile(false)
|
|
28
|
+
}
|
|
29
|
+
}, [isMobile])
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
window.addEventListener("resize", handleResize)
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
window.removeEventListener("resize", handleResize)
|
|
36
|
+
}
|
|
37
|
+
}, [handleResize])
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
handleResize()
|
|
41
|
+
}, [])
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<MobileContext.Provider
|
|
45
|
+
value={{
|
|
46
|
+
isMobile,
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{children}
|
|
50
|
+
</MobileContext.Provider>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const useMobile = () => {
|
|
55
|
+
const context = useContext(MobileContext)
|
|
56
|
+
|
|
57
|
+
if (!context) {
|
|
58
|
+
throw new Error("useMobile must be used within a MobileProvider")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return context
|
|
62
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import React, { useContext, useState } from "react"
|
|
3
|
+
import { createContext } from "react"
|
|
4
|
+
import { Modal, type ModalProps } from "../../components/Modal"
|
|
5
|
+
|
|
6
|
+
export type ModalContextType = {
|
|
7
|
+
modalProps: ModalProps | null
|
|
8
|
+
setModalProps: (value: ModalProps | null) => void
|
|
9
|
+
closeModal: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ModalContext = createContext<ModalContextType | null>(null)
|
|
13
|
+
|
|
14
|
+
export type ModalProviderProps = {
|
|
15
|
+
children?: React.ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ModalProvider = ({ children }: ModalProviderProps) => {
|
|
19
|
+
const [modalProps, setModalProps] = useState<ModalProps | null>(null)
|
|
20
|
+
|
|
21
|
+
const closeModal = () => {
|
|
22
|
+
setModalProps(null)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ModalContext.Provider
|
|
27
|
+
value={{
|
|
28
|
+
modalProps,
|
|
29
|
+
setModalProps,
|
|
30
|
+
closeModal,
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
{children}
|
|
34
|
+
{modalProps && (
|
|
35
|
+
<>
|
|
36
|
+
<div className="bg-acmekit-bg-overlay fixed top-0 left-0 z-[499] h-screen w-screen"></div>
|
|
37
|
+
<Modal {...modalProps} onClose={closeModal} />
|
|
38
|
+
</>
|
|
39
|
+
)}
|
|
40
|
+
</ModalContext.Provider>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const useModal = () => {
|
|
45
|
+
const context = useContext(ModalContext)
|
|
46
|
+
|
|
47
|
+
if (!context) {
|
|
48
|
+
throw new Error("useModal must be used within a ModalProvider")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return context
|
|
52
|
+
}
|