@nucleux/code-block 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +70 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var utils = require('@nucleux/utils');
|
|
7
|
+
var hooks = require('@nucleux/hooks');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var CodeBlock = React__namespace.forwardRef(
|
|
32
|
+
({ code, language, hideCopy = false, className, ...props }, ref) => {
|
|
33
|
+
const { copied, copy } = hooks.useCopyToClipboard();
|
|
34
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
ref,
|
|
38
|
+
className: utils.cn(
|
|
39
|
+
"group relative overflow-hidden rounded-md border border-border bg-muted/40 text-sm",
|
|
40
|
+
className
|
|
41
|
+
),
|
|
42
|
+
...props,
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-1.5", children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-xs text-muted-foreground", children: language ?? "text" }),
|
|
46
|
+
!hideCopy && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
47
|
+
"button",
|
|
48
|
+
{
|
|
49
|
+
type: "button",
|
|
50
|
+
onClick: () => void copy(code),
|
|
51
|
+
"aria-label": copied ? "Copied" : "Copy code",
|
|
52
|
+
className: "inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
53
|
+
children: [
|
|
54
|
+
copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-3.5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "size-3.5" }),
|
|
55
|
+
copied ? "Copied" : "Copy"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "overflow-x-auto p-3", children: /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono text-[13px] leading-relaxed text-foreground", children: code }) })
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
CodeBlock.displayName = "CodeBlock";
|
|
67
|
+
|
|
68
|
+
exports.CodeBlock = CodeBlock;
|
|
69
|
+
//# sourceMappingURL=index.cjs.map
|
|
70
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","useCopyToClipboard","jsxs","cn","jsx","Check","Copy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAM,SAAA,GAAkBA,gBAAA,CAAA,UAAA;AAAA,EAC7B,CAAC,EAAE,IAAA,EAAM,QAAA,EAAU,QAAA,GAAW,OAAO,SAAA,EAAW,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AAClE,IAAA,MAAM,EAAE,MAAA,EAAQ,IAAA,EAAK,GAAIC,wBAAA,EAAmB;AAC5C,IAAA,uBACEC,eAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,SAAA,EAAWC,QAAA;AAAA,UACT,oFAAA;AAAA,UACA;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEJ,QAAA,EAAA;AAAA,0BAAAD,eAAA,CAAC,KAAA,EAAA,EAAI,WAAU,sEAAA,EACb,QAAA,EAAA;AAAA,4BAAAE,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yCAAA,EACb,QAAA,EAAA,QAAA,IAAY,MAAA,EACf,CAAA;AAAA,YACC,CAAC,QAAA,oBACAF,eAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,MAAM,KAAK,IAAA,CAAK,IAAI,CAAA;AAAA,gBAC7B,YAAA,EAAY,SAAS,QAAA,GAAW,WAAA;AAAA,gBAChC,SAAA,EAAU,2NAAA;AAAA,gBAET,QAAA,EAAA;AAAA,kBAAA,MAAA,mBAASE,cAAA,CAACC,qBAAM,SAAA,EAAU,UAAA,EAAW,oBAAKD,cAAA,CAACE,gBAAA,EAAA,EAAK,WAAU,UAAA,EAAW,CAAA;AAAA,kBACrE,SAAS,QAAA,GAAW;AAAA;AAAA;AAAA;AACvB,WAAA,EAEJ,CAAA;AAAA,0BACAF,cAAA,CAAC,SAAI,SAAA,EAAU,qBAAA,EACb,yCAAC,MAAA,EAAA,EAAK,SAAA,EAAU,uDAAA,EACb,QAAA,EAAA,IAAA,EACH,CAAA,EACF;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,SAAA,CAAU,WAAA,GAAc,WAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { Check, Copy } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\nimport { useCopyToClipboard } from \"@nucleux/hooks\";\n\nexport interface CodeBlockProps extends React.HTMLAttributes<HTMLDivElement> {\n /** The raw source code to display. */\n code: string;\n /** Language label shown in the header (e.g. \"ts\", \"python\"). */\n language?: string;\n /** Hide the copy button. */\n hideCopy?: boolean;\n}\n\n/**\n * A code surface with a language label and copy-to-clipboard button. Syntax\n * highlighting is intentionally left to the consumer (bring your own\n * highlighter such as Shiki) so the library stays dependency-light.\n */\nexport const CodeBlock = React.forwardRef<HTMLDivElement, CodeBlockProps>(\n ({ code, language, hideCopy = false, className, ...props }, ref) => {\n const { copied, copy } = useCopyToClipboard();\n return (\n <div\n ref={ref}\n className={cn(\n \"group relative overflow-hidden rounded-md border border-border bg-muted/40 text-sm\",\n className,\n )}\n {...props}\n >\n <div className=\"flex items-center justify-between border-b border-border px-3 py-1.5\">\n <span className=\"font-mono text-xs text-muted-foreground\">\n {language ?? \"text\"}\n </span>\n {!hideCopy && (\n <button\n type=\"button\"\n onClick={() => void copy(code)}\n aria-label={copied ? \"Copied\" : \"Copy code\"}\n className=\"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n {copied ? <Check className=\"size-3.5\" /> : <Copy className=\"size-3.5\" />}\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n )}\n </div>\n <pre className=\"overflow-x-auto p-3\">\n <code className=\"font-mono text-[13px] leading-relaxed text-foreground\">\n {code}\n </code>\n </pre>\n </div>\n );\n },\n);\nCodeBlock.displayName = \"CodeBlock\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface CodeBlockProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** The raw source code to display. */
|
|
5
|
+
code: string;
|
|
6
|
+
/** Language label shown in the header (e.g. "ts", "python"). */
|
|
7
|
+
language?: string;
|
|
8
|
+
/** Hide the copy button. */
|
|
9
|
+
hideCopy?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A code surface with a language label and copy-to-clipboard button. Syntax
|
|
13
|
+
* highlighting is intentionally left to the consumer (bring your own
|
|
14
|
+
* highlighter such as Shiki) so the library stays dependency-light.
|
|
15
|
+
*/
|
|
16
|
+
declare const CodeBlock: React.ForwardRefExoticComponent<CodeBlockProps & React.RefAttributes<HTMLDivElement>>;
|
|
17
|
+
|
|
18
|
+
export { CodeBlock, type CodeBlockProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface CodeBlockProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** The raw source code to display. */
|
|
5
|
+
code: string;
|
|
6
|
+
/** Language label shown in the header (e.g. "ts", "python"). */
|
|
7
|
+
language?: string;
|
|
8
|
+
/** Hide the copy button. */
|
|
9
|
+
hideCopy?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A code surface with a language label and copy-to-clipboard button. Syntax
|
|
13
|
+
* highlighting is intentionally left to the consumer (bring your own
|
|
14
|
+
* highlighter such as Shiki) so the library stays dependency-light.
|
|
15
|
+
*/
|
|
16
|
+
declare const CodeBlock: React.ForwardRefExoticComponent<CodeBlockProps & React.RefAttributes<HTMLDivElement>>;
|
|
17
|
+
|
|
18
|
+
export { CodeBlock, type CodeBlockProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Check, Copy } from 'lucide-react';
|
|
4
|
+
import { cn } from '@nucleux/utils';
|
|
5
|
+
import { useCopyToClipboard } from '@nucleux/hooks';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/index.tsx
|
|
9
|
+
var CodeBlock = React.forwardRef(
|
|
10
|
+
({ code, language, hideCopy = false, className, ...props }, ref) => {
|
|
11
|
+
const { copied, copy } = useCopyToClipboard();
|
|
12
|
+
return /* @__PURE__ */ jsxs(
|
|
13
|
+
"div",
|
|
14
|
+
{
|
|
15
|
+
ref,
|
|
16
|
+
className: cn(
|
|
17
|
+
"group relative overflow-hidden rounded-md border border-border bg-muted/40 text-sm",
|
|
18
|
+
className
|
|
19
|
+
),
|
|
20
|
+
...props,
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-1.5", children: [
|
|
23
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-muted-foreground", children: language ?? "text" }),
|
|
24
|
+
!hideCopy && /* @__PURE__ */ jsxs(
|
|
25
|
+
"button",
|
|
26
|
+
{
|
|
27
|
+
type: "button",
|
|
28
|
+
onClick: () => void copy(code),
|
|
29
|
+
"aria-label": copied ? "Copied" : "Copy code",
|
|
30
|
+
className: "inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
31
|
+
children: [
|
|
32
|
+
copied ? /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "size-3.5" }),
|
|
33
|
+
copied ? "Copied" : "Copy"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
] }),
|
|
38
|
+
/* @__PURE__ */ jsx("pre", { className: "overflow-x-auto p-3", children: /* @__PURE__ */ jsx("code", { className: "font-mono text-[13px] leading-relaxed text-foreground", children: code }) })
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
CodeBlock.displayName = "CodeBlock";
|
|
45
|
+
|
|
46
|
+
export { CodeBlock };
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
48
|
+
//# sourceMappingURL=index.js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,SAAA,EAAU,uDAAA,EACb,QAAA,EAAA,IAAA,EACH,CAAA,EACF;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,SAAA,CAAU,WAAA,GAAc,WAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { Check, Copy } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\nimport { useCopyToClipboard } from \"@nucleux/hooks\";\n\nexport interface CodeBlockProps extends React.HTMLAttributes<HTMLDivElement> {\n /** The raw source code to display. */\n code: string;\n /** Language label shown in the header (e.g. \"ts\", \"python\"). */\n language?: string;\n /** Hide the copy button. */\n hideCopy?: boolean;\n}\n\n/**\n * A code surface with a language label and copy-to-clipboard button. Syntax\n * highlighting is intentionally left to the consumer (bring your own\n * highlighter such as Shiki) so the library stays dependency-light.\n */\nexport const CodeBlock = React.forwardRef<HTMLDivElement, CodeBlockProps>(\n ({ code, language, hideCopy = false, className, ...props }, ref) => {\n const { copied, copy } = useCopyToClipboard();\n return (\n <div\n ref={ref}\n className={cn(\n \"group relative overflow-hidden rounded-md border border-border bg-muted/40 text-sm\",\n className,\n )}\n {...props}\n >\n <div className=\"flex items-center justify-between border-b border-border px-3 py-1.5\">\n <span className=\"font-mono text-xs text-muted-foreground\">\n {language ?? \"text\"}\n </span>\n {!hideCopy && (\n <button\n type=\"button\"\n onClick={() => void copy(code)}\n aria-label={copied ? \"Copied\" : \"Copy code\"}\n className=\"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n {copied ? <Check className=\"size-3.5\" /> : <Copy className=\"size-3.5\" />}\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n )}\n </div>\n <pre className=\"overflow-x-auto p-3\">\n <code className=\"font-mono text-[13px] leading-relaxed text-foreground\">\n {code}\n </code>\n </pre>\n </div>\n );\n },\n);\nCodeBlock.displayName = \"CodeBlock\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/code-block",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18",
|
|
21
|
+
"react-dom": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"lucide-react": "^0.469.0",
|
|
25
|
+
"@nucleux/hooks": "0.1.0",
|
|
26
|
+
"@nucleux/utils": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.3.5",
|
|
30
|
+
"typescript": "^5.7.2",
|
|
31
|
+
"@types/react": "^18.3.18",
|
|
32
|
+
"react": "^18.3.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
41
|
+
"directory": "packages/code-block"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup"
|
|
46
|
+
}
|
|
47
|
+
}
|