migrate markdown widget

This commit is contained in:
Shawn Erquhart
2018-07-24 21:46:04 -04:00
parent 3f47fe6dbf
commit f1a2eb33b4
62 changed files with 411 additions and 538 deletions

View File

@ -0,0 +1,53 @@
import PropTypes from 'prop-types';
import { Component, Children } from 'react';
import { List, Record, fromJS } from 'immutable';
import { isFunction } from 'lodash';
const plugins = { editor: List() };
const catchesNothing = /.^/;
const EditorComponent = Record({
id: null,
label: 'unnamed component',
icon: 'exclamation-triangle',
fields: [],
pattern: catchesNothing,
fromBlock(match) { return {}; },
toBlock(attributes) { return 'Plugin'; },
toPreview(attributes) { return 'Plugin'; },
});
class Plugin extends Component { // eslint-disable-line
static propTypes = {
children: PropTypes.element.isRequired,
};
static childContextTypes = {
plugins: PropTypes.object,
};
getChildContext() {
return { plugins };
}
render() {
return Children.only(this.props.children);
}
}
export default function createEditorComponent(config) {
const configObj = new EditorComponent({
id: config.id || config.label.replace(/[^A-Z0-9]+/ig, '_'),
label: config.label,
icon: config.icon,
fields: fromJS(config.fields),
pattern: config.pattern,
fromBlock: isFunction(config.fromBlock) ? config.fromBlock.bind(null) : null,
toBlock: isFunction(config.toBlock) ? config.toBlock.bind(null) : null,
toPreview: isFunction(config.toPreview) ? config.toPreview.bind(null) : config.toBlock.bind(null),
});
return configObj;
}