← Back
Editing: single-product.js
(()=>{var e,t,o,r,s,n={7709:(e,t,o)=>{"use strict";const r=window.wp.blocks;var s=o(11789),n=o(3683);const c=window.wc.wcBlocksRegistry;var i=o(86087),a=o(98516);o.p=a.XK,(0,c.registerBlockComponent)({blockName:"woocommerce/product-price",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(2388)]).then(o.bind(o,87746)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-image",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(4232)]).then(o.bind(o,67763)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-title",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(2105)]).then(o.bind(o,10266)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-rating",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(462)]).then(o.bind(o,89650)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-rating-stars",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(8578)]).then(o.bind(o,11886)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-rating-counter",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(8553)]).then(o.bind(o,14257)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-average-rating",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(8647)]).then(o.bind(o,68092)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-button",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(7409)]).then(o.bind(o,77817)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-summary",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(3895)]).then(o.bind(o,35235)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-sale-badge",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(4442)]).then(o.bind(o,72334)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-sku",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(2724)]).then(o.bind(o,35822)))}),(0,c.registerBlockComponent)({blockName:"woocommerce/product-stock-indicator",component:(0,i.lazy)(()=>Promise.all([o.e(94),o.e(345)]).then(o.bind(o,15143)))});var l=o(15703);const d=JSON.parse('{"name":"woocommerce/single-product","icon":"info","title":"Product","description":"Display a single product of your choice with full control over its presentation.","category":"woocommerce","keywords":["WooCommerce","single product"],"supports":{"interactivity":true,"align":["wide","full"],"color":{"background":true,"gradients":true,"text":false,"__experimentalDefaultControls":{"background":true}},"spacing":{"padding":true,"margin":["top","bottom"]},"__experimentalBorder":{"color":true,"style":true,"width":true,"radius":true},"listView":true,"shadow":true},"attributes":{"productId":{"type":"number"}},"example":{},"usesContext":["postId","postType","queryId"],"style":"file:../woocommerce/single-product-style.css","textdomain":"woocommerce","apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json"}');var m=o(56427),p=o(27723),u=o(79401),h=o(10790);const g="woocommerce/product-query/product-title";!function(e,{blockDescription:t,blockIcon:o,blockTitle:s,variationName:n,scope:c}){(0,r.registerBlockVariation)(e,{description:t,name:n,title:s,isActive:e=>e.__woocommerceNamespace===n,icon:{src:o},attributes:{__woocommerceNamespace:n},scope:c})}("core/post-title",{blockDescription:(0,p.__)("Display the title of a product.","woocommerce"),blockIcon:(0,h.jsx)(m.Icon,{icon:u.A}),blockTitle:(0,p.__)("Product Title","woocommerce"),variationName:g,scope:["block"]});const w=(0,h.jsx)(s.A,{icon:n.A,className:"wc-block-editor-components-block-icon"}),b=[["core/columns",{},[["core/column",{},[["woocommerce/product-gallery"]]],["core/column",{},[["core/post-title",{headingLevel:2,isLink:!0,__woocommerceNamespace:g}],["woocommerce/product-rating"],["woocommerce/product-price"],["woocommerce/product-summary"],[(0,l.getSetting)("isBlockTheme",!1)?"woocommerce/add-to-cart-with-options":"woocommerce/add-to-cart-form"],["woocommerce/product-meta"]]]]]],x=["core/columns","core/column","core/post-title","core/post-excerpt","woocommerce/add-to-cart-form","woocommerce/add-to-cart-with-options","woocommerce/product-meta","woocommerce/product-gallery","woocommerce/product-reviews","woocommerce/product-details",...Object.keys((_=d.name,(0,c.getRegisteredBlockComponents)(_)))];var _,v=o(29491);const f=window.wp.url,k=window.wp.apiFetch;var j=o.n(k);const y=({selected:e=[],search:t="",queryArgs:o={}})=>{const r=(({selected:e=[],search:t="",queryArgs:o={}})=>{const r=a.r7.productCount>100&&e.length>0,s=[(0,f.addQueryArgs)("/wc/store/v1/products",{per_page:100,catalog_visibility:"any",search:t,orderby:"title",order:"asc",exclude:r?e:[],...o})];if(r){const t=Math.ceil(e.length/100);for(let o=1;o<=t;o++)s.push((0,f.addQueryArgs)("/wc/store/v1/products",{catalog_visibility:"any",include:e,per_page:100,page:o}))}return s})({selected:e,search:t,queryArgs:o});return Promise.all(r.map(e=>j()({path:e}))).then(e=>[...new Map(e.flatMap(e=>e.map(e=>[e.id,{...e,parent:0}]))).values()])},S=async e=>{if(!("json"in e))return{code:e.code||"",message:e.message,type:e.type||"general"};try{const t=await e.json();return{code:t.code||"",message:t.message,type:t.type||"api"}}catch(e){return{message:e.message,type:"general"}}},C=(0,v.createHigherOrderComponent)(e=>class extends i.Component{state={error:null,loading:!1,product:"preview"===this.props.attributes.productId?this.props.attributes.previewProduct:null};componentDidMount(){this.loadProduct()}componentDidUpdate(e){e.attributes.productId!==this.props.attributes.productId&&this.loadProduct()}loadProduct=()=>{const{productId:e}=this.props.attributes;"preview"!==e&&(e?(this.setState({loading:!0}),(e=>j()({path:`/wc/store/v1/products/${e}`}))(e).then(e=>{this.setState({product:e,loading:!1,error:null})}).catch(async e=>{const t=await S(e);this.setState({product:null,loading:!1,error:t})})):this.setState({product:null,loading:!1,error:null}))};render(){const{error:t,loading:o,product:r}=this.state;return(0,h.jsx)(e,{...this.props,error:t,getProduct:this.loadProduct,isLoading:o,product:r})}},"withProduct"),P=({imageUrl:e=`${a.sW}/block-error.svg`,header:t=(0,p.__)("Oops!","woocommerce"),text:o=(0,p.__)("There was an error loading the content.","woocommerce"),errorMessage:r,errorMessagePrefix:s=(0,p.__)("Error:","woocommerce"),button:n,showErrorBlock:c=!0})=>c?(0,h.jsxs)("div",{className:"wc-block-error wc-block-components-error",children:[e&&(0,h.jsx)("img",{className:"wc-block-error__image wc-block-components-error__image",src:e,alt:""}),(0,h.jsxs)("div",{className:"wc-block-error__content wc-block-components-error__content",children:[t&&(0,h.jsx)("p",{className:"wc-block-error__header wc-block-components-error__header",children:t}),o&&(0,h.jsx)("p",{className:"wc-block-error__text wc-block-components-error__text",children:o}),r&&(0,h.jsxs)("p",{className:"wc-block-error__message wc-block-components-error__message",children:[s?s+" ":"",r]}),n&&(0,h.jsx)("p",{className:"wc-block-error__button wc-block-components-error__button",children:n})]})]}):null;o(45893);class N extends i.Component{state={errorMessage:"",hasError:!1};static getDerivedStateFromError(e){return void 0!==e.statusText&&void 0!==e.status?{errorMessage:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("strong",{children:e.status}),": ",e.statusText]}),hasError:!0}:{errorMessage:e.message,hasError:!0}}render(){const{header:e,imageUrl:t,showErrorMessage:o=!0,showErrorBlock:r=!0,text:s,errorMessagePrefix:n,renderError:c,button:i}=this.props,{errorMessage:a,hasError:l}=this.state;return l?"function"==typeof c?c({errorMessage:a}):(0,h.jsx)(P,{showErrorBlock:r,errorMessage:o?a:null,header:e,imageUrl:t,text:s,errorMessagePrefix:n,button:i}):this.props.children}}const E=N;var I=o(96900),A=o(94715),B=o(62796);const O=e=>{const t=((0,B.useProductDataContext)().product||{}).id||e.productId||0;return t&&1!==t?(0,h.jsx)(A.InspectorControls,{children:(0,h.jsxs)("div",{className:"wc-block-single-product__edit-card",children:[(0,h.jsx)("div",{className:"wc-block-single-product__edit-card-title",children:(0,h.jsxs)("a",{href:`${l.ADMIN_URL}post.php?post=${t}&action=edit`,target:"_blank",rel:"noopener noreferrer",children:[(0,p.__)("Edit this product's details","woocommerce"),(0,h.jsx)(s.A,{icon:I.A,size:16})]})}),(0,h.jsx)("div",{className:"wc-block-single-product__edit-card-description",children:(0,p.__)("Edit details such as title, price, description and more.","woocommerce")})]})}):null};var T=o(54331),L=o(4921);const M=window.wp.escapeHtml,R=({message:e,type:t})=>e?"general"===t?(0,h.jsxs)("span",{children:[(0,p.__)("The following error was returned","woocommerce"),(0,h.jsx)("br",{}),(0,h.jsx)("code",{children:(0,M.escapeHTML)(e)})]}):"api"===t?(0,h.jsxs)("span",{children:[(0,p.__)("The following error was returned from the API","woocommerce"),(0,h.jsx)("br",{}),(0,h.jsx)("code",{children:(0,M.escapeHTML)(e)})]}):e:(0,p.__)("An error has prevented the block from being updated.","woocommerce"),V=({error:e})=>(0,h.jsx)("div",{className:"wc-block-error-message",children:R(e)});o(63120);const $=({className:e="",error:t,isLoading:o=!1,onRetry:r})=>(0,h.jsxs)(m.Placeholder,{icon:(0,h.jsx)(s.A,{icon:T.A}),label:(0,p.__)("Sorry, an error occurred","woocommerce"),className:(0,L.A)("wc-block-api-error",e),children:[(0,h.jsx)(V,{error:t}),r&&(0,h.jsx)(h.Fragment,{children:o?(0,h.jsx)(m.Spinner,{}):(0,h.jsx)(m.Button,{variant:"secondary",onClick:r,children:(0,p.__)("Retry","woocommerce")})})]}),F=window.wc.data;var D=o(47143),z=o(74515);o(27539);var H=o(73993);function G(e,t,o){const r=new Set(t.map(e=>e[o]));return e.filter(e=>!r.has(e[o]))}var U=o(18537);const W={clear:(0,p.__)("Clear all selected items","woocommerce"),noItems:(0,p.__)("No items found.","woocommerce"), /* Translators: %s search term */ noResults:(0,p.__)("No results for %s","woocommerce"),search:(0,p.__)("Search for items","woocommerce"),selected:e=>(0,p.sprintf)(/* translators: Number of items selected from list. */ /* translators: Number of items selected from list. */ (0,p._n)("%d item selected","%d items selected",e,"woocommerce"),e),updated:(0,p.__)("Search results updated.","woocommerce")},q=(e,t)=>null!==t&&(e.id===t||!!(Array.isArray(e.children)&&e.children.length>0)&&e.children.some(e=>q(e,t))),K=(e,t=e)=>{const o=e.reduce((e,t)=>{const o=t.parent||0;return e[o]||(e[o]=[]),e[o].push(t),e},{}),r=t.reduce((e,t)=>(e[String(t.id)]=t,e),{});const s=["0"],n=(e={})=>e.parent?[...n(r[e.parent]),e.name]:e.name?[e.name]:[],c=e=>e.map(e=>{const t=o[e.id];return s.push(""+e.id),{...e,breadcrumbs:n(r[e.parent]),children:t&&t.length?c(t):[]}}),i=c(o[0]||[]);return Object.entries(o).forEach(([e,t])=>{s.includes(e)||i.push(...c(t||[]))}),i},J=(e,t)=>{if(!t)return e;const o=new RegExp(`(${t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")})`,"ig");return e.split(o).map((e,t)=>o.test(e)?(0,h.jsx)("strong",{children:e},t):(0,h.jsx)(i.Fragment,{children:e},t))},X=e=>{const t=e.children?.map(e=>[e,...X(e)]);return t?t.flat():[]},Q=(e,t)=>X(e).some(e=>t.find(t=>t.id===e.id)),Y=(e,t)=>X(e).every(e=>t.find(t=>t.id===e.id)),Z=({label:e})=>(0,h.jsx)("span",{className:"woocommerce-search-list__item-count",children:e}),ee=e=>{const{item:t,search:o}=e,r=t.breadcrumbs&&t.breadcrumbs.length;return(0,h.jsxs)("span",{className:"woocommerce-search-list__item-label",children:[r?(0,h.jsx)("span",{className:"woocommerce-search-list__item-prefix",children:(s=t.breadcrumbs,1===s.length?s.slice(0,1).toString():2===s.length?s.slice(0,1).toString()+" › "+s.slice(-1).toString():s.slice(0,1).toString()+" … "+s.slice(-1).toString())}):null,(0,h.jsx)("span",{className:"woocommerce-search-list__item-name",children:J((0,U.decodeEntities)(t.name),o)})]});var s},te=({countLabel:e,className:t,depth:o=0,controlId:r="",disabled:s=!1,item:n,isSelected:c,isSelectable:a=!0,isSingle:l,onSelect:d,search:p="",selected:u,useExpandedPanelId:g,...w})=>{const[b,x]=g,_=null!=e&&void 0!==n.count&&null!==n.count,v=!!n.breadcrumbs?.length,f=!!n.children?.length,k=q(n,b),j=(0,L.A)(["woocommerce-search-list__item",`depth-${o}`,t],{"has-breadcrumbs":v,"has-children":f,"has-count":_,"is-expanded":k,"is-radio-button":l}),y=w.name||`search-list-item-${r}`,S=`${y}-${n.id}`,C=(0,i.useCallback)(()=>{k||"number"!=typeof n.id&&"string"!=typeof n.id?!n.parent||"number"!=typeof n.parent&&"string"!=typeof n.parent?x(null):x(n.parent):x(n.id)},[k,n.id,n.parent,x]),P=(c||!a)&&Y(n,u);return f?(0,h.jsx)("div",{className:j,onClick:C,onKeyDown:e=>"Enter"===e.key||" "===e.key?C():null,role:"treeitem",tabIndex:0,children:l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("input",{type:"radio",id:S,name:y,value:n.value,onChange:()=>{d(n)(),k||x(n.id)},onClick:e=>e.stopPropagation(),checked:c,disabled:s,className:"woocommerce-search-list__item-input",...w}),(0,h.jsx)(ee,{item:n,search:p}),_?(0,h.jsx)(Z,{label:e||n.count}):null]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(m.CheckboxControl,{className:"woocommerce-search-list__item-input",checked:P,disabled:s,indeterminate:!P&&(c||Q(n,u)),label:J((0,U.decodeEntities)(n.name),p),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),onChange:()=>{const e=X(n),t=a?[n,...e]:[...e],o=Y(n,u);a&&c||!a&&o?d(G(u,t,"id"))():(d(function(e,t){const o=G(t,e,"id");return[...e,...o]}(u,t))(),k||x(n.id))},__nextHasNoMarginBottom:!0}),_?(0,h.jsx)(Z,{label:e||n.count}):null]})}):(0,h.jsxs)("div",{className:j,onClick:s?void 0:d(n),children:[l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("input",{...w,type:"radio",id:S,name:y,value:n.value,onChange:d(n),checked:c,disabled:s,className:"woocommerce-search-list__item-input",onClick:e=>e.stopPropagation()}),(0,h.jsx)("label",{htmlFor:S,children:(0,h.jsx)(ee,{item:n,search:p})})]}):(0,h.jsx)(m.CheckboxControl,{...w,id:S,name:y,className:"woocommerce-search-list__item-input",value:(0,U.decodeEntities)(n.value),label:J((0,U.decodeEntities)(n.name),p),onChange:()=>{d(n)(),k||x(n.id)},checked:c,disabled:s,__nextHasNoMarginBottom:!0,onClick:e=>e.stopPropagation()}),_?(0,h.jsx)(Z,{label:e||n.count}):null]})},oe=te;var re=o(13739);o(75022);const se=({id:e,label:t,popoverContents:o,remove:r,screenReaderLabel:n,className:c=""})=>{const[a,l]=(0,i.useState)(!1),d=(0,v.useInstanceId)(se);if(n=n||t,!t)return null;t=(0,U.decodeEntities)(t);const u=(0,L.A)("woocommerce-tag",c,{"has-remove":!!r}),g=`woocommerce-tag__label-${d}`,w=(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("span",{className:"screen-reader-text",children:n}),(0,h.jsx)("span",{"aria-hidden":"true",children:t})]});return(0,h.jsxs)("span",{className:u,children:[o?(0,h.jsx)(m.Button,{className:"woocommerce-tag__text",id:g,onClick:()=>l(!0),children:w}):(0,h.jsx)("span",{className:"woocommerce-tag__text",id:g,children:w}),o&&a&&(0,h.jsx)(m.Popover,{onClose:()=>l(!1),children:o}),r&&(0,h.jsx)(m.Button,{className:"woocommerce-tag__remove",onClick:r(e),label:(0,p.sprintf)( // Translators: %s label. // Translators: %s label. (0,p.__)("Remove %s","woocommerce"),t),"aria-describedby":g,children:(0,h.jsx)(s.A,{icon:re.A,size:20,className:"clear-icon",role:"img"})})]})},ne=se;o(71939);const ce=e=>(0,h.jsx)(oe,{...e}),ie=e=>{const{list:t,selected:o,renderItem:r,depth:s=0,loadMoreChildrenText:n,onLoadMoreChildren:c,totalChildren:a,onSelect:l,instanceId:d,isSingle:m,search:u,useExpandedPanelId:g}=e,[w]=g;return t?(0,h.jsx)(h.Fragment,{children:t.map(t=>{const b=t.children?.length??0,x=!!o.find(({id:e})=>e===t.id),_=q(t,w),v=a?.[t.id],f="number"==typeof v&&b<v;return(0,h.jsxs)(i.Fragment,{children:[(0,h.jsx)("li",{children:r({item:t,isSelected:x,onSelect:l,isSingle:m,selected:o,search:u,depth:s,useExpandedPanelId:g,controlId:d})}),_?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ie,{...e,list:t.children,depth:s+1}),c&&f?(0,h.jsx)("li",{children:(0,h.jsx)("button",{type:"button",className:"woocommerce-search-list__item woocommerce-search-list__item-load-more",onClick:()=>c(),children:n||(0,p.__)("Load more","woocommerce")})}):null]}):null]},t.id)})}):null},ae=({isLoading:e,isSingle:t,selected:o,messages:r,onChange:s,onRemove:n})=>{if(e||t||!o)return null;const c=o.length;return(0,h.jsxs)("div",{className:"woocommerce-search-list__selected",children:[(0,h.jsxs)("div",{className:"woocommerce-search-list__selected-header",children:[(0,h.jsx)("strong",{children:r.selected(c)}),c>0?(0,h.jsx)(m.Button,{variant:"link",isDestructive:!0,onClick:()=>s([]),"aria-label":r.clear,children:(0,p.__)("Clear all","woocommerce")}):null]}),c>0?(0,h.jsx)("ul",{children:o.map((e,t)=>(0,h.jsx)("li",{children:(0,h.jsx)(ne,{label:e.name,id:e.id,remove:n})},t))}):null]})},le=({filteredList:e,search:t,onSelect:o,instanceId:r,useExpandedPanelId:n,...c})=>{const{messages:i,renderItem:a,selected:l,isSingle:d,loadMoreChildrenText:m,onLoadMoreChildren:u,totalChildren:g}=c,w=a||ce;return 0===e.length?(0,h.jsxs)("div",{className:"woocommerce-search-list__list is-not-found",children:[(0,h.jsx)("span",{className:"woocommerce-search-list__not-found-icon",children:(0,h.jsx)(s.A,{icon:z.A,role:"img"})}),(0,h.jsx)("span",{className:"woocommerce-search-list__not-found-text",children:t?(0,p.sprintf)(i.noResults,t):i.noItems})]}):(0,h.jsx)("ul",{className:"woocommerce-search-list__list",children:(0,h.jsx)(ie,{useExpandedPanelId:n,list:e,selected:l,renderItem:w,loadMoreChildrenText:m,onLoadMoreChildren:u,totalChildren:g,onSelect:o,instanceId:r,isSingle:d,search:t})})},de=e=>{const{className:t="",isCompact:o,isHierarchical:r,isLoading:s,isSingle:n,list:c,messages:a=W,onChange:l,onSearch:d,selected:u,type:g="text",debouncedSpeak:w}=e,[b,x]=(0,i.useState)(""),_=(0,i.useState)(null),f=(0,v.useInstanceId)(de),k=(0,i.useMemo)(()=>({...W,...a}),[a]),j=(0,i.useMemo)(()=>((e,t,o)=>{if(!t)return o?K(e):e;const r=new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i"),s=e.map(e=>!!r.test(e.name)&&e).filter(Boolean);return o?K(s,e):s})(c,b,r),[c,b,r]);(0,i.useEffect)(()=>{w&&w(k.updated)},[w,k]),(0,i.useEffect)(()=>{"function"==typeof d&&d(b)},[b,d]);const y=(0,i.useCallback)(e=>()=>{n&&l([]);const t=u.findIndex(({id:t})=>t===e);l([...u.slice(0,t),...u.slice(t+1)])},[n,u,l]),S=(0,i.useCallback)(e=>()=>{Array.isArray(e)?l(e):-1===u.findIndex(({id:t})=>t===e.id)?l(n?[e]:[...u,e]):y(e.id)()},[n,y,l,u]),C=(0,i.useCallback)(e=>{const[t]=u.filter(t=>!e.find(e=>t.id===e.id));y(t.id)()},[y,u]);return(0,h.jsxs)("div",{className:(0,L.A)("woocommerce-search-list",t,{"is-compact":o,"is-loading":s,"is-token":"token"===g}),children:["text"===g&&(0,h.jsx)(ae,{...e,onRemove:y,messages:k}),(0,h.jsx)("div",{className:"woocommerce-search-list__search",children:"text"===g?(0,h.jsx)(m.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:k.search,type:"search",value:b,onChange:e=>x(e)}):(0,h.jsx)(m.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,disabled:s,label:k.search,onChange:C,onInputChange:e=>x(e),suggestions:[],__experimentalValidateInput:()=>!1,value:s?[(0,p.__)("Loading…","woocommerce")]:u.map(e=>({...e,value:e.name})),__experimentalShowHowTo:!1})}),s?(0,h.jsx)("div",{className:"woocommerce-search-list__list",children:(0,h.jsx)(m.Spinner,{})}):(0,h.jsx)(le,{...e,search:b,filteredList:j,messages:k,onSelect:S,instanceId:f,useExpandedPanelId:_})]})},me=((0,m.withSpokenMessages)(de),e=>t=>{let{selected:o}=t;o=void 0===o?null:o;const r=null===o;return Array.isArray(o)?(0,h.jsx)(e,{...t}):(0,h.jsx)(e,{...t,selected:r?[]:[o]})});var pe=o(64347);var ue=o(20923),he=o.n(ue);const ge=(0,v.createHigherOrderComponent)(e=>{class t extends i.Component{state={error:null,loading:!1,variations:{},totalVariations:{}};componentDidMount(){const{selected:e,showVariations:t}=this.props;e&&t&&this.loadVariations()}componentDidUpdate(e){const{isLoading:t,selected:o,showVariations:r}=this.props;r&&(!he()(e.selected,o)||e.isLoading&&!t)&&this.loadVariations()}loadVariations=({offset:e=0}={})=>{const{products:t}=this.props,{loading:o,variations:r,totalVariations:s}=this.state;if(o)return;const n=this.getExpandedProduct();if(!n)return;if(!e&&r?.[n])return;if(r?.[n]&&s?.[n]&&r[n].length>=s[n])return;const c=t.find(e=>e.id===n);if(!c?.variations||0===c.variations.length)return void this.setState({variations:{...this.state.variations,[n]:null},loading:!1,error:null});this.setState({loading:!0});const i=this.state.variations[n]||[];((e,t={})=>j()({path:(0,f.addQueryArgs)("wc/store/v1/products",{type:"variation",parent:e,orderby:"title",per_page:25,...t}),parse:!1}).then(e=>e.json().then(t=>{const o=e.headers.get("x-wp-total");return{variations:t,total:o?Number(o):null}})))(n,{offset:e}).then(({variations:e,total:t})=>{const o=e.map(e=>({...e,parent:n}));this.setState({variations:{...this.state.variations,[n]:[...i,...o]},totalVariations:{...this.state.totalVariations,[n]:t},loading:!1,error:null})}).catch(async e=>{const t=await S(e);this.setState({variations:{...this.state.variations,[n]:null},totalVariations:{...this.state.totalVariations,[n]:null},loading:!1,error:t})})};isProductId(e){const{products:t}=this.props;return t.some(t=>t.id===e)}findParentProduct(e){const{products:t}=this.props,o=t.filter(t=>t.variations&&t.variations.find(({id:t})=>t===e));return o[0]?.id}getExpandedProduct(){const{isLoading:e,selected:t,showVariations:o}=this.props;if(!o)return null;let r=t&&t.length?t[0]:null;return r?this.prevSelectedItem=r:!this.prevSelectedItem||e||this.isProductId(this.prevSelectedItem)||(r=this.prevSelectedItem),!e&&r?this.isProductId(r)?r:this.findParentProduct(r):null}render(){const{error:t,isLoading:o}=this.props,{error:r,loading:s,variations:n,totalVariations:c}=this.state,i=this.getExpandedProduct(),a=i&&n[i]?.length||0;return(0,h.jsx)(e,{...this.props,error:r||t,onLoadMoreVariations:()=>this.loadVariations({offset:a}),expandedProduct:this.getExpandedProduct(),isLoading:o,totalVariations:c,variations:n,variationsLoading:s})}}return t},"withProductVariations"),we=e=>{const{id:t,name:o,parent:r}=e;return{id:t,name:o,parent:r,breadcrumbs:[],children:[],details:e,value:e.slug}};var be=o(51609);const xe=({className:e,item:t,isSelected:o,isLoading:r,onSelect:s,disabled:n,...c})=>(0,h.jsxs)(h.Fragment,{children:[(0,be.createElement)(te,{...c,key:t.id,...e&&{className:e},isSelected:o,item:t,onSelect:s,...n&&{disabled:n}}),o&&r&&(0,h.jsx)("div",{className:(0,L.A)("woocommerce-search-list__item","woocommerce-product-attributes__item","depth-1","is-loading","is-not-active"),children:(0,h.jsx)(m.Spinner,{})},"loading")]});o(20415);const _e={list:(0,p.__)("Products","woocommerce"),noItems:(0,p.__)("Your store doesn't have any products.","woocommerce"),search:(0,p.__)("Search for a product to display","woocommerce"),updated:(0,p.__)("Product search results updated.","woocommerce")},ve=me((je=ge((0,v.withInstanceId)(e=>{const{expandedProduct:t=null,error:o,instanceId:r,isCompact:s=!1,isLoading:n,onChange:c,onLoadMoreVariations:i,totalVariations:a,onSearch:l,products:d,renderItem:m,selected:u=[],showVariations:g=!1,variations:w,variationsLoading:b}=e;if(o)return(0,h.jsx)(V,{error:o});const x=[...d,...w&&t&&w[t]?w[t]:[]].map(we);return(0,h.jsx)(de,{className:"woocommerce-products",list:x,isCompact:s,isLoading:n,isSingle:!0,selected:x.filter(({id:e})=>u.includes(Number(e))),onChange:c,loadMoreChildrenText:g?(0,p.__)("Load more variations","woocommerce"):void 0,onLoadMoreChildren:g?i:void 0,totalChildren:g?a:void 0,renderItem:m||(g?e=>{const{item:t,search:o,depth:s=0,isSelected:c,onSelect:i,useExpandedPanelId:a}=e,[l,d]=a??[null,()=>{}],m=q(t,l),u=t.details?.variations&&Array.isArray(t.details.variations)?t.details.variations.length:0,g=(0,L.A)("woocommerce-search-product__item","woocommerce-search-list__item",`depth-${s}`,"has-count",{"is-searching":o.length>0,"is-skip-level":0===s&&0!==t.parent,"is-variable":u>0});if(!t.breadcrumbs.length){const o=t.details?.variations&&t.details.variations.length>0;return(0,h.jsx)(xe,{...e,className:(0,L.A)(g,{"is-selected":c}),isSelected:c,item:t,onSelect:()=>()=>{i(t)(),m||d(t.id)},isLoading:n||b,countLabel:o?(0,p.sprintf)(/* translators: %1$d is the number of variations of a product product. */ /* translators: %1$d is the number of variations of a product product. */ (0,p.__)("%1$d variations","woocommerce"),t.details?.variations.length):null,name:`products-${r}`,"aria-label":o?(0,p.sprintf)(/* translators: %1$s is the product name, %2$d is the number of variations of that product. */ /* translators: %1$s is the product name, %2$d is the number of variations of that product. */ (0,p._n)("%1$s, has %2$d variation","%1$s, has %2$d variations",t.details?.variations?.length,"woocommerce"),t.name,t.details?.variations.length):void 0})}const w=(0,H.isEmpty)(t.details?.variation)?e:{...e,item:{...e.item,name:t.details?.variation},"aria-label":`${t.breadcrumbs[0]}: ${t.details?.variation}`};return(0,h.jsx)(te,{...w,className:g,name:`variations-${r}`})}:void 0),onSearch:l,messages:{..._e,...e.messages},isHierarchical:!0})})),({selected:e,...t})=>{const[o,r]=(0,i.useState)(!0),[s,n]=(0,i.useState)(null),[c,l]=(0,i.useState)([]),d=a.r7.productCount>100,m=async e=>{const t=await S(e);n(t),r(!1)},p=(0,i.useRef)(e);(0,i.useEffect)(()=>{y({selected:p.current}).then(e=>{l(e),r(!1)}).catch(m)},[p]);const u=(0,pe.YQ)(t=>{y({selected:e,search:t}).then(e=>{l(e),r(!1)}).catch(m)},400),g=(0,i.useCallback)(e=>{r(!0),u(e)},[r,u]);return(0,h.jsx)(je,{...t,selected:e,error:s,products:c,isLoading:o,onSearch:d?g:null})})),fe=({attributes:e,setAttributes:t,onChange:o})=>(0,h.jsx)(ve,{selected:e.productId||0,showVariations:!0,onChange:(e=[])=>{const r=e[0]?e[0].id:0;t({productId:r}),o&&o()}}),ke=({isEditing:e,setIsEditing:t})=>(0,h.jsx)(A.BlockControls,{children:(0,h.jsx)(m.ToolbarGroup,{controls:[{icon:"edit",title:(0,p.__)("Edit selected product","woocommerce"),onClick:()=>t(!e),isActive:e}]})});var je,ye=o(71881);const Se=({isLoading:e,product:t,clientId:o})=>{const s="wc-block-editor-single-product",{replaceInnerBlocks:n}=(0,D.useDispatch)("core/block-editor"),c=(0,i.useCallback)(()=>{n(o,(0,r.createBlocksFromInnerBlocksTemplate)(b),!1)},[o,n]);return(0,h.jsx)(B.InnerBlockLayoutContextProvider,{parentName:d.name,parentClassName:s,children:(0,h.jsxs)(B.ProductDataContextProvider,{product:t,isLoading:e,children:[(0,h.jsx)(A.InspectorControls,{children:(0,h.jsx)(m.PanelBody,{title:(0,p.__)("Layout","woocommerce"),initialOpen:!0,children:(0,h.jsx)(m.Button,{label:(0,p.__)("Reset layout to default","woocommerce"),onClick:c,variant:"tertiary",className:"wc-block-editor-single-product__reset-layout",icon:ye.A,children:(0,p.__)("Reset layout","woocommerce")})})}),(0,h.jsx)("div",{className:s,children:(0,h.jsx)(A.BlockContextProvider,{value:{postId:t?.id,postType:"product"},children:(0,h.jsx)(A.InnerBlocks,{template:b,allowedBlocks:x,templateLock:!1})})})]})})},Ce=C(({attributes:e,setAttributes:t,error:o,getProduct:r,product:n,isLoading:c,clientId:a})=>{const{productId:l}=e,u=(0,D.useSelect)(e=>{const{getSettings:t}=e(A.store);return Boolean(t()?.isPreviewMode??!1)},[]),[g,b]=(0,i.useState)(!l),x=(0,A.useBlockProps)(),_=(0,D.useSelect)(e=>e("core/blocks").getBlockType(d.name),[]),v=(0,D.useSelect)(e=>u?e(F.PRODUCTS_STORE_NAME).getProducts({per_page:1}):null),f="object"==typeof o&&"woocommerce_rest_product_invalid_id"===o?.code;if((0,i.useEffect)(()=>{const o=v?v[0]?.id:null;o&&!l&&(t({...e,productId:o}),b(!1))},[e,l,v,t]),(0,i.useEffect)(()=>{f&&b(!0)},[f]),o&&!f)return(0,h.jsx)($,{className:"wc-block-editor-single-product-error",error:o,isLoading:c,onRetry:r});const k=f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s.A,{icon:z.A,className:"wc-block-editor-single-product__info-icon"}),(0,h.jsx)(m.__experimentalText,{children:(0,p.__)("Previously selected product is no longer available.","woocommerce")})]}):(0,h.jsx)(m.__experimentalText,{children:_.description}),j=f?()=>b(!1):void 0;return(0,h.jsx)("div",{...x,children:(0,h.jsxs)(E,{header:(0,p.__)("Single Product Block Error","woocommerce"),children:[(0,h.jsx)(ke,{setIsEditing:b,isEditing:g}),g?(0,h.jsxs)(m.Placeholder,{icon:w,label:_.title,className:"wc-block-editor-single-product",children:[(0,h.jsxs)(m.__experimentalHStack,{alignment:"center",children:[" ",k," "]}),(0,h.jsxs)("div",{className:"wc-block-editor-single-product__selection",children:[(0,h.jsx)(fe,{attributes:e,setAttributes:t,onChange:j}),!f&&(0,h.jsx)(m.Button,{variant:"secondary",onClick:()=>{b(!1)},children:(0,p.__)("Done","woocommerce")})]})]}):(0,h.jsxs)("div",{children:[(0,h.jsx)(A.InspectorControls,{children:(0,h.jsx)(m.PanelBody,{title:(0,p.__)("Product","woocommerce"),initialOpen:!1,children:(0,h.jsx)(fe,{attributes:e,setAttributes:t})})}),(0,h.jsx)(O,{productId:l}),(0,h.jsx)(Se,{clientId:a,product:n,isLoading:c})]})]})})}),Pe=[{attributes:d.attributes,supports:d.supports,save:()=>{const e=A.useBlockProps.save();return(0,h.jsx)("div",{...e,children:(0,h.jsx)(A.InnerBlocks.Content,{})})}}];(0,r.registerBlockType)(d,{icon:w,edit:Ce,save:()=>{const e=A.useBlockProps.save({className:"woocommerce"});return(0,h.jsx)("div",{...e,children:(0,h.jsx)(A.InnerBlocks.Content,{})})},deprecated:Pe})},35921:(e,t,o)=>{"use strict";o.d(t,{Hw:()=>h,Vo:()=>a,XK:()=>i,iI:()=>p,r7:()=>n,sW:()=>c});var r=o(15703),s=o(73993);const n=(0,r.getSetting)("wcBlocksConfig",{pluginUrl:"",productCount:0,defaultAvatar:"",restApiRoutes:{},wordCountType:"words"}),c=n.pluginUrl+"assets/images/",i=n.pluginUrl+"assets/client/blocks/",a=(r.STORE_PAGES.shop,r.STORE_PAGES.checkout,r.STORE_PAGES.checkout,r.STORE_PAGES.privacy,r.STORE_PAGES.privacy,r.STORE_PAGES.terms,r.STORE_PAGES.terms,r.STORE_PAGES.cart,r.STORE_PAGES.cart?.permalink),l=(r.STORE_PAGES.myaccount?.permalink?r.STORE_PAGES.myaccount.permalink:(0,r.getSetting)("wpLoginUrl","/wp-login.php"),(0,r.getSetting)("localPickupEnabled",!1),(0,r.getSetting)("shippingMethodsExist",!1),(0,r.getSetting)("shippingEnabled",!0),(0,r.getSettingWithCoercion)("countries",{},s.isObject)),d=(0,r.getSetting)("countryData",{}),m={...Object.fromEntries(Object.keys(d).filter(e=>!0===d[e].allowBilling).map(e=>{const t=l[e];return[e,(0,s.isString)(t)?t:""]})),...Object.fromEntries(Object.keys(d).filter(e=>!0===d[e].allowShipping).map(e=>{const t=l[e];return[e,(0,s.isString)(t)?t:""]}))},p=(Object.fromEntries(Object.keys(m).map(e=>[e,d[e].states||{}])),Object.fromEntries(Object.keys(m).map(e=>[e,d[e].locale||{}]))),u={address:["first_name","last_name","company","address_1","address_2","city","postcode","country","state","phone"],contact:["email"],order:[]},h=(0,r.getSetting)("addressFieldsLocations",u).address;(0,r.getSetting)("addressFieldsLocations",u).contact,(0,r.getSetting)("addressFieldsLocations",u).order,(0,r.getSetting)("additionalOrderFields",{}),(0,r.getSetting)("additionalContactFields",{}),(0,r.getSetting)("additionalAddressFields",{})},96484:(e,t,o)=>{"use strict";o.d(t,{S:()=>s});var r=o(15703);const s=()=>(0,r.getSetting)("experimentalWcRestApiV4",!1)},98516:(e,t,o)=>{"use strict";o.d(t,{Hw:()=>r.Hw,Sc:()=>s.S,Vo:()=>r.Vo,XK:()=>r.XK,iI:()=>r.iI,r7:()=>r.r7,sW:()=>r.sW});var r=o(35921),s=o(96484)},45893:()=>{},27539:()=>{},63120:()=>{},20415:()=>{},71939:()=>{},75022:()=>{},51609:e=>{"use strict";e.exports=window.React},10790:e=>{"use strict";e.exports=window.ReactJSXRuntime},14656:e=>{"use strict";e.exports=window.wc.blocksComponents},70910:e=>{"use strict";e.exports=window.wc.priceFormat},42435:e=>{"use strict";e.exports=window.wc.sanitize},47594:e=>{"use strict";e.exports=window.wc.wcBlocksData},62796:e=>{"use strict";e.exports=window.wc.wcBlocksSharedContext},41616:e=>{"use strict";e.exports=window.wc.wcBlocksSharedHocs},15703:e=>{"use strict";e.exports=window.wc.wcSettings},73993:e=>{"use strict";e.exports=window.wc.wcTypes},56004:e=>{"use strict";e.exports=window.wp.autop},94715:e=>{"use strict";e.exports=window.wp.blockEditor},56427:e=>{"use strict";e.exports=window.wp.components},29491:e=>{"use strict";e.exports=window.wp.compose},47143:e=>{"use strict";e.exports=window.wp.data},86087:e=>{"use strict";e.exports=window.wp.element},52619:e=>{"use strict";e.exports=window.wp.hooks},18537:e=>{"use strict";e.exports=window.wp.htmlEntities},27723:e=>{"use strict";e.exports=window.wp.i18n},20923:e=>{"use strict";e.exports=window.wp.isShallowEqual},5573:e=>{"use strict";e.exports=window.wp.primitives},49786:e=>{"use strict";e.exports=window.wp.styleEngine},69446:e=>{"use strict";e.exports=window.wp.wordcount}},c={};function i(e){var t=c[e];if(void 0!==t)return t.exports;var o=c[e]={exports:{}};return n[e](o,o.exports,i),o.exports}i.m=n,e=[],i.O=(t,o,r,s)=>{if(!o){var n=1/0;for(d=0;d<e.length;d++){for(var[o,r,s]=e[d],c=!0,a=0;a<o.length;a++)(!1&s||n>=s)&&Object.keys(i.O).every(e=>i.O[e](o[a]))?o.splice(a--,1):(c=!1,s<n&&(n=s));if(c){e.splice(d--,1);var l=r();void 0!==l&&(t=l)}}return t}s=s||0;for(var d=e.length;d>0&&e[d-1][2]>s;d--)e[d]=e[d-1];e[d]=[o,r,s]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var s=Object.create(null);i.r(s);var n={};t=t||[null,o({}),o([]),o(o)];for(var c=2&r&&e;"object"==typeof c&&!~t.indexOf(c);c=o(c))Object.getOwnPropertyNames(c).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,i.d(s,n),s},i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.f={},i.e=e=>Promise.all(Object.keys(i.f).reduce((t,o)=>(i.f[o](e,t),t),[])),i.u=e=>({345:"product-stock-indicator",462:"product-rating",2105:"product-title",2388:"product-price",2724:"product-sku",3895:"product-summary",4232:"product-image",4442:"product-sale-badge",7409:"product-button",8553:"product-rating-counter",8578:"product-rating-stars",8647:"product-average-rating"}[e]+".js?ver="+{345:"16d5a0415aaead7f19af",462:"3f8fe031903b042eedc4",2105:"d8f4aeb6e4114aef9503",2388:"4e5067f3b220a11dfa35",2724:"cd17e9deb9addd7f4680",3895:"2f4b70e162a2c9b23cb9",4232:"800f4e4551616e49686f",4442:"f1690c67bb890de2f776",7409:"be4a7e5bc68e617d09d0",8553:"942481ce707d4e78635c",8578:"8d2f76f81f637da20eb6",8647:"9ea362c941ff520f5acf"}[e]),i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r={},s="webpackWcBlocksMainJsonp:",i.l=(e,t,o,n)=>{if(r[e])r[e].push(t);else{var c,a;if(void 0!==o)for(var l=document.getElementsByTagName("script"),d=0;d<l.length;d++){var m=l[d];if(m.getAttribute("src")==e||m.getAttribute("data-webpack")==s+o){c=m;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",c.timeout=120,i.nc&&c.setAttribute("nonce",i.nc),c.setAttribute("data-webpack",s+o),c.src=e),r[e]=[t];var p=(t,o)=>{c.onerror=c.onload=null,clearTimeout(u);var s=r[e];if(delete r[e],c.parentNode&&c.parentNode.removeChild(c),s&&s.forEach(e=>e(o)),t)return t(o)},u=setTimeout(p.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=p.bind(null,c.onerror),c.onload=p.bind(null,c.onload),a&&document.head.appendChild(c)}},i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.j=5065,(()=>{var e;i.g.importScripts&&(e=i.g.location+"");var t=i.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var o=t.getElementsByTagName("script");if(o.length)for(var r=o.length-1;r>-1&&(!e||!/^http(s?):/.test(e));)e=o[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),(()=>{var e={5065:0};i.f.j=(t,o)=>{var r=i.o(e,t)?e[t]:void 0;if(0!==r)if(r)o.push(r[2]);else{var s=new Promise((o,s)=>r=e[t]=[o,s]);o.push(r[2]=s);var n=i.p+i.u(t),c=new Error;i.l(n,o=>{if(i.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var s=o&&("load"===o.type?"missing":o.type),n=o&&o.target&&o.target.src;c.message="Loading chunk "+t+" failed.\n("+s+": "+n+")",c.name="ChunkLoadError",c.type=s,c.request=n,r[1](c)}},"chunk-"+t,t)}},i.O.j=t=>0===e[t];var t=(t,o)=>{var r,s,[n,c,a]=o,l=0;if(n.some(t=>0!==e[t])){for(r in c)i.o(c,r)&&(i.m[r]=c[r]);if(a)var d=a(i)}for(t&&t(o);l<n.length;l++)s=n[l],i.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return i.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var a=i.O(void 0,[94],()=>i(7709));a=i.O(a),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["single-product"]=a})();
Save File
Cancel