1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _react = _interopRequireDefault(require("react"));
|
9 |
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 |
|
12 | var _remarkUnImporter = _interopRequireDefault(require("../utils/remark-un-importer"));
|
13 |
|
14 | var _getScope = _interopRequireDefault(require("../utils/get-scope"));
|
15 |
|
16 | var _MDX = _interopRequireDefault(require("./MDX"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
21 |
|
22 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
23 |
|
24 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
25 |
|
26 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
27 |
|
28 | function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
29 |
|
30 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
31 |
|
32 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
33 |
|
34 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
35 |
|
36 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
37 |
|
38 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
39 |
|
40 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
41 |
|
42 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
43 |
|
44 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
45 |
|
46 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
47 |
|
48 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
49 |
|
50 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
51 |
|
52 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
53 |
|
54 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
55 |
|
56 | function ErrorRenderer(_ref) {
|
57 | var children = _ref.children;
|
58 | return _react.default.createElement("pre", {
|
59 | className: "mdx-scoped-runtime__error",
|
60 | style: {
|
61 | overflowX: 'auto',
|
62 | background: 'rgba(255, 0, 0, .1)'
|
63 | }
|
64 | }, "Invalid MDX:\n".concat(children.toString()));
|
65 | }
|
66 |
|
67 | ErrorRenderer.propTypes = {
|
68 | children: _propTypes.default.shape({
|
69 | toString: _propTypes.default.func.isRequired
|
70 | }).isRequired
|
71 | };
|
72 |
|
73 | var MDXScopedRuntime =
|
74 |
|
75 | function (_React$Component) {
|
76 | _inherits(MDXScopedRuntime, _React$Component);
|
77 |
|
78 | function MDXScopedRuntime() {
|
79 | var _getPrototypeOf2;
|
80 |
|
81 | var _this;
|
82 |
|
83 | _classCallCheck(this, MDXScopedRuntime);
|
84 |
|
85 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
86 | args[_key] = arguments[_key];
|
87 | }
|
88 |
|
89 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MDXScopedRuntime)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
90 |
|
91 | _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
|
92 | error: undefined
|
93 | });
|
94 |
|
95 | _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onError", function (error) {
|
96 | var onError = _this.props.onError;
|
97 |
|
98 | _this.setState({
|
99 | error: error
|
100 | });
|
101 |
|
102 | onError(error);
|
103 | });
|
104 |
|
105 | return _this;
|
106 | }
|
107 |
|
108 | _createClass(MDXScopedRuntime, [{
|
109 | key: "componentDidUpdate",
|
110 | value: function componentDidUpdate(prevProps) {
|
111 | var error = this.state.error;
|
112 | var children = this.props.children;
|
113 |
|
114 | if (error && children !== prevProps.children) {
|
115 | this.setState({
|
116 | error: undefined
|
117 | });
|
118 | }
|
119 | }
|
120 | }, {
|
121 | key: "componentDidCatch",
|
122 | value: function componentDidCatch(error) {
|
123 | this.onError(error);
|
124 | }
|
125 | }, {
|
126 | key: "render",
|
127 | value: function render() {
|
128 | var error = this.state.error;
|
129 |
|
130 | var _this$props = this.props,
|
131 | scope = _this$props.scope,
|
132 | mdPlugins = _this$props.mdPlugins,
|
133 | onError = _this$props.onError,
|
134 | props = _objectWithoutProperties(_this$props, ["scope", "mdPlugins", "onError"]);
|
135 |
|
136 | if (error) {
|
137 | return _react.default.createElement(ErrorRenderer, null, error);
|
138 | }
|
139 |
|
140 | try {
|
141 | var resolvedScope = props.allowedImports ? (0, _getScope.default)({
|
142 | mdPlugins: mdPlugins,
|
143 | hastPlugins: props.hastPlugins,
|
144 | mdx: props.children,
|
145 | allowedImports: props.allowedImports
|
146 | }) : {};
|
147 | return _react.default.createElement(_MDX.default, _extends({}, props, {
|
148 | scope: _objectSpread({
|
149 | Layout: function Layout(_ref2) {
|
150 | var children = _ref2.children;
|
151 | return children;
|
152 | }
|
153 | }, scope, resolvedScope),
|
154 | mdPlugins: [[_remarkUnImporter.default]].concat(_toConsumableArray(mdPlugins))
|
155 | }));
|
156 | } catch (err) {
|
157 | this.onError(err);
|
158 | return _react.default.createElement(ErrorRenderer, null, err);
|
159 | }
|
160 | }
|
161 | }]);
|
162 |
|
163 | return MDXScopedRuntime;
|
164 | }(_react.default.Component);
|
165 |
|
166 | MDXScopedRuntime.propTypes = {
|
167 | scope: _propTypes.default.shape({}).isRequired,
|
168 | mdPlugins: _propTypes.default.arrayOf(_propTypes.default.any).isRequired,
|
169 | allowedImports: _propTypes.default.shape({}),
|
170 | onError: _propTypes.default.func.isRequired,
|
171 | children: _propTypes.default.node
|
172 | };
|
173 | MDXScopedRuntime.defaultProps = {
|
174 | scope: {},
|
175 | mdPlugins: [],
|
176 | onError: function onError() {
|
177 | return undefined;
|
178 | }
|
179 | };
|
180 | var _default = MDXScopedRuntime;
|
181 | exports.default = _default;
|
182 |
|
\ | No newline at end of file |