UNPKG

@react-querybuilder/dnd

Version:

Drag-and-drop-enabled version of react-querybuilder (DnD-library-agnostic)

2 lines 4.29 kB
const e=require("./dndLogic-Bisek_7m.js");let t=require("react");t=e.c(t);let n=require("react-querybuilder");const r=()=>typeof window<`u`&&`ontouchstart`in window||typeof navigator<`u`&&navigator.maxTouchPoints>0;let i;const a=()=>(i||(i=new Image,i.src=`data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==`),i),o=[`rule`,`ruleGroup`],s=(t,r,i)=>i(()=>({type:r,item:()=>({...(0,n.findPath)(t.path,t.schema.getQuery()),path:t.path,qbId:t.schema.qbId}),canDrag:!t.disabled,previewOptions:{captureDraggingState:!!t.hideDefaultDragPreview},collect:e=>({isDragging:!t.disabled&&e.isDragging(),dragMonitorId:e.getHandlerId()??``}),end:(n,r)=>{e.o({item:n,dropResult:r.getDropResult(),schema:t.schema,actions:t.actions,copyModeModifierKey:t.copyModeModifierKey,groupModeModifierKey:t.groupModeModifierKey,onRuleDrop:t.onRuleDrop})}}),[t.actions.groupRule,t.actions.moveRule,t.disabled,t.path]),c=n=>{let{useDrag:i,useDrop:c,DndProvider:l,DndContext:u}=n,d=n.ReactDndBackend;return d||=r()?n.TouchBackend??n.HTML5Backend:n.HTML5Backend??n.TouchBackend,{DndProvider:({debugMode:e,children:n})=>t.createElement(l,{backend:d,debugMode:e},t.createElement(u.Consumer,null,()=>t.createElement(t.Fragment,null,n))),useRuleDnD:n=>{let r=(0,t.useRef)(null),l=(0,t.useRef)(null),[{isDragging:u,dragMonitorId:d},f,p]=s(n,`rule`,i),[{isOver:m,dropMonitorId:h,dropEffect:g,groupItems:_,dropNotAllowed:v},y]=c(()=>({accept:o,canDrop:t=>e.r({dragging:t,path:n.path,schema:n.schema,canDrop:n.canDrop,groupModeModifierKey:n.groupModeModifierKey,disabled:n.disabled,rule:n.rule}),collect:t=>({dropNotAllowed:t.isOver()&&!t.canDrop(),isOver:t.canDrop()&&t.isOver(),dropMonitorId:t.getHandlerId()??``,dropEffect:e.s(n.copyModeModifierKey)?`copy`:`move`,groupItems:e.s(n.groupModeModifierKey)}),drop:()=>e.t({type:`rule`,path:n.path,schema:n.schema,copyModeModifierKey:n.copyModeModifierKey,groupModeModifierKey:n.groupModeModifierKey})}),[n.disabled,n.actions.moveRule,n.path,n.canDrop,n.rule,n.schema]);return t.useEffect(()=>{f(l),y(r),p(n.hideDefaultDragPreview?a():r)},[f,y,n.hideDefaultDragPreview,p]),{isDragging:u,dragMonitorId:d,isOver:m,dropMonitorId:h,dndRef:r,dragRef:l,dropEffect:g,groupItems:_,dropNotAllowed:v}},useRuleGroupDnD:n=>{let r=(0,t.useRef)(null),l=(0,t.useRef)(null),u=(0,t.useRef)(null),[{isDragging:d,dragMonitorId:f},p,m]=s(n,`ruleGroup`,i),[{isOver:h,dropMonitorId:g,dropEffect:_,groupItems:v,dropNotAllowed:y},b]=c(()=>({accept:o,canDrop:t=>e.i({dragging:t,path:n.path,schema:n.schema,canDrop:n.canDrop,disabled:n.disabled,ruleGroup:n.ruleGroup}),collect:t=>({dropNotAllowed:t.isOver()&&!t.canDrop(),isOver:t.canDrop()&&t.isOver(),dropMonitorId:t.getHandlerId()??``,dropEffect:e.s(n.copyModeModifierKey)?`copy`:`move`,groupItems:e.s(n.groupModeModifierKey)}),drop:()=>e.t({type:`ruleGroup`,path:n.path,schema:n.schema,copyModeModifierKey:n.copyModeModifierKey,groupModeModifierKey:n.groupModeModifierKey})}),[n.disabled,n.actions.groupRule,n.actions.moveRule,n.path,n.canDrop,n.ruleGroup,n.schema]);return t.useEffect(()=>{n.path.length>0&&(p(l),m(n.hideDefaultDragPreview?a():r)),b(u)},[p,b,n.hideDefaultDragPreview,n.path.length,m]),{isDragging:d,dragMonitorId:f,isOver:h,dropMonitorId:g,previewRef:r,dragRef:l,dropRef:u,dropEffect:_,groupItems:v,dropNotAllowed:y}},useInlineCombinatorDnD:n=>{let r=(0,t.useRef)(null),i=(n.rules??[])[n.path.at(-1)-1],[{isOver:a,dropMonitorId:o,dropEffect:s,dropNotAllowed:l},u]=c(()=>({accept:[`rule`,`ruleGroup`],canDrop:t=>e.n({dragging:t,path:n.path,schema:n.schema,canDrop:n.canDrop,groupModeModifierKey:n.groupModeModifierKey,hoveringItem:i}),collect:t=>({dropNotAllowed:t.isOver()&&!t.canDrop(),isOver:t.canDrop()&&t.isOver(),dropMonitorId:t.getHandlerId()??``,dropEffect:e.s(n.copyModeModifierKey)?`copy`:`move`,groupItems:e.s(n.groupModeModifierKey)}),drop:()=>e.t({type:`inlineCombinator`,path:n.path,schema:n.schema,copyModeModifierKey:n.copyModeModifierKey,groupModeModifierKey:n.groupModeModifierKey})}),[n.canDrop,i,n.path,n.schema]);return u(r),{dropRef:r,dropMonitorId:o,isOver:a,dropEffect:s,dropNotAllowed:l}}}};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}}); //# sourceMappingURL=react-dnd-toiD3-hw.js.map