@mantine/code-highlight 7.0.0-alpha.7 → 7.0.0-alpha.9
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/cjs/CodeHighlight.js +31 -103
- package/cjs/CodeHighlight.js.map +1 -1
- package/cjs/CodeHighlight.module.css.js +0 -1
- package/cjs/CodeHighlight.module.css.js.map +1 -1
- package/cjs/CodeHighlight.theme.module.css.js +0 -1
- package/cjs/CodeHighlight.theme.module.css.js.map +1 -1
- package/cjs/CodeHighlightTabs.js +60 -167
- package/cjs/CodeHighlightTabs.js.map +1 -1
- package/cjs/CopyIcon.js +9 -55
- package/cjs/CopyIcon.js.map +1 -1
- package/cjs/ExpandIcon.js +15 -68
- package/cjs/ExpandIcon.js.map +1 -1
- package/cjs/FileIcon.js +7 -8
- package/cjs/FileIcon.js.map +1 -1
- package/cjs/InlineCodeHighlight.js +19 -55
- package/cjs/InlineCodeHighlight.js.map +1 -1
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.js +55 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.module.css.js +8 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.module.css.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.theme.module.css.js +8 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlight.theme.module.css.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlightTabs.js +90 -0
- package/cjs/src/mantine-code-highlight/src/CodeHighlightTabs.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/CopyIcon.js +25 -0
- package/cjs/src/mantine-code-highlight/src/CopyIcon.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/ExpandIcon.js +31 -0
- package/cjs/src/mantine-code-highlight/src/ExpandIcon.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/FileIcon.js +22 -0
- package/cjs/src/mantine-code-highlight/src/FileIcon.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/InlineCodeHighlight.js +43 -0
- package/cjs/src/mantine-code-highlight/src/InlineCodeHighlight.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/index.js +14 -0
- package/cjs/src/mantine-code-highlight/src/index.js.map +1 -0
- package/cjs/src/mantine-code-highlight/src/use-highlight.js +29 -0
- package/cjs/src/mantine-code-highlight/src/use-highlight.js.map +1 -0
- package/cjs/use-highlight.js +13 -12
- package/cjs/use-highlight.js.map +1 -1
- package/esm/CodeHighlight.js +31 -103
- package/esm/CodeHighlight.js.map +1 -1
- package/esm/CodeHighlight.module.css.js +0 -1
- package/esm/CodeHighlight.module.css.js.map +1 -1
- package/esm/CodeHighlight.theme.module.css.js +0 -1
- package/esm/CodeHighlight.theme.module.css.js.map +1 -1
- package/esm/CodeHighlightTabs.js +60 -167
- package/esm/CodeHighlightTabs.js.map +1 -1
- package/esm/CopyIcon.js +9 -55
- package/esm/CopyIcon.js.map +1 -1
- package/esm/ExpandIcon.js +15 -68
- package/esm/ExpandIcon.js.map +1 -1
- package/esm/FileIcon.js +7 -8
- package/esm/FileIcon.js.map +1 -1
- package/esm/InlineCodeHighlight.js +19 -55
- package/esm/InlineCodeHighlight.js.map +1 -1
- package/esm/src/mantine-code-highlight/src/CodeHighlight.js +46 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlight.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlight.module.css.js +4 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlight.module.css.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlight.theme.module.css.js +4 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlight.theme.module.css.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlightTabs.js +80 -0
- package/esm/src/mantine-code-highlight/src/CodeHighlightTabs.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/CopyIcon.js +17 -0
- package/esm/src/mantine-code-highlight/src/CopyIcon.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/ExpandIcon.js +23 -0
- package/esm/src/mantine-code-highlight/src/ExpandIcon.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/FileIcon.js +14 -0
- package/esm/src/mantine-code-highlight/src/FileIcon.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/InlineCodeHighlight.js +33 -0
- package/esm/src/mantine-code-highlight/src/InlineCodeHighlight.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/index.js +4 -0
- package/esm/src/mantine-code-highlight/src/index.js.map +1 -0
- package/esm/src/mantine-code-highlight/src/use-highlight.js +21 -0
- package/esm/src/mantine-code-highlight/src/use-highlight.js.map +1 -0
- package/esm/use-highlight.js +13 -12
- package/esm/use-highlight.js.map +1 -1
- package/package.json +16 -8
- package/tsconfig.build.tsbuildinfo +1 -1
- package/styles.css +0 -327
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import cx from 'clsx';
|
|
4
4
|
import { factory, useProps, useStyles, Box } from '@mantine/core';
|
|
@@ -6,64 +6,28 @@ import hljs from 'highlight.js';
|
|
|
6
6
|
import _classes from './CodeHighlight.module.css.js';
|
|
7
7
|
import themeClasses from './CodeHighlight.theme.module.css.js';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var __defProps = Object.defineProperties;
|
|
11
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
12
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
-
var __spreadValues = (a, b) => {
|
|
17
|
-
for (var prop in b || (b = {}))
|
|
18
|
-
if (__hasOwnProp.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
if (__getOwnPropSymbols)
|
|
21
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
-
if (__propIsEnum.call(b, prop))
|
|
23
|
-
__defNormalProp(a, prop, b[prop]);
|
|
24
|
-
}
|
|
25
|
-
return a;
|
|
26
|
-
};
|
|
27
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
28
|
-
var __objRest = (source, exclude) => {
|
|
29
|
-
var target = {};
|
|
30
|
-
for (var prop in source)
|
|
31
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
if (source != null && __getOwnPropSymbols)
|
|
34
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
35
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
36
|
-
target[prop] = source[prop];
|
|
37
|
-
}
|
|
38
|
-
return target;
|
|
39
|
-
};
|
|
40
|
-
const classes = __spreadProps(__spreadValues({}, _classes), { code: cx(_classes.code, themeClasses.theme) });
|
|
9
|
+
const classes = Object.assign(Object.assign({}, _classes), { code: cx(_classes.code, themeClasses.theme) });
|
|
41
10
|
const defaultProps = {
|
|
42
|
-
|
|
11
|
+
language: 'tsx',
|
|
43
12
|
};
|
|
44
13
|
const InlineCodeHighlight = factory((_props, ref) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
component: "code",
|
|
61
|
-
ref
|
|
62
|
-
}), others), {
|
|
63
|
-
dangerouslySetInnerHTML: { __html: highlighted }
|
|
64
|
-
}));
|
|
14
|
+
const props = useProps('InlineCodeHighlight', defaultProps, _props);
|
|
15
|
+
const { classNames, className, style, styles, unstyled, vars, code, language } = props, others = __rest(props, ["classNames", "className", "style", "styles", "unstyled", "vars", "code", "language"]);
|
|
16
|
+
const getStyles = useStyles({
|
|
17
|
+
name: 'InlineCodeHighlight',
|
|
18
|
+
props,
|
|
19
|
+
classes,
|
|
20
|
+
className,
|
|
21
|
+
style,
|
|
22
|
+
classNames,
|
|
23
|
+
styles,
|
|
24
|
+
unstyled,
|
|
25
|
+
rootSelector: 'code',
|
|
26
|
+
});
|
|
27
|
+
const highlighted = hljs.highlight(code.trim(), { language: language }).value;
|
|
28
|
+
return (React.createElement(Box, Object.assign({}, getStyles('code'), { component: "code", ref: ref }, others, { dangerouslySetInnerHTML: { __html: highlighted } })));
|
|
65
29
|
});
|
|
66
|
-
InlineCodeHighlight.displayName =
|
|
30
|
+
InlineCodeHighlight.displayName = '@mantine/core/InlineCodeHighlight';
|
|
67
31
|
|
|
68
32
|
export { InlineCodeHighlight };
|
|
69
33
|
//# sourceMappingURL=InlineCodeHighlight.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineCodeHighlight.js","sources":["../src/InlineCodeHighlight.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'clsx';\nimport {\n Box,\n BoxProps,\n StylesApiProps,\n factory,\n ElementProps,\n useProps,\n useStyles,\n Factory,\n} from '@mantine/core';\nimport hljs from 'highlight.js';\nimport _classes from './CodeHighlight.module.css';\nimport themeClasses from './CodeHighlight.theme.module.css';\n\nconst classes = { ..._classes, code: cx(_classes.code, themeClasses.theme) };\n\nexport type InlineCodeHighlightStylesNames = 'code';\nexport type InlineCodeHighlightVariant = string;\n\nexport interface InlineCodeHighlightProps\n extends BoxProps,\n StylesApiProps<InlineCodeHighlightFactory>,\n ElementProps<'div'> {\n /** Code to highlight */\n code: string;\n\n /** Code language, `'tsx'` by default */\n language?: string;\n}\n\nexport type InlineCodeHighlightFactory = Factory<{\n props: InlineCodeHighlightProps;\n ref: HTMLElement;\n stylesNames: InlineCodeHighlightStylesNames;\n}>;\n\nconst defaultProps: Partial<InlineCodeHighlightProps> = {\n language: 'tsx',\n};\n\nexport const InlineCodeHighlight = factory<InlineCodeHighlightFactory>((_props, ref) => {\n const props = useProps('InlineCodeHighlight', defaultProps, _props);\n const { classNames, className, style, styles, unstyled, vars, code, language, ...others } = props;\n\n const getStyles = useStyles<InlineCodeHighlightFactory>({\n name: 'InlineCodeHighlight',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n rootSelector: 'code',\n });\n\n const highlighted = hljs.highlight(code.trim(), { language: language! }).value;\n\n return (\n <Box\n {...getStyles('code')}\n component=\"code\"\n ref={ref}\n {...others}\n dangerouslySetInnerHTML={{ __html: highlighted }}\n />\n );\n});\n\nInlineCodeHighlight.displayName = '@mantine/core/InlineCodeHighlight';\n"],"names":[],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"InlineCodeHighlight.js","sources":["../src/InlineCodeHighlight.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'clsx';\nimport {\n Box,\n BoxProps,\n StylesApiProps,\n factory,\n ElementProps,\n useProps,\n useStyles,\n Factory,\n} from '@mantine/core';\nimport hljs from 'highlight.js';\nimport _classes from './CodeHighlight.module.css';\nimport themeClasses from './CodeHighlight.theme.module.css';\n\nconst classes = { ..._classes, code: cx(_classes.code, themeClasses.theme) };\n\nexport type InlineCodeHighlightStylesNames = 'code';\nexport type InlineCodeHighlightVariant = string;\n\nexport interface InlineCodeHighlightProps\n extends BoxProps,\n StylesApiProps<InlineCodeHighlightFactory>,\n ElementProps<'div'> {\n /** Code to highlight */\n code: string;\n\n /** Code language, `'tsx'` by default */\n language?: string;\n}\n\nexport type InlineCodeHighlightFactory = Factory<{\n props: InlineCodeHighlightProps;\n ref: HTMLElement;\n stylesNames: InlineCodeHighlightStylesNames;\n}>;\n\nconst defaultProps: Partial<InlineCodeHighlightProps> = {\n language: 'tsx',\n};\n\nexport const InlineCodeHighlight = factory<InlineCodeHighlightFactory>((_props, ref) => {\n const props = useProps('InlineCodeHighlight', defaultProps, _props);\n const { classNames, className, style, styles, unstyled, vars, code, language, ...others } = props;\n\n const getStyles = useStyles<InlineCodeHighlightFactory>({\n name: 'InlineCodeHighlight',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n rootSelector: 'code',\n });\n\n const highlighted = hljs.highlight(code.trim(), { language: language! }).value;\n\n return (\n <Box\n {...getStyles('code')}\n component=\"code\"\n ref={ref}\n {...others}\n dangerouslySetInnerHTML={{ __html: highlighted }}\n />\n );\n});\n\nInlineCodeHighlight.displayName = '@mantine/core/InlineCodeHighlight';\n"],"names":[],"mappings":";;;;;;;;AAgBA,MAAM,OAAO,mCAAQ,QAAQ,KAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,GAAE,CAAC;AAsB7E,MAAM,YAAY,GAAsC;IACtD,QAAQ,EAAE,KAAK;CAChB,CAAC;MAEW,mBAAmB,GAAG,OAAO,CAA6B,CAAC,MAAM,EAAE,GAAG;IACjF,MAAM,KAAK,GAAG,QAAQ,CAAC,qBAAqB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACpE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,KAAgB,KAAK,EAAhB,MAAM,UAAK,KAAK,EAA3F,sFAAmF,CAAQ,CAAC;IAElG,MAAM,SAAS,GAAG,SAAS,CAA6B;QACtD,IAAI,EAAE,qBAAqB;QAC3B,KAAK;QACL,OAAO;QACP,SAAS;QACT,KAAK;QACL,UAAU;QACV,MAAM;QACN,QAAQ;QACR,YAAY,EAAE,MAAM;KACrB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAS,EAAE,CAAC,CAAC,KAAK,CAAC;IAE/E,QACE,oBAAC,GAAG,oBACE,SAAS,CAAC,MAAM,CAAC,IACrB,SAAS,EAAC,MAAM,EAChB,GAAG,EAAE,GAAG,IACJ,MAAM,IACV,uBAAuB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,IAChD,EACF;AACJ,CAAC,EAAE;AAEH,mBAAmB,CAAC,WAAW,GAAG,mCAAmC;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import cx from 'clsx';
|
|
4
|
+
import { factory, useProps, useStyles, Box, CopyButton, Tooltip, ActionIcon, ScrollArea } from '@mantine/core';
|
|
5
|
+
import { useHighlight } from './use-highlight.js';
|
|
6
|
+
import { CopyIcon } from './CopyIcon.js';
|
|
7
|
+
import _classes from './CodeHighlight.module.css.js';
|
|
8
|
+
import themeClasses from './CodeHighlight.theme.module.css.js';
|
|
9
|
+
|
|
10
|
+
const classes = Object.assign(Object.assign({}, _classes), { root: cx(_classes.root, themeClasses.theme) });
|
|
11
|
+
const defaultProps = {
|
|
12
|
+
copyLabel: 'Copy code',
|
|
13
|
+
copiedLabel: 'Copied',
|
|
14
|
+
language: 'tsx',
|
|
15
|
+
withCopyButton: true,
|
|
16
|
+
};
|
|
17
|
+
const CodeHighlight = factory((_props, ref) => {
|
|
18
|
+
const props = useProps('CodeHighlight', defaultProps, _props);
|
|
19
|
+
const { classNames, className, style, styles, unstyled, vars, children, code, copiedLabel, copyLabel, language, withCopyButton, highlightOnClient } = props, others = __rest(props, ["classNames", "className", "style", "styles", "unstyled", "vars", "children", "code", "copiedLabel", "copyLabel", "language", "withCopyButton", "highlightOnClient"]);
|
|
20
|
+
const getStyles = useStyles({
|
|
21
|
+
name: 'CodeHighlight',
|
|
22
|
+
props,
|
|
23
|
+
classes,
|
|
24
|
+
className,
|
|
25
|
+
style,
|
|
26
|
+
classNames,
|
|
27
|
+
styles,
|
|
28
|
+
unstyled,
|
|
29
|
+
});
|
|
30
|
+
const getCodeProps = useHighlight({
|
|
31
|
+
code,
|
|
32
|
+
language: language,
|
|
33
|
+
highlightOnClient,
|
|
34
|
+
});
|
|
35
|
+
return (React.createElement(Box, Object.assign({}, getStyles('root'), { ref: ref }, others, { dir: "ltr" }),
|
|
36
|
+
withCopyButton && (React.createElement(CopyButton, { value: code.trim() }, ({ copied, copy }) => (React.createElement(Tooltip, { label: copied ? copiedLabel : copyLabel, fz: "sm", position: "left" },
|
|
37
|
+
React.createElement(ActionIcon, Object.assign({ onClick: copy, variant: "none" }, getStyles('copy')),
|
|
38
|
+
React.createElement(CopyIcon, { copied: copied })))))),
|
|
39
|
+
React.createElement(ScrollArea, { type: "auto", dir: "ltr", offsetScrollbars: false },
|
|
40
|
+
React.createElement("pre", Object.assign({}, getStyles('pre')),
|
|
41
|
+
React.createElement("code", Object.assign({}, getStyles('code'), getCodeProps()))))));
|
|
42
|
+
});
|
|
43
|
+
CodeHighlight.displayName = '@mantine/core/CodeHighlight';
|
|
44
|
+
|
|
45
|
+
export { CodeHighlight };
|
|
46
|
+
//# sourceMappingURL=CodeHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeHighlight.js","sources":["../../../../src/CodeHighlight.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'clsx';\nimport {\n Box,\n BoxProps,\n StylesApiProps,\n factory,\n ElementProps,\n useProps,\n useStyles,\n CopyButton,\n Tooltip,\n ActionIcon,\n ScrollArea,\n Factory,\n} from '@mantine/core';\nimport { useHighlight } from './use-highlight';\nimport { CopyIcon } from './CopyIcon';\nimport _classes from './CodeHighlight.module.css';\nimport themeClasses from './CodeHighlight.theme.module.css';\n\nconst classes = { ..._classes, root: cx(_classes.root, themeClasses.theme) };\n\nexport type CodeHighlightStylesNames = 'root' | 'code' | 'pre' | 'copy';\nexport type CodeHighlightVariant = string;\n\nexport interface CodeHighlightProps\n extends BoxProps,\n StylesApiProps<CodeHighlightFactory>,\n ElementProps<'div'> {\n /** Code to highlight */\n code: string;\n\n /** Code language, `'tsx'` by default */\n language?: string;\n\n /** Determines whether copy button should be displayed, `true` by default */\n withCopyButton?: boolean;\n\n /** Copy tooltip label, `'Copy code'` by default */\n copyLabel?: string;\n\n /** Copied tooltip label, `'Copied'` by default */\n copiedLabel?: string;\n\n /** Determines whether code should be highlighted only after component is mounted to the dom (disables code highlight on server), `false` by default */\n highlightOnClient?: boolean;\n}\n\nexport type CodeHighlightFactory = Factory<{\n props: CodeHighlightProps;\n ref: HTMLDivElement;\n stylesNames: CodeHighlightStylesNames;\n variant: CodeHighlightVariant;\n}>;\n\nconst defaultProps: Partial<CodeHighlightProps> = {\n copyLabel: 'Copy code',\n copiedLabel: 'Copied',\n language: 'tsx',\n withCopyButton: true,\n};\n\nexport const CodeHighlight = factory<CodeHighlightFactory>((_props, ref) => {\n const props = useProps('CodeHighlight', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n children,\n code,\n copiedLabel,\n copyLabel,\n language,\n withCopyButton,\n highlightOnClient,\n ...others\n } = props;\n\n const getStyles = useStyles<CodeHighlightFactory>({\n name: 'CodeHighlight',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n\n const getCodeProps = useHighlight({\n code,\n language: language!,\n highlightOnClient,\n });\n\n return (\n <Box {...getStyles('root')} ref={ref} {...others} dir=\"ltr\">\n {withCopyButton && (\n <CopyButton value={code.trim()}>\n {({ copied, copy }) => (\n <Tooltip label={copied ? copiedLabel : copyLabel} fz=\"sm\" position=\"left\">\n <ActionIcon onClick={copy} variant=\"none\" {...getStyles('copy')}>\n <CopyIcon copied={copied} />\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\n )}\n\n <ScrollArea type=\"auto\" dir=\"ltr\" offsetScrollbars={false}>\n <pre {...getStyles('pre')}>\n <code {...getStyles('code')} {...getCodeProps()} />\n </pre>\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,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,EAAE,EAAE,EAAC,IAAI,EAAC,QAAQ,EAAC,MAAM;YACvE,oBAAC,UAAU,kBAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,IAAK,SAAS,CAAC,MAAM,CAAC;gBAC7D,oBAAC,QAAQ,IAAC,MAAM,EAAE,MAAM,GAAI,CACjB,CACL,CACX,CACU,CACd;QAED,oBAAC,UAAU,IAAC,IAAI,EAAC,MAAM,EAAC,GAAG,EAAC,KAAK,EAAC,gBAAgB,EAAE,KAAK;YACvD,6CAAS,SAAS,CAAC,KAAK,CAAC;gBACvB,8CAAU,SAAS,CAAC,MAAM,CAAC,EAAM,YAAY,EAAE,EAAI,CAC/C,CACK,CACT,EACN;AACJ,CAAC,EAAE;AAEH,aAAa,CAAC,WAAW,GAAG,6BAA6B;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var _classes = {"code":"mantine-XIBJZDt","pre":"mantine-RDvBcjB","header":"mantine-cmEtjrV","controls":"mantine-059sM-t","copy":"mantine-tB-P5PD","control":"mantine-NTm-nGn","file":"mantine-PBrPXnu","files":"mantine-IvOddiX","codeWrapper":"mantine-YfYyOiA","showCodeButton":"mantine-haNyFRC","root":"mantine-k6OJW8l"};
|
|
2
|
+
|
|
3
|
+
export default _classes;
|
|
4
|
+
//# sourceMappingURL=CodeHighlight.module.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeHighlight.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeHighlight.theme.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import hljs from 'highlight.js';
|
|
4
|
+
import cx from 'clsx';
|
|
5
|
+
import { useUncontrolled } from '@mantine/hooks';
|
|
6
|
+
import { rem, createVarsResolver, factory, useProps, useStyles, UnstyledButton, Box, ScrollArea, Tooltip, ActionIcon, CopyButton } from '@mantine/core';
|
|
7
|
+
import { CopyIcon } from './CopyIcon.js';
|
|
8
|
+
import { FileIcon } from './FileIcon.js';
|
|
9
|
+
import { ExpandIcon } from './ExpandIcon.js';
|
|
10
|
+
import _classes from './CodeHighlight.module.css.js';
|
|
11
|
+
import themeClasses from './CodeHighlight.theme.module.css.js';
|
|
12
|
+
|
|
13
|
+
const classes = Object.assign(Object.assign({}, _classes), { root: cx(_classes.root, themeClasses.theme) });
|
|
14
|
+
const defaultProps = {
|
|
15
|
+
withHeader: true,
|
|
16
|
+
copyLabel: 'Copy code',
|
|
17
|
+
copiedLabel: 'Copied',
|
|
18
|
+
maxCollapsedHeight: rem('8rem'),
|
|
19
|
+
expandCodeLabel: 'Expand code',
|
|
20
|
+
collapseCodeLabel: 'Collapse code',
|
|
21
|
+
};
|
|
22
|
+
const varsResolver = createVarsResolver((_, { maxCollapsedHeight }) => ({
|
|
23
|
+
root: { '--ch-max-collapsed-height': rem(maxCollapsedHeight) },
|
|
24
|
+
}));
|
|
25
|
+
const CodeHighlightTabs = factory((_props, ref) => {
|
|
26
|
+
const props = useProps('CodeHighlightTabs', defaultProps, _props);
|
|
27
|
+
const { classNames, className, style, styles, unstyled, vars, children, code, defaultActiveTab, activeTab, onTabChange, withHeader, copiedLabel, copyLabel, getFileIcon, maxCollapsedHeight, expanded, defaultExpanded, onExpandedChange, expandCodeLabel, collapseCodeLabel, withExpandButton } = props, others = __rest(props, ["classNames", "className", "style", "styles", "unstyled", "vars", "children", "code", "defaultActiveTab", "activeTab", "onTabChange", "withHeader", "copiedLabel", "copyLabel", "getFileIcon", "maxCollapsedHeight", "expanded", "defaultExpanded", "onExpandedChange", "expandCodeLabel", "collapseCodeLabel", "withExpandButton"]);
|
|
28
|
+
const getStyles = useStyles({
|
|
29
|
+
name: 'CodeHighlightTabs',
|
|
30
|
+
props,
|
|
31
|
+
classes,
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
classNames,
|
|
35
|
+
styles,
|
|
36
|
+
unstyled,
|
|
37
|
+
vars,
|
|
38
|
+
varsResolver,
|
|
39
|
+
});
|
|
40
|
+
const [value, setValue] = useUncontrolled({
|
|
41
|
+
defaultValue: defaultActiveTab,
|
|
42
|
+
value: activeTab,
|
|
43
|
+
finalValue: 0,
|
|
44
|
+
onChange: onTabChange,
|
|
45
|
+
});
|
|
46
|
+
const [_expanded, setExpanded] = useUncontrolled({
|
|
47
|
+
defaultValue: defaultExpanded,
|
|
48
|
+
value: expanded,
|
|
49
|
+
finalValue: true,
|
|
50
|
+
onChange: onExpandedChange,
|
|
51
|
+
});
|
|
52
|
+
const nodes = Array.isArray(code) ? code : [code];
|
|
53
|
+
const currentCode = nodes[value];
|
|
54
|
+
const highlighted = hljs.highlight(currentCode.code.trim(), {
|
|
55
|
+
language: currentCode.language,
|
|
56
|
+
}).value;
|
|
57
|
+
const files = nodes.map((node, index) => (React.createElement(UnstyledButton, Object.assign({}, getStyles('file'), { key: node.fileName, mod: { active: index === value }, onClick: () => setValue(index) }),
|
|
58
|
+
React.createElement(FileIcon, { fileIcon: node.icon, getFileIcon: getFileIcon, fileName: node.fileName }),
|
|
59
|
+
React.createElement("span", null, node.fileName))));
|
|
60
|
+
return (React.createElement(Box, Object.assign({}, getStyles('root'), { ref: ref }, others, { dir: "ltr" }),
|
|
61
|
+
withHeader && (React.createElement("div", Object.assign({}, getStyles('header')),
|
|
62
|
+
React.createElement(ScrollArea, { type: "never", dir: "ltr", offsetScrollbars: false },
|
|
63
|
+
React.createElement("div", Object.assign({}, getStyles('files')), files)),
|
|
64
|
+
React.createElement("div", Object.assign({}, getStyles('controls')),
|
|
65
|
+
withExpandButton && (React.createElement(Tooltip, { label: _expanded ? collapseCodeLabel : expandCodeLabel, fz: "sm", position: "left" },
|
|
66
|
+
React.createElement(ActionIcon, Object.assign({ onClick: () => setExpanded(!_expanded), variant: "none" }, getStyles('control')),
|
|
67
|
+
React.createElement(ExpandIcon, { expanded: _expanded })))),
|
|
68
|
+
React.createElement(CopyButton, { value: currentCode.code.trim() }, ({ copied, copy }) => (React.createElement(Tooltip, { label: copied ? copiedLabel : copyLabel, fz: "sm", position: "left" },
|
|
69
|
+
React.createElement(ActionIcon, Object.assign({ onClick: copy, variant: "none" }, getStyles('control')),
|
|
70
|
+
React.createElement(CopyIcon, { copied: copied })))))))),
|
|
71
|
+
React.createElement(ScrollArea, { type: "auto", dir: "ltr", offsetScrollbars: false },
|
|
72
|
+
React.createElement(Box, Object.assign({}, getStyles('codeWrapper'), { mod: { expanded: _expanded } }),
|
|
73
|
+
React.createElement("pre", Object.assign({}, getStyles('pre')),
|
|
74
|
+
React.createElement("code", Object.assign({}, getStyles('code'), { dangerouslySetInnerHTML: { __html: highlighted } }))))),
|
|
75
|
+
React.createElement(UnstyledButton, Object.assign({}, getStyles('showCodeButton'), { mod: { hidden: _expanded }, onClick: () => setExpanded(true) }), "Expand code")));
|
|
76
|
+
});
|
|
77
|
+
CodeHighlightTabs.displayName = '@mantine/core/CodeHighlightTabs';
|
|
78
|
+
|
|
79
|
+
export { CodeHighlightTabs };
|
|
80
|
+
//# sourceMappingURL=CodeHighlightTabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeHighlightTabs.js","sources":["../../../../src/CodeHighlightTabs.tsx"],"sourcesContent":["import React from 'react';\nimport hljs from 'highlight.js';\nimport cx from 'clsx';\nimport { useUncontrolled } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n StylesApiProps,\n factory,\n ElementProps,\n useProps,\n useStyles,\n CopyButton,\n Tooltip,\n ActionIcon,\n UnstyledButton,\n ScrollArea,\n createVarsResolver,\n rem,\n Factory,\n} from '@mantine/core';\nimport { CopyIcon } from './CopyIcon';\nimport { FileIcon } from './FileIcon';\nimport { ExpandIcon } from './ExpandIcon';\nimport _classes from './CodeHighlight.module.css';\nimport themeClasses from './CodeHighlight.theme.module.css';\n\nconst classes = { ..._classes, root: cx(_classes.root, themeClasses.theme) };\n\nexport type CodeHighlightTabsStylesNames =\n | 'root'\n | 'code'\n | 'codeWrapper'\n | 'showCodeButton'\n | 'pre'\n | 'controls'\n | 'control'\n | 'header'\n | 'file'\n | 'files';\n\nexport type CodeHighlightTabsVariant = string;\nexport type CodeHighlightTabsCssVariables = {\n root: '--ch-max-collapsed-height';\n};\n\nexport interface CodeHighlightTabsCode {\n language?: string;\n code: string;\n fileName?: string;\n icon?: React.ReactNode;\n}\n\nexport interface CodeHighlightTabsProps\n extends BoxProps,\n StylesApiProps<CodeHighlightTabsFactory>,\n ElementProps<'div'> {\n /** Code to highlight with meta data (file name and icon) */\n code: CodeHighlightTabsCode | CodeHighlightTabsCode[];\n\n /** Default active tab index */\n defaultActiveTab?: number;\n\n /** Index of controlled active tab state */\n activeTab?: number;\n\n /** Called when tab changes */\n onTabChange?(tab: number): void;\n\n /** Determines whether header with file names and copy button should be rendered, `true` by default */\n withHeader?: boolean;\n\n /** Copy tooltip label, `'Copy code'` by default */\n copyLabel?: string;\n\n /** Copied tooltip label, `'Copied'` by default */\n copiedLabel?: string;\n\n /** Function that returns icon based on file name */\n getFileIcon?(fileName: string): React.ReactNode;\n\n /** `max-height` of code in collapsed state */\n maxCollapsedHeight?: React.CSSProperties['maxHeight'];\n\n /** Controlled expanded state */\n expanded?: boolean;\n\n /** Uncontrolled expanded state initial value */\n defaultExpanded?: boolean;\n\n /** Called when expanded state changes */\n onExpandedChange?(expanded: boolean): void;\n\n /** Expand button label and tooltip, `'Expand code'` by default */\n expandCodeLabel?: string;\n\n /** Collapse button label and tooltip, `'Collapse code'` by default */\n collapseCodeLabel?: string;\n\n /** Determines whether to show the expand button, `false` by default */\n withExpandButton?: boolean;\n}\n\nexport type CodeHighlightTabsFactory = Factory<{\n props: CodeHighlightTabsProps;\n ref: HTMLDivElement;\n stylesNames: CodeHighlightTabsStylesNames;\n}>;\n\nconst defaultProps: Partial<CodeHighlightTabsProps> = {\n withHeader: true,\n copyLabel: 'Copy code',\n copiedLabel: 'Copied',\n maxCollapsedHeight: rem('8rem'),\n expandCodeLabel: 'Expand code',\n collapseCodeLabel: 'Collapse code',\n};\n\nconst varsResolver = createVarsResolver<CodeHighlightTabsFactory>((_, { maxCollapsedHeight }) => ({\n root: { '--ch-max-collapsed-height': rem(maxCollapsedHeight) },\n}));\n\nexport const CodeHighlightTabs = factory<CodeHighlightTabsFactory>((_props, ref) => {\n const props = useProps('CodeHighlightTabs', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n children,\n code,\n defaultActiveTab,\n activeTab,\n onTabChange,\n withHeader,\n copiedLabel,\n copyLabel,\n getFileIcon,\n maxCollapsedHeight,\n expanded,\n defaultExpanded,\n onExpandedChange,\n expandCodeLabel,\n collapseCodeLabel,\n withExpandButton,\n ...others\n } = props;\n\n const getStyles = useStyles<CodeHighlightTabsFactory>({\n name: 'CodeHighlightTabs',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n varsResolver,\n });\n\n const [value, setValue] = useUncontrolled({\n defaultValue: defaultActiveTab,\n value: activeTab,\n finalValue: 0,\n onChange: onTabChange,\n });\n\n const [_expanded, setExpanded] = useUncontrolled({\n defaultValue: defaultExpanded,\n value: expanded,\n finalValue: true,\n onChange: onExpandedChange,\n });\n\n const nodes = Array.isArray(code) ? code : [code];\n const currentCode = nodes[value];\n\n const highlighted = hljs.highlight(currentCode.code.trim(), {\n language: currentCode.language!,\n }).value;\n\n const files = nodes.map((node, index) => (\n <UnstyledButton\n {...getStyles('file')}\n key={node.fileName}\n mod={{ active: index === value }}\n onClick={() => setValue(index)}\n >\n <FileIcon fileIcon={node.icon} getFileIcon={getFileIcon} fileName={node.fileName} />\n <span>{node.fileName}</span>\n </UnstyledButton>\n ));\n\n return (\n <Box {...getStyles('root')} ref={ref} {...others} dir=\"ltr\">\n {withHeader && (\n <div {...getStyles('header')}>\n <ScrollArea type=\"never\" dir=\"ltr\" offsetScrollbars={false}>\n <div {...getStyles('files')}>{files}</div>\n </ScrollArea>\n <div {...getStyles('controls')}>\n {withExpandButton && (\n <Tooltip\n label={_expanded ? collapseCodeLabel : expandCodeLabel}\n fz=\"sm\"\n position=\"left\"\n >\n <ActionIcon\n onClick={() => setExpanded(!_expanded)}\n variant=\"none\"\n {...getStyles('control')}\n >\n <ExpandIcon expanded={_expanded} />\n </ActionIcon>\n </Tooltip>\n )}\n\n <CopyButton value={currentCode.code.trim()}>\n {({ copied, copy }) => (\n <Tooltip label={copied ? copiedLabel : copyLabel} fz=\"sm\" position=\"left\">\n <ActionIcon onClick={copy} variant=\"none\" {...getStyles('control')}>\n <CopyIcon copied={copied} />\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\n </div>\n </div>\n )}\n\n <ScrollArea type=\"auto\" dir=\"ltr\" offsetScrollbars={false}>\n <Box {...getStyles('codeWrapper')} mod={{ expanded: _expanded }}>\n <pre {...getStyles('pre')}>\n <code {...getStyles('code')} dangerouslySetInnerHTML={{ __html: highlighted }} />\n </pre>\n </Box>\n </ScrollArea>\n <UnstyledButton\n {...getStyles('showCodeButton')}\n mod={{ hidden: _expanded }}\n onClick={() => setExpanded(true)}\n >\n Expand code\n </UnstyledButton>\n </Box>\n );\n});\n\nCodeHighlightTabs.displayName = '@mantine/core/CodeHighlightTabs';\n"],"names":[],"mappings":";;;;;;;;;;;;AA2BA,MAAM,OAAO,mCAAQ,QAAQ,KAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,GAAE,CAAC;AAkF7E,MAAM,YAAY,GAAoC;IACpD,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,QAAQ;IACrB,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC;IAC/B,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AG,iCAAiC;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { rem } from '@mantine/core';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
function CopyIcon(_a) {
|
|
6
|
+
var { copied, style } = _a, others = __rest(_a, ["copied", "style"]);
|
|
7
|
+
return (React.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", style: Object.assign({ width: rem(18), height: rem(18) }, style), viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", fill: "none", strokeLinecap: "round", strokeLinejoin: "round" }, others), copied ? (React.createElement(React.Fragment, null,
|
|
8
|
+
React.createElement("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
9
|
+
React.createElement("path", { d: "M5 12l5 5l10 -10" }))) : (React.createElement(React.Fragment, null,
|
|
10
|
+
React.createElement("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
11
|
+
React.createElement("path", { d: "M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z" }),
|
|
12
|
+
React.createElement("path", { d: "M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2" })))));
|
|
13
|
+
}
|
|
14
|
+
CopyIcon.displayName = '@mantine/code-highlight/CopyIcon';
|
|
15
|
+
|
|
16
|
+
export { CopyIcon };
|
|
17
|
+
//# sourceMappingURL=CopyIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyIcon.js","sources":["../../../../src/CopyIcon.tsx"],"sourcesContent":["import { rem } from '@mantine/core';\nimport React from 'react';\n\ninterface CopyIconProps extends React.ComponentPropsWithoutRef<'svg'> {\n copied: boolean;\n}\n\nexport function CopyIcon({ copied, style, ...others }: CopyIconProps) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n style={{ width: rem(18), height: rem(18), ...style }}\n viewBox=\"0 0 24 24\"\n strokeWidth=\"2\"\n stroke=\"currentColor\"\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...others}\n >\n {copied ? (\n <>\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path>\n <path d=\"M5 12l5 5l10 -10\"></path>\n </>\n ) : (\n <>\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path>\n <path d=\"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z\"></path>\n <path d=\"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2\"></path>\n </>\n )}\n </svg>\n );\n}\n\nCopyIcon.displayName = '@mantine/code-highlight/CopyIcon';\n"],"names":[],"mappings":";;;;SAOgB,QAAQ,CAAC,EAA2C;QAA3C,EAAE,MAAM,EAAE,KAAK,OAA4B,EAAvB,MAAM,cAA1B,mBAA4B,CAAF;IACjD,QACE,2CACE,KAAK,EAAC,4BAA4B,EAClC,KAAK,kBAAI,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAK,KAAK,GAClD,OAAO,EAAC,WAAW,EACnB,WAAW,EAAC,GAAG,EACf,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,MAAM,EACX,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,IAClB,MAAM,GAET,MAAM,IACL;QACE,8BAAM,MAAM,EAAC,MAAM,EAAC,CAAC,EAAC,eAAe,EAAC,IAAI,EAAC,MAAM,GAAQ;QACzD,8BAAM,CAAC,EAAC,kBAAkB,GAAQ,CACjC,KAEH;QACE,8BAAM,MAAM,EAAC,MAAM,EAAC,CAAC,EAAC,eAAe,EAAC,IAAI,EAAC,MAAM,GAAQ;QACzD,8BAAM,CAAC,EAAC,8EAA8E,GAAQ;QAC9F,8BAAM,CAAC,EAAC,8DAA8D,GAAQ,CAC7E,CACJ,CACG,EACN;AACJ,CAAC;AAED,QAAQ,CAAC,WAAW,GAAG,kCAAkC;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { rem } from '@mantine/core';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
function ExpandIcon(_a) {
|
|
6
|
+
var { expanded, style } = _a, others = __rest(_a, ["expanded", "style"]);
|
|
7
|
+
return (React.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", style: Object.assign({ width: rem(18), height: rem(18) }, style), viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", fill: "none", strokeLinecap: "round", strokeLinejoin: "round" }, others), expanded ? (React.createElement(React.Fragment, null,
|
|
8
|
+
React.createElement("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
9
|
+
React.createElement("path", { d: "M12 13v-8l-3 3m6 0l-3 -3" }),
|
|
10
|
+
React.createElement("path", { d: "M9 17l1 0" }),
|
|
11
|
+
React.createElement("path", { d: "M14 17l1 0" }),
|
|
12
|
+
React.createElement("path", { d: "M19 17l1 0" }),
|
|
13
|
+
React.createElement("path", { d: "M4 17l1 0" }))) : (React.createElement(React.Fragment, null,
|
|
14
|
+
React.createElement("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
15
|
+
React.createElement("path", { d: "M12 11v8l3 -3m-6 0l3 3" }),
|
|
16
|
+
React.createElement("path", { d: "M9 7l1 0" }),
|
|
17
|
+
React.createElement("path", { d: "M14 7l1 0" }),
|
|
18
|
+
React.createElement("path", { d: "M19 7l1 0" }),
|
|
19
|
+
React.createElement("path", { d: "M4 7l1 0" })))));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { ExpandIcon };
|
|
23
|
+
//# sourceMappingURL=ExpandIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpandIcon.js","sources":["../../../../src/ExpandIcon.tsx"],"sourcesContent":["import { rem } from '@mantine/core';\nimport React from 'react';\n\ninterface ExpandIconProps extends React.ComponentPropsWithoutRef<'svg'> {\n expanded: boolean;\n}\n\nexport function ExpandIcon({ expanded, style, ...others }: ExpandIconProps) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n style={{ width: rem(18), height: rem(18), ...style }}\n viewBox=\"0 0 24 24\"\n strokeWidth=\"2\"\n stroke=\"currentColor\"\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...others}\n >\n {expanded ? (\n <>\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\n <path d=\"M12 13v-8l-3 3m6 0l-3 -3\" />\n <path d=\"M9 17l1 0\" />\n <path d=\"M14 17l1 0\" />\n <path d=\"M19 17l1 0\" />\n <path d=\"M4 17l1 0\" />\n </>\n ) : (\n <>\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\n <path d=\"M12 11v8l3 -3m-6 0l3 3\" />\n <path d=\"M9 7l1 0\" />\n <path d=\"M14 7l1 0\" />\n <path d=\"M19 7l1 0\" />\n <path d=\"M4 7l1 0\" />\n </>\n )}\n </svg>\n );\n}\n"],"names":[],"mappings":";;;;SAOgB,UAAU,CAAC,EAA+C;QAA/C,EAAE,QAAQ,EAAE,KAAK,OAA8B,EAAzB,MAAM,cAA5B,qBAA8B,CAAF;IACrD,QACE,2CACE,KAAK,EAAC,4BAA4B,EAClC,KAAK,kBAAI,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAK,KAAK,GAClD,OAAO,EAAC,WAAW,EACnB,WAAW,EAAC,GAAG,EACf,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,MAAM,EACX,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,IAClB,MAAM,GAET,QAAQ,IACP;QACE,8BAAM,MAAM,EAAC,MAAM,EAAC,CAAC,EAAC,eAAe,EAAC,IAAI,EAAC,MAAM,GAAG;QACpD,8BAAM,CAAC,EAAC,0BAA0B,GAAG;QACrC,8BAAM,CAAC,EAAC,WAAW,GAAG;QACtB,8BAAM,CAAC,EAAC,YAAY,GAAG;QACvB,8BAAM,CAAC,EAAC,YAAY,GAAG;QACvB,8BAAM,CAAC,EAAC,WAAW,GAAG,CACrB,KAEH;QACE,8BAAM,MAAM,EAAC,MAAM,EAAC,CAAC,EAAC,eAAe,EAAC,IAAI,EAAC,MAAM,GAAG;QACpD,8BAAM,CAAC,EAAC,wBAAwB,GAAG;QACnC,8BAAM,CAAC,EAAC,UAAU,GAAG;QACrB,8BAAM,CAAC,EAAC,WAAW,GAAG;QACtB,8BAAM,CAAC,EAAC,WAAW,GAAG;QACtB,8BAAM,CAAC,EAAC,UAAU,GAAG,CACpB,CACJ,CACG,EACN;AACJ;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
function FileIcon({ fileIcon, fileName, getFileIcon }) {
|
|
4
|
+
if (fileIcon) {
|
|
5
|
+
return React.createElement(React.Fragment, null, fileIcon);
|
|
6
|
+
}
|
|
7
|
+
if (getFileIcon && fileName) {
|
|
8
|
+
return React.createElement(React.Fragment, null, getFileIcon(fileName));
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { FileIcon };
|
|
14
|
+
//# sourceMappingURL=FileIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileIcon.js","sources":["../../../../src/FileIcon.tsx"],"sourcesContent":["import React from 'react';\n\ninterface FileIconProps {\n fileName: string | undefined;\n getFileIcon?: ((fileName: string) => React.ReactNode) | undefined;\n fileIcon: React.ReactNode | undefined;\n}\n\nexport function FileIcon({ fileIcon, fileName, getFileIcon }: FileIconProps) {\n if (fileIcon) {\n return <>{fileIcon}</>;\n }\n\n if (getFileIcon && fileName) {\n return <>{getFileIcon(fileName)}</>;\n }\n\n return null;\n}\n"],"names":[],"mappings":";;SAQgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAiB;IACzE,IAAI,QAAQ,EAAE;QACZ,OAAO,0CAAG,QAAQ,CAAI,CAAC;KACxB;IAED,IAAI,WAAW,IAAI,QAAQ,EAAE;QAC3B,OAAO,0CAAG,WAAW,CAAC,QAAQ,CAAC,CAAI,CAAC;KACrC;IAED,OAAO,IAAI,CAAC;AACd;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __rest } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import cx from 'clsx';
|
|
4
|
+
import { factory, useProps, useStyles, Box } from '@mantine/core';
|
|
5
|
+
import hljs from 'highlight.js';
|
|
6
|
+
import _classes from './CodeHighlight.module.css.js';
|
|
7
|
+
import themeClasses from './CodeHighlight.theme.module.css.js';
|
|
8
|
+
|
|
9
|
+
const classes = Object.assign(Object.assign({}, _classes), { code: cx(_classes.code, themeClasses.theme) });
|
|
10
|
+
const defaultProps = {
|
|
11
|
+
language: 'tsx',
|
|
12
|
+
};
|
|
13
|
+
const InlineCodeHighlight = factory((_props, ref) => {
|
|
14
|
+
const props = useProps('InlineCodeHighlight', defaultProps, _props);
|
|
15
|
+
const { classNames, className, style, styles, unstyled, vars, code, language } = props, others = __rest(props, ["classNames", "className", "style", "styles", "unstyled", "vars", "code", "language"]);
|
|
16
|
+
const getStyles = useStyles({
|
|
17
|
+
name: 'InlineCodeHighlight',
|
|
18
|
+
props,
|
|
19
|
+
classes,
|
|
20
|
+
className,
|
|
21
|
+
style,
|
|
22
|
+
classNames,
|
|
23
|
+
styles,
|
|
24
|
+
unstyled,
|
|
25
|
+
rootSelector: 'code',
|
|
26
|
+
});
|
|
27
|
+
const highlighted = hljs.highlight(code.trim(), { language: language }).value;
|
|
28
|
+
return (React.createElement(Box, Object.assign({}, getStyles('code'), { component: "code", ref: ref }, others, { dangerouslySetInnerHTML: { __html: highlighted } })));
|
|
29
|
+
});
|
|
30
|
+
InlineCodeHighlight.displayName = '@mantine/core/InlineCodeHighlight';
|
|
31
|
+
|
|
32
|
+
export { InlineCodeHighlight };
|
|
33
|
+
//# sourceMappingURL=InlineCodeHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InlineCodeHighlight.js","sources":["../../../../src/InlineCodeHighlight.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'clsx';\nimport {\n Box,\n BoxProps,\n StylesApiProps,\n factory,\n ElementProps,\n useProps,\n useStyles,\n Factory,\n} from '@mantine/core';\nimport hljs from 'highlight.js';\nimport _classes from './CodeHighlight.module.css';\nimport themeClasses from './CodeHighlight.theme.module.css';\n\nconst classes = { ..._classes, code: cx(_classes.code, themeClasses.theme) };\n\nexport type InlineCodeHighlightStylesNames = 'code';\nexport type InlineCodeHighlightVariant = string;\n\nexport interface InlineCodeHighlightProps\n extends BoxProps,\n StylesApiProps<InlineCodeHighlightFactory>,\n ElementProps<'div'> {\n /** Code to highlight */\n code: string;\n\n /** Code language, `'tsx'` by default */\n language?: string;\n}\n\nexport type InlineCodeHighlightFactory = Factory<{\n props: InlineCodeHighlightProps;\n ref: HTMLElement;\n stylesNames: InlineCodeHighlightStylesNames;\n}>;\n\nconst defaultProps: Partial<InlineCodeHighlightProps> = {\n language: 'tsx',\n};\n\nexport const InlineCodeHighlight = factory<InlineCodeHighlightFactory>((_props, ref) => {\n const props = useProps('InlineCodeHighlight', defaultProps, _props);\n const { classNames, className, style, styles, unstyled, vars, code, language, ...others } = props;\n\n const getStyles = useStyles<InlineCodeHighlightFactory>({\n name: 'InlineCodeHighlight',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n rootSelector: 'code',\n });\n\n const highlighted = hljs.highlight(code.trim(), { language: language! }).value;\n\n return (\n <Box\n {...getStyles('code')}\n component=\"code\"\n ref={ref}\n {...others}\n dangerouslySetInnerHTML={{ __html: highlighted }}\n />\n );\n});\n\nInlineCodeHighlight.displayName = '@mantine/core/InlineCodeHighlight';\n"],"names":[],"mappings":";;;;;;;;AAgBA,MAAM,OAAO,mCAAQ,QAAQ,KAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,GAAE,CAAC;AAsB7E,MAAM,YAAY,GAAsC;IACtD,QAAQ,EAAE,KAAK;CAChB,CAAC;MAEW,mBAAmB,GAAG,OAAO,CAA6B,CAAC,MAAM,EAAE,GAAG;IACjF,MAAM,KAAK,GAAG,QAAQ,CAAC,qBAAqB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACpE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,KAAgB,KAAK,EAAhB,MAAM,UAAK,KAAK,EAA3F,sFAAmF,CAAQ,CAAC;IAElG,MAAM,SAAS,GAAG,SAAS,CAA6B;QACtD,IAAI,EAAE,qBAAqB;QAC3B,KAAK;QACL,OAAO;QACP,SAAS;QACT,KAAK;QACL,UAAU;QACV,MAAM;QACN,QAAQ;QACR,YAAY,EAAE,MAAM;KACrB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAS,EAAE,CAAC,CAAC,KAAK,CAAC;IAE/E,QACE,oBAAC,GAAG,oBACE,SAAS,CAAC,MAAM,CAAC,IACrB,SAAS,EAAC,MAAM,EAChB,GAAG,EAAE,GAAG,IACJ,MAAM,IACV,uBAAuB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,IAChD,EACF;AACJ,CAAC,EAAE;AAEH,mBAAmB,CAAC,WAAW,GAAG,mCAAmC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import hljs from 'highlight.js';
|
|
3
|
+
|
|
4
|
+
function useHighlight({ code, language, highlightOnClient }) {
|
|
5
|
+
const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language }).value;
|
|
6
|
+
const [highlighted, setHighlighted] = useState(!highlightOnClient);
|
|
7
|
+
const [highlightedCode, setHighlightedCode] = useState(highlightOnClient ? code : getHighlightedCode());
|
|
8
|
+
const getCodeProps = () => highlighted
|
|
9
|
+
? { dangerouslySetInnerHTML: { __html: highlightedCode } }
|
|
10
|
+
: { children: code.trim() };
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (highlightOnClient) {
|
|
13
|
+
setHighlightedCode(getHighlightedCode());
|
|
14
|
+
setHighlighted(true);
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
return getCodeProps;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { useHighlight };
|
|
21
|
+
//# sourceMappingURL=use-highlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-highlight.js","sources":["../../../../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":";;;SASgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAqB;IACnF,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAS,EAAE,CAAC,CAAC,KAAK,CAAC;IAC5F,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACnE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CACpD,iBAAiB,GAAG,IAAI,GAAG,kBAAkB,EAAE,CAChD,CAAC;IAEF,MAAM,YAAY,GAAG,MACnB,WAAW;UACP,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;UACxD,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;IAEhC,SAAS,CAAC;QACR,IAAI,iBAAiB,EAAE;YACrB,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,CAAC;YACzC,cAAc,CAAC,IAAI,CAAC,CAAC;SACtB;KACF,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,YAAY,CAAC;AACtB;;;;"}
|
package/esm/use-highlight.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
'use client';
|
|
2
1
|
import { useState, useEffect } from 'react';
|
|
3
2
|
import hljs from 'highlight.js';
|
|
4
3
|
|
|
5
4
|
function useHighlight({ code, language, highlightOnClient }) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language }).value;
|
|
6
|
+
const [highlighted, setHighlighted] = useState(!highlightOnClient);
|
|
7
|
+
const [highlightedCode, setHighlightedCode] = useState(highlightOnClient ? code : getHighlightedCode());
|
|
8
|
+
const getCodeProps = () => highlighted
|
|
9
|
+
? { dangerouslySetInnerHTML: { __html: highlightedCode } }
|
|
10
|
+
: { children: code.trim() };
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (highlightOnClient) {
|
|
13
|
+
setHighlightedCode(getHighlightedCode());
|
|
14
|
+
setHighlighted(true);
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
return getCodeProps;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export { useHighlight };
|
package/esm/use-highlight.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-highlight.js","sources":["../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-highlight.js","sources":["../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":";;;SASgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAqB;IACnF,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAS,EAAE,CAAC,CAAC,KAAK,CAAC;IAC5F,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACnE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CACpD,iBAAiB,GAAG,IAAI,GAAG,kBAAkB,EAAE,CAChD,CAAC;IAEF,MAAM,YAAY,GAAG,MACnB,WAAW;UACP,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;UACxD,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;IAEhC,SAAS,CAAC;QACR,IAAI,iBAAiB,EAAE;YACrB,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,CAAC;YACzC,cAAc,CAAC,IAAI,CAAC,CAAC;SACtB;KACF,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,YAAY,CAAC;AACtB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/code-highlight",
|
|
3
3
|
"description": "Code highlight with Mantine theme",
|
|
4
|
-
"version": "7.0.0-alpha.
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
4
|
+
"version": "7.0.0-alpha.9",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./esm/index.js",
|
|
9
|
+
"require": "./cjs/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./styles.css": "./esm/index.css"
|
|
12
|
+
},
|
|
8
13
|
"license": "MIT",
|
|
9
14
|
"author": "Vitaly Rtishchev <rtivital@gmail.com>",
|
|
10
|
-
"sideEffects":
|
|
15
|
+
"sideEffects": [
|
|
16
|
+
"*.css"
|
|
17
|
+
],
|
|
11
18
|
"homepage": "https://mantine.dev/others/prism/",
|
|
12
19
|
"repository": {
|
|
13
20
|
"url": "https://github.com/mantinedev/mantine.git",
|
|
@@ -29,14 +36,15 @@
|
|
|
29
36
|
"syntax-highlight"
|
|
30
37
|
],
|
|
31
38
|
"peerDependencies": {
|
|
32
|
-
"@mantine/core": "7.0.0-alpha.
|
|
33
|
-
"@mantine/hooks": "7.0.0-alpha.
|
|
39
|
+
"@mantine/core": "7.0.0-alpha.9",
|
|
40
|
+
"@mantine/hooks": "7.0.0-alpha.9",
|
|
34
41
|
"react": ">=16.8.0",
|
|
35
42
|
"react-dom": ">=16.8.0"
|
|
36
43
|
},
|
|
37
44
|
"dependencies": {
|
|
38
45
|
"highlight.js": "^11.7.0",
|
|
39
|
-
"clsx": "1.1.1"
|
|
46
|
+
"clsx": "1.1.1",
|
|
47
|
+
"tslib": "^2.5.2"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {}
|
|
42
50
|
}
|