Files

1 line
6.8 KiB
JavaScript
Raw Permalink Normal View History

2026-10-19 17:33:22 +03:00
function $({statePath:l,isCollapsed:c,collapseKey:f}){return{isCollapsed:f?Alpine.$persist(c).as(f):c,collapseFromEvent(m){m.detail===l&&(this.isCollapsed=!0)},expandFromEvent(m){m.detail===l&&(this.isCollapsed=!1)},expand(){this.isCollapsed=!1},toggleCollapsed(){this.isCollapsed=!this.isCollapsed},get itemClasses(){return{"fi-collapsed":this.isCollapsed}}}}function x({schemaComponent:l,moveUpAction:c,moveDownAction:f,reorderAction:m,message:y,hasCustomReorderAction:w}){let A=e=>JSON.stringify({name:e?.name,arguments:e?.arguments,context:e?.context});return{pending:null,frame:null,destroyed:!1,listeners:[],removeCommitHook:null,init(){let e=(t,s,d,g=!0)=>{t.addEventListener(s,d,g),this.listeners.push(()=>t.removeEventListener(s,d,g))};e(document,"pointerdown",t=>{this.pending?.control?.contains(t.target)||this.relinquishFocus()}),e(document,"keydown",t=>{t.key==="Tab"&&this.relinquishFocus()}),e(document,"focusin",t=>{this.pending&&t.target!==this.pending.control&&this.relinquishFocus()}),e(this.$root,"click",t=>{let s=t.target.closest("[data-reorder-direction]");if(!(!s||!this.owns(s))){if(this.pending){t.preventDefault(),t.stopImmediatePropagation();return}!s.dataset.reorderAction?.startsWith("mountAction(")||s.getAttribute("wire:click")!==s.dataset.reorderAction||s.getAttributeNames().some(d=>d==="wire:confirm"||d.startsWith("wire:confirm."))||s.disabled||this.begin(s.closest("[x-sortable-item]").getAttribute("x-sortable-item"),s.dataset.reorderDirection,s)}}),e(this.$root,"start",t=>{t.target===this.$refs.reorderItems&&this.begin(t.item.getAttribute("x-sortable-item"),"drag")}),e(this.$root,"end",t=>{if(t.target===this.$refs.reorderItems){if(t.oldDraggableIndex===t.newDraggableIndex){this.finish(),t.stopImmediatePropagation();return}this.setSortingDisabled(!0)}}),this.removeCommitHook=Livewire.hook("commit",({component:t,commit:s,succeed:d,fail:g})=>{let i=this.pending;if(t.id!==this.$wire.$id)return;let n=[];for(let r=this.$root;r&&!(r.hasAttribute("wire:id")&&r.getAttribute("wire:id")!==t.id);r=r.parentElement){let u=r.getAttribute("wire:partial");if(u&&n.push(u),r===t.el)break}let b=r=>r.html||n.some(u=>r.partials?.[u]);if(d(({effects:r})=>{this.pending===i&&(i&&(!i.synchronizing||!b(r))||this.schedule(()=>{this.destroyed||!this.$root.isConnected||(this.updateHandles(),i?.synchronizing&&this.isCurrent(i)&&this.finish())}))}),!i||i.synchronizing)return;let a=t.canonical.mountedActions??[],o=r=>r?.context?.schemaComponent===l&&r.name===i.action&&(i.direction==="drag"||String(r.arguments?.item)===i.item),C=a.some(o)&&!o(a.at(-1));if(!s.calls.some(r=>r.method==="mountAction"?o({name:r.params[0],arguments:r.params[1],context:r.params[2]}):["callMountedAction","unmountAction"].includes(r.method)&&a.some(o)))return;let S=s.calls.some(r=>r.method==="unmountAction");d(({effects:r})=>{if(!this.isCurrent(i))return;let u=t.canonical.mountedActions??[],I=u.some(o);for(let[h,p]of i.reopenedModals??[])A(u[h])!==p&&i.reopenedModals.delete(h);if(I){i.focus=!1,i.modal=!0,this.setSortingDisabled(!0);let h=u.length-1;u.length<a.length&&i.reopenedModals?.has(h)&&this.schedule(()=>{if(!this.isCurrent(i))return;let p=t.canonical.mountedActions??[];p.length===h+1&&A(p[h])===i.reopenedModals.get(h)&&this.$dispatch("open-modal",{id:`fi-${t.id}-action-${h}`})});return}if(!b(r)||C){this.resynchronize(i);return}this.schedule(()=>this.reconcile(i))}),g(()=>{this.isCurrent(i)&&(i.focus=!1,i.modal&&S&&(i.reopenedModals??(i.reopenedModals=new Map),i.reopenedModals.set(a.length-1,A(a.at(-1))),this.$dispatch("open-modal",{id:`fi-${t.id}-action-${a.length-1}`})),!i.modal&&(i.direction==="drag"?this.resynchronize(i):this.finish()))})}),this.updateHandles()},owns(e){return e.closest("[data-reorder-owner]")===this.$root},order(){return JSON.parse(this.$root.dataset.reorderItems)},reorder(e){e.target===this.$refs.reorderItems&&this.$wire.mountAction(m,{items:e.target.sortable.toArray()},{schemaComponent:l})},begin(e,t,s=null){this.pending={item:e,direction:t,control:s,focus:!s?.hasAttribute("data-reorder-hidden")&&document.activeElement===s,before:this