import React, { Component } from 'react';
import PropTypes from 'prop-types';
import useBlockBase from '../block-decorators/base';
import { createComponent } from 'olymp-fela';

export default WrappedComponent =>
  class WithBlockTypes extends Component {
    static contextTypes = {
      blockTypes: PropTypes.object,
    };
    render() {
      return (
        <WrappedComponent
          blockTypes={this.context.blockTypes}
          {...this.props}
        />
      );
    }
  };

export default (types) => {
  const blockTypes = Object.keys(types).reduce((result, key) => {
    let { component, styles, editable, slate, ...rest } = types[key];
    const newKey = types[key].key || key;
    const isVoid = editable !== true;
    if (styles && typeof styles === 'object') {
      component = createComponent(() => styles, component, p => Object.keys(p));
    }
    if (styles && typeof styles === 'function') {
      component = createComponent(styles, component, p => Object.keys(p));
    }
    result[newKey] = useBlockBase({
      ...slate,
      ...rest,
      isVoid,
      key: newKey,
      isAtomic: true,
    })(component);
    return result;
  }, {});
  return WrappedComponent =>
    class UseBlockTypes extends Component {
      static childContextTypes = {
        blockTypes: PropTypes.object,
      };
      getChildContext() {
        return {
          blockTypes: blockTypes || this.props.blockTypes,
        };
      }
      render() {
        return <WrappedComponent {...this.props} />;
      }
    };
};

@@ -175,318 +175,8 @@
 ';%0A%0A
-export default WrappedComponent =%3E%0A  class WithBlockTypes extends Component %7B%0A    static contextTypes = %7B%0A      blockTypes: PropTypes.object,%0A    %7D;%0A    render() %7B%0A      return (%0A        %3CWrappedComponent%0A          blockTypes=%7Bthis.context.blockTypes%7D%0A          %7B...this.props%7D%0A        /%3E%0A      );%0A    %7D%0A  %7D;%0A%0A
 expo

fix bug