UNPKG

@lyra/form-builder

Version:
97 lines (81 loc) 2.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _LyraFormBuilderContext = require('./LyraFormBuilderContext'); var _LyraFormBuilderContext2 = _interopRequireDefault(_LyraFormBuilderContext); var _FormBuilderInput = require('../FormBuilderInput'); var _typedefs = require('../typedefs'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /*:: type PatchChannel = { subscribe: () => () => {}, receivePatches: (patches: Array<*>) => void }*/ /*:: type Props = { value: ?any, schema: any, type: Object, markers: Array<Marker>, patchChannel: PatchChannel, onFocus: Path => void, path: Path, readOnly: boolean, onChange: () => {}, onBlur: () => void, autoFocus: boolean, focusPath: Path }*/ class LyraFormBuilder extends _react2.default.Component /*:: <Props>*/ { constructor(...args) { var _temp; return _temp = super(...args), this.setInput = (input /*: ?FormBuilderInput*/) => { this._input = input; }, _temp; } componentDidMount() { const autoFocus = this.props.autoFocus; if (this._input && autoFocus) { this._input.focus(); } } render() { var _props = this.props; const value = _props.value, schema = _props.schema, patchChannel = _props.patchChannel, type = _props.type, path = _props.path, onChange = _props.onChange, readOnly = _props.readOnly, markers = _props.markers, onFocus = _props.onFocus, onBlur = _props.onBlur, focusPath = _props.focusPath; return _react2.default.createElement( _LyraFormBuilderContext2.default, { value: value, schema: schema, patchChannel: patchChannel }, _react2.default.createElement(_FormBuilderInput.FormBuilderInput, { type: type, path: path, onChange: onChange, level: 0, value: value, onFocus: onFocus, onBlur: onBlur, markers: markers, focusPath: focusPath, isRoot: true, readOnly: readOnly, ref: this.setInput }) ); } } exports.default = LyraFormBuilder; LyraFormBuilder.createPatchChannel = _LyraFormBuilderContext2.default.createPatchChannel;