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 111 kB
import{createContext as qr}from"react";var Ke=qr({});import{jsx as Qr}from"react/jsx-runtime";var Xe=t=>Qr("button",{type:"button","data-testid":t.testID,disabled:t.disabled&&!t.disabledTranslation,className:t.className,title:t.disabledTranslation&&t.disabled?t.disabledTranslation.title:t.title,onClick:e=>t.handleOnClick(e),children:t.disabledTranslation&&t.disabled?t.disabledTranslation.label:t.label});import{jsx as Fr}from"react/jsx-runtime";import{forwardRef as jr}from"react";var gl=jr((t,e)=>Fr("span",{"data-testid":t.testID,ref:e,className:t.className,title:t.title,children:t.label}));var Eo="~",Ct="------",ko=Eo,Mr=Ct,Wr=Ct,To=Eo,Hr=Ct,_r=Ct,Ur=Eo,zr=Ct,Jr=Ct,lo=",",ro={fields:{title:"Fields",placeholderName:ko,placeholderLabel:Mr,placeholderGroupLabel:Wr},operators:{title:"Operators",placeholderName:To,placeholderLabel:Hr,placeholderGroupLabel:_r},values:{title:"Values",placeholderName:Ur,placeholderLabel:zr,placeholderGroupLabel:Jr},value:{title:"Value"},removeRule:{label:"\u2A2F",title:"Remove rule"},removeGroup:{label:"\u2A2F",title:"Remove group"},addRule:{label:"+ Rule",title:"Add rule"},addGroup:{label:"+ Group",title:"Add group"},combinators:{title:"Combinators"},notToggle:{label:"Not",title:"Invert this group"},cloneRule:{label:"\u29C9",title:"Clone rule"},cloneRuleGroup:{label:"\u29C9",title:"Clone group"},shiftActionUp:{label:"\u02C4",title:"Shift up"},shiftActionDown:{label:"\u02C5",title:"Shift down"},dragHandle:{label:"\u205E\u205E",title:"Drag handle"},lockRule:{label:"\u{1F513}",title:"Lock rule"},lockGroup:{label:"\u{1F513}",title:"Lock group"},lockRuleDisabled:{label:"\u{1F512}",title:"Unlock rule"},lockGroupDisabled:{label:"\u{1F512}",title:"Unlock group"},valueSourceSelector:{title:"Value source"}},vl=[{name:"=",value:"=",label:"="},{name:"!=",value:"!=",label:"!="},{name:"<",value:"<",label:"<"},{name:">",value:">",label:">"},{name:"<=",value:"<=",label:"<="},{name:">=",value:">=",label:">="},{name:"contains",value:"contains",label:"contains"},{name:"beginsWith",value:"beginsWith",label:"begins with"},{name:"endsWith",value:"endsWith",label:"ends with"},{name:"doesNotContain",value:"doesNotContain",label:"does not contain"},{name:"doesNotBeginWith",value:"doesNotBeginWith",label:"does not begin with"},{name:"doesNotEndWith",value:"doesNotEndWith",label:"does not end with"},{name:"null",value:"null",label:"is null"},{name:"notNull",value:"notNull",label:"is not null"},{name:"in",value:"in",label:"in"},{name:"notIn",value:"notIn",label:"not in"},{name:"between",value:"between",label:"between"},{name:"notBetween",value:"notBetween",label:"not between"}],sa={"=":"!=","!=":"=","<":">=","<=":">",">":"<=",">=":"<",beginsWith:"doesNotBeginWith",doesNotBeginWith:"beginsWith",endsWith:"doesNotEndWith",doesNotEndWith:"endsWith",contains:"doesNotContain",doesNotContain:"contains",between:"notBetween",notBetween:"between",in:"notIn",notIn:"in",notNull:"null",null:"notNull"},_e=[{name:"and",value:"and",label:"AND"},{name:"or",value:"or",label:"OR"}],ia=[..._e,{name:"xor",value:"xor",label:"XOR"}],Q={queryBuilder:"queryBuilder",ruleGroup:"ruleGroup",header:"ruleGroup-header",body:"ruleGroup-body",combinators:"ruleGroup-combinators",addRule:"ruleGroup-addRule",addGroup:"ruleGroup-addGroup",cloneRule:"rule-cloneRule",cloneGroup:"ruleGroup-cloneGroup",removeGroup:"ruleGroup-remove",notToggle:"ruleGroup-notToggle",rule:"rule",fields:"rule-fields",operators:"rule-operators",value:"rule-value",removeRule:"rule-remove",betweenRules:"betweenRules",valid:"queryBuilder-valid",invalid:"queryBuilder-invalid",shiftActions:"shiftActions",dndDragging:"dndDragging",dndOver:"dndOver",dndCopy:"dndCopy",dndGroup:"dndGroup",dragHandle:"queryBuilder-dragHandle",disabled:"queryBuilder-disabled",lockRule:"rule-lock",lockGroup:"ruleGroup-lock",valueSource:"rule-valueSource",valueListItem:"rule-value-list-item",branches:"queryBuilder-branches"},yl={queryBuilder:"",ruleGroup:"",header:"",body:"",combinators:"",addRule:"",addGroup:"",cloneRule:"",cloneGroup:"",removeGroup:"",notToggle:"",rule:"",fields:"",operators:"",value:"",removeRule:"",shiftActions:"",dragHandle:"",lockRule:"",lockGroup:"",valueSource:"",actionElement:"",valueSelector:"",betweenRules:"",valid:"",invalid:"",dndDragging:"",dndOver:"",dndGroup:"",dndCopy:"",disabled:"",valueListItem:"",branches:""},no={empty:"empty",invalidCombinator:"invalid combinator",invalidIndependentCombinators:"invalid independent combinators"},F={rule:"rule",ruleGroup:"rule-group",inlineCombinator:"inline-combinator",addGroup:"add-group",removeGroup:"remove-group",cloneGroup:"clone-group",cloneRule:"clone-rule",addRule:"add-rule",removeRule:"remove-rule",combinators:"combinators",fields:"fields",operators:"operators",valueEditor:"value-editor",notToggle:"not-toggle",shiftActions:"shift-actions",dragHandle:"drag-handle",lockRule:"lock-rule",lockGroup:"lock-group",valueSourceSelector:"value-source-selector"},he={parentPathDisabled:"action aborted: parent path disabled",pathDisabled:"action aborted: path is disabled",queryUpdate:"query updated",onAddRuleFalse:"onAddRule callback returned false",onAddGroupFalse:"onAddGroup callback returned false",onGroupRuleFalse:"onGroupRule callback returned false",onGroupGroupFalse:"onGroupGroup callback returned false",onMoveRuleFalse:"onMoveRule callback returned false",onMoveGroupFalse:"onMoveGroup callback returned false",onRemoveFalse:"onRemove callback returned false",add:"rule or group added",remove:"rule or group removed",update:"rule or group updated",move:"rule or group moved",group:"rule or group grouped with another"},Rl=[];import{jsx as Al}from"react/jsx-runtime";function Gl(t){let e,l,o="";if(typeof t=="string"||typeof t=="number")o+=t;else if(typeof t=="object")if(Array.isArray(t)){let r=t.length;for(e=0;e<r;e++)t[e]&&(l=Gl(t[e]))&&(o&&(o+=" "),o+=l)}else for(l in t)t[l]&&(o&&(o+=" "),o+=l);return o}function Y(){let t=0,e,l,o="",r=arguments.length;for(;t<r;t++)(e=t<0||arguments.length<=t?void 0:arguments[t])&&(l=Gl(e))&&(o&&(o+=" "),o+=l);return o}var Nl=Y;var $l=t=>{let{component:e,...l}=t,o=Y(l.schema.suppressStandardClassnames||Q.betweenRules,l.schema.classNames.betweenRules);return Al("div",{className:o,"data-testid":F.inlineCombinator,children:Al(e,{...l,testID:F.combinators})})};import{jsx as Kr,jsxs as Xr}from"react/jsx-runtime";var Cl=t=>Xr("label",{"data-testid":t.testID,className:t.className,title:t.title,children:[Kr("input",{type:"checkbox",onChange:e=>t.handleOnChange(e.target.checked),checked:!!t.checked,disabled:t.disabled}),t.label]});var nt={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."};import*as xl from"react";var Ft=xl.createContext(null);import{createDispatchHook as on,createStoreHook as ln}from"react-redux";import{createSlice as Yr}from"@reduxjs/toolkit";var Zr={},ht=Yr({name:"queries",initialState:Zr,reducers:{setQueryState:(t,e)=>{let{payload:{qbId:l,query:o}}=e;t[l]=o}},selectors:{getQuerySelectorById:(t,e)=>t[e]}});import{createSlice as en}from"@reduxjs/toolkit";var tn={[nt.errorInvalidIndependentCombinatorsProp]:!1,[nt.errorUnnecessaryIndependentCombinatorsProp]:!1,[nt.errorDeprecatedRuleGroupProps]:!1,[nt.errorDeprecatedRuleProps]:!1,[nt.errorBothQueryDefaultQuery]:!1,[nt.errorUncontrolledToControlled]:!1,[nt.errorControlledToUncontrolled]:!1,[nt.errorEnabledDndWithoutReactDnD]:!1},ao=en({name:"warnings",initialState:tn,reducers:{rqbWarn:(t,e)=>{let{payload:l}=e;t[l]||(console.error(l),t[l]=!0)}}});var so=t=>{let{payload:e,onQueryChange:l}=t;return o=>{o(ht.actions.setQueryState(e)),typeof l=="function"&&l(e.query)}},xt=on(Ft),Sl=ln(Ft),{rqbWarn:wa}=ao.actions;var rn={queries:ht.getInitialState(),warnings:ao.getInitialState()},Da={reducer:{queries:ht.reducer,warnings:ao.reducer},preloadedState:rn,middleware:t=>t({serializableCheck:{ignoredActions:[ht.actions.setQueryState.type],ignoredPaths:[/^queries\b.*\.rules\.\d+\.value$/]}})};function St(t,e,l){xt()}var io=(t,e)=>{};import*as Dl from"react";var wl=Symbol.for("react.memo_cache_sentinel");function be(t){return Dl.useMemo(()=>{let e=Array.from({length:t});for(let l=0;l<t;l++)e[l]=wl;return e[wl]=!0,e},[])}import"react";var Be=t=>{let e=be(2),l;return e[0]!==t?(l=(o,r)=>{o?.preventDefault(),o?.stopPropagation(),t(o,r)},e[0]=t,e[1]=l):l=e[1],l};var Io=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lo;return typeof t=="string"?t.split(`\\${e}`).map(l=>l.split(e)).reduce((l,o,r)=>r===0?o:[...l.slice(0,-1),`${l.at(-1)}${e}${o[0]}`,...o.slice(1)],[]):[]},ct=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lo;return t.map(l=>`${l??""}`.replaceAll(e[0],`\\${e[0]}`)).join(e)},re=t=>typeof t=="string"?t.trim():t,z=function(t){let{retainEmptyStrings:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Array.isArray(t)?t.map(l=>re(l)):typeof t=="string"?Io(t,lo).filter(e?()=>!0:l=>!/^\s*$/.test(l)).map(l=>l.trim()):typeof t=="number"?[t]:[]},Qa=t=>t.every(e=>e===!1||(e??!1)!==!1);import{numericRegex as nn}from"numeric-quantity";var Ol=new RegExp(nn.source.replace(/^\^/,String.raw`^\s*`).replace(/\$$/,String.raw`\s*$`)),$e=t=>t===null||typeof t!="object"?!1:Object.getPrototypeOf(t)===Object.prototype,at=t=>t==null||t==="";var q=t=>$e(t)&&Array.isArray(t.rules),se=t=>q(t)&&typeof t.combinator=="string",Me=t=>q(t)&&t.combinator===void 0;import{produce as an}from"immer";var Ll=["or","xor","and"],sn=(t,e)=>typeof t=="string"&&t.toLowerCase()===e,uo=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,l=Ll[e];return t.rules.includes(l)?an(t,o=>{let r=0;for(;r<o.rules.length-2;){if(sn(o.rules[r+1],l)){r+=2;continue}let s=o.rules.findIndex((a,c)=>c>r&&typeof a=="string"&&a.toLowerCase()===l);if(s===-1){o.rules.splice(r,o.rules.length,uo({rules:o.rules.slice(r)},e+1));break}else o.rules.splice(r,s-r,uo({rules:o.rules.slice(r,s)},e+1))}}):e<Ll.length-2?uo(t,e+1):t},dt=t=>{if(se(t))return t;let e=uo(t),l=e.rules.map(s=>typeof s=="string"||!q(s)?s:dt(s)),o=l.length<2?"and":l[1],r=l.filter(s=>typeof s!="string");return{...e,combinator:o,rules:r}},Pl=t=>{if(Me(t))return t;let{combinator:e,...l}=t,o=[],{length:r}=t.rules;for(let[s,a]of t.rules.entries())q(a)?o.push(Pl(a)):o.push(a),e&&s<r-1&&o.push(e);return{...l,rules:o}};function za(t){return Me(t)?dt(t):Pl(t)}var Ya=t=>{let e={},l=r=>{},o=r=>{let s=[];if(r.rules.length===0)s.push(no.empty);else if(!se(r)){let a=!1;for(let c=0;c<r.rules.length&&!a;c++)(c%2===0&&typeof r.rules[c]=="string"||c%2===1&&typeof r.rules[c]!="string"||c%2===1&&typeof r.rules[c]=="string"&&!_e.map(h=>h.name).includes(r.rules[c]))&&(a=!0);a&&s.push(no.invalidIndependentCombinators)}se(r)&&!_e.map(a=>a.name).includes(r.combinator)&&r.rules.length>1&&s.push(no.invalidCombinator),r.id&&(e[r.id]=s.length>0?{valid:!1,reasons:s}:!0);for(let a of r.rules)typeof a=="string"||(q(a)?o(a):l(a))};return o(t),e};import{produce as El}from"immer";var co=t=>$e(t)&&"name"in t&&typeof t.name=="string",po=t=>$e(t)&&"value"in t&&typeof t.value=="string";function Ve(t,e){return El(o=>{let r={},s=!!e;if(co(o)&&!po(o)?(r.value=o.name,s=!0):!co(o)&&po(o)&&(r.name=o.value,s=!0),s)return Object.assign({},e,o,r)})(t)}function Le(t,e){return Array.isArray(t)?El(o=>{if(qe(o))for(let r of o)for(let[s,a]of r.options.entries())r.options[s]=Ve(a,e);else for(let[r,s]of o.entries())o[r]=Ve(s,e)})(t):[]}function Bo(t,e){return Object.fromEntries(Object.entries(t).map(l=>{let[o,r]=l;return[o,Ve(r,e)]}))}var os=t=>wt(t),wt=t=>{let e=new Set,l=[];for(let o of t)e.has(o.value??o.name)||(e.add(o.value??o.name),l.push(o));return t.length===l.length?t:l},Vo=t=>Array.isArray(t)&&t.length>0&&$e(t[0])&&"options"in t[0]&&Array.isArray(t[0].options),qo=t=>{let e=!1;if(Array.isArray(t))for(let l of t)if(co(l)||po(l))e=!0;else return!1;return e},un=t=>{let e=!1;if(Array.isArray(t))for(let l of t)if(co(l)&&po(l))e=!0;else return!1;return e},qe=function(t){let{allowEmpty:e=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},l=!1;if(Array.isArray(t))for(let o of t)if($e(o)&&"options"in o&&(qo(o.options)||e&&Array.isArray(o.options)&&o.options.length===0))l=!0;else return!1;return l},ls=function(t){let{allowEmpty:e=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},l=!1;if(Array.isArray(t))for(let o of t)if($e(o)&&"options"in o&&(un(o.options)||e&&Array.isArray(o.options)&&o.options.length===0))l=!0;else return!1;return l},ce=(t,e)=>(qe(t,{allowEmpty:!0})?t.flatMap(l=>l.options):t).find(l=>l.value===e||l.name===e),ve=t=>{if(!Array.isArray(t)||t.length===0)return null;if(qe(t,{allowEmpty:!0})){for(let e of t)if(e.options.length>0)return e.options[0].value??e.options[0].name;return null}return t[0].value??t[0].name},kl=t=>wt(Vo(t)?t.flatMap(e=>e.options):t),mo=t=>{let e=new Set,l=new Set,o=[];for(let r of t)if(!e.has(r.label)){e.add(r.label);let s=[];for(let a of r.options)l.has(a.value??a.name)||(l.add(a.value??a.name),s.push(Ve(a)));o.push({...r,options:s})}return o},Tl=t=>qe(t)?mo(t):wt(t.map(e=>Ve(e)));var Il=(t,e,l)=>{let o=Ve(t),r=Ve(l);return o.value===r.value?!1:typeof o.comparator=="string"?o[o.comparator]===r[o.comparator]:o.comparator?.(r,e)??!1},fo=(t,e,l)=>{if(!t.comparator){let o=r=>(r.value??r.name)!==(t.value??t.name);return qe(e)?e.map(r=>({...r,options:r.options.filter(s=>o(s))})):e.filter(r=>o(r))}return qe(e)?e.map(o=>({...o,options:o.options.filter(r=>Il(t,l,r))})).filter(o=>o.options.length>0):e.filter(o=>Il(t,l,o))};import{numericQuantity as cn}from"numeric-quantity";var J=function(t){let{parseNumbers:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e||typeof t=="bigint"||typeof t=="number")return t;if(e==="native")return parseFloat(t);let l=cn(t,{allowTrailingInvalid:e==="enhanced",romanNumerals:!1,round:!1});return isNaN(l)?t:l};var Dt=t=>{let{parseNumbers:e,inputType:l}=t;if(typeof e=="string"){let[o,r]=e.split("-");return r==="limited"?l==="number"?o:!1:o}return e?"strict":!1};var ql=t=>{switch(t.toLowerCase()){case"null":return"is null";case"notnull":return"is not null";case"notin":return"not in";case"notbetween":return"not between";case"contains":case"beginswith":case"endswith":return"like";case"doesnotcontain":case"doesnotbeginwith":case"doesnotendwith":return"not like";default:return t}},Fo={"=":"$eq","!=":"$ne","<":"$lt","<=":"$lte",">":"$gt",">=":"$gte",in:"$in",notin:"$nin",notIn:"$nin"},jo={and:"&&",or:"||"},bs={startsWith:(t,e)=>typeof t=="string"&&t.startsWith(e),endsWith:(t,e)=>typeof t=="string"&&t.endsWith(e)},Mo=(t,e)=>({...t,rules:t.rules.map(l=>{if(typeof l=="string")return l;if(q(l))return Mo(l,e);let o=ce(e.fields,l.field),r=Dt({parseNumbers:e.parseNumbers,inputType:o?.inputType});if(Array.isArray(l.value))return{...l,value:l.value.map(a=>J(a,{parseNumbers:r}))};let s=z(l.value,{retainEmptyStrings:!0}).map(a=>J(a,{parseNumbers:r}));if(s.every(a=>typeof a=="number")){if(s.length>1)return{...l,value:s};if(s.length===1)return{...l,value:s[0]}}return l})}),Pe=t=>typeof t=="string"&&t.length>0||typeof t=="number"&&!isNaN(t)||typeof t!="string"&&typeof t!="number",M=(t,e)=>!!e&&(typeof t=="number"||typeof t=="bigint"||typeof t=="string"&&Ol.test(t)),Ql=t=>t.length>=3,Wo=function(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["",""];return Array.isArray(t)?t:typeof t=="string"?[t,t]:t??["",""]},Ye=(t,e)=>{let{quoteFieldNamesWith:l,fieldIdentifierSeparator:o}=e,[r,s]=Wo(l);return typeof o=="string"&&o.length>0?ct(Io(t,o).map(a=>`${r}${a}${s}`),o):`${r}${t}${s}`},Bl=["S","V","O"],Fl=t=>{let e=[],l=new Set(Bl);for(let o of t.toUpperCase())if(l.has(o)&&(e.push(o),l.delete(o),l.size===0))break;for(let o of Bl)l.has(o)&&e.push(o);return e},Qo={groupPrefix:"",groupPrefix_not_xor:"either zero or more than one of",groupPrefix_xor:"exactly one of",groupSuffix:"is true",groupSuffix_not:"is not true"},Vl=(t,e,l)=>e.startsWith(t)&&l.every(o=>e.includes(`_${o}`)&&e.match(/_/g)?.length===l.length),jt=function(t,e){let l=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return l.length===0?e[t]??Qo[t]??"":Object.entries(e).find(o=>{let[r]=o;return Vl(t,r,l)})?.[1]??Object.entries(Qo).find(o=>{let[r]=o;return Vl(t,r,l)})?.[1]??Qo[t]??""};var ho=t=>t.startsWith("not")||t.startsWith("doesnot"),bt=(t,e)=>typeof t!="string"||!e?t:t.replaceAll('"','\\"'),Mt=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{escapeQuotes:s,parseNumbers:a,preserveValueOrder:c}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},h=r==="field",d=(l==="="?"==":l).toLowerCase(),p=typeof o=="number"||typeof o=="boolean"||typeof o=="bigint"||M(o,a);switch(d){case"<":case"<=":case"==":case"!=":case">":case">=":return`${e} ${d} ${h||p?re(o):`"${bt(o,s)}"`}`;case"contains":case"doesnotcontain":return`${ho(d)?"!":""}${e}.contains(${h?re(o):`"${bt(o,s)}"`})`;case"beginswith":case"doesnotbeginwith":return`${ho(d)?"!":""}${e}.startsWith(${h?re(o):`"${bt(o,s)}"`})`;case"endswith":case"doesnotendwith":return`${ho(d)?"!":""}${e}.endsWith(${h?re(o):`"${bt(o,s)}"`})`;case"null":return`${e} == null`;case"notnull":return`${e} != null`;case"in":case"notin":{let[b,g]=ho(d)?["!(",")"]:["",""],i=z(o);return`${b}${e} in [${i.map(G=>h||M(G,a)?`${re(G)}`:`"${bt(G,s)}"`).join(", ")}]${g}`}case"between":case"notbetween":{let b=z(o);if(b.length>=2&&!at(b[0])&&!at(b[1])){let[g,i]=b,G=M(g,!0)?J(g,{parseNumbers:!0}):NaN,v=M(i,!0)?J(i,{parseNumbers:!0}):NaN,y=isNaN(G)?h?`${g}`:`"${bt(g,s)}"`:G,f=isNaN(v)?h?`${i}`:`"${bt(i,s)}"`:v;if(!c&&y===G&&f===v&&v<G){let m=v;f=G,y=m}return d==="between"?`(${e} >= ${y} && ${e} <= ${f})`:`(${e} < ${y} || ${e} > ${f})`}else return""}}return""};var Wt=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{parseNumbers:s,preserveValueOrder:a}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=r==="field";if(l==="="&&!c)return{[e]:M(o,s)?J(o,{parseNumbers:"strict"}):o};let h=l.toLowerCase();switch(h){case"<":case"<=":case"=":case"!=":case">":case">=":{let d=Fo[h];return c?{$expr:{[d]:[`$${e}`,`$${o}`]}}:{[e]:{[d]:M(o,s)?J(o,{parseNumbers:"strict"}):o}}}case"contains":return c?{$where:`this.${e}.includes(this.${o})`}:{[e]:{$regex:o}};case"beginswith":return c?{$where:`this.${e}.startsWith(this.${o})`}:{[e]:{$regex:`^${o}`}};case"endswith":return c?{$where:`this.${e}.endsWith(this.${o})`}:{[e]:{$regex:`${o}$`}};case"doesnotcontain":return c?{$where:`!this.${e}.includes(this.${o})`}:{[e]:{$not:{$regex:o}}};case"doesnotbeginwith":return c?{$where:`!this.${e}.startsWith(this.${o})`}:{[e]:{$not:{$regex:`^${o}`}}};case"doesnotendwith":return c?{$where:`!this.${e}.endsWith(this.${o})`}:{[e]:{$not:{$regex:`${o}$`}}};case"null":return{[e]:null};case"notnull":return{[e]:{$ne:null}};case"in":case"notin":{let d=z(o);return c?{$where:`${h==="notin"?"!":""}[${d.map(p=>`this.${p}`).join(",")}].includes(this.${e})`}:{[e]:{[Fo[h]]:d.map(p=>M(p,s)?J(p,{parseNumbers:"strict"}):p)}}}case"between":case"notbetween":{let d=z(o);if(d.length>=2&&Pe(d[0])&&Pe(d[1])){let[p,b]=d,g=M(p,!0)?J(p,{parseNumbers:"strict"}):NaN,i=M(b,!0)?J(b,{parseNumbers:"strict"}):NaN,G=c||isNaN(g)?p:g,v=c||isNaN(i)?b:i;if(!a&&G===g&&v===i&&i<g){let y=i;v=g,G=y}return h==="between"?c?{$and:[{$expr:{$gte:[`$${e}`,`$${G}`]}},{$expr:{$lte:[`$${e}`,`$${v}`]}}]}:{[e]:{$gte:G,$lte:v}}:c?{$or:[{$expr:{$lt:[`$${e}`,`$${G}`]}},{$expr:{$gt:[`$${e}`,`$${v}`]}}]}:{$or:[{[e]:{$lt:G}},{[e]:{$gt:v}}]}}else return""}}return""};var Ht=(t,e)=>{let l=Wt(t,e);return l?JSON.stringify(l):""};var bo=t=>t.startsWith("not")||t.startsWith("doesnot"),Ho=(t,e)=>e?`!(${t})`:`${t}`,gt=(t,e)=>typeof t!="string"||!e?t:t.replaceAll("'","\\'"),_t=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{escapeQuotes:s,parseNumbers:a,preserveValueOrder:c}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},h=r==="field",d=(l==="="?"==":l).toLowerCase(),p=typeof o=="number"||typeof o=="boolean"||typeof o=="bigint"||M(o,a);switch(d){case"<":case"<=":case"==":case"!=":case">":case">=":return`${e} ${d} ${h||p?re(o):`'${gt(o,s)}'`}`;case"contains":case"doesnotcontain":return Ho(`${e} matches ${h||p?re(o):`'${gt(o,s)}'`}`,bo(d));case"beginswith":case"doesnotbeginwith":{let b=h?`'^'.concat(${re(o)})`:`'${typeof o=="string"&&!o.startsWith("^")||p?"^":""}${gt(o,s)}'`;return Ho(`${e} matches ${b}`,bo(d))}case"endswith":case"doesnotendwith":{let b=h?`${re(o)}.concat('$')`:`'${gt(o,s)}${typeof o=="string"&&!o.endsWith("$")||p?"$":""}'`;return Ho(`${e} matches ${b}`,bo(d))}case"null":return`${e} == null`;case"notnull":return`${e} != null`;case"in":case"notin":{let b=bo(d)?"!":"",g=z(o);return g.length>0?`${b}(${g.map(i=>`${e} == ${h||M(i,a)?`${re(i)}`:`'${gt(i,s)}'`}`).join(" or ")})`:""}case"between":case"notbetween":{let b=z(o);if(b.length>=2&&!at(b[0])&&!at(b[1])){let[g,i]=b,G=M(g,!0)?J(g,{parseNumbers:!0}):NaN,v=M(i,!0)?J(i,{parseNumbers:!0}):NaN,y=isNaN(G)?h?`${g}`:`'${gt(g,s)}'`:G,f=isNaN(v)?h?`${i}`:`'${gt(i,s)}'`:v;if(!c&&y===G&&f===v&&v<G){let m=v;f=G,y=m}return d==="between"?`(${e} >= ${y} and ${e} <= ${f})`:`(${e} < ${y} or ${e} > ${f})`}else return""}}return""};var dn=(t,e,l)=>l&&typeof t=="string"?t.replaceAll(`${e}`,`${e}${e}`):t,Ue=function(t){let{operator:e,value:l,valueSource:o}=t,{escapeQuotes:r,parseNumbers:s,preserveValueOrder:a,quoteFieldNamesWith:c,quoteValuesWith:h,concatOperator:d="||",fieldIdentifierSeparator:p,wrapValueWith:b=["",""],translations:g}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=o==="field",G=e.toLowerCase(),v=h||"'",y=S=>`${b[0]}${v}${S}${v}${b[1]}`,f=S=>dn(S,v,r),m=S=>y(f(S)),T=S=>Ye(S,{quoteFieldNamesWith:c,fieldIdentifierSeparator:p}),x=function(){for(var S=arguments.length,k=new Array(S),E=0;E<S;E++)k[E]=arguments[E];return d.toUpperCase()==="CONCAT"?`CONCAT(${k.join(", ")})`:k.join(` ${d} `)};switch(G){case"null":case"notnull":return"";case"in":case"notin":{let S=z(l);return S.length>0?`(${S.map(k=>i?T(k):M(k,s)?`${re(k)}`:`${m(k)}`).join(", ")})`:""}case"between":case"notbetween":{let S=z(l,{retainEmptyStrings:!0});if(S.length<2||!Pe(S[0])||!Pe(S[1]))return"";let[k,E]=S,u=M(k,s)?J(k,{parseNumbers:"strict"}):NaN,n=M(E,s)?J(E,{parseNumbers:"strict"}):NaN,_=isNaN(u)?i?`${k}`:k:u,W=isNaN(n)?i?`${E}`:E:n,B=[_,W];return!a&&_===u&&W===n&&n<u&&(B[0]=n,B[1]=u),(i?B.map($=>T($)):B.every($=>M($,s))?B.map($=>J($,{parseNumbers:"strict"})):B.map($=>m($))).join(` ${g?.and??"and"} `)}case"contains":case"doesnotcontain":return i?x(y("%"),T(l),y("%")):y(`%${f(l)}%`);case"beginswith":case"doesnotbeginwith":return i?x(T(l),y("%")):y(`${f(l)}%`);case"endswith":case"doesnotendwith":return i?x(y("%"),T(l)):y(`%${f(l)}`)}return typeof l=="boolean"?l?"TRUE":"FALSE":i?T(l):M(l,s)?`${re(l)}`:`${m(l)}`};var pn={"<":"lt","<=":"lte",">":"gt",">=":"gte"},go=(t,e)=>t.startsWith("not")||t.startsWith("doesnot")?{bool:{must_not:e}}:e,_o=t=>t?.replace(/('|\\)/g,"\\$1"),mn={beginswith:"startsWith",doesnotbeginwith:"startsWith",doesnotcontain:"contains",doesnotendwith:"endsWith",endswith:"endsWith"},fn=(t,e,l)=>{let o=`doc['${t}'].value.${mn[e]??e}(doc['${l}'].value)`;return e.startsWith("d")?`!${o}`:o},Ut=(t,e)=>typeof t=="boolean"?t:M(t,e)?J(t,{parseNumbers:e}):t,Uo=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{parseNumbers:s,preserveValueOrder:a}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=l.toLowerCase();if(r==="field"){if(z(o).some(d=>typeof d!="string"))return!1;let h=_o(e);switch(c){case"=":case"!=":case">":case">=":case"<":case"<=":{let d=c==="="?"==":c,p=_o(o);return p?{bool:{filter:{script:{script:`doc['${h}'].value ${d} doc['${p}'].value`}}}}:!1}case"in":case"notin":{let d=z(o);if(d.length>0){let p=d.map(b=>({bool:{filter:{script:{script:`doc['${h}'].value == doc['${b}'].value`}}}}));return{bool:c==="in"?{should:p}:{must_not:p}}}return!1}case"between":case"notbetween":{let d=z(o);if(d.length>=2&&d[0]&&d[1]){let p=`doc['${h}'].value >= doc['${d[0]}'].value && doc['${h}'].value <= doc['${d[1]}'].value`;return{bool:{filter:{script:{script:c==="notbetween"?`!(${p})`:p}}}}}return!1}case"contains":case"doesnotcontain":case"beginswith":case"doesnotbeginwith":case"endswith":case"doesnotendwith":{let d=_o(o);return d?{bool:{filter:{script:{script:fn(h,c,d)}}}}:!1}}}switch(c){case"<":case"<=":case">":case">=":return{range:{[e]:{[pn[c]]:Ut(o,s)}}};case"=":return{term:{[e]:Ut(o,s)}};case"!=":return{bool:{must_not:{term:{[e]:Ut(o,s)}}}};case"null":return{bool:{must_not:{exists:{field:e}}}};case"notnull":return{exists:{field:e}};case"in":case"notin":{let h=z(o).map(d=>Ut(d,s));if(h.length>0){let d=h.map(p=>({term:{[e]:Ut(p,s)}}));return{bool:c==="in"?{should:d}:{must_not:d}}}return!1}case"between":case"notbetween":{let h=z(o);if(h.length>=2&&Pe(h[0])&&Pe(h[1])){let[d,p]=h;if(M(d,!0)&&M(p,!0)){let b=J(d,{parseNumbers:!0}),g=J(p,{parseNumbers:!0});if(!a&&g<b){let i=g;p=b,d=i}else d=b,p=g}return go(c,{range:{[e]:{gte:d,lte:p}}})}return!1}case"contains":case"doesnotcontain":return go(c,{regexp:{[e]:{value:`.*${o}.*`}}});case"beginswith":case"doesnotbeginwith":return go(c,{regexp:{[e]:{value:`${o}.*`}}});case"endswith":case"doesnotendwith":return go(c,{regexp:{[e]:{value:`.*${o}`}}})}return!1};var vo=t=>t.startsWith("not")||t.startsWith("doesnot"),zt=(t,e)=>`"${typeof t!="string"||!e?t:t.replaceAll('"','\\"')}"`,Jt=(t,e)=>e?`$not(${t})`:`${t}`,jl=t=>`${t}`.replaceAll(/[$()*+.?[\\\]^{|}]/g,String.raw`\$&`).replaceAll("-",String.raw`\x2d`),zo=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{escapeQuotes:s,parseNumbers:a=!0,preserveValueOrder:c,quoteFieldNamesWith:h=["",""],fieldIdentifierSeparator:d=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},p=r==="field",b=typeof o=="number"||typeof o=="boolean"||typeof o=="bigint"||M(o,a),g=G=>Ye(G,{quoteFieldNamesWith:h,fieldIdentifierSeparator:d}),i=l.toLowerCase();switch(i){case"<":case"<=":case"=":case"!=":case">":case">=":return`${g(e)} ${i} ${p?g(re(o)):b?re(o):zt(o,s)}`;case"contains":case"doesnotcontain":return Jt(`$contains(${g(e)}, ${p?g(re(o)):zt(o,s)})`,vo(i));case"beginswith":case"doesnotbeginwith":return Jt(p?`$substring(${g(e)}, 0, $length(${g(re(o))})) = ${g(re(o))}`:`$contains(${g(e)}, /^${jl(o)}/)`,vo(i));case"endswith":case"doesnotendwith":return Jt(p?`$substring(${g(e)}, $length(${g(e)}) - $length(${g(re(o))})) = ${g(re(o))}`:`$contains(${g(e)}, /${jl(o)}$/)`,vo(i));case"null":return`${g(e)} = null`;case"notnull":return`${g(e)} != null`;case"in":case"notin":{let G=z(o);return Jt(`${g(e)} in [${G.map(v=>p?`${g(re(v))}`:M(v,a)?`${re(v)}`:zt(v,s)).join(", ")}]`,vo(i))}case"between":case"notbetween":{let G=z(o);if(G.length<2||at(G[0])||at(G[1]))return"";let[v,y]=G,f=M(v,!0)?J(v,{parseNumbers:!0}):NaN,m=M(y,!0)?J(y,{parseNumbers:!0}):NaN,T=isNaN(f)?p?`${v}`:v:f,x=isNaN(m)?p?`${y}`:y:m;if(!c&&T===f&&x===m&&m<f){let E=m;x=f,T=E}let S=M(v,a)&&M(y,a),k=`${g(e)} >= ${p?g(v):S?T:zt(T,s)} and ${g(e)} <= ${p?g(y):S?x:zt(x,s)}`;return i==="between"?`(${k})`:Jt(k,!0)}}return""};var hn=t=>t.replace(/^(=)$/,"$1=").replace(/^notnull$/i,"!=").replace(/^null$/i,"=="),Kt=(t,e)=>t.startsWith("not")||t.startsWith("doesnot")?{"!":e}:e,Jo=function(t){let{field:e,operator:l,value:o,valueSource:r}=t,{parseNumbers:s,preserveValueOrder:a}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=r==="field",h={var:e},d=b=>c?{var:`${b}`}:M(b,s)?J(b,{parseNumbers:s}):b,p=l.toLowerCase();switch(p){case"<":case"<=":case"=":case"!=":case">":case">=":return{[hn(p)]:[h,d(o)]};case"null":case"notnull":return{[`${p==="notnull"?"!":"="}=`]:[h,null]};case"in":case"notin":{let b=z(o).map(g=>d(g));return Kt(p,{in:[h,b]})}case"between":case"notbetween":{let b=z(o);if(b.length>=2&&Pe(b[0])&&Pe(b[1])){let[g,i]=b;if(!c&&M(g,!0)&&M(i,!0)){let v=J(g,{parseNumbers:!0}),y=J(i,{parseNumbers:!0});if(!a&&y<v){let f=y;i=v,g=f}else g=v,i=y}else c&&(g={var:g},i={var:i});return Kt(p,{"<=":[g,h,i]})}return!1}case"contains":case"doesnotcontain":{let b={in:[d(o),h]};return Kt(p,b)}case"beginswith":case"doesnotbeginwith":{let b={startsWith:[h,d(o)]};return Kt(p,b)}case"endswith":case"doesnotendwith":{let b={endsWith:[h,d(o)]};return Kt(p,b)}}return!1};var bn=(t,e,l)=>l&&typeof t=="string"?t.replaceAll(`${e}`,`${e}${e}`):t,Xt=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{escapeQuotes:l,fields:o,parseNumbers:r,quoteFieldNamesWith:s,quoteValuesWith:a,fieldIdentifierSeparator:c,translations:h}=e,d=t.valueSource==="field",p=t.operator.toLowerCase(),b=a||"'",g=x=>`${b}${x}${b}`,i=x=>bn(x,b,l),G=x=>g(i(x)),v=x=>Ye(x,{quoteFieldNamesWith:s,fieldIdentifierSeparator:c}),y=h??{},f=y.or??"or",m=y.true??"true",T=y.false??"false";switch(p){case"null":case"notnull":return"";case"between":case"notbetween":{if(!d)return Ue(t,e);let x=z(t.value,{retainEmptyStrings:!0}).slice(0,2).map(S=>v(ce(o??[],S)?.label??S));return x.length<2||!Pe(x[0])||!Pe(x[1])?"":Ue({...t,value:x},e)}case"in":case"notin":{let x=z(t.value);if(x.length===0)return"";let S=x.map(k=>d?v(ce(o??[],k)?.label??k):M(k,r)?`${re(k)}`:`${G(k)}`);return`${S.slice(0,-1).join(", ")}${S.length>2?",":""} ${f} ${S.at(-1)}`}}return typeof t.value=="boolean"?t.value?m:T:d?v(ce(o??[],t.value)?.label??t.value):M(t.value,r)?`${re(t.value)}`:`${G(t.value)}`};var Ml={"=":["is","is the same as the value in"],"!=":["is not","is not the same as the value in"],"<":["is less than","is less than the value in"],">":["is greater than","is greater than the value in"],"<=":["is less than or equal to","is less than or equal to the value in"],">=":["is greater than or equal to","is greater than or equal to the value in"],contains:["contains","contains the value in"],beginswith:["starts with","starts with the value in"],endswith:["ends with","ends with the value in"],doesnotcontain:["does not contain","does not contain the value in"],doesnotbeginwith:["does not start with","does not start with the value in"],doesnotendwith:["does not end with","does not end with the value in"],null:"is null",notnull:"is not null",in:["is one of the values","is the same as a value in"],notin:["is not one of the values","is not the same as any value in"],between:["is between","is between the values in"],notbetween:["is not between","is not between the values in"]},gn=()=>[],Ko=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{valueSource:l="value"}=t,{getOperators:o=gn,operatorMap:r=Ml}=e,s=new Map(Object.entries(Ml));for(let[p,b]of Object.entries(r))s.set(p.toLowerCase(),b);let a=Object.fromEntries(s),{value:c,label:h}=ce(Le(o(t.field,{fieldData:e.fieldData??{name:t.field,value:t.field,label:t.field}})??[]),t.operator)??{name:t.operator,value:t.operator,label:t.operator},d=a[c]??a[c.toLowerCase()]??[h,h];return typeof d=="string"?d:d[l==="field"?1:0]},Wl=(t,e)=>{let{fieldData:l,quoteFieldNamesWith:o=["",""],fieldIdentifierSeparator:r="",quoteValuesWith:s="'",operatorProcessor:a=Ko,valueProcessor:c=Xt,concatOperator:h="||",wordOrder:d="SVO"}=e??{},p=c(t,{...e,quoteFieldNamesWith:o,fieldIdentifierSeparator:r,quoteValuesWith:s,concatOperator:h}),b=t.operator.toLowerCase();if((b==="in"||b==="notin"||b==="between"||b==="notbetween")&&!p)return"";let g=Ye(l?.label??t.field,{quoteFieldNamesWith:o,fieldIdentifierSeparator:r}),i=a(t,e),G={S:g,V:i,O:p};return Fl(d).map(v=>`${G[v]}`).join(" ").trim()};var vt=t=>ql(t.operator).toLowerCase(),Ot=function(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{quoteFieldNamesWith:l=["",""],fieldIdentifierSeparator:o="",quoteValuesWith:r="'",operatorProcessor:s=vt,valueProcessor:a=Ue,concatOperator:c="||"}=e,h=a(t,{...e,quoteFieldNamesWith:l,fieldIdentifierSeparator:o,quoteValuesWith:r,concatOperator:c}),d=s(t,e),p=d.toLowerCase();return(p==="in"||p==="not in"||p==="between"||p==="not between")&&!h?"":`${Ye(t.field,{quoteFieldNamesWith:l,fieldIdentifierSeparator:o})} ${d} ${h}`.trim()};var yo=(t,e,l)=>{let{fieldData:o,format:r,getNextNamedParam:s,parseNumbers:a,paramPrefix:c,paramsKeepPrefix:h,numberedParams:d,quoteFieldNamesWith:p=["",""],concatOperator:b,operatorProcessor:g=vt,valueProcessor:i=Ue}=e??{},{processedParams:G=[]}=l??{},v=r==="parameterized",y=[],f={},m=_=>v?{sql:_,params:y}:{sql:_,params:f},T=i(t,{parseNumbers:a,quoteFieldNamesWith:p,concatOperator:b,fieldData:o,format:r}),x=g(t,e),S=x.toLowerCase(),[k,E]=p;if((S==="in"||S==="not in"||S==="between"||S==="not between")&&!T)return m("");if(S==="is null"||S==="is not null")return m(`${k}${t.field}${E} ${x}`);if(t.valueSource==="field")return m(`${k}${t.field}${E} ${x} ${T}`.trim());if(S==="in"||S==="not in"){let _=z(t.value);if(v){for(let B of _)y.push(M(B,a)?J(B,{parseNumbers:a}):B);return m(`${k}${t.field}${E} ${x} (${_.map((B,$)=>d?`${c}${G.length+1+_.length-(_.length-$)}`:"?").join(", ")})`)}let W=[];for(let B of _){let $=s(t.field);W.push(`${c}${$}`),f[`${h?c:""}${$}`]=M(B,a)?J(B,{parseNumbers:a}):B}return m(`${k}${t.field}${E} ${x} (${W.join(", ")})`)}else if(S==="between"||S==="not between"){let _=z(t.value,{retainEmptyStrings:!0}),[W,B]=_.slice(0,2).map(w=>M(w,a)?J(w,{parseNumbers:a}):w);if(v)return y.push(W,B),m(`${k}${t.field}${E} ${x} ${d?`${c}${G.length+1}`:"?"} and ${d?`${c}${G.length+2}`:"?"}`);let $=s(t.field),C=s(t.field);return f[`${h?c:""}${$}`]=W,f[`${h?c:""}${C}`]=B,m(`${k}${t.field}${E} ${x} ${c}${$} and ${c}${C}`)}let u=t.value;typeof t.value=="string"&&(M(t.value,a)?u=J(t.value,{parseNumbers:a}):u=/^'.*'$/g.test(T)?T.replaceAll(/(^'|'$)/g,""):T);let n="";return v?y.push(u):(n=s(t.field),f[`${h?c:""}${n}`]=u),m(`${k}${t.field}${E} ${x} ${v?d?`${c}${G.length+1}`:"?":`${c}${n}`}`.trim())};var Hl=t=>$e(t)&&typeof t.valid=="boolean",pe=(t,e,l)=>{if(typeof e=="boolean")return e;if(Hl(e))return e.valid;if(typeof l=="function"&&!q(t)){let o=l(t);if(typeof o=="boolean")return o;if(Hl(o))return o.valid}return!0};import{produce as vn}from"immer";var _l={ansi:{},sqlite:{paramsKeepPrefix:!0},oracle:{},mssql:{concatOperator:"+",quoteFieldNamesWith:["[","]"],fieldIdentifierSeparator:".",paramPrefix:"@"},mysql:{concatOperator:"CONCAT"},postgresql:{quoteFieldNamesWith:'"',numberedParams:!0,paramPrefix:"$"}},Ul={cel:Mt,elasticsearch:Uo,json_without_ids:Ot,json:Ot,jsonata:zo,jsonlogic:Jo,mongodb_query:Wt,mongodb:Ht,natural_language:Wl,parameterized_named:yo,parameterized:yo,spel:_t,sql:Ot},Ze=t=>t.operator,yn={cel:Ze,elasticsearch:Ze,json_without_ids:Ze,json:Ze,jsonata:Ze,jsonlogic:Ze,mongodb_query:Ze,mongodb:Ze,natural_language:Ko,parameterized_named:vt,parameterized:vt,spel:Ze,sql:vt},zl={cel:"1 == 1",mongodb:'"$and":[{"$expr":true}]',natural_language:"1 is 1",spel:"1 == 1",sql:"(1 = 1)"},Xo={$and:[{$expr:!0}]},Rn={format:"json",fields:[],quoteFieldNamesWith:["",""],fieldIdentifierSeparator:"",getOperators:()=>[],paramPrefix:":",paramsKeepPrefix:!1,numberedParams:!1,parseNumbers:!1,preserveValueOrder:!1,placeholderFieldName:ko,placeholderOperatorName:To,quoteValuesWith:"'",concatOperator:"||",preset:"ansi",wordOrder:"SVO",translations:{},operatorMap:{}},Jl=t=>t==="mongodb"||t==="mongodb_query"||t==="cel"||t==="spel"||t==="jsonlogic"||t==="elasticsearch"||t==="jsonata";function qi(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},l={...Rn,..._l[e.preset??"ansi"]??null,...typeof e=="string"?{format:e}:e,...typeof e!="string"&&!e.format&&(Object.keys(_l).includes(e.preset??"")?{format:"sql"}:null)},{fallbackExpression:o,getOperators:r,operatorProcessor:s,parseNumbers:a,placeholderFieldName:c,placeholderOperatorName:h,placeholderValueName:d,quoteFieldNamesWith:p,ruleProcessor:b,validator:g,valueProcessor:i,translations:G}=l,v=$=>!!Dt({parseNumbers:a,inputType:$}),y=l.format.toLowerCase(),f=typeof s=="function"?s:yn[y]??Ze,m=typeof i=="function"?Ql(i)?$=>i($.field,$.operator,$.value,$.valueSource):i:y==="natural_language"?Xt:Jl(y)?b??Ul[y]:Ue,T=(typeof b=="function"?b:null)??(Jl(y)&&typeof b!="function"&&i?m:null)??Ul[y]??Ot,x=Wo(p),S=Le(l.fields),k=($,C)=>Le(r($,C)??[]),E=o??zl[y]??zl.sql,u={...l,fallbackExpression:E,fields:S,format:y,getOperators:k,quoteFieldNamesWith:x,operatorProcessor:f,ruleProcessor:T,valueProcessor:m};if(y==="json"||y==="json_without_ids"){let $=a?vn(t,C=>Mo(C,u)):t;return y==="json_without_ids"?JSON.stringify($,(C,w)=>C==="id"||C==="path"?void 0:w):JSON.stringify($,null,2)}let n={};if(typeof g=="function"){let $=g(t);if(typeof $=="boolean"){if($===!1)return y==="parameterized"?{sql:E,params:[]}:y==="parameterized_named"?{sql:E,params:{}}:y==="mongodb"?`{${E}}`:y==="mongodb_query"?Xo:y==="jsonlogic"?!1:y==="elasticsearch"?{}:E}else n=$}let _={},W=kl(S);for(let $ of W)typeof $.validator=="function"&&(_[$.value??$.name]=$.validator);let B=$=>{let C,w;if($.id&&(C=n[$.id]),W.length>0){let O=W.filter(P=>P.name===$.field);if(O.length>0){let P=O[0];typeof P.validator=="function"&&(w=P.validator)}}return[C,w]};if(y==="sql"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?E:"";let O=C.rules.map(P=>{if(typeof P=="string")return P;if(q(P))return $(P,C.rules.length===1);let[A,N]=B(P);if(!pe(P,A,N)||P.field===c||P.operator===h||d!==void 0&&P.value===d)return"";let D=(P.valueSource??"value")==="value",R=ce(S,P.field);return T(P,{...u,parseNumbers:v(R?.inputType),escapeQuotes:D,fieldData:R})}).filter(Boolean);return O.length===0?E:`${C.not?"NOT ":""}(${O.join(se(C)?` ${C.combinator} `:" ")})`};return $(t,!0)}if(y==="parameterized"||y==="parameterized_named"){let $=y==="parameterized",C=[],w={},O=new Map,P=D=>{O.has(D)||O.set(D,new Set);let R=`${D}_${O.get(D).size+1}`;return O.get(D).add(R),R},A=D=>{let[R,V]=B(D);if(!pe(D,R,V)||D.field===c||D.operator===h||d!==void 0&&D.value===d)return"";let U=ce(S,D.field),ye=Object.fromEntries([...O.entries()].map(xe=>{let[Qe,Fe]=xe;return[Qe,[...Fe]]})),H=T(D,{...u,parseNumbers:v(U?.inputType),getNextNamedParam:P,fieldParamNames:ye,fieldData:U},{processedParams:C});if(!$e(H))return"";let{sql:Re,params:Ge}=H;if(typeof Re!="string"||!Re)return"";if(y==="parameterized"&&Array.isArray(Ge))C.push(...Ge);else if(y==="parameterized_named"&&$e(Ge)){Object.assign(w,Ge);for(let xe of Object.keys(Ge))O.get(D.field)?.add(xe)}return Re},N=(D,R)=>{if(!pe(D,n[D.id??""]))return R?E:"";let V=D.rules.map(U=>typeof U=="string"?U:q(U)?N(U,D.rules.length===1):A(U)).filter(Boolean);return V.length===0?E:`${D.not?"NOT ":""}(${V.join(se(D)?` ${D.combinator} `:" ")})`};return $?{sql:N(t,!0),params:C}:{sql:N(t,!0),params:w}}if(y==="mongodb"){let $=(O,P)=>{if(!pe(O,n[O.id??""]))return P?E:"";let A=`"$${O.combinator.toLowerCase()}"`,N=!1,D=O.rules.map(R=>{if(q(R)){let H=$(R);return H?(N=!0,/^\{.+\}$/.test(H)?H:`{${H}}`):""}let[V,U]=B(R);if(!pe(R,V,U)||R.field===c||R.operator===h||d!==void 0&&R.value===d)return"";let ye=ce(S,R.field);return T(R,{...u,parseNumbers:v(ye?.inputType),fieldData:ye})}).filter(Boolean);return D.length>0?D.length===1&&!N?D[0]:`${A}:[${D.join(",")}]`:E},C=se(t)?t:dt(t),w=$(C,!0);return/^\{.+\}$/.test(w)?w:`{${w}}`}if(y==="mongodb_query"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?Xo:!1;let O=`$${C.combinator.toLowerCase()}`,P=!1,A=C.rules.map(N=>{if(q(N)){let U=$(N);return U?(P=!0,U):!1}let[D,R]=B(N);if(!pe(N,D,R)||N.field===c||N.operator===h||d!==void 0&&N.value===d)return!1;let V=ce(S,N.field);return T(N,{...u,parseNumbers:v(V?.inputType),fieldData:V})}).filter(Boolean);return A.length>0?A.length===1&&!P?A[0]:{[O]:A}:Xo};return $(dt(t),!0)}if(y==="cel"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?E:"";let O=C.rules.map(N=>{if(typeof N=="string")return jo[N];if(q(N))return $(N);let[D,R]=B(N);if(!pe(N,D,R)||N.field===c||N.operator===h||d!==void 0&&N.value===d)return"";let V=ce(S,N.field);return T(N,{...u,parseNumbers:v(V?.inputType),escapeQuotes:(N.valueSource??"value")==="value",fieldData:V})}).filter(Boolean).join(se(C)?` ${jo[C.combinator]} `:" "),[P,A]=C.not||!w?[`${C.not?"!":""}(`,")"]:["",""];return O?`${P}${O}${A}`:E};return $(t,!0)}if(y==="spel"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?E:"";let O=C.rules.map(N=>{if(typeof N=="string")return N;if(q(N))return $(N);let[D,R]=B(N);if(!pe(N,D,R)||N.field===c||N.operator===h||d!==void 0&&N.value===d)return"";let V=ce(S,N.field);return T(N,{...u,parseNumbers:v(V?.inputType),escapeQuotes:(N.valueSource??"value")==="value",fieldData:V})}).filter(Boolean).join(se(C)?` ${C.combinator} `:" "),[P,A]=C.not||!w?[`${C.not?"!":""}(`,")"]:["",""];return O?`${P}${O}${A}`:E};return $(t,!0)}if(y==="jsonata"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?E:"";let O=C.rules.map(N=>{if(typeof N=="string")return N;if(q(N))return $(N);let[D,R]=B(N);if(!pe(N,D,R)||N.field===c||N.operator===h||d!==void 0&&N.value===d)return"";let V=ce(S,N.field);return T(N,{...u,parseNumbers:v(V?.inputType),escapeQuotes:(N.valueSource??"value")==="value",fieldData:V})}).filter(Boolean).join(se(C)?` ${C.combinator} `:" "),[P,A]=C.not||!w?[`${C.not?"$not":""}(`,")"]:["",""];return O?`${P}${O}${A}`:E};return $(t,!0)}if(y==="jsonlogic"){let $=se(t)?t:dt(t),C=(w,O)=>{if(!pe(w,n[w.id??""]))return!1;let P=w.rules.map(N=>{if(q(N))return C(N);let[D,R]=B(N);if(!pe(N,D,R)||N.field===c||N.operator===h||d!==void 0&&N.value===d)return!1;let V=ce(S,N.field);return T(N,{...u,parseNumbers:v(V?.inputType),fieldData:V})}).filter(Boolean);if(P.length===0)return!1;let A={[w.combinator]:P};return w.not?{"!":A}:A};return C($,!0)}if(y==="elasticsearch"){let $=se(t)?t:dt(t),C=O=>{if(!pe(O,n[O.id??""]))return!1;let P=O.rules.map(A=>{if(q(A))return C(A);let[N,D]=B(A);if(!pe(A,N,D)||A.field===c||A.operator===h||d!==void 0&&A.value===d)return!1;let R=ce(S,A.field);return T(A,{...u,parseNumbers:v(R?.inputType),fieldData:R})}).filter(Boolean);return P.length===0?!1:{bool:O.not?{must_not:/^or$/i.test(O.combinator)?{bool:{should:P}}:P}:{[/^or$/i.test(O.combinator)?"should":"must"]:P}}},w=C($);return w===!1?{}:w}if(y==="natural_language"){let $=(C,w)=>{if(!pe(C,n[C.id??""]))return w?E:"";let O=C;Me(C)&&C.rules.some(H=>typeof H=="string"&&H.toLowerCase()==="xor")&&(O=dt(C));let P=O.rules.map(H=>{if(typeof H=="string")return`, ${G[H]??H} `;if(q(H))return $(H,O.rules.length===1&&!(O.not||/^xor$/i.test(O.combinator??"")));let[Re,Ge]=B(H);if(!pe(H,Re,Ge)||H.field===c||H.operator===h||d!==void 0&&H.value===d)return"";let xe=(H.valueSource??"value")==="value",Qe=ce(S,H.field);return T(H,{...u,parseNumbers:v(Qe?.inputType),escapeQuotes:xe,fieldData:Qe})});if(P.length===0)return E;let A=(O.combinator??"").toLowerCase()==="xor",N=A?O.combinator.slice(1):O.combinator,D=O.not||!w||A&&P.length>1,[R,V]=["groupPrefix","groupSuffix"].map(H=>O.not?A?jt(H,G,["not","xor"]):jt(H,G,["not"]):A?jt(H,G,["xor"]):jt(H,G)),U=D?`${R} (`.trim():"",ye=D?`) ${V}`.trim():"";return`${U}${P.filter(Boolean).join(se(O)?`, ${G[N]??N} `:"")}${ye}`};return $(t,!0)}return""}var Gn={default:Ue,mongodb:Ht,cel:Mt,spel:_t},Ro=t=>(e,l,o,r)=>Gn[t]({field:e,operator:l,value:o,valueSource:r},{parseNumbers:!1}),Hi=Ro("default"),_i=Ro("mongodb"),Ui=Ro("cel"),zi=Ro("spel");var Ji=Mt,Ki=Ht,Xi=_t;var de=(t,e)=>{let l=e,o=0;for(;o<t.length&&l&&q(l);){let r=l.rules[t[o]];l=typeof r=="string"?null:r,o++}return l},ie=t=>t.slice(0,-1),et=(t,e)=>t.length===e.length&&t.every((l,o)=>l===e[o]),du=(t,e)=>t.length<e.length&&new RegExp(`^${t.join("-")}`).test(e.join("-")),Yo=(t,e)=>{let l=[],o=ie(t),r=ie(e),s=0;for(;s<o.length&&s<r.length&&o[s]===r[s];)l.push(r[s]),s++;return l},yt=(t,e)=>{let l=!!e.disabled,o=e,r=0;for(;r<t.length&&!l&&q(o);){let s=o.rules[t[r]];$e(s)&&(q(s)||"field"in s&&s.field)&&(l=!!s.disabled,o=s),r++}return l};var Kl=t=>et([],t.path)?"Query builder":`Rule group at path ${t.path.join("-")}`;var Yt=globalThis.crypto,Ce=()=>"00-0-4-2-000".replaceAll(/[^-]/g,t=>((Math.random()+Math.trunc(t))*65536>>parseInt(t)).toString(16).padStart(4,"0"));if(Yt){if(typeof Yt.randomUUID=="function")Ce=()=>Yt.randomUUID();else if(typeof Yt.getRandomValues=="function"){let t="89ab",e=new Uint32Array(32);Ce=()=>{Yt.getRandomValues(e);let l=(e[0]%16).toString(16);for(let o=1;o<32;o++)o===12?l=`${l}4`:o===16?l=`${l}${t[e[17]%4]}`:l=`${l}${(e[o]%16).toString(16)}`,(o===7||o===11||o===15||o===19)&&(l=`${l}-`);return l}}}var Nn=(t,e)=>t===!1?!1:t?!0:e!==!1,An=(t,e)=>t?!0:t===!1?!1:!!e,$n=(t,e,l)=>t?Nn(e,l):An(e,l),Go=(t,e,l)=>$n(t,e,l),bu=(t,e,l)=>e!==void 0&&e!=null?e:l!==void 0&&l!=null?l:t;import{forwardRef as Qn,useContext as Fn}from"react";import{Fragment as ol,jsx as ze,jsxs as ll}from"react/jsx-runtime";import*as rl from"react";import{useCallback as Et,useMemo as ge}from"react";import{jsx as No}from"react/jsx-runtime";var Nu=t=>{let e=o=>{let r=be(3),s=Zt(t),a;return r[0]!==o.children||r[1]!==s?(a=No(Ke.Provider,{value:s,children:o.children}),r[0]=o.children,r[1]=s,r[2]=a):a=r[2],a},l=o=>{let r=be(3),s=Zt(o),a;return r[0]!==o.children||r[1]!==s?(a=No(Ke.Provider,{value:s,children:o.children}),r[0]=o.children,r[1]=s,r[2]=a):a=r[2],a};return o=>No(e,{children:No(l,{...o,children:o.children})})};var Ao=t=>{let e=typeof t=="boolean"?t:typeof t=="object"&&t!==null?t.valid:null;return typeof e=="boolean"?e?Q.valid:Q.invalid:""};var Cn=["value"],xn={name:"name",value:"name",valueSources:null,label:"label"},Xl=(t,e,l)=>{let o=t?Ve(t):xn;if(o.valueSources)return typeof o.valueSources=="function"?o.valueSources(e):o.valueSources;if(l){let r=l(o.value,e,{fieldData:Ve(o)});if(r)return r}return Cn};var ee=(t,e)=>Y(e.map(l=>Y(l?.[t]))),Yl=function(){for(var t=arguments.length,e=new Array(t),l=0;l<t;l++)e[l]=arguments[l];return{queryBuilder:ee("queryBuilder",e),ruleGroup:ee("ruleGroup",e),header:ee("header",e),body:ee("body",e),combinators:ee("combinators",e),addRule:ee("addRule",e),addGroup:ee("addGroup",e),cloneRule:ee("cloneRule",e),cloneGroup:ee("cloneGroup",e),removeGroup:ee("removeGroup",e),rule:ee("rule",e),fields:ee("fields",e),operators:ee("operators",e),value:ee("value",e),removeRule:ee("removeRule",e),notToggle:ee("notToggle",e),shiftActions:ee("shiftActions",e),dragHandle:ee("dragHandle",e),lockRule:ee("lockRule",e),lockGroup:ee("lockGroup",e),valueSource:ee("valueSource",e),actionElement:ee("actionElement",e),valueSelector:ee("valueSelector",e),betweenRules:ee("betweenRules",e),valid:ee("valid",e),invalid:ee("invalid",e),dndDragging:ee("dndDragging",e),dndOver:ee("dndOver",e),dndCopy:ee("dndCopy",e),dndGroup:ee("dndGroup",e),disabled:ee("disabled",e),valueListItem:ee("valueListItem",e),branches:ee("branches",e)}};import{produce as Sn}from"immer";var $o=Object.keys,Zl=Object.entries;var ku=function(t){for(var e=arguments.length,l=new Array(e>1?e-1:0),o=1;o<e;o++)l[o-1]=arguments[o];return Sn(t,r=>{for(let s of l)if(s)for(let a of $o(s))r[a]?Object.assign(r[a],s[a]):Object.assign(r,{[a]:s[a]})})},me=(t,e,l)=>{let o=Zl(e).map(r=>{let[s,[a,c]]=r;return[s,a??c??(l?ro:{})[t]?.[s]]}).filter(r=>!!r[1]);return o.length>0?{[t]:Object.fromEntries(o)}:void 0};import{produce as er}from"immer";var tr=function(t){let{idGenerator:e=Ce}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return er(t,l=>{l.id||(l.id=e())})},Co=function(t){let{idGenerator:e=Ce}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return er(t,l=>{l.id||(l.id=e()),l.rules=l.rules.map(o=>typeof o=="string"?o:q(o)?Co(o,{idGenerator:e}):tr(o,{idGenerator:e}))})},Zo=function(t){let{idGenerator:e=Ce}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return q(t)?Co(t,{idGenerator:e}):tr(t,{idGenerator:e})};import{produce as Pt}from"immer";var or=function(t){let{idGenerator:e=Ce}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return structuredClone({...t,id:e()})},Lt=function(t){let{idGenerator:e=Ce}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!$e(t))return t;if(!q(t))return structuredClone({...t,id:e()});if(se(t)){let o