# elasticpress/5.0.0/dist/js/features-script.js

ElasticPress, version 5.0.0. 1 lines.

- Page: https://pluginprobe.com/plugins/elasticpress/5.0.0/code/dist/js/features-script.js
- Raw: https://pluginprobe.com/plugins/elasticpress/5.0.0/raw/dist/js/features-script.js
- Modified: 2023-11-01T18:08:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elasticpress/5.0.0/code/dist/js/features-script.js#L10-L20`.

```javascript
!function(){"use strict";var e={5251:function(e,s,t){var n=t(9196),a=60103;if(s.Fragment=60107,"function"===typeof Symbol&&Symbol.for){var r=Symbol.for;a=r("react.element"),s.Fragment=r("react.fragment")}var i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l=Object.prototype.hasOwnProperty,o={key:!0,ref:!0,__self:!0,__source:!0};function c(e,s,t){var n,r={},c=null,u=null;for(n in void 0!==t&&(c=""+t),void 0!==s.key&&(c=""+s.key),void 0!==s.ref&&(u=s.ref),s)l.call(s,n)&&!o.hasOwnProperty(n)&&(r[n]=s[n]);if(e&&e.defaultProps)for(n in s=e.defaultProps)void 0===r[n]&&(r[n]=s[n]);return{$$typeof:a,type:e,key:c,ref:u,props:r,_owner:i.current}}s.jsx=c,s.jsxs=c},5893:function(e,s,t){e.exports=t(5251)},9196:function(e){e.exports=window.React}},s={};function t(n){var a=s[n];if(void 0!==a)return a.exports;var r=s[n]={exports:{}};return e[n](r,r.exports,t),r.exports}t.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(s,{a:s}),s},t.d=function(e,s){for(var n in s)t.o(s,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:s[n]})},t.o=function(e,s){return Object.prototype.hasOwnProperty.call(e,s)},function(){var e=window.wp.element,s=window.wp.i18n,n=window.wp.components,a=window.wp.data,r=window.wp.notices,i=t(5893);const l=(0,e.createContext)(),o=({children:s,title:t})=>{const{createNotice:o,removeNotice:c}=(0,a.useDispatch)(r.store),{notices:u}=(0,a.useSelect)((e=>({notices:e(r.store).getNotices()})),[]),d=(0,e.useMemo)((()=>({createNotice:o,removeNotice:c})),[o,c]);return(0,i.jsx)(l.Provider,{value:d,children:(0,i.jsxs)("div",{className:"ep-settings-page",children:[(0,i.jsxs)("div",{className:"ep-settings-page__wrap",children:[(0,i.jsx)("h1",{className:"ep-settings-page__title",children:t}),s]}),(0,i.jsx)(n.SnackbarList,{className:"ep-settings-page__snackbar-list",notices:u,onRemove:e=>c(e)})]})})},{apiUrl:c,epioLogoUrl:u,features:d,indexMeta:p,settings:g,settingsDraft:h,syncUrl:f}=window.epDashboard;var y=window.wp.apiFetch,m=t.n(y),_=window.lodash;const x=(0,e.createContext)(),b=({apiUrl:s,children:t,defaultSettings:n,epioLogoUrl:a,features:r,indexMeta:l,syncedSettings:o})=>{const[c,u]=(0,e.useState)(!1),[d,p]=(0,e.useState)(!!l),[g,h]=(0,e.useState)({...n}),[f,y]=(0,e.useState)({...o}),b=(0,e.useCallback)((e=>r.find((s=>s.slug===e))),[r]),v=(0,e.useMemo)((()=>!(0,_.isEqual)(g,f)),[g,f]),S=(0,e.useCallback)(((e,s,t)=>t&&e&&"0"!==e&&e!==s),[]),w=(0,e.useCallback)((e=>{const{slug:s,settingsSchema:t}=e;return t.some((e=>{if(!0!==g?.[s]?.active)return!1;const t=e.requires_sync,n=g?.[s]?.[e.key],a=o?.[s]?.[e.key];return S(n,a,t)}))}),[g,o,S]),j=(0,e.useMemo)((()=>r.reduce(((e,s)=>(w(s)&&e.push(s.slug),e)),[])),[r,w]),C=(0,e.useMemo)((()=>!!j.length),[j]),F={epioLogoUrl:a,features:r,featuresRequiringSync:j,getFeature:b,isBusy:c,isModified:v,isSyncing:d,setIsSyncing:p,isSyncRequired:C,resetSettings:()=>{h({...f})},saveSettings:async()=>{try{u(!0);const e=await m()({body:JSON.stringify(g),headers:{"Content-Type":"application/json"},method:"PUT",url:s});y(e.data)}finally{u(!1)}},savedSettings:f,syncedSettings:o,settings:g,setSettings:h,willSettingRequireSync:S};return(0,i.jsx)(x.Provider,{value:F,children:t})},v=()=>(0,e.useContext)(x);var S=window.wp.dom,w=({disabled:t,help:a,label:r,name:l,onChange:o,options:c,requiresFeature:u,requiresSync:d,syncedValue:p,type:g,value:h})=>{const{getFeature:f,isBusy:y,settings:m,willSettingRequireSync:_}=v(),x=a?(0,i.jsx)("span",{dangerouslySetInnerHTML:{__html:(0,S.safeHTML)(a)}}):null,b=c?c.map((e=>({value:e.value,label:(0,i.jsx)("span",{dangerouslySetInnerHTML:{__html:(0,S.safeHTML)(e.label)}})}))):[],w=!(!u||!0===m[u]?.active)&&f(u),j="active"===l?(0,s.__)("The %s feature must be enabled to use this feature.","elasticpress"):(0,s.__)("The %s feature must be enabled to use the following setting.","elasticpress"),C="active"===l?(0,s.__)("Enabling this feature requires re-syncing your content.","elasticpress"):(0,s.__)("A change to following setting requires re-syncing your content.","elasticpress"),F=y||t||w,T=_(h,p,d),M=e=>{o(e?"1":"0")},N=e=>{const s=e.map((e=>c.find((s=>s.label===e))?.value)).filter(Boolean).join(",");o(s)};return(0,i.jsxs)(i.Fragment,{children:[w?(0,i.jsx)(n.Notice,{isDismissible:!1,status:"active"===l?"error":"warning",children:(0,s.sprintf)(j,w.shortTitle)}):null,T?(0,i.jsx)(n.Notice,{isDismissible:!1,status:"warning",children:C}):null,(0,i.jsx)("div",{className:"ep-dashboard-control",children:(()=>{switch(g){case"checkbox":return(0,i.jsx)(n.CheckboxControl,{checked:"1"===h,help:x,label:r,onChange:M,disabled:F});case"hidden":return null;case"markup":return(0,i.jsx)(e.RawHTML,{children:(0,S.safeHTML)(r)});case"multiple":{const e=c.map((e=>e.label)),s=h.split(",").map((e=>c.find((s=>s.value===e))?.label)).filter(Boolean);return(0,i.jsx)(n.FormTokenField,{__experimentalExpandOnFocus:!0,__experimentalShowHowTo:!1,label:r,onChange:N,disabled:F,suggestions:e,value:s})}case"radio":return(0,i.jsx)(n.RadioControl,{help:x,label:r,onChange:o,options:b,disabled:F,selected:h});case"select":return(0,i.jsx)(n.SelectControl,{help:x,label:r,onChange:o,options:c,disabled:F,value:h});case"toggle":return(0,i.jsx)(n.ToggleControl,{checked:h,help:x,label:r,onChange:o,disabled:F});case"textarea":return(0,i.jsx)(n.TextareaControl,{help:x,label:r,onChange:o,disabled:F,value:h});default:return(0,i.jsx)(n.TextControl,{help:x,label:r,onChange:o,disabled:F,value:h,type:g})}})()})]})},j=({feature:e,settingsSchema:s})=>{const{getFeature:t,settings:n,setSettings:a,syncedSettings:r}=v(),{isAvailable:l}=t(e);return s.map((s=>{const{default:t,disabled:o,help:c,key:u,label:d,options:p,requires_feature:g,requires_sync:h,type:f}=s;let y="undefined"!==typeof n[e]?.[u]?n[e][u]:t;return"active"!==u||l||(y=!1),(0,i.jsx)(w,{disabled:o||!l,help:c,label:d,name:u,onChange:s=>((s,t)=>{a({...n,[e]:{...n[e],[s]:t}})})(u,s),options:p,syncedValue:r?.[e]?.[u],requiresFeature:g,requiresSync:h,type:f,value:y},u)}))},C=({feature:t})=>{const{epioLogoUrl:a,getFeature:r}=v(),{isPoweredByEpio:l,reqStatusCode:o,reqStatusMessages:c,settingsSchema:u,summary:d,title:p}=r(t);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("h3",{className:"ep-dashboard-heading",children:[(0,i.jsx)(e.RawHTML,{children:(0,S.safeHTML)(p)}),l?(0,i.jsx)("img",{alt:(0,s.__)("ElasticPress.io logo"),height:"20",src:a,width:"110"}):null]}),(0,i.jsx)("p",{dangerouslySetInnerHTML:{__html:(0,S.safeHTML)(d)}}),c.map(((e,s)=>(0,i.jsx)(n.Notice,{isDismissible:!1,status:2===o?"error":"warning",children:(0,i.jsx)("span",{dangerouslySetInnerHTML:{__html:(0,S.safeHTML)(e)}})},s))),(0,i.jsx)(j,{feature:t,settingsSchema:u})]})},F=({feature:e})=>{const{getFeature:t,featuresRequiringSync:n}=v(),{shortTitle:a,isAvailable:r}=t(e),l=r?"":(0,s.__)("Unavailable","elasticpress"),o=n.includes(e)?(0,s.__)("Sync required","elasticpress"):l;return(0,i.jsxs)("div",{className:"ep-feature-tab",children:[a,o?(0,i.jsx)("small",{className:"ep-feature-tab__status",children:o}):null]})},T=()=>{const{createNotice:t}=(0,e.useContext)(l),{features:a,isBusy:r,isModified:o,isSyncing:c,isSyncRequired:u,resetSettings:d,saveSettings:p,setIsSyncing:g}=v(),h=(0,e.useMemo)((()=>{const e=new URL(f);return e.searchParams.append("do_sync","features"),e.toString()}),[]),y=(0,s.__)("Could not save feature settings. Please try again.","elasticpress"),m=[{url:f,label:(0,s.__)("View sync status","elasticpress")}],_=(0,s.__)("Cannot save settings while a sync is in progress.","elasticpress"),x=(0,s.__)("Changes to feature settings discarded.","elasticpress"),b=[{url:h,label:(0,s.__)("Sync","elasticpress")}],S=(0,s.__)("If you choose to sync later some settings changes may not take effect until the sync is performed. Save and sync later?","elasticpress"),w=(0,s.__)("Saving these settings will begin re-syncing your content. Save and sync now?","elasticpress"),j=(0,s.__)("Feature settings saved. Starting sync…","elasticpress"),T=(0,s.__)("Feature settings saved.","elasticpress"),[M,N]=(0,e.useState)(!1),k=a.filter((e=>e.isVisible)).map((e=>({name:e.slug,title:(0,i.jsx)(F,{feature:e.slug})}))),L=e=>{if("is_syncing"===e.data)return t("error",_,{actions:m}),void g(!0);const n=`${(0,s.__)("ElasticPress: Could not save feature settings.","elasticpress")}\n${e.message}`;console.error(n),t("error",y)};return(0,i.jsxs)("form",{onReset:e=>{e.preventDefault(),d(),t("success",x)},onSubmit:async e=>{if(e.preventDefault(),!u||window.confirm(w)){N(!1);try{await p(),u?(t("success",j),window.location=h):t("success",T)}catch(e){L(e)}}},children:[(0,i.jsx)(n.Panel,{className:"ep-dashboard-panel",children:(0,i.jsxs)(n.PanelBody,{children:[c?(0,i.jsx)(n.Notice,{actions:m,isDismissible:!1,status:"warning",children:_}):null,(0,i.jsx)(n.TabPanel,{className:"ep-dashboard-tabs",orientation:"vertical",tabs:k,children:({name:e})=>(0,i.jsx)(C,{feature:e},e)})]})}),(0,i.jsxs)(n.Flex,{justify:"start",children:[(0,i.jsx)(n.FlexItem,{children:(0,i.jsx)(n.Button,{disabled:r||c,isBusy:r&&!M,type:"submit",variant:"primary",children:u?(0,s.__)("Save and sync now","elasticpress"):(0,s.__)("Save changes","elasticpress")})}),u?(0,i.jsx)(n.FlexItem,{children:(0,i.jsx)(n.Button,{disabled:r||c,isBusy:r&&M,onClick:async()=>{if(window.confirm(S)){N(!0);try{await p(!1),t("success",T,{actions:b})}catch(e){L(e)}}},type:"button",variant:"secondary",children:(0,s.__)("Save and sync later","elasticpress")})}):null,o?(0,i.jsx)(n.FlexItem,{children:(0,i.jsx)(n.Button,{disabled:r,type:"reset",variant:"tertiary",children:(0,s.__)("Discard changes","elasticpress")})}):null]})]})};const M=()=>(0,i.jsx)(o,{title:(0,s.__)("Features","elasticpress"),children:(0,i.jsxs)(b,{apiUrl:c,defaultSettings:h||g,epioLogoUrl:u,features:d,indexMeta:p,syncedSettings:g,syncUrl:f,children:[(0,i.jsx)("p",{children:(0,e.createInterpolateElement)((0,s.__)("ElasticPress Features add functionality to enhance search and queries on your site. You may choose to activate some or all of these Features depending on your needs. You can learn more about each Feature <a>here</a>.","elasticpress"),{a:(0,i.jsx)("a",{target:"_blank",href:"https://elasticpress.zendesk.com/hc/en-us/articles/16671825423501-Features",rel:"noreferrer"})})}),(0,i.jsx)(T,{})]})});if("function"===typeof e.createRoot){(0,e.createRoot)(document.getElementById("ep-dashboard")).render((0,i.jsx)(M,{}))}else(0,e.render)((0,i.jsx)(M,{}),document.getElementById("ep-dashboard"))}()}();
```
