UNPKG

react-grace

Version:
1 lines 13.5 kB
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n,a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=r(1),i=(n=o)&&n.__esModule?n:{default:n};r(2);var c=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(7));function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var f=function(e){function t(){return s(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return l(t,o.Component),a(t,[{key:"render",value:function(){if(!this.props.document)return null;for(var e=Array.from(this.props.document.children),t=[],r=0;r<e.length;r++)t.push(this.deriveTag(e[r],r));var n=this.props.className?this.props.className:"grace-general";return i.default.createElement("div",{className:n},t)}},{key:"deriveTag",value:function(e,t){switch(e.type){case"PARAGRAPH":return this.deriveParagraph(e,t);case"HEADER":return this.deriveHeader(e,t);case"NOTE":return this.deriveNote(e,t);case"IMAGE":return this.deriveImage(e,t);case"UNORDERED_LIST":return this.deriveUnorderedList(e,t);case"ORDERED_LIST":return this.deriveOrderedList(e,t);case"CODE":return this.deriveCode(e,t);case"TERMINAL":return this.deriveTerminal(e,t);case"GIST":return this.deriveGist(e,t);default:return null}}},{key:"deriveParagraph",value:function(e,t){return i.default.createElement("p",{key:t},this.deriveRichText(e))}},{key:"deriveRichText",value:function(e){var t=Array.from(e.children),r=[];return t.forEach(function(e){switch(e.type){case"TEXT":r.push(e.data.value);break;case"STRONG_TEXT":r.push(i.default.createElement("strong",null,e.data.value));break;case"ITALIC_TEXT":r.push(i.default.createElement("i",null,e.data.value));break;case"LINK":r.push(i.default.createElement("a",{href:e.data.url},e.data.value))}0}),r}},{key:"deriveHeader",value:function(e,t){var r="h"+e.data.size;return i.default.createElement(r,{key:t},e.data.value)}},{key:"deriveNote",value:function(e,t){return i.default.createElement("section",null,i.default.createElement("p",{key:t},this.deriveRichText(e)))}},{key:"deriveImage",value:function(e,t){return i.default.createElement("img",{src:e.data.resource,alt:e.data.caption})}},{key:"deriveUnorderedList",value:function(e,t){var r=this,n=Array.from(e.children),a=[],o=0;return n.forEach(function(e){a.push(i.default.createElement("li",{key:o},r.deriveRichText(e))),o++}),i.default.createElement("ul",{key:t},a)}},{key:"deriveOrderedList",value:function(e,t){var r=this,n=Array.from(e.children),a=[],o=0;return n.forEach(function(e){a.push(i.default.createElement("li",{key:o},r.deriveRichText(e))),o++}),i.default.createElement("ol",{key:t},a)}},{key:"deriveCode",value:function(e,t){var r=Array.from(e.children),n=[],a=0;return r.forEach(function(e){n.push(e.data.value),n.push(i.default.createElement("br",{key:a++}))}),i.default.createElement("div",{key:t},i.default.createElement("pre",{className:"grace-code"},n))}},{key:"deriveTerminal",value:function(e,t){var r=Array.from(e.children),n=[],a=0,o=e.data.prompt?e.data.prompt:"$";return r.forEach(function(e){n.push(i.default.createElement("li",{key:a++,prefix:o},e.data.value))}),i.default.createElement("div",{key:t},i.default.createElement("pre",{className:"grace-code"},i.default.createElement("ul",{className:"grace-code-list"},n)))}},{key:"deriveGist",value:function(e,t){return i.default.createElement(d,{key:t,gist:e.data.source,file:e.data.file})}}]),t}();t.default=f;var d=function(e){function t(e){s(this,t);var r=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.gist=e.gist,r.file=e.file,r.stylesheetAdded=!1,r.state={src:""},r.gistSrcSet=r.gistSrcSet.bind(r),r}return l(t,o.Component),a(t,[{key:"addStylesheet",value:function(e){if(!this.stylesheetAdded){var t=document.createElement("link");t.type="text/css",t.rel="stylesheet",t.href=e,document.head.appendChild(t),this.stylesheetAdded=!0}}},{key:"gistSrcSet",value:function(e){this.setState({src:e.div}),this.addStylesheet(e.stylesheet)}},{key:"componentDidMount",value:function(){var e=t.nextGistCallback();window[e]=this.gistSrcSet;var r="https://gist.github.com/"+this.props.gist+".json?callback="+e;this.props.file&&(r+="&file="+this.props.file);var n=document.createElement("script");n.type="text/javascript",n.src=r,document.head.appendChild(n)}},{key:"render",value:function(){return i.default.createElement("div",null,i.default.createElement("div",{dangerouslySetInnerHTML:{__html:this.state.src}}))}}]),t}();d.propTypes={gist:c.string.isRequired,file:c.string};var p=0;d.nextGistCallback=function(){return"embed_gist_callback_"+p++}},function(e,t){e.exports=require("react")},function(e,t,r){var n=r(3);"string"==typeof n&&(n=[[e.i,n,""]]);var a={hmr:!0,transform:void 0,insertInto:void 0};r(5)(n,a);n.locals&&(e.exports=n.locals)},function(e,t,r){(e.exports=r(4)(!1)).push([e.i,".grace-general section {\n background: black;\n color: white;\n}\n\n.grace-general .grace-code {\n background-color: #F6F8FA;\n word-wrap: normal;\n overflow: auto;\n}\n\n.grace-general .grace-code-list {\n list-style: none;\n margin-left: 0;\n padding-left: 1em;\n}\n\n.grace-general .grace-code-list li::before {\n content: attr(prefix);\n margin-right: 0.5em;\n margin-left: 0.1em;\n}\n",""])},function(e,t,r){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var r=function(e,t){var r=e[1]||"",n=e[3];if(!n)return r;if(t&&"function"==typeof btoa){var a=(i=n,c=btoa(unescape(encodeURIComponent(JSON.stringify(i)))),s="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(c),"/*# ".concat(s," */")),o=n.sources.map(function(e){return"/*# sourceURL=".concat(n.sourceRoot).concat(e," */")});return[r].concat(o).concat([a]).join("\n")}var i,c,s;return[r].join("\n")}(t,e);return t[2]?"@media ".concat(t[2],"{").concat(r,"}"):r}).join("")},t.i=function(e,r){"string"==typeof e&&(e=[[null,e,""]]);for(var n={},a=0;a<this.length;a++){var o=this[a][0];null!=o&&(n[o]=!0)}for(var i=0;i<e.length;i++){var c=e[i];null!=c[0]&&n[c[0]]||(r&&!c[2]?c[2]=r:r&&(c[2]="(".concat(c[2],") and (").concat(r,")")),t.push(c))}},t}},function(e,t,r){var n,a,o={},i=(n=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===a&&(a=n.apply(this,arguments)),a}),c=function(e){var t={};return function(e,r){if("function"==typeof e)return e();if(void 0===t[e]){var n=function(e,t){return t?t.querySelector(e):document.querySelector(e)}.call(this,e,r);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}}(),s=null,u=0,l=[],f=r(6);function d(e,t){for(var r=0;r<e.length;r++){var n=e[r],a=o[n.id];if(a){a.refs++;for(var i=0;i<a.parts.length;i++)a.parts[i](n.parts[i]);for(;i<n.parts.length;i++)a.parts.push(b(n.parts[i],t))}else{var c=[];for(i=0;i<n.parts.length;i++)c.push(b(n.parts[i],t));o[n.id]={id:n.id,refs:1,parts:c}}}}function p(e,t){for(var r=[],n={},a=0;a<e.length;a++){var o=e[a],i=t.base?o[0]+t.base:o[0],c={css:o[1],media:o[2],sourceMap:o[3]};n[i]?n[i].parts.push(c):r.push(n[i]={id:i,parts:[c]})}return r}function h(e,t){var r=c(e.insertInto);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var n=l[l.length-1];if("top"===e.insertAt)n?n.nextSibling?r.insertBefore(t,n.nextSibling):r.appendChild(t):r.insertBefore(t,r.firstChild),l.push(t);else if("bottom"===e.insertAt)r.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var a=c(e.insertAt.before,r);r.insertBefore(t,a)}}function v(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=l.indexOf(e);t>=0&&l.splice(t,1)}function y(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var n=function(){0;return r.nc}();n&&(e.attrs.nonce=n)}return m(t,e.attrs),h(e,t),t}function m(e,t){Object.keys(t).forEach(function(r){e.setAttribute(r,t[r])})}function b(e,t){var r,n,a,o;if(t.transform&&e.css){if(!(o="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=o}if(t.singleton){var i=u++;r=s||(s=y(t)),n=k.bind(null,r,i,!1),a=k.bind(null,r,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(r=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",m(t,e.attrs),h(e,t),t}(t),n=function(e,t,r){var n=r.css,a=r.sourceMap,o=void 0===t.convertToAbsoluteUrls&&a;(t.convertToAbsoluteUrls||o)&&(n=f(n));a&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */");var i=new Blob([n],{type:"text/css"}),c=e.href;e.href=URL.createObjectURL(i),c&&URL.revokeObjectURL(c)}.bind(null,r,t),a=function(){v(r),r.href&&URL.revokeObjectURL(r.href)}):(r=y(t),n=function(e,t){var r=t.css,n=t.media;n&&e.setAttribute("media",n);if(e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}.bind(null,r),a=function(){v(r)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else a()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=i()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var r=p(e,t);return d(r,t),function(e){for(var n=[],a=0;a<r.length;a++){var i=r[a];(c=o[i.id]).refs--,n.push(c)}e&&d(p(e,t),t);for(a=0;a<n.length;a++){var c;if(0===(c=n[a]).refs){for(var s=0;s<c.parts.length;s++)c.parts[s]();delete o[c.id]}}}};var g,E=(g=[],function(e,t){return g[e]=t,g.filter(Boolean).join("\n")});function k(e,t,r,n){var a=r?"":n.css;if(e.styleSheet)e.styleSheet.cssText=E(t,a);else{var o=document.createTextNode(a),i=e.childNodes;i[t]&&e.removeChild(i[t]),i.length?e.insertBefore(o,i[t]):e.appendChild(o)}}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var r=t.protocol+"//"+t.host,n=r+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var a,o=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(o)?e:(a=0===o.indexOf("//")?o:0===o.indexOf("/")?r+o:n+o.replace(/^\.\//,""),"url("+JSON.stringify(a)+")")})}},function(e,t,r){e.exports=r(8)()},function(e,t,r){"use strict";var n=r(9);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,r,a,o,i){if(i!==n){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return r.PropTypes=r,r}},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}]);