@d1vij/react-mdx-loader 0.1.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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Divij Verma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # React MDX Loader
2
+
3
+ Supporting lib to create content driven sites using MDX
4
+
5
+ > [!NOTE] WIP
@@ -0,0 +1,22 @@
1
+ type JSX = React.JSX.Element | null;
2
+ type HeaderLevels = 1 | 2 | 3 | 4 | 5 | 6;
3
+ type StyleClasses = "header" | `header_${HeaderLevels}` | "header_icon" | "anchor" | "button" | "bold" | "italic" | "span" | "striked" | "paragraph" | "code" | "preformatted" | "blockquote" | "horizontal_line" | "image" | "list" | `${"un" | ""}ordered_list` | "list_item" | "table" | "table_head" | "table_head_cell" | "table_body" | "table_row" | "table_data";
4
+ type StyleClassesMap = Partial<{ [K in StyleClasses] : string }>;
5
+ declare const StyleContext: React.Context<StyleClassesMap>;
6
+ import { MDXProps } from "mdx/types";
7
+ type MDXSourceComponent = React.ComponentType<MDXProps>;
8
+ type MDXFromComponentProps = {
9
+ SourceComponent: MDXSourceComponent;
10
+ };
11
+ declare function MDXFromComponent({ SourceComponent }: MDXFromComponentProps): JSX;
12
+ import { Options as MDXOptions } from "@mdx-js/rollup";
13
+ import { Plugin } from "vite";
14
+ type MDXLoaderPluginOptions = {
15
+ mdxPluginOptions: MDXOptions;
16
+ };
17
+ /**
18
+ * Vite plugin to support MDX conversion.
19
+ * Users wont have to explicitly setup their vite config
20
+ */
21
+ declare function MDXLoaderPlugin({ mdxPluginOptions }: MDXLoaderPluginOptions): Plugin;
22
+ export { StyleContext, MDXLoaderPlugin, MDXFromComponent, HeaderLevels };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{createContext as G,useContext as K}from"react";var c=G({});function o(){return K(c)}import{cn as W}from"@d1vij/shit-i-always-use";import{useState as Y}from"react";import{jsxDEV as $}from"react/jsx-dev-runtime";var Z=new URL(window.location.href).origin.toString();function J(t){let e=o(),[r]=Y(()=>{if(t.href?.match(/^#.*/))return"_self";return new URL(t.href??"").origin.toString()===Z?"_self":"_blank"});return $("a",{className:W(e.anchor),target:r,href:t.href,children:t.children},void 0,!1,void 0,this)}import{cn as Q}from"@d1vij/shit-i-always-use";import{jsxDEV as R}from"react/jsx-dev-runtime";function f(t){let e=o();return R("blockquote",{className:Q(e.blockquote),children:t.children},void 0,!1,void 0,this)}import{cn as A}from"@d1vij/shit-i-always-use";import{jsxDEV as B}from"react/jsx-dev-runtime";function P(t){let e=o();return B("span",{className:A(e.bold),children:t.children},void 0,!1,void 0,this)}import{cn as I}from"@d1vij/shit-i-always-use";import{jsxDEV as H}from"react/jsx-dev-runtime";function i(t){let e=o(),r=/language-(\w+)/.exec(t.className||"")?.[1];return H("code",{className:I(e.code,r&&`language-${r}`),children:t.children},void 0,!1,void 0,this)}import{cn as T,useClipboardText as D}from"@d1vij/shit-i-always-use";import{useEffect as x,useRef as v,useState as V}from"react";import{jsxDEV as d}from"react/jsx-dev-runtime";function n(t){let e=o(),r=v(null),[p,u]=V(""),{copy:O}=D();async function U(){let X=new URL(`/#${p}`,window.location.origin).toString();console.log("clicked"),await O(X)}return x(()=>{if(!r.current)return;let z=(r.current.textContent??"").toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").slice(0,30);u(z)},[]),d("h1",{className:T(e.header,e[`header_${t.level}`]),children:d("button",{onClick:()=>void U(),ref:r,id:p,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 h(t){let e=o();return ot("span",{className:et(e.italic),children:t.children},void 0,!1,void 0,this)}import{cn as b}from"@d1vij/shit-i-always-use";import{jsxDEV as g}from"react/jsx-dev-runtime";function s(t){let e=o(),r=t.type==="ordered"?"ol":"ul";return g(r,{className:b(e.list,t.type==="ordered"&&e.ordered_list,t.type==="unordered"&&e.unordered_list),children:t.children},void 0,!1,void 0,this)}function N(t){let e=o();return g("li",{className:b(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 _(t){let e=o();return nt("p",{className:rt(e.paragraph),children:t.children},void 0,!1,void 0,this)}import{cn as mt}from"@d1vij/shit-i-always-use";import{jsxDEV as lt}from"react/jsx-dev-runtime";function a(t){let e=o();return lt("pre",{className:mt(e.preformatted),children:t.children},void 0,!1,void 0,this)}import{cn as st}from"@d1vij/shit-i-always-use";import{jsxDEV as pt}from"react/jsx-dev-runtime";function M(t){let e=o();return pt("span",{className:st(e.striked),children:t.children},void 0,!1,void 0,this)}import{cn as m}from"@d1vij/shit-i-always-use";import{jsxDEV as l}from"react/jsx-dev-runtime";function F(t){let e=o();return l("table",{className:m(e.table),children:t.children},void 0,!1,void 0,this)}function q(t){let e=o();return l("thead",{className:m(e.table_head),children:t.children},void 0,!1,void 0,this)}function E(t){let e=o();return l("tbody",{className:m(e.table_body),children:t.children},void 0,!1,void 0,this)}function k(t){let e=o();return l("tr",{className:m(e.table_row),children:t.children},void 0,!1,void 0,this)}function w(t){let e=o();return l("th",{className:m(e.table_head_cell),children:t.children},void 0,!1,void 0,this)}function L(t){let e=o();return l("td",{className:m(e.table_data),children:t.children},void 0,!1,void 0,this)}var ct={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:J,em:h,del:M,strong:P,code:i,blockquote:f,pre:a,p:_,ol:(t)=>s({...t,type:"ordered"}),ul:(t)=>s({...t,type:"unordered"}),li:N,img:y,table:F,thead:q,tbody:E,th:w,tr:k,td:L},S=ct;import{jsxDEV as ft}from"react/jsx-dev-runtime";function C({SourceComponent:t}){return ft(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{c as StyleContext,yt as MDXLoaderPlugin,C as MDXFromComponent};
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@d1vij/react-mdx-loader",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/d1vij/react-mdx-loader"
6
+ },
7
+ "homepage": "https://github.com/d1vij/react-mdx-loader",
8
+ "version": "0.1.0",
9
+ "description": "Supporting lib to create content driven sites using MDX",
10
+ "license": "MIT",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "sideEffects": false,
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "bunup",
20
+ "dev:ui": "cd test/ui && vite",
21
+ "dev": "bunup --watch",
22
+ "prepare": "bun simple-git-hooks",
23
+ "type-check": "tsc --noEmit",
24
+ "prepack": "bun run build",
25
+ "release": "bumpp --commit --push --tag",
26
+ "lint": "biome check --fix && tsc -b",
27
+ "format": "biome format --write"
28
+ },
29
+ "devDependencies": {
30
+ "@biomejs/biome": "^2.4.4",
31
+ "@types/bun": "^1.3.9",
32
+ "@types/mdx": "^2.0.13",
33
+ "@types/react": "^19.2.14",
34
+ "@types/react-dom": "^19.2.3",
35
+ "bumpp": "^10.4.1",
36
+ "bunup": "^0.16.29",
37
+ "simple-git-hooks": "^2.13.1",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "peerDependencies": {
41
+ "@mdx-js/rollup": "^3.1.1",
42
+ "react": "^19.2.4",
43
+ "react-dom": "^19.2.4",
44
+ "typescript": ">=4.5.0",
45
+ "vite": "^7.3.1"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "typescript": {
49
+ "optional": true
50
+ }
51
+ },
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
+ "dependencies": {
65
+ "@d1vij/shit-i-always-use": "^0.1.3"
66
+ },
67
+ "simple-git-hooks": {
68
+ "pre-commit": "bun run lint && bun run type-check"
69
+ }
70
+ }