@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.
- package/.idea/git_toolbox_blame.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/xyd-components.iml +12 -0
- package/CHANGELOG.md +1369 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/TODO.md +1 -0
- package/coder.ts +1 -0
- package/content.ts +1 -0
- package/dist/Button-BLA2ghHZ.js +2 -0
- package/dist/Button-BLA2ghHZ.js.map +1 -0
- package/dist/Button-BTJ2hIal.js +2 -0
- package/dist/Button-BTJ2hIal.js.map +1 -0
- package/dist/Button-r4BCrEjy.js +2 -0
- package/dist/Button-r4BCrEjy.js.map +1 -0
- package/dist/CodeSample-BZ5tvyWY.js +2 -0
- package/dist/CodeSample-BZ5tvyWY.js.map +1 -0
- package/dist/CodeSample-BqXDbWdi.js +2 -0
- package/dist/CodeSample-BqXDbWdi.js.map +1 -0
- package/dist/CodeSample-Cqv86IdN.js +2 -0
- package/dist/CodeSample-Cqv86IdN.js.map +1 -0
- package/dist/Icon--77MqplU.js +2 -0
- package/dist/Icon--77MqplU.js.map +1 -0
- package/dist/Icon-DbNmvK_Q.js +2 -0
- package/dist/Icon-DbNmvK_Q.js.map +1 -0
- package/dist/Icon-uVIU1LW6.js +2 -0
- package/dist/Icon-uVIU1LW6.js.map +1 -0
- package/dist/PageFirstSlide-BDNmCTiJ.js +2 -0
- package/dist/PageFirstSlide-BDNmCTiJ.js.map +1 -0
- package/dist/PageFirstSlide-BpZ42bEU.js +2 -0
- package/dist/PageFirstSlide-BpZ42bEU.js.map +1 -0
- package/dist/PageFirstSlide-CqxiyK57.js +2 -0
- package/dist/PageFirstSlide-CqxiyK57.js.map +1 -0
- package/dist/TabsAnalytics-B_JYpawG.js +2 -0
- package/dist/TabsAnalytics-B_JYpawG.js.map +1 -0
- package/dist/TabsAnalytics-DAOfTZgv.js +2 -0
- package/dist/TabsAnalytics-DAOfTZgv.js.map +1 -0
- package/dist/TabsAnalytics-Dhyadlbu.js +2 -0
- package/dist/TabsAnalytics-Dhyadlbu.js.map +1 -0
- package/dist/Update-53fEhmjh.js +2 -0
- package/dist/Update-53fEhmjh.js.map +1 -0
- package/dist/Update-CFi6uapq.js +2 -0
- package/dist/Update-CFi6uapq.js.map +1 -0
- package/dist/Update-CiMIOgZi.js +2 -0
- package/dist/Update-CiMIOgZi.js.map +1 -0
- package/dist/VideoGuide-C0K9fFar.js +2 -0
- package/dist/VideoGuide-C0K9fFar.js.map +1 -0
- package/dist/VideoGuide-CJYkuLst.js +2 -0
- package/dist/VideoGuide-CJYkuLst.js.map +1 -0
- package/dist/VideoGuide-DBY-EyxG.js +2 -0
- package/dist/VideoGuide-DBY-EyxG.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-CvhQFv1t.js +4 -0
- package/dist/_rollupPluginBabelHelpers-CvhQFv1t.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-DSwDY1Dm.js +4 -0
- package/dist/_rollupPluginBabelHelpers-DSwDY1Dm.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-Dc-ocx4G.js +4 -0
- package/dist/_rollupPluginBabelHelpers-Dc-ocx4G.js.map +1 -0
- package/dist/coder/themes/classic.css +57 -0
- package/dist/coder/themes/classic.d.ts +96 -0
- package/dist/coder/themes/classic.js +2 -0
- package/dist/coder/themes/classic.js.map +1 -0
- package/dist/coder/themes/cosmo.css +64 -0
- package/dist/coder/themes/cosmo.d.ts +96 -0
- package/dist/coder/themes/cosmo.js +2 -0
- package/dist/coder/themes/cosmo.js.map +1 -0
- package/dist/coder.d.ts +94 -0
- package/dist/coder.js +2 -0
- package/dist/coder.js.map +1 -0
- package/dist/content.d.ts +411 -0
- package/dist/content.js +2 -0
- package/dist/content.js.map +1 -0
- package/dist/index.css +282 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts.d.ts +33 -0
- package/dist/layouts.js +2 -0
- package/dist/layouts.js.map +1 -0
- package/dist/pages.d.ts +176 -0
- package/dist/pages.js +2 -0
- package/dist/pages.js.map +1 -0
- package/dist/system.d.ts +45 -0
- package/dist/system.js +2 -0
- package/dist/system.js.map +1 -0
- package/dist/useUXClick-DK3cTAMR.js +2 -0
- package/dist/useUXClick-DK3cTAMR.js.map +1 -0
- package/dist/useUXClick-DO6qBcRy.js +2 -0
- package/dist/useUXClick-DO6qBcRy.js.map +1 -0
- package/dist/useUXClick-NwpsiuK9.js +2 -0
- package/dist/useUXClick-NwpsiuK9.js.map +1 -0
- package/dist/useUXEvents-CJtgGV4R.js +2 -0
- package/dist/useUXEvents-CJtgGV4R.js.map +1 -0
- package/dist/useUXEvents-Cxgl7xb-.js +2 -0
- package/dist/useUXEvents-Cxgl7xb-.js.map +1 -0
- package/dist/useUXEvents-XqAGxoEj.js +2 -0
- package/dist/useUXEvents-XqAGxoEj.js.map +1 -0
- package/dist/useUXScrollDepth-3rk3Z95r.js +2 -0
- package/dist/useUXScrollDepth-3rk3Z95r.js.map +1 -0
- package/dist/useUXScrollDepth-BwK-XOBg.js +2 -0
- package/dist/useUXScrollDepth-BwK-XOBg.js.map +1 -0
- package/dist/useUXScrollDepth-DKre7PBz.js +2 -0
- package/dist/useUXScrollDepth-DKre7PBz.js.map +1 -0
- package/dist/uxsdk.d.ts +53 -0
- package/dist/uxsdk.js +2 -0
- package/dist/uxsdk.js.map +1 -0
- package/dist/views.d.ts +18 -0
- package/dist/views.js +2 -0
- package/dist/views.js.map +1 -0
- package/dist/writer.d.ts +580 -0
- package/dist/writer.js +2 -0
- package/dist/writer.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1640 -0
- package/docs/functions/GuideCard.html +6 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +2 -0
- package/docs/interfaces/GuideCardProps.html +18 -0
- package/docs/modules.html +1 -0
- package/index.ts +0 -0
- package/layouts.ts +1 -0
- package/output.txt +13 -0
- package/package.json +81 -0
- package/pages.ts +1 -0
- package/postcss.config.cjs +5 -0
- package/rollup.config.js +195 -0
- package/src/coder/Code/Code.styles.tsx +151 -0
- package/src/coder/Code/Code.tsx +171 -0
- package/src/coder/Code/CodeLoader.tsx +10 -0
- package/src/coder/Code/annotations.tsx +51 -0
- package/src/coder/Code/highlight.ts +208 -0
- package/src/coder/Code/index.ts +16 -0
- package/src/coder/CodeCopy/CodeCopy.styles.tsx +21 -0
- package/src/coder/CodeCopy/CodeCopy.tsx +36 -0
- package/src/coder/CodeCopy/index.ts +7 -0
- package/src/coder/CodeSample/CodeSample.tsx +118 -0
- package/src/coder/CodeSample/CodeSampleAnalytics.tsx +112 -0
- package/src/coder/CodeSample/index.ts +11 -0
- package/src/coder/CodeSample/withLocalStored.tsx +50 -0
- package/src/coder/CodeTabs/CodeTabs.styles.tsx +126 -0
- package/src/coder/CodeTabs/CodeTabs.tsx +128 -0
- package/src/coder/CodeTabs/index.ts +6 -0
- package/src/coder/CodeTheme/CodeTheme.tsx +126 -0
- package/src/coder/CodeTheme/index.ts +7 -0
- package/src/coder/CoderProvider.tsx +26 -0
- package/src/coder/README.md +1 -0
- package/src/coder/hooks/highlight.ts +182 -0
- package/src/coder/index.ts +37 -0
- package/src/coder/themes/classic.css +57 -0
- package/src/coder/themes/classic.ts +270 -0
- package/src/coder/themes/cosmo.css +64 -0
- package/src/coder/themes/cosmo.ts +264 -0
- package/src/content/AppearanceDecorator.styles.tsx +11 -0
- package/src/content/ContentDecoator.styles.tsx +180 -0
- package/src/content/ContentDecorator.tsx +17 -0
- package/src/content/GridDecorator.styles.tsx +86 -0
- package/src/content/GridDecorator.tsx +23 -0
- package/src/content/ReactContent.tsx +671 -0
- package/src/content/TODO.md +1 -0
- package/src/content/index.ts +13 -0
- package/src/kit/Loader/Loader.styles.tsx +53 -0
- package/src/kit/Loader/Loader.tsx +22 -0
- package/src/kit/TODO.md +2 -0
- package/src/kit/index.ts +1 -0
- package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +325 -0
- package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +252 -0
- package/src/layouts/LayoutPrimary/index.ts +3 -0
- package/src/layouts/index.ts +6 -0
- package/src/pages/PageBlogHome/PageBlogHome.styles.tsx +67 -0
- package/src/pages/PageBlogHome/PageBlogHome.tsx +64 -0
- package/src/pages/PageBlogHome/index.ts +3 -0
- package/src/pages/PageBlogHome/types.ts +35 -0
- package/src/pages/PageBlogPost/PageBlogPost.styles.tsx +4 -0
- package/src/pages/PageBlogPost/PageBlogPost.tsx +9 -0
- package/src/pages/PageBlogPost/index.ts +3 -0
- package/src/pages/PageFirstSlide/PageFirstSlide.styles.tsx +134 -0
- package/src/pages/PageFirstSlide/PageFirstSlide.tsx +56 -0
- package/src/pages/PageFirstSlide/index.ts +1 -0
- package/src/pages/PageFirstSlide/types.ts +67 -0
- package/src/pages/PageHome/PageHome.styles.tsx +51 -0
- package/src/pages/PageHome/PageHome.tsx +62 -0
- package/src/pages/PageHome/index.ts +3 -0
- package/src/pages/PageHome/types.ts +79 -0
- package/src/pages/index.ts +7 -0
- package/src/system/Baseline/Baseline.styles.tsx +128 -0
- package/src/system/Baseline/Baseline.tsx +40 -0
- package/src/system/Baseline/bun.svg +1 -0
- package/src/system/Baseline/check.svg +1 -0
- package/src/system/Baseline/index.ts +1 -0
- package/src/system/Baseline/logo.svg +1 -0
- package/src/system/Baseline/node.svg +7 -0
- package/src/system/Baseline/npm.svg +5 -0
- package/src/system/Baseline/pnpm.svg +1 -0
- package/src/system/Footer/Footer.styles.tsx +213 -0
- package/src/system/Footer/Footer.tsx +105 -0
- package/src/system/Footer/index.ts +1 -0
- package/src/system/SearchButton/SearchButton.styles.tsx +89 -0
- package/src/system/SearchButton/SearchButton.tsx +118 -0
- package/src/system/SearchButton/index.ts +1 -0
- package/src/system/index.ts +3 -0
- package/src/utils/useStyle.ts +19 -0
- package/src/uxsdk/const.ts +1 -0
- package/src/uxsdk/index.ts +21 -0
- package/src/uxsdk/useUXClick.ts +21 -0
- package/src/uxsdk/useUXEvents.ts +105 -0
- package/src/uxsdk/useUXScrollDepth.ts +49 -0
- package/src/uxsdk/useUXUnreachableElementTracker.ts +100 -0
- package/src/views/HomeView/HomeView.styles.tsx +37 -0
- package/src/views/HomeView/HomeView.tsx +34 -0
- package/src/views/HomeView/index.ts +3 -0
- package/src/writer/Anchor/Anchor.styles.tsx +26 -0
- package/src/writer/Anchor/Anchor.tsx +51 -0
- package/src/writer/Anchor/index.tsx +1 -0
- package/src/writer/Badge/Badge.styles.tsx +44 -0
- package/src/writer/Badge/Badge.tsx +47 -0
- package/src/writer/Badge/index.ts +7 -0
- package/src/writer/Banner/Banner.styles.tsx +111 -0
- package/src/writer/Banner/Banner.tsx +151 -0
- package/src/writer/Banner/index.ts +1 -0
- package/src/writer/Blockquote/Blockquote.styles.tsx +20 -0
- package/src/writer/Blockquote/Blockquote.tsx +38 -0
- package/src/writer/Blockquote/index.ts +7 -0
- package/src/writer/BlogCard/BlogCard.styles.tsx +4 -0
- package/src/writer/BlogCard/BlogCard.tsx +9 -0
- package/src/writer/BlogCard/index.ts +3 -0
- package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +24 -0
- package/src/writer/Breadcrumbs/Breadcrumbs.tsx +57 -0
- package/src/writer/Breadcrumbs/index.ts +7 -0
- package/src/writer/Button/Button.styles.tsx +149 -0
- package/src/writer/Button/Button.tsx +82 -0
- package/src/writer/Button/index.ts +2 -0
- package/src/writer/Callout/Callout.styles.tsx +102 -0
- package/src/writer/Callout/Callout.tsx +166 -0
- package/src/writer/Callout/index.tsx +3 -0
- package/src/writer/Card/Card.styles.tsx +110 -0
- package/src/writer/Card/Card.tsx +94 -0
- package/src/writer/Card/index.ts +1 -0
- package/src/writer/Code/Code.styles.tsx +16 -0
- package/src/writer/Code/Code.tsx +16 -0
- package/src/writer/Code/index.ts +3 -0
- package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +191 -0
- package/src/writer/ColorSchemeButton/index.ts +1 -0
- package/src/writer/Details/Details.styles.tsx +101 -0
- package/src/writer/Details/Details.tsx +168 -0
- package/src/writer/Details/DetailsProps.tsx +34 -0
- package/src/writer/Details/index.ts +6 -0
- package/src/writer/GuideCard/GuideCard.styles.tsx +129 -0
- package/src/writer/GuideCard/GuideCard.tsx +123 -0
- package/src/writer/GuideCard/index.ts +1 -0
- package/src/writer/Heading/Heading.styles.tsx +93 -0
- package/src/writer/Heading/Heading.tsx +123 -0
- package/src/writer/Heading/index.ts +7 -0
- package/src/writer/Hr/Hr.styles.tsx +7 -0
- package/src/writer/Hr/Hr.tsx +10 -0
- package/src/writer/Hr/index.ts +3 -0
- package/src/writer/Icon/Icon.styles.tsx +15 -0
- package/src/writer/Icon/Icon.tsx +99 -0
- package/src/writer/Icon/index.ts +1 -0
- package/src/writer/IconSocial/IconSocial.tsx +107 -0
- package/src/writer/IconSocial/index.ts +1 -0
- package/src/writer/Image/Image.styles.tsx +9 -0
- package/src/writer/Image/Image.tsx +35 -0
- package/src/writer/Image/index.ts +1 -0
- package/src/writer/List/List.styles.tsx +47 -0
- package/src/writer/List/List.tsx +29 -0
- package/src/writer/List/index.ts +4 -0
- package/src/writer/NavLinks/NavLinks.styles.ts +32 -0
- package/src/writer/NavLinks/NavLinks.tsx +95 -0
- package/src/writer/NavLinks/index.ts +7 -0
- package/src/writer/Pre/Pre.styles.tsx +13 -0
- package/src/writer/Pre/Pre.tsx +14 -0
- package/src/writer/Pre/index.ts +3 -0
- package/src/writer/README.md +1 -0
- package/src/writer/Steps/Steps.styles.tsx +91 -0
- package/src/writer/Steps/Steps.tsx +75 -0
- package/src/writer/Steps/index.ts +5 -0
- package/src/writer/Table/Table.styles.tsx +100 -0
- package/src/writer/Table/Table.tsx +158 -0
- package/src/writer/Table/index.ts +3 -0
- package/src/writer/Tabs/Tabs.tsx +67 -0
- package/src/writer/Tabs/TabsAnalytics.tsx +25 -0
- package/src/writer/Tabs/TabsPrimary.styles.tsx +187 -0
- package/src/writer/Tabs/TabsPrimary.tsx +215 -0
- package/src/writer/Tabs/TabsProps.tsx +13 -0
- package/src/writer/Tabs/TabsSecondary.styles.tsx +78 -0
- package/src/writer/Tabs/TabsSecondary.tsx +176 -0
- package/src/writer/Tabs/index.ts +2 -0
- package/src/writer/Tabs/useValueChange.ts +84 -0
- package/src/writer/Text/Text.styles.tsx +66 -0
- package/src/writer/Text/Text.tsx +79 -0
- package/src/writer/Text/index.ts +3 -0
- package/src/writer/TocCard/TocCard.module.css +44 -0
- package/src/writer/TocCard/TocCard.tsx +42 -0
- package/src/writer/TocCard/index.ts +3 -0
- package/src/writer/Update/Update.styles.tsx +33 -0
- package/src/writer/Update/Update.tsx +37 -0
- package/src/writer/Update/index.ts +1 -0
- package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
- package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
- package/src/writer/VideoGuide/index.ts +1 -0
- package/src/writer/index.ts +53 -0
- package/system.ts +1 -0
- package/tsconfig.json +46 -0
- package/types.d.ts +52 -0
- package/uxsdk.ts +1 -0
- package/views.ts +2 -0
- package/writer.ts +1 -0
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
|
|
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";
|
|
11
|
+
import {useCodeSampleAnalytics} from "../CodeSample/CodeSampleAnalytics";
|
|
12
|
+
|
|
13
|
+
export interface CodeProps {
|
|
14
|
+
codeblocks?: CodeThemeBlockProps[];
|
|
15
|
+
theme?: Theme
|
|
16
|
+
children: React.ReactNode
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Code(props: CodeProps) {
|
|
20
|
+
return <Suspense fallback={<CodeLoader />}>
|
|
21
|
+
<CodeTheme
|
|
22
|
+
codeblocks={props.codeblocks}
|
|
23
|
+
theme={props.theme}
|
|
24
|
+
>
|
|
25
|
+
{props.children}
|
|
26
|
+
</CodeTheme>
|
|
27
|
+
</Suspense>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// TODO: fix any
|
|
31
|
+
Code.LineNumber = function CodeLineNumber(props: any) {
|
|
32
|
+
if (!props.children || !props.children.length) {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
<xyd-code-linenumber
|
|
37
|
+
className={cn.LineNumberHost}
|
|
38
|
+
style={{ minWidth: `${props.width}ch` }}
|
|
39
|
+
>
|
|
40
|
+
<span part="line-number">
|
|
41
|
+
{props.lineNumber}
|
|
42
|
+
</span>
|
|
43
|
+
<InnerLine merge={props} />
|
|
44
|
+
</xyd-code-linenumber>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// TODO: fix any
|
|
49
|
+
Code.Mark = function CodeMark(props: any) {
|
|
50
|
+
return <xyd-code-mark
|
|
51
|
+
data-diff={props.annotation?.diff ? "true" : undefined}
|
|
52
|
+
data-query={props.annotation?.diff && props.annotation?.query ? props.annotation?.query : undefined}
|
|
53
|
+
data-annotated={String(!!props.annotation)}
|
|
54
|
+
className={`${cn.MarkHost}`}
|
|
55
|
+
>
|
|
56
|
+
<InnerLine
|
|
57
|
+
part="line"
|
|
58
|
+
merge={props}
|
|
59
|
+
/>
|
|
60
|
+
</xyd-code-mark>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Code.MarkInline = function CodeMarkInline(props: any) {
|
|
64
|
+
return (
|
|
65
|
+
<xyd-code-mark-inline
|
|
66
|
+
data-diff={props.annotation?.diff ? "true" : undefined}
|
|
67
|
+
data-query={props.annotation?.diff && props.annotation?.query ? props.annotation?.query : undefined}
|
|
68
|
+
className={cn.MarkInlineHost}
|
|
69
|
+
>
|
|
70
|
+
{props.children}
|
|
71
|
+
</xyd-code-mark-inline>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// TODO: fix any
|
|
76
|
+
Code.Bg = function CodeLine(props: any) {
|
|
77
|
+
return <xyd-code-bg
|
|
78
|
+
data-annotated={String(!!props.annotation)}
|
|
79
|
+
className={`${cn.BgHost}`}
|
|
80
|
+
>
|
|
81
|
+
{props.children}
|
|
82
|
+
</xyd-code-bg>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Code.Pre = function CodePre(props: {
|
|
86
|
+
codeblock: HighlightedCode,
|
|
87
|
+
size?: "full",
|
|
88
|
+
handlers: AnnotationHandler[],
|
|
89
|
+
className?: string,
|
|
90
|
+
descriptionHead?: string | React.ReactNode,
|
|
91
|
+
descriptionContent?: string | React.ReactNode,
|
|
92
|
+
descriptionIcon?: string
|
|
93
|
+
}
|
|
94
|
+
) {
|
|
95
|
+
const codeSampleAnalytics = useCodeSampleAnalytics()
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
size,
|
|
99
|
+
className,
|
|
100
|
+
codeblock,
|
|
101
|
+
handlers,
|
|
102
|
+
} = props;
|
|
103
|
+
|
|
104
|
+
fixLastToken(codeblock)
|
|
105
|
+
|
|
106
|
+
let description: React.ReactNode | null = null
|
|
107
|
+
|
|
108
|
+
if (props.descriptionHead || props.descriptionContent) {
|
|
109
|
+
description = <div part="code-description" className={cn.CodeDescription}>
|
|
110
|
+
<div>
|
|
111
|
+
{props.descriptionIcon ? <Icon name={props.descriptionIcon} size={16} /> : <_DefaultDescriptionIcon />}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div>
|
|
115
|
+
<Text weight="bold">
|
|
116
|
+
{props.descriptionHead}
|
|
117
|
+
</Text>
|
|
118
|
+
<span>
|
|
119
|
+
{props.descriptionContent}
|
|
120
|
+
</span>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return <xyd-code-pre>
|
|
126
|
+
<Pre
|
|
127
|
+
part="pre"
|
|
128
|
+
data-size={size}
|
|
129
|
+
style={codeblock?.style || codeblock?.style}
|
|
130
|
+
className={`${cn.CodeHost} ${className || ""}`}
|
|
131
|
+
code={codeblock}
|
|
132
|
+
handlers={handlers}
|
|
133
|
+
ref={codeSampleAnalytics.ref}
|
|
134
|
+
/>
|
|
135
|
+
|
|
136
|
+
{description}
|
|
137
|
+
</xyd-code-pre>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* FOR SOME REASONS FOR SINGLE CODE BLOCKS LAST TOKEN IS EMPTY STRING
|
|
142
|
+
*
|
|
143
|
+
* @todo: fix this
|
|
144
|
+
*/
|
|
145
|
+
function fixLastToken(codeblock: HighlightedCode) {
|
|
146
|
+
const lastToken = codeblock.tokens[codeblock.tokens.length - 1]
|
|
147
|
+
if (typeof lastToken === 'string' && (lastToken === ' ' || lastToken === '\n')) {
|
|
148
|
+
codeblock.tokens.pop()
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function _DefaultDescriptionIcon() {
|
|
153
|
+
return <svg
|
|
154
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
155
|
+
viewBox="0 0 24 24"
|
|
156
|
+
strokeWidth={3}
|
|
157
|
+
stroke="currentColor"
|
|
158
|
+
fill="none"
|
|
159
|
+
width={16}
|
|
160
|
+
strokeLinecap="round"
|
|
161
|
+
strokeLinejoin="round"
|
|
162
|
+
>
|
|
163
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
164
|
+
<path d="M12 12l8 -4.5" />
|
|
165
|
+
<path d="M12 12v9" />
|
|
166
|
+
<path d="M12 12l-8 -4.5" />
|
|
167
|
+
<path d="M12 12l8 4.5" />
|
|
168
|
+
<path d="M12 3v9" />
|
|
169
|
+
<path d="M12 12l-8 4.5" />
|
|
170
|
+
</svg>
|
|
171
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AnnotationHandler, BlockAnnotation, InnerLine } from "codehike/code";
|
|
3
|
+
|
|
4
|
+
import { Code } from "./Code";
|
|
5
|
+
|
|
6
|
+
const markAnnotation: AnnotationHandler = {
|
|
7
|
+
name: "mark",
|
|
8
|
+
Line: (props) => {
|
|
9
|
+
return <Code.Mark {...props} />
|
|
10
|
+
},
|
|
11
|
+
Inline: (props) => {
|
|
12
|
+
return <Code.MarkInline {...props} />
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const bgAnnotation: AnnotationHandler = {
|
|
17
|
+
name: "bg",
|
|
18
|
+
Inline: (props) => {
|
|
19
|
+
return <Code.Bg {...props} />
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lineNumberAnnotation: AnnotationHandler = {
|
|
24
|
+
name: "line-numbers",
|
|
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 }]
|
|
35
|
+
},
|
|
36
|
+
Line: ({ annotation, ...props }) => (
|
|
37
|
+
<>
|
|
38
|
+
<div>
|
|
39
|
+
{annotation?.query}
|
|
40
|
+
</div>
|
|
41
|
+
<InnerLine merge={props} />
|
|
42
|
+
</>
|
|
43
|
+
),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const annotations = {
|
|
47
|
+
mark: markAnnotation,
|
|
48
|
+
bg: bgAnnotation,
|
|
49
|
+
lineNumbers: lineNumberAnnotation,
|
|
50
|
+
diff: diffAnnotation
|
|
51
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CodeAnnotation,
|
|
3
|
+
type RawCode,
|
|
4
|
+
type HighlightedCode,
|
|
5
|
+
type Token
|
|
6
|
+
} from 'codehike/code';
|
|
7
|
+
import {
|
|
8
|
+
type Lines,
|
|
9
|
+
type Tokens,
|
|
10
|
+
highlight as lighterAsync,
|
|
11
|
+
highlightSync as lighter,
|
|
12
|
+
LANG_NAMES,
|
|
13
|
+
type Theme
|
|
14
|
+
} from '@code-hike/lighter';
|
|
15
|
+
|
|
16
|
+
type Whitespace = string
|
|
17
|
+
|
|
18
|
+
type AnyToken = Token | Whitespace
|
|
19
|
+
|
|
20
|
+
function isWhitespace(token: Token | Whitespace): token is Whitespace {
|
|
21
|
+
return typeof token === 'string';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function highlight(
|
|
25
|
+
data: RawCode,
|
|
26
|
+
theme: Theme,
|
|
27
|
+
lang: string
|
|
28
|
+
): HighlightedCode {
|
|
29
|
+
if (!LANG_NAMES.includes(lang)) {
|
|
30
|
+
console.warn(`Unknown language "${lang}"`);
|
|
31
|
+
lang = 'txt';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
lines,
|
|
36
|
+
lang: lighterLang,
|
|
37
|
+
style
|
|
38
|
+
} = lighter(data.value, lang, theme as any, {
|
|
39
|
+
annotations: [],
|
|
40
|
+
scopes: false // true for better token transitions, but breaks css themes
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const tokens = joinLines(lines);
|
|
44
|
+
// split surrounding whitespace for each token
|
|
45
|
+
const splitTokens = splitWhitespace(tokens);
|
|
46
|
+
// join consecutive whitespace tokens
|
|
47
|
+
const joinedTokens = joinWhitespace(splitTokens);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...data,
|
|
51
|
+
code: data.value,
|
|
52
|
+
tokens: joinedTokens,
|
|
53
|
+
lang: lighterLang,
|
|
54
|
+
annotations: [], // TODO: in the future
|
|
55
|
+
// annotations: compatAnnotations(annotations),
|
|
56
|
+
themeName: typeof theme === 'string' ? theme : theme?.name || 'unknown',
|
|
57
|
+
style
|
|
58
|
+
};
|
|
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
|
+
|
|
98
|
+
function compatAnnotations(annotations: any[]): CodeAnnotation[] {
|
|
99
|
+
const newAnnotations: CodeAnnotation[] = [];
|
|
100
|
+
for (const a of annotations) {
|
|
101
|
+
const {name, query, ranges} = a;
|
|
102
|
+
for (const r of ranges) {
|
|
103
|
+
if (r.lineNumber) {
|
|
104
|
+
const {lineNumber, fromColumn, toColumn} = r;
|
|
105
|
+
newAnnotations.push({
|
|
106
|
+
name,
|
|
107
|
+
query,
|
|
108
|
+
lineNumber,
|
|
109
|
+
fromColumn,
|
|
110
|
+
toColumn
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
const {fromLineNumber, toLineNumber} = r;
|
|
114
|
+
newAnnotations.push({
|
|
115
|
+
name,
|
|
116
|
+
query,
|
|
117
|
+
fromLineNumber,
|
|
118
|
+
toLineNumber
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return newAnnotations;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// group the Lines into one array
|
|
127
|
+
function joinLines(lines: Lines): AnyToken[] {
|
|
128
|
+
const joinedTokens: AnyToken[] = [];
|
|
129
|
+
lines.forEach((lineOrGroup, i) => {
|
|
130
|
+
if ('lines' in lineOrGroup) {
|
|
131
|
+
throw new Error('Shouldnt be groups');
|
|
132
|
+
} else {
|
|
133
|
+
const tokens = joinTokens(lineOrGroup.tokens);
|
|
134
|
+
joinedTokens.push(...tokens);
|
|
135
|
+
if (i < lines.length - 1) {
|
|
136
|
+
joinedTokens.push('\n');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return joinedTokens;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function joinTokens(tokens: Tokens): AnyToken[] {
|
|
144
|
+
return tokens.map((tokenOrGroup) => {
|
|
145
|
+
if ('tokens' in tokenOrGroup) {
|
|
146
|
+
throw new Error('Shouldnt be groups');
|
|
147
|
+
} else {
|
|
148
|
+
const t = [tokenOrGroup.content] as Token;
|
|
149
|
+
const {color, ...rest} = tokenOrGroup.style || {};
|
|
150
|
+
t.push(color);
|
|
151
|
+
if (Object.keys(rest).length) {
|
|
152
|
+
t.push(rest);
|
|
153
|
+
}
|
|
154
|
+
return t;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function splitWhitespace(tokens: AnyToken[]) {
|
|
160
|
+
const ejected: AnyToken[] = [];
|
|
161
|
+
tokens.forEach((tokenOrGroup) => {
|
|
162
|
+
if (isWhitespace(tokenOrGroup)) {
|
|
163
|
+
ejected.push(tokenOrGroup);
|
|
164
|
+
} else {
|
|
165
|
+
const [before, content, after] = splitSurroundingWhitespace(
|
|
166
|
+
tokenOrGroup[0]
|
|
167
|
+
);
|
|
168
|
+
if (before?.length) {
|
|
169
|
+
ejected.push(before);
|
|
170
|
+
}
|
|
171
|
+
if (content.length) {
|
|
172
|
+
const copy = [...tokenOrGroup] as Token;
|
|
173
|
+
copy[0] = content;
|
|
174
|
+
ejected.push(copy);
|
|
175
|
+
}
|
|
176
|
+
if (after?.length) {
|
|
177
|
+
ejected.push(after);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return ejected;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function joinWhitespace(tokens: AnyToken[]) {
|
|
185
|
+
const joinedTokens: AnyToken[] = [];
|
|
186
|
+
tokens.forEach((tokenOrGroup) => {
|
|
187
|
+
if (isWhitespace(tokenOrGroup)) {
|
|
188
|
+
let last = joinedTokens[joinedTokens.length - 1];
|
|
189
|
+
if (last && isWhitespace(last)) {
|
|
190
|
+
joinedTokens[joinedTokens.length - 1] += tokenOrGroup;
|
|
191
|
+
} else if (tokenOrGroup !== '') {
|
|
192
|
+
joinedTokens.push(tokenOrGroup);
|
|
193
|
+
}
|
|
194
|
+
} else if (tokenOrGroup[0].length > 0) {
|
|
195
|
+
joinedTokens.push(tokenOrGroup);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return joinedTokens;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// splits " \t foo bar \n" into [" \t ","foo bar"," \n"]
|
|
202
|
+
// "foo bar" -> ["","foo bar",""]
|
|
203
|
+
function splitSurroundingWhitespace(content: string) {
|
|
204
|
+
const trimmed = content.trim();
|
|
205
|
+
const before = content.slice(0, content.indexOf(trimmed));
|
|
206
|
+
const after = content.slice(content.indexOf(trimmed) + trimmed.length);
|
|
207
|
+
return [before, trimmed, after];
|
|
208
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
annotations
|
|
3
|
+
} from "./annotations"
|
|
4
|
+
export type {
|
|
5
|
+
CodeProps
|
|
6
|
+
} from "./Code"
|
|
7
|
+
export {
|
|
8
|
+
Code,
|
|
9
|
+
} from "./Code"
|
|
10
|
+
export {
|
|
11
|
+
CodeLoader,
|
|
12
|
+
} from "./CodeLoader"
|
|
13
|
+
export {
|
|
14
|
+
highlight,
|
|
15
|
+
highlightAsync
|
|
16
|
+
} from "./highlight"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {css} from "@linaria/core";
|
|
2
|
+
|
|
3
|
+
export const CodeCopyHost = css`
|
|
4
|
+
@layer defaults {
|
|
5
|
+
all: unset;
|
|
6
|
+
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
|
|
13
|
+
border-radius: 6px;
|
|
14
|
+
padding: 6px;
|
|
15
|
+
|
|
16
|
+
&:hover {
|
|
17
|
+
transition: ease-in 0.1s;
|
|
18
|
+
background: var(--xyd-code-copy-color);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useState } from "react"
|
|
2
|
+
import { Copy, CheckCheck } from "lucide-react"
|
|
3
|
+
|
|
4
|
+
import { useUXEvents } from "../../uxsdk"
|
|
5
|
+
|
|
6
|
+
import * as cn from "./CodeCopy.styles"
|
|
7
|
+
|
|
8
|
+
export interface CodeCopyProps {
|
|
9
|
+
text: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function CodeCopy({ text }: CodeCopyProps) {
|
|
13
|
+
const [copied, setCopied] = useState(false)
|
|
14
|
+
const ux = useUXEvents()
|
|
15
|
+
|
|
16
|
+
function onClick() {
|
|
17
|
+
navigator.clipboard.writeText(text)
|
|
18
|
+
setCopied(true)
|
|
19
|
+
ux.docs.code.copy({ code: text })
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
setCopied(false)
|
|
22
|
+
}, 1200)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <xyd-code-copy>
|
|
26
|
+
<button
|
|
27
|
+
part="button"
|
|
28
|
+
className={cn.CodeCopyHost}
|
|
29
|
+
aria-label="Copy to clipboard"
|
|
30
|
+
onClick={onClick}
|
|
31
|
+
>
|
|
32
|
+
{copied ? <CheckCheck size={16} /> : <Copy size={16} />}
|
|
33
|
+
</button>
|
|
34
|
+
</xyd-code-copy>
|
|
35
|
+
|
|
36
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, {useEffect, useState} from "react";
|
|
2
|
+
import {Theme} from "@code-hike/lighter";
|
|
3
|
+
|
|
4
|
+
import type {CodeThemeBlockProps} from "../CodeTheme";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Code,
|
|
8
|
+
annotations,
|
|
9
|
+
} from "../Code"
|
|
10
|
+
import {
|
|
11
|
+
withCodeTabs
|
|
12
|
+
} from "../CodeTabs";
|
|
13
|
+
import {useCodeTheme} from "../CodeTheme";
|
|
14
|
+
import {useCoder} from "../CoderProvider";
|
|
15
|
+
import {CodeSampleAnalytics} from "./CodeSampleAnalytics";
|
|
16
|
+
|
|
17
|
+
export interface CodeSampleProps {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
codeblocks?: CodeThemeBlockProps[];
|
|
21
|
+
theme?: Theme
|
|
22
|
+
size?: "full"
|
|
23
|
+
lineNumbers?: boolean
|
|
24
|
+
descriptionHead?: string
|
|
25
|
+
descriptionContent?: string | React.ReactNode
|
|
26
|
+
descriptionIcon?: string
|
|
27
|
+
kind?: "secondary"
|
|
28
|
+
controlByMeta?: boolean // TODO: BETTER IN THE FUTURE
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const CodeContext = React.createContext<{
|
|
32
|
+
size?: "full"
|
|
33
|
+
lineNumbers?: boolean
|
|
34
|
+
descriptionHead?: string
|
|
35
|
+
descriptionContent?: string | React.ReactNode
|
|
36
|
+
descriptionIcon?: string
|
|
37
|
+
}>({})
|
|
38
|
+
|
|
39
|
+
export function CodeSample(props: CodeSampleProps) {
|
|
40
|
+
return <CodeSampleAnalytics>
|
|
41
|
+
<Code
|
|
42
|
+
codeblocks={props.codeblocks}
|
|
43
|
+
theme={props.theme}
|
|
44
|
+
>
|
|
45
|
+
<$ThemedCodeSample {...props} />
|
|
46
|
+
</Code>
|
|
47
|
+
</CodeSampleAnalytics>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function $ThemedCodeSample(props: CodeSampleProps) {
|
|
51
|
+
const {highlighted} = useCodeTheme()
|
|
52
|
+
const coder = useCoder()
|
|
53
|
+
|
|
54
|
+
if (props.kind === "secondary") {
|
|
55
|
+
return <CodeContext value={{
|
|
56
|
+
size: props.size,
|
|
57
|
+
lineNumbers: props.lineNumbers,
|
|
58
|
+
descriptionHead: props.descriptionHead,
|
|
59
|
+
descriptionContent: props.descriptionContent,
|
|
60
|
+
descriptionIcon: props.descriptionIcon,
|
|
61
|
+
}}>
|
|
62
|
+
<Code.Pre
|
|
63
|
+
codeblock={highlighted[0]}
|
|
64
|
+
handlers={[
|
|
65
|
+
annotations.mark,
|
|
66
|
+
annotations.bg,
|
|
67
|
+
annotations.lineNumbers
|
|
68
|
+
]}
|
|
69
|
+
/>
|
|
70
|
+
</CodeContext>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let size: "full" | undefined = undefined
|
|
74
|
+
if (typeof props.size === "string") {
|
|
75
|
+
size = props.size
|
|
76
|
+
} else if (typeof coder.scroll === "boolean" && !coder.scroll) {
|
|
77
|
+
size = "full"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lineNumbers = props.lineNumbers ?? coder.lines
|
|
81
|
+
|
|
82
|
+
return <CodeContext value={{
|
|
83
|
+
size,
|
|
84
|
+
lineNumbers,
|
|
85
|
+
descriptionHead: props.descriptionHead,
|
|
86
|
+
descriptionContent: props.descriptionContent,
|
|
87
|
+
descriptionIcon: props.descriptionIcon,
|
|
88
|
+
}}>
|
|
89
|
+
<$CodeSampleTabs
|
|
90
|
+
description={props.description}
|
|
91
|
+
highlighted={highlighted}
|
|
92
|
+
controlByMeta={props.controlByMeta}
|
|
93
|
+
/>
|
|
94
|
+
</CodeContext>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const $CodeSampleTabs = withCodeTabs((props) => {
|
|
98
|
+
const {lineNumbers, size, descriptionHead, descriptionContent, descriptionIcon} = React.useContext(CodeContext)
|
|
99
|
+
const handlers = [
|
|
100
|
+
annotations.mark,
|
|
101
|
+
annotations.bg,
|
|
102
|
+
annotations.diff
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
if (lineNumbers) {
|
|
106
|
+
handlers.push(annotations.lineNumbers)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return <Code.Pre
|
|
110
|
+
{...props}
|
|
111
|
+
descriptionHead={descriptionHead}
|
|
112
|
+
descriptionContent={descriptionContent}
|
|
113
|
+
descriptionIcon={descriptionIcon}
|
|
114
|
+
size={size}
|
|
115
|
+
handlers={handlers}
|
|
116
|
+
/>
|
|
117
|
+
})
|
|
118
|
+
|