@dxos/react-ui-syntax-highlighter 0.6.11-staging.32b42e4
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 +8 -0
- package/README.md +3 -0
- package/dist/lib/browser/index.mjs +22 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/types/src/SyntaxHighlighter.d.ts +11 -0
- package/dist/types/src/SyntaxHighlighter.d.ts.map +1 -0
- package/dist/types/src/SyntaxHighlighter.stories.d.ts +26 -0
- package/dist/types/src/SyntaxHighlighter.stories.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/package.json +45 -0
- package/src/SyntaxHighlighter.stories.tsx +36 -0
- package/src/SyntaxHighlighter.tsx +43 -0
- package/src/index.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// packages/ui/react-ui-syntax-highlighter/src/SyntaxHighlighter.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import NativeSyntaxHighlighter from "react-syntax-highlighter";
|
|
4
|
+
import styleDark from "react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark";
|
|
5
|
+
import styleLight from "react-syntax-highlighter/dist/esm/styles/hljs/a11y-light";
|
|
6
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
7
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
8
|
+
var zeroWidthSpace = "\u200B";
|
|
9
|
+
var SyntaxHighlighter = ({ classNames, fallback = zeroWidthSpace, children, ...props }) => {
|
|
10
|
+
const { themeMode } = useThemeContext();
|
|
11
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
12
|
+
role: "none",
|
|
13
|
+
className: mx("w-full", classNames)
|
|
14
|
+
}, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
|
|
15
|
+
...props,
|
|
16
|
+
style: themeMode === "dark" ? styleDark : styleLight
|
|
17
|
+
}, children || fallback));
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
SyntaxHighlighter
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/SyntaxHighlighter.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\nimport NativeSyntaxHighlighter, {\n type SyntaxHighlighterProps as NativeSyntaxHighlighterProps,\n} from 'react-syntax-highlighter';\n// eslint-disable-next-line no-restricted-imports\nimport styleDark from 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark';\n// eslint-disable-next-line no-restricted-imports\nimport styleLight from 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-light';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nexport type SyntaxHighlighterProps = ThemedClassName<\n NativeSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\n/**\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n */\nexport const SyntaxHighlighter = ({\n classNames,\n fallback = zeroWidthSpace,\n children,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n return (\n <div role='none' className={mx('w-full', classNames)}>\n <NativeSyntaxHighlighter {...props} style={themeMode === 'dark' ? styleDark : styleLight}>\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAOA,WAAW;AAClB,OAAOC,6BAEA;AAEP,OAAOC,eAAe;AAEtB,OAAOC,gBAAgB;AAEvB,SAA+BC,uBAAuB;AACtD,SAASC,UAAU;AAEnB,IAAMC,iBAAiB;AAWhB,IAAMC,oBAAoB,CAAC,EAChCC,YACAC,WAAWH,gBACXI,UACA,GAAGC,MAAAA,MACoB;AACvB,QAAM,EAAEC,UAAS,IAAKC,gBAAAA;AACtB,SACE,sBAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAWC,GAAG,UAAUT,UAAAA;KACvC,sBAAA,cAACU,yBAAAA;IAAyB,GAAGP;IAAOQ,OAAOP,cAAc,SAASQ,YAAYC;KAE3EX,YAAYD,QAAAA,CAAAA;AAIrB;",
|
|
6
|
+
"names": ["React", "NativeSyntaxHighlighter", "styleDark", "styleLight", "useThemeContext", "mx", "zeroWidthSpace", "SyntaxHighlighter", "classNames", "fallback", "children", "props", "themeMode", "useThemeContext", "div", "role", "className", "mx", "NativeSyntaxHighlighter", "style", "styleDark", "styleLight"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-syntax-highlighter/src/SyntaxHighlighter.tsx":{"bytes":4115,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs/a11y-light","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-syntax-highlighter/src/index.ts":{"bytes":536,"imports":[{"path":"packages/ui/react-ui-syntax-highlighter/src/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-syntax-highlighter/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":2165},"packages/ui/react-ui-syntax-highlighter/dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs/a11y-light","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"exports":["SyntaxHighlighter"],"entryPoint":"packages/ui/react-ui-syntax-highlighter/src/index.ts","inputs":{"packages/ui/react-ui-syntax-highlighter/src/SyntaxHighlighter.tsx":{"bytesInOutput":798},"packages/ui/react-ui-syntax-highlighter/src/index.ts":{"bytesInOutput":0}},"bytes":934}}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SyntaxHighlighterProps as NativeSyntaxHighlighterProps } from 'react-syntax-highlighter';
|
|
3
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
4
|
+
export type SyntaxHighlighterProps = ThemedClassName<NativeSyntaxHighlighterProps & {
|
|
5
|
+
fallback?: string;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* https://github.com/react-syntax-highlighter/react-syntax-highlighter
|
|
9
|
+
*/
|
|
10
|
+
export declare const SyntaxHighlighter: ({ classNames, fallback, children, ...props }: SyntaxHighlighterProps) => React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=SyntaxHighlighter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyntaxHighlighter.d.ts","sourceRoot":"","sources":["../../../src/SyntaxHighlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAgC,EAC9B,KAAK,sBAAsB,IAAI,4BAA4B,EAC5D,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AAKvE,MAAM,MAAM,sBAAsB,GAAG,eAAe,CAClD,4BAA4B,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,iDAK3B,sBAAsB,sBAUxB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import '@dxos-theme';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: ({ classNames, fallback, children, ...props }: import("./SyntaxHighlighter").SyntaxHighlighterProps) => import("react").JSX.Element;
|
|
5
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare const Default: {
|
|
9
|
+
args: {
|
|
10
|
+
language: string;
|
|
11
|
+
className: string;
|
|
12
|
+
children: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const Typescript: {
|
|
16
|
+
args: {
|
|
17
|
+
language: string;
|
|
18
|
+
children: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const Empty: {
|
|
22
|
+
args: {
|
|
23
|
+
children: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=SyntaxHighlighter.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyntaxHighlighter.stories.d.ts","sourceRoot":"","sources":["../../../src/SyntaxHighlighter.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;;;;;;AAMrB,wBAIE;AAEF,eAAO,MAAM,OAAO;;;;;;CAMnB,CAAC;AAEF,eAAO,MAAM,UAAU;;;;;CAKtB,CAAC;AAEF,eAAO,MAAM,KAAK;;;;CAIjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/react-ui-syntax-highlighter",
|
|
3
|
+
"version": "0.6.11-staging.32b42e4",
|
|
4
|
+
"description": "A syntax highlighter wrapper.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
12
|
+
"types": "./dist/types/src/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "dist/types/src/index.d.ts",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"react-syntax-highlighter": "^15.5.0",
|
|
25
|
+
"@dxos/react-ui": "0.6.11-staging.32b42e4",
|
|
26
|
+
"@dxos/react-ui-theme": "0.6.11-staging.32b42e4"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "~18.2.0",
|
|
30
|
+
"@types/react-dom": "~18.2.0",
|
|
31
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
32
|
+
"react": "~18.2.0",
|
|
33
|
+
"react-dom": "~18.2.0",
|
|
34
|
+
"vite": "^5.3.4",
|
|
35
|
+
"@dxos/react-ui-theme": "0.6.11-staging.32b42e4",
|
|
36
|
+
"@dxos/storybook-utils": "0.6.11-staging.32b42e4"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"react-dom": "^18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
8
|
+
|
|
9
|
+
import { SyntaxHighlighter } from './SyntaxHighlighter';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'react-ui-syntax-highlighter/SyntaxHighlighter',
|
|
13
|
+
component: SyntaxHighlighter,
|
|
14
|
+
decorators: [withTheme],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Default = {
|
|
18
|
+
args: {
|
|
19
|
+
language: 'json',
|
|
20
|
+
className: 'text-sm',
|
|
21
|
+
children: JSON.stringify({ message: 'DXOS', initialized: true }, null, 2),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Typescript = {
|
|
26
|
+
args: {
|
|
27
|
+
language: 'ts',
|
|
28
|
+
children: 'const x = 100;',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Empty = {
|
|
33
|
+
args: {
|
|
34
|
+
children: false,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import NativeSyntaxHighlighter, {
|
|
7
|
+
type SyntaxHighlighterProps as NativeSyntaxHighlighterProps,
|
|
8
|
+
} from 'react-syntax-highlighter';
|
|
9
|
+
// eslint-disable-next-line no-restricted-imports
|
|
10
|
+
import styleDark from 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark';
|
|
11
|
+
// eslint-disable-next-line no-restricted-imports
|
|
12
|
+
import styleLight from 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-light';
|
|
13
|
+
|
|
14
|
+
import { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
15
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
16
|
+
|
|
17
|
+
const zeroWidthSpace = '\u200b';
|
|
18
|
+
|
|
19
|
+
export type SyntaxHighlighterProps = ThemedClassName<
|
|
20
|
+
NativeSyntaxHighlighterProps & {
|
|
21
|
+
fallback?: string;
|
|
22
|
+
}
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* https://github.com/react-syntax-highlighter/react-syntax-highlighter
|
|
27
|
+
*/
|
|
28
|
+
export const SyntaxHighlighter = ({
|
|
29
|
+
classNames,
|
|
30
|
+
fallback = zeroWidthSpace,
|
|
31
|
+
children,
|
|
32
|
+
...props
|
|
33
|
+
}: SyntaxHighlighterProps) => {
|
|
34
|
+
const { themeMode } = useThemeContext();
|
|
35
|
+
return (
|
|
36
|
+
<div role='none' className={mx('w-full', classNames)}>
|
|
37
|
+
<NativeSyntaxHighlighter {...props} style={themeMode === 'dark' ? styleDark : styleLight}>
|
|
38
|
+
{/* Non-empty fallback prevents collapse. */}
|
|
39
|
+
{children || fallback}
|
|
40
|
+
</NativeSyntaxHighlighter>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
};
|