All files / src CodeMirrorBlocks.js

93.55% Statements 29/31
25% Branches 1/4
50% Functions 2/4
93.55% Lines 29/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           2x 1x 1x 1x                     1x 1x       1x                       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import React from 'react';
import ReactDOM from 'react-dom';
import ToggleEditor from './ui/ToggleEditor';
const Args = require('./components/Args');
const DropTarget = require('./components/DropTarget');
const Node = require('./components/Node');
const AST = require('./ast');
const Nodes = require('./nodes');
const NodeSpec = require('./nodeSpec');
const Languages = require('./languages');
const Pretty = require('pretty-fast-pretty-printer');
const { PrimitiveGroup } = require('./parsers/primitives');
 
// Consumes a DOM node to host the editor, a language object and the code
// to render. Produces an object-representation of CMB, allowing for
// integration with external (non-react) code
export default class CodeMirrorBlocks {
  constructor(container, options = {}, language, cmOptions = {}) {
    let api = {};
    let initialCode = options.value;
    ReactDOM.render(
      <ToggleEditor
        language={language}
        initialCode={(initialCode == null) ? "" : initialCode}
        api={api}
        appElement={container}
        options={options}
        cmOptions={cmOptions}
      />,
      container
    );
    Object.assign(api, this.buildAPI());
    return api;
  }
 
  buildAPI = () => {
    return {
      'fromTextArea': this.fromTextArea,
    };
  }
 
  fromTextArea = myTextArea => {
    myTextArea.parentNode.replaceChild(<ToggleEditor
      initialCode={myTextArea.value}
    />, myTextArea);
  }
}
 
module.exports.CodeMirrorBlocks = CodeMirrorBlocks;
module.exports.Args = Args.default;
module.exports.DT = DropTarget;
module.exports.AST = AST;
module.exports.Node = Node.default;
module.exports.Nodes = Nodes;
module.exports.NodeSpec = NodeSpec;
module.exports.Languages = Languages;
module.exports.Pretty = Pretty;
module.exports.PrimitiveGroup = PrimitiveGroup;