{"version":3,"file":"LoadMore.CPc3E9ih.mjs","names":["useState","useState","_Fragment"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/SNQCAFzsGw6Y3zQX5Y4P/pKwcoFcwKGoYtB4J0eob/LoadMore.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})});// Create a set function that updates the state\nconst setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});};// Store the initial state, copy the object if it's an object\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;// Update all the listeners / setters with the new value\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState);// If we unmount the component using this hook, we need to remove the listener\n// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[]);// If Data context exists, use Data, otherwise use vanilla React state\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","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ément. https://lionneclement.com/\n// Full tutorial: https://lionneclement.com/tutorial/how-to-create-pagination-for-cms-collections-in-framer\nconst LIMIT=4;const OFFSET=6;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(props);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\":{\"withInfiniteScroll\":{\"type\":\"reactHoc\",\"name\":\"withInfiniteScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCollectionList\":{\"type\":\"reactHoc\",\"name\":\"withCollectionList\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCurrentPage\":{\"type\":\"reactHoc\",\"name\":\"withCurrentPage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPageSelector\":{\"type\":\"reactHoc\",\"name\":\"withPageSelector\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTablePagination\":{\"type\":\"reactHoc\",\"name\":\"withTablePagination\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClear\":{\"type\":\"reactHoc\",\"name\":\"withClear\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNext\":{\"type\":\"reactHoc\",\"name\":\"withNext\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPrevious\":{\"type\":\"reactHoc\",\"name\":\"withPrevious\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLoadMore\":{\"type\":\"reactHoc\",\"name\":\"withLoadMore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LoadMore.map"],"mappings":"+MAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,CAAM,CAAC,CAAC,CAAC,EACjD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,KAAK,GAAG,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,CAAQ,CAA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