theme.keycloak.v2.admin.resources.assets.DraggableTable-yOogAvJ0.js Maven / Gradle / Ivy
import{jsxs as I,jsx as i}from"react/jsx-runtime";import{s as m}from"./DataListItemRow-BC0LurDd.js";import{useRef as $,useState as j,useMemo as N}from"react";import{a as V,cQ as o}from"./main-C7ps2lmX.js";import{U as B,V as K,W as C,X as A,Y as M,Z as p,a2 as Q}from"./Td-D2hVFK0Z.js";function z({keyField:g,columns:u,data:f,actions:T,onDragFinish:y,...L}){const{t:h}=V(),s=$(null),[a,c]=j({draggedItemId:"",draggingToItemIndex:-1,dragging:!1,tempItemOrder:[""]}),b=N(()=>f.map(e=>o(e,g)),[f]),O=e=>{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",e.currentTarget.id);const r=e.currentTarget.id;e.currentTarget.classList.add(m.modifiers.ghostRow),e.currentTarget.setAttribute("aria-grabbed","true"),c({...a,draggedItemId:r,dragging:!0})},v=(e,r,t)=>{const n=e.indexOf(r);if(n===t)return e;const d=e.splice(n,1);return e.splice(t,0,d[0]),e},x=e=>{if(!s.current)return;const r=s.current,t=Array.from(r.children);if(!t.map(n=>n.id).every((n,d)=>n===e[d])){for(;r.firstChild;)r.removeChild(r.lastChild);e.forEach(n=>{r.appendChild(t.find(d=>d.id===n))})}},w=()=>{Array.from(s.current?.children||[]).forEach(e=>{e.classList.remove(m.modifiers.ghostRow),e.setAttribute("aria-grabbed","false")}),c({...a,draggedItemId:"",draggingToItemIndex:-1,dragging:!1})},E=e=>{D(e)||(x(b),c({...a,draggingToItemIndex:-1}))},D=e=>{const r=s.current.getBoundingClientRect();return e.clientX>r.x&&e.clientXr.y&&e.clientY{D(e)?y(a.draggedItemId,a.tempItemOrder):w()},R=e=>{e.preventDefault();const t=e.target.closest("tr");if(!t||s.current&&!s.current.contains(t)||t.id===a.draggedItemId)return null;{const n=t.id,d=Array.from(s.current?.children||[]).findIndex(l=>l.id===n);if(d!==a.draggingToItemIndex){const l=v(b,a.draggedItemId,d);x(l),c({...a,draggingToItemIndex:d,tempItemOrder:l})}}},X=e=>{const r=e.target;r.classList.remove(m.modifiers.ghostRow),r.setAttribute("aria-grabbed","false"),c({...a,draggedItemId:"",draggingToItemIndex:-1,dragging:!1})},Y=e=>{if(e.thTooltipText)return{popover:i("div",{children:h(e.thTooltipText)}),ariaLabel:h(e.thTooltipText)}};return I(B,{"aria-label":"Draggable table",className:a.dragging?m.modifiers.dragOver:"",...L,children:[i(K,{children:I(C,{children:[i(A,{"aria-hidden":"true"}),u.map(e=>i(A,{info:Y(e),width:e.width,modifier:"fitContent",children:h(e.displayKey||e.name)},e.name))]})}),i(M,{ref:s,onDragOver:R,onDrop:R,onDragLeave:E,children:f.map(e=>I(C,{id:o(e,g),draggable:!0,onDrop:S,onDragEnd:X,onDragStart:O,children:[i(p,{draggableRow:{id:`draggable-row-${o(e,g)}`}}),u.map(r=>i(p,{dataLabel:r.name,children:r.cellRenderer?r.cellRenderer(e):o(e,r.name)},`${o(e,g)}_${r.name}`)),T&&i(p,{isActionCell:!0,children:i(Q,{items:T.map(({isActionable:r,...t})=>r?{...t,isDisabled:!r(e)}:t),rowData:e})})]},o(e,g)))})]})}export{z as D};
//# sourceMappingURL=DraggableTable-yOogAvJ0.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy