PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
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 1.2.0 All 47 releases
fluent-cart / assets / MediaCarouselBlockEditor.js

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

2 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import{j as e}from"./chunks/jsx-runtime.js?ver=1.6.4";import{M as G}from"./chunks/Icons.js?ver=1.6.4";import{a as F}from"./chunks/index5.js?ver=1.6.4";import{E as C}from"./chunks/EditorPanel.js?ver=1.6.4";import{E as u}from"./chunks/EditorPanelRow.js?ver=1.6.4";import{b as o}from"./chunks/BlockEditorTranslator.js?ver=1.6.4";import{S as U}from"./chunks/SelectVariationModal.js?ver=1.6.4";import{u as V}from"./chunks/SingleProductContext.js?ver=1.6.4";import{P as H}from"./chunks/ProductContext.js?ver=1.6.4";import{a as Q}from"./chunks/add-query-args.js?ver=1.6.4";import"./chunks/ProductListItem.js?ver=1.6.4";import"./chunks/index6.js?ver=1.6.4";const{InspectorControls:W}=wp.blockEditor,{CheckboxControl:X}=wp.components,{RangeControl:E}=wp.components,{SelectControl:S,ToggleControl:M,__experimentalToggleGroupControl:J,__experimentalToggleGroupControlOption:K}=wp.components,Y=J,I=K,Z=({attributes:t,setAttributes:n,selectedProduct:c,setSelectedProduct:v,selectedVariations:p,setSelectedVariations:r,isInsideProductInfo:_})=>{const{carousel_settings:s}=t;return 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.jsxs(C,{title:o("Product"),children:[e.jsx(u,{children:e.jsxs(Y,{isBlock:!0,label:o("Query type"),value:t.query_type,onChange:a=>{n({query_type:a})},children:[e.jsx(I,{value:"default",label:o("Default")}),e.jsx(I,{value:"custom",label:o("Custom")})]})}),t.query_type==="custom"&&e.jsxs(u,{className:"flex-col",children:[e.jsx(U,{setAttributes:n,preSelectedVariations:p,onModalClosed:a=>{if(!a||Object.keys(a).length===0){n({variation_ids:[],product_id:""}),r({});return}const m={...a},h=Object.keys(m).map(g=>Number(g)),f=Object.values(m)[0],w=(f==null?void 0:f.post_id)??"";n({variation_ids:h,product_id:w}),r(m)},selectedVariations:p,setSelectedVariations:r,button:!0,isMultiple:!0}),c&&c.length>0&&e.jsxs("div",{className:"fct-selected-products",children:[e.jsx("span",{className:"fct-selected-products__label",children:o("Selected products")}),e.jsx("div",{className:"fct-selected-products__list",children:c.map(a=>{var m;return e.jsxs("div",{className:"fct-product-chip-group",children:[e.jsx("span",{className:"fct-product-chip fct-product-chip--parent",children:a.post_title}),((m=a==null?void 0:a.detail)==null?void 0:m.variation_type)==="simple_variations"&&Array.isArray(a.variants)&&a.variants.length>0&&e.jsx("div",{className:"fct-variation-chip-group",children:a.variants.map(h=>e.jsx("span",{className:"fct-variation-chip",children:h.variation_title},h.id))})]},a.ID)})})]})]})]}),e.jsx(C,{title:o("Layout"),children:e.jsxs(u,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:o("Slides per view")}),e.jsx(E,{value:s.slidesToShow,onChange:a=>n({carousel_settings:{...s,slidesToShow:a}}),min:1,max:6})]})}),e.jsxs(C,{title:o("Behavior"),children:[e.jsx("p",{className:"fct-panel-subtitle",children:o("Carousel interaction & animation")}),e.jsx(u,{children:e.jsx(S,{label:o("Autoplay"),value:s.autoplay,options:[{label:o("Disabled"),value:"no"},{label:o("Always"),value:"yes"},{label:o("On Hover"),value:"hover"}],onChange:a=>{n({carousel_settings:{...s,autoplay:a}})}})}),s.autoplay==="hover"&&s.slidesToShow>1&&e.jsx("p",{className:"fct-inspector-hint",children:"Hover autoplay works best with single slide view"}),["yes","hover"].includes(s.autoplay)&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(E,{label:"Autoplay Delay (ms)",help:o("Time between slides in milliseconds"),value:s.autoplayDelay||3e3,min:300,max:1e4,step:100,onChange:a=>n({carousel_settings:{...s,autoplayDelay:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(M,{label:o("Show arrows"),checked:s.arrows==="yes",onChange:a=>n({carousel_settings:{...s,arrows:a?"yes":"no"}})})}),s.arrows==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(S,{label:o("Arrow Size"),value:s.arrowsSize,options:[{label:o("Small"),value:"sm"},{label:o("Medium"),value:"md"},{label:o("Large"),value:"lg"}],onChange:a=>n({carousel_settings:{...s,arrowsSize:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(M,{label:o("Show Pagination"),checked:s.pagination==="yes",onChange:a=>n({carousel_settings:{...s,pagination:a?"yes":"no"}})})}),s.pagination==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(S,{label:o("Pagination Type"),value:s.paginationType,options:[{label:o("Bullets"),value:"bullets"},{label:o("Fraction"),value:"fraction"},{label:o("Progress Bar"),value:"progress"},{label:o("Segmented (Modern)"),value:"segmented"}],onChange:a=>n({carousel_settings:{...s,paginationType:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(X,{label:o("Infinite loop"),checked:s.infinite==="yes",onChange:a=>n({carousel_settings:{...s,infinite:a?"yes":"no"}})})})]})]})})})})},$=""+new URL("assets/ProductGallery.png",import.meta.url).href,A=(t,n=[])=>{var p;const c=n.map(r=>Number(r)),v={};return(p=t==null?void 0:t.variants)!=null&&p.length&&t.variants.forEach(r=>{var _,s;if(c.includes(Number(r.id))){const a=(_=t==null?void 0:t.detail)!=null&&_.featured_media?[{url:t.detail.featured_media.url,title:t.detail.featured_media.title}]:[],m=(Array.isArray((s=r==null?void 0:r.media)==null?void 0:s.meta_value)?r.media.meta_value:[]).map(f=>({url:f.url,title:f.title})),h=[...a,...m];v[r.id]={...r,images:h}}}),v},{InnerBlocks:D,useBlockProps:L,useInnerBlocksProps:ye,__experimentalUseBlockPreview:ve,BlockContextProvider:_e}=wp.blockEditor,{registerBlockType:ee}=wp.blocks,{useEffect:j,useState:P,useRef:ae,useMemo:se}=wp.element,{useSelect:T}=wp.data,{store:oe}=wp.blockEditor,N=window.fluent_cart_media_carousel_block_editor_data,z=window.fluentCartRestVars.rest,te=[["fluent-cart/media-carousel-loop",{className:"fluent-cart-media-carousel-loop",layout:{type:"constrained"},metadata:{name:"Media Carousel Loop"}},[["fluent-cart/media-carousel-product-image"]]],["fluent-cart/media-carousel-controls"],["fluent-cart/media-carousel-pagination"]];ee(N.slug+"/"+N.name,{apiVersion:3,title:N.title,description:N.description,example:{attributes:{},innerBlocks:[{name:"core/image",attributes:{url:$,alt:"Media Carousel Preview",style:{width:"100%",height:"auto"}}}]},icon:{src:G},category:"fluent-cart",supports:{html:!1,reusable:!1,innerBlocks:!0},attributes:{product_id:{type:["string","number"],default:""},variation_ids:{type:"array",default:[]},inside_product_info:{type:"string",default:""},query_type:{type:"string",default:"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/query_type":"query_type","fluent-cart/carousel_settings":"carousel_settings","fluent-cart/product_id":"product_id","fluent-cart/variation_ids":"variation_ids","fluent-cart/has_controls":"has_controls","fluent-cart/has_pagination":"has_pagination"},edit:({attributes:t,setAttributes:n,clientId:c})=>{const v=L({className:"fluent-cart-media-carousel-block"}),[p,r]=P([]),[_,s]=P({}),[a,m]=P(!1),h=ae(!1),{has_controls:f,has_pagination:w}=T(l=>{const d=l("core/block-editor").getBlocks(c);return{has_controls:d.some(i=>i.name==="fluent-cart/media-carousel-controls"),has_pagination:d.some(i=>i.name==="fluent-cart/media-carousel-pagination"),innerCount:d.length}},[c]);j(()=>{if(!h.current){h.current=!0;return}n({has_controls:f?"yes":"no",has_pagination:w?"yes":"no"})},[f,w]);const g=T(l=>{const{getBlockParents:d,getBlockName:i}=l(oe);return d(c).some(x=>{const k=i(x);return["fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-info"].includes(k)})},[c]);j(()=>{n({inside_product_info:g?"yes":"no"})},[g]);const y=V();j(()=>{if(!g||t.inside_product_info==="yes")return;const l=t.carousel_settings||{};n({carousel_settings:{...l,slidesToShow:1,autoplay:"hover",pagination:"no",arrowsSize:"sm"}})},[g]);const b=Math.max(1,Number(t.carousel_settings.slidesToShow||3)),R=se(()=>Array.from({length:b}),[b]);return T(l=>l("core/block-editor").getBlock(c),[c]),j(()=>{if(g||!t.product_id||!t.variation_ids.length)return;(()=>{const d=z.url+"/products/"+t.product_id;F({path:Q(d,{with:["block_product_detail"]}),headers:{"X-WP-Nonce":z.nonce}}).then(i=>{if(!(i!=null&&i.product))return;const B=(t.variation_ids||[]).map(Number),x=i.product,k={...x,variants:Array.isArray(x.variants)?x.variants.filter(O=>B.includes(Number(O.id))):[]};r([k]);const q=A(i.product,t.variation_ids);s(q)}).catch(i=>{console.error("Failed to fetch variations:",i)})})()},[g,t.product_id,t.variation_ids]),j(()=>{if(y!=null&&y.product){const l=y.product;if(!l||!l.ID)return;r([l])}},[y==null?void 0:y.product]),e.jsxs("div",{...v,children:[e.jsx(Z,{attributes:t,setAttributes:n,selectedProduct:p,setSelectedProduct:r,selectedVariations:_,setSelectedVariations:s,isInsideProductInfo:g}),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:a||!p.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:o("Loading media...")})]}),e.jsx("div",{className:"dummy-grid",style:{"--fct-slides-per-view":b},children:R.map((l,d)=>e.jsx("div",{className:"dummy-media-card",style:{"--card-index":d},children:e.jsx("div",{className:"dummy-image skeleton"})},d))})]})}):e.jsx(H,{value:{products:p},children:e.jsx(D,{template:te})})})})]})},save:({attributes:t})=>{const n=L.save({className:"fluent-cart-media-carousel-block"});return e.jsx("div",{...n,children:e.jsx(D.Content,{})})}});
2