40167-vm/wp-content/plugins/woocommerce/assets/client/blocks/add-to-cart-with-options-variation-selector-attribute-options.js
2026-05-30 14:06:18 +00:00

1 line
8.1 KiB
JavaScript

(()=>{var e,t,o,r={1749:(e,t,o)=>{"use strict";const r=window.wp.blocks;var i=o(7871),l=o(4064);const n=JSON.parse('{"name":"woocommerce/add-to-cart-with-options-variation-selector-attribute-options","title":"Variation Selector: Attribute Options (Beta)","description":"Display the attribute options associated with a variable product.","category":"woocommerce-product-elements","keywords":["WooCommerce"],"ancestor":["woocommerce/add-to-cart-with-options-variation-selector-attribute"],"attributes":{"optionStyle":{"type":"string","enum":["pills","dropdown"],"default":"pills"},"autoselect":{"type":"boolean","default":false},"disabledAttributesAction":{"type":"string","enum":["disable","hide"],"default":"disable"}},"textdomain":"woocommerce","apiVersion":3,"$schema":"https://schemas.wp.org/trunk/block.json","supports":{"inserter":false,"interactivity":true},"usesContext":["woocommerce/attributeId","woocommerce/attributeName","woocommerce/attributeTerms"],"style":"file:../woocommerce/add-to-cart-with-options-variation-selector-attribute-options-style.css"}');var a=o(4921);const s=window.wc.wcBlocksSharedContext;var c=o(7723);const d=window.wp.blockEditor,u=window.wp.components;var p=o(6087),b=o(790);function m({id:e,options:t}){return(0,b.jsx)("ul",{id:e,className:"wc-block-add-to-cart-with-options-variation-selector-attribute-options__pills",children:t.map((e,t)=>(0,b.jsx)("li",{className:(0,a.A)("wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill",{"wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--selected":0===t,"wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--disabled":e.disabled}),children:e.label},e.value))})}o(8180),(0,r.registerBlockType)(n,{edit:function(e){const{attributes:t,setAttributes:o}=e,{className:r,optionStyle:i,autoselect:l,disabledAttributesAction:n}=t,a=(0,d.useBlockProps)({className:r});((e,t)=>{const o=(0,p.useRef)(null);(0,p.useEffect)(()=>{let r=document.querySelector(".editor-styles-wrapper");if(!r){const e=document.querySelector(".edit-site-visual-editor__editor-canvas");if(!(e&&e instanceof HTMLIFrameElement))return;const t=e.contentDocument||e.contentWindow?.document;if(!t)return;r=t.querySelector(".editor-styles-wrapper")}if(!r)return;const i=window.getComputedStyle(r),l=i?.backgroundColor,n=i?.color;if(!l||!n)return;const a=`${e}-editor-theme-colors`;let s=r.querySelector(`#${a}`);s||(s=document.createElement("style"),s.id=a,r.appendChild(s)),o.current=s;const c=t({editorBackgroundColor:l,editorColor:n});s.textContent=c;const d=new MutationObserver(()=>{const e=window.getComputedStyle(r),i=e?.backgroundColor,a=e?.color;if(i!==l||a!==n){const e=t({editorBackgroundColor:i,editorColor:a});o.current&&(o.current.textContent=e)}});return d.observe(r,{attributes:!0,attributeFilter:["class"]}),()=>{d.disconnect(),o.current&&o.current.parentNode&&o.current.parentNode.removeChild(o.current)}},[t,e])})("add-to-cart-with-options-variation-selector-attribute-options",({editorBackgroundColor:e,editorColor:t})=>`\n\t\t\t:where(.wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill--selected) {\n\t\t\t\t--pill-color: ${e};\n\t\t\t\t--pill-background-color: ${t};\n\t\t\t}\n\t\t`);const{data:w}=(0,s.useCustomDataContext)("attribute");if(!w)return null;const h=w.terms.map((e,t)=>({value:e.slug,label:e.name,disabled:t>1&&t===w.terms.length-1}));return(0,b.jsxs)("div",{...a,children:[(0,b.jsxs)(d.InspectorControls,{children:[(0,b.jsx)(u.__experimentalToolsPanel,{label:(0,c.__)("Style","woocommerce"),resetAll:()=>o({optionStyle:"pills"}),children:(0,b.jsx)(u.__experimentalToolsPanelItem,{hasValue:()=>"pills"!==i,label:(0,c.__)("Style","woocommerce"),onDeselect:()=>o({optionStyle:"pills"}),isShownByDefault:!0,children:(0,b.jsxs)(u.__experimentalToggleGroupControl,{label:(0,c.__)("Style","woocommerce"),value:i,onChange:e=>{"pills"!==e&&"dropdown"!==e||o({optionStyle:e})},isBlock:!0,hideLabelFromVision:!0,size:"__unstable-large",children:[(0,b.jsx)(u.__experimentalToggleGroupControlOption,{value:"pills",label:(0,c.__)("Pills","woocommerce")}),(0,b.jsx)(u.__experimentalToggleGroupControlOption,{value:"dropdown",label:(0,c.__)("Dropdown","woocommerce")})]})})}),(0,b.jsxs)(u.__experimentalToolsPanel,{label:(0,c.__)("Auto-select","woocommerce"),resetAll:()=>o({autoselect:!1,disabledAttributesAction:"disable"}),children:[(0,b.jsx)(u.__experimentalToolsPanelItem,{label:(0,c.__)("Auto-select when only one option is available","woocommerce"),hasValue:()=>l,onDeselect:()=>o({autoselect:!1}),isShownByDefault:!0,children:(0,b.jsx)(u.ToggleControl,{label:(0,c.__)("Auto-select when only one option is available","woocommerce"),help:(0,c.__)("Automatically select options on page load or after the shopper changes attributes, when only one valid choice is available.","woocommerce"),checked:l,onChange:()=>o({autoselect:!l}),__nextHasNoMarginBottom:!0})}),(0,b.jsx)(u.__experimentalToolsPanelItem,{label:(0,c.__)("Invalid options","woocommerce"),hasValue:()=>"disable"!==n,onDeselect:()=>o({disabledAttributesAction:"disable"}),isShownByDefault:!0,children:(0,b.jsxs)(u.__experimentalToggleGroupControl,{label:(0,c.__)("Invalid options","woocommerce"),help:(0,c.__)("Control the display of invalid options.","woocommerce"),value:n,onChange:e=>{"hide"!==e&&"disable"!==e||o({disabledAttributesAction:e})},isBlock:!0,size:"__unstable-large",children:[(0,b.jsx)(u.__experimentalToggleGroupControlOption,{value:"disable",label:(0,c.__)("Grayed-out","woocommerce")}),(0,b.jsx)(u.__experimentalToggleGroupControlOption,{value:"hide",label:(0,c.__)("Hidden","woocommerce")})]})})]})]}),(0,b.jsx)(u.Disabled,{children:"dropdown"===i?(0,b.jsx)("select",{id:w.taxonomy,className:"wc-block-add-to-cart-with-options-variation-selector-attribute-options__dropdown",children:h.map(e=>(0,b.jsx)("option",{value:e.value,children:e.label},e.value))}):(0,b.jsx)(m,{id:w.taxonomy,options:h})})]})},attributes:n.attributes,icon:{src:(0,b.jsx)(i.A,{icon:l.A})},save:()=>null})},8180:()=>{},790:e=>{"use strict";e.exports=window.ReactJSXRuntime},6087:e=>{"use strict";e.exports=window.wp.element},7723:e=>{"use strict";e.exports=window.wp.i18n},5573:e=>{"use strict";e.exports=window.wp.primitives}},i={};function l(e){var t=i[e];if(void 0!==t)return t.exports;var o=i[e]={exports:{}};return r[e](o,o.exports,l),o.exports}l.m=r,e=[],l.O=(t,o,r,i)=>{if(!o){var n=1/0;for(d=0;d<e.length;d++){for(var[o,r,i]=e[d],a=!0,s=0;s<o.length;s++)(!1&i||n>=i)&&Object.keys(l.O).every(e=>l.O[e](o[s]))?o.splice(s--,1):(a=!1,i<n&&(n=i));if(a){e.splice(d--,1);var c=r();void 0!==c&&(t=c)}}return t}i=i||0;for(var d=e.length;d>0&&e[d-1][2]>i;d--)e[d]=e[d-1];e[d]=[o,r,i]},l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},o=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,l.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 i=Object.create(null);l.r(i);var n={};t=t||[null,o({}),o([]),o(o)];for(var a=2&r&&e;"object"==typeof a&&!~t.indexOf(a);a=o(a))Object.getOwnPropertyNames(a).forEach(t=>n[t]=()=>e[t]);return n.default=()=>e,l.d(i,n),i},l.d=(e,t)=>{for(var o in t)l.o(t,o)&&!l.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.j=277,(()=>{var e={277:0};l.O.j=t=>0===e[t];var t=(t,o)=>{var r,i,[n,a,s]=o,c=0;if(n.some(t=>0!==e[t])){for(r in a)l.o(a,r)&&(l.m[r]=a[r]);if(s)var d=s(l)}for(t&&t(o);c<n.length;c++)i=n[c],l.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return l.O(d)},o=globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[];o.forEach(t.bind(null,0)),o.push=t.bind(null,o.push.bind(o))})();var n=l.O(void 0,[94],()=>l(1749));n=l.O(n),((this.wc=this.wc||{}).blocks=this.wc.blocks||{})["add-to-cart-with-options-variation-selector-attribute-options"]=n})();