infinity-forge
Version:
53 lines • 1.85 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChildren = getChildren;
var react_1 = __importDefault(require("react"));
function isChildSwiperSlide(child) {
return child.type && child.type.displayName && child.type.displayName.includes('SwiperSlide');
}
function processChildren(c) {
var slides = [];
react_1.default.Children.toArray(c).forEach(function (child) {
if (isChildSwiperSlide(child)) {
slides.push(child);
}
else if (child.props && child.props.children) {
processChildren(child.props.children).forEach(function (slide) { return slides.push(slide); });
}
});
return slides;
}
function getChildren(c) {
var slides = [];
var slots = {
'container-start': [],
'container-end': [],
'wrapper-start': [],
'wrapper-end': [],
};
react_1.default.Children.toArray(c).forEach(function (child) {
if (isChildSwiperSlide(child)) {
slides.push(child);
}
else if (child.props && child.props.slot && slots[child.props.slot]) {
slots[child.props.slot].push(child);
}
else if (child.props && child.props.children) {
var foundSlides = processChildren(child.props.children);
if (foundSlides.length > 0) {
foundSlides.forEach(function (slide) { return slides.push(slide); });
}
else {
slots['container-end'].push(child);
}
}
else {
slots['container-end'].push(child);
}
});
return { slides: slides, slots: slots };
}
//# sourceMappingURL=get-children.js.map