{"version":3,"file":"Reference_Plus.CURIw-EB.mjs","names":["useMemo","_Fragment","BaseControls"],"sources":["https:/framerusercontent.com/modules/QGRqJkgeASS31a3hsL58/KYeBcisX73BYW2z43Xq4/Reference_Plus.js"],"sourcesContent":["import{jsx as _jsx,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,// @ts-ignore\ngetPropertyControls,ControlType,useIsOnFramerCanvas,// @ts-ignore\nuseQueryData}from\"framer\";import{useMemo}from\"react\";import{useFilter,useConsoleLogWhenDebuggingCMSPlus}from\"https://framerusercontent.com/modules/uaC9hWf3ec7HqMv3sXMc/fThGQnEUZeWwDLSQMzea/Hooks.js\";import{useStore}from\"https://framerusercontent.com/modules/oaAH7umUjUOTeKmykfom/4GSr51yWhuxjuWu6QpOf/Stores.js\";import{getProps}from\"https://framerusercontent.com/modules/NktNXvnf4m4T7jKQcOHx/ld1Thy4iHs6v3180zPrJ/Utilities.js\";import BaseControls from\"https://framerusercontent.com/modules/1abSdslctova79WmNQRw/3fHstYFUOpeaxageGRMz/Filter_Base.js\";import CollectionIDControl from\"https://framerusercontent.com/modules/Hxho9sUnioBkMjGbLBed/csoxszrftuhmv2NyuE1c/collectionID.js\";import CMSFieldNameControl from\"https://framerusercontent.com/modules/xPWn77sAdxuRvon75kLo/B2UIyi7WVbdsZJvHIaDR/cmsFieldName.js\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n *\n * @framerDisableUnlink\n */export default function ReferencePlus(props){const{applyFilter,cmsFieldName,collectionID,condition,interactionActiveFilter,interactionInactiveFilter,referenceCollectionListInstance,preserveActiveFilter,value,values}=props;const cmsPlusComponentName=\"Filter+ Reference\";const{consoleLogWhenDebuggingCMSPlus}=useConsoleLogWhenDebuggingCMSPlus();const[store]=useStore();const collection=store[collectionID]||null;const isOnFramerCanvas=useIsOnFramerCanvas();const collectionIsReady=!isOnFramerCanvas&&!!collection;const cmsIDs=useMemo(()=>{// when this filter is checking if the reference is set or not, then the value is not used, therefore 'null' is returned\nif(condition.includes(\"IS_SET\"))return null;if(!collectionIsReady){if(condition.includes(\"=\"))return value;return values;}consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > Value(s):`,value,values);const referenceCollectionList=referenceCollectionListInstance?.[0];const collectionReferenceLink=getProps({object:referenceCollectionList,target:{name:\"from\",type:\"object\"}});consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > Linked Collection Ref:`,collectionReferenceLink);// get all the referenced collections\nconst collectionReferences=collection?.collectionReferences||null;// get the CMS field\nconst cmsField=collection?.fields?.[cmsFieldName]||null;// for CMS fields of type: collection references, their control ID is the alias of their collection\nconst collectionAlias=cmsField?.id;// get the referenced collection\nconst collectionReference=collectionReferences?.[collectionAlias]||collectionReferenceLink||null;consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > Collection Ref:`,collectionReference);if(!collectionReference)return null;// const collectionReferenceAlias = collectionReference.alias\n// get the CMS fields of the referenced collection\nconst collectionReferenceFields=getProps({object:collectionReference,target:{name:\"propertyControls\",type:\"object\"}});const collectionIdentifier={collection:collectionReference.alias,name:\"id\",type:\"Identifier\"};// construct the new query for extracting its CMS items\nconst newQuery={from:collectionReference,select:[collectionIdentifier]};consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > New Query:`,newQuery);let slugControlID;// loop throught the referenced colletion fields until you find the Slug field\nfor(const[controlID,controlProps]of Object.entries(collectionReferenceFields)){if(controlProps.title!==\"Slug\")continue;// push the slug into the select array, which is needed in the new query\nnewQuery.select.push({...collectionIdentifier,name:controlID});slugControlID=controlID;break;}// extract the cmsItems\nconst cmsItems=useQueryData(newQuery)||[];consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > CMS Items:`,cmsItems);// filter out only the cmsItems that the user inputed and return only the CMS item ID\n// slugs are unique, so there should be one result per input value\nconst selectedCMSItems=cmsItems.filter(item=>{const{id,[slugControlID]:slug}=item;consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > Item:`,item);consoleLogWhenDebuggingCMSPlus(`Reference Filter+ ${cmsFieldName} > Slug:`,slug);// for equals/doesn't equal compare with the single value\nif(condition.includes(\"=\")){if(value===slug)return true;}else{// for included/not included compare the current slug agains all the values the user inputed\nif(values.find(v=>v===slug))return true;}return false;});// we only need to retrun the CMS item IDs\nconst selectedCMSItemIDs=selectedCMSItems.map(item=>item.id);/**\n         * when the condition is equals/doesn't equal, then the array should have only one, and if the user inputed a valid slug to reference, then the first element is defined, otherwise no slug was found and returns 'null'\n         *\n         * when condition is included/not included in, the array will contain all found CMS item IDs, one for each valid input, if nothing was found and it results in an empty array, then return 'null'\n         */return condition.includes(\"=\")?selectedCMSItemIDs[0]||null:selectedCMSItemIDs.length>0?selectedCMSItemIDs:null;},[collectionIsReady,value,values]);useFilter({cmsFieldName,cmsPlusComponentName,collectionID,condition,interactionActiveFilter,interactionInactiveFilter,isPreserving:preserveActiveFilter,controlType:\"collectionreference\",isFilterActive:applyFilter,value:cmsIDs,valueIsRequired:!condition.includes(\"IS_SET\")});return /*#__PURE__*/_jsx(_Fragment,{});}ReferencePlus.displayName=\"Filter+ Reference\";addPropertyControls(ReferencePlus,{...getPropertyControls(CollectionIDControl),...getPropertyControls(BaseControls),...getPropertyControls(CMSFieldNameControl),referenceCollectionListInstance:{type:ControlType.ComponentInstance,title:\"Referenced Collection List\",description:`Link the referenced collection list.`},condition:{type:ControlType.Enum,title:\"Condition\",defaultValue:\"IS_SET\",optionTitles:[\"Is Set\",\"Isn't Set\",\"Equals\",\"Doesn't Equal\",\"Is Included In\",\"Isn't Included In\"],options:[\"IS_SET\",\"!IS_SET\",\"==\",\"!=\",\"IS_INCLUDED\",\"!IS_INCLUDED\"]},value:{type:ControlType.String,defaultValue:\"\",title:\"Slug\",description:\"The slug of the referenced CMS item in its collection.\",hidden:({condition})=>!condition.includes(\"=\")},values:{type:ControlType.Array,defaultValue:[],title:\"Slugs\",description:\"A list of slugs of the referenced CMS items in their collection.\",control:{type:ControlType.String},hidden:({condition})=>!condition.includes(\"IS_INCLUDED\")}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ReferencePlus\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerDisableUnlink\":\"\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"2oBAOG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,cAAY,eAAa,eAAa,YAAU,0BAAwB,4BAA0B,kCAAgC,uBAAqB,QAAM,UAAQ,EAA0D,CAAC,kCAAgC,GAAmC,CAAM,CAAC,GAAO,GAAU,CAAO,EAAW,EAAM,IAAe,KAAwD,EAAkB,CAA9C,GAAqB,EAA4C,CAAC,CAAC,EAAiB,EAAOA,MAAY,CAC3hB,GAAG,EAAU,SAAS,SAAS,CAAC,OAAO,KAAK,GAAG,CAAC,EAA2D,OAArC,EAAU,SAAS,IAAI,CAAQ,EAAa,EAAQ,EAA+B,qBAAqB,EAAa,cAAc,EAAM,EAAO,CAAC,IAAM,EAAwB,IAAkC,GAAS,EAAwB,EAAS,CAAC,OAAO,EAAwB,OAAO,CAAC,KAAK,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAA+B,qBAAqB,EAAa,2BAA2B,EAAwB,CAC1f,IAAM,EAAqB,GAAY,sBAAsB,KAEvD,GADS,GAAY,SAAS,IAAe,OACnB,GAC1B,EAAoB,IAAuB,IAAkB,GAAyB,KAA+G,GAA1G,EAA+B,qBAAqB,EAAa,oBAAoB,EAAoB,CAAI,CAAC,EAAoB,OAAO,KAE1O,IAAM,EAA0B,EAAS,CAAC,OAAO,EAAoB,OAAO,CAAC,KAAK,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAO,EAAqB,CAAC,WAAW,EAAoB,MAAM,KAAK,KAAK,KAAK,aAAa,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