{"version":3,"file":"CMSLibrary-vH7O.AXerKy4I.mjs","names":[],"sources":["https:/framerusercontent.com/modules/PNm0aYRdp2Urx1MCseUn/jWeh7GKvm3RetCKspgqG/CMSLibrary.js","https:/framer.com/m/CMSLibrary-vH7O.js"],"sourcesContent":["/**\n * Extracts query metadata and collection information from a Framer Collection List component.\n * Returns query object, collections, property controls, and other metadata needed for CMS operations.\n */export function getCollectionData(collectionList){// Traverse component tree to find the query object\n// Framer's Collection List component structure varies, so we check multiple levels\n// Query is stored in props.query of one of the nested components\nlet 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;// Extract collection(s) from query.from clause\n// Can be single Collection or LeftJoin (multiple collections joined)\nlet collections=[];if(from){if(from.type===\"Collection\"){collections.push(from);}else if(from.type===\"LeftJoin\"){// Recursively process joined collections\nprocessJoin(from.left,collections);processJoin(from.right,collections);}}const select=query?.select;// Determine main collection when multiple collections are joined\n// Main collection is the one whose \"id\" field is selected (without alias)\n// This ensures consistent ordering: main collection first, then referenced collections\nif(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;}}}// Extract multi-reference field queries\n// Multi-reference fields use ARRAY() or FLAT_ARRAY() functions in the select clause\n// Each function argument contains a sub-query for the referenced collection\nconst multiReferenceQueries={};const multiReferenceIdMap={};if(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;// Field ID can be from alias or from where clause's right side\nlet 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;// Build property controls index: by ID and by title for each collection\n// This allows quick lookup of field definitions by either ID or name\nconst 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;// Index each field definition by both ID and title for flexible lookups\nfor(const id of Object.keys(propertyControls)){const control={id,...propertyControls[id]};byId[id]=control;byName[control.title]=control;}}// Extract the children render function from Collection List\n// This function is used to render CMS items with proper data binding\n// Structure varies, so we check multiple nesting levels\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};}// Recursively process LeftJoin queries to extract all collections\n// LeftJoin can be nested (e.g., Collection1 LEFT JOIN (Collection2 LEFT JOIN Collection3))\nfunction processJoin(join,collections){if(join&&typeof join===\"object\"){if(join.type===\"Collection\"){collections.push(join);}else if(join.type===\"LeftJoin\"){// Recursively process nested joins\nprocessJoin(join.left,collections);processJoin(join.right,collections);}}}/**\n * Adds fields to a query's select array.\n * Used to include additional fields needed for filtering, search, or sorting.\n *\n * @param fields - Array of { name: string, referenceFieldName?: string }\n * @param query - Original query object\n * @param propertyControlsByTitle - Field definitions indexed by title\n * @param collections - Collection metadata\n * @returns New select array with added fields (deduplicated)\n */export function addFieldsToSelect(fields,query,propertyControlsByTitle,collections){// Create copy of existing select array to avoid mutation\nconst select=Array.isArray(query?.select)?[...query.select]:[];for(const field of fields){const selectItem=getSelectItemForField(field.name,field.referenceFieldName,query,propertyControlsByTitle,collections,select);// Only add if field exists and isn't already in select\nif(selectItem){select.push(selectItem);}}return select;}/**\n * Gets the select item configuration for a CMS field.\n * Returns null if field doesn't exist or is already in select array.\n *\n * @param name - Field name (e.g., \"Title\", \"Category\")\n * @param referenceFieldName - If field is a reference, name of field in referenced collection\n * @param query - Query object (currently unused but kept for compatibility)\n * @param propertyControlsByTitle - Field definitions indexed by title\n * @param collections - Collection metadata\n * @param select - Existing select array to check for duplicates (optional)\n * @returns Select item object or null\n */export function getSelectItemForField(name,referenceFieldName,query,propertyControlsByTitle,collections,select=null){const mainAlias=collections[0]?.alias||\"\";const propertyControl=propertyControlsByTitle[mainAlias]?.[name];if(!propertyControl){return null;}const fieldId=propertyControl?.id;const alias=referenceFieldName?fieldId:mainAlias;// For reference fields, get the referenced collection's field definition\nconst referencedField=referenceFieldName?propertyControlsByTitle[fieldId]?.[referenceFieldName]:null;// Check if field is already in select array to avoid duplicates\nif(select){let matchFound=false;for(const item of select){if(item.type===\"Identifier\"){if(referenceFieldName){// For reference fields, match by alias format: \"fieldId.referencedFieldId\"\nif(referencedField&&item.alias===`${fieldId}.${referencedField.id}`&&item.collection===fieldId&&item.name===referencedField.id){matchFound=true;break;}}else{// For regular fields, match by fieldId and collection\nif(item.name===fieldId&&item.collection===alias){matchFound=true;break;}}}else if(item.type===\"FunctionCall\"){// Match function calls by alias (e.g., ARRAY() functions)\nif(item.alias===fieldId){matchFound=true;break;}}}if(matchFound){return null;}}// Build select item object\nif(referenceFieldName){// Reference field: points to a field in the referenced collection\n// Format: alias = \"fieldId.referencedFieldId\", collection = fieldId, name = referencedFieldId\nif(referencedField){return{alias:`${fieldId}.${referencedField.id}`,collection:fieldId,name:referencedField.id,type:\"Identifier\"};}}else{// Regular field: points directly to a field in the main collection\nreturn{collection:alias,name:fieldId,type:\"Identifier\"};}}\nexport const __FramerMetadata__ = {\"exports\":{\"getCollectionData\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"addFieldsToSelect\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSelectItemForField\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CMSLibrary.map","/*\n * CMSLibrary\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/PNm0aYRdp2Urx1MCseUn/jWeh7GKvm3RetCKspgqG/CMSLibrary.js\"\n"],"mappings":"oDAGG,SAAgB,EAAkB,EAAe,CAGpD,IAAI,EAAY,KAAQ,GAAgB,OAAO,MAAO,EAAY,EAAwB,GAAgB,OAAO,UAAU,OAAO,MAAO,EAAY,EAAe,MAAM,SAAkB,GAAgB,OAAO,UAAU,OAAO,UAAU,OAAO,QAAO,EAAY,EAAe,MAAM,SAAS,MAAM,UAAU,IAAM,EAAM,GAAa,OAAO,MAAY,EAAK,GAAO,KAE1W,EAAY,EAAE,CAAI,IAAS,EAAK,OAAO,aAAc,EAAY,KAAK,EAAK,CAAU,EAAK,OAAO,aACrG,EAAY,EAAK,KAAK,EAAY,CAAC,EAAY,EAAK,MAAM,EAAY,GAAG,IAAM,EAAO,GAAO,OAG7F,GAAG,EAAY,OAAO,GAAG,MAAM,QAAQ,EAAO,MAAM,IAAM,KAAS,EAAQ,GAAG,EAAM,MAAM,cAAc,EAAM,MAAM,MAAM,CAAC,EAAM,MAAM,CAAC,IAAM,EAAe,EAAY,KAAK,GAAG,EAAE,OAAO,EAAM,WAAW,CAAI,IAAgB,EAAY,CAAC,EAAe,GAAG,EAAY,OAAO,GAAG,IAAI,EAAe,CAAC,EAAE,OAG1S,IAAM,EAAsB,EAAE,CAAO,EAAoB,EAAE,CAAC,GAAG,MAAM,QAAQ,EAAO,MAAM,IAAM,KAAS,EAAQ,GAAG,EAAM,OAAO,iBAAiB,EAAM,eAAe,SAAS,EAAM,eAAe,eAAe,MA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