{"version":3,"file":"Search_Plus.B-Rp4paR.mjs","names":["_Fragment","collection","useState","useRef","cmsFieldNames"],"sources":["https:/framerusercontent.com/modules/Hxho9sUnioBkMjGbLBed/csoxszrftuhmv2NyuE1c/collectionID.js","https:/framerusercontent.com/modules/Zj8vwyaZ9D974JJDIpb6/i0Htui6PPTrQsbmPET9Z/Search_Plus.js"],"sourcesContent":["import{jsx as _jsx,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n *\n * @framerDisableUnlink\n */export default function CollectionIDControl(props){return /*#__PURE__*/_jsx(_Fragment,{});}addPropertyControls(CollectionIDControl,{collectionID:{type:ControlType.Number,title:\"Collection+ ID\",defaultValue:0,min:0,displayStepper:true,step:1}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CollectionIDControl\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./collectionID.map","import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,// @ts-ignore\ngetPropertyControls,ControlType,useIsOnFramerCanvas}from\"framer\";import{useEffect,useState,useRef}from\"react\";import{useStore}from\"https://framerusercontent.com/modules/oaAH7umUjUOTeKmykfom/4GSr51yWhuxjuWu6QpOf/Stores.js\";import{useDebouncer,useConsoleLogWhenDebuggingCMSPlus}from\"https://framerusercontent.com/modules/uaC9hWf3ec7HqMv3sXMc/fThGQnEUZeWwDLSQMzea/Hooks.js\";import CollectionIDControl from\"https://framerusercontent.com/modules/Hxho9sUnioBkMjGbLBed/csoxszrftuhmv2NyuE1c/collectionID.js\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n *\n * @framerDisableUnlink\n */export default function Search_Plus(props){const{fontColor,cmsFieldNames,fontStyles,placeHolderColor,placeHolderText,preserveFilter,selectedRealTimeSearches,onInput}=props;const fieldPlusComponent=\"Search+\";const[store,setStore]=useStore();/**\n     * looks for at least one valid collection ID in store.\n     *\n     * if Search+ has multiple elements in selectedRealTimeSearches listed, then i all listed valid collections will have the same realTimeSearch.text string\n     */const foundValidCollection=selectedRealTimeSearches.find(({collectionID})=>!!store[collectionID]);const collection=store[foundValidCollection?.collectionID]||null;const collectionIsInitialized=!!collection;// gather all the real time search text form every initialized collection in the store\n// it will be used watch the value that will trigger a useEffect when any value is cleared remotely\nconst realTimeSearchTexts=Object.values(store).map(collection=>collection.realTimeSearch.text);const supportedFieldTypes=[\"string\"];const isOnFramerCanvas=useIsOnFramerCanvas();const{consoleLogWhenDebuggingCMSPlus}=useConsoleLogWhenDebuggingCMSPlus();const[userInput,setUserInput]=useState(collectionIsInitialized?collection.realTimeSearch.text:\"\");const userInputDebounced=useDebouncer({delay:200,value:userInput});const[inputHasFocus,setInputHasFocus]=useState(false);const hasMountedRef=useRef(false);const inputStyles={...props.style,...fontStyles,backgroundColor:\"transparent\",border:\"none\",color:!inputHasFocus&&!userInput?placeHolderColor:fontColor,outline:\"none\",width:\"100%\"};const handleOnInput=e=>{// allows for an override to hook into the change event\nif(onInput&&typeof onInput===\"function\")onInput?.(e);if(collectionIsInitialized)setUserInput(e.target.value);};const handleInputOnFocus=()=>setInputHasFocus(true);const handleInputOnBlur=()=>setInputHasFocus(false);// handles realTimeSearch.text and input change. reset the input value if the realTimeSearch.text is cleared externally from Clear+\nuseEffect(()=>{if(collectionIsInitialized&&hasMountedRef.current&&!!userInputDebounced&&!collection.realTimeSearch.text){consoleLogWhenDebuggingCMSPlus(\"🆑:\",\"Search+:\",` id#s [${selectedRealTimeSearches.map(search=>search.collectionID).join(\",\")}] cleared remotely.`);setUserInput(\"\");}},[collectionIsInitialized,...realTimeSearchTexts]);// handles userInputDebounced\n// when userInputDebounced is different from userInput, it will update the realTimeSearch.text in collection's store\nuseEffect(()=>{if(collectionIsInitialized&&userInputDebounced!==collection.realTimeSearch?.text){consoleLogWhenDebuggingCMSPlus(\"🔍:\",\"Search+:\",`\"${userInputDebounced}\"`);setStore(prev=>{const newStore={...prev};// loop through each element in selectedRealTimeSearches\n// each element will contain a collectionID\nfor(let index=0;index<selectedRealTimeSearches.length;index++){const{clearAllActiveFilters,cmsFieldNames,collectionID}=selectedRealTimeSearches[index];// get the collection from store\nconst collection=newStore[collectionID];// skip if collection not initiated in store\nif(!collection)continue;// set the input text\nnewStore[collectionID].realTimeSearch.text=userInputDebounced;// the input text will be searched in these fields\nconst searchFields=[];// loop through each field in this collection\nfor(const[fieldName,{type}]of Object.entries(collection.fields)){// skip if this field does not have any filters or the type is not supported\nif(!supportedFieldTypes.includes(type))continue;// push field if clearAllActiveFilters was selected, otherwise push if included in cmsFieldNames array\nif(clearAllActiveFilters||cmsFieldNames.includes(fieldName)){searchFields.push(fieldName);}}// set the searchFields to collection store realTimeSearch\nnewStore[collectionID].realTimeSearch.fields=searchFields;}return{...newStore};});}},[collectionIsInitialized,userInputDebounced]);// clean up function to reset when user is not preserving this filter search\nuseEffect(()=>{hasMountedRef.current=true;return()=>{if(collectionIsInitialized&&!preserveFilter){setStore(prev=>{const newStore={...prev};for(let index=0;index<selectedRealTimeSearches.length;index++){const{collectionID}=selectedRealTimeSearches[index];const collection=newStore[collectionID];if(!collection)continue;newStore[collectionID].realTimeSearch={...newStore[collectionID].realTimeSearch,text:\"\",fields:[]};}return{...newStore};});}};},[collectionIsInitialized,preserveFilter]);return /*#__PURE__*/_jsx(\"input\",{style:inputStyles,type:\"text\",value:!inputHasFocus&&!userInput?placeHolderText:userInput,onChange:handleOnInput,onFocus:handleInputOnFocus,onBlur:handleInputOnBlur});}Search_Plus.displayName=\"Search+\";addPropertyControls(Search_Plus,{selectedRealTimeSearches:{type:ControlType.Array,title:\"Searches\",defaultValue:[],description:`Explore its [documentation](https://framercms.plus/documentation/component-search-plus).`,control:{type:ControlType.Object,title:\"Collections & Fields\",controls:{...getPropertyControls(CollectionIDControl),clearAllActiveFilters:{type:ControlType.Boolean,title:\"All Fields\",defaultValue:true,description:\"Slug field is included.\"},cmsFieldNames:{type:ControlType.Array,title:\"Fields\",defaultValue:[],description:\"Must match exactly as the field is named in its collection.\",control:{type:ControlType.String,title:\"Field\",defaultValue:\"\"},hidden:props=>props.clearAllActiveFilters}}}},preserveFilter:{type:ControlType.Boolean,title:\"Preserve\",defaultValue:true,description:`Input text. [Explore feature.](https://framercms.plus/documentation/preserve-settings)`},fontStyles:{type:ControlType.Font,controls:\"extended\",title:\"Font\"},fontColor:{type:ControlType.Color,title:\"Font Color\"},placeHolderText:{type:ControlType.String,title:\"Placeholder\",defaultValue:\"CMS Plus Search+ Component\",placeholder:\"Optional\"},placeHolderColor:{type:ControlType.Color,title:\"Placeholder Color\",defaultValue:\"#b8b8b8\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Search_Plus\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Search_Plus.map"],"mappings":"wRAKG,SAAwB,EAAoB,EAAM,CAAC,OAAoB,EAAKA,EAAU,EAAE,CAAC,kBAL3B,IAAoD,CAKvB,EAAoB,EAAoB,CAAC,aAAa,CAAC,KAAK,EAAY,OAAO,MAAM,iBAAiB,aAAa,EAAE,IAAI,EAAE,eAAe,GAAK,KAAK,EAAE,CAAC,CAAC,ICCnP,SAAwB,EAAY,EAAM,CAAC,GAAK,CAAC,YAAU,gBAAc,aAAW,mBAAiB,kBAAgB,iBAAe,2BAAyB,WAAS,EAA8C,CAAC,EAAM,GAAU,GAAU,CAInI,EAAW,EAAxF,EAAyB,MAAM,CAAC,kBAAgB,CAAC,CA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