{"version":3,"file":"PreserveCurrentQueryOnClick.DDt_FCx9.mjs","names":["useCallback"],"sources":["https:/framerusercontent.com/modules/cPk7aQQsZsiFC4o3fbWq/zyrZzvlEPYUSlmeniDHE/PreserveCurrentQueryOnClick.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useCallback}from\"react\";/**\n * User request: Create a Framer code override export named withPreserveCurrentQueryOnClick. It will be applied to an existing canvas button Frame that already has a Framer link to an internal path. The override must keep the canvas styling fully editable and only change click behavior. On click/tap, read the element's href if available (or the clicked anchor href), merge window.location.search query parameters into the destination URL without overwriting destination parameters that already exist, then navigate to that resulting URL. It should work for relative internal paths and absolute URLs. Respect modifier clicks / middle clicks / target _blank by not intercepting those. If there are no current query params, allow normal behavior. Export it as a Framer code override, not a code component. Keep the code robust for SSR by checking typeof window.\n */export function withPreserveCurrentQueryOnClick(Component){return /*#__PURE__*/forwardRef(function PreserveCurrentQueryOnClick(props,ref){const navigateWithMergedQuery=useCallback(event=>{if(typeof window===\"undefined\")return;const mouseEvent=event;const hasModifierKey=!!mouseEvent&&(mouseEvent.metaKey||mouseEvent.ctrlKey||mouseEvent.shiftKey||mouseEvent.altKey);const isMiddleClick=!!mouseEvent&&mouseEvent.button===1;const currentTarget=event?.currentTarget;const targetElement=event?.target;const clickedAnchor=targetElement?.closest?.(\"a\");const linkTarget=currentTarget?.target||clickedAnchor?.target||props.target;const opensNewTab=linkTarget===\"_blank\";if(hasModifierKey||isMiddleClick||opensNewTab)return;const currentSearch=window.location.search||\"\";if(!currentSearch||currentSearch===\"?\")return;const href=currentTarget?.href||clickedAnchor?.href||props.href||\"\";if(!href)return;let destination;try{destination=new URL(href,window.location.href);}catch{return;}const sourceParams=new URLSearchParams(currentSearch);sourceParams.forEach((_,key)=>{if(destination.searchParams.has(key))return;sourceParams.getAll(key).forEach(value=>{destination.searchParams.append(key,value);});});if(typeof event?.preventDefault===\"function\"){event.preventDefault();}window.location.assign(destination.toString());},[props]);const handleClickNavigate=useCallback(event=>{if(typeof props.onClick===\"function\")props.onClick(event);navigateWithMergedQuery(event);},[navigateWithMergedQuery,props]);const handleTapNavigate=useCallback(event=>{if(typeof props.onTap===\"function\")props.onTap(event);navigateWithMergedQuery(event);},[navigateWithMergedQuery,props]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:handleClickNavigate,onTap:handleTapNavigate});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withPreserveCurrentQueryOnClick\":{\"type\":\"reactHoc\",\"name\":\"withPreserveCurrentQueryOnClick\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PreserveCurrentQueryOnClick.map"],"mappings":"uIAEG,SAAgB,EAAgC,EAAU,CAAC,OAAoB,EAAW,SAAqC,EAAM,EAAI,CAAC,IAAM,EAAwBA,EAAY,GAAO,CAAC,GAAU,IAAS,OAAY,OAAO,IAAM,EAAW,EAAY,EAAe,CAAC,CAAC,IAAa,EAAW,SAAS,EAAW,SAAS,EAAW,UAAU,EAAW,QAAc,EAAc,CAAC,CAAC,GAAY,EAAW,SAAS,EAAQ,EAAc,GAAO,cAAsD,GAApB,GAAO,SAA0C,UAAU,IAAI,CAAmF,GAAjE,GAAe,QAAQ,GAAe,QAAQ,EAAM,UAAsC,SAAS,GAAG,GAAgB,GAAe,EAAY,OAAO,IAAM,EAAc,EAAO,SAAS,QAAQ,GAAG,GAAG,CAAC,GAAe,IAAgB,IAAI,OAAO,IAAM,EAAK,GAAe,MAAM,GAAe,MAAM,EAAM,MAAM,GAAG,GAAG,CAAC,EAAK,OAAO,IAAI,EAAY,GAAG,CAAC,EAAY,IAAI,IAAI,EAAK,EAAO,SAAS,KAAK,MAAO,CAAC,OAAQ,IAAM,EAAa,IAAI,gBAAgB,EAAc,CAAC,EAAa,SAAS,EAAE,IAAM,CAAI,EAAY,aAAa,IAAI,EAAI,EAAQ,EAAa,OAAO,EAAI,CAAC,QAAQ,GAA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