UNPKG

sobs

Version:
44 lines 2.03 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; 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 }); const react_1 = __importStar(require("react")); exports.default = (_a) => { var { children } = _a, props = __rest(_a, ["children"]); if (props.object !== undefined) return createEnvironment([props.object], children); if (props.objects !== undefined) return createEnvironment(props.objects, children); throw new Error('sobs: You must specify either "object" or "objects" in an Environment'); }; const createEnvironment = (objects, children) => (react_1.default.createElement(react_1.default.Fragment, null, transformChildProps(children, props => { var _a; return (Object.assign(Object.assign({}, props), { __sobs_environment: [ ...(_a = props.__sobs_environment) !== null && _a !== void 0 ? _a : [], ...objects ] })); }))); const transformChildProps = (children, transform) => react_1.Children.map(children, child => { if (!(react_1.isValidElement(child) && child.props)) return child; const props = transform(child.props); props.children = transformChildProps(child.props.children, transform); return react_1.cloneElement(child, props); }); //# sourceMappingURL=Environment.js.map