@discord/markdown-react 0.1.5 → 0.1.6

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/dist/src/index.js CHANGED
@@ -1 +1 @@
1
- import{jsx as e,Fragment as r}from"react/jsx-runtime";import{parse as t}from"@discord/markdown-wasm";import{useMemo as n,createContext as l,useContext as o}from"react";let i=l(null);export function useAst(){return o(i)}export const RULES=new Set(["bold","italic","underline","strikethrough","spoiler","emoji","timestamp","mention","link","code","code_block","heading","list","quote","small"]);export function Node({node:r,renderers:t,...n}){let l=t[r.type];if(!function(e,r){if(null==e)throw Error(`Attempted to render "${r}" but no renderer was provided`)}(l,r.type),Array.isArray(r.value))return e(l,{...n,children:e(NodeList,{nodes:r.value,renderers:t})});switch(r.type){case"mention":case"timestamp":case"emoji":case"code_block":return e(l,{...r.value,...n});case"link":let o=r.value,i=null;if("normal"===o.type){let{value:{text:r,url:n}}=o;i=r?e(NodeList,{nodes:r,renderers:t}):n}return e(l,{...r.value,...n,children:i});case"text":case"code":return e(l,{...n,children:r.value});case"heading":return e(l,{level:r.value.level,...n,children:e(NodeList,{nodes:r.value.content,renderers:t})});case"list":let s=t.listItem??"li";return e(l,{...r.value,...n,children:r.value.items.map((n,l)=>e(s,{siblings:r.value.items,index:l,children:e(NodeList,{nodes:n.content,renderers:t})},l))});case"empty":return e(l,{...n});case"small":return e(l,{...n,children:e(NodeList,{nodes:r.value.content,renderers:t})});default:throw TypeError(`Unknown node type "${r.type}"`)}}export function NodeList({nodes:t,renderers:n}){return e(r,{children:t.map((r,l)=>e(Node,{node:r,renderers:n,siblings:t,index:l},l))})}export default function s({content:r,renderers:l}){let o=n(()=>{let e=Object.keys(l).filter(e=>RULES.has(e));return e.length>0?e:null},[l]),s=n(()=>t(r,o),[r,o]);return e(i.Provider,{value:s,children:e(NodeList,{nodes:s,renderers:l})})}
1
+ import{jsx as e,Fragment as r}from"react/jsx-runtime";import{parse as t}from"@discord/markdown-wasm";import{createContext as n,useContext as l,useMemo as o}from"react";let i=n(null);export function useAst(){return l(i)}export const RULES=new Set(["bold","italic","underline","strikethrough","spoiler","emoji","timestamp","mention","link","code","code_block","heading","list","quote","small"]);export function Node({node:r,renderers:t,...n}){let l=t[r.type];if(!function(e,r){if(null==e)throw Error(`Attempted to render "${r}" but no renderer was provided`)}(l,r.type),Array.isArray(r.value))return e(l,{...n,children:e(NodeList,{nodes:r.value,renderers:t})});switch(r.type){case"mention":case"timestamp":case"emoji":case"code_block":return e(l,{...r.value,...n});case"link":{let o=r.value,i=null;if("normal"===o.type){let{value:{text:r,url:n}}=o;i=r?e(NodeList,{nodes:r,renderers:t}):n}return e(l,{...r.value,...n,children:i})}case"text":case"code":return e(l,{...n,children:r.value});case"heading":return e(l,{level:r.value.level,...n,children:e(NodeList,{nodes:r.value.content,renderers:t})});case"list":{let o=t.listItem??"li";return e(l,{...r.value,...n,children:r.value.items.map((n,l)=>e(o,{siblings:r.value.items,index:l,children:e(NodeList,{nodes:n.content,renderers:t})},l))})}case"empty":return e(l,{...n});case"small":return e(l,{...n,children:e(NodeList,{nodes:r.value.content,renderers:t})});default:throw TypeError(`Unknown node type "${r.type}"`)}}export function NodeList({nodes:t,renderers:n}){return e(r,{children:t.map((r,l)=>e(Node,{node:r,renderers:n,siblings:t,index:l},l))})}export default function s({content:r,renderers:n}){let l=o(()=>{let e=Object.keys(n).filter(e=>RULES.has(e));return e.length>0?e:null},[n]),s=o(()=>t(r,l),[r,l]);return e(i.Provider,{value:s,children:e(NodeList,{nodes:s,renderers:n})})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/markdown-react",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "React library for parsing and rendering Discord Markdown",
6
6
  "main": "dist/src/index.js",
@@ -13,7 +13,7 @@
13
13
  "src/index.d.ts"
14
14
  ],
15
15
  "dependencies": {
16
- "@discord/markdown-wasm": "0.1.5"
16
+ "@discord/markdown-wasm": "0.1.6"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@swc/cli": "^0.5.2",
@@ -26,7 +26,7 @@
26
26
  "vite": "^5.4.0",
27
27
  "vite-plugin-wasm": "^3.3.0",
28
28
  "vitest": "^2.0.3",
29
- "@discord/markdown-types": "0.1.3"
29
+ "@discord/markdown-types": "0.1.4"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "17 - 19"
package/src/index.d.ts CHANGED
@@ -1,20 +1,9 @@
1
- import React from "react";
2
- import {
3
- Node,
4
- AnyNode,
5
- CodeBlock,
6
- Emoji,
7
- Timestamp,
8
- Mention,
9
- Link,
10
- List,
11
- Block,
12
- Node,
13
- } from "@discord/markdown-types";
1
+ import {} from "@discord/markdown-types";
2
+ import type React from "react";
14
3
 
15
4
  type NodeRenderProps<P> = P & { siblings: Node[]; index: number };
16
- type NodeRenderPropsWithChildren<P = {}> = React.PropsWithChildren<
17
- NodeRenderProps<P>
5
+ type NodeRenderPropsWithChildren<P = unknown> = React.PropsWithChildren<
6
+ NodeRenderProps<P>
18
7
  >;
19
8
 
20
9
  // inline
@@ -31,17 +20,17 @@ export type CodeProps = NodeRenderPropsWithChildren;
31
20
  export type CodeBlockProps = NodeRenderProps<CodeBlock["value"]>;
32
21
 
33
22
  export type InlineProps =
34
- | BoldProps
35
- | ItalicProps
36
- | UnderlineProps
37
- | StrikethroughProps
38
- | SpoilerProps
39
- | EmojiProps
40
- | TimestampProps
41
- | MentionProps
42
- | LinkProps
43
- | CodeProps
44
- | CodeBlockProps;
23
+ | BoldProps
24
+ | ItalicProps
25
+ | UnderlineProps
26
+ | StrikethroughProps
27
+ | SpoilerProps
28
+ | EmojiProps
29
+ | TimestampProps
30
+ | MentionProps
31
+ | LinkProps
32
+ | CodeProps
33
+ | CodeBlockProps;
45
34
 
46
35
  // block
47
36
  export type HeadingProps = NodeRenderPropsWithChildren<{ level: 1 | 2 | 3 }>;
@@ -58,62 +47,62 @@ export type EmptyProps = NodeRenderProps;
58
47
  export type ListItemProps = NodeRenderPropsWithChildren;
59
48
 
60
49
  export type TopLevelProps =
61
- | TextProps
62
- | ParagraphProps
63
- | EmptyProps
64
- | ListItemProps;
50
+ | TextProps
51
+ | ParagraphProps
52
+ | EmptyProps
53
+ | ListItemProps;
65
54
 
66
55
  export type AllProps = InlineProps | BlockProps | TopLevelProps;
67
56
 
68
57
  export type RendererProps = {
69
- // inline
70
- bold: BoldProps;
71
- italic: ItalicProps;
72
- underline: UnderlineProps;
73
- strikethrough: StrikethroughProps;
74
- spoiler: SpoilerProps;
75
- emoji: EmojiProps;
76
- timestamp: TimestampProps;
77
- mention: MentionProps;
78
- link: LinkProps;
79
- code: CodeProps;
80
- code_block: CodeBlockProps;
81
-
82
- // block
83
- heading: HeadingProps;
84
- list: ListProps;
85
- quote: QuoteProps;
86
- small: SmallProps;
87
-
88
- // top-level
89
- text: TextProps;
90
- paragraph: ParagraphProps;
91
- empty: EmptyProps;
92
-
93
- // pseudo
94
- listItem: ListItemProps;
58
+ // inline
59
+ bold: BoldProps;
60
+ italic: ItalicProps;
61
+ underline: UnderlineProps;
62
+ strikethrough: StrikethroughProps;
63
+ spoiler: SpoilerProps;
64
+ emoji: EmojiProps;
65
+ timestamp: TimestampProps;
66
+ mention: MentionProps;
67
+ link: LinkProps;
68
+ code: CodeProps;
69
+ code_block: CodeBlockProps;
70
+
71
+ // block
72
+ heading: HeadingProps;
73
+ list: ListProps;
74
+ quote: QuoteProps;
75
+ small: SmallProps;
76
+
77
+ // top-level
78
+ text: TextProps;
79
+ paragraph: ParagraphProps;
80
+ empty: EmptyProps;
81
+
82
+ // pseudo
83
+ listItem: ListItemProps;
95
84
  };
96
85
 
97
86
  export type Renderers = {
98
- readonly [K in keyof RendererProps]?: React.FC<RendererProps[K]>;
87
+ readonly [K in keyof RendererProps]?: React.FC<RendererProps[K]>;
99
88
  };
100
89
 
101
90
  export type NodeProps = {
102
- node: AnyNode;
103
- renderers: Renderers;
91
+ node: AnyNode;
92
+ renderers: Renderers;
104
93
  };
105
94
 
106
95
  export type NodeListProps = {
107
- nodes: AnyNode[];
108
- renderers: Renderers;
96
+ nodes: AnyNode[];
97
+ renderers: Renderers;
109
98
  };
110
99
 
111
100
  export type MarkdownProps = {
112
- content: string;
113
- renderers: Renderers;
101
+ content: string;
102
+ renderers: Renderers;
114
103
  };
115
104
 
116
- export const RULES: Set<string>;
105
+ declare const RULES: Set<string>;
117
106
 
118
107
  export function useAst(): Block[];
119
108
  export function Node(props: NodeProps): React.ReactNode;