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

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

2 lines 9.7 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 c}from"./chunks/BlockEditorTranslator.js?ver=1.4.1";import{M as G}from"./chunks/Icons.js?ver=1.4.1";import{a as F}from"./chunks/index5.js?ver=1.4.1";import{E as C}from"./chunks/EditorPanel.js?ver=1.4.1";import{E as u}from"./chunks/EditorPanelRow.js?ver=1.4.1";import{S as U}from"./chunks/SelectVariationModal.js?ver=1.4.1";import{u as V}from"./chunks/SingleProductContext.js?ver=1.4.1";import{P as H}from"./chunks/ProductContext.js?ver=1.4.1";import{a as Q}from"./chunks/add-query-args.js?ver=1.4.1";import"./chunks/ProductListItem.js?ver=1.4.1";import"./chunks/index6.js?ver=1.4.1";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:o,setAttributes:t,selectedProduct:i,setSelectedProduct:v,selectedVariations:p,setSelectedVariations:n,isInsideProductInfo:_})=>{const{carousel_settings:s}=o;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:c("Product"),children:[e.jsx(u,{children:e.jsxs(Y,{isBlock:!0,label:c("Query type"),value:o.query_type,onChange:a=>{t({query_type:a})},children:[e.jsx(I,{value:"default",label:c("Default")}),e.jsx(I,{value:"custom",label:c("Custom")})]})}),o.query_type==="custom"&&e.jsxs(u,{className:"flex-col",children:[e.jsx(U,{setAttributes:t,preSelectedVariations:p,onModalClosed:a=>{if(!a||Object.keys(a).length===0){t({variation_ids:[],product_id:""}),n({});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)??"";t({variation_ids:h,product_id:w}),n(m)},selectedVariations:p,setSelectedVariations:n,button:!0,isMultiple:!0}),i&&i.length>0&&e.jsxs("div",{className:"fct-selected-products",children:[e.jsx("span",{className:"fct-selected-products__label",children:c("Selected products")}),e.jsx("div",{className:"fct-selected-products__list",children:i.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:c("Layout"),children:e.jsxs(u,{children:[e.jsx("span",{className:"fct-inspector-control-label",children:c("Slides per view")}),e.jsx(E,{value:s.slidesToShow,onChange:a=>t({carousel_settings:{...s,slidesToShow:a}}),min:1,max:6})]})}),e.jsxs(C,{title:c("Behavior"),children:[e.jsx("p",{className:"fct-panel-subtitle",children:c("Carousel interaction & animation")}),e.jsx(u,{children:e.jsx(S,{label:"Autoplay",value:s.autoplay,options:[{label:"Disabled",value:"no"},{label:"Always",value:"yes"},{label:"On Hover",value:"hover"}],onChange:a=>{t({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:"Time between slides in milliseconds",value:s.autoplayDelay||3e3,min:300,max:1e4,step:100,onChange:a=>t({carousel_settings:{...s,autoplayDelay:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(M,{label:"Show arrows",checked:s.arrows==="yes",onChange:a=>t({carousel_settings:{...s,arrows:a?"yes":"no"}})})}),s.arrows==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(S,{label:"Arrow Size",value:s.arrowsSize,options:[{label:"Small",value:"sm"},{label:"Medium",value:"md"},{label:"Large",value:"lg"}],onChange:a=>t({carousel_settings:{...s,arrowsSize:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(M,{label:"Show Pagination",checked:s.pagination==="yes",onChange:a=>t({carousel_settings:{...s,pagination:a?"yes":"no"}})})}),s.pagination==="yes"&&e.jsx(u,{className:"fct-nested-control",children:e.jsx(S,{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:a=>t({carousel_settings:{...s,paginationType:a}})})}),e.jsx("div",{className:"fct-inspector-divider"}),e.jsx(u,{children:e.jsx(X,{label:c("Infinite loop"),checked:s.infinite==="yes",onChange:a=>t({carousel_settings:{...s,infinite:a?"yes":"no"}})})})]})]})})})})},$=""+new URL("assets/ProductGallery.png",import.meta.url).href,A=(o,t=[])=>{var p;const i=t.map(n=>Number(n)),v={};return(p=o==null?void 0:o.variants)!=null&&p.length&&o.variants.forEach(n=>{var _,s;if(i.includes(Number(n.id))){const a=(_=o==null?void 0:o.detail)!=null&&_.featured_media?[{url:o.detail.featured_media.url,title:o.detail.featured_media.title}]:[],m=(Array.isArray((s=n==null?void 0:n.media)==null?void 0:s.meta_value)?n.media.meta_value:[]).map(f=>({url:f.url,title:f.title})),h=[...a,...m];v[n.id]={...n,images:h}}}),v},{InnerBlocks:D,useBlockProps:L,useInnerBlocksProps:ge,__experimentalUseBlockPreview:ye,BlockContextProvider:ve}=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:o,setAttributes:t,clientId:i})=>{const v=L({className:"fluent-cart-media-carousel-block"}),[p,n]=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(i);return{has_controls:d.some(r=>r.name==="fluent-cart/media-carousel-controls"),has_pagination:d.some(r=>r.name==="fluent-cart/media-carousel-pagination"),innerCount:d.length}},[i]);j(()=>{if(!h.current){h.current=!0;return}t({has_controls:f?"yes":"no",has_pagination:w?"yes":"no"})},[f,w]);const g=T(l=>{const{getBlockParents:d,getBlockName:r}=l(oe);return d(i).some(x=>{const k=r(x);return["fluent-cart/products","fluent-cart/shopapp-product-container","fluent-cart/shopapp-product-loop","fluent-cart/product-info"].includes(k)})},[i]);j(()=>{t({inside_product_info:g?"yes":"no"})},[g]);const y=V();j(()=>{if(!g||o.inside_product_info==="yes")return;const l=o.carousel_settings||{};t({carousel_settings:{...l,slidesToShow:1,autoplay:"hover",pagination:"no",arrowsSize:"sm"}})},[g]);const b=Math.max(1,Number(o.carousel_settings.slidesToShow||3)),R=se(()=>Array.from({length:b}),[b]);return T(l=>l("core/block-editor").getBlock(i),[i]),j(()=>{if(g||!o.product_id||!o.variation_ids.length)return;(()=>{const d=z.url+"/products/"+o.product_id;F({path:Q(d,{with:["detail","variants"]}),headers:{"X-WP-Nonce":z.nonce}}).then(r=>{if(!(r!=null&&r.product))return;const B=(o.variation_ids||[]).map(Number),x=r.product,k={...x,variants:Array.isArray(x.variants)?x.variants.filter(O=>B.includes(Number(O.id))):[]};n([k]);const q=A(r.product,o.variation_ids);s(q)}).catch(r=>{console.error("Failed to fetch variations:",r)})})()},[g,o.product_id,o.variation_ids]),j(()=>{if(y!=null&&y.product){const l=y.product;if(!l||!l.ID)return;n([l])}},[y==null?void 0:y.product]),e.jsxs("div",{...v,children:[e.jsx(Z,{attributes:o,setAttributes:t,selectedProduct:p,setSelectedProduct:n,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:c("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:o})=>{const t=L.save({className:"fluent-cart-media-carousel-block"});return e.jsx("div",{...t,children:e.jsx(D.Content,{})})}});
2