@gild-ui/react-markdown 0.0.0 → 0.1.0-alpha.1

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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -2
  3. package/dist/CodeBlock-BFqv_nVv.mjs +134 -0
  4. package/dist/CodeBlock-BaMe7CiF.cjs +151 -0
  5. package/dist/CodeBlock.cjs +5 -0
  6. package/dist/CodeBlock.d.cts +15 -0
  7. package/dist/CodeBlock.d.mts +3 -0
  8. package/dist/CodeBlock.mjs +1 -0
  9. package/dist/Control.cjs +60 -0
  10. package/dist/Control.d.cts +16 -0
  11. package/dist/Control.d.mts +16 -0
  12. package/dist/Control.mjs +59 -0
  13. package/dist/Editor.cjs +131 -0
  14. package/dist/Editor.d.cts +48 -0
  15. package/dist/Editor.d.mts +48 -0
  16. package/dist/Editor.mjs +130 -0
  17. package/dist/LiveEdit-CXw-vQpD.cjs +224 -0
  18. package/dist/LiveEdit-CzJcNsEo.mjs +215 -0
  19. package/dist/LiveEdit.cjs +3 -0
  20. package/dist/LiveEdit.d.cts +29 -0
  21. package/dist/LiveEdit.d.mts +29 -0
  22. package/dist/LiveEdit.mjs +1 -0
  23. package/dist/MarkdownContext-D28Czdll.mjs +10 -0
  24. package/dist/MarkdownContext-DS1X9B6N.cjs +21 -0
  25. package/dist/Mermaid-DR4XzGaY.mjs +248 -0
  26. package/dist/Mermaid-d1a5LqcK.cjs +253 -0
  27. package/dist/Mermaid.cjs +3 -0
  28. package/dist/Mermaid.d.cts +2 -0
  29. package/dist/Mermaid.d.mts +2 -0
  30. package/dist/Mermaid.mjs +1 -0
  31. package/dist/Preview-CIbu-nRm.cjs +268 -0
  32. package/dist/Preview-DQOQ1NKJ.mjs +258 -0
  33. package/dist/Preview.cjs +3 -0
  34. package/dist/Preview.d.cts +56 -0
  35. package/dist/Preview.d.mts +2 -0
  36. package/dist/Preview.mjs +1 -0
  37. package/dist/Toolbar-Eg7KmYbK.mjs +603 -0
  38. package/dist/Toolbar-gk3KJhCE.cjs +614 -0
  39. package/dist/Toolbar.cjs +4 -0
  40. package/dist/Toolbar.d.cts +18 -0
  41. package/dist/Toolbar.d.mts +18 -0
  42. package/dist/Toolbar.mjs +1 -0
  43. package/dist/applyAction-B3AwrWKV.cjs +121 -0
  44. package/dist/applyAction-CkTQJ5Iy.mjs +116 -0
  45. package/dist/index-BBkHCbE7.d.mts +15 -0
  46. package/dist/index-BVYb370O.d.cts +24 -0
  47. package/dist/index-CfPKWPpM.d.mts +57 -0
  48. package/dist/index-CyddYU7P.d.mts +24 -0
  49. package/dist/index.cjs +21 -0
  50. package/dist/index.d.cts +80 -0
  51. package/dist/index.d.mts +80 -0
  52. package/dist/index.mjs +9 -0
  53. package/dist/mergeOverrides-D2btS1Jb.cjs +19 -0
  54. package/dist/mergeOverrides-DEbU7yDg.mjs +14 -0
  55. package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
  56. package/dist/themeTypes-C4kTtkIA.d.cts +83 -0
  57. package/dist/themeTypes-C4kTtkIA.d.mts +83 -0
  58. package/package.json +166 -3
@@ -0,0 +1,258 @@
1
+ import { r as CodeBlock } from "./CodeBlock-BFqv_nVv.mjs";
2
+ import { t as Mermaid } from "./Mermaid-DR4XzGaY.mjs";
3
+ import { t as mergeOverrides } from "./mergeOverrides-DEbU7yDg.mjs";
4
+ import { createContext, isValidElement, useContext } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { Typography } from "@gild-ui/react/Typography";
7
+ import { StyleSheet, styled } from "@gild-ui/react";
8
+ import { View } from "@gild-ui/react/View";
9
+ import ReactMarkdown from "react-markdown";
10
+ import remarkGfm from "remark-gfm";
11
+ import rehypeHighlight from "rehype-highlight";
12
+ import rehypeSlug from "rehype-slug";
13
+ import { Quote } from "@gild-ui/react/Quote";
14
+ import { Checkbox } from "@gild-ui/react/Checkbox";
15
+ import { Image } from "@gild-ui/react/Image";
16
+ import { Link } from "@gild-ui/react/Link";
17
+ import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from "@gild-ui/react/Table";
18
+ function mermaidSource(children) {
19
+ return (Array.isArray(children) ? children.join("") : String(children ?? "")).replace(/\n$/, "");
20
+ }
21
+ function isMermaidBlock(children) {
22
+ if (!isValidElement(children)) return false;
23
+ const { className } = children.props;
24
+ return typeof className === "string" && className.includes("language-mermaid");
25
+ }
26
+ // src/Preview/Preview.tsx
27
+ const taskItem = StyleSheet.create({ item: { listStyleType: "none" } });
28
+ const remarkPlugins = [remarkGfm];
29
+ const rehypePlugins = [rehypeSlug, [rehypeHighlight, { ignoreMissing: true }]];
30
+ const PreviewRoot = styled(View, {
31
+ name: "MarkdownPreview",
32
+ label: "MarkdownPreview"
33
+ })({
34
+ minWidth: 0,
35
+ maxWidth: "100%",
36
+ overflowWrap: "break-word"
37
+ });
38
+ const alignOf = (style) => style?.textAlign;
39
+ const EMPTY_SLOT_PROPS = {};
40
+ const SlotPropsContext = createContext(EMPTY_SLOT_PROPS);
41
+ function slotted(render) {
42
+ function Slotted(props) {
43
+ return render(useContext(SlotPropsContext), props);
44
+ }
45
+ return Slotted;
46
+ }
47
+ const components = {
48
+ h1: slotted(({ h1 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
49
+ id,
50
+ mt: 2,
51
+ variant: "h1",
52
+ color: "primary",
53
+ gutterBottom: true,
54
+ ...h1,
55
+ children
56
+ })),
57
+ h2: slotted(({ h2 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
58
+ id,
59
+ mt: 2,
60
+ variant: "h2",
61
+ color: "primary",
62
+ gutterBottom: true,
63
+ ...h2,
64
+ children
65
+ })),
66
+ h3: slotted(({ h3 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
67
+ id,
68
+ mt: 2,
69
+ variant: "h3",
70
+ color: "primary",
71
+ gutterBottom: true,
72
+ ...h3,
73
+ children
74
+ })),
75
+ h4: slotted(({ h4 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
76
+ id,
77
+ mt: 2,
78
+ variant: "h4",
79
+ gutterBottom: true,
80
+ ...h4,
81
+ children
82
+ })),
83
+ h5: slotted(({ h5 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
84
+ id,
85
+ mt: 2,
86
+ variant: "h5",
87
+ gutterBottom: true,
88
+ ...h5,
89
+ children
90
+ })),
91
+ h6: slotted(({ h6 }, { id, children }) => /* @__PURE__ */ jsx(Typography, {
92
+ id,
93
+ mt: 2,
94
+ variant: "h6",
95
+ gutterBottom: true,
96
+ ...h6,
97
+ children
98
+ })),
99
+ p: slotted(({ p }, { children }) => /* @__PURE__ */ jsx(Typography, {
100
+ variant: "body1",
101
+ color: "secondary",
102
+ mb: 2,
103
+ lineHeight: "relaxed",
104
+ ...p,
105
+ children
106
+ })),
107
+ a: slotted(({ a }, { href, children }) => /* @__PURE__ */ jsx(Link, {
108
+ href,
109
+ underline: "hover",
110
+ ...a,
111
+ children
112
+ })),
113
+ strong: slotted(({ strong }, { children }) => /* @__PURE__ */ jsx(Typography, {
114
+ as: "strong",
115
+ variant: "inherit",
116
+ fontWeight: "extraBold",
117
+ ...strong,
118
+ children
119
+ })),
120
+ em: slotted(({ em }, { children }) => /* @__PURE__ */ jsx(Typography, {
121
+ as: "em",
122
+ variant: "inherit",
123
+ fontStyle: "italic",
124
+ ...em,
125
+ children
126
+ })),
127
+ ul: slotted(({ ul }, { children }) => /* @__PURE__ */ jsx(View, {
128
+ as: "ul",
129
+ pl: 3,
130
+ mb: 2,
131
+ ...ul,
132
+ children
133
+ })),
134
+ ol: slotted(({ ol }, { children }) => /* @__PURE__ */ jsx(View, {
135
+ as: "ol",
136
+ pl: 3,
137
+ mb: 2,
138
+ ...ol,
139
+ children
140
+ })),
141
+ li: slotted(({ li }, { children, className }) => /* @__PURE__ */ jsx(Typography, {
142
+ as: "li",
143
+ color: "secondary",
144
+ lineHeight: "base",
145
+ variant: "body1",
146
+ gutterBottom: true,
147
+ style: className?.includes("task-list-item") && taskItem.item,
148
+ ...li,
149
+ children
150
+ })),
151
+ input: slotted(({ input }, { checked }) => /* @__PURE__ */ jsx(Checkbox, {
152
+ checked: Boolean(checked),
153
+ disabled: true,
154
+ color: "primary",
155
+ size: "sm",
156
+ "aria-label": "Task item",
157
+ mr: 1,
158
+ ...input
159
+ })),
160
+ blockquote: slotted(({ blockquote }, { children }) => /* @__PURE__ */ jsx(Quote, {
161
+ as: "blockquote",
162
+ pl: 3,
163
+ py: 1,
164
+ my: 2,
165
+ ...blockquote,
166
+ children
167
+ })),
168
+ code: slotted(({ code, mermaid }, { className, children }) => {
169
+ const classes = className ?? "";
170
+ if (classes.includes("language-mermaid")) return /* @__PURE__ */ jsx(Mermaid, {
171
+ chart: mermaidSource(children),
172
+ ...mermaid
173
+ });
174
+ const isBlock = classes.includes("language-");
175
+ return /* @__PURE__ */ jsx(Typography, {
176
+ as: "code",
177
+ className,
178
+ color: "initial",
179
+ variant: "inherit",
180
+ fontFamily: "mono",
181
+ display: isBlock ? "block" : "inline",
182
+ bg: isBlock ? "transparent" : "paper",
183
+ px: isBlock ? 0 : 1,
184
+ borderRadius: "sm",
185
+ ...code,
186
+ children
187
+ });
188
+ }),
189
+ pre: slotted(({ pre }, { children }) => isMermaidBlock(children) ? children : /* @__PURE__ */ jsx(CodeBlock, {
190
+ ...pre,
191
+ children
192
+ })),
193
+ table: slotted(({ table }, { children }) => /* @__PURE__ */ jsx(TableContainer, {
194
+ my: 2,
195
+ children: /* @__PURE__ */ jsx(Table, {
196
+ bg: "terminal",
197
+ borderRadius: "md",
198
+ ...table,
199
+ children
200
+ })
201
+ })),
202
+ thead: slotted(({ thead }, { children }) => /* @__PURE__ */ jsx(TableHead, {
203
+ bg: "grid",
204
+ color: "primary",
205
+ ...thead,
206
+ children
207
+ })),
208
+ tbody: slotted(({ tbody }, { children }) => /* @__PURE__ */ jsx(TableBody, {
209
+ ...tbody,
210
+ children
211
+ })),
212
+ tr: slotted(({ tr }, { children }) => /* @__PURE__ */ jsx(TableRow, {
213
+ isHoverable: true,
214
+ ...tr,
215
+ children
216
+ })),
217
+ th: slotted(({ th }, { children, style }) => /* @__PURE__ */ jsx(TableCell, {
218
+ align: alignOf(style),
219
+ ...th,
220
+ children
221
+ })),
222
+ td: slotted(({ td }, { children, style }) => /* @__PURE__ */ jsx(TableCell, {
223
+ align: alignOf(style),
224
+ ...td,
225
+ children
226
+ })),
227
+ hr: slotted(({ hr }) => /* @__PURE__ */ jsx(View, {
228
+ as: "hr",
229
+ my: 2,
230
+ height: "1px",
231
+ bg: "grid",
232
+ width: "100%",
233
+ border: "none",
234
+ ...hr
235
+ })),
236
+ img: slotted(({ img }, { src, alt }) => /* @__PURE__ */ jsx(Image, {
237
+ src,
238
+ alt,
239
+ maxWidth: "100%",
240
+ ...img
241
+ }))
242
+ };
243
+ /** Renders a markdown string with every element mapped to a design-system primitive. */
244
+ function Preview({ children, slotProps, style }) {
245
+ return /* @__PURE__ */ jsx(PreviewRoot, {
246
+ ...mergeOverrides(slotProps?.root, { style }),
247
+ children: /* @__PURE__ */ jsx(SlotPropsContext.Provider, {
248
+ value: slotProps ?? EMPTY_SLOT_PROPS,
249
+ children: /* @__PURE__ */ jsx(ReactMarkdown, {
250
+ components,
251
+ remarkPlugins,
252
+ rehypePlugins,
253
+ children
254
+ })
255
+ })
256
+ });
257
+ }
258
+ export { Preview as t };
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_Preview = require("./Preview-CIbu-nRm.cjs");
3
+ exports.Preview = require_Preview.Preview;
@@ -0,0 +1,56 @@
1
+ import "./themeTypes-C4kTtkIA.cjs";
2
+ import { CodeBlockProps } from "./CodeBlock.cjs";
3
+ import { r as MermaidProps } from "./index-BVYb370O.cjs";
4
+ import { SlotProps, StyleOverride } from "@gild-ui/react";
5
+ import { QuoteProps } from "@gild-ui/react/Quote";
6
+ import { CheckboxProps } from "@gild-ui/react/Checkbox";
7
+ import { ImageProps } from "@gild-ui/react/Image";
8
+ import { LinkProps } from "@gild-ui/react/Link";
9
+ import { TableBodyProps, TableCellProps, TableHeadProps, TableProps, TableRowProps } from "@gild-ui/react/Table";
10
+ import { TypographyProps } from "@gild-ui/react/Typography";
11
+ import { ViewProps } from "@gild-ui/react/View";
12
+ /**
13
+ * Per-element prop overrides, merged over the design-system defaults (the caller's props win).
14
+ * Keyed by markdown element - e.g. `slotProps={{ p: { color: 'primary' }, h1: { variant: 'h2' } }}` -
15
+ * and by the one slot a theme can style, `root`, which takes a `style`, a `className` and `data-*`
16
+ * and `aria-*` attributes. No markdown element is named `root`.
17
+ */
18
+ export interface PreviewSlotProps extends SlotProps<'root'> {
19
+ h1?: TypographyProps;
20
+ h2?: TypographyProps;
21
+ h3?: TypographyProps;
22
+ h4?: TypographyProps;
23
+ h5?: TypographyProps;
24
+ h6?: TypographyProps;
25
+ p?: TypographyProps;
26
+ strong?: TypographyProps;
27
+ em?: TypographyProps;
28
+ li?: TypographyProps;
29
+ code?: TypographyProps;
30
+ a?: LinkProps;
31
+ ul?: ViewProps;
32
+ ol?: ViewProps;
33
+ hr?: ViewProps;
34
+ blockquote?: QuoteProps;
35
+ img?: ImageProps;
36
+ th?: TableCellProps;
37
+ td?: TableCellProps;
38
+ pre?: CodeBlockProps;
39
+ input?: CheckboxProps;
40
+ table?: TableProps;
41
+ thead?: TableHeadProps;
42
+ tbody?: TableBodyProps;
43
+ tr?: TableRowProps;
44
+ /** Props for a ` ```mermaid ` fence's `Mermaid` renderer - including `diagram` (viewer) props. */
45
+ mermaid?: Omit<MermaidProps, 'chart'>;
46
+ }
47
+ export interface PreviewProps {
48
+ /** The markdown source to render. */
49
+ children: string;
50
+ /** Per-element prop overrides, merged over the defaults. */
51
+ slotProps?: PreviewSlotProps;
52
+ /** Overrides the CSS of the root: an entry of `StyleSheet.create`, or a list of them. It wins over `slotProps.root.style`. */
53
+ style?: StyleOverride;
54
+ }
55
+ /** Renders a markdown string with every element mapped to a design-system primitive. */
56
+ export declare function Preview({ children, slotProps, style }: Readonly<PreviewProps>): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { n as PreviewProps, r as PreviewSlotProps, t as Preview } from "./index-CfPKWPpM.mjs";
2
+ export { Preview, PreviewProps, PreviewSlotProps };
@@ -0,0 +1 @@
1
+ export { t as Preview } from "./Preview-DQOQ1NKJ.mjs";