@traefik-labs/faency 12.0.12 → 12.2.0
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/dist/components/AriaTable/AriaTable.cjs.map +1 -1
- package/dist/components/AriaTable/AriaTable.js.map +1 -1
- package/dist/components/Avatar/Avatar.vanilla.css.cjs +3 -3
- package/dist/components/Avatar/Avatar.vanilla.css.js +1 -1
- package/dist/components/Badge/Badge.vanilla.css.cjs +3 -3
- package/dist/components/Badge/Badge.vanilla.css.js +1 -1
- package/dist/components/Blockquote/Blockquote.vanilla.css.cjs +2 -2
- package/dist/components/Blockquote/Blockquote.vanilla.css.js +1 -1
- package/dist/components/Bubble/Bubble.vanilla.css.cjs +2 -2
- package/dist/components/Bubble/Bubble.vanilla.css.js +1 -1
- package/dist/components/Button/Button.cjs +2 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.js +2 -1
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Button/Button.vanilla.css.cjs +2 -2
- package/dist/components/Button/Button.vanilla.css.js +1 -1
- package/dist/components/Card/Card.vanilla.css.cjs +3 -3
- package/dist/components/Card/Card.vanilla.css.js +1 -1
- package/dist/components/CodeBlock/CodeBlock.cjs +168 -0
- package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.js +168 -0
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.themes.cjs +18 -0
- package/dist/components/CodeBlock/CodeBlock.themes.cjs.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.themes.js +19 -0
- package/dist/components/CodeBlock/CodeBlock.themes.js.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.cjs +158 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.cjs.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.cjs +20 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.cjs.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.js +20 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.js.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.js +158 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.js.map +1 -0
- package/dist/components/Container/Container.vanilla.css.cjs +2 -2
- package/dist/components/Container/Container.vanilla.css.js +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.cjs +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.js +1 -1
- package/dist/components/Elevation/Elevation.vanilla.css.cjs +2 -2
- package/dist/components/Elevation/Elevation.vanilla.css.js +1 -1
- package/dist/components/FaencyProvider.cjs +2 -1
- package/dist/components/FaencyProvider.cjs.map +1 -1
- package/dist/components/FaencyProvider.js +2 -1
- package/dist/components/FaencyProvider.js.map +1 -1
- package/dist/components/Flex/Flex.vanilla.css.cjs +2 -2
- package/dist/components/Flex/Flex.vanilla.css.js +1 -1
- package/dist/components/Grid/Grid.vanilla.css.cjs +2 -2
- package/dist/components/Grid/Grid.vanilla.css.js +1 -1
- package/dist/components/IconButton/IconButton.vanilla.css.cjs +2 -2
- package/dist/components/IconButton/IconButton.vanilla.css.js +1 -1
- package/dist/components/Input/Input.vanilla.css.cjs +4 -4
- package/dist/components/Input/Input.vanilla.css.js +1 -1
- package/dist/components/Label/Label.vanilla.css.cjs +2 -2
- package/dist/components/Label/Label.vanilla.css.js +1 -1
- package/dist/components/List/List.cjs +36 -7
- package/dist/components/List/List.cjs.map +1 -1
- package/dist/components/List/List.js +36 -7
- package/dist/components/List/List.js.map +1 -1
- package/dist/components/Paragraph/Paragraph.vanilla.css.cjs +2 -2
- package/dist/components/Paragraph/Paragraph.vanilla.css.js +1 -1
- package/dist/components/Skeleton/Skeleton.vanilla.css.cjs +2 -2
- package/dist/components/Skeleton/Skeleton.vanilla.css.js +1 -1
- package/dist/components/Textarea/Textarea.vanilla.css.cjs +3 -3
- package/dist/components/Textarea/Textarea.vanilla.css.js +1 -1
- package/dist/components/colorSchemeContext.cjs +45 -0
- package/dist/components/colorSchemeContext.cjs.map +1 -0
- package/dist/components/colorSchemeContext.js +45 -0
- package/dist/components/colorSchemeContext.js.map +1 -0
- package/dist/faency.css +1940 -1886
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +486 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/stitches.config.cjs +4 -0
- package/dist/stitches.config.cjs.map +1 -1
- package/dist/stitches.config.js +19 -15
- package/dist/stitches.config.js.map +1 -1
- package/dist/styles/themes.css.cjs +1 -0
- package/dist/styles/themes.css.cjs.map +1 -1
- package/dist/styles/themes.css.js +1 -0
- package/dist/styles/themes.css.js.map +1 -1
- package/package.json +4 -1
- package/dist/node_modules/@vanilla-extract/recipes/dist/createRuntimeFn-62c9670f.esm.cjs +0 -109
- package/dist/node_modules/@vanilla-extract/recipes/dist/createRuntimeFn-62c9670f.esm.cjs.map +0 -1
- package/dist/node_modules/@vanilla-extract/recipes/dist/createRuntimeFn-62c9670f.esm.js +0 -109
- package/dist/node_modules/@vanilla-extract/recipes/dist/createRuntimeFn-62c9670f.esm.js.map +0 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactIcons = require("@radix-ui/react-icons");
|
|
5
|
+
const prismReactRenderer = require("prism-react-renderer");
|
|
6
|
+
const React = require("react");
|
|
7
|
+
const stitches_config = require("../../stitches.config.cjs");
|
|
8
|
+
const colorSchemeContext = require("../colorSchemeContext.cjs");
|
|
9
|
+
const Box = require("../Box/Box.cjs");
|
|
10
|
+
const Button = require("../Button/Button.cjs");
|
|
11
|
+
const AccessibleIcon = require("../AccessibleIcon/AccessibleIcon.cjs");
|
|
12
|
+
const Pre = stitches_config.styled("pre", {
|
|
13
|
+
m: 0,
|
|
14
|
+
borderRadius: "$2",
|
|
15
|
+
overflow: "auto",
|
|
16
|
+
border: "1px solid $colors$deepBlue3",
|
|
17
|
+
fontSize: "$2",
|
|
18
|
+
lineHeight: 1.6,
|
|
19
|
+
variants: {
|
|
20
|
+
noBorder: {
|
|
21
|
+
true: { border: "none" }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const CopyButtonWrapper = stitches_config.styled("div", {
|
|
26
|
+
position: "absolute",
|
|
27
|
+
zIndex: 1,
|
|
28
|
+
variants: {
|
|
29
|
+
position: {
|
|
30
|
+
top: { top: "$2", right: "$3" },
|
|
31
|
+
topLeft: { top: "$2", left: "$3" },
|
|
32
|
+
bottomRight: { bottom: "$2", right: "$3" },
|
|
33
|
+
bottomLeft: { bottom: "$2", left: "$3" }
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
defaultVariants: {
|
|
37
|
+
position: "top"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const CodeBlock = React.forwardRef(
|
|
41
|
+
({
|
|
42
|
+
lang = "text",
|
|
43
|
+
code,
|
|
44
|
+
copyable = false,
|
|
45
|
+
copyText,
|
|
46
|
+
copiedText,
|
|
47
|
+
copyButtonAlign = "top right",
|
|
48
|
+
onCopy,
|
|
49
|
+
noBorder,
|
|
50
|
+
wrapText = false,
|
|
51
|
+
colorScheme,
|
|
52
|
+
maxHeight = 424,
|
|
53
|
+
css,
|
|
54
|
+
style,
|
|
55
|
+
className,
|
|
56
|
+
...props
|
|
57
|
+
}, ref) => {
|
|
58
|
+
const systemScheme = colorSchemeContext.useColorScheme();
|
|
59
|
+
const resolvedScheme = colorScheme ?? systemScheme;
|
|
60
|
+
const prismTheme = resolvedScheme === "dark" ? prismReactRenderer.themes.nightOwl : prismReactRenderer.themes.nightOwlLight;
|
|
61
|
+
const isBottom = copyButtonAlign.includes("bottom");
|
|
62
|
+
const isLeft = copyButtonAlign.includes("left");
|
|
63
|
+
const buttonPosition = isBottom ? isLeft ? "bottomLeft" : "bottomRight" : isLeft ? "topLeft" : "top";
|
|
64
|
+
const [copied, setCopied] = React.useState(false);
|
|
65
|
+
const preRef = React.useRef(
|
|
66
|
+
null
|
|
67
|
+
);
|
|
68
|
+
const buttonWrapperRef = React.useRef(null);
|
|
69
|
+
const setPreRef = React.useCallback(
|
|
70
|
+
(node) => {
|
|
71
|
+
preRef.current = node;
|
|
72
|
+
if (typeof ref === "function") ref(node);
|
|
73
|
+
else if (ref) ref.current = node;
|
|
74
|
+
},
|
|
75
|
+
[ref]
|
|
76
|
+
);
|
|
77
|
+
React.useLayoutEffect(() => {
|
|
78
|
+
if (!copyable) return;
|
|
79
|
+
const pre = preRef.current;
|
|
80
|
+
const wrapper = buttonWrapperRef.current;
|
|
81
|
+
if (!pre || !wrapper) return;
|
|
82
|
+
const isBottomAlign = isBottom;
|
|
83
|
+
const borderH = noBorder ? 0 : 2;
|
|
84
|
+
const update = () => {
|
|
85
|
+
if (!isLeft) {
|
|
86
|
+
const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);
|
|
87
|
+
wrapper.style.right = `${16 + vScrollbar}px`;
|
|
88
|
+
}
|
|
89
|
+
if (isBottomAlign) {
|
|
90
|
+
const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);
|
|
91
|
+
wrapper.style.bottom = `${8 + hScrollbar}px`;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
update();
|
|
95
|
+
const observer = new ResizeObserver(update);
|
|
96
|
+
observer.observe(pre);
|
|
97
|
+
return () => observer.disconnect();
|
|
98
|
+
}, [copyable, isBottom, isLeft, noBorder]);
|
|
99
|
+
const handleCopy = async () => {
|
|
100
|
+
try {
|
|
101
|
+
await navigator.clipboard.writeText(code);
|
|
102
|
+
setCopied(true);
|
|
103
|
+
onCopy?.();
|
|
104
|
+
setTimeout(() => setCopied(false), 1500);
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const copyButton = copyable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
109
|
+
Button.Button,
|
|
110
|
+
{
|
|
111
|
+
variant: "secondary",
|
|
112
|
+
ghost: true,
|
|
113
|
+
size: "small",
|
|
114
|
+
type: "button",
|
|
115
|
+
onClick: handleCopy,
|
|
116
|
+
css: {
|
|
117
|
+
color: "$hiContrast",
|
|
118
|
+
gap: "$1",
|
|
119
|
+
backgroundColor: "$codeBlockCopyButtonBg",
|
|
120
|
+
height: "32px"
|
|
121
|
+
},
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsx(AccessibleIcon.AccessibleIcon, { label: copied ? "Copied" : "Copy", children: copied ? /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CheckIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CopyIcon, {}) }),
|
|
124
|
+
copied ? copiedText : copyText
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
) : null;
|
|
128
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
129
|
+
prismReactRenderer.Highlight,
|
|
130
|
+
{
|
|
131
|
+
theme: prismTheme,
|
|
132
|
+
code,
|
|
133
|
+
language: prismReactRenderer.Prism.languages[lang] != null ? lang : "text",
|
|
134
|
+
children: ({
|
|
135
|
+
className: highlightClass,
|
|
136
|
+
style: highlightStyle,
|
|
137
|
+
tokens,
|
|
138
|
+
getLineProps,
|
|
139
|
+
getTokenProps
|
|
140
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs(Box.Box, { css: { position: "relative", ...css }, children: [
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
+
Pre,
|
|
143
|
+
{
|
|
144
|
+
ref: setPreRef,
|
|
145
|
+
className: [highlightClass, className].filter(Boolean).join(" "),
|
|
146
|
+
style: { maxHeight, ...highlightStyle, backgroundColor: "inherit", ...style },
|
|
147
|
+
noBorder,
|
|
148
|
+
...props,
|
|
149
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Box.Box, { css: { p: "$4", ...copyable && isBottom ? { pb: "$7" } : {} }, children: tokens.map((line, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
...getLineProps({ line }),
|
|
153
|
+
style: wrapText ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : void 0,
|
|
154
|
+
children: line.map((token, key) => /* @__PURE__ */ jsxRuntime.jsx("span", { ...getTokenProps({ token }) }, key))
|
|
155
|
+
},
|
|
156
|
+
i
|
|
157
|
+
)) })
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
copyButton && /* @__PURE__ */ jsxRuntime.jsx(CopyButtonWrapper, { ref: buttonWrapperRef, position: buttonPosition, children: copyButton })
|
|
161
|
+
] })
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
CodeBlock.displayName = "CodeBlock";
|
|
167
|
+
exports.CodeBlock = CodeBlock;
|
|
168
|
+
//# sourceMappingURL=CodeBlock.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.cjs","sources":["../../../components/CodeBlock/CodeBlock.tsx"],"sourcesContent":["import './prism-extend';\n\nimport { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { Highlight, Language, Prism, themes } from 'prism-react-renderer';\nimport React, {\n ComponentProps,\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { CSS, styled } from '../../stitches.config';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { useColorScheme } from '../colorSchemeContext';\nimport type { CodeBlockCopyButtonAlign, CodeBlockLanguage } from './index';\n\nconst Pre = styled('pre', {\n m: 0,\n borderRadius: '$2',\n overflow: 'auto',\n border: '1px solid $colors$deepBlue3',\n fontSize: '$2',\n lineHeight: 1.6,\n\n variants: {\n noBorder: {\n true: { border: 'none' },\n },\n },\n});\n\nconst CopyButtonWrapper = styled('div', {\n position: 'absolute',\n zIndex: 1,\n variants: {\n position: {\n top: { top: '$2', right: '$3' },\n topLeft: { top: '$2', left: '$3' },\n bottomRight: { bottom: '$2', right: '$3' },\n bottomLeft: { bottom: '$2', left: '$3' },\n },\n },\n\n defaultVariants: {\n position: 'top',\n },\n});\n\nexport type CodeBlockProps = {\n lang?: CodeBlockLanguage;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: CodeBlockCopyButtonAlign;\n onCopy?: () => void;\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n css?: CSS;\n} & Omit<ComponentProps<typeof Pre>, 'css'>;\n\nexport const CodeBlock = forwardRef<HTMLPreElement, CodeBlockProps>(\n (\n {\n lang = 'text',\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top right',\n onCopy,\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const systemScheme = useColorScheme();\n const resolvedScheme = colorScheme ?? systemScheme;\n const prismTheme = resolvedScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const isBottom = copyButtonAlign.includes('bottom');\n const isLeft = copyButtonAlign.includes('left');\n const buttonPosition = isBottom\n ? isLeft\n ? 'bottomLeft'\n : 'bottomRight'\n : isLeft\n ? 'topLeft'\n : 'top';\n\n const [copied, setCopied] = useState(false);\n\n const preRef = useRef<HTMLPreElement | null>(\n null,\n ) as React.MutableRefObject<HTMLPreElement | null>;\n const buttonWrapperRef = useRef<HTMLDivElement>(null);\n\n const setPreRef = useCallback(\n (node: HTMLPreElement | null) => {\n preRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLPreElement | null>).current = node;\n },\n [ref],\n );\n\n useLayoutEffect(() => {\n if (!copyable) return;\n const pre = preRef.current;\n const wrapper = buttonWrapperRef.current;\n if (!pre || !wrapper) return;\n\n const isBottomAlign = isBottom;\n const borderH = noBorder ? 0 : 2;\n\n const update = () => {\n if (!isLeft) {\n const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);\n wrapper.style.right = `${16 + vScrollbar}px`;\n }\n if (isBottomAlign) {\n const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);\n wrapper.style.bottom = `${8 + hScrollbar}px`;\n }\n };\n\n update();\n const observer = new ResizeObserver(update);\n observer.observe(pre);\n return () => observer.disconnect();\n }, [copyable, isBottom, isLeft, noBorder]);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n onCopy?.();\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n const copyButton = copyable ? (\n <Button\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{\n color: '$hiContrast',\n gap: '$1',\n backgroundColor: '$codeBlockCopyButtonBg',\n height: '32px',\n }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </Button>\n ) : null;\n\n return (\n <Highlight\n theme={prismTheme}\n code={code}\n language={(Prism.languages[lang] != null ? lang : 'text') as Language}\n >\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <Box css={{ position: 'relative', ...css }}>\n <Pre\n ref={setPreRef}\n className={[highlightClass, className].filter(Boolean).join(' ')}\n style={{ maxHeight, ...highlightStyle, backgroundColor: 'inherit', ...style }}\n noBorder={noBorder}\n {...props}\n >\n <Box css={{ p: '$4', ...(copyable && isBottom ? { pb: '$7' } : {}) }}>\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={\n wrapText ? { whiteSpace: 'pre-wrap', wordBreak: 'break-all' } : undefined\n }\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </Box>\n </Pre>\n {copyButton && (\n <CopyButtonWrapper ref={buttonWrapperRef} position={buttonPosition}>\n {copyButton}\n </CopyButtonWrapper>\n )}\n </Box>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlock.displayName = 'CodeBlock';\n"],"names":["styled","forwardRef","useColorScheme","themes","useState","useRef","useCallback","useLayoutEffect","jsxs","Button","jsx","AccessibleIcon","CheckIcon","CopyIcon","Highlight","Prism","Box"],"mappings":";;;;;;;;;;;AAoBA,MAAM,MAAMA,gBAAAA,OAAO,OAAO;AAAA,EACxB,GAAG;AAAA,EACH,cAAc;AAAA,EACd,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,UAAU;AAAA,MACR,MAAM,EAAE,QAAQ,OAAA;AAAA,IAAO;AAAA,EACzB;AAEJ,CAAC;AAED,MAAM,oBAAoBA,gBAAAA,OAAO,OAAO;AAAA,EACtC,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,UAAU;AAAA,IACR,UAAU;AAAA,MACR,KAAK,EAAE,KAAK,MAAM,OAAO,KAAA;AAAA,MACzB,SAAS,EAAE,KAAK,MAAM,MAAM,KAAA;AAAA,MAC5B,aAAa,EAAE,QAAQ,MAAM,OAAO,KAAA;AAAA,MACpC,YAAY,EAAE,QAAQ,MAAM,MAAM,KAAA;AAAA,IAAK;AAAA,EACzC;AAAA,EAGF,iBAAiB;AAAA,IACf,UAAU;AAAA,EAAA;AAEd,CAAC;AAiBM,MAAM,YAAYC,MAAAA;AAAAA,EACvB,CACE;AAAA,IACE,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IAC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cACC,KAAK;AAAA,cACL,WAAW,CAAC,gBAAgB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,cAC/D,OAAO,EAAE,WAAW,GAAG,gBAAgB,iBAAiB,WAAW,GAAG,MAAA;AAAA,cACtE;AAAA,cACC,GAAG;AAAA,cAEJ,UAAAA,2BAAAA,IAACM,IAAAA,OAAI,KAAK,EAAE,GAAG,MAAM,GAAI,YAAY,WAAW,EAAE,IAAI,KAAA,IAAS,CAAA,EAAC,GAC7D,iBAAO,IAAI,CAAC,MAAM,MACjBN,2BAAAA;AAAAA,gBAAC;AAAA,gBAAA;AAAA,kBAEE,GAAG,aAAa,EAAE,MAAM;AAAA,kBACzB,OACE,WAAW,EAAE,YAAY,YAAY,WAAW,gBAAgB;AAAA,kBAGjE,UAAA,KAAK,IAAI,CAAC,OAAO,QAChBA,2BAAAA,IAAC,QAAA,EAAgB,GAAG,cAAc,EAAE,MAAA,CAAO,EAAA,GAAhC,GAAmC,CAC/C;AAAA,gBAAA;AAAA,gBARI;AAAA,cAAA,CAUR,EAAA,CACH;AAAA,YAAA;AAAA,UAAA;AAAA,UAED,cACCA,2BAAAA,IAAC,mBAAA,EAAkB,KAAK,kBAAkB,UAAU,gBACjD,UAAA,WAAA,CACH;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,UAAU,cAAc;;"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CheckIcon, CopyIcon } from "@radix-ui/react-icons";
|
|
3
|
+
import { themes, Highlight, Prism } from "prism-react-renderer";
|
|
4
|
+
import { forwardRef, useState, useRef, useCallback, useLayoutEffect } from "react";
|
|
5
|
+
import { styled } from "../../stitches.config.js";
|
|
6
|
+
import { useColorScheme } from "../colorSchemeContext.js";
|
|
7
|
+
import { Box } from "../Box/Box.js";
|
|
8
|
+
import { Button } from "../Button/Button.js";
|
|
9
|
+
import { AccessibleIcon } from "../AccessibleIcon/AccessibleIcon.js";
|
|
10
|
+
const Pre = styled("pre", {
|
|
11
|
+
m: 0,
|
|
12
|
+
borderRadius: "$2",
|
|
13
|
+
overflow: "auto",
|
|
14
|
+
border: "1px solid $colors$deepBlue3",
|
|
15
|
+
fontSize: "$2",
|
|
16
|
+
lineHeight: 1.6,
|
|
17
|
+
variants: {
|
|
18
|
+
noBorder: {
|
|
19
|
+
true: { border: "none" }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const CopyButtonWrapper = styled("div", {
|
|
24
|
+
position: "absolute",
|
|
25
|
+
zIndex: 1,
|
|
26
|
+
variants: {
|
|
27
|
+
position: {
|
|
28
|
+
top: { top: "$2", right: "$3" },
|
|
29
|
+
topLeft: { top: "$2", left: "$3" },
|
|
30
|
+
bottomRight: { bottom: "$2", right: "$3" },
|
|
31
|
+
bottomLeft: { bottom: "$2", left: "$3" }
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
position: "top"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const CodeBlock = forwardRef(
|
|
39
|
+
({
|
|
40
|
+
lang = "text",
|
|
41
|
+
code,
|
|
42
|
+
copyable = false,
|
|
43
|
+
copyText,
|
|
44
|
+
copiedText,
|
|
45
|
+
copyButtonAlign = "top right",
|
|
46
|
+
onCopy,
|
|
47
|
+
noBorder,
|
|
48
|
+
wrapText = false,
|
|
49
|
+
colorScheme,
|
|
50
|
+
maxHeight = 424,
|
|
51
|
+
css,
|
|
52
|
+
style,
|
|
53
|
+
className,
|
|
54
|
+
...props
|
|
55
|
+
}, ref) => {
|
|
56
|
+
const systemScheme = useColorScheme();
|
|
57
|
+
const resolvedScheme = colorScheme ?? systemScheme;
|
|
58
|
+
const prismTheme = resolvedScheme === "dark" ? themes.nightOwl : themes.nightOwlLight;
|
|
59
|
+
const isBottom = copyButtonAlign.includes("bottom");
|
|
60
|
+
const isLeft = copyButtonAlign.includes("left");
|
|
61
|
+
const buttonPosition = isBottom ? isLeft ? "bottomLeft" : "bottomRight" : isLeft ? "topLeft" : "top";
|
|
62
|
+
const [copied, setCopied] = useState(false);
|
|
63
|
+
const preRef = useRef(
|
|
64
|
+
null
|
|
65
|
+
);
|
|
66
|
+
const buttonWrapperRef = useRef(null);
|
|
67
|
+
const setPreRef = useCallback(
|
|
68
|
+
(node) => {
|
|
69
|
+
preRef.current = node;
|
|
70
|
+
if (typeof ref === "function") ref(node);
|
|
71
|
+
else if (ref) ref.current = node;
|
|
72
|
+
},
|
|
73
|
+
[ref]
|
|
74
|
+
);
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (!copyable) return;
|
|
77
|
+
const pre = preRef.current;
|
|
78
|
+
const wrapper = buttonWrapperRef.current;
|
|
79
|
+
if (!pre || !wrapper) return;
|
|
80
|
+
const isBottomAlign = isBottom;
|
|
81
|
+
const borderH = noBorder ? 0 : 2;
|
|
82
|
+
const update = () => {
|
|
83
|
+
if (!isLeft) {
|
|
84
|
+
const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);
|
|
85
|
+
wrapper.style.right = `${16 + vScrollbar}px`;
|
|
86
|
+
}
|
|
87
|
+
if (isBottomAlign) {
|
|
88
|
+
const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);
|
|
89
|
+
wrapper.style.bottom = `${8 + hScrollbar}px`;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
update();
|
|
93
|
+
const observer = new ResizeObserver(update);
|
|
94
|
+
observer.observe(pre);
|
|
95
|
+
return () => observer.disconnect();
|
|
96
|
+
}, [copyable, isBottom, isLeft, noBorder]);
|
|
97
|
+
const handleCopy = async () => {
|
|
98
|
+
try {
|
|
99
|
+
await navigator.clipboard.writeText(code);
|
|
100
|
+
setCopied(true);
|
|
101
|
+
onCopy?.();
|
|
102
|
+
setTimeout(() => setCopied(false), 1500);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const copyButton = copyable ? /* @__PURE__ */ jsxs(
|
|
107
|
+
Button,
|
|
108
|
+
{
|
|
109
|
+
variant: "secondary",
|
|
110
|
+
ghost: true,
|
|
111
|
+
size: "small",
|
|
112
|
+
type: "button",
|
|
113
|
+
onClick: handleCopy,
|
|
114
|
+
css: {
|
|
115
|
+
color: "$hiContrast",
|
|
116
|
+
gap: "$1",
|
|
117
|
+
backgroundColor: "$codeBlockCopyButtonBg",
|
|
118
|
+
height: "32px"
|
|
119
|
+
},
|
|
120
|
+
children: [
|
|
121
|
+
/* @__PURE__ */ jsx(AccessibleIcon, { label: copied ? "Copied" : "Copy", children: copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}) }),
|
|
122
|
+
copied ? copiedText : copyText
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
) : null;
|
|
126
|
+
return /* @__PURE__ */ jsx(
|
|
127
|
+
Highlight,
|
|
128
|
+
{
|
|
129
|
+
theme: prismTheme,
|
|
130
|
+
code,
|
|
131
|
+
language: Prism.languages[lang] != null ? lang : "text",
|
|
132
|
+
children: ({
|
|
133
|
+
className: highlightClass,
|
|
134
|
+
style: highlightStyle,
|
|
135
|
+
tokens,
|
|
136
|
+
getLineProps,
|
|
137
|
+
getTokenProps
|
|
138
|
+
}) => /* @__PURE__ */ jsxs(Box, { css: { position: "relative", ...css }, children: [
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
Pre,
|
|
141
|
+
{
|
|
142
|
+
ref: setPreRef,
|
|
143
|
+
className: [highlightClass, className].filter(Boolean).join(" "),
|
|
144
|
+
style: { maxHeight, ...highlightStyle, backgroundColor: "inherit", ...style },
|
|
145
|
+
noBorder,
|
|
146
|
+
...props,
|
|
147
|
+
children: /* @__PURE__ */ jsx(Box, { css: { p: "$4", ...copyable && isBottom ? { pb: "$7" } : {} }, children: tokens.map((line, i) => /* @__PURE__ */ jsx(
|
|
148
|
+
"div",
|
|
149
|
+
{
|
|
150
|
+
...getLineProps({ line }),
|
|
151
|
+
style: wrapText ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : void 0,
|
|
152
|
+
children: line.map((token, key) => /* @__PURE__ */ jsx("span", { ...getTokenProps({ token }) }, key))
|
|
153
|
+
},
|
|
154
|
+
i
|
|
155
|
+
)) })
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
copyButton && /* @__PURE__ */ jsx(CopyButtonWrapper, { ref: buttonWrapperRef, position: buttonPosition, children: copyButton })
|
|
159
|
+
] })
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
CodeBlock.displayName = "CodeBlock";
|
|
165
|
+
export {
|
|
166
|
+
CodeBlock
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.js","sources":["../../../components/CodeBlock/CodeBlock.tsx"],"sourcesContent":["import './prism-extend';\n\nimport { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { Highlight, Language, Prism, themes } from 'prism-react-renderer';\nimport React, {\n ComponentProps,\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { CSS, styled } from '../../stitches.config';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { useColorScheme } from '../colorSchemeContext';\nimport type { CodeBlockCopyButtonAlign, CodeBlockLanguage } from './index';\n\nconst Pre = styled('pre', {\n m: 0,\n borderRadius: '$2',\n overflow: 'auto',\n border: '1px solid $colors$deepBlue3',\n fontSize: '$2',\n lineHeight: 1.6,\n\n variants: {\n noBorder: {\n true: { border: 'none' },\n },\n },\n});\n\nconst CopyButtonWrapper = styled('div', {\n position: 'absolute',\n zIndex: 1,\n variants: {\n position: {\n top: { top: '$2', right: '$3' },\n topLeft: { top: '$2', left: '$3' },\n bottomRight: { bottom: '$2', right: '$3' },\n bottomLeft: { bottom: '$2', left: '$3' },\n },\n },\n\n defaultVariants: {\n position: 'top',\n },\n});\n\nexport type CodeBlockProps = {\n lang?: CodeBlockLanguage;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: CodeBlockCopyButtonAlign;\n onCopy?: () => void;\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n css?: CSS;\n} & Omit<ComponentProps<typeof Pre>, 'css'>;\n\nexport const CodeBlock = forwardRef<HTMLPreElement, CodeBlockProps>(\n (\n {\n lang = 'text',\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top right',\n onCopy,\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const systemScheme = useColorScheme();\n const resolvedScheme = colorScheme ?? systemScheme;\n const prismTheme = resolvedScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const isBottom = copyButtonAlign.includes('bottom');\n const isLeft = copyButtonAlign.includes('left');\n const buttonPosition = isBottom\n ? isLeft\n ? 'bottomLeft'\n : 'bottomRight'\n : isLeft\n ? 'topLeft'\n : 'top';\n\n const [copied, setCopied] = useState(false);\n\n const preRef = useRef<HTMLPreElement | null>(\n null,\n ) as React.MutableRefObject<HTMLPreElement | null>;\n const buttonWrapperRef = useRef<HTMLDivElement>(null);\n\n const setPreRef = useCallback(\n (node: HTMLPreElement | null) => {\n preRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLPreElement | null>).current = node;\n },\n [ref],\n );\n\n useLayoutEffect(() => {\n if (!copyable) return;\n const pre = preRef.current;\n const wrapper = buttonWrapperRef.current;\n if (!pre || !wrapper) return;\n\n const isBottomAlign = isBottom;\n const borderH = noBorder ? 0 : 2;\n\n const update = () => {\n if (!isLeft) {\n const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);\n wrapper.style.right = `${16 + vScrollbar}px`;\n }\n if (isBottomAlign) {\n const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);\n wrapper.style.bottom = `${8 + hScrollbar}px`;\n }\n };\n\n update();\n const observer = new ResizeObserver(update);\n observer.observe(pre);\n return () => observer.disconnect();\n }, [copyable, isBottom, isLeft, noBorder]);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n onCopy?.();\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n const copyButton = copyable ? (\n <Button\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{\n color: '$hiContrast',\n gap: '$1',\n backgroundColor: '$codeBlockCopyButtonBg',\n height: '32px',\n }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </Button>\n ) : null;\n\n return (\n <Highlight\n theme={prismTheme}\n code={code}\n language={(Prism.languages[lang] != null ? lang : 'text') as Language}\n >\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <Box css={{ position: 'relative', ...css }}>\n <Pre\n ref={setPreRef}\n className={[highlightClass, className].filter(Boolean).join(' ')}\n style={{ maxHeight, ...highlightStyle, backgroundColor: 'inherit', ...style }}\n noBorder={noBorder}\n {...props}\n >\n <Box css={{ p: '$4', ...(copyable && isBottom ? { pb: '$7' } : {}) }}>\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={\n wrapText ? { whiteSpace: 'pre-wrap', wordBreak: 'break-all' } : undefined\n }\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </Box>\n </Pre>\n {copyButton && (\n <CopyButtonWrapper ref={buttonWrapperRef} position={buttonPosition}>\n {copyButton}\n </CopyButtonWrapper>\n )}\n </Box>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlock.displayName = 'CodeBlock';\n"],"names":[],"mappings":";;;;;;;;;AAoBA,MAAM,MAAM,OAAO,OAAO;AAAA,EACxB,GAAG;AAAA,EACH,cAAc;AAAA,EACd,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,UAAU;AAAA,MACR,MAAM,EAAE,QAAQ,OAAA;AAAA,IAAO;AAAA,EACzB;AAEJ,CAAC;AAED,MAAM,oBAAoB,OAAO,OAAO;AAAA,EACtC,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,UAAU;AAAA,IACR,UAAU;AAAA,MACR,KAAK,EAAE,KAAK,MAAM,OAAO,KAAA;AAAA,MACzB,SAAS,EAAE,KAAK,MAAM,MAAM,KAAA;AAAA,MAC5B,aAAa,EAAE,QAAQ,MAAM,OAAO,KAAA;AAAA,MACpC,YAAY,EAAE,QAAQ,MAAM,MAAM,KAAA;AAAA,IAAK;AAAA,EACzC;AAAA,EAGF,iBAAiB;AAAA,IACf,UAAU;AAAA,EAAA;AAEd,CAAC;AAiBM,MAAM,YAAY;AAAA,EACvB,CACE;AAAA,IACE,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,eAAe,eAAA;AACrB,UAAM,iBAAiB,eAAe;AACtC,UAAM,aAAa,mBAAmB,SAAS,OAAO,WAAW,OAAO;AAExE,UAAM,WAAW,gBAAgB,SAAS,QAAQ;AAClD,UAAM,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Y,WAAW,gBAAgB;AAAA,kBAGjE,UAAA,KAAK,IAAI,CAAC,OAAO,QAChB,oBAAC,QAAA,EAAgB,GAAG,cAAc,EAAE,MAAA,CAAO,EAAA,GAAhC,GAAmC,CAC/C;AAAA,gBAAA;AAAA,gBARI;AAAA,cAAA,CAUR,EAAA,CACH;AAAA,YAAA;AAAA,UAAA;AAAA,UAED,cACC,oBAAC,mBAAA,EAAkB,KAAK,kBAAkB,UAAU,gBACjD,UAAA,WAAA,CACH;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,UAAU,cAAc;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
exports.Theme = void 0;
|
|
4
|
+
((Theme2) => {
|
|
5
|
+
function getLight() {
|
|
6
|
+
return {
|
|
7
|
+
codeBlockCopyButtonBg: "transparent"
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
Theme2.getLight = getLight;
|
|
11
|
+
function getDark() {
|
|
12
|
+
return {
|
|
13
|
+
codeBlockCopyButtonBg: "transparent"
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Theme2.getDark = getDark;
|
|
17
|
+
})(exports.Theme || (exports.Theme = {}));
|
|
18
|
+
//# sourceMappingURL=CodeBlock.themes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.themes.cjs","sources":["../../../components/CodeBlock/CodeBlock.themes.ts"],"sourcesContent":["import { Property } from '@stitches/react/types/css';\n\nexport namespace Theme {\n type Colors = {\n codeBlockCopyButtonBg: Property.Color;\n };\n\n export function getLight(): Colors {\n return {\n codeBlockCopyButtonBg: 'transparent',\n };\n }\n\n export function getDark(): Colors {\n return {\n codeBlockCopyButtonBg: 'transparent',\n };\n }\n}\n"],"names":["Theme"],"mappings":";;AAEiBA,QAAAA,QAAAA;AAAAA,CAAV,CAAUA,WAAV;AAKE,WAAS,WAAmB;AACjC,WAAO;AAAA,MACL,uBAAuB;AAAA,IAAA;AAAA,EAE3B;AAJOA,SAAS,WAAA;AAMT,WAAS,UAAkB;AAChC,WAAO;AAAA,MACL,uBAAuB;AAAA,IAAA;AAAA,EAE3B;AAJOA,SAAS,UAAA;AAAA,GAXDA,QAAAA,UAAAA,gBAAA,CAAA,EAAA;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var Theme;
|
|
2
|
+
((Theme2) => {
|
|
3
|
+
function getLight() {
|
|
4
|
+
return {
|
|
5
|
+
codeBlockCopyButtonBg: "transparent"
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
Theme2.getLight = getLight;
|
|
9
|
+
function getDark() {
|
|
10
|
+
return {
|
|
11
|
+
codeBlockCopyButtonBg: "transparent"
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Theme2.getDark = getDark;
|
|
15
|
+
})(Theme || (Theme = {}));
|
|
16
|
+
export {
|
|
17
|
+
Theme
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=CodeBlock.themes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.themes.js","sources":["../../../components/CodeBlock/CodeBlock.themes.ts"],"sourcesContent":["import { Property } from '@stitches/react/types/css';\n\nexport namespace Theme {\n type Colors = {\n codeBlockCopyButtonBg: Property.Color;\n };\n\n export function getLight(): Colors {\n return {\n codeBlockCopyButtonBg: 'transparent',\n };\n }\n\n export function getDark(): Colors {\n return {\n codeBlockCopyButtonBg: 'transparent',\n };\n }\n}\n"],"names":["Theme"],"mappings":"AAEO,IAAU;AAAA,CAAV,CAAUA,WAAV;AAKE,WAAS,WAAmB;AACjC,WAAO;AAAA,MACL,uBAAuB;AAAA,IAAA;AAAA,EAE3B;AAJOA,SAAS,WAAA;AAMT,WAAS,UAAkB;AAChC,WAAO;AAAA,MACL,uBAAuB;AAAA,IAAA;AAAA,EAE3B;AAJOA,SAAS,UAAA;AAAA,GAXD,UAAA,QAAA,CAAA,EAAA;"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactIcons = require("@radix-ui/react-icons");
|
|
5
|
+
const dynamic = require("@vanilla-extract/dynamic");
|
|
6
|
+
const prismReactRenderer = require("prism-react-renderer");
|
|
7
|
+
const React = require("react");
|
|
8
|
+
const cssProps = require("../../styles/cssProps.cjs");
|
|
9
|
+
const themeContext = require("../../styles/themeContext.cjs");
|
|
10
|
+
const CodeBlock_vanilla_css = require("./CodeBlock.vanilla.css.cjs");
|
|
11
|
+
const Button_vanilla = require("../Button/Button.vanilla.cjs");
|
|
12
|
+
const AccessibleIcon = require("../AccessibleIcon/AccessibleIcon.cjs");
|
|
13
|
+
const CodeBlockVanilla = React.forwardRef(
|
|
14
|
+
({
|
|
15
|
+
lang = "text",
|
|
16
|
+
code,
|
|
17
|
+
copyable = false,
|
|
18
|
+
copyText,
|
|
19
|
+
copiedText,
|
|
20
|
+
copyButtonAlign = "top right",
|
|
21
|
+
onCopy,
|
|
22
|
+
noBorder,
|
|
23
|
+
wrapText = false,
|
|
24
|
+
colorScheme,
|
|
25
|
+
maxHeight = 424,
|
|
26
|
+
css,
|
|
27
|
+
style,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}, ref) => {
|
|
31
|
+
const { colors, resolvedTheme } = themeContext.useVanillaExtractTheme();
|
|
32
|
+
const effectiveScheme = colorScheme ?? resolvedTheme;
|
|
33
|
+
const prismTheme = effectiveScheme === "dark" ? prismReactRenderer.themes.nightOwl : prismReactRenderer.themes.nightOwlLight;
|
|
34
|
+
const { style: cssStyles, vars } = cssProps.processCSSProp(css, colors);
|
|
35
|
+
const containerStyles = {
|
|
36
|
+
position: "relative",
|
|
37
|
+
...cssStyles,
|
|
38
|
+
...dynamic.assignInlineVars(vars)
|
|
39
|
+
};
|
|
40
|
+
const [copied, setCopied] = React.useState(false);
|
|
41
|
+
const preRef = React.useRef(
|
|
42
|
+
null
|
|
43
|
+
);
|
|
44
|
+
const buttonWrapperRef = React.useRef(null);
|
|
45
|
+
const setPreRef = React.useCallback(
|
|
46
|
+
(node) => {
|
|
47
|
+
preRef.current = node;
|
|
48
|
+
if (typeof ref === "function") ref(node);
|
|
49
|
+
else if (ref) ref.current = node;
|
|
50
|
+
},
|
|
51
|
+
[ref]
|
|
52
|
+
);
|
|
53
|
+
React.useLayoutEffect(() => {
|
|
54
|
+
if (!copyable) return;
|
|
55
|
+
const pre2 = preRef.current;
|
|
56
|
+
const wrapper = buttonWrapperRef.current;
|
|
57
|
+
if (!pre2 || !wrapper) return;
|
|
58
|
+
const isLeftAlign = copyButtonAlign.includes("left");
|
|
59
|
+
const isBottomAlign = copyButtonAlign.includes("bottom");
|
|
60
|
+
const borderH = noBorder ? 0 : 2;
|
|
61
|
+
const update = () => {
|
|
62
|
+
if (!isLeftAlign) {
|
|
63
|
+
const vScrollbar = Math.max(0, pre2.offsetWidth - pre2.clientWidth - borderH);
|
|
64
|
+
wrapper.style.right = `${16 + vScrollbar}px`;
|
|
65
|
+
}
|
|
66
|
+
if (isBottomAlign) {
|
|
67
|
+
const hScrollbar = Math.max(0, pre2.offsetHeight - pre2.clientHeight - borderH);
|
|
68
|
+
wrapper.style.bottom = `${8 + hScrollbar}px`;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
update();
|
|
72
|
+
const observer = new ResizeObserver(update);
|
|
73
|
+
observer.observe(pre2);
|
|
74
|
+
return () => observer.disconnect();
|
|
75
|
+
}, [copyable, copyButtonAlign, noBorder]);
|
|
76
|
+
const handleCopy = async () => {
|
|
77
|
+
try {
|
|
78
|
+
await navigator.clipboard.writeText(code);
|
|
79
|
+
setCopied(true);
|
|
80
|
+
onCopy?.();
|
|
81
|
+
setTimeout(() => setCopied(false), 1500);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const isBottom = copyButtonAlign.includes("bottom");
|
|
86
|
+
const isLeft = copyButtonAlign.includes("left");
|
|
87
|
+
const buttonPositionClass = isBottom ? isLeft ? CodeBlock_vanilla_css.copyButtonWrapperBottomLeft : CodeBlock_vanilla_css.copyButtonWrapperBottomRight : isLeft ? CodeBlock_vanilla_css.copyButtonWrapperTopLeft : CodeBlock_vanilla_css.copyButtonWrapperTop;
|
|
88
|
+
const copyButton = copyable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
89
|
+
Button_vanilla.ButtonVanilla,
|
|
90
|
+
{
|
|
91
|
+
variant: "secondary",
|
|
92
|
+
ghost: true,
|
|
93
|
+
size: "small",
|
|
94
|
+
type: "button",
|
|
95
|
+
onClick: handleCopy,
|
|
96
|
+
css: {
|
|
97
|
+
color: "$hiContrast",
|
|
98
|
+
gap: "$1",
|
|
99
|
+
backgroundColor: "$codeBlockCopyButtonBg",
|
|
100
|
+
height: "32px"
|
|
101
|
+
},
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsxRuntime.jsx(AccessibleIcon.AccessibleIcon, { label: copied ? "Copied" : "Copy", children: copied ? /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CheckIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CopyIcon, {}) }),
|
|
104
|
+
copied ? copiedText : copyText
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
) : null;
|
|
108
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
109
|
+
prismReactRenderer.Highlight,
|
|
110
|
+
{
|
|
111
|
+
theme: prismTheme,
|
|
112
|
+
code,
|
|
113
|
+
language: prismReactRenderer.Prism.languages[lang] != null ? lang : "text",
|
|
114
|
+
children: ({
|
|
115
|
+
className: highlightClass,
|
|
116
|
+
style: highlightStyle,
|
|
117
|
+
tokens,
|
|
118
|
+
getLineProps,
|
|
119
|
+
getTokenProps
|
|
120
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyles, children: [
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
122
|
+
"pre",
|
|
123
|
+
{
|
|
124
|
+
ref: setPreRef,
|
|
125
|
+
className: [CodeBlock_vanilla_css.pre, noBorder ? CodeBlock_vanilla_css.preNoBorder : "", highlightClass, className].filter(Boolean).join(" "),
|
|
126
|
+
style: {
|
|
127
|
+
maxHeight,
|
|
128
|
+
...highlightStyle,
|
|
129
|
+
backgroundColor: "inherit",
|
|
130
|
+
...style
|
|
131
|
+
},
|
|
132
|
+
...props,
|
|
133
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
134
|
+
"div",
|
|
135
|
+
{
|
|
136
|
+
className: [CodeBlock_vanilla_css.codeContent, copyable && isBottom ? CodeBlock_vanilla_css.codeContentBottomPadding : ""].filter(Boolean).join(" "),
|
|
137
|
+
children: tokens.map((line, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
...getLineProps({ line }),
|
|
141
|
+
style: wrapText ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : void 0,
|
|
142
|
+
children: line.map((token, key) => /* @__PURE__ */ jsxRuntime.jsx("span", { ...getTokenProps({ token }) }, key))
|
|
143
|
+
},
|
|
144
|
+
i
|
|
145
|
+
))
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
copyButton && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: buttonWrapperRef, className: buttonPositionClass, children: copyButton })
|
|
151
|
+
] })
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
CodeBlockVanilla.displayName = "CodeBlockVanilla";
|
|
157
|
+
exports.CodeBlockVanilla = CodeBlockVanilla;
|
|
158
|
+
//# sourceMappingURL=CodeBlock.vanilla.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.cjs","sources":["../../../components/CodeBlock/CodeBlock.vanilla.tsx"],"sourcesContent":["import './prism-extend';\n\nimport { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { Highlight, Language, Prism, themes } from 'prism-react-renderer';\nimport React, {\n forwardRef,\n HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { CSSProps, processCSSProp } from '../../styles/cssProps';\nimport { useVanillaExtractTheme } from '../../styles/themeContext';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { ButtonVanilla } from '../Button';\nimport {\n codeContent,\n codeContentBottomPadding,\n copyButtonWrapperBottomLeft,\n copyButtonWrapperBottomRight,\n copyButtonWrapperTop,\n copyButtonWrapperTopLeft,\n pre,\n preNoBorder,\n} from './CodeBlock.vanilla.css';\nimport type { CodeBlockCopyButtonAlign, CodeBlockLanguage } from './index';\n\nexport interface CodeBlockVanillaProps\n extends Omit<HTMLAttributes<HTMLPreElement>, 'css'>,\n CSSProps {\n lang?: CodeBlockLanguage;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: CodeBlockCopyButtonAlign;\n onCopy?: () => void;\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n}\n\nexport const CodeBlockVanilla = forwardRef<HTMLPreElement, CodeBlockVanillaProps>(\n (\n {\n lang = 'text',\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top right',\n onCopy,\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const { colors, resolvedTheme } = useVanillaExtractTheme();\n const effectiveScheme = colorScheme ?? resolvedTheme;\n const prismTheme = effectiveScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const { style: cssStyles, vars } = processCSSProp(css, colors);\n const containerStyles = {\n position: 'relative' as const,\n ...cssStyles,\n ...assignInlineVars(vars),\n };\n\n const [copied, setCopied] = useState(false);\n\n const preRef = useRef<HTMLPreElement | null>(\n null,\n ) as React.MutableRefObject<HTMLPreElement | null>;\n const buttonWrapperRef = useRef<HTMLDivElement>(null);\n\n const setPreRef = useCallback(\n (node: HTMLPreElement | null) => {\n preRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLPreElement | null>).current = node;\n },\n [ref],\n );\n\n useLayoutEffect(() => {\n if (!copyable) return;\n const pre = preRef.current;\n const wrapper = buttonWrapperRef.current;\n if (!pre || !wrapper) return;\n\n const isLeftAlign = copyButtonAlign.includes('left');\n const isBottomAlign = copyButtonAlign.includes('bottom');\n const borderH = noBorder ? 0 : 2;\n\n const update = () => {\n if (!isLeftAlign) {\n const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);\n wrapper.style.right = `${16 + vScrollbar}px`;\n }\n if (isBottomAlign) {\n const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);\n wrapper.style.bottom = `${8 + hScrollbar}px`;\n }\n };\n\n update();\n const observer = new ResizeObserver(update);\n observer.observe(pre);\n return () => observer.disconnect();\n }, [copyable, copyButtonAlign, noBorder]);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n onCopy?.();\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n const isBottom = copyButtonAlign.includes('bottom');\n const isLeft = copyButtonAlign.includes('left');\n const buttonPositionClass = isBottom\n ? isLeft\n ? copyButtonWrapperBottomLeft\n : copyButtonWrapperBottomRight\n : isLeft\n ? copyButtonWrapperTopLeft\n : copyButtonWrapperTop;\n\n const copyButton = copyable ? (\n <ButtonVanilla\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{\n color: '$hiContrast',\n gap: '$1',\n backgroundColor: '$codeBlockCopyButtonBg',\n height: '32px',\n }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </ButtonVanilla>\n ) : null;\n\n return (\n <Highlight\n theme={prismTheme}\n code={code}\n language={(Prism.languages[lang] != null ? lang : 'text') as Language}\n >\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <div style={containerStyles}>\n <pre\n ref={setPreRef}\n className={[pre, noBorder ? preNoBorder : '', highlightClass, className]\n .filter(Boolean)\n .join(' ')}\n style={{\n maxHeight,\n ...highlightStyle,\n backgroundColor: 'inherit',\n ...style,\n }}\n {...props}\n >\n <div\n className={[codeContent, copyable && isBottom ? codeContentBottomPadding : '']\n .filter(Boolean)\n .join(' ')}\n >\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={\n wrapText ? { whiteSpace: 'pre-wrap', wordBreak: 'break-all' } : undefined\n }\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </div>\n </pre>\n {copyButton && (\n <div ref={buttonWrapperRef} className={buttonPositionClass}>\n {copyButton}\n </div>\n )}\n </div>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlockVanilla.displayName = 'CodeBlockVanilla';\n"],"names":["forwardRef","useVanillaExtractTheme","themes","processCSSProp","assignInlineVars","useState","useRef","useCallback","useLayoutEffect","pre","copyButtonWrapperBottomLeft","copyButtonWrapperBottomRight","copyButtonWrapperTopLeft","copyButtonWrapperTop","jsxs","ButtonVanilla","jsx","AccessibleIcon","CheckIcon","CopyIcon","Highlight","Prism","preNoBorder","codeContent","codeContentBottomPadding"],"mappings":";;;;;;;;;;;;AA8CO,MAAM,mBAAmBA,MAAAA;AAAAA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AAAA,IAAC,OAAA,EAAI,KAAK,kBAAkB,WAAW,qBACpC,UAAA,WAAA,CACH;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
;/* empty css */
|
|
4
|
+
var pre = "_1krwcuz0";
|
|
5
|
+
var preNoBorder = "_1krwcuz1";
|
|
6
|
+
var codeContent = "_1krwcuz2";
|
|
7
|
+
var codeContentBottomPadding = "_1krwcuz3";
|
|
8
|
+
var copyButtonWrapperTop = "_1krwcuz4";
|
|
9
|
+
var copyButtonWrapperTopLeft = "_1krwcuz5";
|
|
10
|
+
var copyButtonWrapperBottomRight = "_1krwcuz6";
|
|
11
|
+
var copyButtonWrapperBottomLeft = "_1krwcuz7";
|
|
12
|
+
exports.codeContent = codeContent;
|
|
13
|
+
exports.codeContentBottomPadding = codeContentBottomPadding;
|
|
14
|
+
exports.copyButtonWrapperBottomLeft = copyButtonWrapperBottomLeft;
|
|
15
|
+
exports.copyButtonWrapperBottomRight = copyButtonWrapperBottomRight;
|
|
16
|
+
exports.copyButtonWrapperTop = copyButtonWrapperTop;
|
|
17
|
+
exports.copyButtonWrapperTopLeft = copyButtonWrapperTopLeft;
|
|
18
|
+
exports.pre = pre;
|
|
19
|
+
exports.preNoBorder = preNoBorder;
|
|
20
|
+
//# sourceMappingURL=CodeBlock.vanilla.css.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
var pre = "_1krwcuz0";
|
|
3
|
+
var preNoBorder = "_1krwcuz1";
|
|
4
|
+
var codeContent = "_1krwcuz2";
|
|
5
|
+
var codeContentBottomPadding = "_1krwcuz3";
|
|
6
|
+
var copyButtonWrapperTop = "_1krwcuz4";
|
|
7
|
+
var copyButtonWrapperTopLeft = "_1krwcuz5";
|
|
8
|
+
var copyButtonWrapperBottomRight = "_1krwcuz6";
|
|
9
|
+
var copyButtonWrapperBottomLeft = "_1krwcuz7";
|
|
10
|
+
export {
|
|
11
|
+
codeContent,
|
|
12
|
+
codeContentBottomPadding,
|
|
13
|
+
copyButtonWrapperBottomLeft,
|
|
14
|
+
copyButtonWrapperBottomRight,
|
|
15
|
+
copyButtonWrapperTop,
|
|
16
|
+
copyButtonWrapperTopLeft,
|
|
17
|
+
pre,
|
|
18
|
+
preNoBorder
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=CodeBlock.vanilla.css.js.map
|