frontity
Version:
Frontity cli and entry point to other packages
57 lines (56 loc) • 2.71 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
const connect_1 = __importStar(require("@frontity/connect"));
const use_fills_1 = __importDefault(require("./use-fills"));
/**
* A React component that renders a Fill to fulfill a Slot and Fill pattern.
*/
const Slot = (_a) => {
var { name, children } = _a, slotProps = __rest(_a, ["name", "children"]);
const { state } = connect_1.useConnect();
// Get the data, either from props or the current link.
const data = slotProps.data || state.source.get(state.router.link);
// Get the fills for this name.
const fills = use_fills_1.default(name);
return (
// Returning a <Fragment/> because returning an array of components results in a typescript error
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20356
jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: fills.length > 0
? fills.map(({ Fill, props, key }) => (jsx_runtime_1.jsx(Fill, Object.assign({ name: key, data: data }, slotProps, props), key)))
: children }, void 0));
};
exports.default = connect_1.default(Slot, { injectProps: false });