@blocz/mdx-live
Advanced tools
Comparing version 0.2.0-rc.5 to 0.2.0-rc.6
@@ -1,2 +0,2 @@ | ||
import*as e from"react";import*as r from"react/jsx-runtime.js";import{compile as n}from"@mdx-js/mdx";import{selectAll as t}from"unist-util-select";function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},o.apply(this,arguments)}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function u(e,r,n){if(!e.s){if(n instanceof c){if(!n.s)return void(n.o=u.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(u.bind(null,e,r),u.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var a=function(){return Promise.resolve()};const c=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{u(t,1,e(this.v))}catch(e){u(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?u(t,1,r?r(o):o):n?u(t,1,n(o)):u(t,2,o)}catch(e){u(t,2,e)}},t},e}();var f="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function l(e){return e instanceof c&&1&e.s}function s(e,r,n){if("function"==typeof e[f]){var t,o,i,a=e[f]();if(function e(f){try{for(;!((t=a.next()).done||n&&n());)if((f=r(t.value))&&f.then){if(!l(f))return void f.then(e,i||(i=u.bind(null,o=new c,2)));f=f.v}o?u(o,1,f):o=f}catch(e){u(o||(o=new c),2,e)}}(),a.return){var s=function(e){try{t.done||a.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var v=[],h=0;h<e.length;h++)v.push(e[h]);return function(e,r,n){var t,o,i=-1;return function a(f){try{for(;++i<e.length&&(!n||!n());)if((f=r(i))&&f.then){if(!l(f))return void f.then(a,o||(o=u.bind(null,t=new c,2)));f=f.v}t?u(t,1,f):t=f}catch(e){u(t||(t=new c),2,e)}}(),t}(v,function(e){return r(v[e])},n)}var v=function(r){var f=r.code,l=r.defaultScope,v=void 0===l?{}:l,h=r.resolveImport,m=void 0===h?a:h,d=r.recmaPlugins,p=r.rehypePlugins,y=r.remarkPlugins,g=e.useState(void 0),b=g[0],P=g[1],S=e.useRef(null),k=e.useRef(!1);e.useEffect(function(){return function(){k.current=!0}},[]);var w=e.useCallback(function(){if(S.current){var e,r,o=S.current;(e=o,r=[],n(e.code,{outputFormat:"function-body",recmaPlugins:e.recmaPlugins,rehypePlugins:e.rehypePlugins,remarkPlugins:[].concat(e.remarkPlugins||[],[function(){return function(e){try{for(var n,o=function(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return i(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,r):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t("mdxjsEsm",e));!(n=o()).done;)for(var u=n.value,a=u.data.estree.body,c=a.length-1;c>=0;c--){var f=a[c];"ImportDeclaration"===f.type&&(a.splice(c,1),u.value=u.value.substring(0,f.range[0]-1)+u.value.substring(f.range[1]-1),r.push(f))}return Promise.resolve()}catch(e){return Promise.reject(e)}}}])}).then(function(e){return[e,r]})).then(function(e){k.current||P(e)}).catch(function(e){console.error(e)}).then(function(){S.current===o&&(S.current=null),k.current||w()})}},[]);e.useMemo(function(){var e=null===S.current;S.current={code:f,recmaPlugins:d,rehypePlugins:p,remarkPlugins:y},e&&w()},[f,d,p,y]);var j=e.useRef();j.current||(j.current=new WeakSet);var x=e.useState({}),I=x[0],E=x[1];return e.useEffect(function(){if(b){var e=!1;return function(){try{var r=function(){e||(j.current.add(b),E(n))},n={},t=s(b[1],function(e){return s(e.specifiers,function(r){var t=function(e,r){var n,t=-1;e:{for(var o=0;o<r.length;o++){var i=r[o][0];if(i){var a=i();if(a&&a.then)break e;if(a===e){t=o;break}}else t=o}if(-1!==t){do{for(var f=r[t][1];!f;)t++,f=r[t][1];var l=f();if(l&&l.then){n=!0;break e}var s=r[t][2];t++}while(s&&!s());return l}}var v=new c,h=u.bind(null,v,2);return(n?l.then(m):a.then(function n(a){for(;;){if(a===e){t=o;break}if(++o===r.length){if(-1!==t)break;return void u(v,1,f)}if(i=r[o][0]){if((a=i())&&a.then)return void a.then(n).then(void 0,h)}else t=o}do{for(var c=r[t][1];!c;)t++,c=r[t][1];var f=c();if(f&&f.then)return void f.then(m).then(void 0,h);var l=r[t][2];t++}while(l&&!l());u(v,1,f)})).then(void 0,h),v;function m(e){for(;;){var n=r[t][2];if(!n||n())break;t++;for(var o=r[t][1];!o;)t++,o=r[t][1];if((e=o())&&e.then)return void e.then(m).then(void 0,h)}u(v,1,e)}}(r.type,[[function(){return"ImportNamespaceSpecifier"},function(){return Promise.resolve(m({kind:"namespace",path:e.source.value})).then(function(e){n[r.local.name]=e})}],[function(){return"ImportDefaultSpecifier"},function(){return Promise.resolve(m({kind:"default",path:e.source.value})).then(function(e){n[r.local.name]=e})}],[function(){return"ImportSpecifier"},function(){return Promise.resolve(m({kind:"named",path:e.source.value,variable:r.imported.name})).then(function(e){n[r.local.name]=e})}]]);if(t&&t.then)return t.then(function(){})})});Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}}(),function(){e=!0}}},[m,b]),b?{scope:o({},v,I),text:b[0].toString(),isReady:j.current.has(b)}:{scope:{},text:"",isReady:!1}},h=function(r){return e.createElement(e.Fragment,null,r.children)},m=function(n){var t=n.Provider,o=void 0===t?h:t,i=v({code:n.code,defaultScope:n.defaultScope,resolveImport:n.resolveImport,recmaPlugins:n.recmaPlugins,rehypePlugins:n.rehypePlugins,remarkPlugins:n.remarkPlugins}),u=i.scope,a=i.text,c=i.isReady,f=e.useMemo(function(){return a?new Function(a)(r).default:function(){return null}},[a]);return c?e.createElement(o,{value:{scope:u,text:a,isReady:c}},e.createElement(f,{components:u})):null};export{m as MDX,v as useMDX}; | ||
import*as e from"react";import*as r from"react/jsx-runtime.js";import{compile as n}from"@mdx-js/mdx";import{selectAll as t}from"unist-util-select";function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},o.apply(this,arguments)}function u(e,r){return u=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},u(e,r)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function c(e,r,n){return c=i()?Reflect.construct:function(e,r,n){var t=[null];t.push.apply(t,r);var o=new(Function.bind.apply(e,t));return n&&u(o,n.prototype),o},c.apply(null,arguments)}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function f(e,r,n){if(!e.s){if(n instanceof s){if(!n.s)return void(n.o=f.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(f.bind(null,e,r),f.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var l=function(){return Promise.resolve()};const s=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{f(t,1,e(this.v))}catch(e){f(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?f(t,1,r?r(o):o):n?f(t,1,n(o)):f(t,2,o)}catch(e){f(t,2,e)}},t},e}();var v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function h(e){return e instanceof s&&1&e.s}function m(e,r,n){if("function"==typeof e[v]){var t,o,u,i=e[v]();if(function e(c){try{for(;!((t=i.next()).done||n&&n());)if((c=r(t.value))&&c.then){if(!h(c))return void c.then(e,u||(u=f.bind(null,o=new s,2)));c=c.v}o?f(o,1,c):o=c}catch(e){f(o||(o=new s),2,e)}}(),i.return){var c=function(e){try{t.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(c,function(e){throw c(e)});c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],l=0;l<e.length;l++)a.push(e[l]);return function(e,r,n){var t,o,u=-1;return function i(c){try{for(;++u<e.length&&(!n||!n());)if((c=r(u))&&c.then){if(!h(c))return void c.then(i,o||(o=f.bind(null,t=new s,2)));c=c.v}t?f(t,1,c):t=c}catch(e){f(t||(t=new s),2,e)}}(),t}(a,function(e){return r(a[e])},n)}var p=function(r){var o=r.code,u=r.resolveImport,i=void 0===u?l:u,c=r.recmaPlugins,v=r.rehypePlugins,h=r.remarkPlugins,p=e.useState(void 0),d=p[0],y=p[1],b=e.useRef(null),g=e.useRef(!1);e.useEffect(function(){return function(){g.current=!0}},[]);var P=e.useCallback(function(){if(b.current){var e,r,o=b.current;(e=o,r=[],n(e.code,{outputFormat:"function-body",recmaPlugins:e.recmaPlugins,rehypePlugins:e.rehypePlugins,remarkPlugins:[].concat(e.remarkPlugins||[],[function(){return function(e){try{for(var n,o=function(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return a(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,r):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t("mdxjsEsm",e));!(n=o()).done;)for(var u=n.value,i=u.data.estree.body,c=i.length-1;c>=0;c--){var f=i[c];"ImportDeclaration"===f.type&&(i.splice(c,1),u.value=u.value.substring(0,f.range[0]-1)+u.value.substring(f.range[1]-1),r.push(f))}return Promise.resolve()}catch(e){return Promise.reject(e)}}}])}).then(function(e){return[e,r]})).then(function(e){g.current||y(e)}).catch(function(e){console.error(e)}).then(function(){b.current===o&&(b.current=null),g.current||P()})}},[]);e.useMemo(function(){var e=null===b.current;b.current={code:o,recmaPlugins:c,rehypePlugins:v,remarkPlugins:h},e&&P()},[o,c,v,h]);var k=e.useRef();k.current||(k.current=new WeakSet);var S=e.useState({}),w=S[0],j=S[1];return e.useEffect(function(){if(d){var e=!1;return function(){try{var r=function(){e||(k.current.add(d),j(n))},n={},t=m(d[1],function(e){return m(e.specifiers,function(r){var t=function(e,r){var n,t=-1;e:{for(var o=0;o<r.length;o++){var u=r[o][0];if(u){var i=u();if(i&&i.then)break e;if(i===e){t=o;break}}else t=o}if(-1!==t){do{for(var c=r[t][1];!c;)t++,c=r[t][1];var a=c();if(a&&a.then){n=!0;break e}var l=r[t][2];t++}while(l&&!l());return a}}var v=new s,h=f.bind(null,v,2);return(n?a.then(m):i.then(function n(i){for(;;){if(i===e){t=o;break}if(++o===r.length){if(-1!==t)break;return void f(v,1,a)}if(u=r[o][0]){if((i=u())&&i.then)return void i.then(n).then(void 0,h)}else t=o}do{for(var c=r[t][1];!c;)t++,c=r[t][1];var a=c();if(a&&a.then)return void a.then(m).then(void 0,h);var l=r[t][2];t++}while(l&&!l());f(v,1,a)})).then(void 0,h),v;function m(e){for(;;){var n=r[t][2];if(!n||n())break;t++;for(var o=r[t][1];!o;)t++,o=r[t][1];if((e=o())&&e.then)return void e.then(m).then(void 0,h)}f(v,1,e)}}(r.type,[[function(){return"ImportNamespaceSpecifier"},function(){return Promise.resolve(i({kind:"namespace",path:e.source.value})).then(function(e){n[r.local.name]=e})}],[function(){return"ImportDefaultSpecifier"},function(){return Promise.resolve(i({kind:"default",path:e.source.value})).then(function(e){n[r.local.name]=e})}],[function(){return"ImportSpecifier"},function(){return Promise.resolve(i({kind:"named",path:e.source.value,variable:r.imported.name})).then(function(e){n[r.local.name]=e})}]]);if(t&&t.then)return t.then(function(){})})});Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}}(),function(){e=!0}}},[i,d]),d?{resolvedImports:w,text:d[0].toString(),isReady:k.current.has(d)}:{resolvedImports:{},text:"",isReady:!1}},d=["default"],y=function(r){return e.createElement(e.Fragment,null,r.children)},b=function(n){var t=n.Provider,u=void 0===t?y:t,i=n.defaultScope,a=p({code:n.code,resolveImport:n.resolveImport,recmaPlugins:n.recmaPlugins,rehypePlugins:n.rehypePlugins,remarkPlugins:n.remarkPlugins}),f=a.resolvedImports,l=a.text,s=a.isReady,v=e.useMemo(function(){return o({},i,f)},[i,f]),h=e.useMemo(function(){return l?c(Function,["React"].concat(Object.keys(v),[l])).apply(void 0,[r].concat(Object.values(v))):function(){return null}},[l,v]);if(!s)return null;var m=h.default,b=function(e,r){if(null==e)return{};var n,t,o={},u=Object.keys(e);for(t=0;t<u.length;t++)r.indexOf(n=u[t])>=0||(o[n]=e[n]);return o}(h,d);return e.createElement(u,{value:{scope:o({},v,b),text:l,isReady:s}},e.createElement(m,{components:v}))};export{b as MDX,p as useMDX}; | ||
//# sourceMappingURL=mdx-live.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"react";import*as r from"react/jsx-runtime.js";import{compile as t}from"@mdx-js/mdx";import{selectAll as n}from"unist-util-select";function s(){return s=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},s.apply(this,arguments)}const a=async()=>{},c=({code:r,defaultScope:c={},resolveImport:o=a,recmaPlugins:u,rehypePlugins:l,remarkPlugins:i})=>{const[m,p]=e.useState(void 0),f=e.useRef(null),d=e.useRef(!1);e.useEffect(()=>()=>{d.current=!0},[]);const g=e.useCallback(()=>{if(!f.current)return;const e=f.current;(function({code:e,recmaPlugins:r,rehypePlugins:s,remarkPlugins:a}){const c=[];return t(e,{outputFormat:"function-body",recmaPlugins:r,rehypePlugins:s,remarkPlugins:[...a||[],()=>async e=>{const r=n("mdxjsEsm",e);for(const e of r){const r=e.data.estree.body;for(let t=r.length-1;t>=0;t--){const n=r[t];"ImportDeclaration"===n.type&&(r.splice(t,1),e.value=e.value.substring(0,n.range[0]-1)+e.value.substring(n.range[1]-1),c.push(n))}}}]}).then(e=>[e,c])})(e).then(e=>{d.current||p(e)}).catch(e=>{console.error(e)}).then(()=>{f.current===e&&(f.current=null),d.current||g()})},[]);e.useMemo(()=>{const e=null===f.current;f.current={code:r,recmaPlugins:u,rehypePlugins:l,remarkPlugins:i},e&&g()},[r,u,l,i]);const h=e.useRef();h.current||(h.current=new WeakSet);const[y,P]=e.useState({});return e.useEffect(()=>{if(!m)return;let e=!1;return(async()=>{const r={};for(const e of m[1])for(const t of e.specifiers)switch(t.type){case"ImportNamespaceSpecifier":r[t.local.name]=await o({kind:"namespace",path:e.source.value});break;case"ImportDefaultSpecifier":r[t.local.name]=await o({kind:"default",path:e.source.value});break;case"ImportSpecifier":r[t.local.name]=await o({kind:"named",path:e.source.value,variable:t.imported.name})}e||(h.current.add(m),P(r))})(),()=>{e=!0}},[o,m]),m?{scope:s({},c,y),text:m[0].toString(),isReady:h.current.has(m)}:{scope:{},text:"",isReady:!1}},o=({children:r})=>e.createElement(e.Fragment,null,r),u=({Provider:t=o,code:n,defaultScope:s,resolveImport:a,recmaPlugins:u,rehypePlugins:l,remarkPlugins:i})=>{const{scope:m,text:p,isReady:f}=c({code:n,defaultScope:s,resolveImport:a,recmaPlugins:u,rehypePlugins:l,remarkPlugins:i}),d=e.useMemo(()=>p?new Function(p)(r).default:()=>null,[p]);return f?e.createElement(t,{value:{scope:m,text:p,isReady:f}},e.createElement(d,{components:m})):null};export{u as MDX,c as useMDX}; | ||
import*as e from"react";import*as r from"react/jsx-runtime.js";import{compile as t}from"@mdx-js/mdx";import{selectAll as n}from"unist-util-select";function s(){return s=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},s.apply(this,arguments)}const a=async()=>{},c=({code:r,resolveImport:s=a,recmaPlugins:c,rehypePlugins:o,remarkPlugins:u})=>{const[l,i]=e.useState(void 0),m=e.useRef(null),p=e.useRef(!1);e.useEffect(()=>()=>{p.current=!0},[]);const f=e.useCallback(()=>{if(!m.current)return;const e=m.current;(function({code:e,recmaPlugins:r,rehypePlugins:s,remarkPlugins:a}){const c=[];return t(e,{outputFormat:"function-body",recmaPlugins:r,rehypePlugins:s,remarkPlugins:[...a||[],()=>async e=>{const r=n("mdxjsEsm",e);for(const e of r){const r=e.data.estree.body;for(let t=r.length-1;t>=0;t--){const n=r[t];"ImportDeclaration"===n.type&&(r.splice(t,1),e.value=e.value.substring(0,n.range[0]-1)+e.value.substring(n.range[1]-1),c.push(n))}}}]}).then(e=>[e,c])})(e).then(e=>{p.current||i(e)}).catch(e=>{console.error(e)}).then(()=>{m.current===e&&(m.current=null),p.current||f()})},[]);e.useMemo(()=>{const e=null===m.current;m.current={code:r,recmaPlugins:c,rehypePlugins:o,remarkPlugins:u},e&&f()},[r,c,o,u]);const d=e.useRef();d.current||(d.current=new WeakSet);const[g,h]=e.useState({});return e.useEffect(()=>{if(!l)return;let e=!1;return(async()=>{const r={};for(const e of l[1])for(const t of e.specifiers)switch(t.type){case"ImportNamespaceSpecifier":r[t.local.name]=await s({kind:"namespace",path:e.source.value});break;case"ImportDefaultSpecifier":r[t.local.name]=await s({kind:"default",path:e.source.value});break;case"ImportSpecifier":r[t.local.name]=await s({kind:"named",path:e.source.value,variable:t.imported.name})}e||(d.current.add(l),h(r))})(),()=>{e=!0}},[s,l]),l?{resolvedImports:g,text:l[0].toString(),isReady:d.current.has(l)}:{resolvedImports:{},text:"",isReady:!1}},o=["default"],u=({children:r})=>e.createElement(e.Fragment,null,r),l=({Provider:t=u,code:n,defaultScope:a,resolveImport:l,recmaPlugins:i,rehypePlugins:m,remarkPlugins:p})=>{const{resolvedImports:f,text:d,isReady:g}=c({code:n,resolveImport:l,recmaPlugins:i,rehypePlugins:m,remarkPlugins:p}),h=e.useMemo(()=>s({},a,f),[a,f]),y=e.useMemo(()=>d?new Function("React",...Object.keys(h),d)(r,...Object.values(h)):()=>null,[d,h]);if(!g)return null;const{default:v}=y,P=function(e,r){if(null==e)return{};var t,n,s={},a=Object.keys(e);for(n=0;n<a.length;n++)r.indexOf(t=a[n])>=0||(s[t]=e[t]);return s}(y,o);return e.createElement(t,{value:{scope:s({},h,P),text:d,isReady:g}},e.createElement(v,{components:h}))};export{l as MDX,c as useMDX}; | ||
//# sourceMappingURL=mdx-live.modern.js.map |
import * as React from "react"; | ||
import type { UseMDXParams, UseMDXOut, ResolveImport } from "./use-mdx"; | ||
export declare type MDXContextType = UseMDXOut; | ||
import { Variables } from "./use-mdx.js"; | ||
import type { UseMDXParams, ResolveImport } from "./use-mdx"; | ||
export interface MDXContextType { | ||
scope: Variables; | ||
text: string; | ||
isReady: boolean; | ||
} | ||
export type { ResolveImport }; | ||
interface MDXProps extends UseMDXParams { | ||
/** **Needs to be memoized** */ | ||
defaultScope?: Variables; | ||
Provider?: React.Provider<MDXContextType>; | ||
} | ||
export declare const MDX: React.FunctionComponent<MDXProps>; |
@@ -15,3 +15,2 @@ import type { CompileOptions } from "@mdx-js/mdx"; | ||
code: string; | ||
defaultScope?: Variables; | ||
/** **Needs to be memoized** */ | ||
@@ -27,6 +26,6 @@ resolveImport?: ResolveImport; | ||
export interface UseMDXOut { | ||
scope: Variables; | ||
resolvedImports: Variables; | ||
text: string; | ||
isReady: boolean; | ||
} | ||
export declare const useMDX: ({ code, defaultScope, resolveImport, recmaPlugins, rehypePlugins, remarkPlugins, }: UseMDXParams) => UseMDXOut; | ||
export declare const useMDX: ({ code, resolveImport, recmaPlugins, rehypePlugins, remarkPlugins, }: UseMDXParams) => UseMDXOut; |
{ | ||
"name": "@blocz/mdx-live", | ||
"version": "0.2.0-rc.5", | ||
"version": "0.2.0-rc.6", | ||
"source": "src/index.ts", | ||
@@ -37,3 +37,3 @@ "main": "lib/mdx-live.js", | ||
"dependencies": { | ||
"unist-util-select": "^4.0.1" | ||
"unist-util-select": "^4.0.0" | ||
}, | ||
@@ -51,7 +51,7 @@ "peerDependencies": { | ||
"@types/react": "17.0.47", | ||
"ava": "^4.3.1", | ||
"ava": "^5.1.0", | ||
"microbundle": "^0.15.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"ts-node": "^10.8.2", | ||
"ts-node": "^10.9.1", | ||
"vfile": "^5.3.4" | ||
@@ -58,0 +58,0 @@ }, |
@@ -24,3 +24,4 @@ # `@blocz/mdx-live` <!-- omit in toc --> | ||
Since the v0.2.0, it's based on MDX v2. It you want to use it with MDX v1, you can look at the [v0.1.0](https://github.com/bloczjs/mdx/tree/v0.1.0). | ||
Since the v0.2.0, it's based on MDX v2. It you want to use it with MDX v1, you can look at the [v0.1.0](https://github.com/bloczjs/mdx/tree/v0.1.0).<br/> | ||
If you’re looking to upgrade to the v0.2.0, [the list of breaking changes is listed here](https://github.com/bloczjs/mdx/releases/tag/v0.2.0). | ||
@@ -35,5 +36,5 @@ This package requires you to also install `@mdx-js/mdx`: | ||
⚠️ This package is only published as an ESM package, it doesn't provide any CJS exports. | ||
The reason behind this is because MDX switch to ESM only in their v2 too (see https://mdxjs.com/migrating/v2/#esm).\ | ||
And as you'll also need regular MDX packages to make this one work, we also switched to ESM. | ||
> **Warning**<br/> | ||
> This package is only published as an ESM package, it doesn't provide any CJS exports.<br/> | ||
> MDX also switched to ESM only in their v2 (see https://mdxjs.com/migrating/v2/#esm). | ||
@@ -168,4 +169,37 @@ ## How to use | ||
The `Provider` will be provided the same data what [`useMDX`](#usemdx-hook) returns: `scope`, `text`, and `isReady`. | ||
`Provider` will be provided an object with: | ||
- `text` and `isReady`, like [`useMDX`](#usemdx-hook)’s returned value, | ||
- a `scope` object, which is a merge between: | ||
- the `defaultScope` prop, | ||
- resolved imports thanks to `resolveImport`, | ||
- exported values in the MDX. | ||
For instance, with the following example: | ||
```jsx | ||
<MDX | ||
Provider={Provider} | ||
defaultScope={{ variant: "blue" }} | ||
code={` | ||
import { Button } from 'example'; | ||
export const label = "Click Me!"; | ||
<Button variant={variant} label={label} /> | ||
`} | ||
resolveImport={async () => ButtonVariable} | ||
/> | ||
``` | ||
The `Provider` will be called with a `scope` of: | ||
```js | ||
{ | ||
Button: ButtonVariable, | ||
label: "Click Me!", | ||
variant: "blue", | ||
} | ||
``` | ||
### `useMDX` hook | ||
@@ -203,3 +237,3 @@ | ||
const App = () => { | ||
const { scope, text, isReady } = useMDX({ | ||
const { resolvedImports, text, isReady } = useMDX({ | ||
code: importMDX, | ||
@@ -209,3 +243,3 @@ resolveImport, | ||
// scope = Object containing all the top-level variables used in the MDX code (all imports & exports, in this case there is only `Button`) | ||
// resolvedImports = Object containing all the resolved imports (in this case there is only `Button`) | ||
// text = parsed version of the MDX code without MDX nor JSX, aka plain code that can be executed | ||
@@ -212,0 +246,0 @@ // isReady: boolean representing if the code sample has been fully parsed yet or if it's still getting parsed |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
46007
109
244
1
Updatedunist-util-select@^4.0.0