UNPKG

@gravel-form/blueprintjs

Version:

A flexible middlewares driven json schema form with Blueprintjs

57 lines (54 loc) 2.15 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __importStar(require("react")); exports.ChangeToBlurMw = function (props) { var schema = props.schema, next = props.next, data = props.data, onChange = props.onChange; var focus = React.useRef(false); var _a = __read(React.useState(null), 2), value = _a[0], setValue = _a[1]; if (typeof schema === 'boolean' || schema.type === 'object' || schema.type === 'array') return next(props); return (React.createElement("div", { onFocus: function () { focus.current = true; setValue(data); }, onBlur: function () { focus.current = false; onChange(value); } }, next(__assign(__assign({}, props), { data: focus.current ? value : data, onChange: focus.current ? setValue : onChange })))); }; exports.default = exports.ChangeToBlurMw; //# sourceMappingURL=ChangeToBlueMw.js.map //# sourceMappingURL=ChangeToBlueMw.js.map