PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.8.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.8.0
1.8.0 1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 All 52 releases
fluent-cart / assets / chunks / reviewBlockShared.js

reviewBlockShared.js in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.8.0, at assets/chunks/reviewBlockShared.js

2 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as r}from"./jsx-runtime.js?ver=1.8.0";import{E as W}from"./EditorPanel.js?ver=1.8.0";import{E as y}from"./EditorPanelRow.js?ver=1.8.0";import{S as F}from"./SelectProductModal.js?ver=1.8.0";import{b as a}from"./BlockEditorTranslator.js?ver=1.8.0";import{a as w}from"./index6.js?ver=1.8.0";import{a as T}from"./Icons.js?ver=1.8.0";import{a as k}from"./add-query-args.js?ver=1.8.0";import{u as q}from"./SingleProductContext.js?ver=1.8.0";const N=100,x="selected",L=e=>e==="custom"||e==="multiple"?x:e==="all"?"all":"default",S=e=>{const t=[];return(Array.isArray(e)?e:[]).forEach(s=>{const l=parseInt(s,10);l>0&&!t.includes(l)&&t.push(l)}),t.slice(0,N)},Q=e=>e.query_type==="custom"?S([e.product_id]):S(e.product_ids),O=e=>{const t=S(e);return t.length===1?{query_type:"custom",product_id:String(t[0]),product_ids:t}:{query_type:"multiple",product_ids:t}},X=(e,t)=>{if(e!==x)return{query_type:e};const s=S(t.product_ids);return O(s.length?s:[t.product_id])},G=(e,t)=>{const s={};return(Array.isArray(t)?t:[]).forEach(l=>{s[String(l.ID)]=l}),S(e).map(l=>s[String(l)]||{ID:l,isPlaceholder:!0})},{useEffect:U,useState:j}=wp.element,{Notice:b}=wp.components;var I;const C=((I=window.fluentCartRestVars)==null?void 0:I.rest)||{},M=e=>{var s;const t=((s=e==null?void 0:e.products)==null?void 0:s.data)||(e==null?void 0:e.products)||[];return Array.isArray(t)?t:[]},$=({productIds:e,onChange:t})=>{const[s,l]=j([]),[i,n]=j(!1),[u,c]=j(!1),p=e.join(",");U(()=>{const o=s.map(f=>String(f.ID)),d=e.every(f=>o.includes(String(f)));if(!e.length||d||!C.url){e.length||l([]);return}let m=!1;return n(!1),w({path:k(C.url+"/products/fetchProductsByIds",{productIds:e}),headers:{"X-WP-Nonce":C.nonce}}).then(f=>{m||l(M(f))}).catch(()=>{m||n(!0)}),()=>{m=!0}},[p]);const g=o=>{const d=(Array.isArray(o)?o:[]).filter(f=>f==null?void 0:f.ID),m=d.slice(0,N);c(d.length>m.length),l(m.filter(f=>!f.isPlaceholder)),t(m.map(f=>parseInt(f.ID,10)))},_=o=>{l(d=>d.filter(m=>String(m.ID)!==String(o))),t(e.filter(d=>String(d)!==String(o)))},v={};return s.forEach(o=>{v[String(o.ID)]=o.post_title}),r.jsxs(r.Fragment,{children:[r.jsx(F,{onSelectionConfirmed:g,selectedProduct:G(e,s),setSelectedProduct:()=>{},isMultiple:!0}),u&&r.jsx(b,{status:"warning",isDismissible:!1,children:a("Only the first %s products were kept.",N)}),i&&r.jsx(b,{status:"error",isDismissible:!1,children:a("Could not load the selected products. The saved selection is unchanged.")}),e.length?r.jsxs("div",{className:"fct-selected-products",children:[r.jsxs("span",{className:"fct-selected-products__label",children:[a("Selected products")," (",e.length,")"]}),r.jsx("ul",{className:"fct-review-selected-products",children:e.map(o=>{const d=v[String(o)]||a("Unavailable product");return r.jsxs("li",{className:"fct-review-selected-product",children:[r.jsx("span",{className:"fct-review-selected-product__title",title:d,children:d}),r.jsxs("span",{className:"fct-review-selected-product__id",children:["#",o]}),r.jsx("button",{type:"button",className:"fct-review-selected-product__remove","aria-label":a("Remove %s",d+" #"+o),onClick:()=>_(o),children:r.jsx(T,{})})]},o)})})]}):r.jsx("p",{className:"fct-review-preset-help",children:a("Select at least one product. Nothing is shown until you do.")})]})},{__experimentalToggleGroupControl:H,__experimentalToggleGroupControlOption:A,SelectControl:K}=wp.components,oe=({attributes:e,setAttributes:t,selectedProduct:s,setSelectedProduct:l,allowMultiProduct:i=!1,hasSingleProductChildren:n=!1})=>{const u=L(e.query_type);return r.jsxs(W,{title:a("Product"),children:[r.jsx(y,{children:i?r.jsx(K,{className:"fct-review-source-select",label:a("Show reviews from"),value:u,options:[{value:"default",label:a("Current product")},{value:x,label:a("Selected products")},{value:"all",label:a("All products")}],onChange:c=>{t(X(c,e))},__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0}):r.jsxs(H,{isBlock:!0,label:a("Query type"),value:e.query_type,onChange:c=>{t({query_type:c})},children:[r.jsx(A,{value:"default",label:a("Default")}),r.jsx(A,{value:"custom",label:a("Custom")})]})}),i&&u===x&&r.jsx(y,{className:"flex-col fct-review-product-picker",children:r.jsx($,{productIds:Q(e),onChange:c=>{t(O(c))}})}),i&&u==="all"&&r.jsx(y,{children:r.jsx("p",{className:"fct-review-preset-help",children:a("Approved reviews from every published product that takes reviews.")})}),i&&n&&u!=="default"&&r.jsx(y,{children:r.jsx("p",{className:"fct-review-preset-help",children:u==="all"?a("The rating summary combines every product. The Write a Review button and review form need a single product, so they are removed."):a("With two or more products, the rating summary combines them and the Write a Review button and review form are removed.")})}),!i&&e.query_type==="custom"&&r.jsxs(y,{className:"flex-col",children:[r.jsx(F,{onSelectionConfirmed:c=>{t({product_id:c!=null&&c.ID?String(c.ID):""})},selectedProduct:s,setSelectedProduct:l,isMultiple:!1}),(s==null?void 0:s.post_title)&&r.jsxs("div",{className:"fct-selected-products",children:[r.jsx("span",{className:"fct-selected-products__label",children:a("Selected Product")}),r.jsx("div",{className:"fct-selected-products__list",children:r.jsx("div",{className:"fct-product-chip-group",children:r.jsx("span",{className:"fct-product-chip fct-product-chip--parent",children:s.post_title})})})]})]})]})},{useEffect:P,useState:E}=wp.element,{useSelect:D}=wp.data,{store:R}=wp.blockEditor;var B;const h=((B=window.fluentCartRestVars)==null?void 0:B.rest)||{},ne=e=>D(t=>{const{getBlockParents:s,getBlockName:l}=t(R),i=["fluent-cart/product-reviews","fluent-cart/product-review-summary-group","fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel","fluent-cart/product-carousel-loop","fluent-cart/related-product","fluent-cart/product-template"];return s(e).some(n=>i.includes(l(n)))},[e]),ae=(e,t,s=!1)=>{const l=q(),[i,n]=E({}),[u,c]=E(null),p=(l==null?void 0:l.product)||null,g=!t&&e.query_type==="custom",_=t?(p==null?void 0:p.ID)||"":g?e.product_id:(p==null?void 0:p.ID)||"";return P(()=>{let v=!1;const o=()=>v;return g?e.product_id&&h.url?w({path:k(h.url+"/products/"+e.product_id,{with:["block_product_detail"]}),headers:{"X-WP-Nonce":h.nonce}}).then(d=>{o()||n(d.product||{})}).catch(()=>{o()||n({})}):n({}):n(p||{}),()=>{v=!0}},[p,g,e.product_id]),P(()=>{let v=!1;const o=()=>v;return s&&_&&h.url?w({path:h.url+"/public/reviews/"+_+"/summary",headers:{"X-WP-Nonce":h.nonce}}).then(d=>{o()||c(d.summary||null)}).catch(()=>{o()||c(null)}):c(null),()=>{v=!0}},[s,_]),{selectedProduct:i,setSelectedProduct:n,reviewSummary:u,effectiveProductId:_}},V=e=>e==="all"||e==="multiple",z=e=>{const t=D(l=>{const{getBlockParents:i,getBlockName:n}=l(R),u=i(e,!0);return u.find(c=>n(c)==="fluent-cart/product-reviews")||u.find(c=>n(c)==="fluent-cart/product-review-summary-group")||""},[e]),s=D(l=>t?l(R).getBlockAttributes(t):null,[t]);return s?{queryType:s.query_type||"default",productIds:Array.isArray(s.product_ids)?s.product_ids:[]}:null},ie=e=>{const t=z(e),s=!!t&&V(t.queryType);return{hidden:s,showNotice:s}},ue=(e,t)=>{const[s,l]=E({status:"idle",total:0}),i=(Array.isArray(t)?t:[]).join(","),n=e==="all"||e==="multiple"&&i!=="";return P(()=>{if(!n||!h.url){l({status:"idle",total:0});return}let u=!1;return l(c=>({...c,status:"loading"})),w({path:k(h.url+"/public/reviews/all",{per_page:1,product_ids:e==="multiple"?i:""}),headers:{"X-WP-Nonce":h.nonce},parse:!1}).then(c=>c.json()).then(c=>{var p;u||l({status:"ready",total:parseInt((p=c==null?void 0:c.reviews)==null?void 0:p.total,10)||0})}).catch(c=>{u||l({status:(c==null?void 0:c.status)===404?"unavailable":"error",total:0})}),()=>{u=!0}},[n,e,i]),s};export{oe as R,ae as a,ie as b,z as c,ue as d,V as i,ne as u};
2