@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.
- 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 +718 -0
- package/LICENSE +21 -0
- package/TODO.md +1 -0
- package/content.ts +0 -2
- package/dist/CTABanner-Bc77pnms.js +2 -0
- package/dist/CTABanner-Bc77pnms.js.map +1 -0
- package/dist/CTABanner-DzO62aGj.js +2 -0
- package/dist/CTABanner-DzO62aGj.js.map +1 -0
- package/dist/CodeSample-BWPDgd2G.js +2 -0
- package/dist/CodeSample-BWPDgd2G.js.map +1 -0
- package/dist/CodeSample-DLnR-knP.js +2 -0
- package/dist/CodeSample-DLnR-knP.js.map +1 -0
- package/dist/HomeView-C8QlNdKh.js +2 -0
- package/dist/HomeView-C8QlNdKh.js.map +1 -0
- package/dist/HomeView-ZAP5saNy.js +2 -0
- package/dist/HomeView-ZAP5saNy.js.map +1 -0
- package/dist/Icon-BESh23UN.js +2 -0
- package/dist/Icon-BESh23UN.js.map +1 -0
- package/dist/Icon-xNucOqd2.js +2 -0
- package/dist/Icon-xNucOqd2.js.map +1 -0
- package/dist/Text-CfN9RkYA.js +2 -0
- package/dist/Text-CfN9RkYA.js.map +1 -0
- package/dist/Text-DKycD2zu.js +2 -0
- package/dist/Text-DKycD2zu.js.map +1 -0
- package/dist/Update-0XruJHjj.js +2 -0
- package/dist/Update-0XruJHjj.js.map +1 -0
- package/dist/Update-DKOAw8p9.js +2 -0
- package/dist/Update-DKOAw8p9.js.map +1 -0
- package/dist/VideoGuide-BUyomFVz.js +2 -0
- package/dist/VideoGuide-BUyomFVz.js.map +1 -0
- package/dist/VideoGuide-B_iUKKv7.js +2 -0
- package/dist/VideoGuide-B_iUKKv7.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-CxSUtGup.js +4 -0
- package/dist/_rollupPluginBabelHelpers-CxSUtGup.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js +4 -0
- package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js.map +1 -0
- package/dist/brand.d.ts +9 -9
- package/dist/brand.js +1 -1
- package/dist/brand.js.map +1 -1
- package/dist/coder/themes/cosmo-light.js.map +1 -1
- package/dist/coder.d.ts +29 -9
- package/dist/coder.js +1 -1
- package/dist/coder.js.map +1 -1
- package/dist/content.d.ts +268 -204
- package/dist/content.js +1 -1
- package/dist/content.js.map +1 -1
- package/dist/index.css +267 -216
- package/dist/layouts.d.ts +20 -21
- package/dist/layouts.js +1 -1
- package/dist/layouts.js.map +1 -1
- package/dist/pages.js +1 -1
- package/dist/pages.js.map +1 -1
- package/dist/system.d.ts +10 -0
- package/dist/system.js +2 -0
- package/dist/system.js.map +1 -0
- package/dist/tslib.es6-DyL9kPq9.js +2 -0
- package/dist/{tslib.es6-DDIOdJiV.js.map → tslib.es6-DyL9kPq9.js.map} +1 -1
- package/dist/tslib.es6-Hqk-Mdr9.js +2 -0
- package/dist/{tslib.es6-DUrRPhZd.js.map → tslib.es6-Hqk-Mdr9.js.map} +1 -1
- package/dist/views.js +1 -1
- package/dist/writer.d.ts +411 -78
- package/dist/writer.js +1 -1
- package/dist/writer.js.map +1 -1
- 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 -1
- package/package.json +13 -18
- package/project.json +677 -0
- package/rollup.config.js +32 -3
- package/src/brand/Button/Button.styles.tsx +28 -0
- package/src/brand/Button/Button.tsx +3 -35
- package/src/brand/CTABanner/CTABanner.styles.tsx +80 -0
- package/src/brand/CTABanner/CTABanner.tsx +34 -112
- package/src/brand/Footer/Footer.styles.tsx +18 -0
- package/src/brand/Footer/Footer.tsx +4 -24
- package/src/brand/TODO.md +1 -0
- package/src/coder/Code/Code.styles.tsx +134 -35
- package/src/coder/Code/Code.tsx +131 -40
- package/src/coder/Code/CodeLoader.tsx +4 -4
- package/src/coder/Code/annotations.tsx +28 -8
- package/src/coder/Code/highlight.ts +38 -0
- package/src/coder/Code/index.ts +2 -1
- package/src/coder/CodeCopy/{CodeCopy.style.tsx → CodeCopy.styles.tsx} +6 -6
- package/src/coder/CodeCopy/CodeCopy.tsx +6 -6
- package/src/coder/CodeSample/CodeSample.tsx +83 -27
- package/src/coder/CodeTabs/CodeTabs.styles.tsx +99 -78
- package/src/coder/CodeTabs/CodeTabs.tsx +71 -56
- package/src/coder/CodeTheme/CodeTheme.tsx +89 -49
- package/src/coder/CodeTheme/index.ts +0 -1
- package/src/coder/CoderProvider.tsx +26 -0
- package/src/coder/index.ts +8 -4
- package/src/content/ContentDecoator.styles.tsx +113 -0
- package/src/content/ContentDecorator.tsx +17 -0
- package/src/content/GridDecorator.styles.tsx +67 -0
- package/src/content/GridDecorator.tsx +21 -0
- package/src/content/ReactContent.tsx +575 -0
- package/src/content/index.ts +10 -2
- package/src/icons/index.ts +0 -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 +263 -278
- package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +173 -96
- package/src/layouts/LayoutPrimary/index.ts +0 -2
- package/src/layouts/index.ts +0 -7
- package/src/pages/HomePage/HomePage.styles.tsx +16 -0
- package/src/pages/HomePage/HomePage.tsx +7 -21
- package/src/pages/TODO.md +1 -0
- package/src/system/SearchButton/SearchButton.styles.tsx +86 -0
- package/src/system/SearchButton/SearchButton.tsx +116 -0
- package/src/system/SearchButton/index.ts +1 -0
- package/src/system/index.ts +1 -0
- package/src/utils/useStyle.ts +19 -0
- package/src/views/HomeView/HomeView.styles.tsx +37 -0
- package/src/views/HomeView/HomeView.tsx +5 -45
- package/src/views/TODO.md +1 -0
- package/src/writer/Anchor/Anchor.styles.tsx +11 -0
- package/src/writer/Anchor/Anchor.tsx +51 -0
- package/src/writer/Anchor/index.tsx +1 -0
- package/src/writer/Badge/Badge.styles.tsx +39 -28
- package/src/writer/Badge/Badge.tsx +37 -20
- package/src/writer/Banner/Banner.styles.tsx +91 -0
- package/src/writer/Banner/Banner.tsx +70 -0
- package/src/writer/Banner/index.ts +1 -0
- package/src/writer/Blockquote/Blockquote.styles.tsx +4 -4
- package/src/writer/Blockquote/Blockquote.tsx +6 -3
- package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +22 -21
- package/src/writer/Breadcrumbs/Breadcrumbs.tsx +19 -13
- package/src/writer/Button/Button.styles.tsx +137 -0
- package/src/writer/Button/Button.tsx +75 -0
- package/src/writer/Button/index.ts +2 -0
- package/src/writer/Callout/Callout.styles.tsx +29 -40
- package/src/writer/Callout/Callout.tsx +31 -16
- package/src/writer/Card/Card.styles.tsx +47 -0
- package/src/writer/Card/Card.tsx +69 -0
- package/src/writer/Card/index.ts +1 -0
- package/src/writer/Code/Code.styles.tsx +10 -11
- package/src/writer/Code/Code.tsx +7 -4
- package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +172 -0
- package/src/writer/ColorSchemeButton/index.ts +1 -0
- package/src/writer/Details/Details.styles.tsx +84 -84
- package/src/writer/Details/Details.tsx +71 -51
- package/src/writer/Example/index.tsx +5 -0
- package/src/writer/GuideCard/GuideCard.styles.tsx +108 -107
- package/src/writer/GuideCard/GuideCard.tsx +72 -37
- package/src/writer/Heading/Heading.styles.tsx +69 -49
- package/src/writer/Heading/Heading.tsx +92 -22
- package/src/writer/Hr/Hr.styles.tsx +5 -5
- package/src/writer/Hr/Hr.tsx +3 -6
- package/src/writer/Icon/Icon.tsx +48 -0
- package/src/writer/Icon/index.ts +1 -0
- package/src/writer/Image/Image.styles.tsx +9 -0
- package/src/writer/Image/Image.tsx +19 -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 +23 -24
- package/src/writer/NavLinks/NavLinks.tsx +66 -19
- package/src/writer/Pre/Pre.styles.tsx +5 -5
- package/src/writer/Pre/Pre.tsx +4 -3
- package/src/writer/Steps/Steps.styles.tsx +14 -12
- package/src/writer/Steps/Steps.tsx +39 -10
- package/src/writer/Table/Table.styles.tsx +62 -30
- package/src/writer/Table/Table.tsx +121 -11
- package/src/writer/Table/index.ts +0 -11
- package/src/writer/Tabs/Tabs.styles.tsx +63 -70
- package/src/writer/Tabs/Tabs.tsx +31 -29
- 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/UnderlineNav/Tabs.tsx +51 -0
- package/src/writer/UnderlineNav/TabsPrimary.styles.tsx +184 -0
- package/src/writer/UnderlineNav/TabsPrimary.tsx +209 -0
- package/src/writer/UnderlineNav/TabsSecondary.styles.tsx +77 -0
- package/src/writer/UnderlineNav/TabsSecondary.tsx +171 -0
- package/src/writer/UnderlineNav/UnderlineNav.styles.tsx +181 -45
- package/src/writer/UnderlineNav/UnderlineNav.tsx +258 -23
- package/src/writer/UnderlineNav/index.ts +2 -1
- package/src/writer/UnderlineNav/useValueChange.ts +60 -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 +23 -1
- package/tsconfig.json +11 -6
- package/types.d.ts +50 -0
- package/writer.ts +1 -1
- package/dist/CTABanner-BrdYlhnD.js +0 -2
- package/dist/CTABanner-BrdYlhnD.js.map +0 -1
- package/dist/CTABanner-XQNnnpUx.js +0 -2
- package/dist/CTABanner-XQNnnpUx.js.map +0 -1
- package/dist/CodeSample-Cp42Adjc.js +0 -2
- package/dist/CodeSample-Cp42Adjc.js.map +0 -1
- package/dist/CodeSample-DxPp80ID.js +0 -2
- package/dist/CodeSample-DxPp80ID.js.map +0 -1
- package/dist/HomeView-BN9mZXh9.js +0 -2
- package/dist/HomeView-BN9mZXh9.js.map +0 -1
- package/dist/HomeView-BVaaV0uE.js +0 -2
- package/dist/HomeView-BVaaV0uE.js.map +0 -1
- package/dist/UnderlineNav-Bs7Ot9Ch.js +0 -2
- package/dist/UnderlineNav-Bs7Ot9Ch.js.map +0 -1
- package/dist/UnderlineNav-C2aEVraN.js +0 -2
- package/dist/UnderlineNav-C2aEVraN.js.map +0 -1
- package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js +0 -2
- package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js.map +0 -1
- package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js +0 -2
- package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js.map +0 -1
- package/dist/index-BVUz77Tm.js +0 -2
- package/dist/index-BVUz77Tm.js.map +0 -1
- package/dist/index-jxd3nv2J.js +0 -2
- package/dist/index-jxd3nv2J.js.map +0 -1
- package/dist/tslib.es6-DDIOdJiV.js +0 -2
- package/dist/tslib.es6-DUrRPhZd.js +0 -2
- package/src/content/Anchor/Anchor.tsx +0 -63
- package/src/content/Anchor/index.tsx +0 -3
- package/src/content/Content/Content.tsx +0 -21
- package/src/content/Content/index.tsx +0 -3
- package/src/content/Content.tsx +0 -180
- package/src/content/Subtitle/Subtitle.tsx +0 -21
- package/src/content/Subtitle/index.tsx +0 -3
- package/src/layouts/Layout.styles.tsx +0 -151
- package/src/layouts/Layout.tsx +0 -121
- package/src/ui/Loader/Loader.styles.tsx +0 -52
- package/src/ui/Loader/Loader.tsx +0 -26
- package/src/ui/index.ts +0 -1
- package/src/writer/Icon/index.tsx +0 -355
- package/src/writer/Table/TableV2.styles.tsx +0 -117
- package/src/writer/Table/TableV2.tsx +0 -83
package/src/coder/Code/Code.tsx
CHANGED
|
@@ -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 {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
44
|
-
return <
|
|
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
|
-
</
|
|
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 <
|
|
76
|
+
return <xyd-code-bg
|
|
77
|
+
data-annotated={String(!!props.annotation)}
|
|
78
|
+
className={`${cn.BgHost}`}
|
|
79
|
+
>
|
|
55
80
|
{props.children}
|
|
56
|
-
</
|
|
81
|
+
</xyd-code-bg>
|
|
57
82
|
}
|
|
58
83
|
|
|
59
84
|
Code.Pre = function CodePre(props: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
4
|
-
import {Loader} from "../../
|
|
3
|
+
import * as cn from "./Code.styles";
|
|
4
|
+
import {Loader} from "../../kit";
|
|
5
5
|
|
|
6
6
|
export function CodeLoader() {
|
|
7
|
-
return <
|
|
7
|
+
return <xyd-code-loader className={cn.CodeHost}>
|
|
8
8
|
<Loader/>
|
|
9
|
-
</
|
|
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
|
|
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) {
|
package/src/coder/Code/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {css} from "@linaria/core";
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
|
26
|
-
|
|
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 <
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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) =>
|
|
52
|
-
{
|
|
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.
|
|
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
|
|