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

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

2 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as t,b as a}from"./chunks/BlockEditorTranslator.js?ver=1.3.26";import{a as C}from"./chunks/index5.js?ver=1.3.26";import{S as I}from"./chunks/SelectVariationModal.js?ver=1.3.26";import{E as w}from"./chunks/EditorPanel.js?ver=1.3.26";import{E as b}from"./chunks/EditorPanelRow.js?ver=1.3.26";import{E as B}from"./chunks/ErrorBoundary.js?ver=1.3.26";import{u as K}from"./chunks/SingleProductContext.js?ver=1.3.26";import{x as T}from"./chunks/Icons.js?ver=1.3.26";import{a as U}from"./chunks/add-query-args.js?ver=1.3.26";import"./chunks/ProductListItem.js?ver=1.3.26";import"./chunks/index6.js?ver=1.3.26";const{InspectorControls:F}=wp.blockEditor,{TextControl:O,ToggleControl:M}=wp.components,L=({attributes:r,setAttributes:d,selectedProduct:p,setSelectedProduct:S,selectedVariations:n,setSelectedVariations:u,sku:f,isInsideProductInfo:v=!1})=>t.jsx(F,{children:t.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-sku",children:t.jsx("div",{className:"fct-inspector-control-group",children:t.jsxs("div",{className:"fct-inspector-control-body",children:[t.jsx(w,{title:a("SKU Settings"),children:t.jsxs(b,{className:"flex-col",children:[t.jsx(M,{label:a("Show Label"),checked:r.show_label,onChange:e=>d({show_label:e})}),r.show_label&&t.jsx(O,{label:a("Label Text"),value:r.label,onChange:e=>d({label:e})}),f&&t.jsxs("div",{className:"fct-product-sku-info",children:[t.jsxs("strong",{children:[a("Current SKU"),":"]})," ",f]})]})}),!v&&t.jsx(w,{title:a("Product"),children:t.jsxs(b,{className:"flex-col",children:[t.jsx("p",{children:a("Select a specific product variation for this button.","fluent-cart")}),t.jsx(I,{preSelectedVariations:n,onModalClosed:e=>{if(!e||Object.keys(e).length===0){d({variant_id:"",product_id:""}),u({}),S({});return}const o=Object.values(e)[0],g=String((o==null?void 0:o.id)??""),s=String((o==null?void 0:o.post_id)??"");d({variant_id:g,product_id:s}),u({...e})},selectedVariations:n,setSelectedVariations:u,button:!0,isMultiple:!1}),Object.keys(n).length>0&&t.jsxs("div",{className:"fct-selected-products",children:[t.jsx("span",{className:"fct-selected-products__label",children:a("Selected Variation")}),t.jsx("div",{className:"fct-selected-products__list",children:t.jsxs("div",{className:"fct-product-chip-group",children:[(p==null?void 0:p.post_title)&&t.jsx("span",{className:"fct-product-chip fct-product-chip--parent",children:p.post_title}),Object.values(n).map(e=>t.jsx("span",{className:"fct-variation-chip",children:e.variation_title||e.title},e.id))]})}),t.jsxs("div",{className:"fct-selected-products__preview",children:[t.jsxs("strong",{children:[a("SKU"),":"]}),f||a("N/A")]})]})]})})]})})})}),{useBlockProps:R}=wp.blockEditor,{registerBlockType:q}=wp.blocks,{useEffect:k,useState:y,useMemo:z}=wp.element,{useSelect:W}=wp.data,{store:H}=wp.blockEditor,j=window.fluent_cart_product_sku_data,N=window.fluentCartRestVars.rest;q(j.slug+"/"+j.name,{apiVersion:3,title:j.title,description:j.description,icon:{src:T},category:"fluent-cart",example:{attributes:{show_label:!0,label:"SKU:"}},attributes:{product_id:{type:["string","number"],default:""},variant_id:{type:["string","number"],default:""},show_label:{type:"boolean",default:!0},label:{type:"string",default:a("SKU:")},query_type:{type:"string",default:"default"},inside_product_info:{type:"string",default:"-"}},edit:({attributes:r,setAttributes:d,clientId:p})=>{const S=R({className:"fct-product-sku"}),[n,u]=y({}),[f,v]=y({}),e=K(),o=W(s=>{const{getBlockParents:l,getBlockName:_}=s(H);return l(p).some(c=>{const i=_(c);return["fluent-cart/product-info","fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-carousel"].includes(i)})},[p]);k(()=>{d({inside_product_info:o?"yes":"no",...o?{}:{query_type:"custom"}})},[o]),k(()=>{o||r.product_id&&C({path:U(N.url+"/products/"+r.product_id,{with:["detail","variants"]}),headers:{"X-WP-Nonce":N.nonce}}).then(s=>{var _;const l=s.product||{};if(u(l),r.variant_id&&((_=l.variants)!=null&&_.length)){const m=String(r.variant_id),c=l.variants.find(i=>String(i.id)===m);c&&v({[m]:c})}})},[r.product_id]),k(()=>{e!=null&&e.product&&u(e.product)},[e==null?void 0:e.product]);const g=z(()=>{var l,_,m;if(!o&&r.variant_id){const c=String(r.variant_id),i=Object.values(f).find(x=>String(x.id)===c);if(i!=null&&i.sku)return i.sku;const h=n!=null&&n.variants?n:null;if((l=h==null?void 0:h.variants)!=null&&l.length){const x=h.variants.find(E=>String(E.id)===c);if(x!=null&&x.sku)return x.sku}}const s=n!=null&&n.variants?n:e==null?void 0:e.product;if((_=s==null?void 0:s.variants)!=null&&_.length){const c=(m=s==null?void 0:s.detail)==null?void 0:m.default_variation_id,i=c&&s.variants.find(h=>h.id===c)||s.variants[0];return(i==null?void 0:i.sku)||""}return""},[n,f,e==null?void 0:e.product,r.variant_id,o]);return t.jsx("div",{...S,children:t.jsxs(B,{children:[t.jsx(L,{attributes:r,setAttributes:d,selectedProduct:n,setSelectedProduct:u,selectedVariations:f,setSelectedVariations:v,sku:g,isInsideProductInfo:o}),t.jsxs("div",{className:"fct-product-sku__preview",children:[r.show_label&&t.jsxs("span",{className:"fct-product-sku__label",children:[r.label||a("SKU:")," "]}),t.jsx("span",{className:"fct-product-sku__value",children:g||a("N/A")})]})]})})},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