@xyd-js/components 0.1.0-build.168

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 (314) hide show
  1. package/.idea/git_toolbox_blame.xml +6 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/.idea/xyd-components.iml +12 -0
  5. package/CHANGELOG.md +1369 -0
  6. package/LICENSE +21 -0
  7. package/README.md +3 -0
  8. package/TODO.md +1 -0
  9. package/coder.ts +1 -0
  10. package/content.ts +1 -0
  11. package/dist/Button-BLA2ghHZ.js +2 -0
  12. package/dist/Button-BLA2ghHZ.js.map +1 -0
  13. package/dist/Button-BTJ2hIal.js +2 -0
  14. package/dist/Button-BTJ2hIal.js.map +1 -0
  15. package/dist/Button-r4BCrEjy.js +2 -0
  16. package/dist/Button-r4BCrEjy.js.map +1 -0
  17. package/dist/CodeSample-BZ5tvyWY.js +2 -0
  18. package/dist/CodeSample-BZ5tvyWY.js.map +1 -0
  19. package/dist/CodeSample-BqXDbWdi.js +2 -0
  20. package/dist/CodeSample-BqXDbWdi.js.map +1 -0
  21. package/dist/CodeSample-Cqv86IdN.js +2 -0
  22. package/dist/CodeSample-Cqv86IdN.js.map +1 -0
  23. package/dist/Icon--77MqplU.js +2 -0
  24. package/dist/Icon--77MqplU.js.map +1 -0
  25. package/dist/Icon-DbNmvK_Q.js +2 -0
  26. package/dist/Icon-DbNmvK_Q.js.map +1 -0
  27. package/dist/Icon-uVIU1LW6.js +2 -0
  28. package/dist/Icon-uVIU1LW6.js.map +1 -0
  29. package/dist/PageFirstSlide-BDNmCTiJ.js +2 -0
  30. package/dist/PageFirstSlide-BDNmCTiJ.js.map +1 -0
  31. package/dist/PageFirstSlide-BpZ42bEU.js +2 -0
  32. package/dist/PageFirstSlide-BpZ42bEU.js.map +1 -0
  33. package/dist/PageFirstSlide-CqxiyK57.js +2 -0
  34. package/dist/PageFirstSlide-CqxiyK57.js.map +1 -0
  35. package/dist/TabsAnalytics-B_JYpawG.js +2 -0
  36. package/dist/TabsAnalytics-B_JYpawG.js.map +1 -0
  37. package/dist/TabsAnalytics-DAOfTZgv.js +2 -0
  38. package/dist/TabsAnalytics-DAOfTZgv.js.map +1 -0
  39. package/dist/TabsAnalytics-Dhyadlbu.js +2 -0
  40. package/dist/TabsAnalytics-Dhyadlbu.js.map +1 -0
  41. package/dist/Update-53fEhmjh.js +2 -0
  42. package/dist/Update-53fEhmjh.js.map +1 -0
  43. package/dist/Update-CFi6uapq.js +2 -0
  44. package/dist/Update-CFi6uapq.js.map +1 -0
  45. package/dist/Update-CiMIOgZi.js +2 -0
  46. package/dist/Update-CiMIOgZi.js.map +1 -0
  47. package/dist/VideoGuide-C0K9fFar.js +2 -0
  48. package/dist/VideoGuide-C0K9fFar.js.map +1 -0
  49. package/dist/VideoGuide-CJYkuLst.js +2 -0
  50. package/dist/VideoGuide-CJYkuLst.js.map +1 -0
  51. package/dist/VideoGuide-DBY-EyxG.js +2 -0
  52. package/dist/VideoGuide-DBY-EyxG.js.map +1 -0
  53. package/dist/_rollupPluginBabelHelpers-CvhQFv1t.js +4 -0
  54. package/dist/_rollupPluginBabelHelpers-CvhQFv1t.js.map +1 -0
  55. package/dist/_rollupPluginBabelHelpers-DSwDY1Dm.js +4 -0
  56. package/dist/_rollupPluginBabelHelpers-DSwDY1Dm.js.map +1 -0
  57. package/dist/_rollupPluginBabelHelpers-Dc-ocx4G.js +4 -0
  58. package/dist/_rollupPluginBabelHelpers-Dc-ocx4G.js.map +1 -0
  59. package/dist/coder/themes/classic.css +57 -0
  60. package/dist/coder/themes/classic.d.ts +96 -0
  61. package/dist/coder/themes/classic.js +2 -0
  62. package/dist/coder/themes/classic.js.map +1 -0
  63. package/dist/coder/themes/cosmo.css +64 -0
  64. package/dist/coder/themes/cosmo.d.ts +96 -0
  65. package/dist/coder/themes/cosmo.js +2 -0
  66. package/dist/coder/themes/cosmo.js.map +1 -0
  67. package/dist/coder.d.ts +94 -0
  68. package/dist/coder.js +2 -0
  69. package/dist/coder.js.map +1 -0
  70. package/dist/content.d.ts +411 -0
  71. package/dist/content.js +2 -0
  72. package/dist/content.js.map +1 -0
  73. package/dist/index.css +282 -0
  74. package/dist/index.d.ts +2 -0
  75. package/dist/index.js +2 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/layouts.d.ts +33 -0
  78. package/dist/layouts.js +2 -0
  79. package/dist/layouts.js.map +1 -0
  80. package/dist/pages.d.ts +176 -0
  81. package/dist/pages.js +2 -0
  82. package/dist/pages.js.map +1 -0
  83. package/dist/system.d.ts +45 -0
  84. package/dist/system.js +2 -0
  85. package/dist/system.js.map +1 -0
  86. package/dist/useUXClick-DK3cTAMR.js +2 -0
  87. package/dist/useUXClick-DK3cTAMR.js.map +1 -0
  88. package/dist/useUXClick-DO6qBcRy.js +2 -0
  89. package/dist/useUXClick-DO6qBcRy.js.map +1 -0
  90. package/dist/useUXClick-NwpsiuK9.js +2 -0
  91. package/dist/useUXClick-NwpsiuK9.js.map +1 -0
  92. package/dist/useUXEvents-CJtgGV4R.js +2 -0
  93. package/dist/useUXEvents-CJtgGV4R.js.map +1 -0
  94. package/dist/useUXEvents-Cxgl7xb-.js +2 -0
  95. package/dist/useUXEvents-Cxgl7xb-.js.map +1 -0
  96. package/dist/useUXEvents-XqAGxoEj.js +2 -0
  97. package/dist/useUXEvents-XqAGxoEj.js.map +1 -0
  98. package/dist/useUXScrollDepth-3rk3Z95r.js +2 -0
  99. package/dist/useUXScrollDepth-3rk3Z95r.js.map +1 -0
  100. package/dist/useUXScrollDepth-BwK-XOBg.js +2 -0
  101. package/dist/useUXScrollDepth-BwK-XOBg.js.map +1 -0
  102. package/dist/useUXScrollDepth-DKre7PBz.js +2 -0
  103. package/dist/useUXScrollDepth-DKre7PBz.js.map +1 -0
  104. package/dist/uxsdk.d.ts +53 -0
  105. package/dist/uxsdk.js +2 -0
  106. package/dist/uxsdk.js.map +1 -0
  107. package/dist/views.d.ts +18 -0
  108. package/dist/views.js +2 -0
  109. package/dist/views.js.map +1 -0
  110. package/dist/writer.d.ts +580 -0
  111. package/dist/writer.js +2 -0
  112. package/dist/writer.js.map +1 -0
  113. package/docs/.nojekyll +1 -0
  114. package/docs/assets/hierarchy.js +1 -0
  115. package/docs/assets/highlight.css +22 -0
  116. package/docs/assets/icons.js +18 -0
  117. package/docs/assets/icons.svg +1 -0
  118. package/docs/assets/main.js +60 -0
  119. package/docs/assets/navigation.js +1 -0
  120. package/docs/assets/search.js +1 -0
  121. package/docs/assets/style.css +1640 -0
  122. package/docs/functions/GuideCard.html +6 -0
  123. package/docs/hierarchy.html +1 -0
  124. package/docs/index.html +2 -0
  125. package/docs/interfaces/GuideCardProps.html +18 -0
  126. package/docs/modules.html +1 -0
  127. package/index.ts +0 -0
  128. package/layouts.ts +1 -0
  129. package/output.txt +13 -0
  130. package/package.json +81 -0
  131. package/pages.ts +1 -0
  132. package/postcss.config.cjs +5 -0
  133. package/rollup.config.js +195 -0
  134. package/src/coder/Code/Code.styles.tsx +151 -0
  135. package/src/coder/Code/Code.tsx +171 -0
  136. package/src/coder/Code/CodeLoader.tsx +10 -0
  137. package/src/coder/Code/annotations.tsx +51 -0
  138. package/src/coder/Code/highlight.ts +208 -0
  139. package/src/coder/Code/index.ts +16 -0
  140. package/src/coder/CodeCopy/CodeCopy.styles.tsx +21 -0
  141. package/src/coder/CodeCopy/CodeCopy.tsx +36 -0
  142. package/src/coder/CodeCopy/index.ts +7 -0
  143. package/src/coder/CodeSample/CodeSample.tsx +118 -0
  144. package/src/coder/CodeSample/CodeSampleAnalytics.tsx +112 -0
  145. package/src/coder/CodeSample/index.ts +11 -0
  146. package/src/coder/CodeSample/withLocalStored.tsx +50 -0
  147. package/src/coder/CodeTabs/CodeTabs.styles.tsx +126 -0
  148. package/src/coder/CodeTabs/CodeTabs.tsx +128 -0
  149. package/src/coder/CodeTabs/index.ts +6 -0
  150. package/src/coder/CodeTheme/CodeTheme.tsx +126 -0
  151. package/src/coder/CodeTheme/index.ts +7 -0
  152. package/src/coder/CoderProvider.tsx +26 -0
  153. package/src/coder/README.md +1 -0
  154. package/src/coder/hooks/highlight.ts +182 -0
  155. package/src/coder/index.ts +37 -0
  156. package/src/coder/themes/classic.css +57 -0
  157. package/src/coder/themes/classic.ts +270 -0
  158. package/src/coder/themes/cosmo.css +64 -0
  159. package/src/coder/themes/cosmo.ts +264 -0
  160. package/src/content/AppearanceDecorator.styles.tsx +11 -0
  161. package/src/content/ContentDecoator.styles.tsx +180 -0
  162. package/src/content/ContentDecorator.tsx +17 -0
  163. package/src/content/GridDecorator.styles.tsx +86 -0
  164. package/src/content/GridDecorator.tsx +23 -0
  165. package/src/content/ReactContent.tsx +671 -0
  166. package/src/content/TODO.md +1 -0
  167. package/src/content/index.ts +13 -0
  168. package/src/kit/Loader/Loader.styles.tsx +53 -0
  169. package/src/kit/Loader/Loader.tsx +22 -0
  170. package/src/kit/TODO.md +2 -0
  171. package/src/kit/index.ts +1 -0
  172. package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +325 -0
  173. package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +252 -0
  174. package/src/layouts/LayoutPrimary/index.ts +3 -0
  175. package/src/layouts/index.ts +6 -0
  176. package/src/pages/PageBlogHome/PageBlogHome.styles.tsx +67 -0
  177. package/src/pages/PageBlogHome/PageBlogHome.tsx +64 -0
  178. package/src/pages/PageBlogHome/index.ts +3 -0
  179. package/src/pages/PageBlogHome/types.ts +35 -0
  180. package/src/pages/PageBlogPost/PageBlogPost.styles.tsx +4 -0
  181. package/src/pages/PageBlogPost/PageBlogPost.tsx +9 -0
  182. package/src/pages/PageBlogPost/index.ts +3 -0
  183. package/src/pages/PageFirstSlide/PageFirstSlide.styles.tsx +134 -0
  184. package/src/pages/PageFirstSlide/PageFirstSlide.tsx +56 -0
  185. package/src/pages/PageFirstSlide/index.ts +1 -0
  186. package/src/pages/PageFirstSlide/types.ts +67 -0
  187. package/src/pages/PageHome/PageHome.styles.tsx +51 -0
  188. package/src/pages/PageHome/PageHome.tsx +62 -0
  189. package/src/pages/PageHome/index.ts +3 -0
  190. package/src/pages/PageHome/types.ts +79 -0
  191. package/src/pages/index.ts +7 -0
  192. package/src/system/Baseline/Baseline.styles.tsx +128 -0
  193. package/src/system/Baseline/Baseline.tsx +40 -0
  194. package/src/system/Baseline/bun.svg +1 -0
  195. package/src/system/Baseline/check.svg +1 -0
  196. package/src/system/Baseline/index.ts +1 -0
  197. package/src/system/Baseline/logo.svg +1 -0
  198. package/src/system/Baseline/node.svg +7 -0
  199. package/src/system/Baseline/npm.svg +5 -0
  200. package/src/system/Baseline/pnpm.svg +1 -0
  201. package/src/system/Footer/Footer.styles.tsx +213 -0
  202. package/src/system/Footer/Footer.tsx +105 -0
  203. package/src/system/Footer/index.ts +1 -0
  204. package/src/system/SearchButton/SearchButton.styles.tsx +89 -0
  205. package/src/system/SearchButton/SearchButton.tsx +118 -0
  206. package/src/system/SearchButton/index.ts +1 -0
  207. package/src/system/index.ts +3 -0
  208. package/src/utils/useStyle.ts +19 -0
  209. package/src/uxsdk/const.ts +1 -0
  210. package/src/uxsdk/index.ts +21 -0
  211. package/src/uxsdk/useUXClick.ts +21 -0
  212. package/src/uxsdk/useUXEvents.ts +105 -0
  213. package/src/uxsdk/useUXScrollDepth.ts +49 -0
  214. package/src/uxsdk/useUXUnreachableElementTracker.ts +100 -0
  215. package/src/views/HomeView/HomeView.styles.tsx +37 -0
  216. package/src/views/HomeView/HomeView.tsx +34 -0
  217. package/src/views/HomeView/index.ts +3 -0
  218. package/src/writer/Anchor/Anchor.styles.tsx +26 -0
  219. package/src/writer/Anchor/Anchor.tsx +51 -0
  220. package/src/writer/Anchor/index.tsx +1 -0
  221. package/src/writer/Badge/Badge.styles.tsx +44 -0
  222. package/src/writer/Badge/Badge.tsx +47 -0
  223. package/src/writer/Badge/index.ts +7 -0
  224. package/src/writer/Banner/Banner.styles.tsx +111 -0
  225. package/src/writer/Banner/Banner.tsx +151 -0
  226. package/src/writer/Banner/index.ts +1 -0
  227. package/src/writer/Blockquote/Blockquote.styles.tsx +20 -0
  228. package/src/writer/Blockquote/Blockquote.tsx +38 -0
  229. package/src/writer/Blockquote/index.ts +7 -0
  230. package/src/writer/BlogCard/BlogCard.styles.tsx +4 -0
  231. package/src/writer/BlogCard/BlogCard.tsx +9 -0
  232. package/src/writer/BlogCard/index.ts +3 -0
  233. package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +24 -0
  234. package/src/writer/Breadcrumbs/Breadcrumbs.tsx +57 -0
  235. package/src/writer/Breadcrumbs/index.ts +7 -0
  236. package/src/writer/Button/Button.styles.tsx +149 -0
  237. package/src/writer/Button/Button.tsx +82 -0
  238. package/src/writer/Button/index.ts +2 -0
  239. package/src/writer/Callout/Callout.styles.tsx +102 -0
  240. package/src/writer/Callout/Callout.tsx +166 -0
  241. package/src/writer/Callout/index.tsx +3 -0
  242. package/src/writer/Card/Card.styles.tsx +110 -0
  243. package/src/writer/Card/Card.tsx +94 -0
  244. package/src/writer/Card/index.ts +1 -0
  245. package/src/writer/Code/Code.styles.tsx +16 -0
  246. package/src/writer/Code/Code.tsx +16 -0
  247. package/src/writer/Code/index.ts +3 -0
  248. package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +191 -0
  249. package/src/writer/ColorSchemeButton/index.ts +1 -0
  250. package/src/writer/Details/Details.styles.tsx +101 -0
  251. package/src/writer/Details/Details.tsx +168 -0
  252. package/src/writer/Details/DetailsProps.tsx +34 -0
  253. package/src/writer/Details/index.ts +6 -0
  254. package/src/writer/GuideCard/GuideCard.styles.tsx +129 -0
  255. package/src/writer/GuideCard/GuideCard.tsx +123 -0
  256. package/src/writer/GuideCard/index.ts +1 -0
  257. package/src/writer/Heading/Heading.styles.tsx +93 -0
  258. package/src/writer/Heading/Heading.tsx +123 -0
  259. package/src/writer/Heading/index.ts +7 -0
  260. package/src/writer/Hr/Hr.styles.tsx +7 -0
  261. package/src/writer/Hr/Hr.tsx +10 -0
  262. package/src/writer/Hr/index.ts +3 -0
  263. package/src/writer/Icon/Icon.styles.tsx +15 -0
  264. package/src/writer/Icon/Icon.tsx +99 -0
  265. package/src/writer/Icon/index.ts +1 -0
  266. package/src/writer/IconSocial/IconSocial.tsx +107 -0
  267. package/src/writer/IconSocial/index.ts +1 -0
  268. package/src/writer/Image/Image.styles.tsx +9 -0
  269. package/src/writer/Image/Image.tsx +35 -0
  270. package/src/writer/Image/index.ts +1 -0
  271. package/src/writer/List/List.styles.tsx +47 -0
  272. package/src/writer/List/List.tsx +29 -0
  273. package/src/writer/List/index.ts +4 -0
  274. package/src/writer/NavLinks/NavLinks.styles.ts +32 -0
  275. package/src/writer/NavLinks/NavLinks.tsx +95 -0
  276. package/src/writer/NavLinks/index.ts +7 -0
  277. package/src/writer/Pre/Pre.styles.tsx +13 -0
  278. package/src/writer/Pre/Pre.tsx +14 -0
  279. package/src/writer/Pre/index.ts +3 -0
  280. package/src/writer/README.md +1 -0
  281. package/src/writer/Steps/Steps.styles.tsx +91 -0
  282. package/src/writer/Steps/Steps.tsx +75 -0
  283. package/src/writer/Steps/index.ts +5 -0
  284. package/src/writer/Table/Table.styles.tsx +100 -0
  285. package/src/writer/Table/Table.tsx +158 -0
  286. package/src/writer/Table/index.ts +3 -0
  287. package/src/writer/Tabs/Tabs.tsx +67 -0
  288. package/src/writer/Tabs/TabsAnalytics.tsx +25 -0
  289. package/src/writer/Tabs/TabsPrimary.styles.tsx +187 -0
  290. package/src/writer/Tabs/TabsPrimary.tsx +215 -0
  291. package/src/writer/Tabs/TabsProps.tsx +13 -0
  292. package/src/writer/Tabs/TabsSecondary.styles.tsx +78 -0
  293. package/src/writer/Tabs/TabsSecondary.tsx +176 -0
  294. package/src/writer/Tabs/index.ts +2 -0
  295. package/src/writer/Tabs/useValueChange.ts +84 -0
  296. package/src/writer/Text/Text.styles.tsx +66 -0
  297. package/src/writer/Text/Text.tsx +79 -0
  298. package/src/writer/Text/index.ts +3 -0
  299. package/src/writer/TocCard/TocCard.module.css +44 -0
  300. package/src/writer/TocCard/TocCard.tsx +42 -0
  301. package/src/writer/TocCard/index.ts +3 -0
  302. package/src/writer/Update/Update.styles.tsx +33 -0
  303. package/src/writer/Update/Update.tsx +37 -0
  304. package/src/writer/Update/index.ts +1 -0
  305. package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
  306. package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
  307. package/src/writer/VideoGuide/index.ts +1 -0
  308. package/src/writer/index.ts +53 -0
  309. package/system.ts +1 -0
  310. package/tsconfig.json +46 -0
  311. package/types.d.ts +52 -0
  312. package/uxsdk.ts +1 -0
  313. package/views.ts +2 -0
  314. package/writer.ts +1 -0
@@ -0,0 +1,671 @@
1
+ import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react'
2
+ import { HighlightedCode } from 'codehike/code';
3
+
4
+ import {
5
+ Settings
6
+ } from "@xyd-js/core"
7
+
8
+ import {
9
+ Anchor,
10
+ Badge,
11
+ Blockquote,
12
+ Callout,
13
+ Code,
14
+ Details,
15
+ GuideCard,
16
+ Heading,
17
+ Hr,
18
+ Table,
19
+ Tabs,
20
+ Steps,
21
+ List,
22
+ ListOl,
23
+ Text,
24
+ Button,
25
+ Icon,
26
+ Image,
27
+ Update,
28
+ Card,
29
+ ColorSchemeButton,
30
+ Breadcrumbs
31
+ } from '../../writer'
32
+ import { PageHome, PageFirstSlide, PageBlogHome } from '../../pages'
33
+ import { CodeSample } from "../../coder";
34
+ import { GridDecorator } from './GridDecorator';
35
+ import { useUXEvents } from '../uxsdk';
36
+
37
+ interface ReactContentOptions {
38
+ Link?: React.ElementType
39
+ components?: { [component: string]: (props: any) => React.JSX.Element | null }
40
+ useLocation?: () => {
41
+ search: string
42
+ } // TODO: !!!! BETTER API !!!!!
43
+ useNavigate?: (to: any) => void // TODO: !!!! BETTER API !!!!!
44
+ useNavigation?: () => any, // TODO: !!!! BETTER API !!!!!
45
+
46
+ }
47
+
48
+ export class ReactContent {
49
+ constructor(
50
+ protected settings?: Settings,
51
+ protected options?: ReactContentOptions
52
+ ) {
53
+ }
54
+
55
+ public components(): { [component: string]: (props: any) => React.JSX.Element | null } {
56
+ const builtInComponents = [
57
+ stdContent,
58
+ writerContent,
59
+ pageComponents,
60
+ iconContent,
61
+ coderContent,
62
+ directiveContent,
63
+ contentDecorators,
64
+ ]
65
+ .map(fn => fn.bind(this))
66
+ .reduce((acc, fn) => ({ ...acc, ...fn() }), {});
67
+
68
+ return {
69
+ ...builtInComponents,
70
+ ...this.options?.components || {}
71
+ }
72
+ }
73
+
74
+ public noop() {
75
+ const components = this.components()
76
+
77
+ const noopBuiltInFlatComponents = [
78
+ ...Object.keys(components),
79
+ ...Object.keys(this.options?.components || {})
80
+ ].reduce((acc, key) => {
81
+ acc[key] = () => null
82
+ return acc
83
+ }, {})
84
+
85
+ const noopNestedComponents = {
86
+ Steps: NoopComponent,
87
+ Tabs: NoopComponent,
88
+ GuideCard: NoopComponent,
89
+ Table: NoopComponent,
90
+ }
91
+
92
+ return {
93
+ ...noopBuiltInFlatComponents,
94
+ ...noopNestedComponents,
95
+ React: NoopReactComponent,
96
+ }
97
+ }
98
+ }
99
+
100
+ function NoopComponent() {
101
+ return null
102
+ }
103
+ NoopComponent.Item = () => null
104
+ NoopComponent.Content = () => null
105
+ NoopComponent.List = () => null
106
+ NoopComponent.Head = () => null
107
+ NoopComponent.Td = () => null
108
+ NoopComponent.Tr = () => null
109
+ NoopComponent.Th = () => null
110
+ NoopComponent.Cell = () => null
111
+
112
+
113
+ function NoopReactComponent() { // TODO: !!!! in the future refactor but `html-to-jsx-transform` creates <React.Fragment> !!!
114
+ return null
115
+ }
116
+ NoopReactComponent.Fragment = React.Fragment
117
+
118
+ export function stdContent(
119
+ this: ReactContent,
120
+ ) {
121
+ const $$Pre = $Pre.bind(this)
122
+ const $$Heading = $Heading.bind(this)
123
+
124
+ const stdComponents = {
125
+ h1: (props) => {
126
+ return <$$Heading depth={1} {...props} noanchor />
127
+ },
128
+ h2: props => {
129
+ const appearance = this.settings?.theme?.appearance
130
+
131
+ return <>
132
+ {appearance?.content?.sectionSeparator ? <Hr /> : null}
133
+
134
+ <$$Heading depth={2} {...props} />
135
+ </>
136
+ },
137
+ h3: props => {
138
+ return <$$Heading depth={3} {...props} />
139
+ },
140
+ h4: props => {
141
+ return <$$Heading depth={4} {...props} />
142
+ },
143
+ h5: props => {
144
+ return <$$Heading depth={5} {...props} />
145
+ },
146
+ p: props => {
147
+ return <Text {...props} />
148
+ },
149
+ ul: props => {
150
+ return <List {...props}>
151
+ {props.children}
152
+ </List>
153
+ },
154
+ ol: props => {
155
+ return <ListOl {...props}>
156
+ {props.children}
157
+ </ListOl>
158
+ },
159
+ li: props => {
160
+ return <List.Item {...props} >
161
+ {props.children}
162
+ </List.Item>
163
+ },
164
+
165
+ table: (props) => {
166
+ const kind = this.settings?.theme?.appearance?.tables?.kind
167
+
168
+ return <Table kind={kind} {...props} />
169
+ },
170
+ tr: (props) => {
171
+ return <Table.Tr {...props} />
172
+ },
173
+ th: (props) => {
174
+ return <Table.Th {...props} />
175
+ },
176
+ td: (props) => {
177
+ return <Table.Td {...props}>
178
+ <Table.Cell>
179
+ {props.children}
180
+ </Table.Cell>
181
+ </Table.Td>
182
+ },
183
+
184
+ code: (props) => {
185
+ return <Code {...props} />
186
+ },
187
+ pre: $$Pre,
188
+ details: (props) => {
189
+ return <Details {...props} />
190
+ },
191
+ blockquote: (props) => {
192
+ return <Blockquote {...props} />
193
+ },
194
+ hr: ({ children, ...props }) => {
195
+ return <Hr {...props} />
196
+ },
197
+ a: (props) => {
198
+ return <$Link {...props} as={this?.options?.Link} />
199
+ },
200
+ br: ({ children, ...props }) => {
201
+ return <br {...props} />
202
+ },
203
+ img: ({ children, src, alt, ...props }) => {
204
+ return <Image src={src} alt={alt} {...props} />
205
+ },
206
+ picture: (props) => {
207
+ const { children, ...rest } = props
208
+
209
+ return <picture {...rest}>
210
+ {children}
211
+ </picture>
212
+ },
213
+ source: (props) => {
214
+ const { children, ...rest } = props
215
+
216
+ return <source {...rest} />
217
+ },
218
+ input: ({ children, ...props }) => {
219
+ return <input {...props} />
220
+ },
221
+ textarea: ({ children, ...props }) => {
222
+ return <textarea {...props} />
223
+ },
224
+ div: (props) => <div {...props} />,
225
+ span: (props) => <span {...props} />,
226
+ iframe: (props) => <iframe {...props} />,
227
+ svg: (props) => <svg {...props} />,
228
+ feature: (props) => <div data-feature-flag={props.flag} data-feature-match={props.match}>{props.children}</div>,
229
+ React: NoopReactComponent,
230
+ }
231
+
232
+ return {
233
+ ...stdComponents,
234
+ H1: stdComponents.h1,
235
+ H2: stdComponents.h2,
236
+ H3: stdComponents.h3,
237
+ H4: stdComponents.h4,
238
+ H5: stdComponents.h5,
239
+ P: stdComponents.p,
240
+ Ul: stdComponents.ul,
241
+ Ol: stdComponents.ol,
242
+ Li: stdComponents.li,
243
+ Table: stdComponents.table,
244
+ Tr: stdComponents.tr,
245
+ Th: stdComponents.th,
246
+ }
247
+ }
248
+
249
+ interface HeadingContentProps {
250
+ id: string
251
+ depth: 1 | 2 | 3 | 4 | 5 | 6
252
+ children: React.ReactNode
253
+ label?: string
254
+ subtitle?: string
255
+ noanchor?: boolean
256
+ style?: any
257
+ }
258
+
259
+ function $Heading({ id, depth, children, label, subtitle, noanchor, style }: HeadingContentProps) {
260
+ // const location = this?.options?.useLocation?.() // TODO: !!!! BETTER API !!!!!
261
+ // const navigate = this?.options?.useNavigate() // TODO: !!!! BETTER API !!!!!
262
+ const navigation = this?.options?.useNavigation() // TODO: !!!! BETTER API !!!!!
263
+ const ux = useUXEvents()
264
+
265
+ const ref = useRef<HTMLHeadingElement>(null!)
266
+ const [active, setActive] = useState(false)
267
+
268
+ function onReplaceState(e: any) {
269
+ const active = window.location.hash === `#${id}`
270
+ setActive(active)
271
+ }
272
+
273
+ useEffect(() => {
274
+ window.addEventListener('replaceState', onReplaceState)
275
+
276
+ const active = window.location.hash === `#${id}`
277
+ setActive(active)
278
+
279
+ if (active && ref.current && navigation?.state !== "loading") {
280
+ ref.current.scrollIntoView()
281
+ }
282
+
283
+ return () => {
284
+ window.removeEventListener('replaceState', onReplaceState)
285
+ }
286
+ }, [])
287
+
288
+ return <Heading
289
+ ref={ref}
290
+ id={id}
291
+ size={depth}
292
+ active={active}
293
+ onClick={() => {
294
+ if (id) {
295
+ ux.docs.anchor.click({
296
+ id: id
297
+ })
298
+ }
299
+ // navigate({
300
+ // hash: id
301
+ // })
302
+
303
+ // TODO: !!! in the future we should use react-router but some issues with the hash !!!
304
+ const url = new URL(window.location.href)
305
+ url.hash = id
306
+ history.replaceState(null, '', url)
307
+
308
+ document.querySelector(`#${id}`)?.scrollIntoView()
309
+ }}
310
+ label={label}
311
+ subtitle={subtitle}
312
+ noanchor={noanchor}
313
+ style={style}
314
+ >
315
+ {children}
316
+ </Heading>
317
+ }
318
+
319
+ export function writerContent() {
320
+ const GuideCardContent = $GuideCardContentComponent.bind(this)
321
+ GuideCardContent.List = GuideCard.List
322
+ const BreadcrumbsContent = $BreadcrumbsContentComponent.bind(this)
323
+
324
+ const TabsContent = $TabsContentComponent.bind(this)
325
+ TabsContent.Content = $TabsContentContentComponent.bind(this)
326
+ TabsContent.Item = $TabsItemContentComponent.bind(this)
327
+ TabsContent.Item.displayName = "Tabs.Item"
328
+
329
+ return {
330
+ Callout,
331
+ Details,
332
+ GuideCard: GuideCardContent,
333
+ Breadcrumbs: BreadcrumbsContent,
334
+ Steps,
335
+ Tabs: TabsContent,
336
+ Table,
337
+ Badge,
338
+ Button,
339
+ Subtitle(props) {
340
+ const paragraph = props?.children?.props?.children
341
+
342
+ return <Heading size={4} kind="muted" {...props}>
343
+ {paragraph}
344
+ </Heading>
345
+ },
346
+ Update,
347
+ Card: $Card.bind(this),
348
+ ColorSchemeButton: ColorSchemeButton,
349
+ Feature: (props) => <div data-feature-flag={props.flag} data-feature-match={props.match}>
350
+ {props.children}
351
+ </div>
352
+ }
353
+ }
354
+
355
+ function pageComponents() {
356
+ return {
357
+ PageHome,
358
+ PageFirstSlide,
359
+ PageBlogHome: $PageBlogHome.bind(this)
360
+ }
361
+ }
362
+
363
+ function $PageBlogHome(props) {
364
+ return <PageBlogHome
365
+ {...props}
366
+ as={this?.options?.Link}
367
+ />
368
+ }
369
+
370
+ function $GuideCardContentComponent(props) {
371
+ return <GuideCard
372
+ {...props}
373
+ as={this?.options?.Link}
374
+ />
375
+ }
376
+
377
+ function $BreadcrumbsContentComponent(props) {
378
+ return <Breadcrumbs
379
+ {...props}
380
+ as={this?.options?.Link}
381
+ />
382
+ }
383
+
384
+ function $Card(props) {
385
+ return <Card
386
+ {...props}
387
+ link={this?.options?.Link}
388
+ />
389
+ }
390
+
391
+ const TabsContentContext = createContext({
392
+ value: "",
393
+ onChange: (v: string) => {
394
+ }
395
+ })
396
+
397
+ function $TabsContentComponent(props) {
398
+ const [value, setValue] = useState(props.value)
399
+
400
+ return <TabsContentContext value={{ value, onChange: setValue }}>
401
+ <Tabs
402
+ {...props}
403
+ value={value}
404
+ onChange={val => {
405
+ const url = new URL(window.location.href)
406
+ const currentParams = url.searchParams
407
+
408
+ // Update parameters from the new params
409
+ new URLSearchParams(val).forEach((value, key) => {
410
+ currentParams.set(key, value)
411
+ })
412
+
413
+ url.search = currentParams.toString()
414
+ history.replaceState(null, '', url)
415
+
416
+ setValue(val)
417
+ }}
418
+ />
419
+ </TabsContentContext>
420
+ }
421
+
422
+ function $TabsContentContentComponent(this: ReactContent, props) {
423
+ const { onChange } = useContext(TabsContentContext)
424
+ const location = this?.options?.useLocation?.() // TODO: !!!! BETTER API !!!!!
425
+
426
+ const search = location?.search
427
+ const params = new URLSearchParams(search)
428
+ const propsParams = new URLSearchParams(props.value)
429
+
430
+ let tabsMatch: boolean | undefined = true
431
+ let keyMatchExists = true
432
+ propsParams.forEach((value, key) => {
433
+ const paramKey = params.get(key)
434
+ if (paramKey !== value) {
435
+ tabsMatch = false
436
+ }
437
+ if (!paramKey) {
438
+ keyMatchExists = false
439
+ }
440
+ })
441
+
442
+ useEffect(() => {
443
+ if (tabsMatch) {
444
+ onChange(props.value)
445
+ }
446
+ }, [tabsMatch])
447
+
448
+ if (!keyMatchExists) {
449
+ tabsMatch = undefined
450
+ }
451
+
452
+ return <Tabs.Content {...props} defaultActive={tabsMatch} />
453
+ }
454
+
455
+ function $TabsItemContentComponent(props) {
456
+ const { onChange } = useContext(TabsContentContext)
457
+ const location = this?.options?.useLocation?.()
458
+
459
+ const search = location?.search
460
+ const params = new URLSearchParams(search)
461
+ const propsParams = new URLSearchParams(props.value)
462
+
463
+ let tabsMatch = true
464
+ propsParams.forEach((value, key) => {
465
+ if (params.get(key) !== value) {
466
+ tabsMatch = false
467
+ }
468
+ })
469
+
470
+ useEffect(() => {
471
+ if (tabsMatch) {
472
+ onChange(props.value)
473
+ }
474
+ }, [tabsMatch])
475
+
476
+ return <Tabs.Item
477
+ {...props}
478
+ as={this?.options?.Link}
479
+ defaultActive={tabsMatch}
480
+ />
481
+ }
482
+
483
+ // TODO: better system for icons + should work with .md like icon="session-replay" etc.
484
+ export function iconContent() {
485
+ return {
486
+ Icon,
487
+ }
488
+ }
489
+
490
+ export function coderContent() {
491
+ return {
492
+ CodeSample, // TODO: server side highlight?
493
+ }
494
+ }
495
+
496
+ export function directiveContent(
497
+ this: ReactContent,
498
+ ) {
499
+ return {
500
+ // TODO: deprecate? - but currently needed for directive cuz we do JSON.parse here
501
+ DirectiveCodeGroup: (props) => {
502
+ return <CodeSample
503
+ {...props}
504
+ theme={this.settings?.theme?.coder?.syntaxHighlight || undefined}
505
+ codeblocks={JSON.parse(props.codeblocks || "[]")}
506
+ />
507
+ }
508
+ }
509
+ }
510
+
511
+ export function contentDecorators() {
512
+ return {
513
+ GridDecorator
514
+ }
515
+ }
516
+
517
+ function $Pre(
518
+ this: ReactContent,
519
+ props: any
520
+ ) {
521
+ let highlighted: HighlightedCode | undefined = undefined
522
+
523
+ if (props.highlighted) {
524
+ // if ssr highlighted code
525
+ try {
526
+ const serverHighlight: HighlightedCode = JSON.parse(props.highlighted)
527
+
528
+ if (serverHighlight) {
529
+ highlighted = serverHighlight
530
+ }
531
+ } catch (e) {
532
+ console.error("Error parsing highlighted code", e)
533
+ }
534
+ }
535
+ const lang = (props?.children?.props?.className || "").replace("language-", "")
536
+
537
+ let descriptionContent: React.ReactNode | undefined = undefined
538
+ if (props?.descriptionContent) {
539
+ const code = mdxContent(props?.descriptionContent)
540
+ if (code?.component) {
541
+ const Component = MemoMDXComponent(code?.component)
542
+
543
+ descriptionContent = <Component components={this.components()} />
544
+ }
545
+ }
546
+
547
+ return <CodeSample
548
+ theme={this.settings?.theme?.coder?.syntaxHighlight || undefined}
549
+ name={lang}
550
+ description={typeof props?.title === "string" ? props?.title : props?.children?.props?.meta}
551
+ codeblocks={[
552
+ {
553
+ value: props?.children?.props?.children,
554
+ lang: lang,
555
+ meta: lang,
556
+ highlighted,
557
+ }
558
+ ]}
559
+ lineNumbers={props?.lineNumbers}
560
+ size={props?.size}
561
+ descriptionHead={props?.descriptionHead}
562
+ descriptionContent={descriptionContent}
563
+ descriptionIcon={props?.descriptionIcon}
564
+ />
565
+ }
566
+
567
+ const EXTERNAL_HREF_REGEX = /https?:\/\//
568
+
569
+ interface LinkProps {
570
+ href?: string
571
+ as?: React.ElementType
572
+ newWindow?: boolean
573
+ children?: React.ReactNode
574
+ }
575
+
576
+ function $Link({
577
+ href = '',
578
+ as,
579
+ newWindow,
580
+ children,
581
+ ...props
582
+ }: LinkProps) {
583
+ const Link = as || Anchor
584
+
585
+ if (!as) {
586
+ // TODO: fix any
587
+ (props as any).newWindow = newWindow || EXTERNAL_HREF_REGEX.test(href)
588
+ }
589
+
590
+ return <Link
591
+ href={href}
592
+ {...props}
593
+ as={as}
594
+ >
595
+ {children}
596
+ </Link>
597
+ }
598
+
599
+ // TODO: move to content?
600
+ function mdxExport(code: string) {
601
+ // Create a wrapper around React.createElement that adds keys to elements in lists
602
+ const scope = {
603
+ Fragment: React.Fragment,
604
+ jsxs: createElementWithKeys,
605
+ jsx: createElementWithKeys,
606
+ jsxDEV: createElementWithKeys,
607
+ }
608
+ const fn = new Function(...Object.keys(scope), code)
609
+
610
+ return fn(scope)
611
+ }
612
+
613
+ function MemoMDXComponent(codeComponent: any) {
614
+ return useMemo(
615
+ () => codeComponent ? codeComponent : null,
616
+ [codeComponent]
617
+ )
618
+ }
619
+
620
+
621
+ // // TODO: move to content?
622
+ function mdxContent(code: string) {
623
+ const content = mdxExport(code) // TODO: fix any
624
+ if (!mdxExport) {
625
+ return {}
626
+ }
627
+
628
+ return {
629
+ component: content?.default,
630
+ }
631
+ }
632
+
633
+ const createElementWithKeys = (type: any, props: any) => {
634
+ // Process children to add keys to all elements
635
+ const processChildren = (childrenArray: any[]): any[] => {
636
+ return childrenArray.map((child, index) => {
637
+ // If the child is a React element and doesn't have a key, add one
638
+ if (React.isValidElement(child) && !child.key) {
639
+ return React.cloneElement(child, { key: `mdx-${index}` });
640
+ }
641
+ // If the child is an array, process it recursively
642
+ if (Array.isArray(child)) {
643
+ return processChildren(child);
644
+ }
645
+ return child;
646
+ });
647
+ };
648
+
649
+ // Handle both cases: children as separate args or as props.children
650
+ let processedChildren;
651
+
652
+ if (props && props.children) {
653
+ if (Array.isArray(props.children)) {
654
+ processedChildren = processChildren(props.children);
655
+ } else if (React.isValidElement(props.children) && !props.children.key) {
656
+ // Single child without key
657
+ processedChildren = React.cloneElement(props.children, { key: 'mdx-child' });
658
+ } else {
659
+ // Single child with key or non-React element
660
+ processedChildren = props.children;
661
+ }
662
+ } else {
663
+ processedChildren = [];
664
+ }
665
+
666
+ // Create the element with processed children
667
+ return React.createElement(type, {
668
+ ...props,
669
+ children: processedChildren
670
+ });
671
+ };
@@ -0,0 +1 @@
1
+ move decorators to xyd-components/decorators?
@@ -0,0 +1,13 @@
1
+ export { SearchButtonFullWidth } from "./AppearanceDecorator.styles"
2
+
3
+ export {
4
+ ReactContent,
5
+
6
+ stdContent,
7
+ writerContent,
8
+ iconContent,
9
+ coderContent,
10
+ directiveContent,
11
+ } from "./ReactContent"
12
+
13
+ export { ContentDecorator } from "./ContentDecorator"