@primeui-devkit/react-markdown 0.1.0-rc.3 → 0.1.0-rc.5

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.
@@ -0,0 +1 @@
1
+ import{MarkdownDocument as e}from"@comark/react";import t,{componentMap as n,sanitizeOptions as r,sanitizeTree as i}from"@primeui-devkit/markdown-core/plugins/sanitize";import{jsx as a}from"react/jsx-runtime";function o(e){let t=[],n=``,r=0,i=``;for(let a of e){if(i)a===i&&(i=``);else if(a===`"`||a===`'`)i=a;else if(a===`(`)r++;else if(a===`)`)r=Math.max(0,r-1);else if(a===`;`&&r===0){t.push(n),n=``;continue}n+=a}return[...t,n]}function s(e){if(typeof e!=`string`)return e;let t=[];for(let n of o(e)){let e=n.indexOf(`:`),r=n.slice(0,e).trim(),i=n.slice(e+1).trim();e<1||!r||!i||t.push([r.startsWith(`--`)?r:r.toLowerCase().replace(/^-ms-/,`ms-`).replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),i])}return Object.fromEntries(t)}function c(e){if(typeof e!=`string`)return e;try{let t=JSON.parse(e);return typeof t==`string`?JSON.stringify(s(t)):e}catch{return e}}function l(e){let t={...e};typeof e.style==`string`&&(t.style=s(e.style)),`:style`in e&&(t[`:style`]=c(e[`:style`]));for(let n of[`class`,`className`]){let r=e[n];Array.isArray(r)&&(t[n]=r.filter(Boolean).join(` `))}return t}function u(e){if(!Array.isArray(e)||typeof e[0]!=`string`)return e;let[t,n,...r]=e;return[t,l(n??{}),...r.map(u)]}function d(e){return{...e,nodes:(e.nodes??[]).map(u)}}const f=(...e)=>e.filter(Boolean).join(` `)||void 0;function p(e=[],n){let i=r(n);return i===!1?e:[...e,t(i)]}function m({sanitize:t,tree:o,components:s,className:c,...l}){let u=r(t),p=u===!1?o:i(o,u);return/* @__PURE__ */ a(e,{...l,value:d(p),components:n(s),className:f(`markdown-content prose`,c)})}function h(e={}){let{name:t,components:n,className:r,sanitize:i}=e;function o({components:e,className:t,sanitize:o=i,...s}){return/* @__PURE__ */ a(m,{...s,sanitize:o,components:{...n,...e},className:f(r,t)})}return o.displayName=t??`MarkdownRenderer`,o}export{s as a,p as i,h as n,f as r,m as t};
@@ -0,0 +1,21 @@
1
+ import { JSX } from 'react';
2
+ import { MarkdownProps, MarkdownRendererProps } from './index.js';
3
+ import '@comark/react';
4
+ import '@primeui-devkit/markdown-core';
5
+ import '@primeui-devkit/markdown-core/plugins/sanitize';
6
+
7
+ type MarkdownLiveProps = MarkdownRendererProps & {
8
+ /** Document key for live updates through `globalThis.comarkContext`; the tree's own `meta.key` wins. */
9
+ comarkKey?: string;
10
+ };
11
+ /** A `MarkdownRenderer` that also takes live updates, each sanitized like the first tree. */
12
+ declare function MarkdownLive({ tree, comarkKey, ...rest }: MarkdownLiveProps): JSX.Element;
13
+ /** Parses markdown in the browser; the sanitizer runs after every plugin. Keep `options` and `plugins` stable: only a change of the markdown parses again. */
14
+ declare function MarkdownClient({ children, markdown, options, plugins, sanitize, ...rest }: MarkdownProps): JSX.Element;
15
+ /** The copy button of `ProsePre`, the only part of it that needs the browser. */
16
+ declare function ProseCopyButton({ code }: {
17
+ code?: string;
18
+ }): JSX.Element;
19
+
20
+ export { MarkdownClient, MarkdownLive, ProseCopyButton };
21
+ export type { MarkdownLiveProps };
package/dist/client.js ADDED
@@ -0,0 +1 @@
1
+ "use client";import{i as e,t}from"./chunks/render-CcsM4C3Y.js";import{jsx as n,jsxs as r}from"react/jsx-runtime";import{parseMarkdown as i}from"@primeui-devkit/markdown-core";import{Suspense as a,use as o,useDeferredValue as s,useEffect as c,useMemo as l,useState as u}from"react";function d({tree:e,comarkKey:r,...i}){let[a,o]=u(null),s=e.meta?.key||r;return c(()=>{let t=globalThis.comarkContext;if(!s||!t)return;let n=t.get(s,e).listen(o);return()=>n(!0)},[s]),/* @__PURE__ */ n(t,{...i,tree:a??e})}function f({parsing:e,...t}){return/* @__PURE__ */ n(d,{...t,tree:o(e)})}function p({children:t,markdown:r=``,options:o={},plugins:c=[],sanitize:u,...d}){let p=t?String(t):r,m=l(()=>i(p,{...o,plugins:e(c,u)}),[p]),h=s(m);return/* @__PURE__ */ n(a,{fallback:null,children:/* @__PURE__ */ n(f,{...d,sanitize:u,parsing:h})})}function m({code:e=``}){let[t,i]=u(!1);async function a(){e&&(await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3))}return/* @__PURE__ */ n(`button`,{type:`button`,className:`prose-pre-copy`,title:t?`Copied`:`Copy Code`,onClick:a,children:t?/* @__PURE__ */ n(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:/* @__PURE__ */ n(`path`,{d:`M20 6 9 17l-5-5`})}):/* @__PURE__ */ r(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[/* @__PURE__ */ n(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`}),/* @__PURE__ */ n(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})})}export{p as MarkdownClient,d as MarkdownLive,m as ProseCopyButton};
package/dist/index.d.ts CHANGED
@@ -1,39 +1,53 @@
1
- export { Comark as Markdown, ComarkClient as MarkdownClient, ComarkLive as MarkdownLive, ComarkRenderer as MarkdownRenderer, defineComarkComponent as defineMarkdownComponent, defineComarkRendererComponent as defineMarkdownRenderer } from '@comark/react';
1
+ import { MarkdownProps, SanitizeSetting } from './render-CwaofC8t.js';
2
+ export { MarkdownRenderer, MarkdownRendererOptions, MarkdownRendererProps, defineMarkdownRenderer } from './render-CwaofC8t.js';
3
+ import { MarkdownParseOptions, MarkdownPlugin } from '@primeui-devkit/markdown-core';
2
4
  import * as react from 'react';
3
- import { ReactNode } from 'react';
5
+ import { JSX, ComponentType, ReactNode } from 'react';
6
+ export { MarkdownClient, MarkdownLive, MarkdownLiveProps } from '@primeui-devkit/react-markdown/client';
7
+ import '@comark/react';
8
+ import '@primeui-devkit/markdown-core/plugins/sanitize';
9
+
10
+ interface MarkdownComponentOptions extends Omit<MarkdownParseOptions, 'plugins'> {
11
+ /** Display name of the component. */
12
+ name?: string;
13
+ /** Plugins run before the ones passed as a prop; the sanitizer runs after both. */
14
+ plugins?: MarkdownPlugin<any, any>[];
15
+ /** Components merged under the ones passed as a prop. */
16
+ components?: Record<string, ComponentType<any>>;
17
+ className?: string;
18
+ /** Default for the `sanitize` prop. @default true */
19
+ sanitize?: SanitizeSetting;
20
+ }
21
+ /** A `Markdown` with parser options, plugins, components and a sanitize default built in. */
22
+ declare function defineMarkdownComponent(config?: MarkdownComponentOptions): (props: MarkdownProps) => Promise<JSX.Element>;
23
+ /** Parses markdown on the server, an async Server Component; the sanitizer runs after every plugin. */
24
+ declare const Markdown: (props: MarkdownProps) => Promise<JSX.Element>;
4
25
 
5
26
  type ProseProps = {
6
27
  children?: ReactNode;
7
28
  [key: string]: unknown;
8
29
  };
9
- declare const ProseH1: ({ id, children }: ProseProps & {
30
+ declare const ProseH1: ({ id, children, ...props }: ProseProps & {
10
31
  id?: string;
11
32
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
12
- declare const ProseH2: ({ id, children }: ProseProps & {
33
+ declare const ProseH2: ({ id, children, ...props }: ProseProps & {
13
34
  id?: string;
14
35
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
15
- declare const ProseH3: ({ id, children }: ProseProps & {
36
+ declare const ProseH3: ({ id, children, ...props }: ProseProps & {
16
37
  id?: string;
17
38
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
18
- declare const ProseH4: ({ id, children }: ProseProps & {
39
+ declare const ProseH4: ({ id, children, ...props }: ProseProps & {
19
40
  id?: string;
20
41
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
21
- declare const ProseH5: ({ id, children }: ProseProps & {
42
+ declare const ProseH5: ({ id, children, ...props }: ProseProps & {
22
43
  id?: string;
23
44
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
24
- declare const ProseH6: ({ id, children }: ProseProps & {
45
+ declare const ProseH6: ({ id, children, ...props }: ProseProps & {
25
46
  id?: string;
26
47
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
27
- declare function ProseA({ href, target, children }: ProseProps & {
28
- href?: string;
29
- target?: string;
30
- }): react.JSX.Element;
31
- declare function ProseImg({ src, alt, width, height }: {
32
- src?: string;
33
- alt?: string;
34
- width?: string | number;
35
- height?: string | number;
36
- }): react.JSX.Element;
48
+ declare const ProseA: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
49
+ declare const ProseImg: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
50
+ /** Server-rendered, with only the copy button on the client. */
37
51
  declare function ProsePre({ code, filename, class: classAttr, className: classNameProp, children }: ProseProps & {
38
52
  code?: string;
39
53
  filename?: string;
@@ -41,57 +55,58 @@ declare function ProsePre({ code, filename, class: classAttr, className: classNa
41
55
  className?: string;
42
56
  }): react.JSX.Element;
43
57
  declare function ProseTable({ children }: ProseProps): react.JSX.Element;
44
- declare const ProseP: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
45
- declare const ProseBlockquote: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
46
- declare const ProseCode: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
47
- declare const ProseEm: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
48
- declare const ProseStrong: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
49
- declare const ProseLi: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
50
- declare const ProseOl: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
51
- declare const ProseUl: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
52
- declare const ProseTbody: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
53
- declare const ProseTd: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
54
- declare const ProseTh: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
55
- declare const ProseThead: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
56
- declare const ProseTr: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
57
- declare function ProseHr(): react.JSX.Element;
58
+ declare const ProseP: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
59
+ declare const ProseBlockquote: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
60
+ declare const ProseCode: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
61
+ declare const ProseEm: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
62
+ declare const ProseStrong: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
63
+ declare const ProseLi: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
64
+ declare const ProseOl: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
65
+ declare const ProseUl: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
66
+ declare const ProseTbody: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
67
+ declare const ProseTd: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
68
+ declare const ProseTh: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
69
+ declare const ProseThead: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
70
+ declare const ProseTr: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
71
+ declare const ProseHr: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
58
72
  declare const proseComponents: {
59
- ProseA: typeof ProseA;
60
- ProseBlockquote: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
61
- ProseCode: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
62
- ProseEm: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
63
- ProseH1: ({ id, children }: ProseProps & {
73
+ ProseA: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
74
+ ProseBlockquote: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
75
+ ProseCode: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
76
+ ProseEm: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
77
+ ProseH1: ({ id, children, ...props }: ProseProps & {
64
78
  id?: string;
65
79
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
66
- ProseH2: ({ id, children }: ProseProps & {
80
+ ProseH2: ({ id, children, ...props }: ProseProps & {
67
81
  id?: string;
68
82
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
69
- ProseH3: ({ id, children }: ProseProps & {
83
+ ProseH3: ({ id, children, ...props }: ProseProps & {
70
84
  id?: string;
71
85
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
72
- ProseH4: ({ id, children }: ProseProps & {
86
+ ProseH4: ({ id, children, ...props }: ProseProps & {
73
87
  id?: string;
74
88
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
75
- ProseH5: ({ id, children }: ProseProps & {
89
+ ProseH5: ({ id, children, ...props }: ProseProps & {
76
90
  id?: string;
77
91
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
78
- ProseH6: ({ id, children }: ProseProps & {
92
+ ProseH6: ({ id, children, ...props }: ProseProps & {
79
93
  id?: string;
80
94
  }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
81
- ProseHr: typeof ProseHr;
82
- ProseImg: typeof ProseImg;
83
- ProseLi: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
84
- ProseOl: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
85
- ProseP: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
95
+ ProseHr: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
96
+ ProseImg: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
97
+ ProseLi: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
98
+ ProseOl: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
99
+ ProseP: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
86
100
  ProsePre: typeof ProsePre;
87
- ProseStrong: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
101
+ ProseStrong: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
88
102
  ProseTable: typeof ProseTable;
89
- ProseTbody: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
90
- ProseTd: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
91
- ProseTh: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
92
- ProseThead: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
93
- ProseTr: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
94
- ProseUl: ({ children, class: classAttr, className: classNameProp, style, ...rest }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
103
+ ProseTbody: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
104
+ ProseTd: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
105
+ ProseTh: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
106
+ ProseThead: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
107
+ ProseTr: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
108
+ ProseUl: ({ children, ...props }: ProseProps) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
95
109
  };
96
110
 
97
- export { ProseA, ProseBlockquote, ProseCode, ProseEm, ProseH1, ProseH2, ProseH3, ProseH4, ProseH5, ProseH6, ProseHr, ProseImg, ProseLi, ProseOl, ProseP, ProsePre, ProseStrong, ProseTable, ProseTbody, ProseTd, ProseTh, ProseThead, ProseTr, ProseUl, proseComponents };
111
+ export { Markdown, MarkdownProps, ProseA, ProseBlockquote, ProseCode, ProseEm, ProseH1, ProseH2, ProseH3, ProseH4, ProseH5, ProseH6, ProseHr, ProseImg, ProseLi, ProseOl, ProseP, ProsePre, ProseStrong, ProseTable, ProseTbody, ProseTd, ProseTh, ProseThead, ProseTr, ProseUl, SanitizeSetting, defineMarkdownComponent, proseComponents };
112
+ export type { MarkdownComponentOptions };
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- 'use client';
2
- import{Comark as e,ComarkClient as t,ComarkLive as n,ComarkRenderer as r,defineComarkComponent as i,defineComarkRendererComponent as a}from"@comark/react";import{createElement as o,useEffect as s,useRef as c,useState as l}from"react";import{jsx as u,jsxs as d}from"react/jsx-runtime";function f(e){return typeof e==`string`?Object.fromEntries(e.split(`;`).map(e=>e.split(`:`)).filter(([e,t])=>e?.trim()&&t!==void 0).map(([e,...t])=>[e.trim().replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),t.join(`:`).trim()])):e}function p(e,t){return function({children:n,class:r,className:i,style:a,...s}){let c=[t,i??r].filter(Boolean).join(` `);return o(e,{...s,className:c,...a===void 0?{}:{style:f(a)}},n)}}function m(e,t){return function({id:n,children:r}){return n?o(e,{id:n,className:t},/* @__PURE__ */ d(`a`,{href:`#${n}`,className:`prose-heading-link`,children:[/* @__PURE__ */ u(`span`,{className:`prose-heading-anchor`,children:`#`}),r]})):o(e,{className:t},r)}}const h=/* @__PURE__ */ m(`h1`,`prose-h1`),g=/* @__PURE__ */ m(`h2`,`prose-h2`),_=/* @__PURE__ */ m(`h3`,`prose-h3`),v=/* @__PURE__ */ m(`h4`,`prose-h4`),y=/* @__PURE__ */ m(`h5`,`prose-h5`),b=/* @__PURE__ */ m(`h6`,`prose-h6`);function x({href:e,target:t,children:n}){return/* @__PURE__ */ u(`a`,{className:`prose-a`,href:e,target:t,children:n})}function S({src:e,alt:t,width:n,height:r}){return/* @__PURE__ */ u(`img`,{className:`prose-img`,src:e,alt:t,width:n,height:r})}function C({code:e=``,filename:t,class:n,className:r,children:i}){let a=r??n,[o,f]=l(!1),p=c(null);s(()=>{for(let e of p.current?.querySelectorAll(`[class*=","]`)??[])e.setAttribute(`class`,e.getAttribute(`class`).split(`,`).join(` `))});let m=t?.replace(`:line-numbers`,``)||null,h=t?.includes(`:line-numbers`);async function g(){e&&(await navigator.clipboard.writeText(e),f(!0),setTimeout(()=>f(!1),2e3))}return/* @__PURE__ */ d(`div`,{className:`prose-pre`,children:[m&&/* @__PURE__ */ u(`div`,{className:`prose-pre-filename`,children:/* @__PURE__ */ u(`span`,{children:m})}),/* @__PURE__ */ u(`div`,{className:`prose-pre-actions`,children:/* @__PURE__ */ u(`button`,{type:`button`,className:`prose-pre-copy`,title:o?`Copied`:`Copy Code`,onClick:g,children:o?/* @__PURE__ */ u(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:/* @__PURE__ */ u(`path`,{d:`M20 6 9 17l-5-5`})}):/* @__PURE__ */ d(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[/* @__PURE__ */ u(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`}),/* @__PURE__ */ u(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})})}),/* @__PURE__ */ u(`pre`,{ref:p,className:[a,h?`prose-pre-line-numbers`:``].filter(Boolean).join(` `)||void 0,children:i})]})}function w({children:e}){return/* @__PURE__ */ u(`div`,{className:`prose-table-scroll`,children:/* @__PURE__ */ u(`table`,{className:`prose-table`,children:e})})}const T=/* @__PURE__ */ p(`p`,`prose-p`),E=/* @__PURE__ */ p(`blockquote`,`prose-blockquote`),D=/* @__PURE__ */ p(`code`,`prose-code`),O=/* @__PURE__ */ p(`em`,`prose-em`),k=/* @__PURE__ */ p(`strong`,`prose-strong`),A=/* @__PURE__ */ p(`li`,`prose-li`),j=/* @__PURE__ */ p(`ol`,`prose-ol`),M=/* @__PURE__ */ p(`ul`,`prose-ul`),N=/* @__PURE__ */ p(`tbody`,`prose-tbody`),P=/* @__PURE__ */ p(`td`,`prose-td`),F=/* @__PURE__ */ p(`th`,`prose-th`),I=/* @__PURE__ */ p(`thead`,`prose-thead`),L=/* @__PURE__ */ p(`tr`,`prose-tr`);function R(){return/* @__PURE__ */ u(`hr`,{className:`prose-hr`})}const z={ProseA:x,ProseBlockquote:E,ProseCode:D,ProseEm:O,ProseH1:h,ProseH2:g,ProseH3:_,ProseH4:v,ProseH5:y,ProseH6:b,ProseHr:R,ProseImg:S,ProseLi:A,ProseOl:j,ProseP:T,ProsePre:C,ProseStrong:k,ProseTable:w,ProseTbody:N,ProseTd:P,ProseTh:F,ProseThead:I,ProseTr:L,ProseUl:M};export{e as Markdown,t as MarkdownClient,n as MarkdownLive,r as MarkdownRenderer,x as ProseA,E as ProseBlockquote,D as ProseCode,O as ProseEm,h as ProseH1,g as ProseH2,_ as ProseH3,v as ProseH4,y as ProseH5,b as ProseH6,R as ProseHr,S as ProseImg,A as ProseLi,j as ProseOl,T as ProseP,C as ProsePre,k as ProseStrong,w as ProseTable,N as ProseTbody,P as ProseTd,F as ProseTh,I as ProseThead,L as ProseTr,M as ProseUl,i as defineMarkdownComponent,a as defineMarkdownRenderer,z as proseComponents};
1
+ import{a as e,i as t,n,r,t as i}from"./chunks/render-CcsM4C3Y.js";import{jsx as a,jsxs as o}from"react/jsx-runtime";import{parseMarkdown as s}from"@primeui-devkit/markdown-core";import{MarkdownClient as c,MarkdownClient as l,MarkdownLive as u,ProseCopyButton as d}from"@primeui-devkit/react-markdown/client";import{createElement as f}from"react";function p(e={}){let{name:n,plugins:o=[],components:c,className:u,sanitize:d,...f}=e;async function p({children:e,markdown:n=``,options:p,plugins:m=[],components:h,className:g,sanitize:_=d,streaming:v=!1,...y}){let b=e?String(e):n,x={...y,components:{...c,...h},className:r(u,g),sanitize:_},S={...f,...p},C=[...o,...m];if(v)return/* @__PURE__ */ a(l,{...x,markdown:b,options:S,plugins:C,streaming:!0});let w=await s(b,{...S,plugins:t(C,_)});return/* @__PURE__ */ a(i,{...x,tree:w})}return Object.defineProperty(p,"name",{value:n??`Markdown`}),p}const m=/* @__PURE__ */ p({name:`Markdown`});function h(t,{class:n,className:r,style:i,...a}){return{...a,className:[t,r??n].filter(Boolean).join(` `),...i===void 0?{}:{style:e(i)}}}function g(e,t){return function({children:n,...r}){return f(e,h(t,r),n)}}function _(e,t){return function({id:n,children:r,...i}){return n?f(e,{...h(t,i),id:n},/* @__PURE__ */ o(`a`,{href:`#${n}`,className:`prose-heading-link`,children:[/* @__PURE__ */ a(`span`,{className:`prose-heading-anchor`,children:`#`}),r]})):f(e,h(t,i),r)}}const v=/* @__PURE__ */ _(`h1`,`prose-h1`),y=/* @__PURE__ */ _(`h2`,`prose-h2`),b=/* @__PURE__ */ _(`h3`,`prose-h3`),x=/* @__PURE__ */ _(`h4`,`prose-h4`),S=/* @__PURE__ */ _(`h5`,`prose-h5`),C=/* @__PURE__ */ _(`h6`,`prose-h6`),w=/* @__PURE__ */ g(`a`,`prose-a`),T=/* @__PURE__ */ g(`img`,`prose-img`);function E({code:e=``,filename:t,class:n,className:r,children:i}){let s=r??n,c=t?.replace(`:line-numbers`,``)||null,l=t?.includes(`:line-numbers`);return/* @__PURE__ */ o(`div`,{className:`prose-pre`,children:[c&&/* @__PURE__ */ a(`div`,{className:`prose-pre-filename`,children:/* @__PURE__ */ a(`span`,{children:c})}),/* @__PURE__ */ a(`div`,{className:`prose-pre-actions`,children:/* @__PURE__ */ a(d,{code:e})}),/* @__PURE__ */ a(`pre`,{className:[s,l?`prose-pre-line-numbers`:``].filter(Boolean).join(` `)||void 0,children:i})]})}function D({children:e}){return/* @__PURE__ */ a(`div`,{className:`prose-table-scroll`,children:/* @__PURE__ */ a(`table`,{className:`prose-table`,children:e})})}const O=/* @__PURE__ */ g(`p`,`prose-p`),k=/* @__PURE__ */ g(`blockquote`,`prose-blockquote`),A=/* @__PURE__ */ g(`code`,`prose-code`),j=/* @__PURE__ */ g(`em`,`prose-em`),M=/* @__PURE__ */ g(`strong`,`prose-strong`),N=/* @__PURE__ */ g(`li`,`prose-li`),P=/* @__PURE__ */ g(`ol`,`prose-ol`),F=/* @__PURE__ */ g(`ul`,`prose-ul`),I=/* @__PURE__ */ g(`tbody`,`prose-tbody`),L=/* @__PURE__ */ g(`td`,`prose-td`),R=/* @__PURE__ */ g(`th`,`prose-th`),z=/* @__PURE__ */ g(`thead`,`prose-thead`),B=/* @__PURE__ */ g(`tr`,`prose-tr`),V=/* @__PURE__ */ g(`hr`,`prose-hr`),H={ProseA:w,ProseBlockquote:k,ProseCode:A,ProseEm:j,ProseH1:v,ProseH2:y,ProseH3:b,ProseH4:x,ProseH5:S,ProseH6:C,ProseHr:V,ProseImg:T,ProseLi:N,ProseOl:P,ProseP:O,ProsePre:E,ProseStrong:M,ProseTable:D,ProseTbody:I,ProseTd:L,ProseTh:R,ProseThead:z,ProseTr:B,ProseUl:F};export{m as Markdown,c as MarkdownClient,u as MarkdownLive,i as MarkdownRenderer,w as ProseA,k as ProseBlockquote,A as ProseCode,j as ProseEm,v as ProseH1,y as ProseH2,b as ProseH3,x as ProseH4,S as ProseH5,C as ProseH6,V as ProseHr,T as ProseImg,N as ProseLi,P as ProseOl,O as ProseP,E as ProsePre,M as ProseStrong,D as ProseTable,I as ProseTbody,L as ProseTd,R as ProseTh,z as ProseThead,B as ProseTr,F as ProseUl,p as defineMarkdownComponent,n as defineMarkdownRenderer,H as proseComponents};
@@ -0,0 +1,43 @@
1
+ import { MarkdownDocument } from '@comark/react';
2
+ import { MarkdownParseOptions, MarkdownPlugin } from '@primeui-devkit/markdown-core';
3
+ import { SanitizeOptions } from '@primeui-devkit/markdown-core/plugins/sanitize';
4
+ import { ComponentProps, ReactNode, JSX, ComponentType, FunctionComponent } from 'react';
5
+
6
+ type DocumentProps = ComponentProps<typeof MarkdownDocument>;
7
+ type ComarkRendererProps = Omit<DocumentProps, 'value'> & {
8
+ /** The parsed tree to render, or a bare `{ nodes }`. */
9
+ tree: NonNullable<DocumentProps['value']>;
10
+ };
11
+ /** The option every renderer shares: on unless `false`, or the sanitizer's options. */
12
+ type SanitizeSetting = boolean | SanitizeOptions;
13
+ type MarkdownRendererProps = ComarkRendererProps & {
14
+ /** Removes what would run script, submit a form or restyle the page before rendering; `false` renders the tree as given. @default true */
15
+ sanitize?: SanitizeSetting;
16
+ };
17
+ interface MarkdownProps extends Omit<ComarkRendererProps, 'tree'> {
18
+ /** Markdown to parse; `children` as text wins over it. */
19
+ markdown?: string;
20
+ children?: ReactNode;
21
+ /** Parser options; plugins go in `plugins`. */
22
+ options?: Omit<MarkdownParseOptions, 'plugins'>;
23
+ /** Extra plugins, run before the sanitizer. */
24
+ plugins?: MarkdownPlugin<any, any>[];
25
+ /** Removes what would run script, submit a form or restyle the page, after every plugin; `false` only for trusted markdown. @default true */
26
+ sanitize?: SanitizeSetting;
27
+ }
28
+ /** Renders a parsed tree, sanitized first. Free of client hooks, so it renders in a Server Component too. */
29
+ declare function MarkdownRenderer({ sanitize, tree, components, className, ...rest }: MarkdownRendererProps): JSX.Element;
30
+ interface MarkdownRendererOptions {
31
+ /** Display name of the component. */
32
+ name?: string;
33
+ /** Components merged under the ones passed as a prop. */
34
+ components?: Record<string, ComponentType<any>>;
35
+ className?: string;
36
+ /** Default for the `sanitize` prop. @default true */
37
+ sanitize?: SanitizeSetting;
38
+ }
39
+ /** A `MarkdownRenderer` with components and a sanitize default built in. */
40
+ declare function defineMarkdownRenderer(config?: MarkdownRendererOptions): FunctionComponent<MarkdownRendererProps>;
41
+
42
+ export { MarkdownRenderer, defineMarkdownRenderer };
43
+ export type { MarkdownProps, MarkdownRendererOptions, MarkdownRendererProps, SanitizeSetting };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primeui-devkit/react-markdown",
3
- "version": "0.1.0-rc.3",
3
+ "version": "0.1.0-rc.5",
4
4
  "author": "PrimeTek Informatics",
5
5
  "description": "React renderer for the PrimeUI DevKit markdown AST, plus the Prose* component set. The rendering backend is an internal implementation detail.",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -22,8 +22,20 @@
22
22
  "import": "./dist/index.js",
23
23
  "default": "./dist/index.js"
24
24
  },
25
+ "./client": {
26
+ "types": "./dist/client.d.ts",
27
+ "import": "./dist/client.js",
28
+ "default": "./dist/client.js"
29
+ },
25
30
  "./package.json": "./package.json"
26
31
  },
32
+ "typesVersions": {
33
+ "*": {
34
+ "client": [
35
+ "./dist/client.d.ts"
36
+ ]
37
+ }
38
+ },
27
39
  "publishConfig": {
28
40
  "access": "public"
29
41
  },
@@ -35,22 +47,25 @@
35
47
  "README.md"
36
48
  ],
37
49
  "dependencies": {
38
- "@comark/react": "^0.5.1"
50
+ "@comark/react": "0.7.0",
51
+ "@primeui-devkit/markdown-core": "0.1.0-rc.5"
39
52
  },
40
53
  "peerDependencies": {
41
- "react": ">=18.0.0"
54
+ "react": "^19.0.0"
42
55
  },
43
56
  "devDependencies": {
44
57
  "@types/react": "^19.0.0",
58
+ "@types/react-dom": "^19.0.0",
45
59
  "cross-env": "^10.1.0",
60
+ "jsdom": "^30.0.1",
46
61
  "react": "^19.0.0",
62
+ "react-dom": "^19.0.0",
47
63
  "typescript": "~6.0.0",
48
64
  "vitest": "4.1.11",
49
- "@primeui-devkit/cli": "0.1.0-rc.1",
50
- "@primeui-devkit/bundle": "0.1.0-rc.1",
51
- "@primeui-devkit/markdown-core": "0.1.0-rc.3",
52
- "@primeui-devkit/test-config": "0.1.0-rc.1",
53
- "@primeui-devkit/ts-config": "0.1.0-rc.1"
65
+ "@primeui-devkit/test-config": "0.1.0-rc.2",
66
+ "@primeui-devkit/bundle": "0.1.0-rc.2",
67
+ "@primeui-devkit/cli": "0.1.0-rc.2",
68
+ "@primeui-devkit/ts-config": "0.1.0-rc.2"
54
69
  },
55
70
  "engines": {
56
71
  "node": ">=22.18.0"