@gild-ui/react-markdown 0.0.0 → 0.1.0-alpha.0
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 +21 -0
- package/README.md +179 -2
- package/dist/CodeBlock.cjs +136 -0
- package/dist/CodeBlock.d.cts +15 -0
- package/dist/CodeBlock.d.mts +3 -0
- package/dist/CodeBlock.mjs +133 -0
- package/dist/Control.cjs +60 -0
- package/dist/Control.d.cts +16 -0
- package/dist/Control.d.mts +16 -0
- package/dist/Control.mjs +59 -0
- package/dist/Editor.cjs +131 -0
- package/dist/Editor.d.cts +48 -0
- package/dist/Editor.d.mts +48 -0
- package/dist/Editor.mjs +130 -0
- package/dist/LiveEdit-1-8cA5Xw.mjs +215 -0
- package/dist/LiveEdit-B83sDZXu.cjs +224 -0
- package/dist/LiveEdit.cjs +3 -0
- package/dist/LiveEdit.d.cts +29 -0
- package/dist/LiveEdit.d.mts +29 -0
- package/dist/LiveEdit.mjs +1 -0
- package/dist/MarkdownContext-D28Czdll.mjs +10 -0
- package/dist/MarkdownContext-DS1X9B6N.cjs +21 -0
- package/dist/Mermaid-DW0NuDS-.mjs +248 -0
- package/dist/Mermaid-D_tCNrQ9.cjs +253 -0
- package/dist/Mermaid.cjs +3 -0
- package/dist/Mermaid.d.cts +2 -0
- package/dist/Mermaid.d.mts +2 -0
- package/dist/Mermaid.mjs +1 -0
- package/dist/Preview-BLXtPaa9.mjs +258 -0
- package/dist/Preview-D-AL97QU.cjs +268 -0
- package/dist/Preview.cjs +3 -0
- package/dist/Preview.d.cts +56 -0
- package/dist/Preview.d.mts +2 -0
- package/dist/Preview.mjs +1 -0
- package/dist/Toolbar-Eg7KmYbK.mjs +603 -0
- package/dist/Toolbar-gk3KJhCE.cjs +614 -0
- package/dist/Toolbar.cjs +4 -0
- package/dist/Toolbar.d.cts +18 -0
- package/dist/Toolbar.d.mts +18 -0
- package/dist/Toolbar.mjs +1 -0
- package/dist/applyAction-B3AwrWKV.cjs +121 -0
- package/dist/applyAction-CkTQJ5Iy.mjs +116 -0
- package/dist/index-BBkHCbE7.d.mts +15 -0
- package/dist/index-BVYb370O.d.cts +24 -0
- package/dist/index-CfPKWPpM.d.mts +57 -0
- package/dist/index-CyddYU7P.d.mts +24 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.mts +80 -0
- package/dist/index.mjs +9 -0
- package/dist/mergeOverrides-D2btS1Jb.cjs +19 -0
- package/dist/mergeOverrides-DEbU7yDg.mjs +14 -0
- package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
- package/dist/themeTypes-C4kTtkIA.d.cts +83 -0
- package/dist/themeTypes-C4kTtkIA.d.mts +83 -0
- package/package.json +163 -3
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
2
|
+
const require_CodeBlock = require("./CodeBlock.cjs");
|
|
3
|
+
const require_Mermaid = require("./Mermaid-D_tCNrQ9.cjs");
|
|
4
|
+
const require_mergeOverrides = require("./mergeOverrides-D2btS1Jb.cjs");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _gild_ui_react_Typography = require("@gild-ui/react/Typography");
|
|
8
|
+
let _gild_ui_react = require("@gild-ui/react");
|
|
9
|
+
let _gild_ui_react_View = require("@gild-ui/react/View");
|
|
10
|
+
let react_markdown = require("react-markdown");
|
|
11
|
+
react_markdown = require_rolldown_runtime.__toESM(react_markdown, 1);
|
|
12
|
+
let remark_gfm = require("remark-gfm");
|
|
13
|
+
remark_gfm = require_rolldown_runtime.__toESM(remark_gfm, 1);
|
|
14
|
+
let rehype_highlight = require("rehype-highlight");
|
|
15
|
+
rehype_highlight = require_rolldown_runtime.__toESM(rehype_highlight, 1);
|
|
16
|
+
let rehype_slug = require("rehype-slug");
|
|
17
|
+
rehype_slug = require_rolldown_runtime.__toESM(rehype_slug, 1);
|
|
18
|
+
let _gild_ui_react_Quote = require("@gild-ui/react/Quote");
|
|
19
|
+
let _gild_ui_react_Checkbox = require("@gild-ui/react/Checkbox");
|
|
20
|
+
let _gild_ui_react_Image = require("@gild-ui/react/Image");
|
|
21
|
+
let _gild_ui_react_Link = require("@gild-ui/react/Link");
|
|
22
|
+
let _gild_ui_react_Table = require("@gild-ui/react/Table");
|
|
23
|
+
function mermaidSource(children) {
|
|
24
|
+
return (Array.isArray(children) ? children.join("") : String(children ?? "")).replace(/\n$/, "");
|
|
25
|
+
}
|
|
26
|
+
function isMermaidBlock(children) {
|
|
27
|
+
if (!(0, react.isValidElement)(children)) return false;
|
|
28
|
+
const { className } = children.props;
|
|
29
|
+
return typeof className === "string" && className.includes("language-mermaid");
|
|
30
|
+
}
|
|
31
|
+
// src/Preview/Preview.tsx
|
|
32
|
+
const taskItem = _gild_ui_react.StyleSheet.create({ item: { listStyleType: "none" } });
|
|
33
|
+
const remarkPlugins = [remark_gfm.default];
|
|
34
|
+
const rehypePlugins = [rehype_slug.default, [rehype_highlight.default, { ignoreMissing: true }]];
|
|
35
|
+
const PreviewRoot = (0, _gild_ui_react.styled)(_gild_ui_react_View.View, {
|
|
36
|
+
name: "MarkdownPreview",
|
|
37
|
+
label: "MarkdownPreview"
|
|
38
|
+
})({
|
|
39
|
+
minWidth: 0,
|
|
40
|
+
maxWidth: "100%",
|
|
41
|
+
overflowWrap: "break-word"
|
|
42
|
+
});
|
|
43
|
+
const alignOf = (style) => style?.textAlign;
|
|
44
|
+
const EMPTY_SLOT_PROPS = {};
|
|
45
|
+
const SlotPropsContext = (0, react.createContext)(EMPTY_SLOT_PROPS);
|
|
46
|
+
function slotted(render) {
|
|
47
|
+
function Slotted(props) {
|
|
48
|
+
return render((0, react.useContext)(SlotPropsContext), props);
|
|
49
|
+
}
|
|
50
|
+
return Slotted;
|
|
51
|
+
}
|
|
52
|
+
const components = {
|
|
53
|
+
h1: slotted(({ h1 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
54
|
+
id,
|
|
55
|
+
mt: 2,
|
|
56
|
+
variant: "h1",
|
|
57
|
+
color: "primary",
|
|
58
|
+
gutterBottom: true,
|
|
59
|
+
...h1,
|
|
60
|
+
children
|
|
61
|
+
})),
|
|
62
|
+
h2: slotted(({ h2 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
63
|
+
id,
|
|
64
|
+
mt: 2,
|
|
65
|
+
variant: "h2",
|
|
66
|
+
color: "primary",
|
|
67
|
+
gutterBottom: true,
|
|
68
|
+
...h2,
|
|
69
|
+
children
|
|
70
|
+
})),
|
|
71
|
+
h3: slotted(({ h3 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
72
|
+
id,
|
|
73
|
+
mt: 2,
|
|
74
|
+
variant: "h3",
|
|
75
|
+
color: "primary",
|
|
76
|
+
gutterBottom: true,
|
|
77
|
+
...h3,
|
|
78
|
+
children
|
|
79
|
+
})),
|
|
80
|
+
h4: slotted(({ h4 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
81
|
+
id,
|
|
82
|
+
mt: 2,
|
|
83
|
+
variant: "h4",
|
|
84
|
+
gutterBottom: true,
|
|
85
|
+
...h4,
|
|
86
|
+
children
|
|
87
|
+
})),
|
|
88
|
+
h5: slotted(({ h5 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
89
|
+
id,
|
|
90
|
+
mt: 2,
|
|
91
|
+
variant: "h5",
|
|
92
|
+
gutterBottom: true,
|
|
93
|
+
...h5,
|
|
94
|
+
children
|
|
95
|
+
})),
|
|
96
|
+
h6: slotted(({ h6 }, { id, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
97
|
+
id,
|
|
98
|
+
mt: 2,
|
|
99
|
+
variant: "h6",
|
|
100
|
+
gutterBottom: true,
|
|
101
|
+
...h6,
|
|
102
|
+
children
|
|
103
|
+
})),
|
|
104
|
+
p: slotted(({ p }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
105
|
+
variant: "body1",
|
|
106
|
+
color: "secondary",
|
|
107
|
+
mb: 2,
|
|
108
|
+
lineHeight: "relaxed",
|
|
109
|
+
...p,
|
|
110
|
+
children
|
|
111
|
+
})),
|
|
112
|
+
a: slotted(({ a }, { href, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Link.Link, {
|
|
113
|
+
href,
|
|
114
|
+
underline: "hover",
|
|
115
|
+
...a,
|
|
116
|
+
children
|
|
117
|
+
})),
|
|
118
|
+
strong: slotted(({ strong }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
119
|
+
as: "strong",
|
|
120
|
+
variant: "inherit",
|
|
121
|
+
fontWeight: "extraBold",
|
|
122
|
+
...strong,
|
|
123
|
+
children
|
|
124
|
+
})),
|
|
125
|
+
em: slotted(({ em }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
126
|
+
as: "em",
|
|
127
|
+
variant: "inherit",
|
|
128
|
+
fontStyle: "italic",
|
|
129
|
+
...em,
|
|
130
|
+
children
|
|
131
|
+
})),
|
|
132
|
+
ul: slotted(({ ul }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_View.View, {
|
|
133
|
+
as: "ul",
|
|
134
|
+
pl: 3,
|
|
135
|
+
mb: 2,
|
|
136
|
+
...ul,
|
|
137
|
+
children
|
|
138
|
+
})),
|
|
139
|
+
ol: slotted(({ ol }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_View.View, {
|
|
140
|
+
as: "ol",
|
|
141
|
+
pl: 3,
|
|
142
|
+
mb: 2,
|
|
143
|
+
...ol,
|
|
144
|
+
children
|
|
145
|
+
})),
|
|
146
|
+
li: slotted(({ li }, { children, className }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
147
|
+
as: "li",
|
|
148
|
+
color: "secondary",
|
|
149
|
+
lineHeight: "base",
|
|
150
|
+
variant: "body1",
|
|
151
|
+
gutterBottom: true,
|
|
152
|
+
style: className?.includes("task-list-item") && taskItem.item,
|
|
153
|
+
...li,
|
|
154
|
+
children
|
|
155
|
+
})),
|
|
156
|
+
input: slotted(({ input }, { checked }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Checkbox.Checkbox, {
|
|
157
|
+
checked: Boolean(checked),
|
|
158
|
+
disabled: true,
|
|
159
|
+
color: "primary",
|
|
160
|
+
size: "sm",
|
|
161
|
+
"aria-label": "Task item",
|
|
162
|
+
mr: 1,
|
|
163
|
+
...input
|
|
164
|
+
})),
|
|
165
|
+
blockquote: slotted(({ blockquote }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Quote.Quote, {
|
|
166
|
+
as: "blockquote",
|
|
167
|
+
pl: 3,
|
|
168
|
+
py: 1,
|
|
169
|
+
my: 2,
|
|
170
|
+
...blockquote,
|
|
171
|
+
children
|
|
172
|
+
})),
|
|
173
|
+
code: slotted(({ code, mermaid }, { className, children }) => {
|
|
174
|
+
const classes = className ?? "";
|
|
175
|
+
if (classes.includes("language-mermaid")) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Mermaid.Mermaid, {
|
|
176
|
+
chart: mermaidSource(children),
|
|
177
|
+
...mermaid
|
|
178
|
+
});
|
|
179
|
+
const isBlock = classes.includes("language-");
|
|
180
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Typography.Typography, {
|
|
181
|
+
as: "code",
|
|
182
|
+
className,
|
|
183
|
+
color: "initial",
|
|
184
|
+
variant: "inherit",
|
|
185
|
+
fontFamily: "mono",
|
|
186
|
+
display: isBlock ? "block" : "inline",
|
|
187
|
+
bg: isBlock ? "transparent" : "paper",
|
|
188
|
+
px: isBlock ? 0 : 1,
|
|
189
|
+
borderRadius: "sm",
|
|
190
|
+
...code,
|
|
191
|
+
children
|
|
192
|
+
});
|
|
193
|
+
}),
|
|
194
|
+
pre: slotted(({ pre }, { children }) => isMermaidBlock(children) ? children : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CodeBlock.CodeBlock, {
|
|
195
|
+
...pre,
|
|
196
|
+
children
|
|
197
|
+
})),
|
|
198
|
+
table: slotted(({ table }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableContainer, {
|
|
199
|
+
my: 2,
|
|
200
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.Table, {
|
|
201
|
+
bg: "terminal",
|
|
202
|
+
borderRadius: "md",
|
|
203
|
+
...table,
|
|
204
|
+
children
|
|
205
|
+
})
|
|
206
|
+
})),
|
|
207
|
+
thead: slotted(({ thead }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableHead, {
|
|
208
|
+
bg: "grid",
|
|
209
|
+
color: "primary",
|
|
210
|
+
...thead,
|
|
211
|
+
children
|
|
212
|
+
})),
|
|
213
|
+
tbody: slotted(({ tbody }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableBody, {
|
|
214
|
+
...tbody,
|
|
215
|
+
children
|
|
216
|
+
})),
|
|
217
|
+
tr: slotted(({ tr }, { children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableRow, {
|
|
218
|
+
isHoverable: true,
|
|
219
|
+
...tr,
|
|
220
|
+
children
|
|
221
|
+
})),
|
|
222
|
+
th: slotted(({ th }, { children, style }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableCell, {
|
|
223
|
+
align: alignOf(style),
|
|
224
|
+
...th,
|
|
225
|
+
children
|
|
226
|
+
})),
|
|
227
|
+
td: slotted(({ td }, { children, style }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Table.TableCell, {
|
|
228
|
+
align: alignOf(style),
|
|
229
|
+
...td,
|
|
230
|
+
children
|
|
231
|
+
})),
|
|
232
|
+
hr: slotted(({ hr }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_View.View, {
|
|
233
|
+
as: "hr",
|
|
234
|
+
my: 2,
|
|
235
|
+
height: "1px",
|
|
236
|
+
bg: "grid",
|
|
237
|
+
width: "100%",
|
|
238
|
+
border: "none",
|
|
239
|
+
...hr
|
|
240
|
+
})),
|
|
241
|
+
img: slotted(({ img }, { src, alt }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gild_ui_react_Image.Image, {
|
|
242
|
+
src,
|
|
243
|
+
alt,
|
|
244
|
+
maxWidth: "100%",
|
|
245
|
+
...img
|
|
246
|
+
}))
|
|
247
|
+
};
|
|
248
|
+
/** Renders a markdown string with every element mapped to a design-system primitive. */
|
|
249
|
+
function Preview({ children, slotProps, style }) {
|
|
250
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PreviewRoot, {
|
|
251
|
+
...require_mergeOverrides.mergeOverrides(slotProps?.root, { style }),
|
|
252
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotPropsContext.Provider, {
|
|
253
|
+
value: slotProps ?? EMPTY_SLOT_PROPS,
|
|
254
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_markdown.default, {
|
|
255
|
+
components,
|
|
256
|
+
remarkPlugins,
|
|
257
|
+
rehypePlugins,
|
|
258
|
+
children
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
Object.defineProperty(exports, "Preview", {
|
|
264
|
+
enumerable: true,
|
|
265
|
+
get: function() {
|
|
266
|
+
return Preview;
|
|
267
|
+
}
|
|
268
|
+
});
|
package/dist/Preview.cjs
ADDED
|
@@ -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;
|
package/dist/Preview.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Preview } from "./Preview-BLXtPaa9.mjs";
|