@d1vij/react-mdx-loader 0.1.2 → 0.1.3

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/index.d.ts CHANGED
@@ -10,14 +10,4 @@ type MDXFromComponentProps = {
10
10
  SourceComponent: MDXSourceComponent;
11
11
  };
12
12
  declare function MDXFromComponent({ SourceComponent }: MDXFromComponentProps): JSX;
13
- import { Options as MDXOptions } from "@mdx-js/rollup";
14
- import { Plugin } from "vite";
15
- type MDXLoaderPluginOptions = {
16
- mdxPluginOptions?: MDXOptions;
17
- };
18
- /**
19
- * Vite plugin to support MDX conversion.
20
- * Users wont have to explicitly setup their vite config
21
- */
22
- declare function MDXLoaderPlugin({ mdxPluginOptions }: MDXLoaderPluginOptions): Plugin;
23
- export { StyleContext, MDXLoaderPlugin, MDXFromComponent, HeaderLevels };
13
+ export { StyleContext, MDXFromComponent, HeaderLevels };
package/dist/index.js CHANGED
@@ -1 +1,259 @@
1
- import{createContext as U,useContext as G}from"react";var p=U({});function o(){return G(p)}import{cn as R}from"@d1vij/shit-i-always-use";import{useMemo as W,useState as Y}from"react";import{jsxDEV as Z}from"react/jsx-dev-runtime";function h(t){let e=W(()=>new URL(window.location.href).origin.toString(),[]),r=o(),[s]=Y(()=>{if(t.href?.match(/^#.*/))return"_self";return new URL(t.href??"").origin.toString()===e?"_self":"_blank"});return Z("a",{className:R(r.anchor),target:s,href:t.href,children:t.children},void 0,!1,void 0,this)}import{cn as $}from"@d1vij/shit-i-always-use";import{jsxDEV as x}from"react/jsx-dev-runtime";function c(t){let e=o();return x("blockquote",{className:$(e.blockquote),children:t.children},void 0,!1,void 0,this)}import{cn as A}from"@d1vij/shit-i-always-use";import{jsxDEV as Q}from"react/jsx-dev-runtime";function _(t){let e=o();return Q("span",{className:A(e.bold),children:t.children},void 0,!1,void 0,this)}import{cn as T}from"@d1vij/shit-i-always-use";import{jsxDEV as B}from"react/jsx-dev-runtime";function i(t){let e=o(),r=/language-(\w+)/.exec(t.className||"")?.[1];return B("code",{className:T(e.code,r&&`language-${r}`),children:t.children},void 0,!1,void 0,this)}import{cn as I,useClipboardText as H}from"@d1vij/shit-i-always-use";import{useEffect as D,useRef as v,useState as V}from"react";import{jsxDEV as b}from"react/jsx-dev-runtime";function n(t){let e=o(),r=v(null),[s,u]=V(""),{copy:d}=H();async function K(){let X=new URL(`/#${s}`,window.location.origin).toString();console.log("clicked"),await d(X)}return D(()=>{if(!r.current)return;let O=(r.current.textContent??"").toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").slice(0,30);u(O)},[]),b("h1",{className:I(e.header,e[`header_${t.level}`]),children:b("button",{onClick:()=>void K(),ref:r,id:s,type:"button",children:t.children},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{cn as j}from"@d1vij/shit-i-always-use";import{jsxDEV as tt}from"react/jsx-dev-runtime";function y(t){let e=o();return tt("img",{className:j(e.image),alt:t.alt,title:t.title,src:t.src},void 0,!1,void 0,this)}import{cn as et}from"@d1vij/shit-i-always-use";import{jsxDEV as ot}from"react/jsx-dev-runtime";function J(t){let e=o();return ot("span",{className:et(e.italic),children:t.children},void 0,!1,void 0,this)}import{cn as P}from"@d1vij/shit-i-always-use";import{jsxDEV as C}from"react/jsx-dev-runtime";function a(t){let e=o(),r=t.type==="ordered"?"ol":"ul";return C(r,{className:P(e.list,t.type==="ordered"&&e.ordered_list,t.type==="unordered"&&e.unordered_list),children:t.children},void 0,!1,void 0,this)}function g(t){let e=o();return C("li",{className:P(e.list_item),children:t.children},void 0,!1,void 0,this)}import{cn as rt}from"@d1vij/shit-i-always-use";import{jsxDEV as nt}from"react/jsx-dev-runtime";function N(t){let e=o();return nt("p",{className:rt(e.paragraph),children:t.children},void 0,!1,void 0,this)}import{cn as lt}from"@d1vij/shit-i-always-use";import{jsxDEV as mt}from"react/jsx-dev-runtime";function f(t){let e=o();return mt("pre",{className:lt(e.preformatted),children:t.children},void 0,!1,void 0,this)}import{cn as st}from"@d1vij/shit-i-always-use";import{jsxDEV as at}from"react/jsx-dev-runtime";function M(t){let e=o();return at("span",{className:st(e.striked),children:t.children},void 0,!1,void 0,this)}import{cn as l}from"@d1vij/shit-i-always-use";import{jsxDEV as m}from"react/jsx-dev-runtime";function E(t){let e=o();return m("table",{className:l(e.table),children:t.children},void 0,!1,void 0,this)}function L(t){let e=o();return m("thead",{className:l(e.table_head),children:t.children},void 0,!1,void 0,this)}function k(t){let e=o();return m("tbody",{className:l(e.table_body),children:t.children},void 0,!1,void 0,this)}function q(t){let e=o();return m("tr",{className:l(e.table_row),children:t.children},void 0,!1,void 0,this)}function F(t){let e=o();return m("th",{className:l(e.table_head_cell),children:t.children},void 0,!1,void 0,this)}function w(t){let e=o();return m("td",{className:l(e.table_data),children:t.children},void 0,!1,void 0,this)}var pt={h1:(t)=>n({...t,level:1}),h2:(t)=>n({...t,level:2}),h3:(t)=>n({...t,level:3}),h4:(t)=>n({...t,level:4}),h5:(t)=>n({...t,level:5}),h6:(t)=>n({...t,level:6}),a:h,em:J,del:M,strong:_,code:i,blockquote:c,pre:f,p:N,ol:(t)=>a({...t,type:"ordered"}),ul:(t)=>a({...t,type:"unordered"}),li:g,img:y,table:E,thead:L,tbody:k,th:F,tr:q,td:w},S=pt;import{jsxDEV as ct}from"react/jsx-dev-runtime";function z({SourceComponent:t}){return ct(t,{components:S},void 0,!1,void 0,this)}import it from"@mdx-js/rollup";function yt({mdxPluginOptions:t}){return{name:"react-mdx-loader-plugin",enforce:"pre",config(e){return{...e,plugins:[it(t)]}}}}export{p as StyleContext,yt as MDXLoaderPlugin,z as MDXFromComponent};
1
+ // src/StyleContext.ts
2
+ import { createContext, useContext } from "react";
3
+ var StyleContext = createContext({});
4
+ function useStyles() {
5
+ return useContext(StyleContext);
6
+ }
7
+ // src/components/Elements/Anchor.tsx
8
+ import { cn } from "@d1vij/shit-i-always-use";
9
+ import { useMemo, useState } from "react";
10
+ import { jsxDEV } from "react/jsx-dev-runtime";
11
+ function Anchor(props) {
12
+ const selfOrigin = useMemo(() => new URL(window.location.href).origin.toString(), []);
13
+ const styles = useStyles();
14
+ const [target] = useState(() => {
15
+ const href = props.href;
16
+ if (href?.match(/^#.*/)) {
17
+ return "_self";
18
+ }
19
+ const targetOrigin = new URL(props.href ?? "").origin.toString();
20
+ return targetOrigin === selfOrigin ? "_self" : "_blank";
21
+ });
22
+ return /* @__PURE__ */ jsxDEV("a", {
23
+ className: cn(styles.anchor),
24
+ target,
25
+ href: props.href,
26
+ children: props.children
27
+ }, undefined, false, undefined, this);
28
+ }
29
+
30
+ // src/components/Elements/BlockQuote.tsx
31
+ import { cn as cn2 } from "@d1vij/shit-i-always-use";
32
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
33
+ function BlockQuote(props) {
34
+ const styles = useStyles();
35
+ return /* @__PURE__ */ jsxDEV2("blockquote", {
36
+ className: cn2(styles.blockquote),
37
+ children: props.children
38
+ }, undefined, false, undefined, this);
39
+ }
40
+
41
+ // src/components/Elements/Bold.tsx
42
+ import { cn as cn3 } from "@d1vij/shit-i-always-use";
43
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
44
+ function Bold(props) {
45
+ const styles = useStyles();
46
+ return /* @__PURE__ */ jsxDEV3("span", {
47
+ className: cn3(styles.bold),
48
+ children: props.children
49
+ }, undefined, false, undefined, this);
50
+ }
51
+
52
+ // src/components/Elements/Code.tsx
53
+ import { cn as cn4 } from "@d1vij/shit-i-always-use";
54
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
55
+ function Code(props) {
56
+ const styles = useStyles();
57
+ const lang = /language-(\w+)/.exec(props.className || "")?.[1];
58
+ return /* @__PURE__ */ jsxDEV4("code", {
59
+ className: cn4(styles.code, lang && `language-${lang}`),
60
+ children: props.children
61
+ }, undefined, false, undefined, this);
62
+ }
63
+
64
+ // src/components/Elements/Heading.tsx
65
+ import { cn as cn5, useClipboardText } from "@d1vij/shit-i-always-use";
66
+ import { useEffect, useRef, useState as useState2 } from "react";
67
+ import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
68
+ function Header(props) {
69
+ const styles = useStyles();
70
+ const headerRef = useRef(null);
71
+ const [id, setId] = useState2("");
72
+ const { copy } = useClipboardText();
73
+ async function handleClick() {
74
+ const url = new URL(`/#${id}`, window.location.origin).toString();
75
+ console.log("clicked");
76
+ await copy(url);
77
+ }
78
+ useEffect(() => {
79
+ if (!headerRef.current)
80
+ return;
81
+ const raw = headerRef.current.textContent ?? "";
82
+ const safe = raw.toLowerCase().replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-").slice(0, 30);
83
+ setId(safe);
84
+ }, []);
85
+ return /* @__PURE__ */ jsxDEV5("h1", {
86
+ className: cn5(styles.header, styles[`header_${props.level}`]),
87
+ children: /* @__PURE__ */ jsxDEV5("button", {
88
+ onClick: () => void handleClick(),
89
+ ref: headerRef,
90
+ id,
91
+ type: "button",
92
+ children: props.children
93
+ }, undefined, false, undefined, this)
94
+ }, undefined, false, undefined, this);
95
+ }
96
+
97
+ // src/components/Elements/Image.tsx
98
+ import { cn as cn6 } from "@d1vij/shit-i-always-use";
99
+ import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
100
+ function Image(props) {
101
+ const styles = useStyles();
102
+ return /* @__PURE__ */ jsxDEV6("img", {
103
+ className: cn6(styles.image),
104
+ alt: props.alt,
105
+ title: props.title,
106
+ src: props.src
107
+ }, undefined, false, undefined, this);
108
+ }
109
+
110
+ // src/components/Elements/Italics.tsx
111
+ import { cn as cn7 } from "@d1vij/shit-i-always-use";
112
+ import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
113
+ function Italics(props) {
114
+ const styles = useStyles();
115
+ return /* @__PURE__ */ jsxDEV7("span", {
116
+ className: cn7(styles.italic),
117
+ children: props.children
118
+ }, undefined, false, undefined, this);
119
+ }
120
+
121
+ // src/components/Elements/List.tsx
122
+ import { cn as cn8 } from "@d1vij/shit-i-always-use";
123
+ import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
124
+ function List(props) {
125
+ const styles = useStyles();
126
+ const L = props.type === "ordered" ? "ol" : "ul";
127
+ return /* @__PURE__ */ jsxDEV8(L, {
128
+ className: cn8(styles.list, props.type === "ordered" && styles.ordered_list, props.type === "unordered" && styles.unordered_list),
129
+ children: props.children
130
+ }, undefined, false, undefined, this);
131
+ }
132
+ function ListItem(props) {
133
+ const styles = useStyles();
134
+ return /* @__PURE__ */ jsxDEV8("li", {
135
+ className: cn8(styles.list_item),
136
+ children: props.children
137
+ }, undefined, false, undefined, this);
138
+ }
139
+
140
+ // src/components/Elements/Paragraph.tsx
141
+ import { cn as cn9 } from "@d1vij/shit-i-always-use";
142
+ import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
143
+ function Paragraph(props) {
144
+ const styles = useStyles();
145
+ return /* @__PURE__ */ jsxDEV9("p", {
146
+ className: cn9(styles.paragraph),
147
+ children: props.children
148
+ }, undefined, false, undefined, this);
149
+ }
150
+
151
+ // src/components/Elements/Preformatted.tsx
152
+ import { cn as cn10 } from "@d1vij/shit-i-always-use";
153
+ import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
154
+ function Preformatted(props) {
155
+ const styles = useStyles();
156
+ return /* @__PURE__ */ jsxDEV10("pre", {
157
+ className: cn10(styles.preformatted),
158
+ children: props.children
159
+ }, undefined, false, undefined, this);
160
+ }
161
+
162
+ // src/components/Elements/Striked.tsx
163
+ import { cn as cn11 } from "@d1vij/shit-i-always-use";
164
+ import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
165
+ function Striked(props) {
166
+ const styles = useStyles();
167
+ return /* @__PURE__ */ jsxDEV11("span", {
168
+ className: cn11(styles.striked),
169
+ children: props.children
170
+ }, undefined, false, undefined, this);
171
+ }
172
+
173
+ // src/components/Elements/Table.tsx
174
+ import { cn as cn12 } from "@d1vij/shit-i-always-use";
175
+ import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
176
+ function Table(props) {
177
+ const styles = useStyles();
178
+ return /* @__PURE__ */ jsxDEV12("table", {
179
+ className: cn12(styles.table),
180
+ children: props.children
181
+ }, undefined, false, undefined, this);
182
+ }
183
+ function TableHead(props) {
184
+ const styles = useStyles();
185
+ return /* @__PURE__ */ jsxDEV12("thead", {
186
+ className: cn12(styles.table_head),
187
+ children: props.children
188
+ }, undefined, false, undefined, this);
189
+ }
190
+ function TableBody(props) {
191
+ const styles = useStyles();
192
+ return /* @__PURE__ */ jsxDEV12("tbody", {
193
+ className: cn12(styles.table_body),
194
+ children: props.children
195
+ }, undefined, false, undefined, this);
196
+ }
197
+ function TableRow(props) {
198
+ const styles = useStyles();
199
+ return /* @__PURE__ */ jsxDEV12("tr", {
200
+ className: cn12(styles.table_row),
201
+ children: props.children
202
+ }, undefined, false, undefined, this);
203
+ }
204
+ function TableHeadCell(props) {
205
+ const styles = useStyles();
206
+ return /* @__PURE__ */ jsxDEV12("th", {
207
+ className: cn12(styles.table_head_cell),
208
+ children: props.children
209
+ }, undefined, false, undefined, this);
210
+ }
211
+ function TableData(props) {
212
+ const styles = useStyles();
213
+ return /* @__PURE__ */ jsxDEV12("td", {
214
+ className: cn12(styles.table_data),
215
+ children: props.children
216
+ }, undefined, false, undefined, this);
217
+ }
218
+
219
+ // src/components/Elements/Elements.tsx
220
+ var Elements = {
221
+ h1: (props) => Header({ ...props, level: 1 }),
222
+ h2: (props) => Header({ ...props, level: 2 }),
223
+ h3: (props) => Header({ ...props, level: 3 }),
224
+ h4: (props) => Header({ ...props, level: 4 }),
225
+ h5: (props) => Header({ ...props, level: 5 }),
226
+ h6: (props) => Header({ ...props, level: 6 }),
227
+ a: Anchor,
228
+ em: Italics,
229
+ del: Striked,
230
+ strong: Bold,
231
+ code: Code,
232
+ blockquote: BlockQuote,
233
+ pre: Preformatted,
234
+ p: Paragraph,
235
+ ol: (props) => List({ ...props, type: "ordered" }),
236
+ ul: (props) => List({ ...props, type: "unordered" }),
237
+ li: ListItem,
238
+ img: Image,
239
+ table: Table,
240
+ thead: TableHead,
241
+ tbody: TableBody,
242
+ th: TableHeadCell,
243
+ tr: TableRow,
244
+ td: TableData
245
+ };
246
+ var Elements_default = Elements;
247
+ // src/components/MDXLoader.tsx
248
+ import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
249
+ function MDXFromComponent({
250
+ SourceComponent
251
+ }) {
252
+ return /* @__PURE__ */ jsxDEV13(SourceComponent, {
253
+ components: Elements_default
254
+ }, undefined, false, undefined, this);
255
+ }
256
+ export {
257
+ StyleContext,
258
+ MDXFromComponent
259
+ };
@@ -0,0 +1,11 @@
1
+ import { Options as MDXOptions } from "@mdx-js/rollup";
2
+ import { Plugin } from "vite";
3
+ type MDXLoaderPluginOptions = {
4
+ mdxPluginOptions?: MDXOptions;
5
+ };
6
+ /**
7
+ * Vite plugin to support MDX conversion.
8
+ * Users wont have to explicitly setup their vite config
9
+ */
10
+ declare function MDXLoaderPlugin({ mdxPluginOptions }: MDXLoaderPluginOptions): Plugin;
11
+ export { MDXLoaderPlugin };
@@ -0,0 +1,19 @@
1
+ // src/vitePlugin.ts
2
+ import mdx from "@mdx-js/rollup";
3
+ function MDXLoaderPlugin({
4
+ mdxPluginOptions
5
+ }) {
6
+ return {
7
+ name: "react-mdx-loader-plugin",
8
+ enforce: "pre",
9
+ config(c) {
10
+ return {
11
+ ...c,
12
+ plugins: [mdx(mdxPluginOptions)]
13
+ };
14
+ }
15
+ };
16
+ }
17
+ export {
18
+ MDXLoaderPlugin
19
+ };
package/package.json CHANGED
@@ -1,16 +1,31 @@
1
1
  {
2
2
  "name": "@d1vij/react-mdx-loader",
3
+ "description": "Supporting lib to create content driven sites using MDX",
4
+ "version": "0.1.3",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./plugin": {
19
+ "import": "./dist/plugin.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
3
23
  "repository": {
4
24
  "type": "git",
5
25
  "url": "https://github.com/d1vij/react-mdx-loader"
6
26
  },
7
27
  "homepage": "https://github.com/d1vij/react-mdx-loader",
8
- "version": "0.1.2",
9
- "description": "Supporting lib to create content driven sites using MDX",
10
28
  "license": "MIT",
11
- "files": [
12
- "dist"
13
- ],
14
29
  "sideEffects": false,
15
30
  "publishConfig": {
16
31
  "access": "public"
@@ -49,18 +64,6 @@
49
64
  "optional": true
50
65
  }
51
66
  },
52
- "type": "module",
53
- "exports": {
54
- ".": {
55
- "import": {
56
- "types": "./dist/index.d.ts",
57
- "default": "./dist/index.js"
58
- }
59
- },
60
- "./package.json": "./package.json"
61
- },
62
- "module": "./dist/index.js",
63
- "types": "./dist/index.d.ts",
64
67
  "dependencies": {
65
68
  "@d1vij/shit-i-always-use": "^0.1.3"
66
69
  },