← Back
Editing: active-filters-frontend.js
var wc;(()=>{var e,t,r,s={2254:(e,t,r)=>{"use strict";var s=r(6087),o=r(7723);const i=window.wc.wcSettings,n=window.wc.wcTypes,l=(0,i.getSetting)("wcBlocksConfig",{pluginUrl:"",productCount:0,defaultAvatar:"",restApiRoutes:{},wordCountType:"words"}),a=l.pluginUrl+"assets/images/",c=(l.pluginUrl,i.STORE_PAGES.shop,i.STORE_PAGES.checkout,i.STORE_PAGES.checkout,i.STORE_PAGES.privacy,i.STORE_PAGES.privacy,i.STORE_PAGES.terms,i.STORE_PAGES.terms,i.STORE_PAGES.cart,i.STORE_PAGES.cart,i.STORE_PAGES.myaccount?.permalink?i.STORE_PAGES.myaccount.permalink:(0,i.getSetting)("wpLoginUrl","/wp-login.php"),(0,i.getSetting)("localPickupEnabled",!1),(0,i.getSetting)("shippingMethodsExist",!1),(0,i.getSetting)("shippingEnabled",!0),(0,i.getSettingWithCoercion)("countries",{},n.isObject)),u=(0,i.getSetting)("countryData",{}),d={...Object.fromEntries(Object.keys(u).filter(e=>!0===u[e].allowBilling).map(e=>{const t=c[e];return[e,(0,n.isString)(t)?t:""]})),...Object.fromEntries(Object.keys(u).filter(e=>!0===u[e].allowShipping).map(e=>{const t=c[e];return[e,(0,n.isString)(t)?t:""]}))},p=(Object.fromEntries(Object.keys(d).map(e=>[e,u[e].states||{}])),Object.fromEntries(Object.keys(d).map(e=>[e,u[e].locale||{}])),{address:["first_name","last_name","company","address_1","address_2","city","postcode","country","state","phone"],contact:["email"],order:[]});(0,i.getSetting)("addressFieldsLocations",p).address,(0,i.getSetting)("addressFieldsLocations",p).contact,(0,i.getSetting)("addressFieldsLocations",p).order,(0,i.getSetting)("additionalOrderFields",{}),(0,i.getSetting)("additionalContactFields",{}),(0,i.getSetting)("additionalAddressFields",{});var m=r(790);const g=({imageUrl:e=`${a}/block-error.svg`,header:t=(0,o.__)("Oops!","woocommerce"),text:r=(0,o.__)("There was an error loading the content.","woocommerce"),errorMessage:s,errorMessagePrefix:i=(0,o.__)("Error:","woocommerce"),button:n,showErrorBlock:l=!0})=>l?(0,m.jsxs)("div",{className:"wc-block-error wc-block-components-error",children:[e&&(0,m.jsx)("img",{className:"wc-block-error__image wc-block-components-error__image",src:e,alt:""}),(0,m.jsxs)("div",{className:"wc-block-error__content wc-block-components-error__content",children:[t&&(0,m.jsx)("p",{className:"wc-block-error__header wc-block-components-error__header",children:t}),r&&(0,m.jsx)("p",{className:"wc-block-error__text wc-block-components-error__text",children:r}),s&&(0,m.jsxs)("p",{className:"wc-block-error__message wc-block-components-error__message",children:[i?i+" ":"",s]}),n&&(0,m.jsx)("p",{className:"wc-block-error__button wc-block-components-error__button",children:n})]})]}):null;r(5893);class w extends s.Component{state={errorMessage:"",hasError:!1};static getDerivedStateFromError(e){return void 0!==e.statusText&&void 0!==e.status?{errorMessage:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("strong",{children:e.status}),": ",e.statusText]}),hasError:!0}:{errorMessage:e.message,hasError:!0}}render(){const{header:e,imageUrl:t,showErrorMessage:r=!0,showErrorBlock:s=!0,text:o,errorMessagePrefix:i,renderError:n,button:l}=this.props,{errorMessage:a,hasError:c}=this.state;return c?"function"==typeof n?n({errorMessage:a}):(0,m.jsx)(g,{showErrorBlock:s,errorMessage:r?a:null,header:e,imageUrl:t,text:o,errorMessagePrefix:i,button:l}):this.props.children}}const h=w,b=[".wp-block-woocommerce-cart"],f=({Block:e,container:t,attributes:r={},props:o={},errorBoundaryProps:i={}})=>{const n=()=>{(0,s.useEffect)(()=>{t.classList&&t.classList.remove("is-loading")},[]);const n=t.classList.contains("wp-block-woocommerce-checkout"),l=t.classList.contains("wp-block-woocommerce-cart");return n||l?(0,m.jsx)(h,{...i,children:(0,m.jsx)(e,{...o,attributes:r})}):(0,m.jsx)(h,{...i,children:(0,m.jsx)(s.Suspense,{fallback:(0,m.jsx)("div",{className:"wc-block-placeholder",children:"Loading..."}),children:e&&(0,m.jsx)(e,{...o,attributes:r})})})},l=(0,s.createRoot)(t);return l.render((0,m.jsx)(n,{})),l},_=({Block:e,containers:t,getProps:r=()=>({}),getErrorBoundaryProps:s=()=>({})})=>{if(0===t.length)return[];const o=[];return t.forEach((t,i)=>{const n=r(t,i),l=s(t,i),a={...t.dataset,...n.attributes||{}};o.push({container:t,root:f({Block:e,container:t,props:n,attributes:a,errorBoundaryProps:l})})}),o},y=window.wc.wcBlocksData,S=window.wp.data;var k=r(923),v=r.n(k);const j=(0,s.createContext)("page"),x=(j.Provider,(e,t,r)=>{const o=(0,s.useContext)(j);r=r||o;const i=(0,S.useSelect)(s=>s(y.QUERY_STATE_STORE_KEY).getValueForQueryKey(r,e,t),[r,e]),{setQueryValue:n}=(0,S.useDispatch)(y.QUERY_STATE_STORE_KEY);return[i,(0,s.useCallback)(t=>{n(r,e,t)},[r,e,n])]});var E=r(4921);const O=window.wc.blocksComponents,P=window.wp.url,A=(0,i.getSettingWithCoercion)("isRenderingPhpTemplate",!1,n.isBoolean);function C(e){if(A){const t=new URL(e);t.pathname=t.pathname.replace(/\/page\/[0-9]+/i,""),t.searchParams.delete("paged"),t.searchParams.forEach((e,r)=>{r.match(/^query(?:-[0-9]+)?-page$/)&&t.searchParams.delete(r)}),window.location.href=t.href}else window.history.replaceState({},"",e)}r(9300);const N=({children:e})=>(0,m.jsx)("div",{className:"wc-block-filter-title-placeholder",children:e});r(4756);const R=(0,i.getSetting)("attributes",[]).reduce((e,t)=>{const r=(s=t)&&s.attribute_name?{id:parseInt(s.attribute_id,10),name:s.attribute_name,taxonomy:"pa_"+s.attribute_name,label:s.attribute_label,orderby:s.attribute_orderby}:null;var s;return r&&r.id&&e.push(r),e},[]),L=window.wc.priceFormat;var B=r(1789),T=r(8533);const F=JSON.parse('{"uK":{"O":{"A":"list"},"F":{"A":3}}}'),M=(e,t)=>Number.isFinite(e)&&Number.isFinite(t)?(0,o.sprintf)(/* translators: %1$s min price, %2$s max price */ /* translators: %1$s min price, %2$s max price */ (0,o.__)("Between %1$s and %2$s","woocommerce"),(0,L.formatPrice)(e),(0,L.formatPrice)(t)):Number.isFinite(e)?(0,o.sprintf)(/* translators: %s min price */ /* translators: %s min price */ (0,o.__)("From %s","woocommerce"),(0,L.formatPrice)(e)):(0,o.sprintf)(/* translators: %s max price */ /* translators: %s max price */ (0,o.__)("Up to %s","woocommerce"),(0,L.formatPrice)(t)),Q=({type:e,name:t,prefix:r="",removeCallback:s=()=>null,showLabel:i=!0,displayStyle:n})=>{const l=r?(0,m.jsxs)(m.Fragment,{children:[r," ",t]}):t,a=(0,o.sprintf)(/* translators: 1: filter type, 2: attribute value used in the filter. For example: Remove Size Large filter. */ /* translators: 1: filter type, 2: attribute value used in the filter. For example: Remove Size Large filter. */ (0,o.__)("Remove %1$s %2$s filter","woocommerce"),e,t);return(0,m.jsxs)("li",{className:"wc-block-active-filters__list-item",children:[i&&(0,m.jsx)("span",{className:"wc-block-active-filters__list-item-type",children:e+": "}),"chips"===n?(0,m.jsx)(O.RemovableChip,{element:"span",text:l,onRemove:s,radius:"large",ariaLabel:a}):(0,m.jsxs)("span",{className:"wc-block-active-filters__list-item-name",children:[(0,m.jsxs)("button",{className:"wc-block-active-filters__list-item-remove",onClick:s,children:[(0,m.jsx)(B.A,{className:"wc-block-components-chip__remove-icon",icon:T.A,size:16}),(0,m.jsx)(O.Label,{screenReaderLabel:a})]}),l]})]},e+":"+t)},$=(...e)=>{if(!window)return;const t=window.location.href,r=(0,P.getQueryArgs)(t),s=(0,P.removeQueryArgs)(t,...Object.keys(r));e.forEach(e=>{if("string"==typeof e)return delete r[e];if("object"==typeof e){const t=Object.keys(e)[0],s=r[t].toString().split(",");r[t]=s.filter(r=>r!==e[t]).join(",")}});const o=Object.fromEntries(Object.entries(r).filter(([,e])=>e));C((0,P.addQueryArgs)(s,o))},G=["min_price","max_price","rating_filter","filter_","query_type_"],U=e=>{let t=!1;for(let r=0;G.length>r;r++){const s=G[r];if(s===e.substring(0,s.length)){t=!0;break}}return t};function q(e){const t=(0,s.useRef)(e);return v()(e,t.current)||(t.current=e),t.current}const K=window.wp.htmlEntities;var W=r(1303);const Y=({attributeObject:e,slugs:t=[],operator:r="in",displayStyle:l,isLoadingCallback:a})=>{const{results:c,isLoading:u}=(e=>{const{namespace:t,resourceName:r,resourceValues:i=[],query:l={},shouldSelect:a=!0}=e;if(!t||!r)throw new Error("The options object must have valid values for the namespace and the resource properties.");const c=(0,s.useRef)({results:[],isLoading:!0}),u=q(l),d=q(i),p=(()=>{const[,e]=(0,s.useState)();return(0,s.useCallback)(t=>{e(()=>{throw t})},[])})(),m=(0,S.useSelect)(e=>{if(!a)return null;const s=e(y.COLLECTIONS_STORE_KEY),i=[t,r,u,d],l=s.getCollectionError(...i);if(l)if((0,n.isError)(l))p(l);else{const e="object"==typeof l&&null!==l&&"string"==typeof l.message?l.message:(0,o.__)("Something went wrong while loading data.","woocommerce");p(new Error(e))}return{results:s.getCollection(...i),isLoading:!s.hasFinishedResolution("getCollection",i)}},[t,r,d,u,a,p]);return null!==m&&(c.current=m),c.current})({namespace:"/wc/store/v1",resourceName:"products/attributes/terms",resourceValues:[e.id]}),[d,p]=x("attributes",[]);if((0,s.useEffect)(()=>{a(u)},[u,a]),!Array.isArray(c)||!(0,n.isAttributeTermCollection)(c)||!(0,n.isAttributeQueryCollection)(d))return null;const g=e.label,w=(0,i.getSettingWithCoercion)("isRenderingPhpTemplate",!1,n.isBoolean);return(0,m.jsxs)("li",{children:[(0,m.jsxs)("span",{className:"wc-block-active-filters__list-item-type",children:[g,":"]}),(0,m.jsx)("ul",{children:t.map((t,s)=>{const i=c.find(e=>e.slug===t);if(!i)return null;let n="";return s>0&&"and"===r&&(n=(0,m.jsx)("span",{className:"wc-block-active-filters__list-item-operator",children:(0,o.__)("All","woocommerce")})),Q({type:g,name:(0,K.decodeEntities)(i.name||t),prefix:n,isLoading:u,removeCallback:()=>{const r=d.find(({attribute:t})=>t===`pa_${e.name}`);1===r?.slug.length?$(`query_type_${e.name}`,`filter_${e.name}`):$({[`filter_${e.name}`]:t}),w||((e=[],t,r,s="")=>{const o=e.filter(e=>e.attribute===r.taxonomy),i=o.length?o[0]:null;if(!(i&&i.slug&&Array.isArray(i.slug)&&i.slug.includes(s)))return;const n=i.slug.filter(e=>e!==s),l=e.filter(e=>e.attribute!==r.taxonomy);n.length>0&&(i.slug=n.sort(),l.push(i)),t((0,W.di)(l).asc("attribute"))})(d,p,e,t)},showLabel:!1,displayStyle:l})})})]})},D=({displayStyle:e,isLoading:t})=>t?(0,m.jsx)(m.Fragment,{children:[...Array("list"===e?2:3)].map((t,r)=>(0,m.jsx)("li",{className:"list"===e?"show-loading-state-list":"show-loading-state-chips",children:(0,m.jsx)("span",{className:"show-loading-state__inner"})},r))}):null,J=(0,s.createContext)({});(e=>{const t=Array.from(document.body.querySelectorAll(b.join(","))),{Block:r,getProps:s,getErrorBoundaryProps:o,selector:i,options:n={multiple:!0}}=e,l=(({Block:e,getProps:t,getErrorBoundaryProps:r,selector:s,wrappers:o,options:i})=>{let n=Array.from(document.body.querySelectorAll(s));return o&&o.length>0&&(n=n.filter(e=>!((e,t)=>t.some(t=>t.contains(e)&&!t.isSameNode(e)))(e,o))),!1===i?.multiple&&(n=n.slice(0,1)),_({Block:e,containers:n,getProps:t,getErrorBoundaryProps:r})})({Block:r,getProps:s,getErrorBoundaryProps:o,selector:i,options:n,wrappers:t});t.forEach(t=>{t.addEventListener("wc-blocks_render_blocks_frontend",()=>{(({Block:e,getProps:t,getErrorBoundaryProps:r,selector:s,wrapper:o,options:i})=>{let n=Array.from(o.querySelectorAll(s));!1===i?.multiple&&(n=n.slice(0,1)),_({Block:e,containers:n,getProps:t,getErrorBoundaryProps:r})})({...e,wrapper:t})})})})({selector:".wp-block-woocommerce-active-filters:not(.wp-block-woocommerce-filter-wrapper .wp-block-woocommerce-active-filters)",Block:({attributes:e,isEditor:t=!1})=>{const r=(()=>{const{wrapper:e}=(0,s.useContext)(J);return t=>{e&&e.current&&(e.current.hidden=!t)}})(),l=function(){const e=(0,s.useRef)(!1);return(0,s.useEffect)(()=>(e.current=!0,()=>{e.current=!1}),[]),(0,s.useCallback)(()=>e.current,[])}()(),a=(0,i.getSettingWithCoercion)("isRenderingPhpTemplate",!1,n.isBoolean),[c,u]=(0,s.useState)(!0),d=(()=>{if(!window)return!1;const e=window.location.href,t=(0,P.getQueryArgs)(e),r=Object.keys(t);let s=!1;for(let e=0;r.length>e;e++){const t=r[e];if(U(t)){s=!0;break}}return s})()&&!t&&c,[p,g]=x("attributes",[]),[w,h]=x("stock_status",[]),[b,f]=x("min_price"),[_,y]=x("max_price"),[S,k]=x("rating"),v=(0,i.getSetting)("stockStatusOptions",[]),j=(0,i.getSetting)("attributes",[]),A=(0,s.useMemo)(()=>{if(d||0===w.length||!(0,n.isStockStatusQueryCollection)(w)||!(0,n.isStockStatusOptions)(v))return null;const t=(0,o.__)("Stock Status","woocommerce");return(0,m.jsxs)("li",{children:[(0,m.jsxs)("span",{className:"wc-block-active-filters__list-item-type",children:[t,":"]}),(0,m.jsx)("ul",{children:w.map(r=>Q({type:t,name:v[r],removeCallback:()=>{if($({filter_stock_status:r}),!a){const e=w.filter(e=>e!==r);h(e)}},showLabel:!1,displayStyle:e.displayStyle}))})]})},[d,v,w,h,e.displayStyle,a]),L=(0,s.useMemo)(()=>d||!Number.isFinite(b)&&!Number.isFinite(_)?null:Q({type:(0,o.__)("Price","woocommerce"),name:M(b,_),removeCallback:()=>{$("max_price","min_price"),a||(f(void 0),y(void 0))},displayStyle:e.displayStyle}),[d,b,_,e.displayStyle,f,y,a]),B=(0,s.useMemo)(()=>!(0,n.isAttributeQueryCollection)(p)&&l||!p.length&&!(e=>{if(!window)return!1;const t=e.map(e=>`filter_${e.attribute_name}`),r=window.location.href,s=(0,P.getQueryArgs)(r),o=Object.keys(s);let i=!1;for(let e=0;o.length>e;e++){const r=o[e];if(t.includes(r)){i=!0;break}}return i})(j)?(c&&u(!1),null):p.map(t=>{const r=(e=>{if(e)return R.find(t=>t.taxonomy===e)})(t.attribute);return r?(0,m.jsx)(Y,{attributeObject:r,displayStyle:e.displayStyle,slugs:t.slug,operator:t.operator,isLoadingCallback:u},t.attribute):(c&&u(!1),null)}),[p,l,j,c,e.displayStyle]);(0,s.useEffect)(()=>{if(!a)return;if(S.length&&S.length>0)return;const e=(window?(0,P.getQueryArg)(window.location.href,"rating_filter"):null)?.toString();e&&k(e.split(","))},[a,S,k]);const T=(0,s.useMemo)(()=>{if(d||0===S.length||!(0,n.isRatingQueryCollection)(S))return null;const t=(0,o.__)("Rating","woocommerce");return(0,m.jsxs)("li",{children:[(0,m.jsxs)("span",{className:"wc-block-active-filters__list-item-type",children:[t,":"]}),(0,m.jsx)("ul",{children:S.map(r=>Q({type:t,name:(0,o.sprintf)(/* translators: %s is referring to the average rating value */ /* translators: %s is referring to the average rating value */ (0,o.__)("Rated %s out of 5","woocommerce"),r),removeCallback:()=>{if($({rating_filter:r}),!a){const e=S.filter(e=>e!==r);k(e)}},showLabel:!1,displayStyle:e.displayStyle}))})]})},[d,S,k,e.displayStyle,a]);if(!d&&!(p.length>0||w.length>0||S.length>0||Number.isFinite(b)||Number.isFinite(_))&&!t)return r(!1),null;const F=`h${e.headingLevel}`,G=(0,m.jsx)(F,{className:"wc-block-active-filters__title",children:e.heading}),q=d?(0,m.jsx)(N,{children:G}):G;if(!(0,i.getSettingWithCoercion)("hasFilterableProducts",!1,n.isBoolean))return r(!1),null;r(!0);const K=(0,E.A)("wc-block-active-filters__list",{"wc-block-active-filters__list--chips":"chips"===e.displayStyle,"wc-block-active-filters--loading":d});return(0,m.jsxs)(m.Fragment,{children:[!t&&e.heading&&q,(0,m.jsxs)("div",{className:"wc-block-active-filters",children:[(0,m.jsx)("ul",{className:K,children:t?(0,m.jsxs)(m.Fragment,{children:[Q({type:(0,o.__)("Size","woocommerce"),name:(0,o.__)("Small","woocommerce"),displayStyle:e.displayStyle}),Q({type:(0,o.__)("Color","woocommerce"),name:(0,o.__)("Blue","woocommerce"),displayStyle:e.displayStyle})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(D,{isLoading:d,displayStyle:e.displayStyle}),L,A,B,T]})}),d?(0,m.jsx)("span",{className:"wc-block-active-filters__clear-all-placeholder"}):(0,m.jsx)("button",{className:"wc-block-active-filters__clear-all",onClick:()=>{(()=>{if(!window)return;const e=window.location.href,t=(0,P.getQueryArgs)(e),r=(0,P.removeQueryArgs)(e,...Object.keys(t)),s=Object.fromEntries(Object.keys(t).filter(e=>!U(e)).map(e=>[e,t[e]]));C((0,P.addQueryArgs)(r,s))})(),a||(f(void 0),y(void 0),g([]),h([]),k([]))},children:(0,m.jsx)(O.Label,{label:(0,o.__)("Clear All","woocommerce"),screenReaderLabel:(0,o.__)("Clear All Filters","woocommerce")})})]})]})},getProps:e=>{return{attributes:(t=e.dataset,{heading:(0,n.isString)(t?.heading)?t.heading:"",headingLevel:(0,n.isString)(t?.headingLevel)&&parseInt(t.headingLevel,10)||F.uK.F.A,displayStyle:(0,n.isString)(t?.displayStyle)&&t.displayStyle||F.uK.O.A}),isEditor:!1};var t}})},5893:()=>{},9300:()=>{},4756:()=>{},790:e=>{"use strict";e.exports=window.ReactJSXRuntime},6087:e=>{"use strict";e.exports=window.wp.element},7723:e=>{"use strict";e.exports=window.wp.i18n},923:e=>{"use strict";e.exports=window.wp.isShallowEqual},5573:e=>{"use strict";e.exports=window.wp.primitives}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return s[e].call(r.exports,r,r.exports,i),r.exports}i.m=s,e=[],i.O=(t,r,s,o)=>{if(!r){var n=1/0;for(u=0;u<e.length;u++){for(var[r,s,o]=e[u],l=!0,a=0;a<r.length;a++)(!1&o||n>=o)&&Object.keys(i.O).every(e=>i.O[e](r[a]))?r.splice(a--,1):(l=!1,o<n&&(n=o));if(l){e.splice(u--,1);var c=s();void 0!==c&&(t=c)}}return t}o=o||0;for(var u=e.length;u>0&&e[u-1][2]>o;u--)e[u]=e[u-1];e[u]=[r,s,o]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,s){if(1&s&&(e=this(e)),8&s)return e;if("object"==typeof e&&e){if(4&s&&e.__esModule)return e;if(16&s&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var n={};t=t||[null,r({}),r([]),r(r)];for(var l=2&s&&e;"object"==typeof l&&!~t.indexOf(l);l=r(l))Object.getOwnPropertyNames(l).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,i.d(o,n),o},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.j=507,(()=>{var e={507:0};i.O.j=t=>0===e[t];var t=(t,r)=>{var s,o,[n,l,a]=r,c=0;if(n.some(t=>0!==e[t])){for(s in l)i.o(l,s)&&(i.m[s]=l[s]);if(a)var u=a(i)}for(t&&t(r);c<n.length;c++)o=n[c],i.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return i.O(u)},r=globalThis.webpackChunkwebpackWcBlocksFrontendJsonp=globalThis.webpackChunkwebpackWcBlocksFrontendJsonp||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var n=i.O(void 0,[763],()=>i(2254));n=i.O(n),(wc=void 0===wc?{}:wc)["active-filters"]=n})();
Save File
Cancel