@react-querybuilder/core 8.14.0 → 8.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/{basic-Dxm6jWFu.d.ts → basic-BXJVfD0P.d.ts} +68 -50
  2. package/dist/{basic-GFsWfi0Z.d.mts → basic-CNIjb6rI.d.mts} +68 -50
  3. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +178 -127
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js +299 -251
  5. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  6. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +178 -127
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  8. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  9. package/dist/{convertQuery-DAj92cbM.mjs → convertQuery-B5Qm_6ut.mjs} +30 -22
  10. package/dist/convertQuery-B5Qm_6ut.mjs.map +1 -0
  11. package/dist/convertQuery-DfZehtnd.js +94 -0
  12. package/dist/convertQuery-DfZehtnd.js.map +1 -0
  13. package/dist/{export-_wipiqJZ.d.mts → export-6x7MilFR.d.mts} +2 -3
  14. package/dist/{export-6VbkhCrf.d.ts → export-CpJOQuZv.d.ts} +2 -3
  15. package/dist/formatQuery.d.mts +4 -3
  16. package/dist/formatQuery.d.ts +4 -3
  17. package/dist/formatQuery.js +18 -50
  18. package/dist/formatQuery.js.map +1 -1
  19. package/dist/formatQuery.mjs +17 -49
  20. package/dist/formatQuery.mjs.map +1 -1
  21. package/dist/{import-D8M7awTx.d.ts → import-B5Iq8XmL.d.ts} +2 -3
  22. package/dist/{import-DRmutNSr.d.mts → import-Bltb2mT4.d.mts} +2 -3
  23. package/dist/{isRuleGroup-Cjk1Q2mj.js → isRuleGroup-BCwaLzDj.js} +38 -40
  24. package/dist/isRuleGroup-BCwaLzDj.js.map +1 -0
  25. package/dist/{isRuleGroup-DztIOOKa.mjs → isRuleGroup-LzP0HCKh.mjs} +2 -4
  26. package/dist/isRuleGroup-LzP0HCKh.mjs.map +1 -0
  27. package/dist/parseCEL.d.mts +2 -2
  28. package/dist/parseCEL.d.ts +2 -2
  29. package/dist/parseCEL.js +9 -11
  30. package/dist/parseCEL.js.map +1 -1
  31. package/dist/parseCEL.mjs +7 -10
  32. package/dist/parseCEL.mjs.map +1 -1
  33. package/dist/parseJSONata.d.mts +2 -3
  34. package/dist/parseJSONata.d.ts +2 -3
  35. package/dist/parseJSONata.js +37 -5611
  36. package/dist/parseJSONata.js.map +1 -1
  37. package/dist/parseJSONata.mjs +11 -13
  38. package/dist/parseJSONata.mjs.map +1 -1
  39. package/dist/parseJsonLogic.d.mts +3 -4
  40. package/dist/parseJsonLogic.d.ts +3 -4
  41. package/dist/parseJsonLogic.js +20 -21
  42. package/dist/parseJsonLogic.js.map +1 -1
  43. package/dist/parseJsonLogic.mjs +19 -21
  44. package/dist/parseJsonLogic.mjs.map +1 -1
  45. package/dist/parseMongoDB.d.mts +2 -3
  46. package/dist/parseMongoDB.d.ts +2 -3
  47. package/dist/parseMongoDB.js +7 -8
  48. package/dist/parseMongoDB.js.map +1 -1
  49. package/dist/parseMongoDB.mjs +6 -8
  50. package/dist/parseMongoDB.mjs.map +1 -1
  51. package/dist/parseSQL.d.mts +2 -3
  52. package/dist/parseSQL.d.ts +2 -3
  53. package/dist/parseSQL.js +9 -11
  54. package/dist/parseSQL.js.map +1 -1
  55. package/dist/parseSQL.mjs +7 -10
  56. package/dist/parseSQL.mjs.map +1 -1
  57. package/dist/parseSpEL.d.mts +2 -3
  58. package/dist/parseSpEL.d.ts +2 -3
  59. package/dist/parseSpEL.js +11 -2700
  60. package/dist/parseSpEL.js.map +1 -1
  61. package/dist/parseSpEL.mjs +7 -9
  62. package/dist/parseSpEL.mjs.map +1 -1
  63. package/dist/{prepareQueryObjects-BxWvIPI4.js → prepareQueryObjects-Dc8rqsYM.js} +49 -34
  64. package/dist/prepareQueryObjects-Dc8rqsYM.js.map +1 -0
  65. package/dist/{prepareQueryObjects-BBayjIn2.mjs → prepareQueryObjects-tMukQHT9.mjs} +34 -18
  66. package/dist/prepareQueryObjects-tMukQHT9.mjs.map +1 -0
  67. package/dist/react-querybuilder_core.d.mts +178 -127
  68. package/dist/react-querybuilder_core.legacy-esm.d.ts +178 -127
  69. package/dist/react-querybuilder_core.legacy-esm.js +296 -279
  70. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  71. package/dist/react-querybuilder_core.mjs +288 -247
  72. package/dist/react-querybuilder_core.mjs.map +1 -1
  73. package/dist/react-querybuilder_core.production.d.mts +178 -127
  74. package/dist/react-querybuilder_core.production.mjs +1 -1
  75. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  76. package/dist/transformQuery.d.mts +1 -2
  77. package/dist/transformQuery.d.ts +1 -2
  78. package/dist/transformQuery.js +44 -2
  79. package/dist/transformQuery.js.map +1 -0
  80. package/dist/transformQuery.mjs +43 -2
  81. package/dist/transformQuery.mjs.map +1 -0
  82. package/dist/{utils-nQU7WCM9.mjs → utils-DQoYnxpa.mjs} +32 -84
  83. package/dist/utils-DQoYnxpa.mjs.map +1 -0
  84. package/dist/{utils-CR1ToTMW.js → utils-EsYRkPtf.js} +182 -246
  85. package/dist/utils-EsYRkPtf.js.map +1 -0
  86. package/package.json +25 -17
  87. package/dist/chunk-U64pC571.js +0 -41
  88. package/dist/convertQuery-DAj92cbM.mjs.map +0 -1
  89. package/dist/convertQuery-DRldbzhZ.js +0 -87
  90. package/dist/convertQuery-DRldbzhZ.js.map +0 -1
  91. package/dist/isRuleGroup-Cjk1Q2mj.js.map +0 -1
  92. package/dist/isRuleGroup-DztIOOKa.mjs.map +0 -1
  93. package/dist/prepareQueryObjects-BBayjIn2.mjs.map +0 -1
  94. package/dist/prepareQueryObjects-BxWvIPI4.js.map +0 -1
  95. package/dist/transformQuery-ClBRfnFg.js +0 -54
  96. package/dist/transformQuery-ClBRfnFg.js.map +0 -1
  97. package/dist/transformQuery-DUpbpqjX.mjs +0 -48
  98. package/dist/transformQuery-DUpbpqjX.mjs.map +0 -1
  99. package/dist/utils-CR1ToTMW.js.map +0 -1
  100. package/dist/utils-nQU7WCM9.mjs.map +0 -1
@@ -1,6 +1,5 @@
1
- import { produce } from "immer";
2
1
  import { numericQuantity, numericRegex as numericRegex$1 } from "numeric-quantity";
3
-
2
+ import { current, isDraft, produce } from "immer";
4
3
  //#region src/defaults.ts
5
4
  /**
6
5
  * @group Defaults
@@ -15,7 +14,7 @@ const defaultPlaceholderLabel = "------";
15
14
  *
16
15
  * @group Defaults
17
16
  */
18
- const defaultPlaceholderFieldName = defaultPlaceholderName;
17
+ const defaultPlaceholderFieldName = "~";
19
18
  /**
20
19
  * Default `label` for placeholder option in the `fields` array.
21
20
  *
@@ -33,7 +32,7 @@ const defaultPlaceholderFieldGroupLabel = defaultPlaceholderLabel;
33
32
  *
34
33
  * @group Defaults
35
34
  */
36
- const defaultPlaceholderOperatorName = defaultPlaceholderName;
35
+ const defaultPlaceholderOperatorName = "~";
37
36
  /**
38
37
  * Default `label` for placeholder option in the `operators` array.
39
38
  *
@@ -51,7 +50,7 @@ const defaultPlaceholderOperatorGroupLabel = defaultPlaceholderLabel;
51
50
  *
52
51
  * @group Defaults
53
52
  */
54
- const defaultPlaceholderValueName = defaultPlaceholderName;
53
+ const defaultPlaceholderValueName = "~";
55
54
  /**
56
55
  * Default `label` for placeholder option in the `values` array.
57
56
  *
@@ -72,19 +71,19 @@ const defaultPlaceholderValueGroupLabel = defaultPlaceholderLabel;
72
71
  const defaultTranslations = {
73
72
  fields: {
74
73
  title: "Field",
75
- placeholderName: defaultPlaceholderFieldName,
74
+ placeholderName: "~",
76
75
  placeholderLabel: defaultPlaceholderFieldLabel,
77
76
  placeholderGroupLabel: defaultPlaceholderFieldGroupLabel
78
77
  },
79
78
  operators: {
80
79
  title: "Operator",
81
- placeholderName: defaultPlaceholderOperatorName,
80
+ placeholderName: "~",
82
81
  placeholderLabel: defaultPlaceholderOperatorLabel,
83
82
  placeholderGroupLabel: defaultPlaceholderOperatorGroupLabel
84
83
  },
85
84
  values: {
86
85
  title: "Values",
87
- placeholderName: defaultPlaceholderValueName,
86
+ placeholderName: "~",
88
87
  placeholderLabel: defaultPlaceholderValueLabel,
89
88
  placeholderGroupLabel: defaultPlaceholderValueGroupLabel
90
89
  },
@@ -562,7 +561,6 @@ const queryBuilderFlagDefaults = {
562
561
  showShiftActions: false,
563
562
  suppressStandardClassnames: false
564
563
  };
565
-
566
564
  //#endregion
567
565
  //#region src/utils/arrayUtils.ts
568
566
  /**
@@ -577,7 +575,7 @@ const queryBuilderFlagDefaults = {
577
575
  * // would return
578
576
  * ['this,,that', '', 'the other', '', '', ',']
579
577
  */
580
- const splitBy = (str, splitChar = defaultJoinChar) => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
578
+ const splitBy = (str, splitChar = ",") => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
581
579
  if (idx === 0) return curr;
582
580
  return [
583
581
  ...prev.slice(0, -1),
@@ -598,7 +596,7 @@ const splitBy = (str, splitChar = defaultJoinChar) => typeof str === "string" ?
598
596
  * // would return
599
597
  * 'this\\,\\,that, , the other, , , \\,'
600
598
  */
601
- const joinWith = (strArr, joinChar = defaultJoinChar) => strArr.map((str) => `${str !== null && str !== void 0 ? str : ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(joinChar);
599
+ const joinWith = (strArr, joinChar = ",") => strArr.map((str) => `${str !== null && str !== void 0 ? str : ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(joinChar);
602
600
  /**
603
601
  * Trims the value if it is a string. Otherwise returns the value as is.
604
602
  */
@@ -607,12 +605,11 @@ const trimIfString = (val) => typeof val === "string" ? val.trim() : val;
607
605
  * Splits a string by comma then trims each element. Arrays are returned as is except
608
606
  * any string elements are trimmed.
609
607
  */
610
- const toArray = (v, { retainEmptyStrings } = {}) => Array.isArray(v) ? v.map((v$1) => trimIfString(v$1)) : typeof v === "string" ? splitBy(v, defaultJoinChar).filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof v === "number" ? [v] : [];
608
+ const toArray = (a, { retainEmptyStrings } = {}) => Array.isArray(a) ? a.map((v) => trimIfString(v)) : typeof a === "string" ? splitBy(a, ",").filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof a === "number" ? [a] : [];
611
609
  /**
612
610
  * Determines if an array is free of `null`/`undefined`.
613
611
  */
614
612
  const nullFreeArray = (arr) => arr.every((el) => el === false || (el !== null && el !== void 0 ? el : false) !== false);
615
-
616
613
  //#endregion
617
614
  //#region src/utils/clsx.ts
618
615
  // istanbul ignore next
@@ -653,7 +650,6 @@ function clsx(...args) {
653
650
  }
654
651
  return str;
655
652
  }
656
-
657
653
  //#endregion
658
654
  //#region src/utils/misc.ts
659
655
  /**
@@ -674,7 +670,6 @@ const isPojo = (obj) => obj === null || typeof obj !== "object" ? false : Object
674
670
  * Simple helper to determine whether a value is null, undefined, or an empty string.
675
671
  */
676
672
  const nullOrUndefinedOrEmpty = (value) => value === null || value === void 0 || value === "";
677
-
678
673
  //#endregion
679
674
  //#region src/utils/isRuleGroup.ts
680
675
  /**
@@ -693,20 +688,18 @@ const isRuleGroupType = (rg) => isRuleGroup(rg) && typeof rg.combinator === "str
693
688
  * Determines if an object is a {@link RuleGroupTypeIC}.
694
689
  */
695
690
  const isRuleGroupTypeIC = (rg) => isRuleGroup(rg) && rg.combinator === void 0;
696
-
697
691
  //#endregion
698
- //#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
692
+ //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
699
693
  function _typeof(o) {
700
694
  "@babel/helpers - typeof";
701
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
702
- return typeof o$1;
703
- } : function(o$1) {
704
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
695
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
696
+ return typeof o;
697
+ } : function(o) {
698
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
705
699
  }, _typeof(o);
706
700
  }
707
-
708
701
  //#endregion
709
- //#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
702
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
710
703
  function toPrimitive(t, r) {
711
704
  if ("object" != _typeof(t) || !t) return t;
712
705
  var e = t[Symbol.toPrimitive];
@@ -717,16 +710,14 @@ function toPrimitive(t, r) {
717
710
  }
718
711
  return ("string" === r ? String : Number)(t);
719
712
  }
720
-
721
713
  //#endregion
722
- //#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
714
+ //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
723
715
  function toPropertyKey(t) {
724
716
  var i = toPrimitive(t, "string");
725
717
  return "symbol" == _typeof(i) ? i : i + "";
726
718
  }
727
-
728
719
  //#endregion
729
- //#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
720
+ //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
730
721
  function _defineProperty(e, r, t) {
731
722
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
732
723
  value: t,
@@ -735,15 +726,14 @@ function _defineProperty(e, r, t) {
735
726
  writable: !0
736
727
  }) : e[r] = t, e;
737
728
  }
738
-
739
729
  //#endregion
740
- //#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
730
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectSpread2.js
741
731
  function ownKeys(e, r) {
742
732
  var t = Object.keys(e);
743
733
  if (Object.getOwnPropertySymbols) {
744
734
  var o = Object.getOwnPropertySymbols(e);
745
- r && (o = o.filter(function(r$1) {
746
- return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
735
+ r && (o = o.filter(function(r) {
736
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
747
737
  })), t.push.apply(t, o);
748
738
  }
749
739
  return t;
@@ -751,17 +741,16 @@ function ownKeys(e, r) {
751
741
  function _objectSpread2(e) {
752
742
  for (var r = 1; r < arguments.length; r++) {
753
743
  var t = null != arguments[r] ? arguments[r] : {};
754
- r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
755
- _defineProperty(e, r$1, t[r$1]);
756
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
757
- Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
744
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
745
+ _defineProperty(e, r, t[r]);
746
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
747
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
758
748
  });
759
749
  }
760
750
  return e;
761
751
  }
762
-
763
752
  //#endregion
764
- //#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutPropertiesLoose.js
753
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js
765
754
  function _objectWithoutPropertiesLoose(r, e) {
766
755
  if (null == r) return {};
767
756
  var t = {};
@@ -771,9 +760,8 @@ function _objectWithoutPropertiesLoose(r, e) {
771
760
  }
772
761
  return t;
773
762
  }
774
-
775
763
  //#endregion
776
- //#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutProperties.js
764
+ //#region \0@oxc-project+runtime@0.115.0/helpers/objectWithoutProperties.js
777
765
  function _objectWithoutProperties(e, t) {
778
766
  if (null == e) return {};
779
767
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
@@ -783,7 +771,6 @@ function _objectWithoutProperties(e, t) {
783
771
  }
784
772
  return i;
785
773
  }
786
-
787
774
  //#endregion
788
775
  //#region src/utils/convertQuery.ts
789
776
  const _excluded = ["combinator"];
@@ -796,20 +783,24 @@ const isSameString = (a, b) => lc(a) === b;
796
783
  const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel = 0) => {
797
784
  const baseCombinator = combinatorLevels[baseCombinatorLevel];
798
785
  if (!rg.rules.includes(baseCombinator)) return baseCombinatorLevel < combinatorLevels.length - 2 ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1) : rg;
799
- return produce(rg, (draft) => {
800
- let cursor = 0;
801
- while (cursor < draft.rules.length - 2) {
802
- if (isSameString(draft.rules[cursor + 1], baseCombinator)) {
803
- cursor += 2;
804
- continue;
805
- }
806
- const nextBaseCombinatorIndex = draft.rules.findIndex((r, i) => i > cursor && typeof r === "string" && lc(r) === baseCombinator);
807
- if (nextBaseCombinatorIndex === -1) {
808
- draft.rules.splice(cursor, draft.rules.length, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor) }, baseCombinatorLevel + 1));
809
- break;
810
- } else draft.rules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
786
+ const newRules = [...rg.rules];
787
+ let cursor = 0;
788
+ while (cursor < newRules.length - 2) {
789
+ if (isSameString(newRules[cursor + 1], baseCombinator)) {
790
+ cursor += 2;
791
+ continue;
811
792
  }
812
- });
793
+ let nextBaseCombinatorIndex = -1;
794
+ for (let i = cursor + 2; i < newRules.length; i++) if (typeof newRules[i] === "string" && lc(newRules[i]) === baseCombinator) {
795
+ nextBaseCombinatorIndex = i;
796
+ break;
797
+ }
798
+ if (nextBaseCombinatorIndex === -1) {
799
+ newRules.splice(cursor, newRules.length, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor) }, baseCombinatorLevel + 1));
800
+ break;
801
+ } else newRules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: newRules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
802
+ }
803
+ return _objectSpread2(_objectSpread2({}, rg), {}, { rules: newRules });
813
804
  };
814
805
  /**
815
806
  * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.
@@ -822,9 +813,11 @@ const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel =
822
813
  const convertFromIC = (rg) => {
823
814
  if (isRuleGroupType(rg)) return rg;
824
815
  const processedRG = generateRuleGroupICWithConsistentCombinators(rg);
825
- const rulesAsMixedList = processedRG.rules.map((r) => typeof r === "string" || !isRuleGroup(r) ? r : convertFromIC(r));
826
- const combinator = rulesAsMixedList.length < 2 ? "and" : rulesAsMixedList[1];
827
- const rules = rulesAsMixedList.filter((r) => typeof r !== "string");
816
+ const rules = [];
817
+ let combinator = "and";
818
+ for (const [idx, r] of processedRG.rules.entries()) if (typeof r === "string") {
819
+ if (idx === 1) combinator = r;
820
+ } else rules.push(isRuleGroup(r) ? convertFromIC(r) : r);
828
821
  return _objectSpread2(_objectSpread2({}, processedRG), {}, {
829
822
  combinator,
830
823
  rules
@@ -843,7 +836,8 @@ const convertToIC = (rg) => {
843
836
  const { combinator } = rg, queryWithoutCombinator = _objectWithoutProperties(rg, _excluded);
844
837
  const rules = [];
845
838
  const { length } = rg.rules;
846
- for (const [idx, r] of rg.rules.entries()) {
839
+ for (let idx = 0; idx < length; idx++) {
840
+ const r = rg.rules[idx];
847
841
  if (isRuleGroup(r)) rules.push(convertToIC(r));
848
842
  else rules.push(r);
849
843
  if (combinator && idx < length - 1) rules.push(combinator);
@@ -853,7 +847,6 @@ const convertToIC = (rg) => {
853
847
  function convertQuery(query) {
854
848
  return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);
855
849
  }
856
-
857
850
  //#endregion
858
851
  //#region src/utils/defaultValidator.ts
859
852
  /**
@@ -890,7 +883,6 @@ const defaultValidator = (query) => {
890
883
  validateGroup(query);
891
884
  return result;
892
885
  };
893
-
894
886
  //#endregion
895
887
  //#region src/utils/objectUtils.ts
896
888
  /**
@@ -905,7 +897,6 @@ const objectKeys = Object.keys;
905
897
  * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-entries.ts)
906
898
  */
907
899
  const objectEntries = Object.entries;
908
-
909
900
  //#endregion
910
901
  //#region src/utils/optGroupUtils.ts
911
902
  const isOptionWithName = (opt) => isPojo(opt) && "name" in opt && typeof opt.name === "string";
@@ -917,26 +908,25 @@ const isOptionWithValue = (opt) => isPojo(opt) && "value" in opt && typeof opt.v
917
908
  * @group Option Lists
918
909
  */
919
910
  function toFullOption(opt, baseProperties, labelMap) {
920
- return produce((draft) => {
921
- const idObj = {};
922
- let needsUpdating = !!baseProperties;
923
- if (typeof draft === "string") {
924
- var _labelMap$draft;
925
- return _objectSpread2(_objectSpread2({}, baseProperties), {}, {
926
- name: draft,
927
- value: draft,
928
- label: (_labelMap$draft = labelMap === null || labelMap === void 0 ? void 0 : labelMap[draft]) !== null && _labelMap$draft !== void 0 ? _labelMap$draft : draft
929
- });
930
- }
931
- if (isOptionWithName(draft) && !isOptionWithValue(draft)) {
932
- idObj.value = draft.name;
933
- needsUpdating = true;
934
- } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {
935
- idObj.name = draft.value;
936
- needsUpdating = true;
937
- }
938
- if (needsUpdating) return Object.assign({}, baseProperties, draft, idObj);
939
- })(opt);
911
+ if (typeof opt === "string") {
912
+ var _labelMap$opt;
913
+ return _objectSpread2(_objectSpread2({}, baseProperties), {}, {
914
+ name: opt,
915
+ value: opt,
916
+ label: (_labelMap$opt = labelMap === null || labelMap === void 0 ? void 0 : labelMap[opt]) !== null && _labelMap$opt !== void 0 ? _labelMap$opt : opt
917
+ });
918
+ }
919
+ const idObj = {};
920
+ let needsUpdating = !!baseProperties;
921
+ if (isOptionWithName(opt) && !isOptionWithValue(opt)) {
922
+ idObj.value = opt.name;
923
+ needsUpdating = true;
924
+ } else if (!isOptionWithName(opt) && isOptionWithValue(opt)) {
925
+ idObj.name = opt.value;
926
+ needsUpdating = true;
927
+ }
928
+ if (needsUpdating) return Object.assign({}, baseProperties, opt, idObj);
929
+ return opt;
940
930
  }
941
931
  /**
942
932
  * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.
@@ -946,10 +936,9 @@ function toFullOption(opt, baseProperties, labelMap) {
946
936
  */
947
937
  function toFullOptionList(optList, baseProperties, labelMap) {
948
938
  if (!Array.isArray(optList)) return [];
949
- return produce((draft) => {
950
- if (isFlexibleOptionGroupArray(draft)) for (const optGroup of draft) for (const [idx, opt] of optGroup.options.entries()) optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);
951
- else for (const [idx, opt] of draft.entries()) draft[idx] = toFullOption(opt, baseProperties, labelMap);
952
- })(optList);
939
+ const list = optList;
940
+ if (isFlexibleOptionGroupArray(list)) return list.map((optGroup) => _objectSpread2(_objectSpread2({}, optGroup), {}, { options: optGroup.options.map((opt) => toFullOption(opt, baseProperties, labelMap)) }));
941
+ return list.map((opt) => toFullOption(opt, baseProperties, labelMap));
953
942
  }
954
943
  /**
955
944
  * Converts a {@link FlexibleOptionList} into a {@link FullOptionList}.
@@ -1095,7 +1084,7 @@ const uniqOptList = (originalArray) => {
1095
1084
  };
1096
1085
  const prepareOptionList = (props) => {
1097
1086
  // istanbul ignore next
1098
- const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName = defaultPlaceholderName, placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
1087
+ const { optionList: optionListPropOriginal, baseOption = {}, labelMap = {}, placeholder: { placeholderName = "~", placeholderLabel = defaultPlaceholderLabel, placeholderGroupLabel = defaultPlaceholderLabel } = {}, autoSelectOption = true } = props;
1099
1088
  const defaultOption = {
1100
1089
  id: placeholderName,
1101
1090
  name: placeholderName,
@@ -1131,7 +1120,6 @@ const prepareOptionList = (props) => {
1131
1120
  optionsMap
1132
1121
  };
1133
1122
  };
1134
-
1135
1123
  //#endregion
1136
1124
  //#region src/utils/filterFieldsByComparator.ts
1137
1125
  const filterByComparator = (field, operator, fieldToCompare) => {
@@ -1165,7 +1153,6 @@ const filterFieldsByComparator = (field, fields, operator) => {
1165
1153
  if (isFlexibleOptionGroupArray(fields)) return fields.map((og) => _objectSpread2(_objectSpread2({}, og), {}, { options: og.options.filter((f) => filterByComparator(field, operator, f)) })).filter((og) => og.options.length > 0);
1166
1154
  return fields.filter((f) => filterByComparator(field, operator, f));
1167
1155
  };
1168
-
1169
1156
  //#endregion
1170
1157
  //#region src/utils/parseNumber.ts
1171
1158
  /**
@@ -1185,23 +1172,20 @@ const parseNumber = (val, { parseNumbers, bigIntOnOverflow } = {}) => {
1185
1172
  });
1186
1173
  return typeof valAsNum === "bigint" || !Number.isNaN(valAsNum) ? valAsNum : val;
1187
1174
  };
1188
-
1189
1175
  //#endregion
1190
1176
  //#region src/utils/transformQuery.ts
1191
- /**
1192
- * Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),
1193
- * passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a
1194
- * new query object if there were any referential changes.
1195
- *
1196
- * @module transformQuery
1197
- */
1198
- const remapProperties = (obj, propertyMap, deleteRemappedProperties) => produce(obj, (draft) => {
1199
- for (const [k, v] of Object.entries(propertyMap)) if (v === false) delete draft[k];
1200
- else if (!!v && k !== v && k in draft) {
1201
- draft[v] = draft[k];
1202
- if (deleteRemappedProperties) delete draft[k];
1177
+ const remapProperties = (obj, propertyMap, deleteRemappedProperties) => {
1178
+ const result = {};
1179
+ for (const key in obj) {
1180
+ const mappedKey = propertyMap[key];
1181
+ if (mappedKey === false) continue;
1182
+ if (mappedKey && key !== mappedKey) {
1183
+ result[mappedKey] = obj[key];
1184
+ if (!deleteRemappedProperties) result[key] = obj[key];
1185
+ } else result[key] = obj[key];
1203
1186
  }
1204
- });
1187
+ return result;
1188
+ };
1205
1189
  function transformQuery(query, options = {}) {
1206
1190
  const { ruleProcessor = (r) => r, ruleGroupProcessor = (rg) => rg, propertyMap = {}, combinatorMap = {}, operatorMap = {}, omitPath = false, deleteRemappedProperties = true } = options;
1207
1191
  const processGroup = (rg) => {
@@ -1218,7 +1202,6 @@ function transformQuery(query, options = {}) {
1218
1202
  };
1219
1203
  return processGroup(_objectSpread2(_objectSpread2({}, query), omitPath ? null : { path: [] }));
1220
1204
  }
1221
-
1222
1205
  //#endregion
1223
1206
  //#region src/utils/isRuleOrGroupValid.ts
1224
1207
  /**
@@ -1242,7 +1225,6 @@ const isRuleOrGroupValid = (rg, validationResult, validator) => {
1242
1225
  }
1243
1226
  return true;
1244
1227
  };
1245
-
1246
1228
  //#endregion
1247
1229
  //#region src/utils/getParseNumberMethod.ts
1248
1230
  const getParseNumberMethod = ({ parseNumbers, inputType }) => {
@@ -1253,7 +1235,6 @@ const getParseNumberMethod = ({ parseNumbers, inputType }) => {
1253
1235
  }
1254
1236
  return parseNumbers ? "strict" : false;
1255
1237
  };
1256
-
1257
1238
  //#endregion
1258
1239
  //#region src/utils/formatQuery/utils.ts
1259
1240
  /**
@@ -1335,7 +1316,8 @@ const jsonLogicAdditionalOperators = {
1335
1316
  endsWith: (a, b) => typeof a === "string" && a.endsWith(b)
1336
1317
  };
1337
1318
  /**
1338
- * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
1319
+ * Returns a new query object with all `string`-type `value` properties converted
1320
+ * to `number` where appropriate.
1339
1321
  *
1340
1322
  * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
1341
1323
  *
@@ -1499,7 +1481,6 @@ const bigIntJsonStringifyReplacer = (_key, value) => typeof value === "bigint" ?
1499
1481
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
1500
1482
  */
1501
1483
  const bigIntJsonParseReviver = (_key, value) => isPojo(value) && Object.keys(value).length === 1 && typeof value.$bigint === "string" ? BigInt(value.$bigint) : value;
1502
-
1503
1484
  //#endregion
1504
1485
  //#region src/utils/formatQuery/defaultRuleGroupProcessorCEL.ts
1505
1486
  /**
@@ -1556,7 +1537,6 @@ const defaultRuleGroupProcessorCEL = (ruleGroup, options) => {
1556
1537
  };
1557
1538
  return processRuleGroup(ruleGroup, true);
1558
1539
  };
1559
-
1560
1540
  //#endregion
1561
1541
  //#region src/utils/formatQuery/defaultRuleProcessorCEL.ts
1562
1542
  const shouldNegate$2 = (op) => op.startsWith("not") || op.startsWith("doesnot");
@@ -1634,7 +1614,6 @@ const defaultRuleProcessorCEL = (rule, opts = {}) => {
1634
1614
  }
1635
1615
  return "";
1636
1616
  };
1637
-
1638
1617
  //#endregion
1639
1618
  //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDBQuery.ts
1640
1619
  /**
@@ -1672,11 +1651,11 @@ const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
1672
1651
  fieldData
1673
1652
  }), meta);
1674
1653
  }).filter(Boolean);
1675
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
1654
+ const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
1655
+ return rg.not ? { $not: result } : result;
1676
1656
  };
1677
1657
  return processRuleGroup(convertFromIC(ruleGroup), true);
1678
1658
  };
1679
-
1680
1659
  //#endregion
1681
1660
  //#region src/utils/formatQuery/defaultRuleProcessorMongoDBQuery.ts
1682
1661
  const processNumber$1 = (value, fallback, parseNumbers = false) => shouldRenderAsNumber(value, parseNumbers || typeof value === "bigint") ? Number(parseNumber(value, { parseNumbers: "strict" })) : fallback;
@@ -1791,7 +1770,6 @@ const defaultRuleProcessorMongoDBQuery = (rule, options = {}) => {
1791
1770
  }
1792
1771
  return "";
1793
1772
  };
1794
-
1795
1773
  //#endregion
1796
1774
  //#region src/utils/formatQuery/defaultRuleProcessorMongoDB.ts
1797
1775
  /**
@@ -1805,7 +1783,6 @@ const defaultRuleProcessorMongoDB = (rule, options) => {
1805
1783
  const queryObj = defaultRuleProcessorMongoDBQuery(rule, options);
1806
1784
  return queryObj ? JSON.stringify(queryObj) : "";
1807
1785
  };
1808
-
1809
1786
  //#endregion
1810
1787
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSpEL.ts
1811
1788
  /**
@@ -1862,11 +1839,10 @@ const defaultRuleGroupProcessorSpEL = (ruleGroup, options) => {
1862
1839
  };
1863
1840
  return processRuleGroup(ruleGroup, true);
1864
1841
  };
1865
-
1866
1842
  //#endregion
1867
1843
  //#region src/utils/formatQuery/defaultRuleProcessorSpEL.ts
1868
1844
  const shouldNegate$1 = (op) => op.startsWith("not") || op.startsWith("doesnot");
1869
- const wrapInNegation = (clause, negate$1) => negate$1 ? `!(${clause})` : clause;
1845
+ const wrapInNegation = (clause, negate) => negate ? `!(${clause})` : clause;
1870
1846
  const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
1871
1847
  /**
1872
1848
  * Default rule processor used by {@link formatQuery} for "spel" format.
@@ -1916,9 +1892,9 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
1916
1892
  case "notnull": return `${field} != null`;
1917
1893
  case "in":
1918
1894
  case "notin": {
1919
- const negate$1 = shouldNegate$1(operatorTL) ? "!" : "";
1895
+ const negate = shouldNegate$1(operatorTL) ? "!" : "";
1920
1896
  const valueAsArray = toArray(value);
1921
- return valueAsArray.length > 0 ? `${negate$1}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
1897
+ return valueAsArray.length > 0 ? `${negate}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
1922
1898
  }
1923
1899
  case "between":
1924
1900
  case "notbetween": {
@@ -1941,7 +1917,6 @@ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
1941
1917
  }
1942
1918
  return "";
1943
1919
  };
1944
-
1945
1920
  //#endregion
1946
1921
  //#region src/utils/formatQuery/defaultValueProcessorByRule.ts
1947
1922
  const escapeStringValueQuotes$1 = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
@@ -1998,7 +1973,6 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
1998
1973
  if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
1999
1974
  return valueIsField ? wrapFieldName(value) : shouldRenderAsNumber(value, parseNumbers) ? `${trimIfString(value)}` : `${wrapAndEscape(value)}`;
2000
1975
  };
2001
-
2002
1976
  //#endregion
2003
1977
  //#region src/utils/formatQuery/defaultRuleProcessorDrizzle.ts
2004
1978
  /**
@@ -2086,7 +2060,6 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
2086
2060
  default: return;
2087
2061
  }
2088
2062
  };
2089
-
2090
2063
  //#endregion
2091
2064
  //#region src/utils/formatQuery/defaultRuleGroupProcessorDrizzle.ts
2092
2065
  /**
@@ -2129,7 +2102,6 @@ const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns
2129
2102
  };
2130
2103
  return processRuleGroup(convertFromIC(ruleGroup), true);
2131
2104
  };
2132
-
2133
2105
  //#endregion
2134
2106
  //#region src/utils/formatQuery/defaultRuleGroupProcessorElasticSearch.ts
2135
2107
  /**
@@ -2158,7 +2130,6 @@ const defaultRuleGroupProcessorElasticSearch = (ruleGroup, options) => {
2158
2130
  const processedRuleGroup = processRuleGroup(convertFromIC(ruleGroup));
2159
2131
  return processedRuleGroup === false ? {} : processedRuleGroup;
2160
2132
  };
2161
-
2162
2133
  //#endregion
2163
2134
  //#region src/utils/formatQuery/defaultRuleGroupProcessorJSONata.ts
2164
2135
  /**
@@ -2215,7 +2186,6 @@ const defaultRuleGroupProcessorJSONata = (ruleGroup, options) => {
2215
2186
  };
2216
2187
  return processRuleGroup(ruleGroup, true);
2217
2188
  };
2218
-
2219
2189
  //#endregion
2220
2190
  //#region src/utils/formatQuery/defaultRuleGroupProcessorJsonLogic.ts
2221
2191
  /**
@@ -2245,7 +2215,6 @@ const defaultRuleGroupProcessorJsonLogic = (ruleGroup, options) => {
2245
2215
  };
2246
2216
  return processRuleGroup(query, true);
2247
2217
  };
2248
-
2249
2218
  //#endregion
2250
2219
  //#region src/utils/formatQuery/defaultRuleGroupProcessorLDAP.ts
2251
2220
  /**
@@ -2277,7 +2246,6 @@ const defaultRuleGroupProcessorLDAP = (ruleGroup, options) => {
2277
2246
  };
2278
2247
  return processRuleGroup(convertFromIC(ruleGroup), true);
2279
2248
  };
2280
-
2281
2249
  //#endregion
2282
2250
  //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDB.ts
2283
2251
  const isBracketed = (str) => str.startsWith("{") && str.endsWith("}");
@@ -2312,12 +2280,12 @@ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
2312
2280
  fieldData
2313
2281
  }), meta);
2314
2282
  }).filter(Boolean);
2315
- return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
2283
+ const result = expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
2284
+ return rg.not ? `"$not":${isBracketed(result) ? result : `{${result}}`}` : result;
2316
2285
  };
2317
2286
  const processedQuery = processRuleGroup(convertFromIC(ruleGroup), true);
2318
2287
  return isBracketed(processedQuery) ? processedQuery : `{${processedQuery}}`;
2319
2288
  };
2320
-
2321
2289
  //#endregion
2322
2290
  //#region src/utils/formatQuery/defaultRuleGroupProcessorNL.ts
2323
2291
  /**
@@ -2384,7 +2352,6 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
2384
2352
  };
2385
2353
  return processRuleGroup(ruleGroup, true);
2386
2354
  };
2387
-
2388
2355
  //#endregion
2389
2356
  //#region src/utils/formatQuery/defaultRuleGroupProcessorParameterized.ts
2390
2357
  /**
@@ -2474,7 +2441,6 @@ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
2474
2441
  params: paramsNamed
2475
2442
  };
2476
2443
  };
2477
-
2478
2444
  //#endregion
2479
2445
  //#region src/utils/formatQuery/defaultRuleGroupProcessorPrisma.ts
2480
2446
  /**
@@ -2517,7 +2483,6 @@ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
2517
2483
  const result = processRuleGroup(convertFromIC(ruleGroup), true);
2518
2484
  return ruleGroup.not ? { NOT: result } : result;
2519
2485
  };
2520
-
2521
2486
  //#endregion
2522
2487
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSequelize.ts
2523
2488
  /**
@@ -2558,7 +2523,6 @@ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
2558
2523
  };
2559
2524
  return processRuleGroup(convertFromIC(ruleGroup), true);
2560
2525
  };
2561
-
2562
2526
  //#endregion
2563
2527
  //#region src/utils/formatQuery/defaultRuleGroupProcessorSQL.ts
2564
2528
  /**
@@ -2616,7 +2580,6 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
2616
2580
  };
2617
2581
  return processRuleGroup(ruleGroup, true);
2618
2582
  };
2619
-
2620
2583
  //#endregion
2621
2584
  //#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
2622
2585
  const rangeOperatorMap = {
@@ -2766,12 +2729,11 @@ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
2766
2729
  }
2767
2730
  return false;
2768
2731
  };
2769
-
2770
2732
  //#endregion
2771
2733
  //#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
2772
2734
  const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
2773
2735
  const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
2774
- const negate = (clause, negate$1) => negate$1 ? `$not(${clause})` : clause;
2736
+ const negate = (clause, neg) => neg ? `$not(${clause})` : clause;
2775
2737
  const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
2776
2738
  /**
2777
2739
  * Default rule processor used by {@link formatQuery} for "jsonata" format.
@@ -2850,7 +2812,6 @@ const defaultRuleProcessorJSONata = (rule, options = {}) => {
2850
2812
  }
2851
2813
  return "";
2852
2814
  };
2853
-
2854
2815
  //#endregion
2855
2816
  //#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
2856
2817
  const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
@@ -2945,10 +2906,9 @@ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
2945
2906
  }
2946
2907
  return false;
2947
2908
  };
2948
-
2949
2909
  //#endregion
2950
2910
  //#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
2951
- const negateIf = (clause, negate$1) => negate$1 ? `(!${clause})` : `${clause}`;
2911
+ const negateIf = (clause, negate) => negate ? `(!${clause})` : `${clause}`;
2952
2912
  const ldapEscape = (s) => `${trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
2953
2913
  /**
2954
2914
  * Default rule processor used by {@link formatQuery} for "ldap" format.
@@ -2997,7 +2957,6 @@ const defaultRuleProcessorLDAP = (rule, options = {}) => {
2997
2957
  // istanbul ignore next
2998
2958
  return "";
2999
2959
  };
3000
-
3001
2960
  //#endregion
3002
2961
  //#region src/utils/formatQuery/defaultValueProcessorNL.ts
3003
2962
  const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
@@ -3051,7 +3010,6 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
3051
3010
  if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
3052
3011
  return valueIsField ? wrapFieldName((_getOption$label3 = (_getOption3 = getOption((_ref3 = fields) !== null && _ref3 !== void 0 ? _ref3 : [], rule.value)) === null || _getOption3 === void 0 ? void 0 : _getOption3.label) !== null && _getOption$label3 !== void 0 ? _getOption$label3 : rule.value) : shouldRenderAsNumber(rule.value, parseNumbers) ? `${trimIfString(rule.value)}` : `${wrapAndEscape(rule.value)}`;
3053
3012
  };
3054
-
3055
3013
  //#endregion
3056
3014
  //#region src/utils/formatQuery/defaultRuleProcessorNL.ts
3057
3015
  /**
@@ -3160,7 +3118,6 @@ const defaultRuleProcessorNL = (rule, opts) => {
3160
3118
  };
3161
3119
  return normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
3162
3120
  };
3163
-
3164
3121
  //#endregion
3165
3122
  //#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
3166
3123
  /**
@@ -3211,7 +3168,6 @@ const defaultRuleProcessorSQL = (rule, opts = {}) => {
3211
3168
  if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
3212
3169
  return `${ruleField} ${operator} ${value}`.trim();
3213
3170
  };
3214
-
3215
3171
  //#endregion
3216
3172
  //#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
3217
3173
  /**
@@ -3310,7 +3266,6 @@ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
3310
3266
  }
3311
3267
  return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
3312
3268
  };
3313
-
3314
3269
  //#endregion
3315
3270
  //#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
3316
3271
  const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
@@ -3372,7 +3327,6 @@ const defaultRuleProcessorPrisma = (rule, options = {}) => {
3372
3327
  }
3373
3328
  return "";
3374
3329
  };
3375
-
3376
3330
  //#endregion
3377
3331
  //#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
3378
3332
  /**
@@ -3439,7 +3393,6 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
3439
3393
  }
3440
3394
  }
3441
3395
  };
3442
-
3443
3396
  //#endregion
3444
3397
  //#region src/utils/formatQuery/formatQuery.ts
3445
3398
  /**
@@ -3528,8 +3481,8 @@ const defaultFormatQueryOptions = {
3528
3481
  paramsKeepPrefix: false,
3529
3482
  numberedParams: false,
3530
3483
  preserveValueOrder: false,
3531
- placeholderFieldName: defaultPlaceholderFieldName,
3532
- placeholderOperatorName: defaultPlaceholderOperatorName,
3484
+ placeholderFieldName: "~",
3485
+ placeholderOperatorName: "~",
3533
3486
  quoteValuesWith: "'",
3534
3487
  concatOperator: "||",
3535
3488
  preset: "ansi",
@@ -3635,7 +3588,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
3635
3588
  switch (format) {
3636
3589
  case "json":
3637
3590
  case "json_without_ids": {
3638
- const rg = parseNumbers ? produce(ruleGroup, (g) => numerifyValues(g, finalOptions)) : ruleGroup;
3591
+ const rg = parseNumbers ? numerifyValues(ruleGroup, finalOptions) : ruleGroup;
3639
3592
  if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : bigIntJsonStringifyReplacer(key, value));
3640
3593
  return JSON.stringify(rg, bigIntJsonStringifyReplacer, 2);
3641
3594
  }
@@ -3657,7 +3610,6 @@ function formatQuery(ruleGroup, optionParam = {}) {
3657
3610
  default: return "";
3658
3611
  }
3659
3612
  }
3660
-
3661
3613
  //#endregion
3662
3614
  //#region src/utils/formatQuery/index.ts
3663
3615
  const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
@@ -3708,7 +3660,6 @@ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
3708
3660
  * @group Export
3709
3661
  */
3710
3662
  const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
3711
-
3712
3663
  //#endregion
3713
3664
  //#region src/utils/pathUtils.ts
3714
3665
  /**
@@ -3767,7 +3718,7 @@ const pathsAreEqual = (path1, path2) => path1.length === path2.length && path1.e
3767
3718
  * Determines if the first path is an ancestor of the second path. The first path must
3768
3719
  * be shorter and exactly match the second path up through the length of the first path.
3769
3720
  */
3770
- const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length && (/* @__PURE__ */ new RegExp(`^${maybeAncestor.join("-")}`)).test(path.join("-"));
3721
+ const isAncestor = (maybeAncestor, path) => maybeAncestor.length < path.length && new RegExp(`^${maybeAncestor.join("-")}`).test(path.join("-"));
3771
3722
  /**
3772
3723
  * Finds the deepest/longest path that two paths have in common.
3773
3724
  */
@@ -3800,11 +3751,9 @@ const pathIsDisabled = (path, query) => {
3800
3751
  }
3801
3752
  return disabled;
3802
3753
  };
3803
-
3804
3754
  //#endregion
3805
3755
  //#region src/utils/generateAccessibleDescription.ts
3806
3756
  const generateAccessibleDescription = (params) => pathsAreEqual([], params.path) ? `Query builder` : `Rule group at path ${params.path.join("-")}`;
3807
-
3808
3757
  //#endregion
3809
3758
  //#region src/utils/generateID.ts
3810
3759
  const cryptoModule = globalThis.crypto;
@@ -3839,7 +3788,6 @@ if (cryptoModule) {
3839
3788
  };
3840
3789
  }
3841
3790
  }
3842
-
3843
3791
  //#endregion
3844
3792
  //#region src/utils/getMatchModesUtil.ts
3845
3793
  const dummyFD$1 = {
@@ -3871,7 +3819,6 @@ const getMatchModesUtil = (fieldData, getMatchModes) => {
3871
3819
  };
3872
3820
  })) !== null && _matchModes$map !== void 0 ? _matchModes$map : [];
3873
3821
  };
3874
-
3875
3822
  //#endregion
3876
3823
  //#region src/utils/getValidationClassNames.ts
3877
3824
  /**
@@ -3882,7 +3829,6 @@ const getValidationClassNames = (validationResult) => {
3882
3829
  const valid = typeof validationResult === "boolean" ? validationResult : typeof validationResult === "object" && validationResult !== null ? validationResult.valid : null;
3883
3830
  return typeof valid === "boolean" ? valid ? standardClassnames.valid : standardClassnames.invalid : "";
3884
3831
  };
3885
-
3886
3832
  //#endregion
3887
3833
  //#region src/utils/getValueSourcesUtil.ts
3888
3834
  const defaultValueSourcesArray = [{
@@ -3919,18 +3865,19 @@ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
3919
3865
  };
3920
3866
  });
3921
3867
  };
3922
-
3923
3868
  //#endregion
3924
3869
  //#region src/utils/mergeAnyTranslations.ts
3925
3870
  /**
3926
3871
  * Merges any number of partial translations into a single definition.
3927
3872
  */
3928
- const mergeAnyTranslations = (base, ...otherTranslations) => produce(base, (draft) => {
3873
+ const mergeAnyTranslations = (base, ...otherTranslations) => {
3874
+ const result = _objectSpread2({}, base);
3929
3875
  for (const translations of otherTranslations)
3930
3876
  // istanbul ignore else
3931
- if (translations) for (const t of objectKeys(translations)) if (draft[t]) Object.assign(draft[t], translations[t]);
3932
- else Object.assign(draft, { [t]: translations[t] });
3933
- });
3877
+ if (translations) for (const key of objectKeys(translations)) if (result[key]) result[key] = _objectSpread2(_objectSpread2({}, result[key]), translations[key]);
3878
+ else result[key] = _objectSpread2({}, translations[key]);
3879
+ return result;
3880
+ };
3934
3881
  const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
3935
3882
  const finalKeys = objectEntries(keyPropContextMap).map(([key, [pT, cT]]) => {
3936
3883
  var _ref, _defaults$el;
@@ -3943,7 +3890,6 @@ const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
3943
3890
  return { [el]: finalObject };
3944
3891
  }
3945
3892
  };
3946
-
3947
3893
  //#endregion
3948
3894
  //#region src/utils/mergeClassnames.ts
3949
3895
  const joinClassnamesByName = (name, args) => clsx(args.map((c) => clsx(c === null || c === void 0 ? void 0 : c[name])));
@@ -3993,7 +3939,6 @@ const mergeClassnames = (...args) => ({
3993
3939
  hasSubQuery: joinClassnamesByName("hasSubQuery", args),
3994
3940
  loading: joinClassnamesByName("loading", args)
3995
3941
  });
3996
-
3997
3942
  //#endregion
3998
3943
  //#region src/utils/preferProp.ts
3999
3944
  const preferPropDefaultTrue = (prop, context) => prop === false ? false : prop ? true : !(context === false);
@@ -4016,29 +3961,41 @@ const preferFlagProps = (props = {}, contextVals = {}, finalize) => objectEntrie
4016
3961
  acc[key] = preferProp(def, props[key], contextVals[key], !finalize);
4017
3962
  return acc;
4018
3963
  }, {});
4019
-
4020
3964
  //#endregion
4021
3965
  //#region src/utils/prepareQueryObjects.ts
4022
3966
  /**
4023
3967
  * Ensures that a rule is valid by adding an `id` property if it does not already exist.
4024
3968
  */
4025
- const prepareRule = (rule, { idGenerator = generateID } = {}) => produce(rule, (draft) => {
4026
- if (!draft.id) draft.id = idGenerator();
4027
- if (processMatchMode(draft)) draft.value = prepareRuleGroup(draft.value, { idGenerator });
4028
- });
3969
+ const prepareRule = (rule, { idGenerator = generateID } = {}) => {
3970
+ const needsId = !rule.id;
3971
+ const hasMatchMode = processMatchMode(rule);
3972
+ if (!needsId && !hasMatchMode) return rule;
3973
+ return _objectSpread2(_objectSpread2(_objectSpread2({}, rule), needsId && { id: idGenerator() }), hasMatchMode && { value: prepareRuleGroup(rule.value, { idGenerator }) });
3974
+ };
4029
3975
  /**
4030
3976
  * Ensures that a rule group is valid by recursively adding an `id` property to the group itself
4031
3977
  * and all its rules and subgroups where one does not already exist.
4032
3978
  */
4033
- const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => produce(queryObject, (draft) => {
4034
- if (!draft.id) draft.id = idGenerator();
4035
- draft.rules = draft.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator }));
4036
- });
3979
+ const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => {
3980
+ const needsId = !queryObject.id;
3981
+ let rulesChanged = false;
3982
+ const newRules = [];
3983
+ for (let i = 0; i < queryObject.rules.length; i++) {
3984
+ const r = queryObject.rules[i];
3985
+ if (typeof r === "string") newRules.push(r);
3986
+ else {
3987
+ const prepared = isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator });
3988
+ newRules.push(prepared);
3989
+ if (prepared !== r) rulesChanged = true;
3990
+ }
3991
+ }
3992
+ if (!needsId && !rulesChanged) return queryObject;
3993
+ return _objectSpread2(_objectSpread2(_objectSpread2({}, queryObject), needsId && { id: idGenerator() }), {}, { rules: newRules });
3994
+ };
4037
3995
  /**
4038
3996
  * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
4039
3997
  */
4040
3998
  const prepareRuleOrGroup = (rg, { idGenerator = generateID } = {}) => isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });
4041
-
4042
3999
  //#endregion
4043
4000
  //#region src/utils/regenerateIDs.ts
4044
4001
  /**
@@ -4056,44 +4013,65 @@ const regenerateIDs = (subject, { idGenerator = generateID } = {}) => {
4056
4013
  if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
4057
4014
  return newGroup;
4058
4015
  };
4059
-
4060
4016
  //#endregion
4061
4017
  //#region src/utils/queryTools.ts
4062
4018
  /**
4063
- * Adds a rule or group to a query.
4064
- * @returns The new query with the rule or group added.
4019
+ * Adds a rule or group to a query without mutating the original query.
4020
+ *
4021
+ * @returns A new query with the rule or group added.
4022
+ *
4023
+ * @group Query Tools
4024
+ */
4025
+ const add = (query, ruleOrGroup, parentPathOrID, options = {}) => produce(query, (q) => addInPlace(q, ruleOrGroup, parentPathOrID, options));
4026
+ /**
4027
+ * Adds a rule or group to a query in place.
4028
+ *
4029
+ * @returns The query (mutated in place) with the rule or group added.
4065
4030
  *
4066
4031
  * @group Query Tools
4067
4032
  */
4068
- const add = (query, ruleOrGroup, parentPathOrID, { combinators = defaultCombinators, combinatorPreceding, idGenerator = generateID } = {}) => produce(query, (draft) => {
4069
- const parent = Array.isArray(parentPathOrID) ? findPath(parentPathOrID, draft) : findID(parentPathOrID, draft);
4070
- if (!parent || !isRuleGroup(parent)) return;
4033
+ const addInPlace = (query, ruleOrGroup, parentPathOrID, options = {}) => {
4034
+ const { combinators = defaultCombinators, combinatorPreceding, idGenerator = generateID } = options;
4035
+ const parent = Array.isArray(parentPathOrID) ? findPath(parentPathOrID, query) : findID(parentPathOrID, query);
4036
+ if (!parent || !isRuleGroup(parent)) return query;
4071
4037
  if (isRuleGroupTypeIC(parent) && parent.rules.length > 0) {
4072
4038
  const prevCombinator = parent.rules.at(-2);
4073
4039
  parent.rules.push(combinatorPreceding !== null && combinatorPreceding !== void 0 ? combinatorPreceding : typeof prevCombinator === "string" ? prevCombinator : getFirstOption(combinators));
4074
4040
  }
4075
4041
  parent.rules.push(prepareRuleOrGroup(ruleOrGroup, { idGenerator }));
4076
- });
4042
+ return query;
4043
+ };
4044
+ /**
4045
+ * Updates a property of a rule or group within a query without mutating the original query.
4046
+ *
4047
+ * @returns A new query with the rule or group property updated.
4048
+ *
4049
+ * @group Query Tools
4050
+ */
4051
+ const update = (query, prop, value, pathOrID, options = {}) => produce(query, (q) => updateInPlace(q, prop, value, pathOrID, options));
4077
4052
  /**
4078
- * Updates a property of a rule or group within a query.
4079
- * @returns The new query with the rule or group property updated.
4053
+ * Updates a property of a rule or group within a query in place.
4054
+ *
4055
+ * @returns The query (mutated in place) with the rule or group property updated.
4080
4056
  *
4081
4057
  * @group Query Tools
4082
4058
  */
4083
- const update = (query, prop, value, pathOrID, { resetOnFieldChange = true, resetOnOperatorChange = false, getRuleDefaultOperator = () => "=", getValueSources = () => ["value"], getRuleDefaultValue = () => "", getMatchModes = () => [] } = {}) => produce(query, (draft) => {
4084
- const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, draft);
4085
- if (!path) return;
4086
- if (prop === "combinator" && !isRuleGroupType(draft)) {
4087
- const parentRules = findPath(getParentPath(path), draft).rules;
4059
+ const updateInPlace = (query, prop, value, pathOrID, options = {}) => {
4060
+ const { resetOnFieldChange: _resetOnFieldChange = true, resetOnOperatorChange = false, getRuleDefaultOperator = () => "=", getValueSources = () => ["value"], getRuleDefaultValue = () => "", getMatchModes = () => [] } = options;
4061
+ let resetOnFieldChange = _resetOnFieldChange;
4062
+ const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
4063
+ if (!path) return query;
4064
+ if (prop === "combinator" && !isRuleGroupType(query)) {
4065
+ const parentRules = findPath(getParentPath(path), query).rules;
4088
4066
  if (path.at(-1) % 2 === 1) parentRules[path.at(-1)] = value;
4089
- return;
4067
+ return query;
4090
4068
  }
4091
- const ruleOrGroup = findPath(path, draft);
4092
- if (!ruleOrGroup) return;
4069
+ const ruleOrGroup = findPath(path, query);
4070
+ if (!ruleOrGroup) return query;
4093
4071
  const isGroup = isRuleGroup(ruleOrGroup);
4094
- if (ruleOrGroup[prop] === value) return;
4072
+ if (ruleOrGroup[prop] === value) return query;
4095
4073
  if (prop !== "valueSource") ruleOrGroup[prop] = value;
4096
- if (isGroup) return;
4074
+ if (isGroup) return query;
4097
4075
  let resetValueSource = false;
4098
4076
  let resetValue = false;
4099
4077
  if (prop === "field") {
@@ -4129,25 +4107,33 @@ const update = (query, prop, value, pathOrID, { resetOnFieldChange = true, reset
4129
4107
  ruleOrGroup.valueSource = resetValueSource ? defaultValueSource : value;
4130
4108
  }
4131
4109
  if (resetValue) ruleOrGroup.value = getRuleDefaultValue(ruleOrGroup);
4132
- });
4110
+ return query;
4111
+ };
4112
+ /**
4113
+ * Removes a rule or group from a query without mutating the original query.
4114
+ *
4115
+ * @returns A new query with the rule or group removed.
4116
+ *
4117
+ * @group Query Tools
4118
+ */
4119
+ const remove = (query, pathOrID) => produce(query, (q) => removeInPlace(q, pathOrID));
4133
4120
  /**
4134
- * Removes a rule or group from a query.
4135
- * @returns The new query with the rule or group removed.
4121
+ * Removes a rule or group from a query in place.
4122
+ *
4123
+ * @returns The query (mutated in place) with the rule or group removed.
4136
4124
  *
4137
4125
  * @group Query Tools
4138
4126
  */
4139
- const remove = (query, pathOrID) => {
4127
+ const removeInPlace = (query, pathOrID) => {
4140
4128
  const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
4141
- if (!path) return query;
4142
- if (path.length === 0 || !isRuleGroupType(query) && !findPath(path, query)) return query;
4143
- return produce(query, (draft) => {
4144
- const index = path.at(-1);
4145
- const parent = findPath(getParentPath(path), draft);
4146
- if (parent && isRuleGroup(parent)) if (!isRuleGroupType(parent) && parent.rules.length > 1) {
4147
- const idxStartDelete = index === 0 ? 0 : index - 1;
4148
- parent.rules.splice(idxStartDelete, 2);
4149
- } else parent.rules.splice(index, 1);
4150
- });
4129
+ if (!path || path.length === 0 || !isRuleGroupType(query) && !findPath(path, query)) return query;
4130
+ const index = path.at(-1);
4131
+ const parent = findPath(getParentPath(path), query);
4132
+ if (parent && isRuleGroup(parent)) if (!isRuleGroupType(parent) && parent.rules.length > 1) {
4133
+ const idxStartDelete = index === 0 ? 0 : index - 1;
4134
+ parent.rules.splice(idxStartDelete, 2);
4135
+ } else parent.rules.splice(index, 1);
4136
+ return query;
4151
4137
  };
4152
4138
  const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
4153
4139
  if (Array.isArray(newPathOrShiftDirection)) return newPathOrShiftDirection;
@@ -4174,65 +4160,85 @@ const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
4174
4160
  return currentPath;
4175
4161
  };
4176
4162
  /**
4177
- * Moves a rule or group from one path to another. In the options parameter, pass
4178
- * `{ clone: true }` to copy instead of move.
4179
- * @returns The new query with the rule or group moved or cloned.
4163
+ * Moves a rule or group from one path to another without mutating the original query.
4164
+ * In the options parameter, pass `{ clone: true }` to copy instead of move.
4165
+ *
4166
+ * @returns A new query with the rule or group moved or cloned.
4167
+ *
4168
+ * @group Query Tools
4169
+ */
4170
+ const move = (query, oldPathOrID, newPath, options = {}) => produce(query, (q) => moveInPlace(q, oldPathOrID, newPath, options));
4171
+ /**
4172
+ * Moves a rule or group from one path to another in place.
4173
+ * In the options parameter, pass `{ clone: true }` to copy instead of move.
4174
+ *
4175
+ * @returns The query (mutated in place) with the rule or group moved or cloned.
4180
4176
  *
4181
4177
  * @group Query Tools
4182
4178
  */
4183
- const move = (query, oldPathOrID, newPath, { clone = false, combinators = defaultCombinators, idGenerator = generateID } = {}) => {
4179
+ const moveInPlace = (query, oldPathOrID, newPath, options = {}) => {
4180
+ const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
4184
4181
  const oldPath = Array.isArray(oldPathOrID) ? oldPathOrID : getPathOfID(oldPathOrID, query);
4185
4182
  if (!oldPath) return query;
4186
4183
  const nextPath = getNextPath(query, oldPath, newPath);
4187
4184
  if (oldPath.length === 0 || pathsAreEqual(oldPath, nextPath) || !findPath(getParentPath(nextPath), query)) return query;
4188
4185
  const ruleOrGroupOriginal = findPath(oldPath, query);
4189
4186
  if (!ruleOrGroupOriginal) return query;
4190
- const ruleOrGroup = clone ? regenerateIDs(ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
4191
- return produce(query, (draft) => {
4192
- const independentCombinators = isRuleGroupTypeIC(draft);
4193
- const parentOfRuleToRemove = findPath(getParentPath(oldPath), draft);
4194
- const ruleToRemoveIndex = oldPath.at(-1);
4195
- const oldPrevCombinator = independentCombinators && ruleToRemoveIndex > 0 ? parentOfRuleToRemove.rules[ruleToRemoveIndex - 1] : null;
4196
- const oldNextCombinator = independentCombinators && ruleToRemoveIndex < parentOfRuleToRemove.rules.length - 1 ? parentOfRuleToRemove.rules[ruleToRemoveIndex + 1] : null;
4197
- if (!clone) {
4198
- const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4199
- const deleteLength = independentCombinators ? 2 : 1;
4200
- parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4201
- }
4202
- const newNewPath = [...nextPath];
4203
- const commonAncestorPath = getCommonAncestorPath(oldPath, nextPath);
4204
- if (!clone && oldPath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > oldPath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4205
- const parentToInsertInto = findPath(getParentPath(newNewPath), draft);
4206
- const newIndex = newNewPath.at(-1);
4207
- /**
4208
- * This function 1) glosses over the need for type assertions to splice directly
4209
- * into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
4210
- */
4211
- const insertRuleOrGroup = (...args) => parentToInsertInto.rules.splice(newIndex, 0, ...args);
4212
- if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(ruleOrGroup);
4213
- else if (newIndex === 0) if (ruleToRemoveIndex === 0 && oldNextCombinator) insertRuleOrGroup(ruleOrGroup, oldNextCombinator);
4214
- else {
4215
- var _ref, _parentToInsertInto$r;
4216
- insertRuleOrGroup(ruleOrGroup, (_ref = (_parentToInsertInto$r = parentToInsertInto.rules[1]) !== null && _parentToInsertInto$r !== void 0 ? _parentToInsertInto$r : oldPrevCombinator) !== null && _ref !== void 0 ? _ref : getFirstOption(combinators));
4217
- }
4218
- else if (oldPrevCombinator) insertRuleOrGroup(oldPrevCombinator, ruleOrGroup);
4219
- else {
4220
- var _ref2, _parentToInsertInto$r2;
4221
- insertRuleOrGroup((_ref2 = (_parentToInsertInto$r2 = parentToInsertInto.rules[newIndex - 2]) !== null && _parentToInsertInto$r2 !== void 0 ? _parentToInsertInto$r2 : oldNextCombinator) !== null && _ref2 !== void 0 ? _ref2 : getFirstOption(combinators), ruleOrGroup);
4222
- }
4223
- });
4187
+ const ruleOrGroup = clone ? regenerateIDs(isDraft(ruleOrGroupOriginal) ? current(ruleOrGroupOriginal) : ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
4188
+ const independentCombinators = isRuleGroupTypeIC(query);
4189
+ const parentOfRuleToRemove = findPath(getParentPath(oldPath), query);
4190
+ const ruleToRemoveIndex = oldPath.at(-1);
4191
+ const oldPrevCombinator = independentCombinators && ruleToRemoveIndex > 0 ? parentOfRuleToRemove.rules[ruleToRemoveIndex - 1] : null;
4192
+ const oldNextCombinator = independentCombinators && ruleToRemoveIndex < parentOfRuleToRemove.rules.length - 1 ? parentOfRuleToRemove.rules[ruleToRemoveIndex + 1] : null;
4193
+ if (!clone) {
4194
+ const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4195
+ const deleteLength = independentCombinators ? 2 : 1;
4196
+ parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4197
+ }
4198
+ const newNewPath = [...nextPath];
4199
+ const commonAncestorPath = getCommonAncestorPath(oldPath, nextPath);
4200
+ if (!clone && oldPath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > oldPath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4201
+ const parentToInsertInto = findPath(getParentPath(newNewPath), query);
4202
+ const newIndex = newNewPath.at(-1);
4203
+ /**
4204
+ * This function 1) glosses over the need for type assertions to splice directly
4205
+ * into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
4206
+ */
4207
+ const insertRuleOrGroup = (...args) => parentToInsertInto.rules.splice(newIndex, 0, ...args);
4208
+ if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(ruleOrGroup);
4209
+ else if (newIndex === 0) if (ruleToRemoveIndex === 0 && oldNextCombinator) insertRuleOrGroup(ruleOrGroup, oldNextCombinator);
4210
+ else {
4211
+ var _ref, _parentToInsertInto$r;
4212
+ insertRuleOrGroup(ruleOrGroup, (_ref = (_parentToInsertInto$r = parentToInsertInto.rules[1]) !== null && _parentToInsertInto$r !== void 0 ? _parentToInsertInto$r : oldPrevCombinator) !== null && _ref !== void 0 ? _ref : getFirstOption(combinators));
4213
+ }
4214
+ else if (oldPrevCombinator) insertRuleOrGroup(oldPrevCombinator, ruleOrGroup);
4215
+ else {
4216
+ var _ref2, _parentToInsertInto$r2;
4217
+ insertRuleOrGroup((_ref2 = (_parentToInsertInto$r2 = parentToInsertInto.rules[newIndex - 2]) !== null && _parentToInsertInto$r2 !== void 0 ? _parentToInsertInto$r2 : oldNextCombinator) !== null && _ref2 !== void 0 ? _ref2 : getFirstOption(combinators), ruleOrGroup);
4218
+ }
4219
+ return query;
4224
4220
  };
4225
4221
  /**
4226
- * Inserts a rule or group into a query.
4227
- * @returns The new query with the rule or group inserted.
4222
+ * Inserts a rule or group into a query without mutating the original query.
4223
+ *
4224
+ * @returns A new query with the rule or group inserted.
4225
+ *
4226
+ * @group Query Tools
4227
+ */
4228
+ const insert = (query, ruleOrGroup, path, options = {}) => produce(query, (q) => insertInPlace(q, ruleOrGroup, path, options));
4229
+ /**
4230
+ * Inserts a rule or group into a query in place.
4231
+ *
4232
+ * @returns The query (mutated in place) with the rule or group inserted.
4228
4233
  *
4229
4234
  * @group Query Tools
4230
4235
  */
4231
- const insert = (query, ruleOrGroup, path, { combinators = defaultCombinators, combinatorPreceding, combinatorSucceeding, idGenerator = generateID, replace = false } = {}) => produce(query, (draft) => {
4232
- const parentToInsertInto = findPath(getParentPath(path), draft);
4233
- if (!parentToInsertInto || !isRuleGroup(parentToInsertInto)) return;
4236
+ const insertInPlace = (query, ruleOrGroup, path, options = {}) => {
4237
+ const { combinators = defaultCombinators, combinatorPreceding, combinatorSucceeding, idGenerator = generateID, replace = false } = options;
4238
+ const parentToInsertInto = findPath(getParentPath(path), query);
4239
+ if (!parentToInsertInto || !isRuleGroup(parentToInsertInto)) return query;
4234
4240
  const rorg = regenerateIDs(ruleOrGroup, { idGenerator });
4235
- const independentCombinators = isRuleGroupTypeIC(draft);
4241
+ const independentCombinators = isRuleGroupTypeIC(query);
4236
4242
  const newIndex = path.at(-1);
4237
4243
  /**
4238
4244
  * This function 1) glosses over the need for type assertions to splice directly
@@ -4256,17 +4262,29 @@ const insert = (query, ruleOrGroup, path, { combinators = defaultCombinators, co
4256
4262
  insertRuleOrGroup(normalizedNewIndex, (_ref4 = (_parentToInsertInto$r4 = parentToInsertInto.rules[normalizedNewIndex - 2]) !== null && _parentToInsertInto$r4 !== void 0 ? _parentToInsertInto$r4 : combinatorSucceeding) !== null && _ref4 !== void 0 ? _ref4 : getFirstOption(combinators), rorg);
4257
4263
  }
4258
4264
  }
4259
- });
4265
+ return query;
4266
+ };
4267
+ /**
4268
+ * Creates a new group at a target path with its `rules` array containing the current
4269
+ * objects at the target path and the source path without mutating the original query.
4270
+ * In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
4271
+ *
4272
+ * @returns A new query with the rules or groups grouped.
4273
+ *
4274
+ * @group Query Tools
4275
+ */
4276
+ const group = (query, sourcePathOrID, targetPathOrID, options = {}) => produce(query, (q) => groupInPlace(q, sourcePathOrID, targetPathOrID, options));
4260
4277
  /**
4261
4278
  * Creates a new group at a target path with its `rules` array containing the current
4262
- * objects at the target path and the source path. In the options parameter, pass
4263
- * `{ clone: true }` to copy the source rule/group instead of move.
4279
+ * objects at the target path and the source path in place.
4280
+ * In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
4264
4281
  *
4265
- * @returns The new query with the rules or groups grouped.
4282
+ * @returns The query (mutated in place) with the rules or groups grouped.
4266
4283
  *
4267
4284
  * @group Query Tools
4268
4285
  */
4269
- const group = (query, sourcePathOrID, targetPathOrID, { clone = false, combinators = defaultCombinators, idGenerator = generateID } = {}) => {
4286
+ const groupInPlace = (query, sourcePathOrID, targetPathOrID, options = {}) => {
4287
+ const { clone = false, combinators = defaultCombinators, idGenerator = generateID } = options;
4270
4288
  const sourcePath = Array.isArray(sourcePathOrID) ? sourcePathOrID : getPathOfID(sourcePathOrID, query);
4271
4289
  const targetPath = Array.isArray(targetPathOrID) ? targetPathOrID : getPathOfID(targetPathOrID, query);
4272
4290
  if (!sourcePath || !targetPath) return query;
@@ -4275,32 +4293,31 @@ const group = (query, sourcePathOrID, targetPathOrID, { clone = false, combinato
4275
4293
  const sourceRuleOrGroupOriginal = findPath(sourcePath, query);
4276
4294
  const targetRuleOrGroup = findPath(targetPath, query);
4277
4295
  if (!sourceRuleOrGroupOriginal || !targetRuleOrGroup) return query;
4278
- const sourceRuleOrGroup = clone ? regenerateIDs(sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
4279
- return produce(query, (draft) => {
4280
- const independentCombinators = isRuleGroupTypeIC(draft);
4281
- const parentOfRuleToRemove = findPath(getParentPath(sourcePath), draft);
4282
- const ruleToRemoveIndex = sourcePath.at(-1);
4283
- if (!clone) {
4284
- const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4285
- const deleteLength = independentCombinators ? 2 : 1;
4286
- parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4287
- }
4288
- const newNewPath = [...nextPath];
4289
- const commonAncestorPath = getCommonAncestorPath(sourcePath, nextPath);
4290
- if (!clone && sourcePath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > sourcePath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4291
- const parentOfTargetPath = findPath(getParentPath(newNewPath), draft);
4292
- const targetPathIndex = newNewPath.at(-1);
4293
- parentOfTargetPath.rules.splice(targetPathIndex, 1, prepareRuleOrGroup(independentCombinators ? { rules: [
4294
- targetRuleOrGroup,
4295
- getFirstOption(combinators),
4296
- sourceRuleOrGroup
4297
- ] } : {
4298
- combinator: getFirstOption(combinators),
4299
- rules: [targetRuleOrGroup, sourceRuleOrGroup]
4300
- }, { idGenerator }));
4301
- });
4296
+ const sourceRuleOrGroup = clone ? regenerateIDs(isDraft(sourceRuleOrGroupOriginal) ? current(sourceRuleOrGroupOriginal) : sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
4297
+ const independentCombinators = isRuleGroupTypeIC(query);
4298
+ const parentOfRuleToRemove = findPath(getParentPath(sourcePath), query);
4299
+ const ruleToRemoveIndex = sourcePath.at(-1);
4300
+ if (!clone) {
4301
+ const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
4302
+ const deleteLength = independentCombinators ? 2 : 1;
4303
+ parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
4304
+ }
4305
+ const newNewPath = [...nextPath];
4306
+ const commonAncestorPath = getCommonAncestorPath(sourcePath, nextPath);
4307
+ if (!clone && sourcePath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > sourcePath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
4308
+ const parentOfTargetPath = findPath(getParentPath(newNewPath), query);
4309
+ const targetPathIndex = newNewPath.at(-1);
4310
+ parentOfTargetPath.rules.splice(targetPathIndex, 1, prepareRuleOrGroup(independentCombinators ? { rules: [
4311
+ targetRuleOrGroup,
4312
+ getFirstOption(combinators),
4313
+ sourceRuleOrGroup
4314
+ ] } : {
4315
+ combinator: getFirstOption(combinators),
4316
+ rules: [targetRuleOrGroup, sourceRuleOrGroup]
4317
+ }, { idGenerator }));
4318
+ return query;
4302
4319
  };
4303
-
4304
4320
  //#endregion
4305
- export { LogType, TestID, add, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInvalidReasons, insert, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update };
4321
+ export { LogType, TestID, add, addInPlace, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInPlace, groupInvalidReasons, insert, insertInPlace, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, moveInPlace, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, preferAnyProp, preferFlagProps, preferProp, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, queryBuilderFlagDefaults, regenerateID, regenerateIDs, remove, removeInPlace, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update, updateInPlace };
4322
+
4306
4323
  //# sourceMappingURL=react-querybuilder_core.legacy-esm.js.map