PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.25
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.25
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 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / assets / SaleBadgeBlockEditor.js

SaleBadgeBlockEditor.js in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.25, at assets/SaleBadgeBlockEditor.js

2 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as a,b as o}from"./chunks/BlockEditorTranslator.js?ver=1.3.25";import{a as D}from"./chunks/index5.js?ver=1.3.25";import{S as M}from"./chunks/SelectProductModal.js?ver=1.3.25";import{E as b}from"./chunks/EditorPanel.js?ver=1.3.25";import{E as v}from"./chunks/EditorPanelRow.js?ver=1.3.25";import{u as R}from"./chunks/SingleProductContext.js?ver=1.3.25";import{T as V}from"./chunks/Icons.js?ver=1.3.25";import{E as $}from"./chunks/ErrorBoundary.js?ver=1.3.25";import{a as F}from"./chunks/add-query-args.js?ver=1.3.25";import"./chunks/ProductListItem.js?ver=1.3.25";import"./chunks/index6.js?ver=1.3.25";const{InspectorControls:I}=wp.blockEditor,{TextControl:w,ToggleControl:z,SelectControl:S,PanelBody:ne}=wp.components,L=({attributes:e,setAttributes:s,selectedProduct:r,setSelectedProduct:i,isInsideProductInfo:l,isInsideVisualContainer:c,saleInfo:n})=>a.jsx(I,{children:a.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--sale-badge",children:a.jsx("div",{className:"fct-inspector-control-group",children:a.jsxs("div",{className:"fct-inspector-control-body",children:[a.jsx(b,{title:o("Badge Settings"),children:a.jsxs(v,{className:"flex-col",children:[a.jsx(w,{label:o("Badge Text"),value:e.badge_text,onChange:t=>s({badge_text:t}),help:o("Text shown when not using percentage mode.")}),a.jsx(z,{label:o("Show Discount Percentage"),checked:e.show_percentage,onChange:t=>s({show_percentage:t})}),e.show_percentage&&a.jsx(w,{label:o("Percentage Format"),value:e.percentage_text,onChange:t=>s({percentage_text:t}),help:o('Use {percent} as placeholder. E.g., "-{percent}% OFF"')}),a.jsx(S,{label:o("Price Source"),value:e.price_source,options:[{label:o("Default Variant"),value:"default_variant"},{label:o("Best Discount (All Variants)"),value:"best_discount"}],onChange:t=>s({price_source:t}),help:o("Where to check the sale price from.")}),n&&a.jsx("div",{className:`fct-sale-badge-status ${n.isOnSale?"fct-sale-badge-status--on-sale":"fct-sale-badge-status--not-on-sale"}`,children:n.isOnSale?`${o("On Sale")} — ${n.discountPercent}% ${o("discount")}`:o("Product is not on sale")})]})}),c&&a.jsx(b,{title:o("Position & Style"),children:a.jsxs(v,{className:"flex-col",children:[a.jsx(S,{label:o("Badge Style"),value:e.badge_style,options:[{label:o("Badge"),value:"badge"},{label:o("Ribbon"),value:"ribbon"},{label:o("Tag"),value:"tag"}],onChange:t=>s({badge_style:t})}),a.jsx(S,{label:o("Position"),value:e.badge_position,options:[{label:o("Top Left"),value:"top-left"},{label:o("Top Right"),value:"top-right"},{label:o("Bottom Left"),value:"bottom-left"},{label:o("Bottom Right"),value:"bottom-right"}],onChange:t=>s({badge_position:t})})]})}),!l&&a.jsx(b,{title:o("Product"),children:a.jsxs(v,{className:"flex-col",children:[a.jsx(M,{onModalClosed:t=>{s({product_id:t!=null&&t.ID?String(t.ID):""}),i(t)},selectedProduct:r,setSelectedProduct:i,isMultiple:!1}),(r==null?void 0:r.post_title)&&a.jsxs("div",{className:"fct-selected-products",children:[a.jsx("span",{className:"fct-selected-products__label",children:o("Selected Product")}),a.jsx("div",{className:"fct-selected-products__list",children:a.jsx("div",{className:"fct-product-chip-group",children:a.jsx("span",{className:"fct-product-chip fct-product-chip--parent",children:r.post_title})})})]})]})})]})})})}),{useBlockProps:W}=wp.blockEditor,{registerBlockType:Q}=wp.blocks,{useEffect:k,useState:U,useMemo:X}=wp.element,{useSelect:B}=wp.data,{store:P}=wp.blockEditor,f=window.fluent_cart_sale_badge_data;var N;const u=(N=window.fluentCartRestVars)==null?void 0:N.rest,q=(e,s)=>{var l,c;if(!((l=e==null?void 0:e.variants)!=null&&l.length))return{isOnSale:!1,discountPercent:0};if(s==="default_variant"){const n=(c=e==null?void 0:e.detail)==null?void 0:c.default_variation_id,t=n&&e.variants.find(p=>p.id===n)||e.variants[0];return t&&t.compare_price>t.item_price&&t.compare_price>0?{isOnSale:!0,discountPercent:Math.round((t.compare_price-t.item_price)/t.compare_price*100)}:{isOnSale:!1,discountPercent:0}}let r=0,i=!1;for(const n of e.variants)if(n.compare_price>n.item_price&&n.compare_price>0){i=!0;const t=Math.round((n.compare_price-n.item_price)/n.compare_price*100);t>r&&(r=t)}return{isOnSale:i,discountPercent:r}};Q(f.slug+"/"+f.name,{apiVersion:3,title:f.title,description:f.description,icon:{src:V},category:"fluent-cart",attributes:{badge_text:{type:"string",default:"Sale!"},show_percentage:{type:"boolean",default:!1},percentage_text:{type:"string",default:"-{percent}%"},price_source:{type:"string",default:"default_variant"},badge_style:{type:"string",default:"badge"},badge_position:{type:"string",default:"top-left"},product_id:{type:["string","number"],default:""}},edit:({attributes:e,setAttributes:s,clientId:r})=>{var y;const i=W(),[l,c]=U({}),n=R(),t=B(d=>{const{getBlockParents:m,getBlockName:_}=d(P);return m(r).some(h=>{const x=_(h);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel","fluent-cart/product-image"].includes(x)})},[r]),p=B(d=>{const{getBlockParents:m,getBlockName:_}=d(P);return m(r).some(h=>{const x=_(h);return["fluent-cart/product-image","fluent-cart/shopapp-product-image","fluent-cart/products"].includes(x)})},[r]),C=()=>{u!=null&&u.url&&D({path:F(u.url+"/products/"+e.product_id,{with:["detail","variants"]}),headers:{"X-WP-Nonce":u==null?void 0:u.nonce}}).then(d=>{c((d==null?void 0:d.product)||{})}).catch(()=>{c({})})};k(()=>{n!=null&&n.product?c(n.product):!t&&e.product_id?C():c({})},[e.product_id,n==null?void 0:n.product]),k(()=>{p&&!e.badge_position?s({badge_position:"top-left"}):!p&&e.badge_position&&s({badge_position:""})},[p]);const g=X(()=>q(l,e.price_source),[l,e.price_source]),E=()=>e.show_percentage&&g.discountPercent>0?e.percentage_text.replace("{percent}",g.discountPercent):e.badge_text||"Sale!",T=["fct-sale-badge",`fct-sale-badge--${e.badge_style||"badge"}`,p?`fct-sale-badge--${e.badge_position||"top-left"}`:""].filter(Boolean).join(" "),j=(l==null?void 0:l.ID)||((y=l==null?void 0:l.variants)==null?void 0:y.length);return a.jsx("div",{...i,children:a.jsxs($,{children:[a.jsx(L,{attributes:e,setAttributes:s,selectedProduct:l,setSelectedProduct:c,isInsideProductInfo:t,isInsideVisualContainer:p,saleInfo:g}),a.jsx("span",{className:T,style:j&&!g.isOnSale?{opacity:.4}:{},children:E()}),j&&!g.isOnSale&&a.jsx("small",{style:{display:"block",color:"#999",fontSize:"11px",marginTop:"4px"},children:o("Product is not on sale")})]})})},save:function(){return null},supports:{html:!1,align:["left","center","right"],color:{text:!0,background:!0,gradients:!0},typography:{fontSize:!0,__experimentalFontWeight:!0,__experimentalLetterSpacing:!0,__experimentalTextTransform:!0,__experimentalDefaultControls:{fontSize:!0}},spacing:{margin:!0,padding:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},shadow:!0}});
2