@xyd-js/components 0.1.0-xyd.7 → 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 (251) 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 +718 -0
  6. package/LICENSE +21 -0
  7. package/TODO.md +1 -0
  8. package/content.ts +0 -2
  9. package/dist/CTABanner-Bc77pnms.js +2 -0
  10. package/dist/CTABanner-Bc77pnms.js.map +1 -0
  11. package/dist/CTABanner-DzO62aGj.js +2 -0
  12. package/dist/CTABanner-DzO62aGj.js.map +1 -0
  13. package/dist/CodeSample-BWPDgd2G.js +2 -0
  14. package/dist/CodeSample-BWPDgd2G.js.map +1 -0
  15. package/dist/CodeSample-DLnR-knP.js +2 -0
  16. package/dist/CodeSample-DLnR-knP.js.map +1 -0
  17. package/dist/HomeView-C8QlNdKh.js +2 -0
  18. package/dist/HomeView-C8QlNdKh.js.map +1 -0
  19. package/dist/HomeView-ZAP5saNy.js +2 -0
  20. package/dist/HomeView-ZAP5saNy.js.map +1 -0
  21. package/dist/Icon-BESh23UN.js +2 -0
  22. package/dist/Icon-BESh23UN.js.map +1 -0
  23. package/dist/Icon-xNucOqd2.js +2 -0
  24. package/dist/Icon-xNucOqd2.js.map +1 -0
  25. package/dist/Text-CfN9RkYA.js +2 -0
  26. package/dist/Text-CfN9RkYA.js.map +1 -0
  27. package/dist/Text-DKycD2zu.js +2 -0
  28. package/dist/Text-DKycD2zu.js.map +1 -0
  29. package/dist/Update-0XruJHjj.js +2 -0
  30. package/dist/Update-0XruJHjj.js.map +1 -0
  31. package/dist/Update-DKOAw8p9.js +2 -0
  32. package/dist/Update-DKOAw8p9.js.map +1 -0
  33. package/dist/VideoGuide-BUyomFVz.js +2 -0
  34. package/dist/VideoGuide-BUyomFVz.js.map +1 -0
  35. package/dist/VideoGuide-B_iUKKv7.js +2 -0
  36. package/dist/VideoGuide-B_iUKKv7.js.map +1 -0
  37. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js +4 -0
  38. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js.map +1 -0
  39. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js +4 -0
  40. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js.map +1 -0
  41. package/dist/brand.d.ts +9 -9
  42. package/dist/brand.js +1 -1
  43. package/dist/brand.js.map +1 -1
  44. package/dist/coder/themes/cosmo-light.js.map +1 -1
  45. package/dist/coder.d.ts +29 -9
  46. package/dist/coder.js +1 -1
  47. package/dist/coder.js.map +1 -1
  48. package/dist/content.d.ts +268 -204
  49. package/dist/content.js +1 -1
  50. package/dist/content.js.map +1 -1
  51. package/dist/index.css +267 -216
  52. package/dist/layouts.d.ts +20 -21
  53. package/dist/layouts.js +1 -1
  54. package/dist/layouts.js.map +1 -1
  55. package/dist/pages.js +1 -1
  56. package/dist/pages.js.map +1 -1
  57. package/dist/system.d.ts +10 -0
  58. package/dist/system.js +2 -0
  59. package/dist/system.js.map +1 -0
  60. package/dist/tslib.es6-DyL9kPq9.js +2 -0
  61. package/dist/{tslib.es6-DDIOdJiV.js.map → tslib.es6-DyL9kPq9.js.map} +1 -1
  62. package/dist/tslib.es6-Hqk-Mdr9.js +2 -0
  63. package/dist/{tslib.es6-DUrRPhZd.js.map → tslib.es6-Hqk-Mdr9.js.map} +1 -1
  64. package/dist/views.js +1 -1
  65. package/dist/writer.d.ts +411 -78
  66. package/dist/writer.js +1 -1
  67. package/dist/writer.js.map +1 -1
  68. package/docs/.nojekyll +1 -0
  69. package/docs/assets/hierarchy.js +1 -0
  70. package/docs/assets/highlight.css +22 -0
  71. package/docs/assets/icons.js +18 -0
  72. package/docs/assets/icons.svg +1 -0
  73. package/docs/assets/main.js +60 -0
  74. package/docs/assets/navigation.js +1 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1640 -0
  77. package/docs/functions/GuideCard.html +6 -0
  78. package/docs/hierarchy.html +1 -0
  79. package/docs/index.html +2 -0
  80. package/docs/interfaces/GuideCardProps.html +18 -0
  81. package/docs/modules.html +1 -0
  82. package/index.ts +0 -1
  83. package/package.json +13 -18
  84. package/project.json +677 -0
  85. package/rollup.config.js +32 -3
  86. package/src/brand/Button/Button.styles.tsx +28 -0
  87. package/src/brand/Button/Button.tsx +3 -35
  88. package/src/brand/CTABanner/CTABanner.styles.tsx +80 -0
  89. package/src/brand/CTABanner/CTABanner.tsx +34 -112
  90. package/src/brand/Footer/Footer.styles.tsx +18 -0
  91. package/src/brand/Footer/Footer.tsx +4 -24
  92. package/src/brand/TODO.md +1 -0
  93. package/src/coder/Code/Code.styles.tsx +134 -35
  94. package/src/coder/Code/Code.tsx +131 -40
  95. package/src/coder/Code/CodeLoader.tsx +4 -4
  96. package/src/coder/Code/annotations.tsx +28 -8
  97. package/src/coder/Code/highlight.ts +38 -0
  98. package/src/coder/Code/index.ts +2 -1
  99. package/src/coder/CodeCopy/{CodeCopy.style.tsx → CodeCopy.styles.tsx} +6 -6
  100. package/src/coder/CodeCopy/CodeCopy.tsx +6 -6
  101. package/src/coder/CodeSample/CodeSample.tsx +83 -27
  102. package/src/coder/CodeTabs/CodeTabs.styles.tsx +99 -78
  103. package/src/coder/CodeTabs/CodeTabs.tsx +71 -56
  104. package/src/coder/CodeTheme/CodeTheme.tsx +89 -49
  105. package/src/coder/CodeTheme/index.ts +0 -1
  106. package/src/coder/CoderProvider.tsx +26 -0
  107. package/src/coder/index.ts +8 -4
  108. package/src/content/ContentDecoator.styles.tsx +113 -0
  109. package/src/content/ContentDecorator.tsx +17 -0
  110. package/src/content/GridDecorator.styles.tsx +67 -0
  111. package/src/content/GridDecorator.tsx +21 -0
  112. package/src/content/ReactContent.tsx +575 -0
  113. package/src/content/index.ts +10 -2
  114. package/src/icons/index.ts +0 -0
  115. package/src/kit/Loader/Loader.styles.tsx +53 -0
  116. package/src/kit/Loader/Loader.tsx +22 -0
  117. package/src/kit/TODO.md +2 -0
  118. package/src/kit/index.ts +1 -0
  119. package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +263 -278
  120. package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +173 -96
  121. package/src/layouts/LayoutPrimary/index.ts +0 -2
  122. package/src/layouts/index.ts +0 -7
  123. package/src/pages/HomePage/HomePage.styles.tsx +16 -0
  124. package/src/pages/HomePage/HomePage.tsx +7 -21
  125. package/src/pages/TODO.md +1 -0
  126. package/src/system/SearchButton/SearchButton.styles.tsx +86 -0
  127. package/src/system/SearchButton/SearchButton.tsx +116 -0
  128. package/src/system/SearchButton/index.ts +1 -0
  129. package/src/system/index.ts +1 -0
  130. package/src/utils/useStyle.ts +19 -0
  131. package/src/views/HomeView/HomeView.styles.tsx +37 -0
  132. package/src/views/HomeView/HomeView.tsx +5 -45
  133. package/src/views/TODO.md +1 -0
  134. package/src/writer/Anchor/Anchor.styles.tsx +11 -0
  135. package/src/writer/Anchor/Anchor.tsx +51 -0
  136. package/src/writer/Anchor/index.tsx +1 -0
  137. package/src/writer/Badge/Badge.styles.tsx +39 -28
  138. package/src/writer/Badge/Badge.tsx +37 -20
  139. package/src/writer/Banner/Banner.styles.tsx +91 -0
  140. package/src/writer/Banner/Banner.tsx +70 -0
  141. package/src/writer/Banner/index.ts +1 -0
  142. package/src/writer/Blockquote/Blockquote.styles.tsx +4 -4
  143. package/src/writer/Blockquote/Blockquote.tsx +6 -3
  144. package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +22 -21
  145. package/src/writer/Breadcrumbs/Breadcrumbs.tsx +19 -13
  146. package/src/writer/Button/Button.styles.tsx +137 -0
  147. package/src/writer/Button/Button.tsx +75 -0
  148. package/src/writer/Button/index.ts +2 -0
  149. package/src/writer/Callout/Callout.styles.tsx +29 -40
  150. package/src/writer/Callout/Callout.tsx +31 -16
  151. package/src/writer/Card/Card.styles.tsx +47 -0
  152. package/src/writer/Card/Card.tsx +69 -0
  153. package/src/writer/Card/index.ts +1 -0
  154. package/src/writer/Code/Code.styles.tsx +10 -11
  155. package/src/writer/Code/Code.tsx +7 -4
  156. package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +172 -0
  157. package/src/writer/ColorSchemeButton/index.ts +1 -0
  158. package/src/writer/Details/Details.styles.tsx +84 -84
  159. package/src/writer/Details/Details.tsx +71 -51
  160. package/src/writer/Example/index.tsx +5 -0
  161. package/src/writer/GuideCard/GuideCard.styles.tsx +108 -107
  162. package/src/writer/GuideCard/GuideCard.tsx +72 -37
  163. package/src/writer/Heading/Heading.styles.tsx +69 -49
  164. package/src/writer/Heading/Heading.tsx +92 -22
  165. package/src/writer/Hr/Hr.styles.tsx +5 -5
  166. package/src/writer/Hr/Hr.tsx +3 -6
  167. package/src/writer/Icon/Icon.tsx +48 -0
  168. package/src/writer/Icon/index.ts +1 -0
  169. package/src/writer/Image/Image.styles.tsx +9 -0
  170. package/src/writer/Image/Image.tsx +19 -0
  171. package/src/writer/Image/index.ts +1 -0
  172. package/src/writer/List/List.styles.tsx +47 -0
  173. package/src/writer/List/List.tsx +29 -0
  174. package/src/writer/List/index.ts +4 -0
  175. package/src/writer/NavLinks/NavLinks.styles.ts +23 -24
  176. package/src/writer/NavLinks/NavLinks.tsx +66 -19
  177. package/src/writer/Pre/Pre.styles.tsx +5 -5
  178. package/src/writer/Pre/Pre.tsx +4 -3
  179. package/src/writer/Steps/Steps.styles.tsx +14 -12
  180. package/src/writer/Steps/Steps.tsx +39 -10
  181. package/src/writer/Table/Table.styles.tsx +62 -30
  182. package/src/writer/Table/Table.tsx +121 -11
  183. package/src/writer/Table/index.ts +0 -11
  184. package/src/writer/Tabs/Tabs.styles.tsx +63 -70
  185. package/src/writer/Tabs/Tabs.tsx +31 -29
  186. package/src/writer/Text/Text.styles.tsx +66 -0
  187. package/src/writer/Text/Text.tsx +79 -0
  188. package/src/writer/Text/index.ts +3 -0
  189. package/src/writer/TocCard/TocCard.module.css +44 -0
  190. package/src/writer/TocCard/TocCard.tsx +42 -0
  191. package/src/writer/TocCard/index.ts +3 -0
  192. package/src/writer/UnderlineNav/Tabs.tsx +51 -0
  193. package/src/writer/UnderlineNav/TabsPrimary.styles.tsx +184 -0
  194. package/src/writer/UnderlineNav/TabsPrimary.tsx +209 -0
  195. package/src/writer/UnderlineNav/TabsSecondary.styles.tsx +77 -0
  196. package/src/writer/UnderlineNav/TabsSecondary.tsx +171 -0
  197. package/src/writer/UnderlineNav/UnderlineNav.styles.tsx +181 -45
  198. package/src/writer/UnderlineNav/UnderlineNav.tsx +258 -23
  199. package/src/writer/UnderlineNav/index.ts +2 -1
  200. package/src/writer/UnderlineNav/useValueChange.ts +60 -0
  201. package/src/writer/Update/Update.styles.tsx +33 -0
  202. package/src/writer/Update/Update.tsx +37 -0
  203. package/src/writer/Update/index.ts +1 -0
  204. package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
  205. package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
  206. package/src/writer/VideoGuide/index.ts +1 -0
  207. package/src/writer/index.ts +23 -1
  208. package/tsconfig.json +11 -6
  209. package/types.d.ts +50 -0
  210. package/writer.ts +1 -1
  211. package/dist/CTABanner-BrdYlhnD.js +0 -2
  212. package/dist/CTABanner-BrdYlhnD.js.map +0 -1
  213. package/dist/CTABanner-XQNnnpUx.js +0 -2
  214. package/dist/CTABanner-XQNnnpUx.js.map +0 -1
  215. package/dist/CodeSample-Cp42Adjc.js +0 -2
  216. package/dist/CodeSample-Cp42Adjc.js.map +0 -1
  217. package/dist/CodeSample-DxPp80ID.js +0 -2
  218. package/dist/CodeSample-DxPp80ID.js.map +0 -1
  219. package/dist/HomeView-BN9mZXh9.js +0 -2
  220. package/dist/HomeView-BN9mZXh9.js.map +0 -1
  221. package/dist/HomeView-BVaaV0uE.js +0 -2
  222. package/dist/HomeView-BVaaV0uE.js.map +0 -1
  223. package/dist/UnderlineNav-Bs7Ot9Ch.js +0 -2
  224. package/dist/UnderlineNav-Bs7Ot9Ch.js.map +0 -1
  225. package/dist/UnderlineNav-C2aEVraN.js +0 -2
  226. package/dist/UnderlineNav-C2aEVraN.js.map +0 -1
  227. package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js +0 -2
  228. package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js.map +0 -1
  229. package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js +0 -2
  230. package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js.map +0 -1
  231. package/dist/index-BVUz77Tm.js +0 -2
  232. package/dist/index-BVUz77Tm.js.map +0 -1
  233. package/dist/index-jxd3nv2J.js +0 -2
  234. package/dist/index-jxd3nv2J.js.map +0 -1
  235. package/dist/tslib.es6-DDIOdJiV.js +0 -2
  236. package/dist/tslib.es6-DUrRPhZd.js +0 -2
  237. package/src/content/Anchor/Anchor.tsx +0 -63
  238. package/src/content/Anchor/index.tsx +0 -3
  239. package/src/content/Content/Content.tsx +0 -21
  240. package/src/content/Content/index.tsx +0 -3
  241. package/src/content/Content.tsx +0 -180
  242. package/src/content/Subtitle/Subtitle.tsx +0 -21
  243. package/src/content/Subtitle/index.tsx +0 -3
  244. package/src/layouts/Layout.styles.tsx +0 -151
  245. package/src/layouts/Layout.tsx +0 -121
  246. package/src/ui/Loader/Loader.styles.tsx +0 -52
  247. package/src/ui/Loader/Loader.tsx +0 -26
  248. package/src/ui/index.ts +0 -1
  249. package/src/writer/Icon/index.tsx +0 -355
  250. package/src/writer/Table/TableV2.styles.tsx +0 -117
  251. package/src/writer/Table/TableV2.tsx +0 -83
@@ -1,76 +1,167 @@
1
- import React, {Suspense} from "react";
2
- import type {HighlightedCode, AnnotationHandler} from "codehike/code";
3
- import {InnerLine, Pre} from "codehike/code";
4
- import {Theme} from "@code-hike/lighter";
1
+ import React, { Suspense } from "react";
2
+ import type { HighlightedCode, AnnotationHandler } from "codehike/code";
3
+ import { InnerLine, Pre } from "codehike/code";
4
+ import { Theme } from "@code-hike/lighter";
5
5
 
6
- import {CodeTheme, type CodeThemeBlockProps} from "../CodeTheme";
7
- import {$lineNumber, $mark, $code} from "./Code.styles.tsx";
8
- import {CodeLoader} from "./CodeLoader.tsx";
6
+ import { Text } from "../../writer/Text"
7
+ import { CodeTheme, type CodeThemeBlockProps } from "../CodeTheme";
8
+ import * as cn from "./Code.styles";
9
+ import { CodeLoader } from "./CodeLoader";
10
+ import { Icon } from "src/writer/Icon";
9
11
 
10
12
  export interface CodeProps {
11
- codeblocks: CodeThemeBlockProps[];
13
+ codeblocks?: CodeThemeBlockProps[];
12
14
  theme?: Theme
13
15
  children: React.ReactNode
14
16
  }
15
17
 
16
18
  export function Code(props: CodeProps) {
17
- return <Suspense fallback={<CodeLoader/>}>
18
- <CodeTheme codeblocks={props.codeblocks} theme={props.theme}>
19
+ return <Suspense fallback={<CodeLoader />}>
20
+ <CodeTheme
21
+ codeblocks={props.codeblocks}
22
+ theme={props.theme}
23
+ >
19
24
  {props.children}
20
25
  </CodeTheme>
21
26
  </Suspense>
22
27
  }
23
28
 
24
29
  // TODO: fix any
25
- Code.LineNumber = function LineNumber(props: any) {
30
+ Code.LineNumber = function CodeLineNumber(props: any) {
26
31
  if (!props.children || !props.children.length) {
27
32
  return null
28
33
  }
29
34
  return (
30
- <>
31
- <span
32
- style={{minWidth: `${props.width}ch`}}
33
- className={$lineNumber.host}
35
+ <xyd-code-linenumber
36
+ className={cn.LineNumberHost}
37
+ style={{ minWidth: `${props.width}ch` }}
34
38
  >
35
- {props.lineNumber}
36
- </span>
37
- <InnerLine merge={props}/>
38
- </>
39
+ <span part="line-number">
40
+ {props.lineNumber}
41
+ </span>
42
+ <InnerLine merge={props} />
43
+ </xyd-code-linenumber>
39
44
  )
40
45
  }
41
46
 
42
47
  // TODO: fix any
43
- Code.Mark = function Mark(props: any) {
44
- return <div className={`${$mark.host} ${props.annotation && $mark.$$annotated}`}>
48
+ Code.Mark = function CodeMark(props: any) {
49
+ return <xyd-code-mark
50
+ data-diff={props.annotation?.diff ? "true" : undefined}
51
+ data-query={props.annotation?.diff && props.annotation?.query ? props.annotation?.query : undefined}
52
+ data-annotated={String(!!props.annotation)}
53
+ className={`${cn.MarkHost}`}
54
+ >
45
55
  <InnerLine
56
+ part="line"
46
57
  merge={props}
47
- className={$mark.line}
48
58
  />
49
- </div>
59
+ </xyd-code-mark>
60
+ }
61
+
62
+ Code.MarkInline = function CodeMarkInline(props: any) {
63
+ return (
64
+ <xyd-code-mark-inline
65
+ data-diff={props.annotation?.diff ? "true" : undefined}
66
+ data-query={props.annotation?.diff && props.annotation?.query ? props.annotation?.query : undefined}
67
+ className={cn.MarkInlineHost}
68
+ >
69
+ {props.children}
70
+ </xyd-code-mark-inline>
71
+ )
50
72
  }
51
73
 
52
74
  // TODO: fix any
53
75
  Code.Bg = function CodeLine(props: any) {
54
- return <span className={`${props.annotation && $mark.$$annotated}`}>
76
+ return <xyd-code-bg
77
+ data-annotated={String(!!props.annotation)}
78
+ className={`${cn.BgHost}`}
79
+ >
55
80
  {props.children}
56
- </span>
81
+ </xyd-code-bg>
57
82
  }
58
83
 
59
84
  Code.Pre = function CodePre(props: {
60
- codeblock: HighlightedCode,
61
- size?: "full",
62
- handlers: AnnotationHandler[],
63
- className?: string,
64
- }
85
+ codeblock: HighlightedCode,
86
+ size?: "full",
87
+ handlers: AnnotationHandler[],
88
+ className?: string,
89
+ descriptionHead?: string | React.ReactNode,
90
+ descriptionContent?: string | React.ReactNode,
91
+ descriptionIcon?: string
92
+ }
65
93
  ) {
66
- return <Pre
67
- className={`
68
- ${$code.host}
69
- ${props?.size === "full" && $code.host$$full}
70
- ${props.className}
71
- `}
72
- style={props.codeblock?.style || props.codeblock?.style}
73
- code={props.codeblock}
74
- handlers={props.handlers}
75
- />
94
+ const {
95
+ size,
96
+ className,
97
+ codeblock,
98
+ handlers,
99
+ } = props;
100
+
101
+ fixLastToken(codeblock)
102
+
103
+ let description: React.ReactNode | null = null
104
+
105
+ if (props.descriptionHead || props.descriptionContent) {
106
+ description = <div part="code-description" className={cn.CodeDescription}>
107
+ <div>
108
+ {props.descriptionIcon ? <Icon name={props.descriptionIcon} size={16} /> : <_DefaultDescriptionIcon />}
109
+ </div>
110
+
111
+ <div>
112
+ <Text weight="bold">
113
+ {props.descriptionHead}
114
+ </Text>
115
+ <span>
116
+ {props.descriptionContent}
117
+ </span>
118
+ </div>
119
+ </div>
120
+
121
+ }
122
+ return <xyd-code-pre>
123
+ <Pre
124
+ part="pre"
125
+ data-size={size}
126
+ style={codeblock?.style || codeblock?.style}
127
+ className={`${cn.CodeHost} ${className || ""}`}
128
+ code={codeblock}
129
+ handlers={handlers}
130
+ />
131
+
132
+ {description}
133
+ </xyd-code-pre>
134
+ }
135
+
136
+ /**
137
+ * FOR SOME REASONS FOR SINGLE CODE BLOCKS LAST TOKEN IS EMPTY STRING
138
+ *
139
+ * @todo: fix this
140
+ */
141
+ function fixLastToken(codeblock: HighlightedCode) {
142
+ const lastToken = codeblock.tokens[codeblock.tokens.length - 1]
143
+ if (typeof lastToken === 'string' && (lastToken === ' ' || lastToken === '\n')) {
144
+ codeblock.tokens.pop()
145
+ }
146
+ }
147
+
148
+ function _DefaultDescriptionIcon() {
149
+ return <svg
150
+ xmlns="http://www.w3.org/2000/svg"
151
+ viewBox="0 0 24 24"
152
+ strokeWidth={3}
153
+ stroke="currentColor"
154
+ fill="none"
155
+ width={16}
156
+ strokeLinecap="round"
157
+ strokeLinejoin="round"
158
+ >
159
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
160
+ <path d="M12 12l8 -4.5" />
161
+ <path d="M12 12v9" />
162
+ <path d="M12 12l-8 -4.5" />
163
+ <path d="M12 12l8 4.5" />
164
+ <path d="M12 3v9" />
165
+ <path d="M12 12l-8 4.5" />
166
+ </svg>
76
167
  }
@@ -1,10 +1,10 @@
1
1
  import React from "react";
2
2
 
3
- import {$code} from "./Code.styles.tsx";
4
- import {Loader} from "../../ui";
3
+ import * as cn from "./Code.styles";
4
+ import {Loader} from "../../kit";
5
5
 
6
6
  export function CodeLoader() {
7
- return <div className={$code.host}>
7
+ return <xyd-code-loader className={cn.CodeHost}>
8
8
  <Loader/>
9
- </div>
9
+ </xyd-code-loader>
10
10
  }
@@ -1,31 +1,51 @@
1
1
  import React from "react";
2
- import {AnnotationHandler} from "codehike/code";
2
+ import { AnnotationHandler, BlockAnnotation, InnerLine } from "codehike/code";
3
3
 
4
- import {Code} from "./Code.tsx";
4
+ import { Code } from "./Code";
5
5
 
6
6
  const markAnnotation: AnnotationHandler = {
7
7
  name: "mark",
8
8
  Line: (props) => {
9
- return <Code.Mark {...props}/>
10
- }
9
+ return <Code.Mark {...props} />
10
+ },
11
+ Inline: (props) => {
12
+ return <Code.MarkInline {...props} />
13
+ },
11
14
  }
12
15
 
13
16
  const bgAnnotation: AnnotationHandler = {
14
17
  name: "bg",
15
18
  Inline: (props) => {
16
- return <Code.Bg {...props}/>
19
+ return <Code.Bg {...props} />
17
20
  }
18
21
  }
19
22
 
20
23
  const lineNumberAnnotation: AnnotationHandler = {
21
24
  name: "line-numbers",
22
- Line: ({annotation, ...props}) => {
23
- return <Code.LineNumber {...props}/>
25
+ Line: ({ annotation, ...props }) => {
26
+ return <Code.LineNumber {...props} />
27
+ },
28
+ }
29
+
30
+ export const diffAnnotation: AnnotationHandler = {
31
+ name: "diff",
32
+ onlyIfAnnotated: true,
33
+ transform: (annotation: BlockAnnotation) => {
34
+ return [annotation, { ...annotation, name: "mark", query: annotation.query, diff: true }]
24
35
  },
36
+ Line: ({ annotation, ...props }) => (
37
+ <>
38
+ <div>
39
+ {annotation?.query}
40
+ </div>
41
+ <InnerLine merge={props} />
42
+ </>
43
+ ),
25
44
  }
26
45
 
27
46
  export const annotations = {
28
47
  mark: markAnnotation,
29
48
  bg: bgAnnotation,
30
- lineNumbers: lineNumberAnnotation
49
+ lineNumbers: lineNumberAnnotation,
50
+ diff: diffAnnotation
31
51
  }
@@ -7,6 +7,7 @@ import {
7
7
  import {
8
8
  type Lines,
9
9
  type Tokens,
10
+ highlight as lighterAsync,
10
11
  highlightSync as lighter,
11
12
  LANG_NAMES,
12
13
  type Theme
@@ -57,6 +58,43 @@ export function highlight(
57
58
  };
58
59
  }
59
60
 
61
+ export async function highlightAsync(
62
+ data: RawCode,
63
+ theme: Theme,
64
+ lang: string
65
+ ): Promise<HighlightedCode> {
66
+ if (!LANG_NAMES.includes(lang)) {
67
+ console.warn(`Unknown language "${lang}"`);
68
+ lang = 'txt';
69
+ }
70
+
71
+ const {
72
+ lines,
73
+ lang: lighterLang,
74
+ style
75
+ } = await lighterAsync(data.value, lang, theme as any, {
76
+ annotations: [],
77
+ scopes: false // true for better token transitions, but breaks css themes
78
+ });
79
+
80
+ const tokens = joinLines(lines);
81
+ // split surrounding whitespace for each token
82
+ const splitTokens = splitWhitespace(tokens);
83
+ // join consecutive whitespace tokens
84
+ const joinedTokens = joinWhitespace(splitTokens);
85
+
86
+ return {
87
+ ...data,
88
+ code: data.value,
89
+ tokens: joinedTokens,
90
+ lang: lighterLang,
91
+ annotations: [], // TODO: in the future
92
+ // annotations: compatAnnotations(annotations),
93
+ themeName: typeof theme === 'string' ? theme : theme?.name || 'unknown',
94
+ style
95
+ };
96
+ }
97
+
60
98
  function compatAnnotations(annotations: any[]): CodeAnnotation[] {
61
99
  const newAnnotations: CodeAnnotation[] = [];
62
100
  for (const a of annotations) {
@@ -11,5 +11,6 @@ export {
11
11
  CodeLoader,
12
12
  } from "./CodeLoader"
13
13
  export {
14
- highlight
14
+ highlight,
15
+ highlightAsync
15
16
  } from "./highlight"
@@ -1,9 +1,9 @@
1
1
  import {css} from "@linaria/core";
2
2
 
3
- export const $copy = {
4
- host: css`
3
+ export const CodeCopyHost = css`
4
+ @layer defaults {
5
5
  all: unset;
6
-
6
+
7
7
  cursor: pointer;
8
8
 
9
9
  display: flex;
@@ -15,7 +15,7 @@ export const $copy = {
15
15
 
16
16
  &:hover {
17
17
  transition: ease-in 0.1s;
18
- background: #e3e3eb;
18
+ background: var(--xyd-code-copy-color);
19
19
  }
20
- `
21
- }
20
+ }
21
+ `;
@@ -1,9 +1,7 @@
1
1
  import React, {useState} from "react"
2
2
  import {Copy, CheckCheck} from "lucide-react"
3
3
 
4
- import {
5
- $copy
6
- } from "./CodeCopy.style"
4
+ import * as cn from "./CodeCopy.styles"
7
5
 
8
6
  export interface CodeCopyProps {
9
7
  text: string
@@ -20,13 +18,15 @@ export function CodeCopy({text}: CodeCopyProps) {
20
18
  }, 1200)
21
19
  }
22
20
 
23
- return (
21
+ return <xyd-code-copy>
24
22
  <button
23
+ part="button"
24
+ className={cn.CodeCopyHost}
25
25
  aria-label="Copy to clipboard"
26
26
  onClick={onClick}
27
- className={$copy.host}
28
27
  >
29
28
  {copied ? <CheckCheck size={16}/> : <Copy size={16}/>}
30
29
  </button>
31
- )
30
+ </xyd-code-copy>
31
+
32
32
  }
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
- import {Theme} from "@code-hike/lighter";
2
+ import { Theme } from "@code-hike/lighter";
3
3
 
4
- import type {CodeThemeBlockProps} from "../CodeTheme";
4
+ import type { CodeThemeBlockProps } from "../CodeTheme";
5
5
 
6
6
  import {
7
7
  Code,
@@ -10,50 +10,106 @@ import {
10
10
  import {
11
11
  withCodeTabs
12
12
  } from "../CodeTabs";
13
- import {useCodeTheme} from "../CodeTheme";
13
+ import { useCodeTheme } from "../CodeTheme";
14
+ import { useCoder } from "../CoderProvider";
14
15
 
15
16
  export interface CodeSampleProps {
16
17
  name: string;
17
18
  description: string;
18
- codeblocks: CodeThemeBlockProps[];
19
+ codeblocks?: CodeThemeBlockProps[];
20
+ theme?: Theme
19
21
  size?: "full"
22
+ lineNumbers?: boolean
23
+ descriptionHead?: string
24
+ descriptionContent?: string | React.ReactNode
25
+ descriptionIcon?: string
20
26
  kind?: "secondary"
21
- theme?: Theme
27
+ controlByMeta?: boolean // TODO: BETTER IN THE FUTURE
22
28
  }
23
29
 
30
+ const CodeContext = React.createContext<{
31
+ size?: "full"
32
+ lineNumbers?: boolean
33
+ descriptionHead?: string
34
+ descriptionContent?: string | React.ReactNode
35
+ descriptionIcon?: string
36
+ }>({})
37
+
24
38
  export function CodeSample(props: CodeSampleProps) {
25
- return <Code codeblocks={props.codeblocks} theme={props.theme}>
26
- <$ThemedCodeSample {...props}/>
39
+ return <Code
40
+ codeblocks={props.codeblocks}
41
+ theme={props.theme}
42
+ >
43
+ <$ThemedCodeSample {...props} />
27
44
  </Code>
28
45
  }
29
46
 
30
47
  function $ThemedCodeSample(props: CodeSampleProps) {
31
- const {highlighted} = useCodeTheme()
48
+ const { highlighted } = useCodeTheme()
49
+ const coder = useCoder()
32
50
 
33
51
  if (props.kind === "secondary") {
34
- return <Code.Pre
35
- codeblock={highlighted[0]}
36
- handlers={[
37
- annotations.mark,
38
- annotations.bg,
39
- annotations.lineNumbers
40
- ]}
41
- />
52
+ return <CodeContext value={{
53
+ size: props.size,
54
+ lineNumbers: props.lineNumbers,
55
+ descriptionHead: props.descriptionHead,
56
+ descriptionContent: props.descriptionContent,
57
+ descriptionIcon: props.descriptionIcon,
58
+ }}>
59
+ <Code.Pre
60
+ codeblock={highlighted[0]}
61
+ handlers={[
62
+ annotations.mark,
63
+ annotations.bg,
64
+ annotations.lineNumbers
65
+ ]}
66
+ />
67
+ </CodeContext>
42
68
  }
43
69
 
44
- return <$CodeSampleTabs
45
- description={props.description}
46
- highlighted={highlighted}
47
- size={props.size}
48
- />
70
+ let size: "full" | undefined = undefined
71
+ if (typeof props.size === "string") {
72
+ size = props.size
73
+ } else if (typeof coder.scroll === "boolean" && !coder.scroll) {
74
+ size = "full"
75
+ }
76
+
77
+ const lineNumbers = props.lineNumbers ?? coder.lines
78
+
79
+ return <CodeContext value={{
80
+ size,
81
+ lineNumbers,
82
+ descriptionHead: props.descriptionHead,
83
+ descriptionContent: props.descriptionContent,
84
+ descriptionIcon: props.descriptionIcon,
85
+ }}>
86
+ <$CodeSampleTabs
87
+ description={props.description}
88
+ highlighted={highlighted}
89
+ controlByMeta={props.controlByMeta}
90
+ />
91
+ </CodeContext>
49
92
  }
50
93
 
51
- const $CodeSampleTabs = withCodeTabs((props) => <Code.Pre
52
- {...props}
53
- handlers={[
94
+ const $CodeSampleTabs = withCodeTabs((props) => {
95
+ const { lineNumbers, size, descriptionHead, descriptionContent, descriptionIcon } = React.useContext(CodeContext)
96
+ const handlers = [
54
97
  annotations.mark,
55
98
  annotations.bg,
56
- annotations.lineNumbers
57
- ]}
58
- />)
99
+ annotations.diff
100
+ ]
101
+
102
+ if (lineNumbers) {
103
+ handlers.push(annotations.lineNumbers)
104
+ }
105
+
106
+ return <Code.Pre
107
+ {...props}
108
+ descriptionHead={descriptionHead}
109
+ descriptionContent={descriptionContent}
110
+ descriptionIcon={descriptionIcon}
111
+ size={size}
112
+ handlers={handlers}
113
+ />
114
+ })
59
115