PluginProbe
ElasticPress / 4.7.2
ElasticPress v4.7.2
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / dist / js / facets-meta-range-block-script.js

facets-meta-range-block-script.js in ElasticPress 4.7.2, at dist/js/facets-meta-range-block-script.js

1 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function(){"use strict";var e={5251:function(e,t,n){var s=n(9196),i=60103;if(t.Fragment=60107,"function"===typeof Symbol&&Symbol.for){var r=Symbol.for;i=r("react.element"),t.Fragment=r("react.fragment")}var o=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a=Object.prototype.hasOwnProperty,u={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,n){var s,r={},l=null,p=null;for(s in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(p=t.ref),t)a.call(t,s)&&!u.hasOwnProperty(s)&&(r[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===r[s]&&(r[s]=t[s]);return{$$typeof:i,type:e,key:l,ref:p,props:r,_owner:o.current}}t.jsx=l,t.jsxs=l},5893:function(e,t,n){e.exports=n(5251)},9196:function(e){e.exports=window.React}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e=window.wp.blocks,t=window.wp.primitives,s=n(5893),i=()=>(0,s.jsxs)(t.SVG,{version:"1.0",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:[(0,s.jsx)(t.Path,{d:"M 9 11 L 15 11 L 15 13 L 9 13 Z"}),(0,s.jsx)(t.Path,{d:"M18.5 11H17.5V13H18.5V11ZM20 13C20.5523 13 21 12.5523 21 12C21 11.4477 20.5523 11 20 11V13ZM16.5 9C16.5 8.44772 16.0523 8 15.5 8C14.9477 8 14.5 8.44772 14.5 9H16.5ZM8 9C8 8.44772 7.55228 8 7 8C6.44772 8 6 8.44772 6 9H8ZM6 15C6 15.5523 6.44772 16 7 16C7.55228 16 8 15.5523 8 15H6ZM14.5 15C14.5 15.5523 14.9477 16 15.5 16C16.0523 16 16.5 15.5523 16.5 15H14.5ZM18.5 13H20V11H18.5V13ZM6 9V15H8V9H6ZM14.5 9V15H16.5V9H14.5Z"}),(0,s.jsx)(t.Path,{d:"M4 11C3.44772 11 3 11.4477 3 12C3 12.5523 3.44772 13 4 13V11ZM4 13H7V11H4V13Z"})]}),r=JSON.parse('{"u2":"elasticpress/facet-meta-range"}'),o=window.wp.blockEditor,a=window.wp.components,u=window.wp.data,l=window.wp.i18n,p=()=>(0,s.jsx)(a.Placeholder,{children:(0,s.jsx)(a.Spinner,{})}),c=window.wp.element,h=({onChange:e,value:t})=>{const n=(0,u.useSelect)((e=>e("elasticpress").getMetaKeys())),i=(0,c.useMemo)((()=>[{label:(0,l.__)("Select key","elasticpress"),value:""},...n.map((e=>({label:e,value:e})))]),[n]);return(0,s.jsx)(a.SelectControl,{disabled:i.length<=1,help:(0,c.createInterpolateElement)((0,l.__)("This is the list of metadata fields indexed in Elasticsearch. If your desired field does not appear in this list please try to <a>sync your content</a>","elasticpress"),{a:(0,s.jsx)("a",{href:window.epBlocks.syncUrl})}),label:(0,l.__)("Filter by","elasticpress"),onChange:e,options:i,value:t})},f=n(9196),d=n.n(f),v="/Users/brians/git/react-slider/src/components/ReactSlider/ReactSlider.jsx";function m(){return m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},m.apply(this,arguments)}function g(e,t){return g=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},g(e,t)}function y(e){return e&&e.stopPropagation&&e.stopPropagation(),e&&e.preventDefault&&e.preventDefault(),!1}function b(e){return null==e?[]:Array.isArray(e)?e.slice():[e]}function x(e){return null!==e&&1===e.length?e[0]:e.slice()}function w(e){Object.keys(e).forEach((function(t){"undefined"!==typeof document&&document.addEventListener(t,e[t],!1)}))}function M(e,t){return C(function(e,t){var n=e;n<=t.min&&(n=t.min);n>=t.max&&(n=t.max);return n}(e,t),t)}function C(e,t){var n=(e-t.min)%t.step,s=e-n;return 2*Math.abs(n)>=t.step&&(s+=n>0?t.step:-t.step),parseFloat(s.toFixed(5))}var _=function(e){var t,n;function s(t){var n;(n=e.call(this,t)||this).onKeyUp=function(){n.onEnd()},n.onMouseUp=function(){n.onEnd(n.getMouseEventMap())},n.onTouchEnd=function(){n.onEnd(n.getTouchEventMap())},n.onBlur=function(){n.setState({index:-1},n.onEnd(n.getKeyDownEventMap()))},n.onMouseMove=function(e){n.setState({pending:!0});var t=n.getMousePosition(e),s=n.getDiffPosition(t[0]),i=n.getValueFromPosition(s);n.move(i)},n.onTouchMove=function(e){if(!(e.touches.length>1)){n.setState({pending:!0});var t=n.getTouchPosition(e);if("undefined"===typeof n.isScrolling){var s=t[0]-n.startPosition[0],i=t[1]-n.startPosition[1];n.isScrolling=Math.abs(i)>Math.abs(s)}if(n.isScrolling)n.setState({index:-1});else{var r=n.getDiffPosition(t[0]),o=n.getValueFromPosition(r);n.move(o)}}},n.onKeyDown=function(e){if(!(e.ctrlKey||e.shiftKey||e.altKey||e.metaKey))switch(n.setState({pending:!0}),e.key){case"ArrowLeft":case"ArrowDown":case"Left":case"Down":e.preventDefault(),n.moveDownByStep();break;case"ArrowRight":case"ArrowUp":case"Right":case"Up":e.preventDefault(),n.moveUpByStep();break;case"Home":e.preventDefault(),n.move(n.props.min);break;case"End":e.preventDefault(),n.move(n.props.max);break;case"PageDown":e.preventDefault(),n.moveDownByStep(n.props.pageFn(n.props.step));break;case"PageUp":e.preventDefault(),n.moveUpByStep(n.props.pageFn(n.props.step))}},n.onSliderMouseDown=function(e){if(!n.props.disabled&&2!==e.button){if(n.setState({pending:!0}),!n.props.snapDragDisabled){var t=n.getMousePosition(e);n.forceValueFromPosition(t[0],(function(e){n.start(e,t[0]),w(n.getMouseEventMap())}))}y(e)}},n.onSliderClick=function(e){if(!n.props.disabled&&n.props.onSliderClick&&!n.hasMoved){var t=n.getMousePosition(e),s=M(n.calcValue(n.calcOffsetFromPosition(t[0])),n.props);n.props.onSliderClick(s)}},n.createOnKeyDown=function(e){return function(t){n.props.disabled||(n.start(e),w(n.getKeyDownEventMap()),y(t))}},n.createOnMouseDown=function(e){return function(t){if(!n.props.disabled&&2!==t.button){n.setState({pending:!0});var s=n.getMousePosition(t);n.start(e,s[0]),w(n.getMouseEventMap()),y(t)}}},n.createOnTouchStart=function(e){return function(t){if(!(n.props.disabled||t.touches.length>1)){n.setState({pending:!0});var s=n.getTouchPosition(t);n.startPosition=s,n.isScrolling=void 0,n.start(e,s[0]),w(n.getTouchEventMap()),function(e){e.stopPropagation&&e.stopPropagation()}(t)}}},n.handleResize=function(){var e=window.setTimeout((function(){n.pendingResizeTimeouts.shift(),n.resize()}),0);n.pendingResizeTimeouts.push(e)},n.renderThumb=function(e,t){var s=n.props.thumbClassName+" "+n.props.thumbClassName+"-"+t+" "+(n.state.index===t?n.props.thumbActiveClassName:""),i={ref:function(e){n["thumb"+t]=e},key:n.props.thumbClassName+"-"+t,className:s,style:e,onMouseDown:n.createOnMouseDown(t),onTouchStart:n.createOnTouchStart(t),onFocus:n.createOnKeyDown(t),tabIndex:0,role:"slider","aria-orientation":n.props.orientation,"aria-valuenow":n.state.value[t],"aria-valuemin":n.props.min,"aria-valuemax":n.props.max,"aria-label":Array.isArray(n.props.ariaLabel)?n.props.ariaLabel[t]:n.props.ariaLabel,"aria-labelledby":Array.isArray(n.props.ariaLabelledby)?n.props.ariaLabelledby[t]:n.props.ariaLabelledby},r={index:t,value:x(n.state.value),valueNow:n.state.value[t]};return n.props.ariaValuetext&&(i["aria-valuetext"]="string"===typeof n.props.ariaValuetext?n.props.ariaValuetext:n.props.ariaValuetext(r)),n.props.renderThumb(i,r)},n.renderTrack=function(e,t,s){var i={key:n.props.trackClassName+"-"+e,className:n.props.trackClassName+" "+n.props.trackClassName+"-"+e,style:n.buildTrackStyle(t,n.state.upperBound-s)},r={index:e,value:x(n.state.value)};return n.props.renderTrack(i,r)};var s=b(t.value);s.length||(s=b(t.defaultValue)),n.pendingResizeTimeouts=[];for(var i=[],r=0;r<s.length;r+=1)s[r]=M(s[r],t),i.push(r);return n.state={index:-1,upperBound:0,sliderLength:0,value:s,zIndices:i},n}n=e,(t=s).prototype=Object.create(n.prototype),t.prototype.constructor=t,g(t,n);var i=s.prototype;return i.componentDidMount=function(){"undefined"!==typeof window&&(window.addEventListener("resize",this.handleResize),this.resize())},s.getDerivedStateFromProps=function(e,t){var n=b(e.value);return n.length?t.pending?null:{value:n.map((function(t){return M(t,e)}))}:null},i.componentDidUpdate=function(){0===this.state.upperBound&&this.resize()},i.componentWillUnmount=function(){this.clearPendingResizeTimeouts(),"undefined"!==typeof window&&window.removeEventListener("resize",this.handleResize)},i.onEnd=function(e){e&&function(e){Object.keys(e).forEach((function(t){"undefined"!==typeof document&&document.removeEventListener(t,e[t],!1)}))}(e),this.hasMoved&&this.fireChangeEvent("onAfterChange"),this.setState({pending:!1}),this.hasMoved=!1},i.getValue=function(){return x(this.state.value)},i.getClosestIndex=function(e){for(var t=Number.MAX_VALUE,n=-1,s=this.state.value,i=s.length,r=0;r<i;r+=1){var o=this.calcOffset(s[r]),a=Math.abs(e-o);a<t&&(t=a,n=r)}return n},i.getMousePosition=function(e){return[e["page"+this.axisKey()],e["page"+this.orthogonalAxisKey()]]},i.getTouchPosition=function(e){var t=e.touches[0];return[t["page"+this.axisKey()],t["page"+this.orthogonalAxisKey()]]},i.getKeyDownEventMap=function(){return{keydown:this.onKeyDown,keyup:this.onKeyUp,focusout:this.onBlur}},i.getMouseEventMap=function(){return{mousemove:this.onMouseMove,mouseup:this.onMouseUp}},i.getTouchEventMap=function(){return{touchmove:this.onTouchMove,touchend:this.onTouchEnd}},i.getValueFromPosition=function(e){var t=e/(this.state.sliderLength-this.state.thumbSize)*(this.props.max-this.props.min);return M(this.state.startValue+t,this.props)},i.getDiffPosition=function(e){var t=e-this.state.startPosition;return this.props.invert&&(t*=-1),t},i.resize=function(){var e=this.slider,t=this.thumb0;if(e&&t){var n=this.sizeKey(),s=e.getBoundingClientRect(),i=e[n],r=s[this.posMaxKey()],o=s[this.posMinKey()],a=t.getBoundingClientRect()[n.replace("client","").toLowerCase()],u=i-a,l=Math.abs(r-o);this.state.upperBound===u&&this.state.sliderLength===l&&this.state.thumbSize===a||this.setState({upperBound:u,sliderLength:l,thumbSize:a})}},i.calcOffset=function(e){var t=this.props.max-this.props.min;return 0===t?0:(e-this.props.min)/t*this.state.upperBound},i.calcValue=function(e){return e/this.state.upperBound*(this.props.max-this.props.min)+this.props.min},i.calcOffsetFromPosition=function(e){var t=this.slider.getBoundingClientRect(),n=t[this.posMaxKey()],s=t[this.posMinKey()],i=e-(window["page"+this.axisKey()+"Offset"]+(this.props.invert?n:s));return this.props.invert&&(i=this.state.sliderLength-i),i-=this.state.thumbSize/2},i.forceValueFromPosition=function(e,t){var n=this,s=this.calcOffsetFromPosition(e),i=this.getClosestIndex(s),r=M(this.calcValue(s),this.props),o=this.state.value.slice();o[i]=r;for(var a=0;a<o.length-1;a+=1)if(o[a+1]-o[a]<this.props.minDistance)return;this.fireChangeEvent("onBeforeChange"),this.hasMoved=!0,this.setState({value:o},(function(){t(i),n.fireChangeEvent("onChange")}))},i.clearPendingResizeTimeouts=function(){do{var e=this.pendingResizeTimeouts.shift();clearTimeout(e)}while(this.pendingResizeTimeouts.length)},i.start=function(e,t){var n=this["thumb"+e];n&&n.focus();var s=this.state.zIndices;s.splice(s.indexOf(e),1),s.push(e),this.setState((function(n){return{startValue:n.value[e],startPosition:void 0!==t?t:n.startPosition,index:e,zIndices:s}}))},i.moveUpByStep=function(e){void 0===e&&(e=this.props.step);var t=M(this.state.value[this.state.index]+e,this.props);this.move(Math.min(t,this.props.max))},i.moveDownByStep=function(e){void 0===e&&(e=this.props.step);var t=M(this.state.value[this.state.index]-e,this.props);this.move(Math.max(t,this.props.min))},i.move=function(e){var t=this.state,n=t.index,s=t.value,i=s.length,r=s[n];if(e!==r){this.hasMoved||this.fireChangeEvent("onBeforeChange"),this.hasMoved=!0;var o=this.props,a=o.pearling,u=o.max,l=o.min,p=o.minDistance;if(!a){if(n>0){var c=s[n-1];e<c+p&&(e=c+p)}if(n<i-1){var h=s[n+1];e>h-p&&(e=h-p)}}s[n]=e,a&&i>1&&(e>r?(this.pushSucceeding(s,p,n),function(e,t,n,s){for(var i=0;i<e;i+=1){var r=s-i*n;t[e-1-i]>r&&(t[e-1-i]=r)}}(i,s,p,u)):e<r&&(this.pushPreceding(s,p,n),function(e,t,n,s){for(var i=0;i<e;i+=1){var r=s+i*n;t[i]<r&&(t[i]=r)}}(i,s,p,l))),this.setState({value:s},this.fireChangeEvent.bind(this,"onChange"))}},i.pushSucceeding=function(e,t,n){var s,i;for(i=e[s=n]+t;null!==e[s+1]&&i>e[s+1];i=e[s+=1]+t)e[s+1]=C(i,this.props)},i.pushPreceding=function(e,t,n){for(var s=n,i=e[s]-t;null!==e[s-1]&&i<e[s-1];i=e[s-=1]-t)e[s-1]=C(i,this.props)},i.axisKey=function(){return"vertical"===this.props.orientation?"Y":"X"},i.orthogonalAxisKey=function(){return"vertical"===this.props.orientation?"X":"Y"},i.posMinKey=function(){return"vertical"===this.props.orientation?this.props.invert?"bottom":"top":this.props.invert?"right":"left"},i.posMaxKey=function(){return"vertical"===this.props.orientation?this.props.invert?"top":"bottom":this.props.invert?"left":"right"},i.sizeKey=function(){return"vertical"===this.props.orientation?"clientHeight":"clientWidth"},i.fireChangeEvent=function(e){this.props[e]&&this.props[e](x(this.state.value),this.state.index)},i.buildThumbStyle=function(e,t){var n={position:"absolute",touchAction:"none",willChange:this.state.index>=0?this.posMinKey():"",zIndex:this.state.zIndices.indexOf(t)+1};return n[this.posMinKey()]=e+"px",n},i.buildTrackStyle=function(e,t){var n={position:"absolute",willChange:this.state.index>=0?this.posMinKey()+","+this.posMaxKey():""};return n[this.posMinKey()]=e,n[this.posMaxKey()]=t,n},i.buildMarkStyle=function(e){var t;return(t={position:"absolute"})[this.posMinKey()]=e,t},i.renderThumbs=function(e){for(var t=e.length,n=[],s=0;s<t;s+=1)n[s]=this.buildThumbStyle(e[s],s);for(var i=[],r=0;r<t;r+=1)i[r]=this.renderThumb(n[r],r);return i},i.renderTracks=function(e){var t=[],n=e.length-1;t.push(this.renderTrack(0,0,e[0]));for(var s=0;s<n;s+=1)t.push(this.renderTrack(s+1,e[s],e[s+1]));return t.push(this.renderTrack(n+1,e[n],this.state.upperBound)),t},i.renderMarks=function(){var e=this,t=this.props.marks,n=this.props.max-this.props.min+1;return"boolean"===typeof t?t=Array.from({length:n}).map((function(e,t){return t})):"number"===typeof t&&(t=Array.from({length:n}).map((function(e,t){return t})).filter((function(e){return e%t===0}))),t.map(parseFloat).sort((function(e,t){return e-t})).map((function(t){var n=e.calcOffset(t),s={key:t,className:e.props.markClassName,style:e.buildMarkStyle(n)};return e.props.renderMark(s)}))},i.render=function(){for(var e=this,t=[],n=this.state.value,s=n.length,i=0;i<s;i+=1)t[i]=this.calcOffset(n[i],i);var r=this.props.withTracks?this.renderTracks(t):null,o=this.renderThumbs(t),a=this.props.marks?this.renderMarks():null;return d().createElement("div",{ref:function(t){e.slider=t},style:{position:"relative"},className:this.props.className+(this.props.disabled?" disabled":""),onMouseDown:this.onSliderMouseDown,onClick:this.onSliderClick},r,o,a)},s}(d().Component);_.displayName="ReactSlider",_.defaultProps={min:0,max:100,step:1,pageFn:function(e){return 10*e},minDistance:0,defaultValue:0,orientation:"horizontal",className:"slider",thumbClassName:"thumb",thumbActiveClassName:"active",trackClassName:"track",markClassName:"mark",withTracks:!0,pearling:!1,disabled:!1,snapDragDisabled:!1,invert:!1,marks:[],renderThumb:function(e){return d().createElement("div",m({},e,{__self:_,__source:{fileName:v,lineNumber:353,columnNumber:31}}))},renderTrack:function(e){return d().createElement("div",m({},e,{__self:_,__source:{fileName:v,lineNumber:354,columnNumber:31}}))},renderMark:function(e){return d().createElement("span",m({},e,{__self:_,__source:{fileName:v,lineNumber:355,columnNumber:30}}))}},_.propTypes={};var k=_,S=({clearUrl:e,min:t,max:n,prefix:i,suffix:r,value:o,...a})=>(0,s.jsxs)("div",{className:"ep-range-facet",children:[(0,s.jsx)("div",{className:"ep-range-facet__slider",children:(0,s.jsx)(k,{className:"ep-range-slider",minDistance:1,thumbActiveClassName:"ep-range-slider__thumb--active",thumbClassName:"ep-range-slider__thumb",trackClassName:"ep-range-slider__track",min:t,max:n,value:o,...a})}),(0,s.jsxs)("div",{className:"ep-range-facet__values",children:[i,o[0],r,"",i,o[1],r]}),(0,s.jsxs)("div",{className:"ep-range-facet__action",children:[e?(0,s.jsx)("a",{href:e,children:(0,l.__)("Clear","elasticpress")}):null," ",(0,s.jsx)("button",{className:"wp-element-button",type:"submit",children:(0,l.__)("Filter","elasticpress")})]})]}),P={from:[{type:"block",blocks:["elasticpress/facet-meta"],transform:t=>(0,e.createBlock)("elasticpress/facet-meta-range",t)}]};(0,e.registerBlockType)(r.u2,{icon:i,edit:({attributes:t,name:n,setAttributes:r})=>{const{facet:c,prefix:f,suffix:d}=t,{title:v}=(0,e.getBlockType)(n),m=(0,o.useBlockProps)(),{min:g=!1,max:y=!1,isLoading:b=!1}=(0,u.useSelect)((e=>e("elasticpress").getMetaRange(c)||{isLoading:!0}),[c]),x=e=>{r({facet:e})};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.InspectorControls,{children:(0,s.jsxs)(a.PanelBody,{title:(0,l.__)("Settings","elasticpress"),children:[(0,s.jsx)(h,{onChange:x,value:c}),(0,s.jsxs)(a.Flex,{children:[(0,s.jsx)(a.FlexItem,{children:(0,s.jsx)(a.TextControl,{label:(0,l.__)("Value prefix","elasticpress"),onChange:e=>{r({prefix:e})},value:f})}),(0,s.jsx)(a.FlexItem,{children:(0,s.jsx)(a.TextControl,{label:(0,l.__)("Value suffix","elasticpress"),onChange:e=>{r({suffix:e})},value:d})})]})]})}),(0,s.jsx)("div",{...m,children:c?b?(0,s.jsx)(p,{}):!1!==g&&!1!==y?(0,s.jsx)(a.Disabled,{children:(0,s.jsx)(S,{min:g,max:y,prefix:f,suffix:d,value:[g,y]})}):(0,s.jsx)(o.Warning,{children:(0,l.sprintf)((0,l.__)('Preview unavailable. The "%s" field does not appear to contain numeric values. Select a new meta field key or populate the field with numeric values to enable filtering by range.',"elasticpress"),c)}):(0,s.jsx)(a.Placeholder,{icon:i,label:v,children:(0,s.jsx)(h,{onChange:x,value:c})})})]})},save:()=>{},transforms:P})}()}();