get-children.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function getChildren(originalSlots, slidesRef, oldSlidesRef) {
  2. if (originalSlots === void 0) {
  3. originalSlots = {};
  4. }
  5. const slides = [];
  6. const slots = {
  7. 'container-start': [],
  8. 'container-end': [],
  9. 'wrapper-start': [],
  10. 'wrapper-end': []
  11. };
  12. const getSlidesFromElements = (els, slotName) => {
  13. if (!Array.isArray(els)) {
  14. return;
  15. }
  16. els.forEach(vnode => {
  17. const isFragment = typeof vnode.type === 'symbol';
  18. if (slotName === 'default') slotName = 'container-end';
  19. if (isFragment && vnode.children) {
  20. getSlidesFromElements(vnode.children, 'default');
  21. } else if (vnode.type && (vnode.type.name === 'SwiperSlide' || vnode.type.name === 'AsyncComponentWrapper')) {
  22. slides.push(vnode);
  23. } else if (slots[slotName]) {
  24. slots[slotName].push(vnode);
  25. }
  26. });
  27. };
  28. Object.keys(originalSlots).forEach(slotName => {
  29. if (typeof originalSlots[slotName] !== 'function') return;
  30. const els = originalSlots[slotName]();
  31. getSlidesFromElements(els, slotName);
  32. });
  33. oldSlidesRef.value = slidesRef.value;
  34. slidesRef.value = slides;
  35. return {
  36. slides,
  37. slots
  38. };
  39. }
  40. export { getChildren };