index.js
1 lines
| 1 | import*as e from"@wordpress/interactivity";var t,n,o={d:function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},r=(t={getContext:function(){return e.getContext},getElement:function(){return e.getElement},store:function(){return e.store},useEffect:function(){return e.useEffect}},n={},o.d(n,t),n);(0,r.store)("surecart/line-item-details",{state:{get role(){return(0,r.getContext)()?.showToggle?"button":null},get tabindex(){return(0,r.getContext)()?.showToggle?"0":"-1"}},actions:{toggleDetailsExpanded(e){if((e=>"keydown"===e.type&&"Enter"!==e.key&&" "!==e.key)(e))return!0;const t=(0,r.getContext)();t&&t.showToggle&&(e?.preventDefault&&e.preventDefault(),t.detailsExpanded=!t.detailsExpanded)}},callbacks:{init(){const e=(0,r.getContext)();(0,r.useEffect)((()=>{const{ref:t}=(0,r.getElement)();if(!t||!e)return;const n=t.querySelector(".sc-cart-line-item-details__content");if(!n)return void(e.showToggle=!1);const o=()=>{const t=Math.max(Number(e.collapseAfter)||2,1),o=n.querySelectorAll(".sc-cart-line-item-variant__bundle-item");if(o.length)return e.hiddenCount=Math.max(o.length-t,0),void(e.showToggle=o.length>t);const r=window.getComputedStyle(n);let s=parseFloat(r.lineHeight);s&&!Number.isNaN(s)||(s=1.4*(parseFloat(r.fontSize)||14));const i=parseFloat(r.rowGap)||0,l=Math.round((n.scrollHeight+i)/(s+i));e.hiddenCount=0,e.showToggle=l>t};o();const s=new ResizeObserver(o);s.observe(n);const i=new MutationObserver(o);return i.observe(n,{childList:!0,subtree:!0}),()=>{s.disconnect(),i.disconnect()}}),[])}}}); |