UNPKG

react-querybuilder

Version:

React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts

1 lines 57.5 kB
import{LogType as e,TestID as t,add as n,clsx as r,defaultCombinatorLabelMap as i,defaultCombinators as a,defaultControlClassnames as o,defaultOperatorLabelMap as s,defaultOperators as c,defaultTranslations as l,filterFieldsByComparator as u,findPath as d,generateAccessibleDescription as f,generateID as p,getFirstOption as m,getMatchModesUtil as h,getOption as g,getParentPath as ee,getParseNumberMethod as te,getValidationClassNames as _,getValueSourcesUtil as v,group as ne,isFlexibleOptionArray as re,isFlexibleOptionGroupArray as y,isOptionGroupArray as b,isPojo as x,isRuleGroup as S,isRuleGroupType as C,isRuleGroupTypeIC as ie,joinWith as ae,lc as oe,mergeAnyTranslation as w,mergeAnyTranslations as se,mergeClassnames as T,move as ce,parseNumber as E,pathIsDisabled as D,pathsAreEqual as O,preferAnyProp as le,preferFlagProps as k,preferProp as ue,prepareOptionList as A,prepareRuleGroup as de,remove as j,rootPath as M,standardClassnames as N,toArray as P,toFullOptionList as fe,update as F}from"@react-querybuilder/core";import*as I from"react";import{Fragment as L,createContext as R,forwardRef as pe,useCallback as z,useContext as B,useEffect as me,useMemo as V,useRef as he,useState as ge}from"react";import{combineSlices as _e,configureStore as H,createSlice as ve}from"@reduxjs/toolkit";import{createDispatchHook as ye,createSelectorHook as be,createStoreHook as xe}from"react-redux";import{produce as Se}from"immer";const U=e=>I.createElement(`button`,{type:`button`,"data-testid":e.testID,disabled:e.disabled&&!e.disabledTranslation,className:e.className,title:e.disabledTranslation&&e.disabled?e.disabledTranslation.title:e.title,onClick:t=>e.handleOnClick(t)},e.disabledTranslation&&e.disabled?e.disabledTranslation.label:e.label),W=pe((e,t)=>I.createElement(`span`,{"data-testid":e.testID,ref:t,className:e.className,title:e.title},e.label)),Ce=e=>{let{component:n,...i}=e,a=r(i.schema.suppressStandardClassnames||N.betweenRules,i.schema.classNames.betweenRules);return I.createElement(`div`,{className:a,"data-testid":t.inlineCombinator},I.createElement(n,{...i,testID:t.combinators}))},we={name:``,value:``,label:``},G=e=>[`atleast`,`atmost`,`exactly`].includes(oe(e)??``),Te=[],Ee=e=>{let{match:t,options:n,title:r,className:i,disabled:a,testID:o,schema:s,selectorComponent:c=e.schema.controls.valueSelector,numericEditorComponent:l=e.schema.controls.valueEditor}=e,{thresholdNum:u,thresholdRule:d,thresholdSchema:f,handleChangeMode:p,handleChangeThreshold:m}=De(e);return I.createElement(I.Fragment,null,I.createElement(c,{schema:s,testID:o,className:i,title:r,handleOnChange:p,disabled:a,value:t.mode,options:n,multiple:!1,listsAsArrays:!1,path:Te,level:0}),G(t.mode)&&I.createElement(l,{skipHook:!0,testID:o,inputType:`number`,title:r,className:i,disabled:a,handleOnChange:m,field:``,operator:``,value:u,valueSource:`value`,fieldData:we,schema:f,path:Te,level:0,rule:d}))},De=e=>{let{match:t,handleOnChange:n}=e,r=I.useMemo(()=>typeof t.threshold==`number`?Math.max(0,t.threshold):1,[t.threshold]);return{thresholdNum:r,thresholdRule:I.useMemo(()=>({field:``,operator:`=`,value:r}),[r]),thresholdSchema:I.useMemo(()=>({...e.schema,parseNumbers:!0}),[e.schema]),handleChangeMode:z(e=>{G(e)&&typeof t.threshold!=`number`?n({...t,mode:e,threshold:1}):n({...t,mode:e})},[n,t]),handleChangeThreshold:z(e=>{n({...t,threshold:E(e,{parseNumbers:!0})})},[n,t])}},Oe=e=>{let t=I.useId();return I.createElement(`label`,{"data-testid":e.testID,className:e.className,title:e.title,htmlFor:t},I.createElement(`input`,{id:t,type:`checkbox`,onChange:t=>e.handleOnChange(t.target.checked),checked:!!e.checked,disabled:e.disabled}),e.label)},K={errorInvalidIndependentCombinatorsProp:`QueryBuilder was rendered with a truthy independentCombinators prop. This prop is deprecated and unnecessary. Furthermore, the initial query/defaultQuery prop was of type RuleGroupType instead of type RuleGroupIC. More info: https://react-querybuilder.js.org/docs/components/querybuilder#independent-combinators`,errorUnnecessaryIndependentCombinatorsProp:`QueryBuilder was rendered with the deprecated and unnecessary independentCombinators prop. To use independent combinators, make sure the query/defaultQuery prop is of type RuleGroupIC when the component mounts. More info: https://react-querybuilder.js.org/docs/components/querybuilder#independent-combinators`,errorDeprecatedRuleGroupProps:`A custom RuleGroup component has rendered a standard RuleGroup component with deprecated props. The combinator, not, and rules props should not be used. Instead, the full group object should be passed as the ruleGroup prop.`,errorDeprecatedRuleProps:`A custom RuleGroup component has rendered a standard Rule component with deprecated props. The field, operator, value, and valueSource props should not be used. Instead, the full rule object should be passed as the rule prop.`,errorBothQueryDefaultQuery:`QueryBuilder was rendered with both query and defaultQuery props. QueryBuilder must be either controlled or uncontrolled (specify either the query prop, or the defaultQuery prop, but not both). Decide between using a controlled or uncontrolled query builder and remove one of these props. More info: https://reactjs.org/link/controlled-components`,errorUncontrolledToControlled:`QueryBuilder is changing from an uncontrolled component to be controlled. This is likely caused by the query changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled query builder for the lifetime of the component. More info: https://reactjs.org/link/controlled-components`,errorControlledToUncontrolled:`QueryBuilder is changing from a controlled component to be uncontrolled. This is likely caused by the query changing from defined to undefined, which should not happen. Decide between using a controlled or uncontrolled query builder for the lifetime of the component. More info: https://reactjs.org/link/controlled-components`,errorEnabledDndWithoutReactDnD:`QueryBuilder was rendered with the enableDragAndDrop prop set to true, but either react-dnd was not detected or one of react-dnd-html5-backend or react-dnd-touch-backend was not detected. To enable drag-and-drop functionality, install react-dnd and one of the backend packages and wrap QueryBuilder in QueryBuilderDnD from @react-querybuilder/dnd.`,errorDeprecatedDebugImport:`Importing from react-querybuilder/debug is deprecated. To enable Redux DevTools for React Query Builder's internal store, set globalThis.__RQB_DEVTOOLS__ = true.`},ke=ve({name:`queries`,initialState:{},reducers:{setQueryState:(e,{payload:{qbId:t,query:n}})=>{e[t]=n}},selectors:{getQuerySelectorById:(e,t)=>e[t]}}),Ae=I.createContext(null),je=ve({name:`warnings`,initialState:{[K.errorInvalidIndependentCombinatorsProp]:!1,[K.errorUnnecessaryIndependentCombinatorsProp]:!1,[K.errorDeprecatedRuleGroupProps]:!1,[K.errorDeprecatedRuleProps]:!1,[K.errorBothQueryDefaultQuery]:!1,[K.errorUncontrolledToControlled]:!1,[K.errorControlledToUncontrolled]:!1,[K.errorEnabledDndWithoutReactDnD]:!1,[K.errorDeprecatedDebugImport]:!1},reducers:{rqbWarn:(e,{payload:t})=>{e[t]||(console.error(t),e[t]=!0)}}}),Me=_e(ke,je).withLazyLoadedSlices(),Ne=e=>ye(e),Pe=e=>xe(e),Fe=e=>be(e),Ie=e=>({useRQB_INTERNAL_QueryBuilderDispatch:Ne(e),useRQB_INTERNAL_QueryBuilderStore:Pe(e),useRQB_INTERNAL_QueryBuilderSelector:Fe(e)}),Le=({payload:e,onQueryChange:t})=>n=>{n(ke.actions.setQueryState(e)),typeof t==`function`&&t(e.query)},Re=Ie(Ae),ze=Re.useRQB_INTERNAL_QueryBuilderDispatch,Be=Re.useRQB_INTERNAL_QueryBuilderStore,Ve=Re.useRQB_INTERNAL_QueryBuilderSelector,{rqbWarn:He}=je.actions,Ue=e=>t=>{setTimeout(()=>t(He(e)))},We={reducer:Me,preloadedState:{queries:ke.getInitialState(),warnings:je.getInitialState()},middleware:e=>e({serializableCheck:{ignoredActions:[ke.actions.setQueryState.type],ignoredPaths:[/^queries\b.*\.rules\.\d+\.value$/]}})},Ge=e=>{let t=he({value:e,prev:null}),n=t.current.value;return e!==n&&(t.current.prev=n,t.current.value=e),t.current.prev},Ke=e=>{let t=ze(),{defaultQuery:n,queryProp:r}=e,i=Ge(!!r);process.env.NODE_ENV!==`production`&&(r&&n?t(Ue(K.errorBothQueryDefaultQuery)):i===!0&&!r&&n?t(Ue(K.errorControlledToUncontrolled)):i===!1&&r&&!n&&t(Ue(K.errorUncontrolledToControlled)))};function qe(e,t,n){let r=ze();process.env.NODE_ENV!==`production`&&t&&(e===`independentCombinators`&&(n===`invalid`&&r(Ue(K.errorInvalidIndependentCombinatorsProp)),n===`unnecessary`&&r(Ue(K.errorUnnecessaryIndependentCombinatorsProp))),e===`rule`&&r(Ue(K.errorDeprecatedRuleProps)),e===`ruleGroup`&&r(Ue(K.errorDeprecatedRuleGroupProps)))}const Je=e=>{let{optionList:t,optionsMap:n,defaultOption:r}=V(()=>A({placeholder:e.translations.fields,optionList:e.fields,autoSelectOption:e.autoSelectField,baseOption:e.baseField}),[e.autoSelectField,e.baseField,e.fields,e.translations.fields]);return{fields:t,fieldMap:n,defaultField:r}},q=e=>{let t=H({...We,devTools:e?{name:`React Query Builder`}:!1});return t.addSlice=e=>{Me.inject(e),t.dispatch({type:crypto.randomUUID().slice(0,8),meta:`Initializing state for slice "${e.name}"`})},t};let J=null;function Ye(e){return J||=q(e||globalThis?.__RQB_DEVTOOLS__),J}const Xe=e=>Ye().addSlice(e),Ze=e=>t=>ke.selectors.getQuerySelectorById({queries:t.queries},e),Qe=(e,t)=>{let n=I.useContext(dt);return Ve(e,t)??n?.initialQuery},$e=e=>{let t=I.useContext(dt);return Ve(Ze(e?.schema.qbId??t.qbId??``))??t?.initialQuery},et={},tt={},nt=[],rt={},it=()=>null,at=()=>``,ot=()=>!0,st=(...e)=>{console.log(...e)};function ct(t,i){let{query:a,defaultQuery:o,getValueEditorSeparator:s=it,getRuleClassname:c=at,getRuleGroupClassname:l=at,onAddRule:u=ot,onAddGroup:p=ot,onMoveRule:m=ot,onMoveGroup:h=ot,onGroupRule:g=ot,onGroupGroup:ee=ot,onRemove:te=ot,onQueryChange:_,showCombinatorsBetweenRules:v=!1,showNotToggle:re=!1,showShiftActions:y=!1,showCloneButtons:b=!1,showLockButtons:x=!1,showMuteButtons:C=!1,suppressStandardClassnames:ae=!1,resetOnFieldChange:oe=!0,resetOnOperatorChange:w=!1,autoSelectField:se=!0,autoSelectOperator:T=!0,autoSelectValue:E=!0,addRuleToNewGroups:O=!1,listsAsArrays:le=!1,parseNumbers:k=!1,disabled:ue=!1,validator:A,onLog:M=st,idGenerator:P,accessibleDescriptionGenerator:fe=f}=t,{qbId:I,rqbContext:L,fields:R,fieldMap:pe,combinators:B,getOperatorsMain:_e,getMatchModesMain:H,getRuleDefaultOperator:ve,getSubQueryBuilderPropsMain:ye,getValueEditorTypeMain:be,getValueSourcesMain:xe,getValuesMain:Se,getRuleDefaultValue:U,getInputTypeMain:W,createRule:Ce,createRuleGroup:we}=i,{controlClassnames:G,controlElements:Te,debugMode:Ee,enableDragAndDrop:De,enableMountQueryChange:Oe,translations:K}=L,ke=!!v,Ae=!!re,je=!!y,Me=!!b,Ne=!!x,Pe=!!C,Fe=!!oe,Ie=!!w,Re=!!se,Ve=!!T,He=!!E,Ue=!!O,We=!!le,Ge=!!ae,Je=(t.maxLevels??0)>0?Number(t.maxLevels):1/0,q=z((...e)=>{Ee&&M(...e)},[Ee,M]);Ke({defaultQuery:o,queryProp:a});let J=Be(),Ye=ze(),Xe=V(()=>Ze(I),[I]),$e=Qe(Xe),ct=z(()=>Xe(J.getState()),[J,Xe]),lt=V(()=>we(),[we]),ut=a??$e??o??lt,Y=ut.id?ut:de(ut,{idGenerator:P}),[dt]=ge(Y),ft=V(()=>({...L,initialQuery:dt}),[L,dt]);me(()=>{a&&!Object.is(a,$e)&&Ye(Le({payload:{qbId:I,query:a},onQueryChange:void 0}))},[a,I,$e,Ye]);let pt=V(()=>ie(Y),[Y]),mt=!!t.independentCombinators&&!pt;qe(`independentCombinators`,mt||!mt&&(t.independentCombinators??`not present`)!==`not present`,mt?`invalid`:`unnecessary`);let ht=he(!1);me(()=>{ht.current||(ht.current=!0,Ye(Le({payload:{qbId:I,query:Y},onQueryChange:Oe&&typeof _==`function`?_:void 0})))},[Oe,_,I,Ye,Y]);let X=z(e=>{Ye(Le({payload:{qbId:I,query:e},onQueryChange:_}))},[_,I,Ye]),gt=Array.isArray(ue)&&ue||nt,Z=ue===!0,_t=Y.disabled||gt.some(e=>e.length===0),vt=z((t,r,i)=>{let a=Ze(I)(J.getState());if(!a)return;if(D(r,a)||Z){q({qbId:I,type:e.parentPathDisabled,rule:t,parentPath:r,query:a});return}let o=u(t,r,a,i);if(!o){q({qbId:I,type:e.onAddRuleFalse,rule:t,parentPath:r,query:a});return}let s=o===!0?t:o,c=n(a,s,r,{combinators:B,combinatorPreceding:s.combinatorPreceding??void 0,idGenerator:P});q({qbId:I,type:e.add,query:a,newQuery:c,newRule:s,parentPath:r}),X(c)},[B,X,P,q,u,I,J,Z]),yt=z((t,r,i)=>{if(r.length>=Je)return;let a=Ze(I)(J.getState());if(!a)return;if(D(r,a)||Z){q({qbId:I,type:e.parentPathDisabled,ruleGroup:t,parentPath:r,query:a});return}let o=p(t,r,a,i);if(!o){q({qbId:I,type:e.onAddGroupFalse,ruleGroup:t,parentPath:r,query:a});return}let s=o===!0?t:o,c=n(a,s,r,{combinators:B,combinatorPreceding:s.combinatorPreceding??void 0,idGenerator:P});q({qbId:I,type:e.add,query:a,newQuery:c,newGroup:s,parentPath:r}),X(c)},[B,X,P,q,Je,p,I,J,Z]),bt=z((t,n,r)=>{let i=Ze(I)(J.getState());if(!i)return;if(D(r,i)&&t!==`disabled`||Z){q({qbId:I,type:e.pathDisabled,path:r,prop:t,value:n,query:i});return}let a=F(i,t,n,r,{resetOnFieldChange:Fe,resetOnOperatorChange:Ie,getRuleDefaultOperator:ve,getValueSources:xe,getRuleDefaultValue:U,getMatchModes:H});q({qbId:I,type:e.update,query:i,newQuery:a,prop:t,value:n,path:r}),X(a)},[X,H,ve,U,xe,q,I,J,Z,Fe,Ie]),xt=z((t,n)=>{let r=Ze(I)(J.getState());if(!r)return;if(D(t,r)||Z){q({qbId:I,type:e.pathDisabled,path:t,query:r});return}let i=d(t,r);if(i)if(te(i,t,r,n)){let n=j(r,t);q({qbId:I,type:e.remove,query:r,newQuery:n,path:t,ruleOrGroup:i}),X(n)}else q({qbId:I,type:e.onRemoveFalse,ruleOrGroup:i,path:t,query:r})},[X,q,te,I,J,Z]),St=z((t,n,r,i)=>{let a=Ze(I)(J.getState());if(!a)return;if(D(t,a)||Z){q({qbId:I,type:e.pathDisabled,oldPath:t,newPath:n,query:a});return}let o=ce(a,t,n,{clone:r,combinators:B,idGenerator:P}),s=d(t,a),c=S(s),l=(c?h:m)(s,t,n,a,o,{clone:r,combinators:B},i);if(!l){q({qbId:I,type:c?e.onMoveGroupFalse:e.onMoveRuleFalse,ruleOrGroup:s,oldPath:t,newPath:n,clone:r,query:a,nextQuery:o});return}let u=S(l)?l:o;q({qbId:I,type:e.move,query:a,newQuery:u,oldPath:t,newPath:n,clone:r}),X(u)},[B,X,P,q,h,m,I,J,Z]),Ct=z((t,n,r,i)=>{let a=Ze(I)(J.getState());if(!a)return;if(D(t,a)||Z){q({qbId:I,type:e.pathDisabled,sourcePath:t,targetPath:n,query:a});return}let o=ne(a,t,n,{clone:r,combinators:B,idGenerator:P}),s=d(t,a),c=S(s),l=(c?ee:g)(s,t,n,a,o,{clone:r,combinators:B},i);if(!l){q({qbId:I,type:c?e.onGroupGroupFalse:e.onGroupRuleFalse,ruleOrGroup:s,sourcePath:t,targetPath:n,clone:r,query:a,nextQuery:o});return}let u=S(l)?l:o;q({qbId:I,type:e.group,query:a,newQuery:u,sourcePath:t,targetPath:n,clone:r}),X(u)},[B,X,P,q,ee,g,I,J,Z]),{validationResult:Q,validationMap:wt}=V(()=>{let e=typeof A==`function`&&Y?A(Y):et;return{validationResult:e,validationMap:typeof e==`boolean`?tt:e}},[Y,A]),Tt=De?`enabled`:`disabled`,Et=pt||ke?`enabled`:`disabled`,Dt=V(()=>typeof Y.combinator==`string`?{combinator:Y.combinator}:rt,[Y.combinator]),Ot=V(()=>r(Ge||N.queryBuilder,r(G.queryBuilder),Z&&G.disabled,typeof Q==`boolean`&&Q&&G.valid,typeof Q==`boolean`&&!Q&&G.invalid,Ge||{[N.disabled]:Z,[N.valid]:typeof Q==`boolean`&&Q,[N.invalid]:typeof Q==`boolean`&&!Q}),[G.disabled,G.invalid,G.queryBuilder,G.valid,Z,Ge,Q]),kt=z(e=>we(e??pt),[we,pt]),At=V(()=>({addRuleToNewGroups:Ue,accessibleDescriptionGenerator:fe,autoSelectField:Re,autoSelectOperator:Ve,autoSelectValue:He,classNames:G,combinators:B,controls:Te,createRule:Ce,createRuleGroup:kt,disabledPaths:gt,enableDragAndDrop:De,fieldMap:pe,fields:R,dispatchQuery:X,getQuery:ct,getInputType:W,getOperators:_e,getMatchModes:H,getRuleClassname:c,getRuleGroupClassname:l,getSubQueryBuilderProps:ye,getValueEditorSeparator:s,getValueEditorType:be,getValues:Se,getValueSources:xe,independentCombinators:pt,listsAsArrays:We,maxLevels:Je,parseNumbers:k,qbId:I,showCloneButtons:Me,showCombinatorsBetweenRules:ke,showLockButtons:Ne,showMuteButtons:Pe,showNotToggle:Ae,showShiftActions:je,suppressStandardClassnames:Ge,validationMap:wt}),[fe,Ue,Re,Ve,He,B,G,Te,Ce,kt,gt,X,De,pe,R,W,_e,H,ct,c,l,ye,s,be,Se,xe,pt,We,Je,k,I,Me,ke,Ne,Pe,Ae,je,Ge,wt]);return{actions:V(()=>({moveRule:St,onGroupAdd:yt,onGroupRemove:xt,onPropChange:bt,onRuleAdd:vt,onRuleRemove:xt,groupRule:Ct}),[Ct,St,yt,bt,vt,xt]),rootGroup:Y,rootGroupDisabled:_t,queryDisabled:Z,rqbContext:ft,schema:At,translations:K,wrapperClassName:Ot,dndEnabledAttr:Tt,inlineCombinatorsAttr:Et,combinatorPropObject:Dt}}const lt=(e,t,n)=>{let r=m(e);if(t.operator===`between`||t.operator===`notBetween`){let e=[r,r];return n?e:ae(e.map(e=>e??``),`,`)}return r},ut=e=>{let[t]=ge(p),{fields:n,baseField:r,operators:o,baseOperator:l,combinators:d,baseCombinator:f,translations:ee,enableMountQueryChange:te=!0,controlClassnames:_,controlElements:ne,getDefaultField:re,getDefaultOperator:y,getDefaultValue:b,getMatchModes:x,getOperators:S,getSubQueryBuilderProps:C,getValueEditorType:ie,getValueSources:ae,getInputType:oe,getValues:w,autoSelectField:se=!0,autoSelectOperator:T=!0,autoSelectValue:ce=!0,addRuleToNewGroups:E=!1,enableDragAndDrop:D,listsAsArrays:O=!1,debugMode:le=!1,idGenerator:k=p}=e,[ue]=ge(e.query??e.defaultQuery),de=Ot({controlClassnames:_,controlElements:ne,debugMode:le,enableDragAndDrop:D,enableMountQueryChange:te,translations:ee,initialQuery:ue,qbId:t,finalize:!0}),{translations:j}=de,{fields:M,fieldMap:N}=Je({fields:n,baseField:r,autoSelectField:se,translations:j}),{optionList:P}=V(()=>A({optionList:d??a,labelMap:i,baseOption:f,autoSelectOption:!0}),[f,d]),{optionList:fe}=V(()=>A({optionList:o??c,placeholder:j.operators,labelMap:s,baseOption:l,autoSelectOption:T}),[T,l,o,j.operators]),F=z((e,{fieldData:t})=>A({optionList:t?.operators??S?.(e,{fieldData:t})??fe,placeholder:j.operators,baseOption:l,labelMap:s,autoSelectOption:T}).optionList,[T,l,S,fe,j.operators]),I=z(e=>{let t=N[e];return t?.defaultOperator?t.defaultOperator:y?typeof y==`function`?y(e,{fieldData:t}):y:m(F(e,{fieldData:t})??[])??``},[N,y,F]),L=z((e,t,{fieldData:n})=>n.valueEditorType?typeof n.valueEditorType==`function`?n.valueEditorType(t):n.valueEditorType:ie?.(e,t,{fieldData:n})??`text`,[ie]),R=z((e,t,n)=>v(N[e],t,ae),[N,ae]),pe=z((e,t)=>h(N[e],x),[N,x]),B=z((e,t)=>C?.(e,t)??{},[C]),me=z((e,t,{fieldData:n})=>A({optionList:n?.values??w?.(e,t,{fieldData:n})??[],placeholder:j.values,autoSelectOption:ce}).optionList,[ce,w,j.values]),he=z(e=>{let t=N[e.field]??{};if(t?.defaultValue!==void 0&&t.defaultValue!==null)return t.defaultValue;if(b)return b(e,{fieldData:t});let n=``,r=me(e.field,e.operator,{fieldData:t});if(e.valueSource===`field`){let r=u(t,M,e.operator);n=r.length>0?lt(r,e,O):``}else if(r.length>0){let i=L(e.field,e.operator,{fieldData:t});i===`multiselect`?n=O?[]:``:(i===`select`||i===`radio`)&&(n=lt(r,e,O))}else L(e.field,e.operator,{fieldData:t})===`checkbox`&&(n=!1);return n},[N,M,b,L,me,O]),_e=z((e,t,{fieldData:n})=>{if(oe){let r=oe(e,t,{fieldData:n});if(r)return r}return`text`},[oe]),H=z(()=>{let e=``,t=M;if(t?.length>0&&t[0]){let n=m(t);n&&(e=n)}if(re)if(typeof re==`function`){let n=re(t);n&&(e=n)}else e=re;let n=I(e),r=m(R(e,n,{fieldData:g(t,e)}))??`value`,i=m(pe(e,{fieldData:g(t,e)})),a={id:k(),field:e,operator:n,valueSource:r,value:``,...i?{match:{mode:i,threshold:1}}:null},o=he(a);return{...a,value:o}},[M,re,pe,I,he,R,k]);return{qbId:t,rqbContext:de,fields:M,fieldMap:N,combinators:P,getMatchModesMain:pe,getOperatorsMain:F,getRuleDefaultOperator:I,getSubQueryBuilderPropsMain:B,getValueEditorTypeMain:L,getValueSourcesMain:R,getValuesMain:me,getRuleDefaultValue:he,getInputTypeMain:_e,createRule:H,createRuleGroup:z(e=>e?{id:k(),rules:E?[H()]:[],not:!1}:{id:k(),rules:E?[H()]:[],combinator:m(P)??``,not:!1},[E,P,H,k])}},Y=e=>ct(e,ut(e)),dt=R({}),ft=I.memo(function(e){let n=ht(e),{schema:{controls:{ruleGroupBodyElements:r,ruleGroupHeaderElements:i}}}=n,a=$(n.addRule),o=$(n.addGroup),s=$(n.cloneGroup),c=$(n.toggleLockGroup),l=$(n.toggleMuteGroup),u=$(n.removeGroup),d=$(n.shiftGroupUp),f=$(n.shiftGroupDown),p=V(()=>({addRule:a,addGroup:o,cloneGroup:s,toggleLockGroup:c,toggleMuteGroup:l,removeGroup:u,shiftGroupUp:d,shiftGroupDown:f}),[a,o,s,c,l,u,d,f]);return I.createElement(`div`,{ref:n.previewRef,title:n.accessibleDescription,className:n.outerClassName,"data-testid":t.ruleGroup,"data-dragmonitorid":n.dragMonitorId,"data-dropmonitorid":n.dropMonitorId,"data-rule-group-id":n.id,"data-level":n.path.length,"data-path":JSON.stringify(n.path)},I.createElement(`div`,{ref:n.dropRef,className:n.classNames.header},I.createElement(i,{...n,...p})),I.createElement(`div`,{className:n.classNames.body},I.createElement(r,{...n,...p})))}),pt=I.memo(function(e){let{schema:{controls:{shiftActions:n,dragHandle:r,combinatorSelector:i,notToggle:a,addRuleAction:o,addGroupAction:s,cloneGroupAction:c,lockGroupAction:l,muteGroupAction:u,removeGroupAction:d}}}=e,f=V(()=>({level:e.path.length,path:e.path,disabled:e.disabled,context:e.context,validation:e.validationResult,schema:e.schema}),[e.path,e.disabled,e.context,e.validationResult,e.schema]),p=V(()=>e.schema.showShiftActions?{shiftUp:e.translations.shiftActionUp.title,shiftDown:e.translations.shiftActionDown.title}:void 0,[e.schema.showShiftActions,e.translations]),m=V(()=>e.schema.showShiftActions?{shiftUp:e.translations.shiftActionUp.label,shiftDown:e.translations.shiftActionDown.label}:void 0,[e.schema.showShiftActions,e.translations]);return I.createElement(L,null,e.schema.showShiftActions&&e.path.length>0&&I.createElement(n,{key:t.shiftActions,...f,testID:t.shiftActions,titles:p,labels:m,className:e.classNames.shiftActions,shiftUp:e.shiftGroupUp,shiftDown:e.shiftGroupDown,shiftUpDisabled:e.shiftUpDisabled,shiftDownDisabled:e.shiftDownDisabled,ruleOrGroup:e.ruleGroup}),e.path.length>0&&e.schema.enableDragAndDrop&&I.createElement(r,{key:t.dragHandle,...f,testID:t.dragHandle,ref:e.dragRef,title:e.translations.dragHandle.title,label:e.translations.dragHandle.label,className:e.classNames.dragHandle,ruleOrGroup:e.ruleGroup}),!e.schema.showCombinatorsBetweenRules&&!e.schema.independentCombinators&&I.createElement(i,{key:t.combinators,...f,testID:t.combinators,options:e.schema.combinators,value:e.combinator,title:e.translations.combinators.title,className:e.classNames.combinators,handleOnChange:e.onCombinatorChange,rules:e.ruleGroup.rules,ruleGroup:e.ruleGroup}),e.schema.showNotToggle&&I.createElement(a,{key:t.notToggle,...f,testID:t.notToggle,className:e.classNames.notToggle,title:e.translations.notToggle.title,label:e.translations.notToggle.label,checked:e.ruleGroup.not,handleOnChange:e.onNotToggleChange,ruleGroup:e.ruleGroup}),I.createElement(o,{key:t.addRule,...f,testID:t.addRule,label:e.translations.addRule.label,title:e.translations.addRule.title,className:e.classNames.addRule,handleOnClick:e.addRule,rules:e.ruleGroup.rules,ruleOrGroup:e.ruleGroup}),e.schema.maxLevels>e.path.length&&I.createElement(s,{key:t.addGroup,...f,testID:t.addGroup,label:e.translations.addGroup.label,title:e.translations.addGroup.title,className:e.classNames.addGroup,handleOnClick:e.addGroup,rules:e.ruleGroup.rules,ruleOrGroup:e.ruleGroup}),e.schema.showCloneButtons&&e.path.length>0&&I.createElement(c,{key:t.cloneGroup,...f,testID:t.cloneGroup,label:e.translations.cloneRuleGroup.label,title:e.translations.cloneRuleGroup.title,className:e.classNames.cloneGroup,handleOnClick:e.cloneGroup,rules:e.ruleGroup.rules,ruleOrGroup:e.ruleGroup}),e.schema.showLockButtons&&I.createElement(l,{key:t.lockGroup,...f,testID:t.lockGroup,label:e.translations.lockGroup.label,title:e.translations.lockGroup.title,className:e.classNames.lockGroup,handleOnClick:e.toggleLockGroup,rules:e.ruleGroup.rules,disabledTranslation:e.parentDisabled?void 0:e.translations.lockGroupDisabled,ruleOrGroup:e.ruleGroup}),e.schema.showMuteButtons&&I.createElement(u,{key:t.muteGroup,...f,testID:t.muteGroup,label:e.ruleGroup.muted?e.translations.unmuteGroup.label:e.translations.muteGroup.label,title:e.ruleGroup.muted?e.translations.unmuteGroup.title:e.translations.muteGroup.title,className:e.classNames.muteGroup,handleOnClick:e.toggleMuteGroup,rules:e.ruleGroup.rules,ruleOrGroup:e.ruleGroup}),e.path.length>0&&I.createElement(d,{key:t.removeGroup,...f,testID:t.removeGroup,label:e.translations.removeGroup.label,title:e.translations.removeGroup.title,className:e.classNames.removeGroup,handleOnClick:e.removeGroup,rules:e.ruleGroup.rules,ruleOrGroup:e.ruleGroup}))}),mt=I.memo(function(e){let{schema:{controls:{combinatorSelector:n,inlineCombinator:r,ruleGroup:i,rule:a}}}=e;return I.createElement(L,null,e.ruleGroup.rules.map((o,s,{length:c})=>{let l=e.pathsMemo[s],u=l.path,d=l.disabled||typeof o!=`string`&&o.disabled,f=O([0],u),p=e.path.length===0&&s===c-1,m=typeof o==`string`?[...u,o].join(`-`):o.id;return I.createElement(L,{key:m},s>0&&!e.schema.independentCombinators&&e.schema.showCombinatorsBetweenRules&&I.createElement(r,{key:t.inlineCombinator,options:e.schema.combinators,value:e.combinator,title:e.translations.combinators.title,className:e.classNames.combinators,handleOnChange:e.onCombinatorChange,rules:e.ruleGroup.rules,level:e.path.length,context:e.context,validation:e.validationResult,component:n,path:u,disabled:e.disabled,schema:e.schema,ruleGroup:e.ruleGroup}),typeof o==`string`?I.createElement(r,{key:`${t.inlineCombinator}-independent`,options:e.schema.combinators,value:o,title:e.translations.combinators.title,className:e.classNames.combinators,handleOnChange:t=>e.onIndependentCombinatorChange(t,s),rules:e.ruleGroup.rules,level:e.path.length,context:e.context,validation:e.validationResult,component:n,path:u,disabled:d,schema:e.schema,ruleGroup:e.ruleGroup}):S(o)?I.createElement(i,{key:t.ruleGroup,id:o.id,schema:e.schema,actions:e.actions,path:u,translations:e.translations,ruleGroup:o,rules:o.rules,combinator:C(o)?o.combinator:void 0,not:!!o.not,disabled:d,parentDisabled:e.parentDisabled||e.disabled,parentMuted:e.parentMuted||e.muted,shiftUpDisabled:f,shiftDownDisabled:p,context:e.context}):I.createElement(a,{key:t.rule,id:o.id,rule:o,field:o.field,operator:o.operator,value:o.value,valueSource:o.valueSource,schema:e.schema,actions:e.actions,path:u,disabled:d,parentDisabled:e.parentDisabled||e.disabled,parentMuted:e.parentMuted||e.muted,translations:e.translations,shiftUpDisabled:f,shiftDownDisabled:p,context:e.context}))}))}),ht=e=>{let{id:t,path:n,ruleGroup:i,schema:{qbId:a,accessibleDescriptionGenerator:o,classNames:s,combinators:c,createRule:l,createRuleGroup:u,disabledPaths:d,independentCombinators:f,validationMap:p,enableDragAndDrop:h,getRuleGroupClassname:te,suppressStandardClassnames:v},actions:{onGroupAdd:ne,onGroupRemove:re,onPropChange:y,onRuleAdd:b,moveRule:x},disabled:S,parentDisabled:ie,parentMuted:ae,shiftUpDisabled:oe,shiftDownDisabled:w,combinator:se,rules:T,not:ce,dropEffect:E=`move`,groupItems:D=!1,dragMonitorId:O=``,dropMonitorId:le=``,previewRef:k=null,dragRef:ue=null,dropRef:A=null,isDragging:de=!1,isOver:j=!1,dropNotAllowed:M=!1}=e;qe(`ruleGroup`,!i),Pt(h,!!(O||le||k||ue||A));let P=!!ie||!!S,fe=!!ae||!!i?.muted,F=V(()=>i&&C(i)?i.combinator:i?m(c):se??m(c),[se,c,i]),I=V(()=>{if(i){if(i.combinator===F||f)return i;let e=structuredClone(i);return e.combinator=F,e}return{rules:T,not:ce}},[F,f,ce,i,T]),L=V(()=>({header:r(v||N.header,s.header,j&&E===`copy`&&s.dndCopy,M&&s.dndDropNotAllowed,v||{[N.dndOver]:j,[N.dndCopy]:j&&E===`copy`,[N.dndDropNotAllowed]:M}),shiftActions:r(v||N.shiftActions,s.shiftActions),dragHandle:r(v||N.dragHandle,s.dragHandle),combinators:r(v||N.combinators,s.valueSelector,s.combinators),notToggle:r(v||N.notToggle,s.notToggle),addRule:r(v||N.addRule,s.actionElement,s.addRule),addGroup:r(v||N.addGroup,s.actionElement,s.addGroup),cloneGroup:r(v||N.cloneGroup,s.actionElement,s.cloneGroup),lockGroup:r(v||N.lockGroup,s.actionElement,s.lockGroup),muteGroup:r(v||N.muteGroup,s.actionElement,s.muteGroup),removeGroup:r(v||N.removeGroup,s.actionElement,s.removeGroup),body:r(v||N.body,s.body)}),[s.actionElement,s.addGroup,s.addRule,s.body,s.cloneGroup,s.combinators,s.dndCopy,s.dndDropNotAllowed,s.dragHandle,s.header,s.lockGroup,s.muteGroup,s.notToggle,s.removeGroup,s.shiftActions,s.valueSelector,E,M,j,v]),R=z(e=>{P||y(`combinator`,e,n)},[P,y,n]),pe=z((e,t,r)=>{P||y(`combinator`,e,[...n,t])},[P,y,n]),B=z((e,t)=>{P||y(`not`,e,n)},[P,y,n]),me=z((e,t)=>{P||b(l(),n,t)},[l,P,b,n]),he=z((e,t)=>{P||ne(u(),n,t)},[u,P,ne,n]),ge=z(()=>{P||x(n,[...ee(n),n.at(-1)+1],!0)},[P,x,n]),_e=z((e,t)=>{!P&&!oe&&x(n,`up`,e?.altKey)},[P,x,n,oe]),H=z((e,t)=>{!P&&!w&&x(n,`down`,e?.altKey)},[P,x,n,w]),ve=z(()=>{y(`disabled`,!P,n)},[P,y,n]),ye=z(()=>{y(`muted`,!I.muted,n)},[I.muted,y,n]),be=z(()=>{P||re(n)},[P,re,n]),xe=p[t??``],Se=V(()=>_(xe),[xe]),U=V(()=>f?null:g(c,F)?.className??``,[F,c,f]),W=V(()=>te(I),[te,I]),Ce=V(()=>r(W,U,v||N.ruleGroup,s.ruleGroup,P&&s.disabled,fe&&s.muted,de&&s.dndDragging,j&&D&&s.dndGroup,v||{[N.disabled]:P,[N.muted]:fe,[N.dndDragging]:de,[N.dndGroup]:j&&D},Se),[s.disabled,s.muted,s.dndDragging,s.dndGroup,s.ruleGroup,U,P,fe,D,de,j,W,v,Se]),we=At({disabled:P,disabledPaths:d,path:n,nestedArray:I.rules}),G=V(()=>o({path:n,qbId:a}),[o,n,a]);return{...e,addGroup:he,addRule:me,accessibleDescription:G,classNames:L,cloneGroup:ge,combinator:F,disabled:P,dragMonitorId:O,dragRef:ue,dropMonitorId:le,dropRef:A,isDragging:de,isOver:j,muted:fe,onCombinatorChange:R,onGroupAdd:ne,onIndependentCombinatorChange:pe,onNotToggleChange:B,outerClassName:Ce,parentDisabled:ie,pathsMemo:we,previewRef:k,removeGroup:be,ruleGroup:I,shiftGroupUp:_e,shiftGroupDown:H,toggleLockGroup:ve,toggleMuteGroup:ye,validationClassName:Se,validationResult:xe}},X=e=>I.createElement(`div`,{"data-testid":e.testID,className:e.className},I.createElement(`button`,{disabled:e.disabled||e.shiftUpDisabled,onClick:e.shiftUp,title:e.titles?.shiftUp},e.labels?.shiftUp),I.createElement(`button`,{disabled:e.disabled||e.shiftDownDisabled,onClick:e.shiftDown,title:e.titles?.shiftDown},e.labels?.shiftDown)),gt=({name:e,disabled:t,checked:n,label:r,handleOnChange:i})=>{let a=I.useId();return I.createElement(`label`,{htmlFor:a},I.createElement(`input`,{id:a,type:`radio`,value:e,disabled:t,checked:n,onChange:e=>i(e.target.value)}),r)},Z=e=>{let{operator:t,value:n,handleOnChange:r,title:i,className:a,type:o=`text`,inputType:s,values:c=[],listsAsArrays:l,fieldData:u,disabled:d,separator:f=null,testID:p,selectorComponent:h=e.schema.controls.valueSelector,parseNumbers:g,skipHook:ee,valueSource:te,..._}=e,{valueAsArray:v,multiValueHandler:ne,bigIntValueHandler:re,parseNumberMethod:y,valueListItemClassName:b,inputTypeCoerced:x}=_t(e);if(t===`null`||t===`notNull`)return null;let S=u?.placeholder??``;if((t===`between`||t===`notBetween`)&&(o===`select`||o===`text`)){let t=[`from`,`to`].map((t,n)=>o===`text`?I.createElement(`input`,{key:t,type:x,placeholder:S,value:v[n]??``,className:b,disabled:d,onChange:e=>ne(e.target.value,n)}):I.createElement(h,{key:t,..._,schema:e.schema,className:b,handleOnChange:e=>ne(e,n),disabled:d,value:v[n]??m(c),options:c,listsAsArrays:l}));return I.createElement(`span`,{"data-testid":p,className:a,title:i},t[0],f,t[1])}switch(o){case`select`:case`multiselect`:return I.createElement(h,{..._,schema:e.schema,testID:p,className:a,title:i,handleOnChange:r,disabled:d,value:n,options:c,multiple:o===`multiselect`,listsAsArrays:l});case`textarea`:return I.createElement(`textarea`,{"data-testid":p,placeholder:S,value:n,title:i,className:a,disabled:d,onChange:e=>r(e.target.value)});case`switch`:case`checkbox`:return I.createElement(`input`,{"data-testid":p,type:`checkbox`,className:a,title:i,onChange:e=>r(e.target.checked),checked:!!n,disabled:d});case`radio`:return I.createElement(`span`,{"data-testid":p,className:a,title:i},c.map(e=>I.createElement(gt,{key:e.name,name:e.name,disabled:d,checked:n===e.name,handleOnChange:r,label:e.label})))}return s===`bigint`?I.createElement(`input`,{"data-testid":p,type:x,placeholder:S,value:`${n}`,title:i,className:a,disabled:d,onChange:e=>re(e.target.value)}):I.createElement(`input`,{"data-testid":p,type:x,placeholder:S,value:n,title:i,className:a,disabled:d,onChange:e=>r(E(e.target.value,{parseNumbers:y}))})},_t=e=>{let{handleOnChange:t,inputType:n,operator:i,value:a,listsAsArrays:o,parseNumbers:s,values:c,type:l,skipHook:u,schema:{classNames:d,suppressStandardClassnames:f}}=e;me(()=>{!u&&l!==`multiselect`&&![`between`,`notBetween`,`in`,`notIn`].includes(i)&&(Array.isArray(a)||n===`number`&&typeof a==`string`&&a.includes(`,`))&&t(P(a,{retainEmptyStrings:!0})[0]??``)},[t,n,i,u,l,a]);let p=V(()=>P(a,{retainEmptyStrings:!0}),[a]),h=V(()=>te({parseNumbers:s,inputType:n}),[n,s]);return{valueAsArray:p,multiValueHandler:z((e,n)=>{let r=Se(p,t=>{t[n]=E(e,{parseNumbers:h}),n===0&&(i===`between`||i===`notBetween`)&&(t.length<2||t[1]===void 0)&&(t[1]=m(c))});t(o?r:ae(r,`,`))},[t,o,i,h,p,c]),bigIntValueHandler:z(e=>{let n=E(e,{parseNumbers:h,bigIntOnOverflow:!0}),r;try{r=BigInt(n)}catch{t(n);return}t(r)},[t,h]),parseNumberMethod:h,valueListItemClassName:r(f||N.valueListItem,d?.valueListItem),inputTypeCoerced:n===`bigint`||i===`in`||i===`notIn`?`text`:n||`text`}},vt=e=>{let{multiple:t,onChange:n}=e;return V(()=>t?e=>n(Array.from(e.target.selectedOptions).map(e=>e.value)):e=>n(e.target.value),[t,n])},yt=e=>{let t=t=>{let n=Ot(e);return I.createElement(dt.Provider,{value:n},t.children)},n=e=>{let t=Ot(e);return I.createElement(dt.Provider,{value:t},e.children)};return e=>I.createElement(t,null,I.createElement(n,e,e.children))},bt=(e,...t)=>se(e,...t),xt=(e,t,n)=>w(e,t,n?l:void 0),St=e=>b(e)?e.map(e=>I.createElement(`optgroup`,{key:e.label,label:e.label},e.options.map(e=>I.createElement(`option`,{key:e.name,value:e.name,disabled:e.disabled},e.label)))):Array.isArray(e)?e.map(e=>I.createElement(`option`,{key:e.name,value:e.name,disabled:e.disabled},e.label)):null,Ct=e=>{let{onChange:t,val:n}=Q(e),r=vt({multiple:e.multiple,onChange:t});return I.createElement(`select`,{"data-testid":e.testID,className:e.className,value:n,title:e.title,disabled:e.disabled,multiple:!!e.multiple,onChange:r},St(e.options))},Q=e=>{let{handleOnChange:t,listsAsArrays:n=!1,multiple:r=!1,value:i}=e;return{onChange:z(e=>{if(r){let r=P(e);t(n?r:ae(r,`,`))}else t(e)},[t,n,r]),val:V(()=>r?P(i):i,[r,i])}},wt=({props:e})=>{let t=Y(e),n=t.schema.controls.ruleGroup,r=dt;return I.createElement(r.Provider,{key:t.dndEnabledAttr,value:t.rqbContext},I.createElement(`div`,{role:`form`,className:t.wrapperClassName,"data-dnd":t.dndEnabledAttr,"data-inlinecombinators":t.inlineCombinatorsAttr},I.createElement(n,{translations:t.translations,ruleGroup:t.rootGroup,rules:t.rootGroup.rules,...t.combinatorPropObject,not:!!t.rootGroup.not,schema:t.schema,actions:t.actions,id:t.rootGroup.id,path:M,disabled:t.rootGroupDisabled,shiftUpDisabled:!0,shiftDownDisabled:!0,parentDisabled:t.queryDisabled,context:e.context})))},Tt=()=>null,Et=pe(Tt),Dt={},Ot=({finalize:e,...t})=>{let n=B(dt),r=V(()=>k(t,n,e),[t,n,e]),i=e?n.enableDragAndDrop!==!1&&ue(!1,t.enableDragAndDrop,n.enableDragAndDrop):t.enableDragAndDrop??n.enableDragAndDrop,a=V(()=>T(e?Object.assign({},o):Dt,n.controlClassnames,t.controlClassnames),[n.controlClassnames,t.controlClassnames,e]),s=V(()=>({actionElement:a.actionElement,addGroup:a.addGroup,addRule:a.addRule,body:a.body,cloneGroup:a.cloneGroup,cloneRule:a.cloneRule,combinators:a.combinators,dragHandle:a.dragHandle,fields:a.fields,header:a.header,lockGroup:a.lockGroup,lockRule:a.lockRule,muteGroup:a.muteGroup,muteRule:a.muteRule,muted:a.muted,notToggle:a.notToggle,operators:a.operators,queryBuilder:a.queryBuilder,removeGroup:a.removeGroup,removeRule:a.removeRule,rule:a.rule,ruleGroup:a.ruleGroup,shiftActions:a.shiftActions,value:a.value,valueSelector:a.valueSelector,valueSource:a.valueSource,betweenRules:a.betweenRules,valid:a.valid,invalid:a.invalid,dndDragging:a.dndDragging,dndOver:a.dndOver,dndCopy:a.dndCopy,dndGroup:a.dndGroup,dndDropNotAllowed:a.dndDropNotAllowed,disabled:a.disabled,valueListItem:a.valueListItem,matchMode:a.matchMode,matchThreshold:a.matchThreshold,branches:a.branches,hasSubQuery:a.hasSubQuery,loading:a.loading}),[a.actionElement,a.addGroup,a.addRule,a.betweenRules,a.body,a.branches,a.cloneGroup,a.cloneRule,a.combinators,a.disabled,a.dndCopy,a.dndDropNotAllowed,a.dndGroup,a.dndDragging,a.dndOver,a.dragHandle,a.fields,a.hasSubQuery,a.header,a.invalid,a.loading,a.lockGroup,a.lockRule,a.muteGroup,a.muteRule,a.muted,a.matchMode,a.matchThreshold,a.notToggle,a.operators,a.queryBuilder,a.removeGroup,a.removeRule,a.rule,a.ruleGroup,a.shiftActions,a.valid,a.value,a.valueListItem,a.valueSelector,a.valueSource]),c=n.controlElements??Dt,u=t.controlElements??Dt,d=z((t,n,r)=>{let i=t===`dragHandle`?Et:Tt,a=(t.endsWith(`Action`)&&u.actionElement?u.actionElement:void 0)??(t.endsWith(`Selector`)&&u.valueSelector?u.valueSelector:void 0),o=(t.endsWith(`Action`)&&c.actionElement?c.actionElement:void 0)??(t.endsWith(`Selector`)&&c.valueSelector?c.valueSelector:void 0),s=n===null?i:n??(e?a:void 0)??(r===null?i:r??(e?o:void 0));return s?{[t]:s}:e?{[t]:Ht[t]}:Dt},[c.actionElement,c.valueSelector,e,u.actionElement,u.valueSelector]),f=V(()=>Object.assign({},d(`addGroupAction`,u.addGroupAction,c.addGroupAction),d(`addRuleAction`,u.addRuleAction,c.addRuleAction),d(`cloneGroupAction`,u.cloneGroupAction,c.cloneGroupAction),d(`cloneRuleAction`,u.cloneRuleAction,c.cloneRuleAction),d(`combinatorSelector`,u.combinatorSelector,c.combinatorSelector),d(`dragHandle`,u.dragHandle,c.dragHandle),d(`fieldSelector`,u.fieldSelector,c.fieldSelector),d(`inlineCombinator`,u.inlineCombinator,c.inlineCombinator),d(`lockGroupAction`,u.lockGroupAction,c.lockGroupAction),d(`lockRuleAction`,u.lockRuleAction,c.lockRuleAction),d(`muteGroupAction`,u.muteGroupAction,c.muteGroupAction),d(`muteRuleAction`,u.muteRuleAction,c.muteRuleAction),d(`notToggle`,u.notToggle,c.notToggle),d(`operatorSelector`,u.operatorSelector,c.operatorSelector),d(`removeGroupAction`,u.removeGroupAction,c.removeGroupAction),d(`removeRuleAction`,u.removeRuleAction,c.removeRuleAction),d(`shiftActions`,u.shiftActions,c.shiftActions),{valueEditor:u.valueEditor===null?Tt:u.valueEditor??(c.valueEditor===null?Tt:c.valueEditor)??Ht.valueEditor},d(`valueSourceSelector`,u.valueSourceSelector,c.valueSourceSelector),d(`matchModeEditor`,u.matchModeEditor,c.matchModeEditor),d(`rule`,u.rule,c.rule),d(`ruleGroup`,u.ruleGroup,c.ruleGroup),d(`ruleGroupBodyElements`,u.ruleGroupBodyElements,c.ruleGroupBodyElements),d(`ruleGroupHeaderElements`,u.ruleGroupHeaderElements,c.ruleGroupHeaderElements),{actionElement:u.actionElement??c.actionElement??(e?Ht.actionElement:void 0)},{valueSelector:u.valueSelector??c.valueSelector??(e?Ht.valueSelector:void 0)}),[c.actionElement,c.addGroupAction,c.addRuleAction,c.cloneGroupAction,c.cloneRuleAction,c.combinatorSelector,c.dragHandle,c.fieldSelector,c.inlineCombinator,c.lockGroupAction,c.lockRuleAction,c.muteGroupAction,c.muteRuleAction,c.matchModeEditor,c.notToggle,c.operatorSelector,c.removeGroupAction,c.removeRuleAction,c.rule,c.ruleGroup,c.ruleGroupBodyElements,c.ruleGroupHeaderElements,c.shiftActions,c.valueEditor,c.valueSelector,c.valueSourceSelector,d,e,u.actionElement,u.addGroupAction,u.addRuleAction,u.cloneGroupAction,u.cloneRuleAction,u.combinatorSelector,u.dragHandle,u.fieldSelector,u.inlineCombinator,u.lockGroupAction,u.lockRuleAction,u.muteGroupAction,u.muteRuleAction,u.matchModeEditor,u.notToggle,u.operatorSelector,u.removeGroupAction,u.removeRuleAction,u.rule,u.ruleGroup,u.ruleGroupBodyElements,u.ruleGroupHeaderElements,u.shiftActions,u.valueEditor,u.valueSelector,u.valueSourceSelector]),p=t.translations??Dt,m=n.translations??Dt,h=V(()=>Object.assign({},w(`addGroup`,{label:[p.addGroup?.label,m.addGroup?.label],title:[p.addGroup?.title,m.addGroup?.title]},e?l:void 0),w(`addRule`,{label:[p.addRule?.label,m.addRule?.label],title:[p.addRule?.title,m.addRule?.title]},e?l:void 0),w(`cloneRule`,{label:[p.cloneRule?.label,m.cloneRule?.label],title:[p.cloneRule?.title,m.cloneRule?.title]},e?l:void 0),w(`cloneRuleGroup`,{label:[p.cloneRuleGroup?.label,m.cloneRuleGroup?.label],title:[p.cloneRuleGroup?.title,m.cloneRuleGroup?.title]},e?l:void 0),w(`combinators`,{title:[p.combinators?.title,m.combinators?.title]},e?l:void 0),w(`dragHandle`,{label:[p.dragHandle?.label,m.dragHandle?.label],title:[p.dragHandle?.title,m.dragHandle?.title]},e?l:void 0),w(`fields`,{placeholderGroupLabel:[p.fields?.placeholderGroupLabel,m.fields?.placeholderGroupLabel],placeholderLabel:[p.fields?.placeholderLabel,m.fields?.placeholderLabel],placeholderName:[p.fields?.placeholderName,m.fields?.placeholderName],title:[p.fields?.title,m.fields?.title]},e?l:void 0),w(`lockGroup`,{label:[p.lockGroup?.label,m.lockGroup?.label],title:[p.lockGroup?.title,m.lockGroup?.title]},e?l:void 0),w(`lockGroupDisabled`,{label:[p.lockGroupDisabled?.label,m.lockGroupDisabled?.label],title:[p.lockGroupDisabled?.title,m.lockGroupDisabled?.title]},e?l:void 0),w(`lockRule`,{label:[p.lockRule?.label,m.lockRule?.label],title:[p.lockRule?.title,m.lockRule?.title]},e?l:void 0),w(`lockRuleDisabled`,{label:[p.lockRuleDisabled?.label,m.lockRuleDisabled?.label],title:[p.lockRuleDisabled?.title,m.lockRuleDisabled?.title]},e?l:void 0),w(`muteGroup`,{label:[p.muteGroup?.label,m.muteGroup?.label],title:[p.muteGroup?.title,m.muteGroup?.title]},e?l:void 0),w(`unmuteGroup`,{label:[p.unmuteGroup?.label,m.unmuteGroup?.label],title:[p.unmuteGroup?.title,m.unmuteGroup?.title]},e?l:void 0),w(`muteRule`,{label:[p.muteRule?.label,m.muteRule?.label],title:[p.muteRule?.title,m.muteRule?.title]},e?l:void 0),w(`unmuteRule`,{label:[p.unmuteRule?.label,m.unmuteRule?.label],title:[p.unmuteRule?.title,m.unmuteRule?.title]},e?l:void 0),w(`notToggle`,{label:[p.notToggle?.label,m.notToggle?.label],title:[p.notToggle?.title,m.notToggle?.title]},e?l:void 0),w(`operators`,{placeholderGroupLabel:[p.operators?.placeholderGroupLabel,m.operators?.placeholderGroupLabel],placeholderLabel:[p.operators?.placeholderLabel,m.operators?.placeholderLabel],placeholderName:[p.operators?.placeholderName,m.operators?.placeholderName],title:[p.operators?.title,m.operators?.title]},e?l:void 0),w(`values`,{placeholderGroupLabel:[p.values?.placeholderGroupLabel,m.values?.placeholderGroupLabel],placeholderLabel:[p.values?.placeholderLabel,m.values?.placeholderLabel],placeholderName:[p.values?.placeholderName,m.values?.placeholderName],title:[p.values?.title,m.values?.title]},e?l:void 0),w(`removeGroup`,{label:[p.removeGroup?.label,m.removeGroup?.label],title:[p.removeGroup?.title,m.removeGroup?.title]},e?l:void 0),w(`removeRule`,{label:[p.removeRule?.label,m.removeRule?.label],title:[p.removeRule?.title,m.removeRule?.title]},e?l:void 0),w(`shiftActionDown`,{label:[p.shiftActionDown?.label,m.shiftActionDown?.label],title:[p.shiftActionDown?.title,m.shiftActionDown?.title]},e?l:void 0),w(`shiftActionUp`,{label:[p.shiftActionUp?.label,m.shiftActionUp?.label],title:[p.shiftActionUp?.title,m.shiftActionUp?.title]},e?l:void 0),w(`matchMode`,{title:[p.matchMode?.title,m.matchMode?.title]},e?l:void 0),w(`matchThreshold`,{title:[p.matchThreshold?.title,m.matchThreshold?.title]},e?l:void 0),w(`value`,{title:[p.value?.title,m.value?.title]},e?l:void 0),w(`valueSourceSelector`,{title:[p.valueSourceSelector?.title,m.valueSourceSelector?.title]},e?l:void 0)),[m.addGroup?.label,m.addGroup?.title,m.addRule?.label,m.addRule?.title,m.cloneRule?.label,m.cloneRule?.title,m.cloneRuleGroup?.label,m.cloneRuleGroup?.title,m.combinators?.title,m.dragHandle?.label,m.dragHandle?.title,m.fields?.placeholderGroupLabel,m.fields?.placeholderLabel,m.fields?.placeholderName,m.fields?.title,m.lockGroup?.label,m.lockGroup?.title,m.lockGroupDisabled?.label,m.lockGroupDisabled?.title,m.lockRule?.label,m.lockRule?.title,m.lockRuleDisabled?.label,m.lockRuleDisabled?.title,m.muteGroup?.label,m.muteGroup?.title,m.unmuteGroup?.label,m.unmuteGroup?.title,m.muteRule?.label,m.muteRule?.title,m.unmuteRule?.label,m.unmuteRule?.title,m.matchMode?.title,m.matchThreshold?.title,m.notToggle?.label,m.notToggle?.title,m.operators?.placeholderGroupLabel,m.operators?.placeholderLabel,m.operators?.placeholderName,m.operators?.title,m.removeGroup?.label,m.removeGroup?.title,m.removeRule?.label,m.removeRule?.title,m.shiftActionDown?.label,m.shiftActionDown?.title,m.shiftActionUp?.label,m.shiftActionUp?.title,m.value?.title,m.values?.placeholderGroupLabel,m.values?.placeholderLabel,m.values?.placeholderName,m.values?.title,m.valueSourceSelector?.title,e,p.addGroup?.label,p.addGroup?.title,p.addRule?.label,p.addRule?.title,p.cloneRule?.label,p.cloneRule?.title,p.cloneRuleGroup?.label,p.cloneRuleGroup?.title,p.combinators?.title,p.dragHandle?.label,p.dragHandle?.title,p.fields?.placeholderGroupLabel,p.fields?.placeholderLabel,p.fields?.placeholderName,p.fields?.title,p.lockGroup?.label,p.lockGroup?.title,p.lockGroupDisabled?.label,p.lockGroupDisabled?.title,p.lockRule?.label,p.lockRule?.title,p.lockRuleDisabled?.label,p.lockRuleDisabled?.title,p.muteGroup?.label,p.muteGroup?.title,p.unmuteGroup?.label,p.unmuteGroup?.title,p.muteRule?.label,p.muteRule?.title,p.unmuteRule?.label,p.unmuteRule?.title,p.matchMode?.title,p.matchThreshold?.title,p.notToggle?.label,p.notToggle?.title,p.operators?.placeholderGroupLabel,p.operators?.placeholderLabel,p.operators?.placeholderName,p.operators?.title,p.removeGroup?.label,p.removeGroup?.title,p.removeRule?.label,p.removeRule?.title,p.shiftActionDown?.label,p.shiftActionDown?.title,p.shiftActionUp?.label,p.shiftActionUp?.title,p.value?.title,p.values?.placeholderGroupLabel,p.values?.placeholderLabel,p.values?.placeholderName,p.values?.title,p.valueSourceSelector?.title]);return{...r,controlClassnames:s,controlElements:f,enableDragAndDrop:i,translations:h,initialQuery:t.initialQuery,qbId:t.qbId}},kt=e=>V(()=>A(e),Object.values(e)),At=({disabled:e,path:t,nestedArray:n,disabledPaths:r})=>{let i=n.length;return V(()=>{let n=[];for(let a=0;a<i;a++){let i=[...t,a];n[a]={path:i,disabled:e||r.some(e=>O(i,e))}}return n},[e,t,i,r])},jt=(e,t,n,r)=>ue(e,t,n,r),Mt=(e,t,n)=>le(e,t,n);let Nt=!1;const Pt=(e,t)=>{process.env.NODE_ENV!==`production`&&!Nt&&e&&!t&&(console.error(K.errorEnabledDndWithoutReactDnD),Nt=!0)},$=e=>z((t,n)=>{t?.preventDefault(),t?.stopPropagation(),e(t,n)},[e]),Ft={mode:`all`},It=[{name:``,value:``,label:``}],Lt=I.memo(function(e){let n=Vt(e),r=$(n.cloneRule),i=$(n.toggleLockRule),a=$(n.toggleMuteRule),o=$(n.removeRule),s=$(n.shiftRuleUp),c=$(n.shiftRuleDown),l=V(()=>({cloneRule:r,toggleLockRule:i,toggleMuteRule:a,removeRule:o,shiftRuleUp:s,shiftRuleDown:c}),[r,o,c,s,i,a]);return I.createElement(`div`,{ref:n.dndRef,"data-testid":t.rule,"data-dragmonitorid":n.dragMonitorId,"data-dropmonitorid":n.dropMonitorId,className:n.outerClassName,"data-rule-id":n.id,"data-level":n.path.length,"data-path":JSON.stringify(n.path)},n.matchModes.length>0?I.createElement(Bt,{...n,...l}):I.createElement(Rt,{...n,...l}))}),Rt=I.memo(function(e){let{schema:{controls:{shiftActions:n,dragHandle:r,fieldSelector:i,matchModeEditor:a,operatorSelector:o,valueSourceSelector:s,valueEditor:c,cloneRuleAction:l,lockRuleAction:u,muteRuleAction:d,removeRuleAction:f,ruleGroupBodyElements:p,ruleGroupHeaderElements:m}},groupComponentsWrapper:h=I.Fragment}=e,g=V(()=>({level:e.path.length,path:e.path,disabled:e.disabled,context:e.context,validation:e.validationResult,schema:e.schema,rule:e.rule}),[e.path,e.disabled,e.context,e.validationResult,e.schema,e.rule]),ee=V(()=>!(e.schema.fields.length===1&&x(e.schema.fields[0])&&`value`in e.schema.fields[0]&&e.schema.fields[0].value===``),[e.schema.fields]),te=V(()=>e.schema.showShiftActions?{shiftUp:e.translations.shiftActionUp.title,shiftDown:e.translations.shiftActionDown.title}:void 0,[e.schema.showShiftActions,e.translations]),_=V(()=>e.schema.showShiftActions?{shiftUp:e.translations.shiftActionUp.label,shiftDown:e.translations.shiftActionDown.label}:void 0,[e.schema.showShiftActions,e.translations]);return I.createElement(I.Fragment,null,e.schema.showShiftActions&&I.createElement(n,{key:t.shiftActions,...g,testID:t.shiftActions,titles:te,labels:_,className:e.classNames.shiftActions,ruleOrGroup:e.rule,shiftUp:e.shiftRuleUp,shiftDown:e.shiftRuleDown,shiftUpDisabled:e.shiftUpDisabled,shiftDownDisabled:e.shiftDownDisabled}),e.schema.enableDragAndDrop&&I.createElement(r,{key:t.dragHandle,...g,testID:t.dragHandle,ref:e.dragRef,title:e.translations.dragHandle.title,label:e.translations.dragHandle.label,className:e.classNames.dragHandle,ruleOrGroup:e.rule}),ee&&I.createElement(i,{key:t.fields,...g,testID:t.fields,options:e.schema.fields,title:e.translations.fields.title,value:e.rule.field,operator:e.rule.operator,className:e.classNames.fields,handleOnChange:e.onChangeField}),(e.schema.autoSelectField||e.rule.field!==e.translations.fields.placeholderName)&&(e.subQuery?I.createElement(a,{key:t.matchModeEditor,...g,testID:t.matchModeEditor,field:e.rule.field,fieldData:e.fieldData,title:e.translations.matchMode.title,options:e.matchModes,match:e.rule.match??Ft,className:e.classNames.matchMode,classNames:e.classNames,handleOnChange:e.onChangeMatchMode}):I.createElement(I.Fragment,null,I.createElement(o,{key:t.operators,...g,testID:t.operators,field:e.rule.field,fieldData:e.fieldData,title:e.translations.operators.title,options:e.operators,value:e.rule.operator,className:e.classNames.operators,handleOnChange:e.onChangeOperator}),(e.schema.autoSelectOperator||e.rule.operator!==e.translations.operators.placeholderName)&&!e.hideValueControls&&I.createElement(I.Fragment,null,![`null`,`notnull`].includes(oe(`${e.rule.operator}`))&&e.valueSources.length>1&&I.createElement(s,{key:t.valueSourceSelector,...g,testID:t.valueSourceSelector,field:e.rule.field,fieldData:e.fieldData,title:e.translations.valueSourceSelector.title,options:e.valueSourceOptions,value:e.rule.valueSource??`value`,className:e.classNames.valueSource,handleOnChange:e.onChangeValueSource}),I.createElement(c,{key:t.valueEditor,...g,testID:t.valueEditor,field:e.rule.field,fieldData:e.fieldData,title:e.translations.value.title,operator:e.rule.operator,value:e.rule.value,valueSource:e.rule.valueSource??`value`,type:e.valueEditorType,inputType:e.inputType,values:e.values,listsAsArrays:e.schema.listsAsArrays,parseNumbers:e.schema.parseNumbers,separator:e.valueEditorSeparator,className:e.classNames.value,handleOnChange:e.onChangeValue})))),e.subQuery&&I.createElement(h,{className:e.subQuery.classNames.header},I.createElement(m,