{"version":3,"file":"Pagination.TaPDKPLL.mjs","names":["useStore","useState","useState"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/FofzWjMzaMAqaelNvQwO/op7UfNonj5yjmX2s82oJ/Pagination.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}from\"react/jsx-runtime\";import{useState,useEffect}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=10;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 Current\";const useStore=createStore({limit:LIMIT,offset:0,totalItems:0,currentPage:1});const useSetQuery=()=>{const[store,setStore]=useStore();useEffect(()=>{setStore({limit:LIMIT,offset:0,currentPage:1});},[]);};export function withCollectionList(Component){return props=>{const[store,setStore]=useStore();const[newProps,setNewProps]=useState(props);useEffect(()=>{setStore({totalItems:props.children.props.query.from.data.length});},[props]);useEffect(()=>{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__*/_jsx(Component,{...newProps});};}export function withPrevious(Component){return props=>{const[store,setStore]=useStore();useSetQuery();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 function withNext(Component){return props=>{const[store,setStore]=useStore();useSetQuery();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 function withCurrentPage(Component){return props=>{const[store,setStore]=useStore();useSetQuery();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 function withPageSelector(Component){return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useSetQuery();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 function withTablePagination(Component){return props=>{const[store,setStore]=useStore();const[pages,setPages]=useState([]);useSetQuery();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);})});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withTablePagination\":{\"type\":\"reactHoc\",\"name\":\"withTablePagination\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNext\":{\"type\":\"reactHoc\",\"name\":\"withNext\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPageSelector\":{\"type\":\"reactHoc\",\"name\":\"withPageSelector\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPrevious\":{\"type\":\"reactHoc\",\"name\":\"withPrevious\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCurrentPage\":{\"type\":\"reactHoc\",\"name\":\"withCurrentPage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCollectionList\":{\"type\":\"reactHoc\",\"name\":\"withCollectionList\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Pagination.map"],"mappings":"oLAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,CAAC,CAClD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,MAAM,EAAE,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,EAAS,CAAC,EAChI,EAAW,OAAO,GAAS,SAAS,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,C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