@dxos/react-ui-markdown 0.8.4-main.3c1ae3b → 0.8.4-main.422d1c7879

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.
@@ -1,52 +1,46 @@
1
1
  // src/MarkdownViewer/MarkdownViewer.tsx
2
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
3
2
  import React from "react";
4
3
  import ReactMarkdown from "react-markdown";
5
4
  import remarkGfm from "remark-gfm";
6
5
  import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
7
- import { mx } from "@dxos/react-ui-theme";
6
+ import { mx } from "@dxos/ui-theme";
8
7
  var MarkdownViewer = ({ classNames, children, components, content = "" }) => {
9
- var _effect = _useSignals();
10
- try {
11
- return /* @__PURE__ */ React.createElement("div", {
12
- className: mx(classNames)
13
- }, /* @__PURE__ */ React.createElement(ReactMarkdown, {
14
- remarkPlugins: [
15
- remarkGfm
16
- ],
17
- skipHtml: true,
18
- components: {
19
- ...defaultComponents,
20
- ...components
21
- }
22
- }, content), children);
23
- } finally {
24
- _effect.f();
25
- }
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);
26
20
  };
27
21
  var defaultComponents = {
28
22
  h1: ({ children }) => {
29
23
  return /* @__PURE__ */ React.createElement("h1", {
30
- className: "pbs-1 pbe-1 text-xl"
24
+ className: "pt-1 pb-1 text-accent-text text-xl"
31
25
  }, children);
32
26
  },
33
27
  h2: ({ children }) => {
34
28
  return /* @__PURE__ */ React.createElement("h2", {
35
- className: "pbs-1 pbe-1 text-lg"
29
+ className: "pt-1 pb-1 text-accent-text text-lg"
36
30
  }, children);
37
31
  },
38
32
  h3: ({ children }) => {
39
33
  return /* @__PURE__ */ React.createElement("h3", {
40
- className: "pbs-1 pbe-1 text-base"
34
+ className: "pt-1 pb-1 text-accent-text text-base"
41
35
  }, children);
42
36
  },
43
37
  blockquote: ({ children, ...props }) => /* @__PURE__ */ React.createElement("blockquote", {
44
- className: "pis-4 mbs-2 mbe-2 pbs-2 pbe-2 border-l-4 border-accentText text-accentText",
38
+ className: "ps-4 mt-2 mb-2 pt-2 pb-2 border-l-4 border-accent-text text-accent-text",
45
39
  ...props
46
40
  }, children),
47
41
  p: ({ children }) => {
48
42
  return /* @__PURE__ */ React.createElement("div", {
49
- className: "pbs-1 pbe-1"
43
+ className: "pt-1 pb-1"
50
44
  }, children);
51
45
  },
52
46
  a: ({ children, href, ...props }) => /* @__PURE__ */ React.createElement("a", {
@@ -57,11 +51,11 @@ var defaultComponents = {
57
51
  ...props
58
52
  }, children),
59
53
  ol: ({ children, ...props }) => /* @__PURE__ */ React.createElement("ol", {
60
- className: "pbs-1 pbe-1 pis-6 leading-tight list-decimal",
54
+ className: "pt-1 pb-1 ps-6 leading-tight list-decimal",
61
55
  ...props
62
56
  }, children),
63
57
  ul: ({ children, ...props }) => /* @__PURE__ */ React.createElement("ul", {
64
- className: "pbs-1 pbe-1 pis-6 leading-tight list-disc",
58
+ className: "pt-1 pb-1 ps-6 leading-tight list-disc",
65
59
  ...props
66
60
  }, children),
67
61
  li: ({ children, ...props }) => /* @__PURE__ */ React.createElement("li", {
@@ -69,12 +63,18 @@ var defaultComponents = {
69
63
  ...props
70
64
  }, children),
71
65
  pre: ({ children }) => children,
72
- // TODO(burdon): Copy/paste button.
73
- code: ({ children, className }) => {
66
+ code: ({ children, className, node }) => {
74
67
  const [, language] = /language-(\w+)/.exec(className || "") || [];
68
+ const inline = !className && node?.position?.start.line === node?.position?.end.line;
69
+ if (inline) {
70
+ return /* @__PURE__ */ React.createElement("code", {
71
+ className: "rounded-xs bg-group-surface px-1 py-0.5 text-sm text-info-text"
72
+ }, children);
73
+ }
75
74
  return /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
76
75
  language,
77
- classNames: "mbs-2 mbe-2 border border-separator rounded-sm text-sm bg-groupSurface",
76
+ classNames: "mt-2 mb-2 p-2 border border-separator rounded-xs text-sm bg-group-surface",
77
+ copyButton: true,
78
78
  PreTag: "pre"
79
79
  }, children);
80
80
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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/react-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,WACE,sBAAA,cAACC,OAAAA;MAAIC,WAAWC,GAAGN,UAAAA;OACjB,sBAAA,cAACO,eAAAA;MAAcC,eAAe;QAACC;;MAAYC,UAAAA;MAASR,YAAY;QAAE,GAAGS;QAAmB,GAAGT;MAAW;OACnGC,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;A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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"]
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='pt-1 pb-1 text-accent-text text-xl'>{children}</h1>;\n },\n h2: ({ children }) => {\n return <h2 className='pt-1 pb-1 text-accent-text text-lg'>{children}</h2>;\n },\n h3: ({ children }) => {\n return <h3 className='pt-1 pb-1 text-accent-text text-base'>{children}</h3>;\n },\n blockquote: ({ children, ...props }) => (\n <blockquote className='ps-4 mt-2 mb-2 pt-2 pb-2 border-l-4 border-accent-text text-accent-text' {...props}>\n {children}\n </blockquote>\n ),\n p: ({ children }) => {\n return <div className='pt-1 pb-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='pt-1 pb-1 ps-6 leading-tight list-decimal' {...props}>\n {children}\n </ol>\n ),\n ul: ({ children, ...props }) => (\n <ul className='pt-1 pb-1 ps-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 code: ({ children, className, node }) => {\n const [, language] = /language-(\\w+)/.exec(className || '') || [];\n const inline = !className && node?.position?.start.line === node?.position?.end.line;\n if (inline) {\n return <code className='rounded-xs bg-group-surface px-1 py-0.5 text-sm text-info-text'>{children}</code>;\n }\n\n return (\n <SyntaxHighlighter\n language={language}\n classNames='mt-2 mb-2 p-2 border border-separator rounded-xs text-sm bg-group-surface'\n copyButton\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;OAAsCJ,QAAAA;EAC7D;EACAY,IAAI,CAAC,EAAEZ,SAAQ,MAAE;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WAAU;SAAkEJ,QAAAA;IAC3F;AAEA,WACE,sBAAA,cAACkC,mBAAAA;MACCP;MACA5B,YAAW;MACXoC,YAAAA;MACAC,QAAO;OAENpC,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", "node", "language", "exec", "inline", "position", "start", "line", "end", "SyntaxHighlighter", "copyButton", "PreTag"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/MarkdownViewer/MarkdownViewer.tsx":{"bytes":9923,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"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/react-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":4985},"dist/lib/browser/index.mjs":{"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"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/react-ui-theme","kind":"import-statement","external":true}],"exports":["MarkdownViewer"],"entryPoint":"src/index.ts","inputs":{"src/MarkdownViewer/MarkdownViewer.tsx":{"bytesInOutput":2694},"src/MarkdownViewer/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":2799}}}
1
+ {"inputs":{"src/MarkdownViewer/MarkdownViewer.tsx":{"bytes":10639,"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":5464},"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":2815},"src/MarkdownViewer/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":2920}}}