You've already forked Atomcms-edit
2 lines
22 KiB
JavaScript
Executable File
2 lines
22 KiB
JavaScript
Executable File
(()=>{var N=Math.min,k=Math.max,H=Math.round,_=Math.floor,O=e=>({x:e,y:e});function Z(e,t,o){return k(e,N(t,o))}function j(e,t){return typeof e=="function"?e(t):e}function Y(e){return e.split("-")[0]}function ee(e){return e.split("-")[1]}function te(e){return e==="x"?"y":"x"}function re(e){return e==="y"?"height":"width"}function z(e){let t=e[0];return t==="t"||t==="b"?"y":"x"}function le(e){return te(z(e))}function Fe(e){return{top:0,right:0,bottom:0,left:0,...e}}function ce(e){return typeof e!="number"?Fe(e):{top:e,right:e,bottom:e,left:e}}function P(e){let{x:t,y:o,width:n,height:s}=e;return{width:n,height:s,top:o,left:t,right:t+n,bottom:o+s,x:t,y:o}}function ae(e,t,o){let{reference:n,floating:s}=e,l=z(t),i=le(t),r=re(i),c=Y(t),a=l==="y",d=n.x+n.width/2-s.width/2,u=n.y+n.height/2-s.height/2,h=n[r]/2-s[r]/2,f;switch(c){case"top":f={x:d,y:n.y-s.height};break;case"bottom":f={x:d,y:n.y+n.height};break;case"right":f={x:n.x+n.width,y:u};break;case"left":f={x:n.x-s.width,y:u};break;default:f={x:n.x,y:n.y}}switch(ee(t)){case"start":f[i]-=h*(o&&a?-1:1);break;case"end":f[i]+=h*(o&&a?-1:1);break}return f}async function fe(e,t){var o;t===void 0&&(t={});let{x:n,y:s,platform:l,rects:i,elements:r,strategy:c}=e,{boundary:a="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:h=!1,padding:f=0}=j(t,e),m=ce(f),w=r[h?u==="floating"?"reference":"floating":u],g=P(await l.getClippingRect({element:(o=await(l.isElement==null?void 0:l.isElement(w)))==null||o?w:w.contextElement||await(l.getDocumentElement==null?void 0:l.getDocumentElement(r.floating)),boundary:a,rootBoundary:d,strategy:c})),x=u==="floating"?{x:n,y:s,width:i.floating.width,height:i.floating.height}:i.reference,y=await(l.getOffsetParent==null?void 0:l.getOffsetParent(r.floating)),b=await(l.isElement==null?void 0:l.isElement(y))?await(l.getScale==null?void 0:l.getScale(y))||{x:1,y:1}:{x:1,y:1},L=P(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:x,offsetParent:y,strategy:c}):x);return{top:(g.top-L.top+m.top)/b.y,bottom:(L.bottom-g.bottom+m.bottom)/b.y,left:(g.left-L.left+m.left)/b.x,right:(L.right-g.right+m.right)/b.x}}var Me=50,de=async(e,t,o)=>{let{placement:n="bottom",strategy:s="absolute",middleware:l=[],platform:i}=o,r=i.detectOverflow?i:{...i,detectOverflow:fe},c=await(i.isRTL==null?void 0:i.isRTL(t)),a=await i.getElementRects({reference:e,floating:t,strategy:s}),{x:d,y:u}=ae(a,n,c),h=n,f=0,m={};for(let p=0;p<l.length;p++){let w=l[p];if(!w)continue;let{name:g,fn:x}=w,{x:y,y:b,data:L,reset:S}=await x({x:d,y:u,initialPlacement:n,placement:h,strategy:s,middlewareData:m,rects:a,platform:r,elements:{reference:e,floating:t}});d=y??d,u=b??u,m[g]={...m[g],...L},S&&f<Me&&(f++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(a=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:s}):S.rects),{x:d,y:u}=ae(a,h,c)),p=-1)}return{x:d,y:u,placement:h,strategy:s,middlewareData:m}};var $e=new Set(["left","top"]);async function Ne(e,t){let{placement:o,platform:n,elements:s}=e,l=await(n.isRTL==null?void 0:n.isRTL(s.floating)),i=Y(o),r=ee(o),c=z(o)==="y",a=$e.has(i)?-1:1,d=l&&c?-1:1,u=j(t,e),{mainAxis:h,crossAxis:f,alignmentAxis:m}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return r&&typeof m=="number"&&(f=r==="end"?m*-1:m),c?{x:f*d,y:h*a}:{x:h*a,y:f*d}}var ue=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var o,n;let{x:s,y:l,placement:i,middlewareData:r}=t,c=await Ne(t,e);return i===((o=r.offset)==null?void 0:o.placement)&&(n=r.arrow)!=null&&n.alignmentOffset?{}:{x:s+c.x,y:l+c.y,data:{...c,placement:i}}}}},he=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){let{x:o,y:n,placement:s,platform:l}=t,{mainAxis:i=!0,crossAxis:r=!1,limiter:c={fn:g=>{let{x,y}=g;return{x,y}}},...a}=j(e,t),d={x:o,y:n},u=await l.detectOverflow(t,a),h=z(Y(s)),f=te(h),m=d[f],p=d[h];if(i){let g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",y=m+u[g],b=m-u[x];m=Z(y,m,b)}if(r){let g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",y=p+u[g],b=p-u[x];p=Z(y,p,b)}let w=c.fn({...t,[f]:m,[h]:p});return{...w,data:{x:w.x-o,y:w.y-n,enabled:{[f]:i,[h]:r}}}}}};function G(){return typeof window<"u"}function F(e){return ge(e)?(e.nodeName||"").toLowerCase():"#document"}function v(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function A(e){var t;return(t=(ge(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function ge(e){return G()?e instanceof Node||e instanceof v(e).Node:!1}function R(e){return G()?e instanceof Element||e instanceof v(e).Element:!1}function T(e){return G()?e instanceof HTMLElement||e instanceof v(e).HTMLElement:!1}function me(e){return!G()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof v(e).ShadowRoot}function B(e){let{overflow:t,overflowX:o,overflowY:n,display:s}=C(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+o)&&s!=="inline"&&s!=="contents"}function pe(e){return/^(table|td|th)$/.test(F(e))}function I(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}var Ve=/transform|translate|scale|rotate|perspective|filter/,Be=/paint|layout|strict|content/,D=e=>!!e&&e!=="none",ne;function J(e){let t=R(e)?C(e):e;return D(t.transform)||D(t.translate)||D(t.scale)||D(t.rotate)||D(t.perspective)||!K()&&(D(t.backdropFilter)||D(t.filter))||Ve.test(t.willChange||"")||Be.test(t.contain||"")}function we(e){let t=E(e);for(;T(t)&&!M(t);){if(J(t))return t;if(I(t))return null;t=E(t)}return null}function K(){return ne==null&&(ne=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),ne}function M(e){return/^(html|body|#document)$/.test(F(e))}function C(e){return v(e).getComputedStyle(e)}function U(e){return R(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function E(e){if(F(e)==="html")return e;let t=e.assignedSlot||e.parentNode||me(e)&&e.host||A(e);return me(t)?t.host:t}function xe(e){let t=E(e);return M(t)?e.ownerDocument?e.ownerDocument.body:e.body:T(t)&&B(t)?t:xe(t)}function V(e,t,o){var n;t===void 0&&(t=[]),o===void 0&&(o=!0);let s=xe(e),l=s===((n=e.ownerDocument)==null?void 0:n.body),i=v(s);if(l){let r=q(i);return t.concat(i,i.visualViewport||[],B(s)?s:[],r&&o?V(r):[])}else return t.concat(s,V(s,[],o))}function q(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Re(e){let t=C(e),o=parseFloat(t.width)||0,n=parseFloat(t.height)||0,s=T(e),l=s?e.offsetWidth:o,i=s?e.offsetHeight:n,r=H(o)!==l||H(n)!==i;return r&&(o=l,n=i),{width:o,height:n,$:r}}function oe(e){return R(e)?e:e.contextElement}function W(e){let t=oe(e);if(!T(t))return O(1);let o=t.getBoundingClientRect(),{width:n,height:s,$:l}=Re(t),i=(l?H(o.width):o.width)/n,r=(l?H(o.height):o.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!r||!Number.isFinite(r))&&(r=1),{x:i,y:r}}var We=O(0);function Ce(e){let t=v(e);return!K()||!t.visualViewport?We:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function He(e,t,o){return t===void 0&&(t=!1),!o||t&&o!==v(e)?!1:t}function $(e,t,o,n){t===void 0&&(t=!1),o===void 0&&(o=!1);let s=e.getBoundingClientRect(),l=oe(e),i=O(1);t&&(n?R(n)&&(i=W(n)):i=W(e));let r=He(l,o,n)?Ce(l):O(0),c=(s.left+r.x)/i.x,a=(s.top+r.y)/i.y,d=s.width/i.x,u=s.height/i.y;if(l){let h=v(l),f=n&&R(n)?v(n):n,m=h,p=q(m);for(;p&&n&&f!==m;){let w=W(p),g=p.getBoundingClientRect(),x=C(p),y=g.left+(p.clientLeft+parseFloat(x.paddingLeft))*w.x,b=g.top+(p.clientTop+parseFloat(x.paddingTop))*w.y;c*=w.x,a*=w.y,d*=w.x,u*=w.y,c+=y,a+=b,m=v(p),p=q(m)}}return P({width:d,height:u,x:c,y:a})}function Q(e,t){let o=U(e).scrollLeft;return t?t.left+o:$(A(e)).left+o}function Oe(e,t){let o=e.getBoundingClientRect(),n=o.left+t.scrollLeft-Q(e,o),s=o.top+t.scrollTop;return{x:n,y:s}}function _e(e){let{elements:t,rect:o,offsetParent:n,strategy:s}=e,l=s==="fixed",i=A(n),r=t?I(t.floating):!1;if(n===i||r&&l)return o;let c={scrollLeft:0,scrollTop:0},a=O(1),d=O(0),u=T(n);if((u||!u&&!l)&&((F(n)!=="body"||B(i))&&(c=U(n)),u)){let f=$(n);a=W(n),d.x=f.x+n.clientLeft,d.y=f.y+n.clientTop}let h=i&&!u&&!l?Oe(i,c):O(0);return{width:o.width*a.x,height:o.height*a.y,x:o.x*a.x-c.scrollLeft*a.x+d.x+h.x,y:o.y*a.y-c.scrollTop*a.y+d.y+h.y}}function ze(e){return Array.from(e.getClientRects())}function Ie(e){let t=A(e),o=U(e),n=e.ownerDocument.body,s=k(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),l=k(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight),i=-o.scrollLeft+Q(e),r=-o.scrollTop;return C(n).direction==="rtl"&&(i+=k(t.clientWidth,n.clientWidth)-s),{width:s,height:l,x:i,y:r}}var ye=25;function Ue(e,t){let o=v(e),n=A(e),s=o.visualViewport,l=n.clientWidth,i=n.clientHeight,r=0,c=0;if(s){l=s.width,i=s.height;let d=K();(!d||d&&t==="fixed")&&(r=s.offsetLeft,c=s.offsetTop)}let a=Q(n);if(a<=0){let d=n.ownerDocument,u=d.body,h=getComputedStyle(u),f=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(n.clientWidth-u.clientWidth-f);m<=ye&&(l-=m)}else a<=ye&&(l+=a);return{width:l,height:i,x:r,y:c}}function Xe(e,t){let o=$(e,!0,t==="fixed"),n=o.top+e.clientTop,s=o.left+e.clientLeft,l=T(e)?W(e):O(1),i=e.clientWidth*l.x,r=e.clientHeight*l.y,c=s*l.x,a=n*l.y;return{width:i,height:r,x:c,y:a}}function be(e,t,o){let n;if(t==="viewport")n=Ue(e,o);else if(t==="document")n=Ie(A(e));else if(R(t))n=Xe(t,o);else{let s=Ce(e);n={x:t.x-s.x,y:t.y-s.y,width:t.width,height:t.height}}return P(n)}function Ae(e,t){let o=E(e);return o===t||!R(o)||M(o)?!1:C(o).position==="fixed"||Ae(o,t)}function je(e,t){let o=t.get(e);if(o)return o;let n=V(e,[],!1).filter(r=>R(r)&&F(r)!=="body"),s=null,l=C(e).position==="fixed",i=l?E(e):e;for(;R(i)&&!M(i);){let r=C(i),c=J(i);!c&&r.position==="fixed"&&(s=null),(l?!c&&!s:!c&&r.position==="static"&&!!s&&(s.position==="absolute"||s.position==="fixed")||B(i)&&!c&&Ae(e,i))?n=n.filter(d=>d!==i):s=r,i=E(i)}return t.set(e,n),n}function Ye(e){let{element:t,boundary:o,rootBoundary:n,strategy:s}=e,i=[...o==="clippingAncestors"?I(t)?[]:je(t,this._c):[].concat(o),n],r=be(t,i[0],s),c=r.top,a=r.right,d=r.bottom,u=r.left;for(let h=1;h<i.length;h++){let f=be(t,i[h],s);c=k(f.top,c),a=N(f.right,a),d=N(f.bottom,d),u=k(f.left,u)}return{width:a-u,height:d-c,x:u,y:c}}function Ge(e){let{width:t,height:o}=Re(e);return{width:t,height:o}}function Je(e,t,o){let n=T(t),s=A(t),l=o==="fixed",i=$(e,!0,l,t),r={scrollLeft:0,scrollTop:0},c=O(0);function a(){c.x=Q(s)}if(n||!n&&!l)if((F(t)!=="body"||B(s))&&(r=U(t)),n){let f=$(t,!0,l,t);c.x=f.x+t.clientLeft,c.y=f.y+t.clientTop}else s&&a();l&&!n&&s&&a();let d=s&&!n&&!l?Oe(s,r):O(0),u=i.left+r.scrollLeft-c.x-d.x,h=i.top+r.scrollTop-c.y-d.y;return{x:u,y:h,width:i.width,height:i.height}}function ie(e){return C(e).position==="static"}function ve(e,t){if(!T(e)||C(e).position==="fixed")return null;if(t)return t(e);let o=e.offsetParent;return A(e)===o&&(o=o.ownerDocument.body),o}function Se(e,t){let o=v(e);if(I(e))return o;if(!T(e)){let s=E(e);for(;s&&!M(s);){if(R(s)&&!ie(s))return s;s=E(s)}return o}let n=ve(e,t);for(;n&&pe(n)&&ie(n);)n=ve(n,t);return n&&M(n)&&ie(n)&&!J(n)?o:n||we(e)||o}var Ke=async function(e){let t=this.getOffsetParent||Se,o=this.getDimensions,n=await o(e.floating);return{reference:Je(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function qe(e){return C(e).direction==="rtl"}var Qe={convertOffsetParentRelativeRectToViewportRelativeRect:_e,getDocumentElement:A,getClippingRect:Ye,getOffsetParent:Se,getElementRects:Ke,getClientRects:ze,getDimensions:Ge,getScale:W,isElement:R,isRTL:qe};function Te(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ze(e,t){let o=null,n,s=A(e);function l(){var r;clearTimeout(n),(r=o)==null||r.disconnect(),o=null}function i(r,c){r===void 0&&(r=!1),c===void 0&&(c=1),l();let a=e.getBoundingClientRect(),{left:d,top:u,width:h,height:f}=a;if(r||t(),!h||!f)return;let m=_(u),p=_(s.clientWidth-(d+h)),w=_(s.clientHeight-(u+f)),g=_(d),y={rootMargin:-m+"px "+-p+"px "+-w+"px "+-g+"px",threshold:k(0,N(1,c))||1},b=!0;function L(S){let X=S[0].intersectionRatio;if(X!==c){if(!b)return i();X?i(!1,X):n=setTimeout(()=>{i(!1,1e-7)},1e3)}X===1&&!Te(a,e.getBoundingClientRect())&&i(),b=!1}try{o=new IntersectionObserver(L,{...y,root:s.ownerDocument})}catch{o=new IntersectionObserver(L,y)}o.observe(e)}return i(!0),l}function Le(e,t,o,n){n===void 0&&(n={});let{ancestorScroll:s=!0,ancestorResize:l=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:r=typeof IntersectionObserver=="function",animationFrame:c=!1}=n,a=oe(e),d=s||l?[...a?V(a):[],...t?V(t):[]]:[];d.forEach(g=>{s&&g.addEventListener("scroll",o,{passive:!0}),l&&g.addEventListener("resize",o)});let u=a&&r?Ze(a,o):null,h=-1,f=null;i&&(f=new ResizeObserver(g=>{let[x]=g;x&&x.target===a&&f&&t&&(f.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var y;(y=f)==null||y.observe(t)})),o()}),a&&!c&&f.observe(a),t&&f.observe(t));let m,p=c?$(e):null;c&&w();function w(){let g=$(e);p&&!Te(p,g)&&o(),p=g,m=requestAnimationFrame(w)}return o(),()=>{var g;d.forEach(x=>{s&&x.removeEventListener("scroll",o),l&&x.removeEventListener("resize",o)}),u?.(),(g=f)==null||g.disconnect(),f=null,c&&cancelAnimationFrame(m)}}var ke=ue;var Ee=he;var Pe=(e,t,o)=>{let n=new Map,s={platform:Qe,...o},l={...s.platform,_c:n};return de(e,t,{...s,platform:l})};var De=({areGroupsCollapsedByDefault:e,canTrackDeselectedRecords:t,currentSelectionLivewireProperty:o,maxSelectableRecords:n,selectsCurrentPageOnly:s,$wire:l})=>({areFiltersOpen:!1,checkboxClickController:null,groupVisibility:[],isLoading:!1,selectedRecords:new Set,deselectedRecords:new Set,isTrackingDeselectedRecords:!1,shouldCheckUniqueSelection:!0,lastCheckedRecord:null,livewireId:null,entangledSelectedRecords:o?l.$entangle(o):null,cleanUpFiltersDropdown:null,unsubscribeLivewireHook:null,init(){this.livewireId=this.$root.closest("[wire\\:id]")?.attributes["wire:id"].value,l.$on("deselectAllTableRecords",()=>this.deselectAllRecords()),l.$on("scrollToTopOfTable",()=>this.$root.scrollIntoView({block:"start",inline:"nearest"})),o&&(n!==1?this.selectedRecords=new Set(this.entangledSelectedRecords):this.selectedRecords=new Set(this.entangledSelectedRecords?[this.entangledSelectedRecords]:[])),this.$nextTick(()=>this.watchForCheckboxClicks()),this.unsubscribeLivewireHook=Livewire.hook("element.init",({component:i})=>{i.id===this.livewireId&&this.watchForCheckboxClicks()})},mountAction(...i){l.set("isTrackingDeselectedTableRecords",this.isTrackingDeselectedRecords,!1),l.set("selectedTableRecords",[...this.selectedRecords],!1),l.set("deselectedTableRecords",[...this.deselectedRecords],!1),l.mountAction(...i)},toggleSelectRecordsOnPage(){let i=this.getRecordsOnPage();if(this.areRecordsSelected(i)){this.deselectRecords(i);return}this.selectRecords(i)},toggleSelectRecords(i){this.areRecordsSelected(i)?this.deselectRecords(i):this.selectRecords(i)},getSelectedRecordsCount(){return this.isTrackingDeselectedRecords?(this.$refs.allSelectableRecordsCount?.value??this.deselectedRecords.size)-this.deselectedRecords.size:this.selectedRecords.size},getRecordsOnPage(){let i=[];for(let r of this.$root?.getElementsByClassName("fi-ta-record-checkbox")??[])i.push(r.value);return i},selectRecords(i){n===1&&(this.deselectAllRecords(),i=i.slice(0,1));for(let r of i)if(!this.isRecordSelected(r)){if(this.isTrackingDeselectedRecords){this.deselectedRecords.delete(r);continue}this.selectedRecords.add(r)}this.updatedSelectedRecords()},deselectRecords(i){for(let r of i){if(this.isTrackingDeselectedRecords){this.deselectedRecords.add(r);continue}this.selectedRecords.delete(r)}this.updatedSelectedRecords()},updatedSelectedRecords(){if(n!==1){this.entangledSelectedRecords=[...this.selectedRecords];return}this.entangledSelectedRecords=[...this.selectedRecords][0]??null},toggleSelectedRecord(i){if(this.isRecordSelected(i)){this.deselectRecords([i]);return}this.selectRecords([i])},async selectAllRecords(){if(!t||s){this.isLoading=!0,this.selectedRecords=new Set(await l.getAllSelectableTableRecordKeys()),this.updatedSelectedRecords(),this.isLoading=!1;return}this.isTrackingDeselectedRecords=!0,this.selectedRecords=new Set,this.deselectedRecords=new Set,this.updatedSelectedRecords()},canSelectAllRecords(){if(s){let c=this.getRecordsOnPage();return!this.areRecordsSelected(c)&&this.areRecordsToggleable(c)}let i=parseInt(this.$refs.allSelectableRecordsCount?.value);if(!i)return!1;let r=this.getSelectedRecordsCount();return i===r?!1:n===null||i<=n},deselectAllRecords(){this.isTrackingDeselectedRecords=!1,this.selectedRecords=new Set,this.deselectedRecords=new Set,this.updatedSelectedRecords()},isRecordSelected(i){return this.isTrackingDeselectedRecords?!this.deselectedRecords.has(i):this.selectedRecords.has(i)},areRecordsSelected(i){return i.every(r=>this.isRecordSelected(r))},areRecordsToggleable(i){if(n===null||n===1)return!0;let r=i.filter(c=>this.isRecordSelected(c));return r.length===i.length?!0:this.getSelectedRecordsCount()+(i.length-r.length)<=n},toggleCollapseGroup(i){this.isGroupCollapsed(i)?e?this.groupVisibility.push(i):this.groupVisibility.splice(this.groupVisibility.indexOf(i),1):e?this.groupVisibility.splice(this.groupVisibility.indexOf(i),1):this.groupVisibility.push(i)},isGroupCollapsed(i){return e?!this.groupVisibility.includes(i):this.groupVisibility.includes(i)},resetCollapsedGroups(){this.groupVisibility=[]},watchForCheckboxClicks(){this.checkboxClickController&&this.checkboxClickController.abort(),this.checkboxClickController=new AbortController;let{signal:i}=this.checkboxClickController;this.$root?.addEventListener("click",r=>r.target?.matches(".fi-ta-record-checkbox")&&this.handleCheckboxClick(r,r.target),{signal:i})},handleCheckboxClick(i,r){if(!this.lastChecked){this.lastChecked=r;return}if(i.shiftKey){let c=Array.from(this.$root?.getElementsByClassName("fi-ta-record-checkbox")??[]);if(!c.includes(this.lastChecked)){this.lastChecked=r;return}let a=c.indexOf(this.lastChecked),d=c.indexOf(r),u=[a,d].sort((f,m)=>f-m),h=[];for(let f=u[0];f<=u[1];f++)h.push(c[f].value);if(r.checked){if(!this.areRecordsToggleable(h)){r.checked=!1,this.deselectRecords([r.value]);return}this.selectRecords(h)}else this.deselectRecords(h)}this.lastChecked=r},toggleFiltersDropdown(){if(this.areFiltersOpen=!this.areFiltersOpen,this.areFiltersOpen){let i=Le(this.$refs.filtersTriggerActionContainer,this.$refs.filtersContentContainer,async()=>{let{x:a,y:d}=await Pe(this.$refs.filtersTriggerActionContainer,this.$refs.filtersContentContainer,{placement:"bottom-end",middleware:[ke(8),Ee({padding:8})]});Object.assign(this.$refs.filtersContentContainer.style,{left:`${a}px`,top:`${d}px`})}),r=a=>{let d=this.$refs.filtersTriggerActionContainer,u=this.$refs.filtersContentContainer;u&&u.contains(a.target)||d&&d.contains(a.target)||(this.areFiltersOpen=!1,this.cleanUpFiltersDropdown&&(this.cleanUpFiltersDropdown(),this.cleanUpFiltersDropdown=null))};document.addEventListener("mousedown",r),document.addEventListener("touchstart",r,{passive:!0});let c=a=>{a.key==="Escape"&&r(a)};document.addEventListener("keydown",c),this.cleanUpFiltersDropdown=()=>{i(),document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r,{passive:!0}),document.removeEventListener("keydown",c)}}else this.cleanUpFiltersDropdown&&(this.cleanUpFiltersDropdown(),this.cleanUpFiltersDropdown=null)},destroy(){this.unsubscribeLivewireHook?.()}});function se({columns:e,isLive:t}){return{error:void 0,isLoading:!1,deferredColumns:[],columns:e,isLive:t,hasReordered:!1,init(){if(!this.columns||this.columns.length===0){this.columns=[];return}this.deferredColumns=JSON.parse(JSON.stringify(this.columns)),this.$watch("columns",()=>{this.resetDeferredColumns()})},get groupedColumns(){let o={};return this.deferredColumns.filter(n=>n.type==="group").forEach(n=>{o[n.name]=this.calculateGroupedColumns(n)}),o},calculateGroupedColumns(o){if((o?.columns?.filter(r=>!r.isHidden)??[]).length===0)return{hidden:!0,checked:!1,disabled:!1,indeterminate:!1};let s=o.columns.filter(r=>!r.isHidden&&r.isToggleable!==!1);if(s.length===0)return{checked:!0,disabled:!0,indeterminate:!1};let l=s.filter(r=>r.isToggled).length,i=o.columns.filter(r=>!r.isHidden&&r.isToggleable===!1);return l===0&&i.length>0?{checked:!0,disabled:!1,indeterminate:!0}:l===0?{checked:!1,disabled:!1,indeterminate:!1}:l===s.length?{checked:!0,disabled:!1,indeterminate:!1}:{checked:!0,disabled:!1,indeterminate:!0}},getColumn(o,n=null){return n?this.deferredColumns.find(l=>l.type==="group"&&l.name===n)?.columns?.find(l=>l.name===o):this.deferredColumns.find(s=>s.name===o)},toggleGroup(o){let n=this.deferredColumns.find(c=>c.type==="group"&&c.name===o);if(!n?.columns)return;let s=this.calculateGroupedColumns(n);if(s.disabled)return;let i=n.columns.filter(c=>c.isToggleable!==!1).some(c=>c.isToggled),r=s.indeterminate?!0:!i;n.columns.filter(c=>c.isToggleable!==!1).forEach(c=>{c.isToggled=r}),this.deferredColumns=[...this.deferredColumns],this.isLive&&this.applyTableColumnManager()},toggleColumn(o,n=null){let s=this.getColumn(o,n);!s||s.isToggleable===!1||(s.isToggled=!s.isToggled,this.deferredColumns=[...this.deferredColumns],this.isLive&&this.applyTableColumnManager())},reorderColumns(o){let n=o.map(s=>s.split("::"));this.reorderTopLevel(n),this.hasReordered=!0,this.isLive&&this.applyTableColumnManager()},reorderGroupColumns(o,n){let s=this.deferredColumns.find(r=>r.type==="group"&&r.name===n);if(!s)return;let l=o.map(r=>r.split("::")),i=[];l.forEach(([r,c])=>{let a=s.columns.find(d=>d.name===c);a&&i.push(a)}),s.columns=i,this.deferredColumns=[...this.deferredColumns],this.hasReordered=!0,this.isLive&&this.applyTableColumnManager()},reorderTopLevel(o){let n=this.deferredColumns,s=[];o.forEach(([l,i])=>{let r=n.find(c=>l==="group"?c.type==="group"&&c.name===i:l==="column"?c.type!=="group"&&c.name===i:!1);r&&s.push(r)}),this.deferredColumns=s},async applyTableColumnManager(){this.isLoading=!0;try{this.columns=JSON.parse(JSON.stringify(this.deferredColumns)),await this.$wire.call("applyTableColumnManager",this.columns,this.hasReordered),this.hasReordered=!1,this.error=void 0}catch(o){this.error="Failed to update column visibility",console.error("Table toggle columns error:",o)}finally{this.isLoading=!1}},resetDeferredColumns(){this.deferredColumns=JSON.parse(JSON.stringify(this.columns)),this.hasReordered=!1}}}document.addEventListener("alpine:init",()=>{window.Alpine.data("filamentTable",De),window.Alpine.data("filamentTableColumnManager",se)});})();
|