PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.2
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 / ProductPackageDescriptionBlockEditor.js

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

2 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as e,b as r}from"./chunks/BlockEditorTranslator.js?ver=1.5.2";import{a as I}from"./chunks/index5.js?ver=1.5.2";import{E as T}from"./chunks/EditorPanel.js?ver=1.5.2";import{E as R}from"./chunks/EditorPanelRow.js?ver=1.5.2";import{E as z}from"./chunks/ErrorBoundary.js?ver=1.5.2";import{u as q}from"./chunks/SingleProductContext.js?ver=1.5.2";import{y as H}from"./chunks/Icons.js?ver=1.5.2";const{InspectorControls:L}=wp.blockEditor,{ToggleControl:w}=wp.components,M=({attributes:n,setAttributes:a,packageData:c})=>e.jsx(L,{children:e.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--package-description",children:e.jsx("div",{className:"fct-inspector-control-group",children:e.jsx("div",{className:"fct-inspector-control-body",children:e.jsx(T,{title:r("Display Settings"),children:e.jsxs(R,{className:"flex-col",children:[e.jsx(w,{label:r("Show Name"),checked:n.show_name,onChange:l=>a({show_name:l})}),e.jsx(w,{label:r("Show Dimensions"),checked:n.show_dimensions,onChange:l=>a({show_dimensions:l})}),e.jsx(w,{label:r("Show Product Weight"),checked:n.show_product_weight,onChange:l=>a({show_product_weight:l})}),e.jsx(w,{label:r("Show Total Weight"),checked:n.show_total_weight,onChange:l=>a({show_total_weight:l})}),c&&e.jsxs("div",{className:"fct-package-info-preview",children:[e.jsxs("strong",{children:[r("Current Package"),":"]})," ",c.name||r("N/A")]})]})})})})})}),{useBlockProps:U}=wp.blockEditor,{registerBlockType:X}=wp.blocks,{useEffect:N,useState:W,useMemo:C}=wp.element,{useSelect:G}=wp.data,{store:J}=wp.blockEditor,x=window.fluent_cart_product_package_description_data,F=window.fluentCartRestVars.rest;function P(n){const a=[n.length,n.width,n.height].filter(c=>c!==""&&c!==null&&c!==void 0);return a.length?a.join(" × ")+" "+(n.dimension_unit||"cm"):""}X(x.slug+"/"+x.name,{apiVersion:3,title:x.title,description:x.description,icon:{src:H},category:"fluent-cart",example:{attributes:{show_name:!0,show_dimensions:!0,show_product_weight:!0,show_total_weight:!0}},attributes:{show_name:{type:"boolean",default:!0},show_dimensions:{type:"boolean",default:!0},show_product_weight:{type:"boolean",default:!0},show_total_weight:{type:"boolean",default:!0},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"yes"}},edit:({attributes:n,setAttributes:a,clientId:c})=>{const l=U({className:"fct-package-description"}),[u,V]=W([]),s=q(),k=G(t=>{const{getBlockParents:d,getBlockName:i}=t(J);return d(c).some(g=>{const h=i(g);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel","fluent-cart/related-product","fluent-cart/product-template"].includes(h)})},[c]);N(()=>{a({inside_product_info:k?"yes":"no"})},[k]);const[B,y]=W(!1);N(()=>{I({path:F.url+"/shipping/packages",headers:{"X-WP-Nonce":F.nonce}}).then(t=>{V(t.packages||[]),y(!1)}).catch(()=>{y(!0)})},[]);const o=C(()=>{var h,m,b;if(!u.length)return null;const t=s==null?void 0:s.product;if(!((h=t==null?void 0:t.variants)!=null&&h.length))return null;const d=(m=t==null?void 0:t.detail)==null?void 0:m.default_variation_id,i=d&&t.variants.find(_=>_.id===d)||t.variants[0];if(!i)return null;const p=((b=i==null?void 0:i.other_info)==null?void 0:b.package_slug)||"";return p?u.find(_=>_.slug===p)||null:u.find(_=>_.is_default)||u[0]||null},[s==null?void 0:s.product,u]),f=C(()=>{var p,g,h;const t=s==null?void 0:s.product;if(!((p=t==null?void 0:t.variants)!=null&&p.length))return 0;const d=(g=t==null?void 0:t.detail)==null?void 0:g.default_variation_id,i=d&&t.variants.find(m=>m.id===d)||t.variants[0];return parseFloat(((h=i==null?void 0:i.other_info)==null?void 0:h.weight)||0)},[s==null?void 0:s.product])||0,v=o?parseFloat(o.weight||0):0,j=f+v,S=(o==null?void 0:o.weight_unit)||"kg",E=o&&(n.show_name&&o.name||n.show_dimensions&&(o.length||o.width||o.height)||n.show_product_weight&&f||n.show_total_weight&&j);return e.jsx("div",{...l,children:e.jsxs(z,{children:[e.jsx(M,{attributes:n,setAttributes:a,packageData:o}),!E&&e.jsx("table",{className:"fct-package-description__table fct-package-description__table--placeholder",role:"presentation",children:e.jsx("tbody",{children:e.jsxs("tr",{children:[e.jsx("th",{children:r("Package")}),e.jsx("td",{children:B?r("Failed to load"):r("N/A")})]})})}),E&&e.jsx("table",{className:"fct-package-description__table",role:"presentation",children:e.jsxs("tbody",{children:[n.show_name&&o.name&&e.jsxs("tr",{children:[e.jsx("th",{children:r("Package")}),e.jsx("td",{children:o.name})]}),n.show_dimensions&&P(o)&&e.jsxs("tr",{children:[e.jsx("th",{children:r("Dimensions")}),e.jsx("td",{children:P(o)})]}),n.show_product_weight&&f>0&&e.jsxs("tr",{children:[e.jsx("th",{children:r("Weight")}),e.jsx("td",{children:f+" "+S})]}),n.show_total_weight&&j>0&&v>0&&e.jsxs("tr",{children:[e.jsx("th",{children:r("Shipping Weight")}),e.jsx("td",{children:j+" "+S})]})]})})]})})},save:()=>null,supports:{html:!1,align:["left","center","right"],typography:{fontSize:!0,lineHeight:!0,__experimentalFontFamily:!0,__experimentalFontWeight:!0,__experimentalFontStyle:!0,__experimentalTextTransform:!0,__experimentalLetterSpacing:!0,__experimentalDefaultControls:{fontSize:!0}},color:{text:!0,background:!0},spacing:{margin:!0,padding:!0},__experimentalBorder:{color:!0,radius:!0,style:!0,width:!0},shadow:!0}});
2