@xyd-js/components 0.1.0-xyd.8 → 0.1.0-xyd.94

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 (322) 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 +712 -0
  6. package/TODO.md +1 -0
  7. package/content.ts +0 -2
  8. package/dist/CTABanner-Bc77pnms.js +2 -0
  9. package/dist/CTABanner-Bc77pnms.js.map +1 -0
  10. package/dist/CTABanner-DzO62aGj.js +2 -0
  11. package/dist/CTABanner-DzO62aGj.js.map +1 -0
  12. package/dist/CodeSample-BWPDgd2G.js +2 -0
  13. package/dist/CodeSample-BWPDgd2G.js.map +1 -0
  14. package/dist/CodeSample-DLnR-knP.js +2 -0
  15. package/dist/CodeSample-DLnR-knP.js.map +1 -0
  16. package/dist/HomeView-C8QlNdKh.js +2 -0
  17. package/dist/{HomeView-ACBdUgyz.js.map → HomeView-C8QlNdKh.js.map} +1 -1
  18. package/dist/HomeView-ZAP5saNy.js +2 -0
  19. package/dist/{HomeView-B0ATNUF1.js.map → HomeView-ZAP5saNy.js.map} +1 -1
  20. package/dist/Icon-BESh23UN.js +2 -0
  21. package/dist/Icon-BESh23UN.js.map +1 -0
  22. package/dist/Icon-xNucOqd2.js +2 -0
  23. package/dist/Icon-xNucOqd2.js.map +1 -0
  24. package/dist/Text-CfN9RkYA.js +2 -0
  25. package/dist/Text-CfN9RkYA.js.map +1 -0
  26. package/dist/Text-DKycD2zu.js +2 -0
  27. package/dist/Text-DKycD2zu.js.map +1 -0
  28. package/dist/Update-0XruJHjj.js +2 -0
  29. package/dist/Update-0XruJHjj.js.map +1 -0
  30. package/dist/Update-DKOAw8p9.js +2 -0
  31. package/dist/Update-DKOAw8p9.js.map +1 -0
  32. package/dist/VideoGuide-BUyomFVz.js +2 -0
  33. package/dist/VideoGuide-BUyomFVz.js.map +1 -0
  34. package/dist/VideoGuide-B_iUKKv7.js +2 -0
  35. package/dist/VideoGuide-B_iUKKv7.js.map +1 -0
  36. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js +4 -0
  37. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js.map +1 -0
  38. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js +4 -0
  39. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js.map +1 -0
  40. package/dist/brand.js +1 -1
  41. package/dist/brand.js.map +1 -1
  42. package/dist/coder/themes/cosmo-light.js.map +1 -1
  43. package/dist/coder.d.ts +29 -9
  44. package/dist/coder.js +1 -1
  45. package/dist/coder.js.map +1 -1
  46. package/dist/content.d.ts +264 -201
  47. package/dist/content.js +1 -1
  48. package/dist/content.js.map +1 -1
  49. package/dist/index.css +261 -211
  50. package/dist/layouts.d.ts +20 -21
  51. package/dist/layouts.js +1 -1
  52. package/dist/layouts.js.map +1 -1
  53. package/dist/pages.js +1 -1
  54. package/dist/pages.js.map +1 -1
  55. package/dist/system.d.ts +10 -0
  56. package/dist/system.js +2 -0
  57. package/dist/system.js.map +1 -0
  58. package/dist/tslib.es6-DyL9kPq9.js +2 -0
  59. package/dist/{tslib.es6-BBkx4Se1.js.map → tslib.es6-DyL9kPq9.js.map} +1 -1
  60. package/dist/tslib.es6-Hqk-Mdr9.js +2 -0
  61. package/dist/{tslib.es6-BF6ZLEXa.js.map → tslib.es6-Hqk-Mdr9.js.map} +1 -1
  62. package/dist/views.js +1 -1
  63. package/dist/writer.d.ts +409 -77
  64. package/dist/writer.js +1 -1
  65. package/dist/writer.js.map +1 -1
  66. package/docs/.nojekyll +1 -0
  67. package/docs/assets/hierarchy.js +1 -0
  68. package/docs/assets/highlight.css +22 -0
  69. package/docs/assets/icons.js +18 -0
  70. package/docs/assets/icons.svg +1 -0
  71. package/docs/assets/main.js +60 -0
  72. package/docs/assets/navigation.js +1 -0
  73. package/docs/assets/search.js +1 -0
  74. package/docs/assets/style.css +1640 -0
  75. package/docs/functions/GuideCard.html +6 -0
  76. package/docs/hierarchy.html +1 -0
  77. package/docs/index.html +2 -0
  78. package/docs/interfaces/GuideCardProps.html +18 -0
  79. package/docs/modules.html +1 -0
  80. package/index.ts +0 -1
  81. package/package.json +9 -15
  82. package/project.json +677 -0
  83. package/rollup.config.js +30 -20
  84. package/src/brand/Button/Button.styles.tsx +0 -3
  85. package/src/brand/CTABanner/CTABanner.styles.tsx +2 -4
  86. package/src/brand/Footer/Footer.styles.tsx +0 -3
  87. package/src/coder/Code/Code.styles.tsx +135 -33
  88. package/src/coder/Code/Code.tsx +129 -38
  89. package/src/coder/Code/CodeLoader.tsx +3 -3
  90. package/src/coder/Code/annotations.tsx +28 -8
  91. package/src/coder/Code/highlight.ts +38 -0
  92. package/src/coder/Code/index.ts +2 -1
  93. package/src/coder/CodeCopy/CodeCopy.styles.tsx +13 -11
  94. package/src/coder/CodeCopy/CodeCopy.tsx +5 -3
  95. package/src/coder/CodeSample/CodeSample.tsx +83 -27
  96. package/src/coder/CodeTabs/CodeTabs.styles.tsx +111 -94
  97. package/src/coder/CodeTabs/CodeTabs.tsx +69 -51
  98. package/src/coder/CodeTheme/CodeTheme.tsx +89 -49
  99. package/src/coder/CodeTheme/index.ts +0 -1
  100. package/src/coder/CoderProvider.tsx +26 -0
  101. package/src/coder/index.ts +8 -4
  102. package/src/content/ContentDecoator.styles.tsx +113 -0
  103. package/src/content/ContentDecorator.tsx +17 -0
  104. package/src/content/GridDecorator.styles.tsx +67 -0
  105. package/src/content/GridDecorator.tsx +21 -0
  106. package/src/content/ReactContent.tsx +575 -0
  107. package/src/content/index.ts +10 -2
  108. package/src/icons/index.ts +0 -0
  109. package/src/kit/Loader/Loader.styles.tsx +53 -0
  110. package/src/kit/Loader/Loader.tsx +22 -0
  111. package/src/kit/index.ts +1 -0
  112. package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +270 -306
  113. package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +171 -91
  114. package/src/layouts/LayoutPrimary/index.ts +0 -2
  115. package/src/layouts/index.ts +0 -7
  116. package/src/system/SearchButton/SearchButton.styles.tsx +86 -0
  117. package/src/system/SearchButton/SearchButton.tsx +116 -0
  118. package/src/system/SearchButton/index.ts +1 -0
  119. package/src/system/index.ts +1 -0
  120. package/src/writer/Anchor/Anchor.styles.tsx +11 -0
  121. package/src/{content → writer}/Anchor/Anchor.tsx +20 -22
  122. package/src/writer/Anchor/index.tsx +1 -0
  123. package/src/writer/Badge/Badge.styles.tsx +37 -27
  124. package/src/writer/Badge/Badge.tsx +34 -48
  125. package/src/writer/Banner/Banner.styles.tsx +91 -0
  126. package/src/writer/Banner/Banner.tsx +70 -0
  127. package/src/writer/Banner/index.ts +1 -0
  128. package/src/writer/Blockquote/Blockquote.styles.tsx +6 -4
  129. package/src/writer/Blockquote/Blockquote.tsx +5 -2
  130. package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +25 -25
  131. package/src/writer/Breadcrumbs/Breadcrumbs.tsx +18 -12
  132. package/src/writer/Button/Button.styles.tsx +137 -0
  133. package/src/writer/Button/Button.tsx +75 -0
  134. package/src/writer/Button/index.ts +2 -0
  135. package/src/writer/Callout/Callout.styles.tsx +35 -42
  136. package/src/writer/Callout/Callout.tsx +30 -15
  137. package/src/writer/Card/Card.styles.tsx +47 -0
  138. package/src/writer/Card/Card.tsx +69 -0
  139. package/src/writer/Card/index.ts +1 -0
  140. package/src/writer/Code/Code.styles.tsx +12 -11
  141. package/src/writer/Code/Code.tsx +6 -3
  142. package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +172 -0
  143. package/src/writer/ColorSchemeButton/index.ts +1 -0
  144. package/src/writer/Details/Details.styles.tsx +87 -98
  145. package/src/writer/Details/Details.tsx +65 -44
  146. package/src/writer/Example/index.tsx +5 -0
  147. package/src/writer/GuideCard/GuideCard.styles.tsx +100 -103
  148. package/src/writer/GuideCard/GuideCard.tsx +72 -37
  149. package/src/writer/Heading/Heading.styles.tsx +76 -60
  150. package/src/writer/Heading/Heading.tsx +92 -22
  151. package/src/writer/Hr/Hr.styles.tsx +3 -1
  152. package/src/writer/Hr/Hr.tsx +2 -5
  153. package/src/writer/Icon/Icon.tsx +48 -0
  154. package/src/writer/Icon/index.ts +1 -0
  155. package/src/writer/Image/Image.styles.tsx +9 -0
  156. package/src/writer/Image/Image.tsx +19 -0
  157. package/src/writer/Image/index.ts +1 -0
  158. package/src/writer/List/List.styles.tsx +47 -0
  159. package/src/writer/List/List.tsx +29 -0
  160. package/src/writer/List/index.ts +4 -0
  161. package/src/writer/NavLinks/NavLinks.styles.ts +26 -26
  162. package/src/writer/NavLinks/NavLinks.tsx +65 -18
  163. package/src/writer/Pre/Pre.styles.tsx +8 -6
  164. package/src/writer/Pre/Pre.tsx +3 -2
  165. package/src/writer/Steps/Steps.styles.tsx +27 -24
  166. package/src/writer/Steps/Steps.tsx +38 -8
  167. package/src/writer/Table/Table.styles.tsx +65 -34
  168. package/src/writer/Table/Table.tsx +121 -11
  169. package/src/writer/Table/index.ts +0 -11
  170. package/src/writer/Tabs/Tabs.styles.tsx +51 -55
  171. package/src/writer/Tabs/Tabs.tsx +30 -23
  172. package/src/writer/Text/Text.styles.tsx +66 -0
  173. package/src/writer/Text/Text.tsx +79 -0
  174. package/src/writer/Text/index.ts +3 -0
  175. package/src/writer/TocCard/TocCard.module.css +44 -0
  176. package/src/writer/TocCard/TocCard.tsx +42 -0
  177. package/src/writer/TocCard/index.ts +3 -0
  178. package/src/writer/UnderlineNav/Tabs.tsx +51 -0
  179. package/src/writer/UnderlineNav/TabsPrimary.styles.tsx +184 -0
  180. package/src/writer/UnderlineNav/TabsPrimary.tsx +209 -0
  181. package/src/writer/UnderlineNav/TabsSecondary.styles.tsx +77 -0
  182. package/src/writer/UnderlineNav/TabsSecondary.tsx +171 -0
  183. package/src/writer/UnderlineNav/UnderlineNav.styles.tsx +165 -31
  184. package/src/writer/UnderlineNav/UnderlineNav.tsx +257 -22
  185. package/src/writer/UnderlineNav/index.ts +2 -1
  186. package/src/writer/UnderlineNav/useValueChange.ts +60 -0
  187. package/src/writer/Update/Update.styles.tsx +33 -0
  188. package/src/writer/Update/Update.tsx +37 -0
  189. package/src/writer/Update/index.ts +1 -0
  190. package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
  191. package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
  192. package/src/writer/VideoGuide/index.ts +1 -0
  193. package/src/writer/index.ts +23 -1
  194. package/tsconfig.json +9 -3
  195. package/types.d.ts +50 -0
  196. package/writer.ts +1 -1
  197. package/dist/CTABanner-4FVIoaTR.js +0 -2
  198. package/dist/CTABanner-4FVIoaTR.js.map +0 -1
  199. package/dist/CTABanner-C6afsXoE.js +0 -2
  200. package/dist/CTABanner-C6afsXoE.js.map +0 -1
  201. package/dist/CTABanner-CEKs-Hb-.js +0 -2
  202. package/dist/CTABanner-CEKs-Hb-.js.map +0 -1
  203. package/dist/CTABanner-CUNcTr6s.js +0 -2
  204. package/dist/CTABanner-CUNcTr6s.js.map +0 -1
  205. package/dist/CTABanner-D02aIAsD.js +0 -2
  206. package/dist/CTABanner-D02aIAsD.js.map +0 -1
  207. package/dist/CTABanner-Dm3tUG3I.js +0 -2
  208. package/dist/CTABanner-Dm3tUG3I.js.map +0 -1
  209. package/dist/CTABanner-MCOcVowa.js +0 -2
  210. package/dist/CTABanner-MCOcVowa.js.map +0 -1
  211. package/dist/CTABanner-X6K49gSr.js +0 -2
  212. package/dist/CTABanner-X6K49gSr.js.map +0 -1
  213. package/dist/CodeSample-B9VUhTKF.js +0 -2
  214. package/dist/CodeSample-B9VUhTKF.js.map +0 -1
  215. package/dist/CodeSample-BSXeFy0x.js +0 -2
  216. package/dist/CodeSample-BSXeFy0x.js.map +0 -1
  217. package/dist/CodeSample-BwP208sQ.js +0 -2
  218. package/dist/CodeSample-BwP208sQ.js.map +0 -1
  219. package/dist/CodeSample-CUemtj_W.js +0 -2
  220. package/dist/CodeSample-CUemtj_W.js.map +0 -1
  221. package/dist/CodeSample-D0iKih-A.js +0 -2
  222. package/dist/CodeSample-D0iKih-A.js.map +0 -1
  223. package/dist/CodeSample-D33vTa6M.js +0 -2
  224. package/dist/CodeSample-D33vTa6M.js.map +0 -1
  225. package/dist/CodeSample-DUSx2KBt.js +0 -2
  226. package/dist/CodeSample-DUSx2KBt.js.map +0 -1
  227. package/dist/CodeSample-P4yxkHPW.js +0 -2
  228. package/dist/CodeSample-P4yxkHPW.js.map +0 -1
  229. package/dist/HomeView-ACBdUgyz.js +0 -2
  230. package/dist/HomeView-B0ATNUF1.js +0 -2
  231. package/dist/HomeView-COJrg8Ju.js +0 -2
  232. package/dist/HomeView-COJrg8Ju.js.map +0 -1
  233. package/dist/HomeView-Cun4apuy.js +0 -2
  234. package/dist/HomeView-Cun4apuy.js.map +0 -1
  235. package/dist/HomeView-D4DXEOOn.js +0 -2
  236. package/dist/HomeView-D4DXEOOn.js.map +0 -1
  237. package/dist/HomeView-DaH1PSBB.js +0 -2
  238. package/dist/HomeView-DaH1PSBB.js.map +0 -1
  239. package/dist/HomeView-O_lj2c2t.js +0 -2
  240. package/dist/HomeView-O_lj2c2t.js.map +0 -1
  241. package/dist/HomeView-_Nu2RcOM.js +0 -2
  242. package/dist/HomeView-_Nu2RcOM.js.map +0 -1
  243. package/dist/UnderlineNav-BCyB0G5d.js +0 -2
  244. package/dist/UnderlineNav-BCyB0G5d.js.map +0 -1
  245. package/dist/UnderlineNav-BEhDJk0H.js +0 -2
  246. package/dist/UnderlineNav-BEhDJk0H.js.map +0 -1
  247. package/dist/UnderlineNav-BqZ2xAp7.js +0 -2
  248. package/dist/UnderlineNav-BqZ2xAp7.js.map +0 -1
  249. package/dist/UnderlineNav-C2-4Vyj8.js +0 -2
  250. package/dist/UnderlineNav-C2-4Vyj8.js.map +0 -1
  251. package/dist/UnderlineNav-Co08Gykm.js +0 -2
  252. package/dist/UnderlineNav-Co08Gykm.js.map +0 -1
  253. package/dist/UnderlineNav-DC3UVmnZ.js +0 -2
  254. package/dist/UnderlineNav-DC3UVmnZ.js.map +0 -1
  255. package/dist/UnderlineNav-DsRYwuGB.js +0 -2
  256. package/dist/UnderlineNav-DsRYwuGB.js.map +0 -1
  257. package/dist/UnderlineNav-FbclXKUW.js +0 -2
  258. package/dist/UnderlineNav-FbclXKUW.js.map +0 -1
  259. package/dist/_rollupPluginBabelHelpers-BEouSrrZ.js +0 -2
  260. package/dist/_rollupPluginBabelHelpers-BEouSrrZ.js.map +0 -1
  261. package/dist/_rollupPluginBabelHelpers-BHehKRBq.js +0 -2
  262. package/dist/_rollupPluginBabelHelpers-BHehKRBq.js.map +0 -1
  263. package/dist/_rollupPluginBabelHelpers-Bunpz22T.js +0 -2
  264. package/dist/_rollupPluginBabelHelpers-Bunpz22T.js.map +0 -1
  265. package/dist/_rollupPluginBabelHelpers-CVblpRvU.js +0 -2
  266. package/dist/_rollupPluginBabelHelpers-CVblpRvU.js.map +0 -1
  267. package/dist/_rollupPluginBabelHelpers-CxmswfqM.js +0 -2
  268. package/dist/_rollupPluginBabelHelpers-CxmswfqM.js.map +0 -1
  269. package/dist/_rollupPluginBabelHelpers-DQJTK9EO.js +0 -2
  270. package/dist/_rollupPluginBabelHelpers-DQJTK9EO.js.map +0 -1
  271. package/dist/_rollupPluginBabelHelpers-DuRQdJ01.js +0 -2
  272. package/dist/_rollupPluginBabelHelpers-DuRQdJ01.js.map +0 -1
  273. package/dist/_rollupPluginBabelHelpers-tRAa4O0f.js +0 -2
  274. package/dist/_rollupPluginBabelHelpers-tRAa4O0f.js.map +0 -1
  275. package/dist/index-B0FncPxO.js +0 -2
  276. package/dist/index-B0FncPxO.js.map +0 -1
  277. package/dist/index-BEm-xkm-.js +0 -2
  278. package/dist/index-BEm-xkm-.js.map +0 -1
  279. package/dist/index-BHwtxG27.js +0 -2
  280. package/dist/index-BHwtxG27.js.map +0 -1
  281. package/dist/index-BTcmIG47.js +0 -2
  282. package/dist/index-BTcmIG47.js.map +0 -1
  283. package/dist/index-CNkHt1r7.js +0 -2
  284. package/dist/index-CNkHt1r7.js.map +0 -1
  285. package/dist/index-D0XuyFm7.js +0 -2
  286. package/dist/index-D0XuyFm7.js.map +0 -1
  287. package/dist/index-DBspcqWq.js +0 -2
  288. package/dist/index-DBspcqWq.js.map +0 -1
  289. package/dist/index-DVBO4gYE.js +0 -2
  290. package/dist/index-DVBO4gYE.js.map +0 -1
  291. package/dist/tslib.es6-BBkx4Se1.js +0 -2
  292. package/dist/tslib.es6-BF6ZLEXa.js +0 -2
  293. package/dist/tslib.es6-BOZCDgb8.js +0 -2
  294. package/dist/tslib.es6-BOZCDgb8.js.map +0 -1
  295. package/dist/tslib.es6-Cjl5tesf.js +0 -2
  296. package/dist/tslib.es6-Cjl5tesf.js.map +0 -1
  297. package/dist/tslib.es6-DEH7Dkgy.js +0 -2
  298. package/dist/tslib.es6-DEH7Dkgy.js.map +0 -1
  299. package/dist/tslib.es6-DTeJ7dWi.js +0 -2
  300. package/dist/tslib.es6-DTeJ7dWi.js.map +0 -1
  301. package/dist/tslib.es6-U9-f6pA7.js +0 -2
  302. package/dist/tslib.es6-U9-f6pA7.js.map +0 -1
  303. package/dist/tslib.es6-cb69JjeS.js +0 -2
  304. package/dist/tslib.es6-cb69JjeS.js.map +0 -1
  305. package/src/content/Anchor/Anchor.styles.tsx +0 -5
  306. package/src/content/Anchor/index.tsx +0 -3
  307. package/src/content/Content/Content.styles.tsx +0 -9
  308. package/src/content/Content/Content.tsx +0 -13
  309. package/src/content/Content/index.tsx +0 -3
  310. package/src/content/Content.tsx +0 -179
  311. package/src/content/Subtitle/Subtitle.styles.ts +0 -8
  312. package/src/content/Subtitle/Subtitle.tsx +0 -12
  313. package/src/content/Subtitle/index.tsx +0 -3
  314. package/src/layouts/Layout.styles.tsx +0 -155
  315. package/src/layouts/Layout.tsx +0 -119
  316. package/src/ui/Loader/Loader.styles.tsx +0 -54
  317. package/src/ui/Loader/Loader.tsx +0 -26
  318. package/src/ui/index.ts +0 -1
  319. package/src/writer/Icon/index.tsx +0 -355
  320. package/src/writer/Table/TableV2.styles.tsx +0 -117
  321. package/src/writer/Table/TableV2.tsx +0 -83
  322. /package/src/{ui → kit}/TODO.md +0 -0
@@ -1,79 +1,119 @@
1
- import React, { createContext, useState, use, useEffect } from "react";
1
+ import React, { createContext, useState, use, useEffect, Suspense } from "react";
2
2
  import { Theme } from "@code-hike/lighter";
3
3
  import { highlight } from "codehike/code";
4
4
  import type { HighlightedCode } from "codehike/code";
5
5
 
6
6
  import defaultTheme from "../themes/cosmo-light"
7
- import { Loader } from "../../ui";
7
+ import { Loader } from "../../kit";
8
8
 
9
9
  export interface CodeThemeProps {
10
- codeblocks: CodeThemeBlockProps[];
11
- children: React.ReactNode;
12
- theme?: Theme;
10
+ codeblocks?: CodeThemeBlockProps[];
11
+ theme?: Theme
12
+ children: React.ReactNode;
13
13
  }
14
14
 
15
15
  export interface CodeThemeBlockProps {
16
- /** This is the raw code. May include annotation comments. */
17
- value: string;
18
- /** The programming language. */
19
- lang: string;
20
- /** Metadata string (the content after the language name in a markdown codeblock). */
21
- meta: string;
16
+ /** This is the raw code. May include annotation comments. */
17
+ value: string;
18
+ /** The programming language. */
19
+ lang: string;
20
+ /** Metadata string (the content after the language name in a markdown codeblock). */
21
+ meta: string;
22
+
23
+ /** The highlighted code. */
24
+ highlighted?: HighlightedCode
22
25
  }
23
26
 
24
27
  const CodeThemeProvider = createContext<{
25
- highlighted: HighlightedCode[];
28
+ highlighted: HighlightedCode[];
26
29
  }>({
27
- highlighted: [],
30
+ highlighted: [],
28
31
  });
29
32
 
30
33
  export function useCodeTheme() {
31
- return use(CodeThemeProvider);
34
+ return use(CodeThemeProvider);
32
35
  }
33
36
 
37
+ // TODO: lazy-loading - some codeblocks on server and another on client
38
+ // TODO: lazdy client loading only on specific codeblock
34
39
  export function CodeTheme(props: CodeThemeProps) {
35
- const highlighted = use(
36
- fetchHighlight(props.codeblocks, props.theme || defaultTheme)
37
- );
38
-
39
- return (
40
- <CodeThemeProvider
41
- value={{
42
- highlighted,
43
- }}
44
- >
45
- {props.children}
46
- </CodeThemeProvider>
47
- );
48
- }
40
+ // Initialize with server-side highlighted codeblocks
41
+ const [highlighted, setHighlighted] = useState<HighlightedCode[] | undefined>(initializeHighlighted(props.codeblocks));
42
+ const [clientSideFetch, setClientSideFetch] = useState(true)
49
43
 
50
- // `CodeThemeSync` ?
51
- export function CodeThemeCSR(props: CodeThemeProps) {
52
- const [highlighted, setHighlighted] = useState<HighlightedCode[]>([]);
44
+ useEffect(() => {
45
+ setHighlighted(initializeHighlighted(props.codeblocks))
46
+ }, [props.codeblocks])
53
47
 
54
- useEffect(() => {
55
- fetchHighlight(props.codeblocks, props.theme || defaultTheme).then(
56
- setHighlighted
57
- );
58
- }, [props.codeblocks, props.theme]);
48
+ useEffect(() => {
49
+ if (!props.codeblocks) {
50
+ return;
51
+ }
52
+
53
+ // Check if we need to highlight any codeblocks
54
+ const needsHighlighting = props.codeblocks.some(
55
+ codeblock => !codeblock.highlighted || !codeblock.highlighted.tokens
56
+ );
57
+
58
+ if (needsHighlighting) {
59
+ clientSideHighlight();
60
+ }
61
+ }, [props.codeblocks]);
62
+
63
+ function initializeHighlighted(codeblocks: any) {
64
+ if (!codeblocks) return [];
59
65
 
60
- if (!highlighted) {
61
- return <Loader />;
62
- }
66
+ return codeblocks.map(codeblock => {
67
+ if (codeblock.highlighted && codeblock.highlighted.tokens) {
68
+ return {
69
+ ...codeblock.highlighted,
70
+ meta: codeblock.highlighted?.meta || codeblock.meta,
71
+ };
72
+ }
63
73
 
64
- return (
65
- <CodeThemeProvider
66
- value={{
67
- highlighted,
68
- }}
74
+ return null
75
+ }).filter(Boolean) as HighlightedCode[]
76
+ }
77
+
78
+ async function clientSideHighlight() {
79
+ if (!props.codeblocks) {
80
+ return;
81
+ }
82
+
83
+ const allHighlighted = props.codeblocks.every(codeblock => codeblock.highlighted)
84
+ if (allHighlighted) {
85
+ return;
86
+ }
87
+
88
+ const newHighlighted = await fetchHighlight(props.codeblocks, props.theme || defaultTheme);
89
+ setHighlighted(newHighlighted)
90
+
91
+ setClientSideFetch(false)
92
+ }
93
+
94
+ const withTheme = <CodeThemeProvider
95
+ value={{
96
+ highlighted: highlighted || [],
97
+ }}
69
98
  >
70
- {props.children}
99
+ {props.children}
71
100
  </CodeThemeProvider>
72
- );
101
+
102
+ const allHighlighted = props.codeblocks?.every(codeblock => codeblock.highlighted)
103
+ if (allHighlighted) {
104
+ return withTheme
105
+ }
106
+
107
+ if (clientSideFetch) {
108
+ return <Loader />
109
+ }
110
+
111
+ return withTheme
73
112
  }
74
113
 
114
+ // TODO: own server with grammars (codehike)
75
115
  async function fetchHighlight(codeblocks: CodeThemeBlockProps[], theme: Theme) {
76
- return await Promise.all(
77
- codeblocks?.map((codeblock) => highlight(codeblock, theme))
78
- );
116
+ return await Promise.all(
117
+ codeblocks?.map((codeblock) => highlight(codeblock, theme))
118
+ );
79
119
  }
@@ -2,7 +2,6 @@ export type {CodeThemeProps, CodeThemeBlockProps} from "./CodeTheme";
2
2
 
3
3
  export {
4
4
  CodeTheme,
5
- CodeThemeCSR,
6
5
 
7
6
  useCodeTheme
8
7
  } from "./CodeTheme";
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { createContext, useContext } from "react";
3
+
4
+ const CoderContext = createContext<{
5
+ lines?: boolean
6
+ scroll?: boolean
7
+ }>({
8
+ lines: undefined,
9
+ scroll: undefined,
10
+ })
11
+
12
+
13
+ interface CoderProviderProps {
14
+ children: React.ReactNode
15
+
16
+ lines?: boolean
17
+
18
+ scroll?: boolean
19
+ }
20
+ export function CoderProvider({ children, lines, scroll }: CoderProviderProps) {
21
+ return <CoderContext.Provider value={{ lines, scroll }}>{children}</CoderContext.Provider>
22
+ }
23
+
24
+ export function useCoder() {
25
+ return useContext(CoderContext)
26
+ }
@@ -8,12 +8,13 @@ export {
8
8
  Code,
9
9
  CodeLoader,
10
10
 
11
+ highlightAsync,
11
12
  highlight
12
13
  } from "./Code"
13
14
  //
14
15
 
15
- export type {CodeSampleProps} from "./CodeSample";
16
- export {CodeSample} from "./CodeSample";
16
+ export type { CodeSampleProps } from "./CodeSample";
17
+ export { CodeSample } from "./CodeSample";
17
18
  //
18
19
 
19
20
  export type {
@@ -24,10 +25,13 @@ export {
24
25
  } from "./CodeTabs";
25
26
  //
26
27
 
27
- export type {CodeThemeProps, CodeThemeBlockProps} from "./CodeTheme";
28
+ export type { CodeThemeProps, CodeThemeBlockProps } from "./CodeTheme";
28
29
  export {
29
30
  CodeTheme,
30
- CodeThemeCSR,
31
31
 
32
32
  useCodeTheme
33
33
  } from "./CodeTheme";
34
+
35
+ export {
36
+ CoderProvider
37
+ } from "./CoderProvider";
@@ -0,0 +1,113 @@
1
+ import { css } from "@linaria/core";
2
+
3
+ export default {
4
+ ContentDecoratorHost: css`
5
+ @layer components {
6
+ --space-small: 8px;
7
+ --space-medium: 16px;
8
+ --space-large: 20px;
9
+ --space-xlarge: 24px;
10
+ --space-xxlarge: 32px;
11
+ --space-2xlarge: 50px;
12
+
13
+ font-size: var(--xyd-font-size-medium);
14
+ line-height: var(--xyd-line-height-medium);
15
+
16
+ p:not(li p):not(ul p):not(xyd-callout p):not(xyd-codetabs p):not(xyd-guidecard p):not([data-button="true"] p) {
17
+ margin-top: var(--space-medium);
18
+ }
19
+
20
+ details {
21
+ --xyd-callout-bgcolor: var(--white);
22
+ margin-top: var(--space-medium);
23
+
24
+ summary {
25
+ [part="summary-deep"], [part="summary-deep-label"] {
26
+ font-size: var(--xyd-font-size-small);
27
+ line-height: var(--xyd-line-height-small);
28
+ }
29
+ [part="summary-deep-label"] {
30
+ font-weight: bold;
31
+ }
32
+ }
33
+
34
+ &[data-kind="secondary"] {
35
+ code {
36
+ background: var(--xyd-details-bgcolor--secondary);
37
+ }
38
+ }
39
+ }
40
+
41
+ hr {
42
+ margin: var(--space-xxlarge) 0;
43
+ }
44
+
45
+ p {
46
+ display: block;
47
+
48
+ code {
49
+ font-size: var(--xyd-font-size-small);
50
+ line-height: var(--xyd-line-height-small);
51
+ margin: 0;
52
+ }
53
+ }
54
+
55
+ h2,h3,h4,h5,h6 {
56
+ margin-top: var(--space-xxlarge);
57
+ &[data-kind="muted"] {
58
+ display: block;
59
+ }
60
+ }
61
+ h2 {
62
+ margin-top: var(--space-2xlarge);
63
+ }
64
+ h2:first-of-type {
65
+ margin-top: var(--space-xxlarge);
66
+ }
67
+
68
+ h4 {
69
+ &[data-kind="muted"] {
70
+ margin: 4px 0 16px;
71
+ }
72
+ }
73
+
74
+
75
+ ul:not(xyd-underlinenav ul), ol:not(xyd-underlinenav ol) {
76
+ margin-top: var(--space-medium);
77
+ }
78
+
79
+ xyd-codetabs, xyd-callout, xyd-guidecard, xyd-tabs {
80
+ margin: var(--space-large) 0;
81
+ }
82
+ xyd-guidecard [part="body"] {
83
+ color: var(--dark48);
84
+ font-size: var(--xyd-font-size-small);
85
+ line-height: var(--xyd-line-height-medium);
86
+
87
+ p {
88
+ color: var(--dark48);
89
+ font-size: var(--xyd-font-size-small);
90
+ line-height: var(--xyd-line-height-medium);
91
+ }
92
+ }
93
+ xyd-guidecard-list xyd-guidecard {
94
+ margin-bottom: 0;
95
+ }
96
+ xyd-tabs [part="buttons"] {
97
+ font-size: var(--xyd-font-size-small);
98
+ line-height: var(--xyd-line-height-small);
99
+ }
100
+
101
+ xyd-callout {
102
+ --xyd-font-size-medium: var(--xyd-font-size-small);
103
+ }
104
+
105
+ xyd-codetabs {
106
+ xyd-code-pre {
107
+ font-size: var(--xyd-font-size-xsmall);
108
+ line-height: var(--xyd-line-height-xsmall);
109
+ }
110
+ }
111
+ }
112
+ `
113
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react'
2
+
3
+ import cn from "./ContentDecoator.styles";
4
+
5
+ interface ContentDecoratorProps {
6
+ children: React.ReactNode
7
+ metaComponent?: string
8
+ }
9
+
10
+ export function ContentDecorator({ children, metaComponent }: ContentDecoratorProps) {
11
+ return <xyd-content-decorator
12
+ className={cn.ContentDecoratorHost}
13
+ meta-component={metaComponent || undefined}
14
+ >
15
+ {children}
16
+ </xyd-content-decorator>
17
+ }
@@ -0,0 +1,67 @@
1
+ import { css } from "@linaria/core";
2
+
3
+ export default {
4
+ GridDecoratorHost: css`
5
+ @layer components {
6
+ display: grid;
7
+ gap: 1rem;
8
+ width: 100%;
9
+
10
+ /* First level ul - 1fr */
11
+ > ul {
12
+ display: grid;
13
+ grid-template-columns: 1fr;
14
+ gap: 1rem;
15
+ width: 100%;
16
+ }
17
+
18
+ /* Nested ul - 2fr */
19
+ ul ul {
20
+ display: grid;
21
+ grid-template-columns: repeat(2, 1fr);
22
+ gap: 1rem;
23
+ width: 100%;
24
+ }
25
+
26
+ &[data-cols] {
27
+ --cols: var(--data-cols, 2);
28
+ ul ul {
29
+ grid-template-columns: repeat(var(--cols), 1fr);
30
+ }
31
+ }
32
+
33
+ &[data-cols="2"] { --data-cols: 2; }
34
+ &[data-cols="3"] { --data-cols: 3; }
35
+ &[data-cols="4"] { --data-cols: 4; }
36
+ &[data-cols="5"] { --data-cols: 5; }
37
+ &[data-cols="6"] { --data-cols: 6; }
38
+
39
+ @media (max-width: 768px) {
40
+ > ul {
41
+ gap: 0;
42
+ }
43
+ ul ul {
44
+ grid-template-columns: 1fr;
45
+ }
46
+ }
47
+
48
+ ul, ol, li {
49
+ &::before {
50
+ content: none;
51
+ }
52
+ }
53
+
54
+ ul, ol {
55
+ display: grid;
56
+ margin: 0;
57
+ padding: 0 !important;
58
+ list-style: none;
59
+ }
60
+
61
+ li {
62
+ margin-left: 0 !important;
63
+ padding-left: 0 !important;
64
+ }
65
+ }
66
+ `
67
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ import cn from "./GridDecorator.styles";
4
+
5
+ interface GridDecoratorProps {
6
+ cols?: 2 | 3 | 4 | 5 | 6
7
+ }
8
+ /**
9
+ * A wrapper component that applies grid decoration styling to its children.
10
+ * This component uses a custom element `xyd-grid-decorator` to provide grid-based layout decoration.
11
+ *
12
+ * @category Component
13
+ */
14
+ export function GridDecorator({ children, cols }: GridDecoratorProps) {
15
+ return <xyd-grid-decorator
16
+ className={cn.GridDecoratorHost}
17
+ data-cols={cols}
18
+ >
19
+ {children}
20
+ </xyd-grid-decorator>
21
+ }