diff options
Diffstat (limited to 'packages/gitbook-core/src/components')
-rw-r--r-- | packages/gitbook-core/src/components/Import.js | 37 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/InjectedComponent.js | 8 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/UnsafeComponent.js | 99 |
3 files changed, 39 insertions, 105 deletions
diff --git a/packages/gitbook-core/src/components/Import.js b/packages/gitbook-core/src/components/Import.js new file mode 100644 index 0000000..057ef7a --- /dev/null +++ b/packages/gitbook-core/src/components/Import.js @@ -0,0 +1,37 @@ +const React = require('react'); +const Head = require('react-helmet'); +const ReactRedux = require('react-redux'); + +const ImportLink = ReactRedux.connect((state, {rel, href}) => { + href = href; // TODO: resolve using current page + + return { + link: [ + { + rel, + href + } + ] + }; +})(Head); + +const ImportScript = ReactRedux.connect((state, {type, src}) => { + src = src; // TODO: resolve using current page + + return { + script: [ + { + type, + src + } + ] + }; +})(Head); + +const ImportCSS = props => <ImportLink rel="stylesheet" {...props} />; + +module.exports = { + ImportLink, + ImportScript, + ImportCSS +}; diff --git a/packages/gitbook-core/src/components/InjectedComponent.js b/packages/gitbook-core/src/components/InjectedComponent.js index a4f81fe..cb50e02 100644 --- a/packages/gitbook-core/src/components/InjectedComponent.js +++ b/packages/gitbook-core/src/components/InjectedComponent.js @@ -2,7 +2,6 @@ const React = require('react'); const ReactRedux = require('react-redux'); const { List } = require('immutable'); -const UnsafeComponent = require('./UnsafeComponent'); const { findMatchingComponents } = require('../actions/components'); /* @@ -37,11 +36,8 @@ const Injection = React.createClass({ const Comp = this.props.component; const { props, children } = this.props; - if (Comp.sandbox === false) { - return <Comp {...props}>{children}</Comp>; - } else { - return <UnsafeComponent Component={Comp} props={props}>{children}</UnsafeComponent>; - } + // TODO: try to render with an error handling for unsafe component + return <Comp {...props}>{children}</Comp>; } }); diff --git a/packages/gitbook-core/src/components/UnsafeComponent.js b/packages/gitbook-core/src/components/UnsafeComponent.js deleted file mode 100644 index 3534f45..0000000 --- a/packages/gitbook-core/src/components/UnsafeComponent.js +++ /dev/null @@ -1,99 +0,0 @@ -/* eslint-disable no-console */ -const React = require('react'); -const ReactDOM = require('react-dom'); -const ReactRedux = require('react-redux'); - -const isServerSide = typeof window === 'undefined'; - -/* - Public: Renders a component provided via the `component` prop, and ensures that - failures in the component's code do not cause state inconsistencies elsewhere in - the application. This component is used by {InjectedComponent} and - {InjectedComponentSet} to isolate third party code that could be buggy. - - Occasionally, having your component wrapped in {UnsafeComponent} can cause style - issues. For example, in a Flexbox, the `div.unsafe-component-wrapper` will cause - your `flex` and `order` values to be one level too deep. For these scenarios, - UnsafeComponent looks for `containerStyles` on your React component and attaches - them to the wrapper div. - */ - - -const UnsafeComponent = React.createClass({ - propTypes: { - Component: React.PropTypes.func.isRequired, - props: React.PropTypes.object, - children: React.PropTypes.node - }, - contextTypes: { - store: React.PropTypes.object - }, - - componentDidMount() { - return this.renderInjected(); - }, - - componentDidUpdate() { - return this.renderInjected(); - }, - - componentWillUnmount() { - return this.unmountInjected(); - }, - - getInjected() { - const { Component, props, children } = this.props; - const { store } = this.context; - - return ( - <ReactRedux.Provider store={store}> - <Component {...props}>{children}</Component> - </ReactRedux.Provider> - ); - }, - - renderInjected() { - const node = ReactDOM.findDOMNode(this); - - try { - this.injected = this.getInjected(); - - ReactDOM.render(this.injected, node); - } catch (err) { - console.error(err); - } - }, - - unmountInjected() { - try { - const node = ReactDOM.findDOMNode(this); - return ReactDOM.unmountComponentAtNode(node); - } catch (err) { - console.error(err); - } - }, - - focus() { - if (this.injected.focus != null) { - return this.injected.focus(); - } - }, - - blur() { - if (this.injected.blur != null) { - return this.injected.blur(); - } - }, - - render() { - let inner; - - if (isServerSide) { - inner = this.getInjected(); - } - - return <div name="unsafe-component-wrapper">{inner}</div>; - } -}); - -module.exports = ReactRedux.connect()(UnsafeComponent); |