@dxos/react-ui-markdown 0.8.4-main.21d9917

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 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 @@
1
+ # @dxos/react-ui-components
@@ -0,0 +1,79 @@
1
+ // src/MarkdownViewer/MarkdownViewer.tsx
2
+ import React from "react";
3
+ import ReactMarkdown from "react-markdown";
4
+ import remarkGfm from "remark-gfm";
5
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
6
+ import { mx } from "@dxos/ui-theme";
7
+ var MarkdownViewer = ({ classNames, children, components, content = "" }) => {
8
+ return /* @__PURE__ */ React.createElement("div", {
9
+ className: mx(classNames)
10
+ }, /* @__PURE__ */ React.createElement(ReactMarkdown, {
11
+ remarkPlugins: [
12
+ remarkGfm
13
+ ],
14
+ skipHtml: true,
15
+ components: {
16
+ ...defaultComponents,
17
+ ...components
18
+ }
19
+ }, content), children);
20
+ };
21
+ var defaultComponents = {
22
+ h1: ({ children }) => {
23
+ return /* @__PURE__ */ React.createElement("h1", {
24
+ className: "pbs-1 pbe-1 text-xl"
25
+ }, children);
26
+ },
27
+ h2: ({ children }) => {
28
+ return /* @__PURE__ */ React.createElement("h2", {
29
+ className: "pbs-1 pbe-1 text-lg"
30
+ }, children);
31
+ },
32
+ h3: ({ children }) => {
33
+ return /* @__PURE__ */ React.createElement("h3", {
34
+ className: "pbs-1 pbe-1 text-base"
35
+ }, children);
36
+ },
37
+ blockquote: ({ children, ...props }) => /* @__PURE__ */ React.createElement("blockquote", {
38
+ className: "pis-4 mbs-2 mbe-2 pbs-2 pbe-2 border-l-4 border-accentText text-accentText",
39
+ ...props
40
+ }, children),
41
+ p: ({ children }) => {
42
+ return /* @__PURE__ */ React.createElement("div", {
43
+ className: "pbs-1 pbe-1"
44
+ }, children);
45
+ },
46
+ a: ({ children, href, ...props }) => /* @__PURE__ */ React.createElement("a", {
47
+ href,
48
+ className: "text-primary-500 hover:text-primary-500",
49
+ target: "_blank",
50
+ rel: "noopener noreferrer",
51
+ ...props
52
+ }, children),
53
+ ol: ({ children, ...props }) => /* @__PURE__ */ React.createElement("ol", {
54
+ className: "pbs-1 pbe-1 pis-6 leading-tight list-decimal",
55
+ ...props
56
+ }, children),
57
+ ul: ({ children, ...props }) => /* @__PURE__ */ React.createElement("ul", {
58
+ className: "pbs-1 pbe-1 pis-6 leading-tight list-disc",
59
+ ...props
60
+ }, children),
61
+ li: ({ children, ...props }) => /* @__PURE__ */ React.createElement("li", {
62
+ className: "",
63
+ ...props
64
+ }, children),
65
+ pre: ({ children }) => children,
66
+ // TODO(burdon): Copy/paste button.
67
+ code: ({ children, className }) => {
68
+ const [, language] = /language-(\w+)/.exec(className || "") || [];
69
+ return /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
70
+ language,
71
+ classNames: "mbs-2 mbe-2 border border-separator rounded-sm text-sm bg-groupSurface",
72
+ PreTag: "pre"
73
+ }, children);
74
+ }
75
+ };
76
+ export {
77
+ MarkdownViewer
78
+ };
79
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/MarkdownViewer/MarkdownViewer.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport React, { type PropsWithChildren } from 'react';\nimport ReactMarkdown, { type Options as ReactMarkdownOptions } from 'react-markdown';\nimport remarkGfm from 'remark-gfm';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';\nimport { mx } from '@dxos/ui-theme';\n\nexport type MarkdownViewerProps = ThemedClassName<\n PropsWithChildren<{\n content?: string;\n components?: ReactMarkdownOptions['components'];\n }>\n>;\n\n/**\n * Transforms markdown text into react elements.\n * https://github.com/remarkjs/react-markdown\n * markdown -> remark -> [mdast -> remark plugins] -> [hast -> rehype plugins] -> components -> react elements.\n * Consider using @dxos/react-ui-editor.\n */\nexport const MarkdownViewer = ({ classNames, children, components, content = '' }: MarkdownViewerProps) => {\n return (\n <div className={mx(classNames)}>\n <ReactMarkdown remarkPlugins={[remarkGfm]} skipHtml components={{ ...defaultComponents, ...components }}>\n {content}\n </ReactMarkdown>\n {children}\n </div>\n );\n};\n\nconst defaultComponents: ReactMarkdownOptions['components'] = {\n h1: ({ children }) => {\n return <h1 className='pbs-1 pbe-1 text-xl'>{children}</h1>;\n },\n h2: ({ children }) => {\n return <h2 className='pbs-1 pbe-1 text-lg'>{children}</h2>;\n },\n h3: ({ children }) => {\n return <h3 className='pbs-1 pbe-1 text-base'>{children}</h3>;\n },\n blockquote: ({ children, ...props }) => (\n <blockquote className='pis-4 mbs-2 mbe-2 pbs-2 pbe-2 border-l-4 border-accentText text-accentText' {...props}>\n {children}\n </blockquote>\n ),\n p: ({ children }) => {\n return <div className='pbs-1 pbe-1'>{children}</div>;\n },\n a: ({ children, href, ...props }) => (\n <a\n href={href}\n className='text-primary-500 hover:text-primary-500' // TODO(burdon): Use link token.\n target='_blank'\n rel='noopener noreferrer'\n {...props}\n >\n {children}\n </a>\n ),\n ol: ({ children, ...props }) => (\n <ol className='pbs-1 pbe-1 pis-6 leading-tight list-decimal' {...props}>\n {children}\n </ol>\n ),\n ul: ({ children, ...props }) => (\n <ul className='pbs-1 pbe-1 pis-6 leading-tight list-disc' {...props}>\n {children}\n </ul>\n ),\n li: ({ children, ...props }) => (\n <li className='' {...props}>\n {children}\n </li>\n ),\n pre: ({ children }) => children,\n // TODO(burdon): Copy/paste button.\n code: ({ children, className }) => {\n const [, language] = /language-(\\w+)/.exec(className || '') || [];\n return (\n <SyntaxHighlighter\n language={language}\n classNames='mbs-2 mbe-2 border border-separator rounded-sm text-sm bg-groupSurface'\n PreTag='pre'\n >\n {children}\n </SyntaxHighlighter>\n );\n },\n};\n"],
5
+ "mappings": ";AAIA,OAAOA,WAAuC;AAC9C,OAAOC,mBAA6D;AACpE,OAAOC,eAAe;AAGtB,SAASC,yBAAyB;AAClC,SAASC,UAAU;AAeZ,IAAMC,iBAAiB,CAAC,EAAEC,YAAYC,UAAUC,YAAYC,UAAU,GAAE,MAAuB;AACpG,SACE,sBAAA,cAACC,OAAAA;IAAIC,WAAWC,GAAGN,UAAAA;KACjB,sBAAA,cAACO,eAAAA;IAAcC,eAAe;MAACC;;IAAYC,UAAAA;IAASR,YAAY;MAAE,GAAGS;MAAmB,GAAGT;IAAW;KACnGC,OAAAA,GAEFF,QAAAA;AAGP;AAEA,IAAMU,oBAAwD;EAC5DC,IAAI,CAAC,EAAEX,SAAQ,MAAE;AACf,WAAO,sBAAA,cAACW,MAAAA;MAAGP,WAAU;OAAuBJ,QAAAA;EAC9C;EACAY,IAAI,CAAC,EAAEZ,SAAQ,MAAE;AACf,WAAO,sBAAA,cAACY,MAAAA;MAAGR,WAAU;OAAuBJ,QAAAA;EAC9C;EACAa,IAAI,CAAC,EAAEb,SAAQ,MAAE;AACf,WAAO,sBAAA,cAACa,MAAAA;MAAGT,WAAU;OAAyBJ,QAAAA;EAChD;EACAc,YAAY,CAAC,EAAEd,UAAU,GAAGe,MAAAA,MAC1B,sBAAA,cAACD,cAAAA;IAAWV,WAAU;IAA8E,GAAGW;KACpGf,QAAAA;EAGLgB,GAAG,CAAC,EAAEhB,SAAQ,MAAE;AACd,WAAO,sBAAA,cAACG,OAAAA;MAAIC,WAAU;OAAeJ,QAAAA;EACvC;EACAiB,GAAG,CAAC,EAAEjB,UAAUkB,MAAM,GAAGH,MAAAA,MACvB,sBAAA,cAACE,KAAAA;IACCC;IACAd,WAAU;IACVe,QAAO;IACPC,KAAI;IACH,GAAGL;KAEHf,QAAAA;EAGLqB,IAAI,CAAC,EAAErB,UAAU,GAAGe,MAAAA,MAClB,sBAAA,cAACM,MAAAA;IAAGjB,WAAU;IAAgD,GAAGW;KAC9Df,QAAAA;EAGLsB,IAAI,CAAC,EAAEtB,UAAU,GAAGe,MAAAA,MAClB,sBAAA,cAACO,MAAAA;IAAGlB,WAAU;IAA6C,GAAGW;KAC3Df,QAAAA;EAGLuB,IAAI,CAAC,EAAEvB,UAAU,GAAGe,MAAAA,MAClB,sBAAA,cAACQ,MAAAA;IAAGnB,WAAU;IAAI,GAAGW;KAClBf,QAAAA;EAGLwB,KAAK,CAAC,EAAExB,SAAQ,MAAOA;;EAEvByB,MAAM,CAAC,EAAEzB,UAAUI,UAAS,MAAE;AAC5B,UAAM,CAAA,EAAGsB,QAAAA,IAAY,iBAAiBC,KAAKvB,aAAa,EAAA,KAAO,CAAA;AAC/D,WACE,sBAAA,cAACwB,mBAAAA;MACCF;MACA3B,YAAW;MACX8B,QAAO;OAEN7B,QAAAA;EAGP;AACF;",
6
+ "names": ["React", "ReactMarkdown", "remarkGfm", "SyntaxHighlighter", "mx", "MarkdownViewer", "classNames", "children", "components", "content", "div", "className", "mx", "ReactMarkdown", "remarkPlugins", "remarkGfm", "skipHtml", "defaultComponents", "h1", "h2", "h3", "blockquote", "props", "p", "a", "href", "target", "rel", "ol", "ul", "li", "pre", "code", "language", "exec", "SyntaxHighlighter", "PreTag"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/MarkdownViewer/MarkdownViewer.tsx":{"bytes":9683,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-markdown","kind":"import-statement","external":true},{"path":"remark-gfm","kind":"import-statement","external":true},{"path":"@dxos/react-ui-syntax-highlighter","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/MarkdownViewer/index.ts":{"bytes":489,"imports":[{"path":"src/MarkdownViewer/MarkdownViewer.tsx","kind":"import-statement","original":"./MarkdownViewer"}],"format":"esm"},"src/index.ts":{"bytes":474,"imports":[{"path":"src/MarkdownViewer/index.ts","kind":"import-statement","original":"./MarkdownViewer"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4973},"dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-markdown","kind":"import-statement","external":true},{"path":"remark-gfm","kind":"import-statement","external":true},{"path":"@dxos/react-ui-syntax-highlighter","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["MarkdownViewer"],"entryPoint":"src/index.ts","inputs":{"src/MarkdownViewer/MarkdownViewer.tsx":{"bytesInOutput":2509},"src/MarkdownViewer/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":2614}}}
@@ -0,0 +1,15 @@
1
+ import React, { type PropsWithChildren } from 'react';
2
+ import { type Options as ReactMarkdownOptions } from 'react-markdown';
3
+ import { type ThemedClassName } from '@dxos/react-ui';
4
+ export type MarkdownViewerProps = ThemedClassName<PropsWithChildren<{
5
+ content?: string;
6
+ components?: ReactMarkdownOptions['components'];
7
+ }>>;
8
+ /**
9
+ * Transforms markdown text into react elements.
10
+ * https://github.com/remarkjs/react-markdown
11
+ * markdown -> remark -> [mdast -> remark plugins] -> [hast -> rehype plugins] -> components -> react elements.
12
+ * Consider using @dxos/react-ui-editor.
13
+ */
14
+ export declare const MarkdownViewer: ({ classNames, children, components, content }: MarkdownViewerProps) => React.JSX.Element;
15
+ //# sourceMappingURL=MarkdownViewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownViewer.d.ts","sourceRoot":"","sources":["../../../../src/MarkdownViewer/MarkdownViewer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AACtD,OAAsB,EAAE,KAAK,OAAO,IAAI,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGrF,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAC/C,iBAAiB,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;CACjD,CAAC,CACH,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,+CAAoD,mBAAmB,sBASrG,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type StoryObj } from '@storybook/react-vite';
2
+ import { MarkdownViewer } from './MarkdownViewer';
3
+ declare const meta: {
4
+ title: string;
5
+ component: ({ classNames, children, components, content }: import("./MarkdownViewer").MarkdownViewerProps) => import("react").JSX.Element;
6
+ decorators: import("@storybook/react").Decorator[];
7
+ };
8
+ export default meta;
9
+ type Story = StoryObj<typeof MarkdownViewer>;
10
+ export declare const Default: Story;
11
+ //# sourceMappingURL=MarkdownViewer.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownViewer.stories.d.ts","sourceRoot":"","sources":["../../../../src/MarkdownViewer/MarkdownViewer.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,QAAA,MAAM,IAAI;;;;CAI6B,CAAC;AAExC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,cAAc,CAAC,CAAC;AA+C7C,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './MarkdownViewer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/MarkdownViewer/index.ts"],"names":[],"mappings":"AAIA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './MarkdownViewer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,kBAAkB,CAAC"}