{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/8xulrCX6d25PQ19jMU7W/N775gZeAp3olVstVvtUm/Pagination.js"],
  "sourcesContent": ["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useState,useEffect,useLayoutEffect}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";// Made with love by Cl\u00E9ment. https://lionneclement.com/\n// Full tutorial: https://lionneclement.com/tutorial/how-to-create-pagination-for-cms-collections-in-framer\nconst LIMIT=6;const OFFSET=0;const SCROLL_THRESHOLD=200;const PREVIOUS_CLASS=\"Previous\";const PREVIOUS_DISABLED_CLASS=\"Previous Disabled\";const NEXT_CLASS=\"Next\";const NEXT_DISABLED_CLASS=\"Next Disabled\";const PAGE_NUMBER_CLASS=\"Page Number\";const PAGE_NUMBER_ACTIVE_CLASS=\"Page Number Active\";const useStore=createStore({limit:LIMIT,offset:OFFSET,totalItems:null,currentPage:1});export const withCollectionList=Component=>{return props=>{const[store,setStore]=useStore();const[newProps,setNewProps]=useState(useState({...props,children:{...props.children,props:{...props.children.props,query:{...props.children.props.query,limit:{type:\"LiteralValue\",value:store.limit}}}}}));useEffect(()=>{if(store.totalItems===null){const queryTotalItems=document.querySelector(`.${props.className}none .${props.className}`).children.length;const newTotalItems=queryTotalItems-OFFSET;setStore({totalItems:Math.max(newTotalItems,0)});}},[props,store]);useLayoutEffect(()=>{setNewProps({...props,children:{...props.children,props:{...props.children.props,query:{...props.children.props.query,limit:{type:\"LiteralValue\",value:store.limit},offset:{type:\"LiteralValue\",value:store.offset}}}}});},[store.offset,store.limit,props]);return /*#__PURE__*/_jsxs(_Fragment,{children:[store.totalItems===null&&/*#__PURE__*/_jsx(\"div\",{className:`${props.className}none`,style:{display:\"none\"},children:/*#__PURE__*/_jsx(Component,{...props})}),/*#__PURE__*/_jsx(Component,{...newProps})]});};};export const withLoadMore=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1});},[]);return /*#__PURE__*/_jsx(_Fragment,{children:store.limit<store.totalItems&&/*#__PURE__*/_jsx(Component,{...props,onClick:()=>setStore({limit:store.limit+LIMIT})})});};};export const withInfiniteScroll=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1});},[]);useEffect(()=>{window.addEventListener(\"scroll\",handleScroll);return()=>{window.removeEventListener(\"scroll\",handleScroll);};},[store,store.limit,store.totalItems]);const handleScroll=()=>{if(store.totalItems&&store.limit<store.totalItems&&window.innerHeight+document.documentElement.scrollTop>=document.documentElement.offsetHeight-SCROLL_THRESHOLD){setStore({limit:store.limit+LIMIT});}};return /*#__PURE__*/_jsx(Component,{...props});};};export const withPrevious=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const handlePreviousPage=()=>{if(store.currentPage>1){const newPage=store.currentPage-1;const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);}};return /*#__PURE__*/_jsx(Component,{...props,onClick:handlePreviousPage,variant:store.currentPage!==1?PREVIOUS_CLASS:PREVIOUS_DISABLED_CLASS});};};export const withNext=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const handleNextPage=()=>{if(store.currentPage*LIMIT<store.totalItems){const newPage=store.currentPage+1;const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);}};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleNextPage,variant:store.currentPage*LIMIT<store.totalItems?NEXT_CLASS:NEXT_DISABLED_CLASS});};};export const withCurrentPage=Component=>{return props=>{const[store,setStore]=useStore();useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);const[currentPage,setCurrentPage]=useState(()=>store.currentPage.toString());const[totalPages,setTotalPages]=useState(()=>Math.ceil(store.totalItems/LIMIT));useEffect(()=>{setCurrentPage(store.currentPage.toString());setTotalPages(Math.ceil(store.totalItems/LIMIT));},[store.currentPage,store.totalItems]);return /*#__PURE__*/_jsx(Component,{...props,page:`${currentPage}/${totalPages}`});};};export const withPageSelector=Component=>{return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);useEffect(()=>{const generatePages=()=>{const totalPages=Math.ceil(store.totalItems/LIMIT);const newPages=Array.from({length:totalPages},(_,index)=>index+1);setPages(newPages);};generatePages();},[store.totalItems]);const handleNewPage=newPage=>{const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);};return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"row\"},children:pages.map((item,index)=>{return /*#__PURE__*/_jsx(Component,{...props,page:item.toString(),onClick:()=>handleNewPage(item),variant:store.currentPage===item?PAGE_NUMBER_ACTIVE_CLASS:PAGE_NUMBER_CLASS},index);})});};};export const withTablePagination=Component=>{return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useEffect(()=>{setStore({totalItems:null,limit:LIMIT});},[]);useEffect(()=>{const generatePages=()=>{const totalPages=Math.ceil(store.totalItems/LIMIT);const adjacentPages=store.currentPage===1||store.currentPage===totalPages?2:1;const pages=[];for(let i=1;i<=totalPages;i++){const isWithinRange=i>=store.currentPage-adjacentPages&&i<=store.currentPage+adjacentPages;if(i===1||i===totalPages||isWithinRange){pages.push(i);}else if(i===store.currentPage-adjacentPages-1&&i!==1||i===store.currentPage+adjacentPages+1&&i!==totalPages){pages.push(\"...\");}}setPages(pages);};generatePages();},[store.totalItems,store.currentPage]);const handleNewPage=newPage=>{const newOffset=(newPage-1)*LIMIT;setStore({offset:newOffset,currentPage:newPage});window.scrollTo(0,0);};return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"row\"},children:pages.map((item,index,array)=>{const isEllipsis=item===\"...\";return /*#__PURE__*/_jsx(Component,{...props,page:item.toString(),onClick:()=>!isEllipsis&&handleNewPage(item),variant:store.currentPage===item||isEllipsis?PAGE_NUMBER_ACTIVE_CLASS:PAGE_NUMBER_CLASS},index);})});};};export const withClear=Component=>{return props=>{const[store,setStore]=useStore();const handleClick=()=>{setStore({offset:OFFSET,totalItems:null,currentPage:1,limit:LIMIT});};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};};\nexport const __FramerMetadata__ = {\"exports\":{\"withPrevious\":{\"type\":\"reactHoc\",\"name\":\"withPrevious\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTablePagination\":{\"type\":\"reactHoc\",\"name\":\"withTablePagination\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCollectionList\":{\"type\":\"reactHoc\",\"name\":\"withCollectionList\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withInfiniteScroll\":{\"type\":\"reactHoc\",\"name\":\"withInfiniteScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNext\":{\"type\":\"reactHoc\",\"name\":\"withNext\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPageSelector\":{\"type\":\"reactHoc\",\"name\":\"withPageSelector\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCurrentPage\":{\"type\":\"reactHoc\",\"name\":\"withCurrentPage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClear\":{\"type\":\"reactHoc\",\"name\":\"withClear\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoadMore\":{\"type\":\"reactHoc\",\"name\":\"withLoadMore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Pagination.map"],
  "mappings": "uGAEA,IAAMA,EAAM,EAAQC,EAAO,EAA2Q,IAAMC,EAASC,EAAY,CAAC,MAAMC,EAAM,OAAOC,EAAO,WAAW,KAAK,YAAY,CAAC,CAAC,EAAwkC,IAAMC,EAAaC,GAAmBC,GAAO,CAAC,GAAK,CAACC,EAAMC,CAAQ,EAAEC,EAAS,EAAE,OAAAC,EAAU,IAAI,CAACF,EAAS,CAAC,OAAOG,EAAO,WAAW,KAAK,YAAY,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,EAAsBC,EAAKC,EAAU,CAAC,SAASN,EAAM,MAAMA,EAAM,YAAyBK,EAAKP,EAAU,CAAC,GAAGC,EAAM,QAAQ,IAAIE,EAAS,CAAC,MAAMD,EAAM,MAAMO,CAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAmlD,IAAMC,EAAgBC,GAAmBC,GAAO,CAAC,GAAK,CAACC,EAAMC,CAAQ,EAAEC,EAAS,EAAEC,EAAU,IAAI,CAACF,EAAS,CAAC,WAAW,KAAK,MAAMG,CAAK,CAAC,CAAE,EAAE,CAAC,CAAC,EAAE,GAAK,CAACC,EAAYC,CAAc,EAAEC,EAAS,IAAIP,EAAM,YAAY,SAAS,CAAC,EAAO,CAACQ,EAAWC,CAAa,EAAEF,EAAS,IAAI,KAAK,KAAKP,EAAM,WAAWI,CAAK,CAAC,EAAE,OAAAD,EAAU,IAAI,CAACG,EAAeN,EAAM,YAAY,SAAS,CAAC,EAAES,EAAc,KAAK,KAAKT,EAAM,WAAWI,CAAK,CAAC,CAAE,EAAE,CAACJ,EAAM,YAAYA,EAAM,UAAU,CAAC,EAAsBU,EAAKZ,EAAU,CAAC,GAAGC,EAAM,KAAK,GAAGM,KAAeG,GAAY,CAAC,CAAE",
  "names": ["LIMIT", "OFFSET", "useStore", "createStore", "LIMIT", "OFFSET", "withLoadMore", "Component", "props", "store", "setStore", "useStore", "ue", "OFFSET", "p", "l", "LIMIT", "withCurrentPage", "Component", "props", "store", "setStore", "useStore", "ue", "LIMIT", "currentPage", "setCurrentPage", "ye", "totalPages", "setTotalPages", "p"]
}
