{"version":3,"file":"CMSLibrary.By-R5SM_.mjs","names":[],"sources":["https:/framerusercontent.com/modules/PNm0aYRdp2Urx1MCseUn/ELGxjV92WFMoGKTv2Ojs/CMSLibrary.js"],"sourcesContent":["export function getCollectionData(collectionList){let queryParent=null;if(collectionList?.props?.query){queryParent=collectionList;}else if(collectionList?.props?.children?.props?.query){queryParent=collectionList.props.children;}else if(collectionList?.props?.children?.props?.children?.props?.query){queryParent=collectionList.props.children.props.children;}const query=queryParent?.props?.query;const from=query?.from;let collections=[];if(from){if(from.type===\"Collection\"){collections.push(from);}else if(from.type===\"LeftJoin\"){processJoin(from.left,collections);processJoin(from.right,collections);}}const select=query?.select;if(collections.length>1&&Array.isArray(select)){for(const field of select){if(field.type==\"Identifier\"&&field.name==\"id\"&&!field.alias){const mainCollection=collections.find(c=>c.alias==field.collection);if(mainCollection){collections=[mainCollection,...collections.filter(c=>c!==mainCollection)];}break;}}}const multiReferenceQueries={};const multiReferenceIdMap={};// Get collections from multi-reference fields\nif(Array.isArray(select)){for(const field of select){if(field.type===\"FunctionCall\"&&(field.functionName===\"ARRAY\"||field.functionName===\"FLAT_ARRAY\")&&Array.isArray(field.arguments)){for(const argument of field.arguments){if(argument.from?.type===\"Collection\"){const alias=argument.from.alias;let fieldId=alias;const right=argument.where?.right;if(right&&right.type===\"Identifier\"&&right.name){fieldId=right.name;}collections.push({...argument.from,fieldId});multiReferenceIdMap[fieldId]=alias;multiReferenceIdMap[alias]=alias;multiReferenceQueries[alias]=argument;}}}}}let queryData=collections[0]?.data;const propertyControlsById={};const propertyControlsByTitle={};for(const collection of collections){const byId={};const byName={};propertyControlsById[collection.alias]=byId;propertyControlsByTitle[collection.alias]=byName;const propertyControls=collection.data?.propertyControls;for(const id of Object.keys(propertyControls)){const control={id,...propertyControls[id]};byId[id]=control;byName[control.title]=control;}}// Get children function\nlet childrenFunction=null;if(collectionList){const clpc=collectionList.props?.children;if(typeof clpc==\"function\"){childrenFunction=clpc;}else if(typeof clpc?.props?.children==\"function\"){childrenFunction=clpc.props.children;}else if(typeof clpc?.props?.children?.props?.children==\"function\"){childrenFunction=clpc.props.children.props.children;}}return{query,queryParent,queryData,collections,propertyControlsById,propertyControlsByTitle,childrenFunction,multiReferenceQueries,multiReferenceIdMap};}function processJoin(join,collections){if(join&&typeof join===\"object\"){if(join.type===\"Collection\"){collections.push(join);}else if(join.type===\"LeftJoin\"){processJoin(join.left,collections);processJoin(join.right,collections);}}}// field: { name: string, referenceFieldName: string }\nexport function addFieldsToSelect(fields,query,propertyControlsByTitle,collections){const select=Array.isArray(query?.select)?[...query.select]:[];for(const field of fields){const selectItem=getSelectItemForField(field.name,field.referenceFieldName,query,propertyControlsByTitle,collections,select);if(selectItem){select.push(selectItem);}}return select;}export function getSelectItemForField(name,referenceFieldName,query,propertyControlsByTitle,collections,select=null// When there is a select, check for a matching existing select item\n){// const mainAlias = query?.from?.alias || \"\"\nconst mainAlias=collections[0]?.alias||\"\";const propertyControl=propertyControlsByTitle[mainAlias]?.[name];if(!propertyControl){return null;}const fieldId=propertyControl?.id;const alias=referenceFieldName?fieldId:mainAlias;const referencedField=referenceFieldName?propertyControlsByTitle[fieldId]?.[referenceFieldName]:null;if(select){let matchFound=false;for(const item of select){if(item.type===\"Identifier\"){if(referenceFieldName){if(referencedField&&item.alias===`${fieldId}.${referencedField.id}`&&item.collection===fieldId&&item.name===referencedField.id){matchFound=true;break;}}else{if(item.name===fieldId&&item.collection===alias){matchFound=true;break;}}}else if(item.type===\"FunctionCall\"){if(item.alias===fieldId){matchFound=true;break;}}}if(matchFound){return null;}}if(referenceFieldName){if(referencedField){return{alias:`${fieldId}.${referencedField.id}`,collection:fieldId,name:referencedField.id,type:\"Identifier\"};}}else{return{collection:alias,name:fieldId,type:\"Identifier\"};}}\nexport const __FramerMetadata__ = {\"exports\":{\"getSelectItemForField\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getCollectionData\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":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