{"version":3,"file":"CMSRandomize.Cjdfjc8I.mjs","names":[],"sources":["https:/framerusercontent.com/modules/M4PVdeA5WjttkTYxo9ar/1gX3x3l7GUyLItyK918o/CMSRandomize.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect,useMemo}from\"react\";import{addPropertyControls,ControlType,RenderTarget,// @ts-ignore\nuseQueryData,// @ts-ignore\nuseLoadMorePaginatedQuery}from\"framer\";import{getCollectionData}from\"https://framer.com/m/CMSLibrary-vH7O.js\";import{Message}from\"https://framerusercontent.com/modules/bWuIUhIQLpjdL0ydQqRy/3nMJlk7029Qui8lmEzG8/Message.js\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function CMSRandomize(props){const{columns,gap,maxWidth,randomize,limit,hasLoadMore}=props;/* Checks */const currentTarget=RenderTarget.current();const isCanvas=currentTarget===RenderTarget.canvas||currentTarget===RenderTarget.export;const collectionList=props.collectionList?.[0];const pageSize=collectionList?.props?.children?.props?.children?.props?.pageSize;const queryRaw=collectionList?.props?.children?.props?.children?.props?.query;if(queryRaw){collectionList.props.children.props.children.props.query.limit={type:\"LiteralValue\",value:limit};}const[items,setItems]=useState([]);const[allItems,setAllItems]=useState([]);const[loadCount,setLoadCount]=useState(1);const[loadMoreBtn,setLoadMoreBtn]=useState(null);const[moreBlogPostsMsg,setMoreBlogPostsMsg]=useState(null);// Get collection data\nconst{query,collections,childrenFunction}=useMemo(()=>getCollectionData(collectionList),[collectionList]);const collectionAlias=collections[0]?.alias;const{paginatedQuery,paginationInfo,loadMore}=!isCanvas?useLoadMorePaginatedQuery(query,pageSize,collectionAlias):\"\";const data=!isCanvas?useQueryData(paginatedQuery):[];const children=!isCanvas?childrenFunction(data,paginationInfo,loadMore):[];const loadMoreClick=()=>{const newCount=loadCount+1;setLoadCount(newCount);const newItems=allItems.slice(0,limit*newCount);setItems(newItems);};// Process CMS Data\nuseEffect(()=>{if(isCanvas)return;if(!data||!Array.isArray(data))return;let rawItems=[];if(hasLoadMore){rawItems=children.props.children[0];setLoadMoreBtn(children.props.children[1]);setMoreBlogPostsMsg(children.props.children[2]);}else{rawItems=children.props.children;}if(randomize){rawItems=shuffleArray(rawItems);}setAllItems(rawItems);setItems(rawItems.slice(0,limit));},[randomize,hasLoadMore]);const allShown=items.length>=allItems.length;return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",display:\"flex\",justifyContent:\"center\"},children:/*#__PURE__*/_jsxs(\"div\",{style:{maxWidth:maxWidth},children:[/*#__PURE__*/_jsx(\"div\",{className:isCanvas?\"\":collectionList?.props?.className,style:{width:\"100%\",gridTemplateColumns:`repeat(${columns},minmax(50px,1fr))`,gap:gap},children:isCanvas?/*#__PURE__*/_jsx(Message,{title:\"Preview site to see results\",subtitle:\"The randomized CMS collection is not available in the editor. Preview or publish your site to see the results.\"}):items}),/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",justifyContent:!allShown?\"center\":\"start\",width:\"100%\"},children:hasLoadMore&&!allShown?/*#__PURE__*/_jsx(\"div\",{style:{width:\"fit-content\"},onClick:loadMoreClick,children:loadMoreBtn}):/*#__PURE__*/_jsx(\"div\",{children:moreBlogPostsMsg})})]})});}function shuffleArray(array){return array.map(value=>({value,sort:Math.random()})).sort((a,b)=>a.sort-b.sort).map(({value})=>value);}addPropertyControls(CMSRandomize,{collectionList:{type:ControlType.ComponentInstance,title:\"CMS Collection\"},columns:{type:ControlType.Number,title:\"Grid Columns\",displayStepper:true,defaultValue:1},gap:{type:ControlType.Number,title:\"Gap\",displayStepper:true,defaultValue:24},maxWidth:{type:ControlType.Number,title:\"Max Width\",displayStepper:true,defaultValue:1400},randomize:{type:ControlType.Boolean,title:\"Randomize\",defaultValue:false},limit:{type:ControlType.Number,title:\"Limit\",defaultValue:20,min:0},hasLoadMore:{type:ControlType.Boolean,title:\"Paginate Load More\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CMSRandomize\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CMSRandomize.map"],"mappings":"gdAKG,SAAwB,EAAa,EAAM,CAAC,GAAK,CAAC,UAAQ,MAAI,WAAS,YAAU,QAAM,cAAY,CAAC,EAAwB,EAAc,EAAa,SAAS,CAAO,EAAS,IAAgB,EAAa,QAAQ,IAAgB,EAAa,OAAa,EAAe,EAAM,iBAAiB,GAAS,EAAS,GAAgB,OAAO,UAAU,OAAO,UAAU,OAAO,SAAe,EAAS,GAAgB,OAAO,UAAU,OAAO,UAAU,OAAO,MAAM,AAAG,IAAU,EAAe,MAAM,SAAS,MAAM,SAAS,MAAM,MAAM,MAAM,CAAC,KAAK,eAAe,MAAM,CAAM,GAAE,GAAK,CAAC,EAAM,EAAS,CAAC,EAAS,CAAE,EAAC,CAAM,CAAC,EAAS,EAAY,CAAC,EAAS,CAAE,EAAC,CAAM,CAAC,EAAU,EAAa,CAAC,EAAS,EAAE,CAAM,CAAC,EAAY,EAAe,CAAC,EAAS,KAAK,CAAM,CAAC,EAAiB,EAAoB,CAAC,EAAS,KAAK,CACrxB,CAAC,QAAM,cAAY,mBAAiB,CAAC,EAAQ,IAAI,EAAkB,EAAe,CAAC,CAAC,CAAe,EAAC,CAAO,EAAgB,EAAY,IAAI,MAAW,CAAC,iBAAe,iBAAe,WAAS,CAAE,EAAmE,GAA1D,EAA0B,EAAM,EAAS,EAAgB,CAAU,EAAM,EAAsC,CAAE,EAA/B,EAAa,EAAe,CAAU,EAAU,EAAwD,CAAE,EAAjD,EAAiB,EAAK,EAAe,EAAS,CAAU,EAAc,IAAI,CAAC,IAAM,EAAS,EAAU,EAAE,EAAa,EAAS,CAAC,IAAM,EAAS,EAAS,MAAM,EAAE,EAAM,EAAS,CAAC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