@hanzo/ui 5.3.28 → 5.3.30
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/3d/button.js +298 -0
- package/dist/3d/button.mjs +273 -0
- package/dist/3d/card.js +234 -0
- package/dist/3d/card.mjs +207 -0
- package/dist/3d/carousel.js +371 -0
- package/dist/3d/carousel.mjs +344 -0
- package/dist/3d/grid.js +362 -0
- package/dist/3d/grid.mjs +337 -0
- package/dist/3d/index.js +1518 -0
- package/dist/3d/index.mjs +1472 -0
- package/dist/3d/marquee.js +352 -0
- package/dist/3d/marquee.mjs +327 -0
- package/dist/3d/pin.js +46 -0
- package/dist/3d/pin.mjs +24 -0
- package/dist/accordion.js +80 -0
- package/dist/accordion.mjs +55 -0
- package/dist/alert-dialog.js +220 -0
- package/dist/alert-dialog.mjs +187 -0
- package/dist/alert.js +68 -0
- package/dist/alert.mjs +64 -0
- package/dist/animation/animated-background.js +424 -0
- package/dist/animation/animated-background.mjs +418 -0
- package/dist/animation/animated-beam.js +119 -0
- package/dist/animation/animated-beam.mjs +97 -0
- package/dist/animation/animated-cursor.js +275 -0
- package/dist/animation/animated-cursor.mjs +270 -0
- package/dist/animation/animated-icon.js +357 -0
- package/dist/animation/animated-icon.mjs +351 -0
- package/dist/animation/animated-list.js +339 -0
- package/dist/animation/animated-list.mjs +333 -0
- package/dist/animation/animated-number.js +283 -0
- package/dist/animation/animated-number.mjs +277 -0
- package/dist/animation/animated-testimonials.js +97 -0
- package/dist/animation/animated-testimonials.mjs +75 -0
- package/dist/animation/animated-tooltip.js +67 -0
- package/dist/animation/animated-tooltip.mjs +45 -0
- package/dist/animation/apple-cards-carousel.js +308 -0
- package/dist/animation/apple-cards-carousel.mjs +285 -0
- package/dist/animation/apple-hello-effect.js +60 -0
- package/dist/animation/apple-hello-effect.mjs +38 -0
- package/dist/animation/index.js +1952 -0
- package/dist/animation/index.mjs +1921 -0
- package/dist/avatar.js +71 -0
- package/dist/avatar.mjs +47 -0
- package/dist/badge.js +66 -0
- package/dist/badge.mjs +40 -0
- package/dist/blocks/index.js +1665 -0
- package/dist/blocks/index.mjs +1626 -0
- package/dist/breadcrumb.js +107 -0
- package/dist/breadcrumb.mjs +99 -0
- package/dist/calendar.js +189 -0
- package/dist/calendar.mjs +164 -0
- package/dist/carousel.js +278 -0
- package/dist/carousel.mjs +249 -0
- package/dist/checkbox.js +60 -0
- package/dist/checkbox.mjs +35 -0
- package/dist/code/block.js +226 -0
- package/dist/code/block.mjs +203 -0
- package/dist/code/compare.js +446 -0
- package/dist/code/compare.mjs +423 -0
- package/dist/code/diff.js +430 -0
- package/dist/code/diff.mjs +407 -0
- package/dist/code/editor.js +243 -0
- package/dist/code/editor.mjs +218 -0
- package/dist/code/explorer.js +291 -0
- package/dist/code/explorer.mjs +268 -0
- package/dist/code/index.js +2551 -0
- package/dist/code/index.mjs +2510 -0
- package/dist/code/preview.js +400 -0
- package/dist/code/preview.mjs +377 -0
- package/dist/code/snippet.js +274 -0
- package/dist/code/snippet.mjs +250 -0
- package/dist/code/tabs.js +75 -0
- package/dist/code/tabs.mjs +53 -0
- package/dist/code/terminal.js +437 -0
- package/dist/code/terminal.mjs +414 -0
- package/dist/collapsible.js +33 -0
- package/dist/collapsible.mjs +9 -0
- package/dist/command.js +262 -0
- package/dist/command.mjs +232 -0
- package/dist/context-menu.js +207 -0
- package/dist/context-menu.mjs +171 -0
- package/dist/device/index.js +3 -0
- package/dist/device/index.mjs +2 -0
- package/dist/dialog.js +151 -0
- package/dist/dialog.mjs +121 -0
- package/dist/dock/basic.js +174 -0
- package/dist/dock/basic.mjs +151 -0
- package/dist/dock/index.js +628 -0
- package/dist/dock/index.mjs +601 -0
- package/dist/dock/limelight-nav.js +295 -0
- package/dist/dock/limelight-nav.mjs +274 -0
- package/dist/dock/macos.js +141 -0
- package/dist/dock/macos.mjs +118 -0
- package/dist/dock/menu.js +70 -0
- package/dist/dock/menu.mjs +48 -0
- package/dist/dock/message.js +144 -0
- package/dist/dock/message.mjs +122 -0
- package/dist/drawer.js +115 -0
- package/dist/drawer.mjs +103 -0
- package/dist/dropdown-menu.js +202 -0
- package/dist/dropdown-menu.mjs +166 -0
- package/dist/finance/AdvancedChart.js +48 -0
- package/dist/finance/AdvancedChart.mjs +46 -0
- package/dist/finance/CompanyProfile.js +48 -0
- package/dist/finance/CompanyProfile.mjs +46 -0
- package/dist/finance/CryptoScreener.js +45 -0
- package/dist/finance/CryptoScreener.mjs +43 -0
- package/dist/finance/Financials.js +52 -0
- package/dist/finance/Financials.mjs +50 -0
- package/dist/finance/ForexScreener.js +46 -0
- package/dist/finance/ForexScreener.mjs +44 -0
- package/dist/finance/MarketOverview.js +104 -0
- package/dist/finance/MarketOverview.mjs +102 -0
- package/dist/finance/NewsTimeline.js +44 -0
- package/dist/finance/NewsTimeline.mjs +42 -0
- package/dist/finance/OrderEntry.js +131 -0
- package/dist/finance/OrderEntry.mjs +129 -0
- package/dist/finance/OrdersHistory.js +64 -0
- package/dist/finance/OrdersHistory.mjs +62 -0
- package/dist/finance/PositionsList.js +80 -0
- package/dist/finance/PositionsList.mjs +78 -0
- package/dist/finance/StockScreener.js +46 -0
- package/dist/finance/StockScreener.mjs +44 -0
- package/dist/finance/SymbolInfo.js +46 -0
- package/dist/finance/SymbolInfo.mjs +44 -0
- package/dist/finance/TechnicalAnalysis.js +54 -0
- package/dist/finance/TechnicalAnalysis.mjs +52 -0
- package/dist/finance/TickerTape.js +56 -0
- package/dist/finance/TickerTape.mjs +54 -0
- package/dist/finance/TradingPanel.js +191 -0
- package/dist/finance/TradingPanel.mjs +189 -0
- package/dist/finance/index.js +930 -0
- package/dist/finance/index.mjs +914 -0
- package/dist/form/index.js +155 -0
- package/dist/form/index.mjs +125 -0
- package/dist/form.js +172 -0
- package/dist/form.mjs +142 -0
- package/dist/hover-card.js +58 -0
- package/dist/hover-card.mjs +34 -0
- package/dist/index.js +8467 -0
- package/dist/index.mjs +8087 -0
- package/dist/input-otp.js +79 -0
- package/dist/input-otp.mjs +54 -0
- package/dist/lib/utils.js +28 -0
- package/dist/lib/utils.mjs +24 -0
- package/dist/navigation/index.js +98 -0
- package/dist/navigation/index.mjs +79 -0
- package/dist/navigation-menu.js +149 -0
- package/dist/navigation-menu.mjs +116 -0
- package/dist/pattern/grid-pattern.js +333 -0
- package/dist/pattern/grid-pattern.mjs +310 -0
- package/dist/pattern/index.js +333 -0
- package/dist/pattern/index.mjs +310 -0
- package/dist/popover.js +63 -0
- package/dist/popover.mjs +37 -0
- package/dist/primitives/index.js +8467 -0
- package/dist/primitives/index.mjs +8087 -0
- package/dist/primitives-export.js +8467 -0
- package/dist/primitives-export.mjs +8087 -0
- package/dist/progress.js +62 -0
- package/dist/progress.mjs +37 -0
- package/dist/project/gantt.js +65 -0
- package/dist/project/gantt.mjs +43 -0
- package/dist/project/index.js +636 -0
- package/dist/project/index.mjs +611 -0
- package/dist/project/kanban.js +597 -0
- package/dist/project/kanban.mjs +572 -0
- package/dist/project/list.js +35 -0
- package/dist/project/list.mjs +12 -0
- package/dist/radio-group.js +68 -0
- package/dist/radio-group.mjs +45 -0
- package/dist/resizable.js +72 -0
- package/dist/resizable.mjs +48 -0
- package/dist/scroll-area.js +89 -0
- package/dist/scroll-area.mjs +66 -0
- package/dist/select.js +140 -0
- package/dist/select.mjs +111 -0
- package/dist/separator.js +59 -0
- package/dist/separator.mjs +34 -0
- package/dist/sheet.js +148 -0
- package/dist/sheet.mjs +117 -0
- package/dist/skeleton.js +32 -0
- package/dist/skeleton.mjs +27 -0
- package/dist/slider.js +99 -0
- package/dist/slider.mjs +73 -0
- package/dist/sonner.js +34 -0
- package/dist/sonner.mjs +29 -0
- package/dist/switch.js +62 -0
- package/dist/switch.mjs +37 -0
- package/dist/table.js +110 -0
- package/dist/table.mjs +101 -0
- package/dist/tabs.js +82 -0
- package/dist/tabs.mjs +57 -0
- package/dist/tailwind/index.js +2023 -0
- package/dist/tailwind/index.mjs +2011 -0
- package/dist/textarea.js +78 -0
- package/dist/textarea.mjs +56 -0
- package/dist/toggle-group.js +118 -0
- package/dist/toggle-group.mjs +93 -0
- package/dist/toggle.js +71 -0
- package/dist/toggle.mjs +48 -0
- package/dist/tooltip.js +67 -0
- package/dist/tooltip.mjs +40 -0
- package/dist/types/index.js +57 -0
- package/dist/types/index.mjs +51 -0
- package/dist/ui/announcement.js +129 -0
- package/dist/ui/announcement.mjs +107 -0
- package/dist/ui/avatar-group.js +88 -0
- package/dist/ui/avatar-group.mjs +65 -0
- package/dist/ui/banner.js +85 -0
- package/dist/ui/banner.mjs +62 -0
- package/dist/ui/cursor.js +78 -0
- package/dist/ui/cursor.mjs +56 -0
- package/dist/ui/index.js +475 -0
- package/dist/ui/index.mjs +442 -0
- package/dist/ui/marquee.js +74 -0
- package/dist/ui/marquee.mjs +52 -0
- package/dist/ui/pill.js +85 -0
- package/dist/ui/pill.mjs +62 -0
- package/dist/ui/spinner.js +28 -0
- package/dist/ui/spinner.mjs +26 -0
- package/dist/ui/tags.js +101 -0
- package/dist/ui/tags.mjs +79 -0
- package/dist/ui/ticker.js +73 -0
- package/dist/ui/ticker.mjs +51 -0
- package/dist/util/index.js +463 -0
- package/dist/util/index.mjs +404 -0
- package/package.json +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
6
|
+
var lucideReact = require('lucide-react');
|
|
7
|
+
var shiki = require('shiki');
|
|
8
|
+
var utils = require('@hanzo/ui/lib/utils');
|
|
9
|
+
var badge = require('@hanzo/ui/badge');
|
|
10
|
+
var button = require('@hanzo/ui/button');
|
|
11
|
+
var skeleton = require('@hanzo/ui/skeleton');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
|
+
|
|
34
|
+
var __defProp = Object.defineProperty;
|
|
35
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
36
|
+
var codeBlockVariants = classVarianceAuthority.cva(
|
|
37
|
+
"relative overflow-hidden rounded-lg border bg-muted/50",
|
|
38
|
+
{
|
|
39
|
+
variants: {
|
|
40
|
+
theme: {
|
|
41
|
+
dark: "bg-slate-950 border-slate-800",
|
|
42
|
+
light: "bg-slate-50 border-slate-200",
|
|
43
|
+
github: "bg-white border-slate-200",
|
|
44
|
+
"github-dark": "bg-slate-900 border-slate-700",
|
|
45
|
+
"vs-dark": "bg-slate-950 border-slate-800",
|
|
46
|
+
monokai: "bg-slate-900 border-slate-700",
|
|
47
|
+
dracula: "bg-slate-900 border-purple-800/30",
|
|
48
|
+
nord: "bg-slate-800 border-slate-600"
|
|
49
|
+
},
|
|
50
|
+
size: {
|
|
51
|
+
sm: "text-xs",
|
|
52
|
+
default: "text-sm",
|
|
53
|
+
lg: "text-base"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
theme: "dark",
|
|
58
|
+
size: "default"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
var CodeLine = React__namespace.memo(
|
|
63
|
+
({
|
|
64
|
+
line,
|
|
65
|
+
lineNumber,
|
|
66
|
+
showLineNumbers,
|
|
67
|
+
isHighlighted = false,
|
|
68
|
+
isDiffAdded = false,
|
|
69
|
+
isDiffRemoved = false
|
|
70
|
+
}) => {
|
|
71
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
72
|
+
"div",
|
|
73
|
+
{
|
|
74
|
+
className: utils.cn(
|
|
75
|
+
"group relative flex min-h-[1.5rem] items-center px-4 py-0.5",
|
|
76
|
+
isHighlighted && "bg-blue-500/10 border-l-2 border-l-blue-500",
|
|
77
|
+
isDiffAdded && "bg-green-500/10 border-l-2 border-l-green-500",
|
|
78
|
+
isDiffRemoved && "bg-red-500/10 border-l-2 border-l-red-500"
|
|
79
|
+
),
|
|
80
|
+
children: [
|
|
81
|
+
showLineNumbers && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-4 inline-block w-8 select-none text-right text-xs text-muted-foreground", children: lineNumber }),
|
|
82
|
+
(isDiffAdded || isDiffRemoved) && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-2 select-none text-xs", children: isDiffAdded ? "+" : isDiffRemoved ? "-" : " " }),
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
84
|
+
"div",
|
|
85
|
+
{
|
|
86
|
+
className: "flex-1 overflow-x-auto",
|
|
87
|
+
dangerouslySetInnerHTML: { __html: line }
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
CodeLine.displayName = "CodeLine";
|
|
96
|
+
var CodeBlock = React__namespace.forwardRef(
|
|
97
|
+
({
|
|
98
|
+
className,
|
|
99
|
+
theme,
|
|
100
|
+
size,
|
|
101
|
+
code,
|
|
102
|
+
language = "text",
|
|
103
|
+
filename,
|
|
104
|
+
showLineNumbers = true,
|
|
105
|
+
highlightLines = [],
|
|
106
|
+
showCopyButton = true,
|
|
107
|
+
maxHeight = "400px",
|
|
108
|
+
diff,
|
|
109
|
+
...props
|
|
110
|
+
}, ref) => {
|
|
111
|
+
const [highlightedCode, setHighlightedCode] = React__namespace.useState("");
|
|
112
|
+
const [copied, setCopied] = React__namespace.useState(false);
|
|
113
|
+
const [isLoading, setIsLoading] = React__namespace.useState(true);
|
|
114
|
+
const themeMap = {
|
|
115
|
+
dark: "github-dark",
|
|
116
|
+
light: "github-light",
|
|
117
|
+
github: "github-light",
|
|
118
|
+
"github-dark": "github-dark",
|
|
119
|
+
"vs-dark": "dark-plus",
|
|
120
|
+
monokai: "monokai",
|
|
121
|
+
dracula: "dracula",
|
|
122
|
+
nord: "nord"
|
|
123
|
+
};
|
|
124
|
+
React__namespace.useEffect(() => {
|
|
125
|
+
const highlightCode = /* @__PURE__ */ __name(async () => {
|
|
126
|
+
setIsLoading(true);
|
|
127
|
+
try {
|
|
128
|
+
const highlighted = await shiki.codeToHtml(code, {
|
|
129
|
+
lang: language,
|
|
130
|
+
theme: themeMap[theme || "dark"],
|
|
131
|
+
transformers: [
|
|
132
|
+
{
|
|
133
|
+
code(node) {
|
|
134
|
+
const codeElement2 = node.children.find(
|
|
135
|
+
(child) => child.type === "element" && child.tagName === "code"
|
|
136
|
+
);
|
|
137
|
+
if (codeElement2 && "children" in codeElement2 && codeElement2.children) {
|
|
138
|
+
node.children = codeElement2.children;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
const tempDiv = document.createElement("div");
|
|
145
|
+
tempDiv.innerHTML = highlighted;
|
|
146
|
+
const codeElement = tempDiv.querySelector("code");
|
|
147
|
+
setHighlightedCode(codeElement?.innerHTML || highlighted);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Failed to highlight code:", error);
|
|
150
|
+
setHighlightedCode(code);
|
|
151
|
+
} finally {
|
|
152
|
+
setIsLoading(false);
|
|
153
|
+
}
|
|
154
|
+
}, "highlightCode");
|
|
155
|
+
highlightCode();
|
|
156
|
+
}, [code, language, theme]);
|
|
157
|
+
const copyToClipboard = React__namespace.useCallback(async () => {
|
|
158
|
+
try {
|
|
159
|
+
await navigator.clipboard.writeText(code);
|
|
160
|
+
setCopied(true);
|
|
161
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error("Failed to copy code:", error);
|
|
164
|
+
}
|
|
165
|
+
}, [code]);
|
|
166
|
+
const lines = highlightedCode.split("\n");
|
|
167
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
ref,
|
|
171
|
+
"data-testid": "code-block",
|
|
172
|
+
className: utils.cn(codeBlockVariants({ theme, size, className })),
|
|
173
|
+
...props,
|
|
174
|
+
children: [
|
|
175
|
+
(filename || language || showCopyButton) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between border-b px-4 py-2", children: [
|
|
176
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
177
|
+
filename && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
179
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: filename })
|
|
180
|
+
] }),
|
|
181
|
+
language && /* @__PURE__ */ jsxRuntime.jsx(badge.Badge, { variant: "secondary", className: "text-xs", children: language })
|
|
182
|
+
] }),
|
|
183
|
+
showCopyButton && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
184
|
+
button.Button,
|
|
185
|
+
{
|
|
186
|
+
variant: "ghost",
|
|
187
|
+
size: "sm",
|
|
188
|
+
onClick: copyToClipboard,
|
|
189
|
+
className: "h-8 w-8 p-0",
|
|
190
|
+
children: [
|
|
191
|
+
copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-3.5 w-3.5 text-green-500" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-3.5 w-3.5" }),
|
|
192
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: copied ? "Copied" : "Copy code" })
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
] }),
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-auto", style: { maxHeight }, children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 space-y-2", children: Array.from({ length: 10 }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [
|
|
198
|
+
showLineNumbers && /* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { "data-testid": "skeleton", className: "h-4 w-8" }),
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { "data-testid": "skeleton", className: "h-4 flex-1" })
|
|
200
|
+
] }, i)) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-mono", children: lines.map((line, index) => {
|
|
201
|
+
const lineNumber = index + 1;
|
|
202
|
+
const isHighlighted = highlightLines.includes(lineNumber);
|
|
203
|
+
const isDiffAdded = diff?.added?.includes(lineNumber);
|
|
204
|
+
const isDiffRemoved = diff?.removed?.includes(lineNumber);
|
|
205
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
206
|
+
CodeLine,
|
|
207
|
+
{
|
|
208
|
+
line,
|
|
209
|
+
lineNumber,
|
|
210
|
+
showLineNumbers,
|
|
211
|
+
isHighlighted,
|
|
212
|
+
isDiffAdded,
|
|
213
|
+
isDiffRemoved
|
|
214
|
+
},
|
|
215
|
+
index
|
|
216
|
+
);
|
|
217
|
+
}) }) })
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
CodeBlock.displayName = "CodeBlock";
|
|
224
|
+
|
|
225
|
+
exports.CodeBlock = CodeBlock;
|
|
226
|
+
exports.codeBlockVariants = codeBlockVariants;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { FileText, Check, Copy } from 'lucide-react';
|
|
5
|
+
import { codeToHtml } from 'shiki';
|
|
6
|
+
import { cn } from '@hanzo/ui/lib/utils';
|
|
7
|
+
import { Badge } from '@hanzo/ui/badge';
|
|
8
|
+
import { Button } from '@hanzo/ui/button';
|
|
9
|
+
import { Skeleton } from '@hanzo/ui/skeleton';
|
|
10
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
+
var codeBlockVariants = cva(
|
|
15
|
+
"relative overflow-hidden rounded-lg border bg-muted/50",
|
|
16
|
+
{
|
|
17
|
+
variants: {
|
|
18
|
+
theme: {
|
|
19
|
+
dark: "bg-slate-950 border-slate-800",
|
|
20
|
+
light: "bg-slate-50 border-slate-200",
|
|
21
|
+
github: "bg-white border-slate-200",
|
|
22
|
+
"github-dark": "bg-slate-900 border-slate-700",
|
|
23
|
+
"vs-dark": "bg-slate-950 border-slate-800",
|
|
24
|
+
monokai: "bg-slate-900 border-slate-700",
|
|
25
|
+
dracula: "bg-slate-900 border-purple-800/30",
|
|
26
|
+
nord: "bg-slate-800 border-slate-600"
|
|
27
|
+
},
|
|
28
|
+
size: {
|
|
29
|
+
sm: "text-xs",
|
|
30
|
+
default: "text-sm",
|
|
31
|
+
lg: "text-base"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
theme: "dark",
|
|
36
|
+
size: "default"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
var CodeLine = React.memo(
|
|
41
|
+
({
|
|
42
|
+
line,
|
|
43
|
+
lineNumber,
|
|
44
|
+
showLineNumbers,
|
|
45
|
+
isHighlighted = false,
|
|
46
|
+
isDiffAdded = false,
|
|
47
|
+
isDiffRemoved = false
|
|
48
|
+
}) => {
|
|
49
|
+
return /* @__PURE__ */ jsxs(
|
|
50
|
+
"div",
|
|
51
|
+
{
|
|
52
|
+
className: cn(
|
|
53
|
+
"group relative flex min-h-[1.5rem] items-center px-4 py-0.5",
|
|
54
|
+
isHighlighted && "bg-blue-500/10 border-l-2 border-l-blue-500",
|
|
55
|
+
isDiffAdded && "bg-green-500/10 border-l-2 border-l-green-500",
|
|
56
|
+
isDiffRemoved && "bg-red-500/10 border-l-2 border-l-red-500"
|
|
57
|
+
),
|
|
58
|
+
children: [
|
|
59
|
+
showLineNumbers && /* @__PURE__ */ jsx("span", { className: "mr-4 inline-block w-8 select-none text-right text-xs text-muted-foreground", children: lineNumber }),
|
|
60
|
+
(isDiffAdded || isDiffRemoved) && /* @__PURE__ */ jsx("span", { className: "mr-2 select-none text-xs", children: isDiffAdded ? "+" : isDiffRemoved ? "-" : " " }),
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
"div",
|
|
63
|
+
{
|
|
64
|
+
className: "flex-1 overflow-x-auto",
|
|
65
|
+
dangerouslySetInnerHTML: { __html: line }
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
CodeLine.displayName = "CodeLine";
|
|
74
|
+
var CodeBlock = React.forwardRef(
|
|
75
|
+
({
|
|
76
|
+
className,
|
|
77
|
+
theme,
|
|
78
|
+
size,
|
|
79
|
+
code,
|
|
80
|
+
language = "text",
|
|
81
|
+
filename,
|
|
82
|
+
showLineNumbers = true,
|
|
83
|
+
highlightLines = [],
|
|
84
|
+
showCopyButton = true,
|
|
85
|
+
maxHeight = "400px",
|
|
86
|
+
diff,
|
|
87
|
+
...props
|
|
88
|
+
}, ref) => {
|
|
89
|
+
const [highlightedCode, setHighlightedCode] = React.useState("");
|
|
90
|
+
const [copied, setCopied] = React.useState(false);
|
|
91
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
92
|
+
const themeMap = {
|
|
93
|
+
dark: "github-dark",
|
|
94
|
+
light: "github-light",
|
|
95
|
+
github: "github-light",
|
|
96
|
+
"github-dark": "github-dark",
|
|
97
|
+
"vs-dark": "dark-plus",
|
|
98
|
+
monokai: "monokai",
|
|
99
|
+
dracula: "dracula",
|
|
100
|
+
nord: "nord"
|
|
101
|
+
};
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
const highlightCode = /* @__PURE__ */ __name(async () => {
|
|
104
|
+
setIsLoading(true);
|
|
105
|
+
try {
|
|
106
|
+
const highlighted = await codeToHtml(code, {
|
|
107
|
+
lang: language,
|
|
108
|
+
theme: themeMap[theme || "dark"],
|
|
109
|
+
transformers: [
|
|
110
|
+
{
|
|
111
|
+
code(node) {
|
|
112
|
+
const codeElement2 = node.children.find(
|
|
113
|
+
(child) => child.type === "element" && child.tagName === "code"
|
|
114
|
+
);
|
|
115
|
+
if (codeElement2 && "children" in codeElement2 && codeElement2.children) {
|
|
116
|
+
node.children = codeElement2.children;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
const tempDiv = document.createElement("div");
|
|
123
|
+
tempDiv.innerHTML = highlighted;
|
|
124
|
+
const codeElement = tempDiv.querySelector("code");
|
|
125
|
+
setHighlightedCode(codeElement?.innerHTML || highlighted);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Failed to highlight code:", error);
|
|
128
|
+
setHighlightedCode(code);
|
|
129
|
+
} finally {
|
|
130
|
+
setIsLoading(false);
|
|
131
|
+
}
|
|
132
|
+
}, "highlightCode");
|
|
133
|
+
highlightCode();
|
|
134
|
+
}, [code, language, theme]);
|
|
135
|
+
const copyToClipboard = React.useCallback(async () => {
|
|
136
|
+
try {
|
|
137
|
+
await navigator.clipboard.writeText(code);
|
|
138
|
+
setCopied(true);
|
|
139
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error("Failed to copy code:", error);
|
|
142
|
+
}
|
|
143
|
+
}, [code]);
|
|
144
|
+
const lines = highlightedCode.split("\n");
|
|
145
|
+
return /* @__PURE__ */ jsxs(
|
|
146
|
+
"div",
|
|
147
|
+
{
|
|
148
|
+
ref,
|
|
149
|
+
"data-testid": "code-block",
|
|
150
|
+
className: cn(codeBlockVariants({ theme, size, className })),
|
|
151
|
+
...props,
|
|
152
|
+
children: [
|
|
153
|
+
(filename || language || showCopyButton) && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b px-4 py-2", children: [
|
|
154
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
155
|
+
filename && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
156
|
+
/* @__PURE__ */ jsx(FileText, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
157
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: filename })
|
|
158
|
+
] }),
|
|
159
|
+
language && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: language })
|
|
160
|
+
] }),
|
|
161
|
+
showCopyButton && /* @__PURE__ */ jsxs(
|
|
162
|
+
Button,
|
|
163
|
+
{
|
|
164
|
+
variant: "ghost",
|
|
165
|
+
size: "sm",
|
|
166
|
+
onClick: copyToClipboard,
|
|
167
|
+
className: "h-8 w-8 p-0",
|
|
168
|
+
children: [
|
|
169
|
+
copied ? /* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5 text-green-500" }) : /* @__PURE__ */ jsx(Copy, { className: "h-3.5 w-3.5" }),
|
|
170
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: copied ? "Copied" : "Copy code" })
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
] }),
|
|
175
|
+
/* @__PURE__ */ jsx("div", { className: "overflow-auto", style: { maxHeight }, children: isLoading ? /* @__PURE__ */ jsx("div", { className: "p-4 space-y-2", children: Array.from({ length: 10 }).map((_, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
176
|
+
showLineNumbers && /* @__PURE__ */ jsx(Skeleton, { "data-testid": "skeleton", className: "h-4 w-8" }),
|
|
177
|
+
/* @__PURE__ */ jsx(Skeleton, { "data-testid": "skeleton", className: "h-4 flex-1" })
|
|
178
|
+
] }, i)) }) : /* @__PURE__ */ jsx("div", { className: "font-mono", children: lines.map((line, index) => {
|
|
179
|
+
const lineNumber = index + 1;
|
|
180
|
+
const isHighlighted = highlightLines.includes(lineNumber);
|
|
181
|
+
const isDiffAdded = diff?.added?.includes(lineNumber);
|
|
182
|
+
const isDiffRemoved = diff?.removed?.includes(lineNumber);
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
CodeLine,
|
|
185
|
+
{
|
|
186
|
+
line,
|
|
187
|
+
lineNumber,
|
|
188
|
+
showLineNumbers,
|
|
189
|
+
isHighlighted,
|
|
190
|
+
isDiffAdded,
|
|
191
|
+
isDiffRemoved
|
|
192
|
+
},
|
|
193
|
+
index
|
|
194
|
+
);
|
|
195
|
+
}) }) })
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
CodeBlock.displayName = "CodeBlock";
|
|
202
|
+
|
|
203
|
+
export { CodeBlock, codeBlockVariants };
|