@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.
Files changed (236) hide show
  1. package/dist/Items-YPPZD6C6.mjs +312 -0
  2. package/dist/chunk-JD7BP7O5.mjs +13144 -0
  3. package/dist/index.d.mts +1550 -0
  4. package/dist/index.d.ts +1550 -0
  5. package/dist/index.js +15218 -0
  6. package/dist/index.mjs +366 -0
  7. package/package.json +58 -0
  8. package/src/components/Badge/index.tsx +74 -0
  9. package/src/components/BadgesList/index.tsx +18 -0
  10. package/src/components/BetaBadge/index.tsx +24 -0
  11. package/src/components/Bordered/index.tsx +21 -0
  12. package/src/components/BorderedIcon/index.tsx +60 -0
  13. package/src/components/Breadcrumbs/index.tsx +83 -0
  14. package/src/components/Button/index.tsx +100 -0
  15. package/src/components/Card/Layout/Default/index.tsx +124 -0
  16. package/src/components/Card/Layout/Filler/index.tsx +30 -0
  17. package/src/components/Card/Layout/Large/index.tsx +88 -0
  18. package/src/components/Card/Layout/Mini/index.tsx +142 -0
  19. package/src/components/Card/index.tsx +50 -0
  20. package/src/components/CardList/index.tsx +40 -0
  21. package/src/components/ChildDocs/index.tsx +9 -0
  22. package/src/components/CodeBlock/Actions/AskAi/index.tsx +10 -0
  23. package/src/components/CodeBlock/Actions/Copy/index.tsx +59 -0
  24. package/src/components/CodeBlock/Actions/index.tsx +137 -0
  25. package/src/components/CodeBlock/Collapsible/Button/index.tsx +58 -0
  26. package/src/components/CodeBlock/Collapsible/Fade/index.tsx +55 -0
  27. package/src/components/CodeBlock/Collapsible/Lines/index.tsx +22 -0
  28. package/src/components/CodeBlock/Header/Wrapper/index.tsx +46 -0
  29. package/src/components/CodeBlock/Header/index.tsx +67 -0
  30. package/src/components/CodeBlock/Inline/index.tsx +20 -0
  31. package/src/components/CodeBlock/Line/index.tsx +331 -0
  32. package/src/components/CodeBlock/index.tsx +510 -0
  33. package/src/components/CodeMdx/index.tsx +45 -0
  34. package/src/components/CodeTabs/Item/index.tsx +67 -0
  35. package/src/components/CodeTabs/index.tsx +319 -0
  36. package/src/components/ContentMenu/Actions/index.tsx +7 -0
  37. package/src/components/ContentMenu/Products/index.tsx +64 -0
  38. package/src/components/ContentMenu/Toc/index.tsx +148 -0
  39. package/src/components/ContentMenu/Version/index.tsx +77 -0
  40. package/src/components/ContentMenu/index.tsx +31 -0
  41. package/src/components/CopyButton/index.tsx +76 -0
  42. package/src/components/Details/Summary/index.tsx +75 -0
  43. package/src/components/Details/index.tsx +98 -0
  44. package/src/components/DetailsList/index.tsx +32 -0
  45. package/src/components/DottedSeparator/index.tsx +30 -0
  46. package/src/components/EditButton/index.tsx +32 -0
  47. package/src/components/EditDate/index.tsx +33 -0
  48. package/src/components/ErrorPage/Icon/index.tsx +428 -0
  49. package/src/components/ErrorPage/index.tsx +32 -0
  50. package/src/components/Feedback/Solutions/index.tsx +105 -0
  51. package/src/components/Feedback/index.tsx +304 -0
  52. package/src/components/Footer/index.tsx +23 -0
  53. package/src/components/Heading/H1/index.tsx +21 -0
  54. package/src/components/Heading/H2/index.tsx +47 -0
  55. package/src/components/Heading/H3/index.tsx +42 -0
  56. package/src/components/Heading/H4/index.tsx +14 -0
  57. package/src/components/Heading/index.tsx +4 -0
  58. package/src/components/IconHeadline/index.tsx +15 -0
  59. package/src/components/Icons/AiAssistant/index.tsx +462 -0
  60. package/src/components/Icons/ArrowRightDown/index.tsx +30 -0
  61. package/src/components/Icons/BundledProduct/index.tsx +72 -0
  62. package/src/components/Icons/CalendarRefresh/index.tsx +70 -0
  63. package/src/components/Icons/ChefHat/index.tsx +65 -0
  64. package/src/components/Icons/CircleDottedLine/index.tsx +60 -0
  65. package/src/components/Icons/CloudSolid/index.tsx +47 -0
  66. package/src/components/Icons/ColoredAcmeKit/index.tsx +13 -0
  67. package/src/components/Icons/DecisionProcess/index.tsx +58 -0
  68. package/src/components/Icons/Erp/index.tsx +92 -0
  69. package/src/components/Icons/Github/index.tsx +22 -0
  70. package/src/components/Icons/House/index.tsx +23 -0
  71. package/src/components/Icons/ImageBinary/index.tsx +69 -0
  72. package/src/components/Icons/Kapa/index.tsx +22 -0
  73. package/src/components/Icons/Markdown/index.tsx +25 -0
  74. package/src/components/Icons/NavigationDropdown/Admin/index.tsx +33 -0
  75. package/src/components/Icons/NavigationDropdown/Doc/index.tsx +41 -0
  76. package/src/components/Icons/NavigationDropdown/DocV1/index.tsx +37 -0
  77. package/src/components/Icons/NavigationDropdown/Modules/index.tsx +33 -0
  78. package/src/components/Icons/NavigationDropdown/Resources/index.tsx +37 -0
  79. package/src/components/Icons/NavigationDropdown/Store/index.tsx +37 -0
  80. package/src/components/Icons/NavigationDropdown/Ui/index.tsx +37 -0
  81. package/src/components/Icons/NavigationDropdown/User/index.tsx +37 -0
  82. package/src/components/Icons/PuzzleColored/index.tsx +35 -0
  83. package/src/components/Icons/QuestionMark/index.tsx +23 -0
  84. package/src/components/Icons/Restock/index.tsx +55 -0
  85. package/src/components/Icons/ScrollText/index.tsx +68 -0
  86. package/src/components/Icons/ShadedBg/index.tsx +334 -0
  87. package/src/components/Icons/Shop/index.tsx +68 -0
  88. package/src/components/Icons/SidebarLeft/index.tsx +42 -0
  89. package/src/components/Icons/StripeColored/index.tsx +60 -0
  90. package/src/components/Icons/ThumbDown/index.tsx +23 -0
  91. package/src/components/Icons/ThumbUp/index.tsx +23 -0
  92. package/src/components/Icons/WindowPaintbrush/index.tsx +57 -0
  93. package/src/components/Icons/index.tsx +20 -0
  94. package/src/components/InlineCode/index.tsx +42 -0
  95. package/src/components/InlineIcon/index.tsx +21 -0
  96. package/src/components/InlineThemeImage/index.tsx +14 -0
  97. package/src/components/Input/Search/index.tsx +64 -0
  98. package/src/components/Input/Text/index.tsx +39 -0
  99. package/src/components/Kbd/index.tsx +33 -0
  100. package/src/components/Label/index.tsx +19 -0
  101. package/src/components/Link/index.tsx +67 -0
  102. package/src/components/LinkButton/index.tsx +43 -0
  103. package/src/components/Loading/Dots/index.tsx +16 -0
  104. package/src/components/Loading/Spinner/index.tsx +19 -0
  105. package/src/components/Loading/index.tsx +43 -0
  106. package/src/components/MDXComponents/index.tsx +209 -0
  107. package/src/components/MainNav/DesktopMenu/ThemeMenu/index.tsx +76 -0
  108. package/src/components/MainNav/DesktopMenu/index.tsx +100 -0
  109. package/src/components/MainNav/Items/Dropdown/index.tsx +88 -0
  110. package/src/components/MainNav/Items/Link/index.tsx +34 -0
  111. package/src/components/MainNav/Items/index.tsx +61 -0
  112. package/src/components/MainNav/MobileMenu/Main/index.tsx +67 -0
  113. package/src/components/MainNav/MobileMenu/SubMenu/index.tsx +77 -0
  114. package/src/components/MainNav/MobileMenu/index.tsx +103 -0
  115. package/src/components/MainNav/Version/index.tsx +33 -0
  116. package/src/components/MainNav/index.tsx +153 -0
  117. package/src/components/MarkdownContent/index.tsx +41 -0
  118. package/src/components/Menu/Action/index.tsx +43 -0
  119. package/src/components/Menu/Divider/index.tsx +35 -0
  120. package/src/components/Menu/Dropdown/index.tsx +78 -0
  121. package/src/components/Menu/Item/index.tsx +36 -0
  122. package/src/components/Menu/SubMenu/index.tsx +47 -0
  123. package/src/components/Menu/index.tsx +44 -0
  124. package/src/components/Modal/Footer/index.tsx +29 -0
  125. package/src/components/Modal/Header/index.tsx +33 -0
  126. package/src/components/Modal/index.tsx +124 -0
  127. package/src/components/Note/Layout/index.tsx +139 -0
  128. package/src/components/Note/Types/checks.tsx +7 -0
  129. package/src/components/Note/Types/default.tsx +7 -0
  130. package/src/components/Note/Types/error.tsx +7 -0
  131. package/src/components/Note/Types/soon.tsx +7 -0
  132. package/src/components/Note/Types/sucess.tsx +7 -0
  133. package/src/components/Note/Types/warning.tsx +7 -0
  134. package/src/components/Note/index.tsx +32 -0
  135. package/src/components/Notices/DeprecatedNotice/index.tsx +33 -0
  136. package/src/components/Notices/ExpandableNotice/index.tsx +36 -0
  137. package/src/components/Notices/FeatureFlagNotice/index.tsx +36 -0
  138. package/src/components/Notices/VersionNotice/index.tsx +37 -0
  139. package/src/components/Notification/Item/Layout/Default/index.tsx +89 -0
  140. package/src/components/Notification/Item/index.tsx +88 -0
  141. package/src/components/Notification/index.tsx +65 -0
  142. package/src/components/Pagination/Card/index.tsx +80 -0
  143. package/src/components/Pagination/index.tsx +35 -0
  144. package/src/components/Prerequisites/Item/index.tsx +43 -0
  145. package/src/components/Prerequisites/index.tsx +94 -0
  146. package/src/components/RadioItem/index.tsx +38 -0
  147. package/src/components/Rating/index.tsx +133 -0
  148. package/src/components/RootProviders/index.tsx +31 -0
  149. package/src/components/Select/Badge/index.tsx +122 -0
  150. package/src/components/Select/Dropdown/index.tsx +188 -0
  151. package/src/components/Select/Input/index.tsx +123 -0
  152. package/src/components/Select/index.ts +13 -0
  153. package/src/components/Sidebar/Child/index.tsx +43 -0
  154. package/src/components/Sidebar/Item/Category/index.tsx +151 -0
  155. package/src/components/Sidebar/Item/Link/index.tsx +174 -0
  156. package/src/components/Sidebar/Item/Sidebar/index.tsx +67 -0
  157. package/src/components/Sidebar/Item/SubCategory/index.tsx +83 -0
  158. package/src/components/Sidebar/Item/index.tsx +41 -0
  159. package/src/components/Sidebar/Top/MobileClose/index.tsx +21 -0
  160. package/src/components/Sidebar/Top/index.tsx +33 -0
  161. package/src/components/Sidebar/index.tsx +153 -0
  162. package/src/components/SourceCodeLink/index.tsx +37 -0
  163. package/src/components/SplitLists/index.tsx +58 -0
  164. package/src/components/Table/index.tsx +87 -0
  165. package/src/components/Tabs/index.tsx +106 -0
  166. package/src/components/TextArea/index.tsx +30 -0
  167. package/src/components/ThemeImage/index.tsx +26 -0
  168. package/src/components/Toggle/index.tsx +28 -0
  169. package/src/components/Tooltip/index.tsx +65 -0
  170. package/src/components/TypeList/Items/index.tsx +337 -0
  171. package/src/components/TypeList/index.tsx +63 -0
  172. package/src/components/WideSection/index.tsx +25 -0
  173. package/src/components/ZoomImg/index.tsx +17 -0
  174. package/src/components/index.ts +75 -0
  175. package/src/constants.tsx +261 -0
  176. package/src/global-config.ts +11 -0
  177. package/src/hooks/index.ts +14 -0
  178. package/src/hooks/use-active-on-scroll/index.tsx +223 -0
  179. package/src/hooks/use-click-outside/index.tsx +37 -0
  180. package/src/hooks/use-collapsible/index.tsx +128 -0
  181. package/src/hooks/use-collapsible-code-lines/index.tsx +149 -0
  182. package/src/hooks/use-copy/index.tsx +28 -0
  183. package/src/hooks/use-heading-url/index.tsx +32 -0
  184. package/src/hooks/use-is-external-link/index.tsx +19 -0
  185. package/src/hooks/use-keyboard-shortcut/index.tsx +71 -0
  186. package/src/hooks/use-mutation-observer/index.ts +32 -0
  187. package/src/hooks/use-page-scroll-manager/index.tsx +82 -0
  188. package/src/hooks/use-resize-observer/index.ts +20 -0
  189. package/src/hooks/use-scroll-utils/index.tsx +372 -0
  190. package/src/hooks/use-select/index.tsx +99 -0
  191. package/src/hooks/use-tabs/index.tsx +94 -0
  192. package/src/index.ts +8 -0
  193. package/src/layouts/barebone.tsx +18 -0
  194. package/src/layouts/index.ts +4 -0
  195. package/src/layouts/main-content.tsx +86 -0
  196. package/src/layouts/root.tsx +43 -0
  197. package/src/layouts/tight.tsx +29 -0
  198. package/src/layouts/wide.tsx +25 -0
  199. package/src/providers/AiAssistant/index.tsx +65 -0
  200. package/src/providers/BrowserProvider/index.tsx +40 -0
  201. package/src/providers/ColorMode/index.tsx +73 -0
  202. package/src/providers/Layout/index.tsx +52 -0
  203. package/src/providers/MainNav/index.tsx +134 -0
  204. package/src/providers/Mobile/index.tsx +62 -0
  205. package/src/providers/Modal/index.tsx +52 -0
  206. package/src/providers/Notification/index.tsx +149 -0
  207. package/src/providers/Pagination/index.tsx +230 -0
  208. package/src/providers/Search/index.tsx +91 -0
  209. package/src/providers/Sidebar/index.tsx +745 -0
  210. package/src/providers/SiteConfig/index.tsx +70 -0
  211. package/src/providers/index.ts +13 -0
  212. package/src/types/config.ts +34 -0
  213. package/src/types/frontmatter.ts +23 -0
  214. package/src/types/general.ts +1 -0
  215. package/src/types/index.ts +9 -0
  216. package/src/types/menu.ts +40 -0
  217. package/src/types/navigation-dropdown.ts +16 -0
  218. package/src/types/navigation.ts +21 -0
  219. package/src/types/sidebar.ts +109 -0
  220. package/src/types/toc.ts +19 -0
  221. package/src/types/ui.ts +9 -0
  222. package/src/utils/array-same-elms.ts +10 -0
  223. package/src/utils/capitalize.ts +3 -0
  224. package/src/utils/check-sidebar-item-visibility.ts +47 -0
  225. package/src/utils/decode-str.ts +8 -0
  226. package/src/utils/dom-utils.ts +29 -0
  227. package/src/utils/event-parser.ts +54 -0
  228. package/src/utils/get-link-with-base-path.ts +3 -0
  229. package/src/utils/get-navbar-items.ts +55 -0
  230. package/src/utils/get-scrolled-top.ts +8 -0
  231. package/src/utils/index.ts +13 -0
  232. package/src/utils/is-elm-window.ts +3 -0
  233. package/src/utils/is-in-view.ts +10 -0
  234. package/src/utils/os-browser-utils.ts +39 -0
  235. package/src/utils/set-obj-value.ts +38 -0
  236. package/src/utils/sidebar-utils.ts +129 -0
@@ -0,0 +1,149 @@
1
+
2
+ import React, { createContext, useContext, useMemo, useReducer } from "react"
3
+ import { NotificationContainer } from "../../components/Notification"
4
+ import uuid from "react-uuid"
5
+ import { NotificationItemProps } from "../../components/Notification/Item"
6
+
7
+ export type NotificationItemType = {
8
+ id?: string
9
+ } & NotificationItemProps
10
+
11
+ export type NotificationContextType = {
12
+ notifications: NotificationItemType[]
13
+ addNotification: (value: NotificationItemType) => void
14
+ generateId: () => string
15
+ removeNotification: (id: string) => void
16
+ updateNotification: (
17
+ id: string,
18
+ updatedData: Partial<Omit<NotificationItemType, "id">>
19
+ ) => void
20
+ }
21
+
22
+ export enum NotificationReducerActionTypes {
23
+ ADD = "add",
24
+ REMOVE = "remove",
25
+ UPDATE = "update",
26
+ }
27
+
28
+ export type NotificationReducerAction =
29
+ | {
30
+ type: NotificationReducerActionTypes.ADD
31
+ notification: NotificationItemType
32
+ }
33
+ | {
34
+ type: NotificationReducerActionTypes.REMOVE
35
+ id: string
36
+ }
37
+ | {
38
+ type: NotificationReducerActionTypes.UPDATE
39
+ id: string
40
+ updatedData: Partial<Omit<NotificationItemType, "id">>
41
+ }
42
+
43
+ const notificationReducer = (
44
+ state: NotificationItemType[],
45
+ action: NotificationReducerAction
46
+ ) => {
47
+ switch (action.type) {
48
+ case NotificationReducerActionTypes.ADD:
49
+ return [...state, action.notification]
50
+ case NotificationReducerActionTypes.REMOVE:
51
+ return state.filter((notification) => notification.id !== action.id)
52
+ case NotificationReducerActionTypes.UPDATE:
53
+ return state.map((notification) => {
54
+ if (notification.id === action.id) {
55
+ return {
56
+ ...notification,
57
+ ...action.updatedData,
58
+ }
59
+ }
60
+
61
+ return notification
62
+ })
63
+ default:
64
+ return state
65
+ }
66
+ }
67
+
68
+ const NotificationContext = createContext<NotificationContextType | null>(null)
69
+
70
+ export type NotificationProviderProps = {
71
+ children?: React.ReactNode
72
+ initial?: NotificationItemType[]
73
+ }
74
+
75
+ export const NotificationProvider = ({
76
+ children,
77
+ initial = [],
78
+ }: NotificationProviderProps) => {
79
+ const generateId = () => uuid()
80
+
81
+ const normalizedInitial = useMemo(() => {
82
+ return initial.map((notif) => ({
83
+ id: generateId(),
84
+ ...notif,
85
+ }))
86
+ }, [initial])
87
+
88
+ const [notifications, dispatch] = useReducer(
89
+ notificationReducer,
90
+ normalizedInitial
91
+ )
92
+
93
+ const addNotification = (notification: NotificationItemType) => {
94
+ if (!notification.id) {
95
+ notification.id = generateId()
96
+ }
97
+ dispatch({
98
+ type: NotificationReducerActionTypes.ADD,
99
+ notification,
100
+ })
101
+ }
102
+
103
+ const updateNotification = (
104
+ id: string,
105
+ updatedData: Partial<Omit<NotificationItemType, "id">>
106
+ ) => {
107
+ dispatch({
108
+ type: NotificationReducerActionTypes.UPDATE,
109
+ id,
110
+ updatedData,
111
+ })
112
+ }
113
+
114
+ const removeNotification = (id: string) => {
115
+ dispatch({
116
+ type: NotificationReducerActionTypes.REMOVE,
117
+ id,
118
+ })
119
+ }
120
+
121
+ return (
122
+ <NotificationContext.Provider
123
+ value={{
124
+ notifications,
125
+ addNotification,
126
+ generateId,
127
+ removeNotification,
128
+ updateNotification,
129
+ }}
130
+ >
131
+ {children}
132
+ <NotificationContainer />
133
+ </NotificationContext.Provider>
134
+ )
135
+ }
136
+
137
+ export const useNotifications = (
138
+ suppressError?: boolean
139
+ ): NotificationContextType | null => {
140
+ const context = useContext(NotificationContext)
141
+
142
+ if (!context && !suppressError) {
143
+ throw new Error(
144
+ "useNotifications must be used within a NotificationProvider"
145
+ )
146
+ }
147
+
148
+ return context
149
+ }
@@ -0,0 +1,230 @@
1
+
2
+ import React, { createContext, useContext, useEffect, useState } from "react"
3
+ import { usePrevious } from "@uidotdev/usehooks"
4
+ import { useSidebar } from "../Sidebar"
5
+ import { isSidebarItemLink } from "../../utils/sidebar-utils"
6
+ import { Sidebar } from "../../types"
7
+
8
+ export type Page = {
9
+ title: string
10
+ description?: string
11
+ parentTitle?: string
12
+ link: string
13
+ }
14
+
15
+ export type PaginationContextType = {
16
+ nextPage?: Page
17
+ previousPage?: Page
18
+ }
19
+
20
+ export const PaginationContext = createContext<PaginationContextType | null>(
21
+ null
22
+ )
23
+
24
+ type SidebarItemWithParent = Sidebar.InteractiveSidebarItem & {
25
+ parent?: Sidebar.InteractiveSidebarItem
26
+ }
27
+
28
+ type SearchItemsResult = {
29
+ foundActive: boolean
30
+ prevItem?: SidebarItemWithParent
31
+ nextItem?: SidebarItemWithParent
32
+ }
33
+
34
+ export type PaginationProviderProps = {
35
+ children?: React.ReactNode
36
+ }
37
+
38
+ export const PaginationProvider = ({ children }: PaginationProviderProps) => {
39
+ const { shownSidebar, activePath } = useSidebar()
40
+ const previousActivePath = usePrevious(activePath)
41
+ const [nextPage, setNextPage] = useState<Page | undefined>()
42
+ const [prevPage, setPrevPage] = useState<Page | undefined>()
43
+
44
+ const getFirstChild = (
45
+ item: Sidebar.InteractiveSidebarItem
46
+ ): SidebarItemWithParent | undefined => {
47
+ const children = getChildrenWithPages(item)
48
+ if (!children?.length) {
49
+ return undefined
50
+ }
51
+
52
+ return isSidebarItemLink(children[0])
53
+ ? {
54
+ ...children[0],
55
+ parent: item,
56
+ }
57
+ : getFirstChild(children[0])
58
+ }
59
+
60
+ const getChildrenWithPages = (
61
+ item: Sidebar.InteractiveSidebarItem
62
+ ): SidebarItemWithParent[] | undefined => {
63
+ return item.children?.filter(
64
+ (childItem) =>
65
+ isSidebarItemLink(childItem) ||
66
+ (childItem.type !== "separator" &&
67
+ getChildrenWithPages(childItem)?.length)
68
+ ) as SidebarItemWithParent[]
69
+ }
70
+
71
+ const getPrevItem = (
72
+ items: Sidebar.SidebarItem[],
73
+ index: number
74
+ ): SidebarItemWithParent | undefined => {
75
+ let foundItem: SidebarItemWithParent | undefined
76
+ items
77
+ .slice(0, index)
78
+ .reverse()
79
+ .some((item) => {
80
+ if (item.type === "separator") {
81
+ return false
82
+ }
83
+ if (item.children?.length) {
84
+ const childItem = getPrevItem(item.children, item.children.length)
85
+ if (childItem) {
86
+ foundItem = {
87
+ ...childItem,
88
+ parent: item,
89
+ }
90
+ }
91
+ } else if (isSidebarItemLink(item)) {
92
+ foundItem = item
93
+ }
94
+
95
+ return foundItem !== undefined
96
+ })
97
+
98
+ return foundItem
99
+ }
100
+
101
+ const getNextItem = (
102
+ items: Sidebar.SidebarItem[],
103
+ index: number
104
+ ): SidebarItemWithParent | undefined => {
105
+ let foundItem: SidebarItemWithParent | undefined
106
+ items.slice(index + 1).some((item) => {
107
+ if (item.type === "separator") {
108
+ return false
109
+ }
110
+
111
+ if (isSidebarItemLink(item)) {
112
+ foundItem = item
113
+ } else if (item.children?.length) {
114
+ const childItem = getNextItem(item.children, -1)
115
+ if (childItem) {
116
+ foundItem = {
117
+ ...childItem,
118
+ parent: item,
119
+ }
120
+ }
121
+ }
122
+
123
+ return foundItem !== undefined
124
+ })
125
+
126
+ return foundItem
127
+ }
128
+
129
+ const searchItems = (
130
+ currentItems: Sidebar.SidebarItem[]
131
+ ): SearchItemsResult => {
132
+ const result: SearchItemsResult = {
133
+ foundActive: false,
134
+ }
135
+
136
+ result.foundActive = currentItems.some((item, index) => {
137
+ if (isSidebarItemLink(item) && item.path === activePath) {
138
+ if (index !== 0) {
139
+ result.prevItem = getPrevItem(currentItems, index)
140
+ }
141
+
142
+ if (item.children?.length) {
143
+ result.nextItem = getFirstChild(item)
144
+ }
145
+
146
+ if (!result.nextItem && index !== currentItems.length - 1) {
147
+ result.nextItem = getNextItem(currentItems, index)
148
+ }
149
+ return true
150
+ }
151
+
152
+ if (item.type !== "separator" && item.children?.length) {
153
+ const childrenResult = searchItems(item.children)
154
+
155
+ if (childrenResult.foundActive) {
156
+ result.prevItem = childrenResult.prevItem
157
+ result.nextItem = childrenResult.nextItem
158
+ if (!result.prevItem) {
159
+ result.prevItem = isSidebarItemLink(item)
160
+ ? item
161
+ : getPrevItem(currentItems, index)
162
+ }
163
+
164
+ if (!result.nextItem && index !== currentItems.length - 1) {
165
+ result.nextItem = getNextItem(currentItems, index)
166
+ }
167
+
168
+ return true
169
+ }
170
+ }
171
+
172
+ return false
173
+ })
174
+
175
+ return result
176
+ }
177
+
178
+ useEffect(() => {
179
+ if (activePath !== previousActivePath) {
180
+ const sidebarItems =
181
+ shownSidebar && "items" in shownSidebar
182
+ ? shownSidebar.items
183
+ : shownSidebar?.children || []
184
+ const result = searchItems(sidebarItems)
185
+ setPrevPage(
186
+ result.prevItem
187
+ ? {
188
+ title: result.prevItem.title,
189
+ link: isSidebarItemLink(result.prevItem)
190
+ ? result.prevItem.path
191
+ : "",
192
+ parentTitle: result.prevItem.parent?.title,
193
+ }
194
+ : undefined
195
+ )
196
+ setNextPage(
197
+ result.nextItem
198
+ ? {
199
+ title: result.nextItem.title,
200
+ link: isSidebarItemLink(result.nextItem)
201
+ ? result.nextItem.path
202
+ : "",
203
+ parentTitle: result.nextItem?.parent?.title,
204
+ }
205
+ : undefined
206
+ )
207
+ }
208
+ }, [activePath, previousActivePath])
209
+
210
+ return (
211
+ <PaginationContext.Provider
212
+ value={{
213
+ previousPage: prevPage,
214
+ nextPage,
215
+ }}
216
+ >
217
+ {children}
218
+ </PaginationContext.Provider>
219
+ )
220
+ }
221
+
222
+ export const usePagination = (): PaginationContextType => {
223
+ const context = useContext(PaginationContext)
224
+
225
+ if (!context) {
226
+ throw new Error("usePagination must be used inside a PaginationProvider")
227
+ }
228
+
229
+ return context
230
+ }
@@ -0,0 +1,91 @@
1
+ import React, { createContext, useContext, useRef, useState } from "react"
2
+ import { BadgeProps } from "../../components/Badge"
3
+
4
+ export type SearchCommand = {
5
+ name: string
6
+ component?: React.ReactNode
7
+ action?: () => void
8
+ icon?: React.ReactNode
9
+ title: string
10
+ badge?: BadgeProps
11
+ }
12
+
13
+ export type SearchContextType = {
14
+ isOpen: boolean
15
+ setIsOpen: React.Dispatch<React.SetStateAction<boolean>>
16
+ searchClient: any
17
+ commands: SearchCommand[]
18
+ command: SearchCommand | null
19
+ setCommand: React.Dispatch<React.SetStateAction<SearchCommand | null>>
20
+ setCommands: React.Dispatch<React.SetStateAction<SearchCommand[]>>
21
+ modalRef: React.RefObject<HTMLDialogElement | null>
22
+ indices: AlgoliaIndex[]
23
+ selectedIndex: string
24
+ setSelectedIndex: (value: string) => void
25
+ }
26
+
27
+ const SearchContext = createContext<SearchContextType | null>(null)
28
+
29
+ export type AlgoliaIndex = {
30
+ value: string
31
+ title: string
32
+ }
33
+
34
+ export type AlgoliaProps = {
35
+ appId: string
36
+ apiKey: string
37
+ mainIndexName: string
38
+ }
39
+
40
+ export type SearchProps = {
41
+ algolia: AlgoliaProps
42
+ }
43
+
44
+ export type SearchProviderProps = {
45
+ children: React.ReactNode
46
+ indices?: AlgoliaIndex[]
47
+ defaultIndex?: string
48
+ algolia?: AlgoliaProps
49
+ searchProps?: any
50
+ commands?: SearchCommand[]
51
+ modalClassName?: string
52
+ }
53
+
54
+ export const SearchProvider = ({
55
+ children,
56
+ }: SearchProviderProps) => {
57
+ const [isOpen, setIsOpen] = useState(false)
58
+ const [commands, setCommands] = useState<SearchCommand[]>([])
59
+ const [command, setCommand] = useState<SearchCommand | null>(null)
60
+ const modalRef = useRef<HTMLDialogElement | null>(null)
61
+
62
+ return (
63
+ <SearchContext.Provider
64
+ value={{
65
+ isOpen,
66
+ setIsOpen,
67
+ searchClient: null,
68
+ commands,
69
+ command,
70
+ setCommand,
71
+ modalRef,
72
+ setCommands,
73
+ indices: [],
74
+ selectedIndex: "",
75
+ setSelectedIndex: () => {},
76
+ }}
77
+ >
78
+ {children}
79
+ </SearchContext.Provider>
80
+ )
81
+ }
82
+
83
+ export const useSearch = (): SearchContextType => {
84
+ const context = useContext(SearchContext)
85
+
86
+ if (!context) {
87
+ throw new Error("useSearch must be used inside a SearchProvider")
88
+ }
89
+
90
+ return context
91
+ }