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.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 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / assets / ProductCarouselBlockEditor.js

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

2 lines 8.5 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 m}from"./chunks/BlockEditorTranslator.js?ver=1.5.2";import{h as O}from"./chunks/Icons.js?ver=1.5.2";import{a as U}from"./chunks/index5.js?ver=1.5.2";import{E as k}from"./chunks/EditorPanel.js?ver=1.5.2";import{E as u}from"./chunks/EditorPanelRow.js?ver=1.5.2";import"./chunks/CustomSelect.js?ver=1.5.2";import{S as V}from"./chunks/SelectProductModal.js?ver=1.5.2";import"./chunks/SingleProductContext.js?ver=1.5.2";import{P as H}from"./chunks/ProductContext.js?ver=1.5.2";import{a as Q}from"./chunks/add-query-args.js?ver=1.5.2";import"./chunks/index6.js?ver=1.5.2";import"./chunks/ProductListItem.js?ver=1.5.2";const{InspectorControls:W}=wp.blockEditor,{CheckboxControl:X}=wp.components,{RangeControl:I}=wp.components,{SelectControl:N,ToggleControl:E}=wp.components,$=({attributes:o,setAttributes:n,selectedProduct:i,setSelectedProduct:g,isInsideProductInfo:c})=>{const{carousel_settings:s}=o,{useEffect:y,useState:M}=wp.element;return y(()=>{},[o,i]),e.jsx(W,{children:e.jsx("div",{className:"fct-inspector-control-wrap fct-inspector-control-wrap--product-card",children:e.jsx("div",{className:"fct-inspector-control-group",children:e.jsxs("div",{className:"fct-inspector-control-body",children:[e.jsx(k,{title:m("Product"),children:!c&&e.jsxs(u,{className:"flex-col",children:[e.jsx(V,{onModalClosed:t=>{const x=Array.isArray(t)?t.filter(a=>a==null?void 0:a.ID):[],v=x.map(a=>a.ID);n({product_ids:v}),g(x)},selectedProduct:i,setSelectedProduct:g,isMultiple:!0}),Array.isArray(o.product_ids)&&o.product_ids.length>0&&i&&i.length>0&&e.jsxs("div",{className:"fct-selected-products",children:[e.jsx("span",{className:"fct-selected-products__label",children:m("Selected products")}),e.jsx("div",{className:"fct-selected-products__list",children:i.map(t=>e.jsx("span",{className:"fct-product-chip",children:t.post_title},t.ID))})]})]})}),e.jsx(k,{title:m("Layout"),children:e.jsxs(u,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:m("Slides per view")}),e.jsx(I,{value:s.slidesToShow,onChange:t=>n({carousel_settings:{...s,slidesToShow:t}}),min:1,max:6})]})}),e.jsxs(k,{title:m("Behavior"),children:[e.jsx("p",{className:"fct-panel-subtitle",children:m("Carousel interaction & animation")}),e.jsx(u,{children:e.jsx(N,{label:"Autoplay",value:s.autoplay,options:[{label:"Disabled",value:"no"},{label:"Always",value:"yes"},{label:"On Hover",value:"hover"}],onChange:t=>{n({carousel_settings:{...s,autoplay:t}})}})}),["yes","hover"].includes(s.autoplay)&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(I,{label:"Autoplay Delay (ms)",help:"Time between slides in milliseconds",value:s.autoplayDelay||3e3,min:300,max:1e4,step:100,onChange:t=>n({carousel_settings:{...s,autoplayDelay:t}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(E,{label:"Show arrows",checked:s.arrows==="yes",onChange:t=>n({carousel_settings:{...s,arrows:t?"yes":"no"}})})}),s.arrows==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(N,{label:"Arrow Size",value:s.arrowsSize,options:[{label:"Small",value:"sm"},{label:"Medium",value:"md"},{label:"Large",value:"lg"}],onChange:t=>n({carousel_settings:{...s,arrowsSize:t}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(E,{label:"Show Pagination",checked:s.pagination==="yes",onChange:t=>n({carousel_settings:{...s,pagination:t?"yes":"no"}})})}),s.pagination==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(N,{label:"Pagination Type",value:s.paginationType,options:[{label:"Bullets",value:"bullets"},{label:"Fraction",value:"fraction"},{label:"Progress Bar",value:"progress"},{label:"Segmented (Modern)",value:"segmented"}],onChange:t=>n({carousel_settings:{...s,paginationType:t}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(X,{label:m("Infinite loop"),checked:s.infinite==="yes",onChange:t=>n({carousel_settings:{...s,infinite:t?"yes":"no"}})})})]})]})})})})},q=""+new URL("assets/ProductGallery.png",import.meta.url).href,{InnerBlocks:T,useBlockProps:D,useInnerBlocksProps:he,__experimentalUseBlockPreview:fe,BlockContextProvider:ge}=wp.blockEditor,{registerBlockType:J}=wp.blocks,{useEffect:h,useState:f,useRef:K}=wp.element,{useSelect:b}=wp.data,{store:Y}=wp.blockEditor,j=window.fluent_cart_product_carousel_block_editor_data,A=window.fluentCartRestVars.rest,Z=[["fluent-cart/product-carousel-loop",{className:"fluent-cart-product-carousel-loop",layout:{type:"constrained"},metadata:{name:"Product Carousel Loop"}},[["fluent-cart/product-image"],["fluent-cart/product-title"],["fluent-cart/excerpt"],["fluent-cart/price-range"],["fluent-cart/shopapp-product-buttons"]]],["fluent-cart/product-carousel-controls"],["fluent-cart/product-carousel-pagination"]];J(j.slug+"/"+j.name,{apiVersion:3,title:j.title,description:j.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:q,alt:"Product Carousel Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:O},category:"fluent-cart",supports:{html:!1,reusable:!1,innerBlocks:!0},attributes:{product_ids:{type:"array",default:[]},inside_product_info:{type:"string",default:"-"},carousel_settings:{type:"object",default:{slidesToShow:3,autoplay:"yes",autoplayDelay:3e3,arrows:"yes",arrowsSize:"md",pagination:"yes",paginationType:"bullets",infinite:"no"}},has_controls:{type:"string",default:"yes"},has_pagination:{type:"string",default:"yes"}},provides_context:{"fluent-cart/carousel_settings":"carousel_settings","fluent-cart/product_ids":"product_ids","fluent-cart/has_controls":"has_controls","fluent-cart/has_pagination":"has_pagination"},edit:({attributes:o,setAttributes:n,clientId:i})=>{const g=D({className:"fluent-cart-product-carousel-block"}),[c,s]=f([]),y=K(!1),[M,t]=f([]),[x,v]=f(!1),a=Math.max(1,Number(o.carousel_settings.slidesToShow||4)),L=o.carousel_settings.infinite==="yes",{has_controls:_,has_pagination:w}=b(r=>{const d=r("core/block-editor").getBlocks(i);return{has_controls:d.some(p=>p.name==="fluent-cart/product-carousel-controls"),has_pagination:d.some(p=>p.name==="fluent-cart/product-carousel-pagination")}},[i]);h(()=>{if(!y.current){if(!_&&!w)return;y.current=!0}n({has_controls:_?"yes":"no",has_pagination:w?"yes":"no"})},[_,w]);const P=b(r=>{const{getBlockParents:d,getBlockName:p}=r(Y);return d(i).some(l=>p(l)==="fluent-cart/product-info")},[i]);h(()=>{const r=P?"yes":"no";o.inside_product_info!==r&&n({inside_product_info:r})},[P]);const R=()=>{if(!(Array.isArray(o.product_ids)&&o.product_ids.length>0))return;v(!0);const d=A.url+"/products/fetchProductsByIds",p={productIds:o.product_ids,with:["detail","variants"]};U({path:Q(d,p),headers:{"X-WP-Nonce":A.nonce}}).then(l=>{var B;const G=Array.isArray((B=l==null?void 0:l.products)==null?void 0:B.data)?l.products.data:Array.isArray(l==null?void 0:l.products)?l.products:Array.isArray(l)?l:[];s(G),console.log("api response",c)}).finally(()=>{v(!1)})};h(()=>{R()},[o.product_ids]),h(()=>{},[c]);const z=(()=>{if(!c.length)return Array.from({length:a}).map((p,l)=>({ID:`placeholder-${l}`,isPlaceholder:!0}));if(!L||c.length>=a)return c.slice(0,a);const r=[...c];let d=0;for(;r.length<a;)r.push(c[d%c.length]),d++;return r.slice(0,a)})();Math.ceil((c.length||a)/a);const C=b(r=>r("core/block-editor").getBlock(i),[i]),[S,F]=f(1);h(()=>{if(S>1){new Date().toISOString();return}F(S+1)},[C]),C.innerBlocks;const[ee,se]=f();return e.jsxs("div",{...g,children:[e.jsx($,{attributes:o,setAttributes:n,selectedProduct:c,setSelectedProduct:s}),e.jsx("div",{className:"fct-product-gallery-wrapper is-editor-preview",children:e.jsx("div",{className:"fct-product-gallery-carousel editor-carousel-preview",style:{display:"grid",gap:"16px"},children:x||!c.length?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"fluent-cart-empty",children:[e.jsxs("div",{className:"fct-loading-header",children:[e.jsx("div",{className:"fct-loading-spinner"}),e.jsx("span",{children:m("Loading products...")})]}),e.jsx("div",{className:"dummy-grid",style:{"--fct-slides-per-view":a},children:Array.from({length:a}).map((r,d)=>e.jsxs("div",{className:"dummy-card",style:{"--card-index":d},children:[e.jsx("div",{className:"dummy-image skeleton"}),e.jsxs("div",{className:"dummy-content",children:[e.jsx("div",{className:"dummy-title skeleton"}),e.jsx("div",{className:"dummy-excerpt skeleton"}),e.jsx("div",{className:"dummy-price skeleton"})]}),e.jsx("div",{className:"dummy-btn-wrap",children:e.jsx("div",{className:"dummy-btn"})})]},d))})]})}):e.jsx(H,{value:{products:z},children:e.jsx(T,{template:Z})})})})]})},save:()=>{const o=D.save({className:"fluent-cart-product-carousel-block"});return e.jsx("div",{...o,children:e.jsx(T.Content,{})})}});
2