@react-querybuilder/core 8.22.5 → 8.23.0

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 (120) hide show
  1. package/derivations/package.json +4 -0
  2. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +2078 -1665
  3. package/dist/cjs/react-querybuilder_core.cjs.development.js +1293 -422
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  5. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +2078 -1665
  6. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  8. package/dist/{convertQuery-Cw76XFIn.js → convertQuery-BLT0GIhM.js} +17 -8
  9. package/dist/{convertQuery-Cw76XFIn.js.map → convertQuery-BLT0GIhM.js.map} +1 -1
  10. package/dist/{convertQuery-D_4J7E-Z.mjs → convertQuery-DaXv3h7S.mjs} +6 -3
  11. package/dist/{convertQuery-D_4J7E-Z.mjs.map → convertQuery-DaXv3h7S.mjs.map} +1 -1
  12. package/dist/derivations.d.mts +2902 -0
  13. package/dist/derivations.d.ts +2902 -0
  14. package/dist/derivations.js +2845 -0
  15. package/dist/derivations.js.map +1 -0
  16. package/dist/derivations.mjs +2678 -0
  17. package/dist/derivations.mjs.map +1 -0
  18. package/dist/formatQuery.d.mts +2 -895
  19. package/dist/formatQuery.d.ts +2 -895
  20. package/dist/formatQuery.js +120 -140
  21. package/dist/formatQuery.js.map +1 -1
  22. package/dist/formatQuery.mjs +8 -28
  23. package/dist/formatQuery.mjs.map +1 -1
  24. package/dist/{import-DVWI7Fdh.d.mts → import-BdKPtLzo.d.mts} +2 -2
  25. package/dist/{import-6ExjhifL.d.ts → import-BfZTwhp2.d.ts} +2 -2
  26. package/dist/{index-CX9mehdL.d.mts → index-DOIE2pwx.d.mts} +274 -3
  27. package/dist/{index-CX9mehdL.d.ts → index-DOIE2pwx.d.ts} +274 -3
  28. package/dist/index-OF2Q1gTp.d.mts +895 -0
  29. package/dist/index-XueTy_XQ.d.ts +895 -0
  30. package/dist/isRuleOrGroupValid-CIMZNkt4.mjs +27 -0
  31. package/dist/isRuleOrGroupValid-CIMZNkt4.mjs.map +1 -0
  32. package/dist/isRuleOrGroupValid-CtUf4_4x.js +38 -0
  33. package/dist/isRuleOrGroupValid-CtUf4_4x.js.map +1 -0
  34. package/dist/{isRuleGroup-CqLThsbu.mjs → objectUtils-DDZ-KhV5.mjs} +25 -2
  35. package/dist/objectUtils-DDZ-KhV5.mjs.map +1 -0
  36. package/dist/{isRuleGroup-0JNiQgLg.js → objectUtils-DfnEmDSV.js} +48 -1
  37. package/dist/objectUtils-DfnEmDSV.js.map +1 -0
  38. package/dist/parseCEL.d.mts +2 -2
  39. package/dist/parseCEL.d.ts +2 -2
  40. package/dist/parseCEL.js +19 -16
  41. package/dist/parseCEL.js.map +1 -1
  42. package/dist/parseCEL.mjs +12 -9
  43. package/dist/parseCEL.mjs.map +1 -1
  44. package/dist/parseCypher.d.mts +1 -1
  45. package/dist/parseCypher.d.ts +1 -1
  46. package/dist/parseGremlin.d.mts +1 -1
  47. package/dist/parseGremlin.d.ts +1 -1
  48. package/dist/parseJSONata.d.mts +2 -2
  49. package/dist/parseJSONata.d.ts +2 -2
  50. package/dist/parseJSONata.js +17 -14
  51. package/dist/parseJSONata.js.map +1 -1
  52. package/dist/parseJSONata.mjs +11 -8
  53. package/dist/parseJSONata.mjs.map +1 -1
  54. package/dist/parseJsonLogic.d.mts +2 -2
  55. package/dist/parseJsonLogic.d.ts +2 -2
  56. package/dist/parseJsonLogic.js +38 -38
  57. package/dist/parseJsonLogic.js.map +1 -1
  58. package/dist/parseJsonLogic.mjs +5 -5
  59. package/dist/parseMongoDB.d.mts +2 -2
  60. package/dist/parseMongoDB.d.ts +2 -2
  61. package/dist/parseMongoDB.js +50 -47
  62. package/dist/parseMongoDB.js.map +1 -1
  63. package/dist/parseMongoDB.mjs +35 -32
  64. package/dist/parseMongoDB.mjs.map +1 -1
  65. package/dist/parseSPARQL.d.mts +1 -1
  66. package/dist/parseSPARQL.d.ts +1 -1
  67. package/dist/parseSQL.d.mts +2 -2
  68. package/dist/parseSQL.d.ts +2 -2
  69. package/dist/parseSQL.js +27 -23
  70. package/dist/parseSQL.js.map +1 -1
  71. package/dist/parseSQL.mjs +21 -17
  72. package/dist/parseSQL.mjs.map +1 -1
  73. package/dist/parseSpEL.d.mts +2 -2
  74. package/dist/parseSpEL.d.ts +2 -2
  75. package/dist/parseSpEL.js +16 -13
  76. package/dist/parseSpEL.js.map +1 -1
  77. package/dist/parseSpEL.mjs +12 -9
  78. package/dist/parseSpEL.mjs.map +1 -1
  79. package/dist/parserUtils-BKPstAaO.mjs +30 -0
  80. package/dist/parserUtils-BKPstAaO.mjs.map +1 -0
  81. package/dist/parserUtils-DbBXyAht.js +41 -0
  82. package/dist/parserUtils-DbBXyAht.js.map +1 -0
  83. package/dist/{prepareQueryObjects-BnGL91Tt.js → prepareQueryObjects-Dj9cTl9D.js} +90 -63
  84. package/dist/prepareQueryObjects-Dj9cTl9D.js.map +1 -0
  85. package/dist/{prepareQueryObjects-ChINDIap.mjs → prepareQueryObjects-Dmyf3Wi_.mjs} +56 -59
  86. package/dist/prepareQueryObjects-Dmyf3Wi_.mjs.map +1 -0
  87. package/dist/react-querybuilder_core.d.mts +2078 -1665
  88. package/dist/react-querybuilder_core.legacy-esm.d.ts +2078 -1665
  89. package/dist/react-querybuilder_core.legacy-esm.js +1445 -635
  90. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  91. package/dist/react-querybuilder_core.mjs +1288 -424
  92. package/dist/react-querybuilder_core.mjs.map +1 -1
  93. package/dist/react-querybuilder_core.production.d.mts +2078 -1665
  94. package/dist/react-querybuilder_core.production.mjs +1 -1
  95. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  96. package/dist/transformQuery-B7d9AWUf.d.mts +116 -0
  97. package/dist/transformQuery-BXDiUBGB.d.ts +116 -0
  98. package/dist/transformQuery.d.mts +2 -116
  99. package/dist/transformQuery.d.ts +2 -116
  100. package/dist/transformQuery.js +3 -4
  101. package/dist/transformQuery.js.map +1 -1
  102. package/dist/transformQuery.mjs +1 -2
  103. package/dist/transformQuery.mjs.map +1 -1
  104. package/dist/utils-CP5Jqy1P.mjs +1294 -0
  105. package/dist/utils-CP5Jqy1P.mjs.map +1 -0
  106. package/dist/utils-e-7KHkjV.js +1779 -0
  107. package/dist/utils-e-7KHkjV.js.map +1 -0
  108. package/package.json +33 -22
  109. package/dist/isRuleGroup-0JNiQgLg.js.map +0 -1
  110. package/dist/isRuleGroup-CqLThsbu.mjs.map +0 -1
  111. package/dist/objectUtils-Cr02aGxb.js +0 -27
  112. package/dist/objectUtils-Cr02aGxb.js.map +0 -1
  113. package/dist/objectUtils-DBlmJgBf.mjs +0 -16
  114. package/dist/objectUtils-DBlmJgBf.mjs.map +0 -1
  115. package/dist/prepareQueryObjects-BnGL91Tt.js.map +0 -1
  116. package/dist/prepareQueryObjects-ChINDIap.mjs.map +0 -1
  117. package/dist/utils-4k-j5FBa.mjs +0 -537
  118. package/dist/utils-4k-j5FBa.mjs.map +0 -1
  119. package/dist/utils-C79dxwZb.js +0 -752
  120. package/dist/utils-C79dxwZb.js.map +0 -1
@@ -0,0 +1,2845 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils = require("./utils-e-7KHkjV.js");
3
+ const require_objectUtils = require("./objectUtils-DfnEmDSV.js");
4
+ const require_convertQuery = require("./convertQuery-BLT0GIhM.js");
5
+ const require_prepareQueryObjects = require("./prepareQueryObjects-Dj9cTl9D.js");
6
+ const require_isRuleOrGroupValid = require("./isRuleOrGroupValid-CtUf4_4x.js");
7
+ const require_transformQuery = require("./transformQuery.js");
8
+ let immer = require("immer");
9
+ //#region src/controlPropKeys.ts
10
+ /**
11
+ * Runtime data describing the set of query builder controls and the props each one receives.
12
+ *
13
+ * These live in `@react-querybuilder/core` (not `react-querybuilder`) so that non-React ports
14
+ * can consume them without a React dependency.
15
+ *
16
+ * Nothing here can drift from the React implementation unnoticed:
17
+ * `react-querybuilder`'s `types/controlPropKeys.test.ts` gates {@link controlKeys} against
18
+ * `defaultControlElements` and `ControlElementsProp`, and every entry of
19
+ * {@link controlPropKeys} against the corresponding props interface—both at runtime and at
20
+ * compile time, in both directions.
21
+ */
22
+ /**
23
+ * The name of every query builder control, alphabetized.
24
+ *
25
+ * @group Props
26
+ */
27
+ const controlKeys = [
28
+ "actionElement",
29
+ "addGroupAction",
30
+ "addRuleAction",
31
+ "cloneGroupAction",
32
+ "cloneRuleAction",
33
+ "combinatorSelector",
34
+ "dragHandle",
35
+ "fieldSelector",
36
+ "inlineCombinator",
37
+ "lockGroupAction",
38
+ "lockRuleAction",
39
+ "matchModeEditor",
40
+ "muteGroupAction",
41
+ "muteRuleAction",
42
+ "notToggle",
43
+ "operatorSelector",
44
+ "removeGroupAction",
45
+ "removeRuleAction",
46
+ "rule",
47
+ "ruleGroup",
48
+ "ruleGroupBodyElements",
49
+ "ruleGroupHeaderElements",
50
+ "shiftActions",
51
+ "undoRedoActions",
52
+ "valueEditor",
53
+ "valueSelector",
54
+ "valueSourceSelector"
55
+ ];
56
+ /**
57
+ * The full set of prop names each default control receives. Ports can use this to declare
58
+ * every prop explicitly instead of relying on fall-through/attribute inheritance.
59
+ *
60
+ * Each array is the complete, alphabetized key set of the control's props interface in
61
+ * `react-querybuilder`. The lists are written out in full rather than composed from shared
62
+ * bases because `--isolatedDeclarations` cannot infer array types built with spreads. A
63
+ * compile-time gate in `react-querybuilder` (`types/controlPropKeys.test.ts`) fails the build
64
+ * if any list drifts from its interface in either direction.
65
+ *
66
+ * @group Props
67
+ */
68
+ const controlPropKeys = {
69
+ actionElement: [
70
+ "className",
71
+ "context",
72
+ "disabled",
73
+ "disabledTranslation",
74
+ "handleOnClick",
75
+ "label",
76
+ "level",
77
+ "path",
78
+ "ruleOrGroup",
79
+ "rules",
80
+ "schema",
81
+ "testID",
82
+ "title",
83
+ "validation"
84
+ ],
85
+ addGroupAction: [
86
+ "className",
87
+ "context",
88
+ "disabled",
89
+ "disabledTranslation",
90
+ "handleOnClick",
91
+ "label",
92
+ "level",
93
+ "path",
94
+ "ruleOrGroup",
95
+ "rules",
96
+ "schema",
97
+ "testID",
98
+ "title",
99
+ "validation"
100
+ ],
101
+ addRuleAction: [
102
+ "className",
103
+ "context",
104
+ "disabled",
105
+ "disabledTranslation",
106
+ "handleOnClick",
107
+ "label",
108
+ "level",
109
+ "path",
110
+ "ruleOrGroup",
111
+ "rules",
112
+ "schema",
113
+ "testID",
114
+ "title",
115
+ "validation"
116
+ ],
117
+ cloneGroupAction: [
118
+ "className",
119
+ "context",
120
+ "disabled",
121
+ "disabledTranslation",
122
+ "handleOnClick",
123
+ "label",
124
+ "level",
125
+ "path",
126
+ "ruleOrGroup",
127
+ "rules",
128
+ "schema",
129
+ "testID",
130
+ "title",
131
+ "validation"
132
+ ],
133
+ cloneRuleAction: [
134
+ "className",
135
+ "context",
136
+ "disabled",
137
+ "disabledTranslation",
138
+ "handleOnClick",
139
+ "label",
140
+ "level",
141
+ "path",
142
+ "ruleOrGroup",
143
+ "rules",
144
+ "schema",
145
+ "testID",
146
+ "title",
147
+ "validation"
148
+ ],
149
+ combinatorSelector: [
150
+ "className",
151
+ "context",
152
+ "disabled",
153
+ "handleOnChange",
154
+ "level",
155
+ "options",
156
+ "path",
157
+ "ruleGroup",
158
+ "rules",
159
+ "schema",
160
+ "testID",
161
+ "title",
162
+ "validation",
163
+ "value"
164
+ ],
165
+ dragHandle: [
166
+ "className",
167
+ "context",
168
+ "disabled",
169
+ "dragHandleAttributes",
170
+ "label",
171
+ "level",
172
+ "path",
173
+ "ruleOrGroup",
174
+ "schema",
175
+ "testID",
176
+ "title",
177
+ "validation"
178
+ ],
179
+ fieldSelector: [
180
+ "className",
181
+ "context",
182
+ "disabled",
183
+ "handleOnChange",
184
+ "level",
185
+ "operator",
186
+ "options",
187
+ "path",
188
+ "rule",
189
+ "schema",
190
+ "testID",
191
+ "title",
192
+ "validation",
193
+ "value"
194
+ ],
195
+ inlineCombinator: [
196
+ "className",
197
+ "component",
198
+ "context",
199
+ "disabled",
200
+ "handleOnChange",
201
+ "level",
202
+ "options",
203
+ "path",
204
+ "ruleGroup",
205
+ "rules",
206
+ "schema",
207
+ "testID",
208
+ "title",
209
+ "validation",
210
+ "value"
211
+ ],
212
+ lockGroupAction: [
213
+ "className",
214
+ "context",
215
+ "disabled",
216
+ "disabledTranslation",
217
+ "handleOnClick",
218
+ "label",
219
+ "level",
220
+ "path",
221
+ "ruleOrGroup",
222
+ "rules",
223
+ "schema",
224
+ "testID",
225
+ "title",
226
+ "validation"
227
+ ],
228
+ lockRuleAction: [
229
+ "className",
230
+ "context",
231
+ "disabled",
232
+ "disabledTranslation",
233
+ "handleOnClick",
234
+ "label",
235
+ "level",
236
+ "path",
237
+ "ruleOrGroup",
238
+ "rules",
239
+ "schema",
240
+ "testID",
241
+ "title",
242
+ "validation"
243
+ ],
244
+ matchModeEditor: [
245
+ "className",
246
+ "classNames",
247
+ "context",
248
+ "disabled",
249
+ "field",
250
+ "fieldData",
251
+ "handleOnChange",
252
+ "level",
253
+ "match",
254
+ "numericEditorComponent",
255
+ "options",
256
+ "path",
257
+ "rule",
258
+ "schema",
259
+ "selectorComponent",
260
+ "testID",
261
+ "thresholdPlaceholder",
262
+ "title",
263
+ "validation",
264
+ "value"
265
+ ],
266
+ muteGroupAction: [
267
+ "className",
268
+ "context",
269
+ "disabled",
270
+ "disabledTranslation",
271
+ "handleOnClick",
272
+ "label",
273
+ "level",
274
+ "path",
275
+ "ruleOrGroup",
276
+ "rules",
277
+ "schema",
278
+ "testID",
279
+ "title",
280
+ "validation"
281
+ ],
282
+ muteRuleAction: [
283
+ "className",
284
+ "context",
285
+ "disabled",
286
+ "disabledTranslation",
287
+ "handleOnClick",
288
+ "label",
289
+ "level",
290
+ "path",
291
+ "ruleOrGroup",
292
+ "rules",
293
+ "schema",
294
+ "testID",
295
+ "title",
296
+ "validation"
297
+ ],
298
+ notToggle: [
299
+ "checked",
300
+ "className",
301
+ "context",
302
+ "disabled",
303
+ "handleOnChange",
304
+ "label",
305
+ "level",
306
+ "path",
307
+ "ruleGroup",
308
+ "schema",
309
+ "testID",
310
+ "title",
311
+ "validation"
312
+ ],
313
+ operatorSelector: [
314
+ "className",
315
+ "context",
316
+ "disabled",
317
+ "field",
318
+ "fieldData",
319
+ "handleOnChange",
320
+ "level",
321
+ "options",
322
+ "path",
323
+ "rule",
324
+ "schema",
325
+ "testID",
326
+ "title",
327
+ "validation",
328
+ "value"
329
+ ],
330
+ removeGroupAction: [
331
+ "className",
332
+ "context",
333
+ "disabled",
334
+ "disabledTranslation",
335
+ "handleOnClick",
336
+ "label",
337
+ "level",
338
+ "path",
339
+ "ruleOrGroup",
340
+ "rules",
341
+ "schema",
342
+ "testID",
343
+ "title",
344
+ "validation"
345
+ ],
346
+ removeRuleAction: [
347
+ "className",
348
+ "context",
349
+ "disabled",
350
+ "disabledTranslation",
351
+ "handleOnClick",
352
+ "label",
353
+ "level",
354
+ "path",
355
+ "ruleOrGroup",
356
+ "rules",
357
+ "schema",
358
+ "testID",
359
+ "title",
360
+ "validation"
361
+ ],
362
+ rule: [
363
+ "actions",
364
+ "context",
365
+ "disabled",
366
+ "dndRef",
367
+ "dragHandleAttributes",
368
+ "dragMonitorId",
369
+ "dragRef",
370
+ "dropEffect",
371
+ "dropMonitorId",
372
+ "dropNotAllowed",
373
+ "field",
374
+ "groupItems",
375
+ "id",
376
+ "isDragging",
377
+ "isOver",
378
+ "operator",
379
+ "parentDisabled",
380
+ "parentMuted",
381
+ "path",
382
+ "rule",
383
+ "schema",
384
+ "shiftDownDisabled",
385
+ "shiftUpDisabled",
386
+ "translations",
387
+ "value",
388
+ "valueSource"
389
+ ],
390
+ ruleGroup: [
391
+ "actions",
392
+ "combinator",
393
+ "context",
394
+ "disabled",
395
+ "dragHandleAttributes",
396
+ "dragMonitorId",
397
+ "dragRef",
398
+ "dropEffect",
399
+ "dropMonitorId",
400
+ "dropNotAllowed",
401
+ "dropRef",
402
+ "groupItems",
403
+ "id",
404
+ "isDragging",
405
+ "isOver",
406
+ "not",
407
+ "parentDisabled",
408
+ "parentMuted",
409
+ "path",
410
+ "previewRef",
411
+ "ruleGroup",
412
+ "rules",
413
+ "schema",
414
+ "shiftDownDisabled",
415
+ "shiftUpDisabled",
416
+ "translations"
417
+ ],
418
+ ruleGroupBodyElements: [
419
+ "accessibleDescription",
420
+ "actions",
421
+ "addGroup",
422
+ "addRule",
423
+ "classNames",
424
+ "cloneGroup",
425
+ "combinator",
426
+ "context",
427
+ "disabled",
428
+ "dragHandleAttributes",
429
+ "dragMonitorId",
430
+ "dragRef",
431
+ "dropEffect",
432
+ "dropMonitorId",
433
+ "dropNotAllowed",
434
+ "dropRef",
435
+ "groupItems",
436
+ "id",
437
+ "isDragging",
438
+ "isOver",
439
+ "muted",
440
+ "not",
441
+ "onCombinatorChange",
442
+ "onGroupAdd",
443
+ "onIndependentCombinatorChange",
444
+ "onNotToggleChange",
445
+ "outerClassName",
446
+ "parentDisabled",
447
+ "parentMuted",
448
+ "path",
449
+ "pathsMemo",
450
+ "previewRef",
451
+ "removeGroup",
452
+ "ruleGroup",
453
+ "rules",
454
+ "schema",
455
+ "shiftDownDisabled",
456
+ "shiftGroupDown",
457
+ "shiftGroupUp",
458
+ "shiftUpDisabled",
459
+ "toggleLockGroup",
460
+ "toggleMuteGroup",
461
+ "translations",
462
+ "validationClassName",
463
+ "validationResult"
464
+ ],
465
+ ruleGroupHeaderElements: [
466
+ "accessibleDescription",
467
+ "actions",
468
+ "addGroup",
469
+ "addRule",
470
+ "classNames",
471
+ "cloneGroup",
472
+ "combinator",
473
+ "context",
474
+ "disabled",
475
+ "dragHandleAttributes",
476
+ "dragMonitorId",
477
+ "dragRef",
478
+ "dropEffect",
479
+ "dropMonitorId",
480
+ "dropNotAllowed",
481
+ "dropRef",
482
+ "groupItems",
483
+ "id",
484
+ "isDragging",
485
+ "isOver",
486
+ "muted",
487
+ "not",
488
+ "onCombinatorChange",
489
+ "onGroupAdd",
490
+ "onIndependentCombinatorChange",
491
+ "onNotToggleChange",
492
+ "outerClassName",
493
+ "parentDisabled",
494
+ "parentMuted",
495
+ "path",
496
+ "pathsMemo",
497
+ "previewRef",
498
+ "removeGroup",
499
+ "ruleGroup",
500
+ "rules",
501
+ "schema",
502
+ "shiftDownDisabled",
503
+ "shiftGroupDown",
504
+ "shiftGroupUp",
505
+ "shiftUpDisabled",
506
+ "toggleLockGroup",
507
+ "toggleMuteGroup",
508
+ "translations",
509
+ "validationClassName",
510
+ "validationResult"
511
+ ],
512
+ shiftActions: [
513
+ "className",
514
+ "context",
515
+ "disabled",
516
+ "labels",
517
+ "level",
518
+ "path",
519
+ "ruleOrGroup",
520
+ "schema",
521
+ "shiftDown",
522
+ "shiftDownDisabled",
523
+ "shiftUp",
524
+ "shiftUpDisabled",
525
+ "testID",
526
+ "title",
527
+ "titles",
528
+ "validation"
529
+ ],
530
+ undoRedoActions: [
531
+ "className",
532
+ "classNames",
533
+ "context",
534
+ "disabled",
535
+ "labels",
536
+ "level",
537
+ "path",
538
+ "ruleOrGroup",
539
+ "schema",
540
+ "testID",
541
+ "title",
542
+ "titles",
543
+ "validation"
544
+ ],
545
+ valueEditor: [
546
+ "className",
547
+ "context",
548
+ "disabled",
549
+ "field",
550
+ "fieldData",
551
+ "handleOnChange",
552
+ "inputType",
553
+ "level",
554
+ "listsAsArrays",
555
+ "operator",
556
+ "parseNumbers",
557
+ "path",
558
+ "rule",
559
+ "schema",
560
+ "selectorComponent",
561
+ "separator",
562
+ "skipHook",
563
+ "testID",
564
+ "title",
565
+ "type",
566
+ "validation",
567
+ "value",
568
+ "valueSource",
569
+ "values"
570
+ ],
571
+ valueSelector: [
572
+ "className",
573
+ "context",
574
+ "disabled",
575
+ "handleOnChange",
576
+ "level",
577
+ "listsAsArrays",
578
+ "multiple",
579
+ "options",
580
+ "path",
581
+ "schema",
582
+ "testID",
583
+ "title",
584
+ "validation",
585
+ "value"
586
+ ],
587
+ valueSourceSelector: [
588
+ "className",
589
+ "context",
590
+ "disabled",
591
+ "field",
592
+ "fieldData",
593
+ "handleOnChange",
594
+ "level",
595
+ "options",
596
+ "path",
597
+ "rule",
598
+ "schema",
599
+ "testID",
600
+ "title",
601
+ "validation",
602
+ "value"
603
+ ]
604
+ };
605
+ /**
606
+ * Which bulk override, if any, applies to each control: `"action"` for controls that a supplied
607
+ * `actionElement` replaces, `"selector"` for controls that a supplied `valueSelector` replaces,
608
+ * and `null` for controls that neither replaces.
609
+ *
610
+ * `actionElement` and `valueSelector` are themselves `null`—they are the _source_ of a bulk
611
+ * override, not a target of one.
612
+ *
613
+ * Replaces name-suffix sniffing (`key.endsWith('Action')`), which would silently misclassify a
614
+ * future control named e.g. `pathSelector`, and which disagrees between implementations about
615
+ * whether `shiftActions`/`undoRedoActions` (plural) match. They do not: neither receives the
616
+ * `actionElement` bulk override.
617
+ *
618
+ * @group Props
619
+ */
620
+ const controlKind = {
621
+ actionElement: null,
622
+ addGroupAction: "action",
623
+ addRuleAction: "action",
624
+ cloneGroupAction: "action",
625
+ cloneRuleAction: "action",
626
+ combinatorSelector: "selector",
627
+ dragHandle: null,
628
+ fieldSelector: "selector",
629
+ inlineCombinator: null,
630
+ lockGroupAction: "action",
631
+ lockRuleAction: "action",
632
+ matchModeEditor: null,
633
+ muteGroupAction: "action",
634
+ muteRuleAction: "action",
635
+ notToggle: null,
636
+ operatorSelector: "selector",
637
+ removeGroupAction: "action",
638
+ removeRuleAction: "action",
639
+ rule: null,
640
+ ruleGroup: null,
641
+ ruleGroupBodyElements: null,
642
+ ruleGroupHeaderElements: null,
643
+ shiftActions: null,
644
+ undoRedoActions: null,
645
+ valueEditor: null,
646
+ valueSelector: null,
647
+ valueSourceSelector: "selector"
648
+ };
649
+ //#endregion
650
+ //#region src/utils/abortReasons.ts
651
+ /**
652
+ * Abort reasons that {@link QueryManager}'s `strict` mode treats as errors. The remaining
653
+ * reasons—`"same-location"` and `"no-change"`—describe valid operations that had nothing to do,
654
+ * so they are reported to `onInvalidTarget` but never throw.
655
+ *
656
+ * Declared apart from `QueryManager` so the `@react-querybuilder/core/derivations` entry point can
657
+ * export it without putting the manager in its module graph.
658
+ *
659
+ * @group Query Tools
660
+ */
661
+ const strictAbortReasons = [
662
+ "target-not-found",
663
+ "parent-not-found",
664
+ "parent-not-a-group",
665
+ "destination-not-found",
666
+ "root-not-allowed",
667
+ "not-a-combinator-slot",
668
+ "target-disabled",
669
+ "parent-disabled",
670
+ "max-levels-exceeded"
671
+ ];
672
+ new Set(strictAbortReasons);
673
+ //#endregion
674
+ //#region ../../node_modules/clsx/dist/clsx.mjs
675
+ function r(e) {
676
+ var t, f, n = "";
677
+ if ("string" == typeof e || "number" == typeof e) n += e;
678
+ else if ("object" == typeof e) if (Array.isArray(e)) {
679
+ var o = e.length;
680
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
681
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
682
+ return n;
683
+ }
684
+ function clsx() {
685
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
686
+ return n;
687
+ }
688
+ //#endregion
689
+ //#region src/utils/signature.ts
690
+ /**
691
+ * Signature returned when a change alters the _shape_ of the query—rules or groups added,
692
+ * removed, moved, or reordered—rather than the properties of a single node. Structural changes
693
+ * never coalesce with each other, so each one produces its own history entry.
694
+ */
695
+ const structuralSignature = "~structural";
696
+ /**
697
+ * Signature returned when two queries differ by reference only, with no observable difference
698
+ * in their properties.
699
+ */
700
+ const unchangedSignature = "";
701
+ /**
702
+ * Returns the list of property names that differ between two nodes, ignoring `rules` (which is
703
+ * compared structurally by the caller).
704
+ */
705
+ const changedProps = (prev, next) => {
706
+ const keys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)]);
707
+ keys.delete("rules");
708
+ const changed = [];
709
+ for (const key of keys) if (!Object.is(prev[key], next[key])) changed.push(key);
710
+ return changed.toSorted();
711
+ };
712
+ const signatureOfNode = (prev, next, parentId, index) => {
713
+ if (prev === next) return "";
714
+ if (typeof prev === "string" || typeof next === "string") return typeof prev === typeof next ? `${parentId}:combinator[${index}]` : structuralSignature;
715
+ const prevIsGroup = require_objectUtils.isRuleGroup(prev);
716
+ const nextIsGroup = require_objectUtils.isRuleGroup(next);
717
+ if (prevIsGroup !== nextIsGroup) return structuralSignature;
718
+ if (!prevIsGroup || !nextIsGroup) {
719
+ const props = changedProps(prev, next);
720
+ return props.length === 0 ? "" : `${next.id ?? ""}:${props.join(",")}`;
721
+ }
722
+ if (prev.rules.length !== next.rules.length) return structuralSignature;
723
+ const ownProps = changedProps(prev, next);
724
+ let changedIndex = -1;
725
+ for (const [i, prevRule] of prev.rules.entries()) if (prevRule !== next.rules[i]) {
726
+ if (changedIndex !== -1) return structuralSignature;
727
+ changedIndex = i;
728
+ }
729
+ if (changedIndex === -1) return ownProps.length === 0 ? "" : `${next.id ?? ""}:${ownProps.join(",")}`;
730
+ if (ownProps.length > 0) return structuralSignature;
731
+ return signatureOfNode(prev.rules[changedIndex], next.rules[changedIndex], next.id ?? "", changedIndex);
732
+ };
733
+ /**
734
+ * Describes _what changed_ between two versions of a query as a short string, so that
735
+ * consecutive edits to the same property of the same rule (e.g. typing in a value editor) can
736
+ * be recognized and coalesced into a single history entry.
737
+ *
738
+ * Returns {@link structuralSignature} for changes to the shape of the query, {@link unchangedSignature} when the
739
+ * two queries differ by reference only, and `"<id>:<props>"` otherwise.
740
+ *
741
+ * The walk prunes on reference equality, so it costs O(depth) rather than O(size) for the
742
+ * single-node edits that make up the overwhelming majority of changes.
743
+ *
744
+ * Note that this relies on the structural sharing that Immer—and therefore every query
745
+ * produced by RQB's own update functions—guarantees: nodes that did not change keep their
746
+ * identity. A query that has been wholly rebuilt (deep-cloned, round-tripped through JSON,
747
+ * re-parsed from a string) shares no identity with its predecessor, so it is reported as
748
+ * {@link structuralSignature} and will not coalesce. That is a graceful degradation—every change simply
749
+ * gets its own history entry—but controlled components that clone the query on every change
750
+ * will not benefit from coalescing.
751
+ */
752
+ const signatureOf = (prev, next) => signatureOfNode(prev, next, "", -1);
753
+ //#endregion
754
+ //#region src/utils/coalesce.ts
755
+ /**
756
+ * Determines whether a change should be absorbed into the current history entry instead of
757
+ * pushing a new one. This is the exact rule {@link QueryManager} applies when recording history,
758
+ * exposed so non-React implementations can manage their own history stacks without
759
+ * reimplementing (and drifting from) the semantics.
760
+ *
761
+ * A change coalesces only when all three hold:
762
+ * - the change is not structural (rules/groups added, removed, moved, or reordered)
763
+ * - its signature matches the previously recorded signature
764
+ * - it occurred within `coalesceMs` of the previous recording
765
+ *
766
+ * Note that {@link unchangedSignature} is not handled here. A change with no observable
767
+ * difference is never recorded at all, which is a separate decision made before this check.
768
+ *
769
+ * @param prevSig Signature of the previously recorded change, or `undefined` if there is none.
770
+ * @param nextSig Signature of the change being recorded, from {@link signatureOf}.
771
+ * @param prevAt Timestamp of the previous recording.
772
+ * @param now Timestamp of the change being recorded.
773
+ * @param coalesceMs Coalescing window in milliseconds.
774
+ */
775
+ const shouldCoalesce = (prevSig, nextSig, prevAt, now, coalesceMs = 500) => nextSig !== "~structural" && nextSig === prevSig && now >= prevAt && now - prevAt < coalesceMs;
776
+ //#endregion
777
+ //#region src/utils/defaultValidator.ts
778
+ /**
779
+ * This is an example validation function you can pass to {@link react-querybuilder!QueryBuilder QueryBuilder} in the
780
+ * `validator` prop. It assumes that you want to validate groups, and has a no-op
781
+ * for validating rules which you can replace with your own implementation.
782
+ */
783
+ const defaultValidator = (query) => {
784
+ const result = {};
785
+ /**
786
+ * Replace this with your custom rule validator.
787
+ */
788
+ const validateRule = (rule) => {
789
+ /* v8 ignore start -- @preserve */
790
+ if (rule.id) result[rule.id];
791
+ /* v8 ignore stop -- @preserve */
792
+ };
793
+ const validateGroup = (rg) => {
794
+ const reasons = [];
795
+ if (rg.rules.length === 0) reasons.push(require_utils.groupInvalidReasons.empty);
796
+ else if (!require_objectUtils.isRuleGroupType(rg)) {
797
+ let invalidICs = false;
798
+ for (let i = 0; i < rg.rules.length && !invalidICs; i++) if (i % 2 === 0 && typeof rg.rules[i] === "string" || i % 2 === 1 && typeof rg.rules[i] !== "string" || i % 2 === 1 && typeof rg.rules[i] === "string" && !require_utils.defaultCombinators.map((c) => c.name).includes(rg.rules[i])) invalidICs = true;
799
+ if (invalidICs) reasons.push(require_utils.groupInvalidReasons.invalidIndependentCombinators);
800
+ }
801
+ if (require_objectUtils.isRuleGroupType(rg) && !require_utils.defaultCombinators.map((c) => c.name).includes(rg.combinator) && rg.rules.length > 1) reasons.push(require_utils.groupInvalidReasons.invalidCombinator);
802
+ /* v8 ignore else -- @preserve */
803
+ if (rg.id) result[rg.id] = reasons.length > 0 ? {
804
+ valid: false,
805
+ reasons
806
+ } : true;
807
+ for (const r of rg.rules) if (typeof r === "string") {} else if (require_objectUtils.isRuleGroup(r)) validateGroup(r);
808
+ else validateRule(r);
809
+ };
810
+ validateGroup(query);
811
+ return result;
812
+ };
813
+ //#endregion
814
+ //#region src/utils/deriveClassNames.ts
815
+ const ruleClassnameSources = {
816
+ shiftActions: ["shiftActions"],
817
+ dragHandle: ["dragHandle"],
818
+ fields: ["valueSelector", "fields"],
819
+ matchMode: ["valueSelector", "matchMode"],
820
+ matchThreshold: ["valueSelector", "matchThreshold"],
821
+ operators: ["valueSelector", "operators"],
822
+ valueSource: ["valueSelector", "valueSource"],
823
+ value: ["value"],
824
+ cloneRule: ["actionElement", "cloneRule"],
825
+ lockRule: ["actionElement", "lockRule"],
826
+ muteRule: ["actionElement", "muteRule"],
827
+ removeRule: ["actionElement", "removeRule"],
828
+ valueListItem: ["valueListItem"]
829
+ };
830
+ const ruleGroupClassnameSources = {
831
+ header: {
832
+ sources: ["header"],
833
+ conditions: [
834
+ {
835
+ key: "dndOver",
836
+ when: (s) => s.isOver,
837
+ standardOnly: true
838
+ },
839
+ {
840
+ key: "dndCopy",
841
+ when: (s) => s.isOver && s.dropEffect === "copy"
842
+ },
843
+ {
844
+ key: "dndDropNotAllowed",
845
+ when: (s) => s.dropNotAllowed
846
+ }
847
+ ]
848
+ },
849
+ shiftActions: ["shiftActions"],
850
+ undoRedoActions: ["undoRedoActions"],
851
+ undoAction: ["actionElement", "undoAction"],
852
+ redoAction: ["actionElement", "redoAction"],
853
+ dragHandle: ["dragHandle"],
854
+ combinators: ["valueSelector", "combinators"],
855
+ notToggle: ["notToggle"],
856
+ addRule: ["actionElement", "addRule"],
857
+ addGroup: ["actionElement", "addGroup"],
858
+ cloneGroup: ["actionElement", "cloneGroup"],
859
+ lockGroup: ["actionElement", "lockGroup"],
860
+ muteGroup: ["actionElement", "muteGroup"],
861
+ removeGroup: ["actionElement", "removeGroup"],
862
+ body: ["body"]
863
+ };
864
+ /**
865
+ * Conditional classes applied to a rule's wrapper element.
866
+ *
867
+ * Note that this is deliberately _not_ the same set as {@link ruleGroupOuterConditions}: a rule
868
+ * reflects more drag-and-drop states than a group does. Declaring each set separately is what
869
+ * keeps an implementation from assuming they're symmetric.
870
+ */
871
+ const ruleOuterConditions = [
872
+ {
873
+ key: "disabled",
874
+ when: (s) => s.disabled
875
+ },
876
+ {
877
+ key: "muted",
878
+ when: (s) => s.muted
879
+ },
880
+ {
881
+ key: "dndDragging",
882
+ when: (s) => s.isDragging
883
+ },
884
+ {
885
+ key: "dndOver",
886
+ when: (s) => s.isOver
887
+ },
888
+ {
889
+ key: "dndCopy",
890
+ when: (s) => s.isOver && s.dropEffect === "copy"
891
+ },
892
+ {
893
+ key: "dndGroup",
894
+ when: (s) => s.isOver && s.groupItems
895
+ },
896
+ {
897
+ key: "dndDropNotAllowed",
898
+ when: (s) => s.dropNotAllowed
899
+ },
900
+ {
901
+ key: "hasSubQuery",
902
+ when: (s) => s.hasSubQuery
903
+ }
904
+ ];
905
+ /** Conditional classes applied to a rule group's wrapper element. */
906
+ const ruleGroupOuterConditions = [
907
+ {
908
+ key: "disabled",
909
+ when: (s) => s.disabled
910
+ },
911
+ {
912
+ key: "muted",
913
+ when: (s) => s.muted
914
+ },
915
+ {
916
+ key: "dndDragging",
917
+ when: (s) => s.isDragging
918
+ },
919
+ {
920
+ key: "dndGroup",
921
+ when: (s) => s.isOver && s.groupItems
922
+ }
923
+ ];
924
+ /**
925
+ * Conditional classes applied to the query builder's wrapper element.
926
+ *
927
+ * Only a `boolean` validation result contributes a class; a {@link ValidationMap} describes
928
+ * individual rules and groups, not the query as a whole.
929
+ */
930
+ const queryBuilderOuterConditions = [
931
+ {
932
+ key: "disabled",
933
+ when: (s) => s.disabled
934
+ },
935
+ {
936
+ key: "valid",
937
+ when: (s) => typeof s.validationResult === "boolean" && s.validationResult
938
+ },
939
+ {
940
+ key: "invalid",
941
+ when: (s) => typeof s.validationResult === "boolean" && !s.validationResult
942
+ }
943
+ ];
944
+ /**
945
+ * Expands conditions into `clsx` arguments: every custom class first (in declaration order),
946
+ * then a single object of standard classes.
947
+ */
948
+ const conditionArgs = (conditions, state, { classNames, suppressStandardClassnames }) => {
949
+ const evaluated = conditions.map((condition) => [condition, !!condition.when(state)]);
950
+ return [...evaluated.filter(([condition]) => !condition.standardOnly).map(([condition, active]) => active && classNames?.[condition.key]), suppressStandardClassnames || Object.fromEntries(evaluated.map(([condition, active]) => [require_utils.standardClassnames[condition.key], active]))];
951
+ };
952
+ /** Composes the classname for a single entry of a spec map. */
953
+ const deriveFromSpec = (key, spec, state, options) => {
954
+ const { sources, conditions } = Array.isArray(spec) ? { sources: spec } : spec;
955
+ return clsx(options.suppressStandardClassnames || require_utils.standardClassnames[key], ...sources.map((source) => options.classNames?.[source]), ...conditions ? conditionArgs(conditions, state, options) : []);
956
+ };
957
+ const deriveFromSpecs = (specs, state, options) => {
958
+ const result = {};
959
+ for (const [key, spec] of Object.entries(specs)) result[key] = deriveFromSpec(key, spec, state, options);
960
+ return result;
961
+ };
962
+ /**
963
+ * Classnames for each element rendered by a rule. This is the framework-agnostic core of the
964
+ * `classNames` object returned by the `useRule` hook.
965
+ *
966
+ * @group Query Tools
967
+ */
968
+ const deriveRuleClassNames = (options) => deriveFromSpecs(ruleClassnameSources, {}, options);
969
+ /**
970
+ * The classname for a single element of a rule, composed from the same table as
971
+ * {@link deriveRuleClassNames}. Useful where only one is needed, such as the items of a
972
+ * multi-value editor.
973
+ *
974
+ * @group Query Tools
975
+ */
976
+ const deriveRuleClassName = (key, options) => deriveFromSpec(key, ruleClassnameSources[key], {}, options);
977
+ /**
978
+ * Classnames for each element rendered by a rule group, including its conditionally-classed
979
+ * `header`. This is the framework-agnostic core of the `classNames` object returned by the
980
+ * `useRuleGroup` hook.
981
+ *
982
+ * @group Query Tools
983
+ */
984
+ const deriveRuleGroupClassNames = (options) => deriveFromSpecs(ruleGroupClassnameSources, options, options);
985
+ const deriveOuterClassName = (standardKey, conditions, options) => {
986
+ const { classNames, suppressStandardClassnames, leadingClassNames = [], validationClassName } = options;
987
+ return clsx(...leadingClassNames, suppressStandardClassnames || require_utils.standardClassnames[standardKey], classNames?.[standardKey], ...conditionArgs(conditions, options, options), validationClassName);
988
+ };
989
+ /**
990
+ * The outer (wrapper) classname for a rule, including every conditional state class.
991
+ *
992
+ * @group Query Tools
993
+ */
994
+ const deriveRuleOuterClassName = (options) => deriveOuterClassName("rule", ruleOuterConditions, options);
995
+ /**
996
+ * The outer (wrapper) classname for a rule group, including every conditional state class.
997
+ *
998
+ * A group reflects fewer drag-and-drop states than a rule—`dndOver`, `dndCopy`,
999
+ * `dndDropNotAllowed`, and `hasSubQuery` do not apply—so this is not interchangeable with
1000
+ * {@link deriveRuleOuterClassName}.
1001
+ *
1002
+ * @group Query Tools
1003
+ */
1004
+ const deriveRuleGroupOuterClassName = (options) => deriveOuterClassName("ruleGroup", ruleGroupOuterConditions, options);
1005
+ /**
1006
+ * The outer (wrapper) classname for the query builder itself, including the conditional
1007
+ * `disabled`, `valid`, and `invalid` state classes.
1008
+ *
1009
+ * @group Query Tools
1010
+ */
1011
+ const deriveQueryBuilderClassNames = (options) => deriveOuterClassName("queryBuilder", queryBuilderOuterConditions, options);
1012
+ //#endregion
1013
+ //#region src/utils/deriveRuleContext.ts
1014
+ /**
1015
+ * Resolves the field configuration for a rule's `field`, falling back to a minimal option object
1016
+ * when the field isn't present in the field map.
1017
+ */
1018
+ const getFieldData = (field, fieldMap) => fieldMap?.[field] ?? {
1019
+ name: field,
1020
+ value: field,
1021
+ label: field
1022
+ };
1023
+ /**
1024
+ * The input type for a rule. A field's own `inputType` takes precedence over `getInputType`.
1025
+ */
1026
+ const getRuleInputType = (field, operator, fieldData, getInputType) => fieldData.inputType ?? getInputType(field, operator, { fieldData });
1027
+ /**
1028
+ * Whether the value editor(s) should be hidden for an operator, based on its `arity`.
1029
+ */
1030
+ const hideValueControlsForOperator = (operatorObject) => {
1031
+ const arity = operatorObject?.arity;
1032
+ return typeof arity === "string" && arity === "unary" || typeof arity === "number" && arity < 2;
1033
+ };
1034
+ /**
1035
+ * Value source options for a rule. A `valueSource` present on the rule but absent from the
1036
+ * configured list is appended, so the current selection is always representable.
1037
+ */
1038
+ const getRuleValueSourceOptions = (rule, fieldData, getValueSources) => {
1039
+ const configuredVSs = getValueSources(rule.field, rule.operator, { fieldData });
1040
+ if (rule.valueSource && !require_utils.getOption(configuredVSs, rule.valueSource)) return [...configuredVSs, {
1041
+ name: rule.valueSource,
1042
+ value: rule.valueSource,
1043
+ label: rule.valueSource
1044
+ }];
1045
+ return configuredVSs;
1046
+ };
1047
+ /**
1048
+ * Normalizes the result of `getParameters` to a non-empty list or `null`.
1049
+ */
1050
+ const getParametersAsList = (parameters) => parameters && parameters.length > 0 ? parameters : null;
1051
+ /**
1052
+ * The value editor type for a rule. `valueSource: "field"` always uses a select list, and
1053
+ * `valueSource: "parameter"` uses a (multi)select when parameters are available.
1054
+ */
1055
+ const getRuleValueEditorType = (rule, fieldData, parametersAsList, getValueEditorType) => rule.valueSource === "field" ? "select" : rule.valueSource === "parameter" ? parametersAsList ? require_objectUtils.lc(rule.operator) === "in" || require_objectUtils.lc(rule.operator) === "notin" ? "multiselect" : "select" : "text" : getValueEditorType(rule.field, rule.operator, { fieldData });
1056
+ /**
1057
+ * The option list presented by a rule's value editor, resolved from its `valueSource`.
1058
+ */
1059
+ const getRuleValues = (rule, fieldData, fields, parametersAsList, getValues) => {
1060
+ const v = rule.valueSource === "field" ? require_prepareQueryObjects.filterFieldsByComparator(fieldData, fields, rule.operator) : rule.valueSource === "parameter" ? parametersAsList ?? [] : getValues(rule.field, rule.operator, { fieldData });
1061
+ return require_utils.isFlexibleOptionArray(v) || require_utils.isFlexibleOptionGroupArray(v) ? require_utils.toFullOptionList(v) : v;
1062
+ };
1063
+ /**
1064
+ * The validation result for a rule: the entry from a query-level {@link ValidationMap} if present,
1065
+ * otherwise the field's own `validator` result, otherwise `null`.
1066
+ */
1067
+ const getRuleValidationResult = (rule, fieldData, validationMap = {}, id = rule.id ?? "") => validationMap[id] ?? (typeof fieldData.validator === "function" ? fieldData.validator(rule) : null);
1068
+ /**
1069
+ * Resolves everything about a single rule that depends on the field/operator configuration:
1070
+ * its field data, operators, value editor type, value list, value sources, match modes, and
1071
+ * validation result.
1072
+ *
1073
+ * This is the framework-agnostic core of the `useRule` hook, shared with
1074
+ * {@link QueryManager.getRuleContext} so that non-React implementations derive identical results.
1075
+ * It performs no memoization; callers are responsible for caching as appropriate.
1076
+ *
1077
+ * @group Query Tools
1078
+ */
1079
+ const deriveRuleContext = (rule, resolvers, options = {}) => {
1080
+ const { fields, fieldMap, getInputType, getMatchModes, getOperators, getParameters, getValueEditorType, getValues, getValueSources, getSubQueryBuilderProps } = resolvers;
1081
+ const fieldData = getFieldData(rule.field, fieldMap);
1082
+ const inputType = fieldData.inputType ?? getInputType(rule.field, rule.operator, { fieldData });
1083
+ const matchModes = getMatchModes(rule.field, { fieldData });
1084
+ const operators = getOperators(rule.field, { fieldData });
1085
+ const operatorObject = require_utils.getOption(operators, rule.operator);
1086
+ const valueSourceOptions = getRuleValueSourceOptions(rule, fieldData, getValueSources);
1087
+ const parameters = getParametersAsList(getParameters(rule.field, rule.operator, { fieldData }));
1088
+ return {
1089
+ fieldData,
1090
+ hideValueControls: hideValueControlsForOperator(operatorObject),
1091
+ inputType,
1092
+ matchModes,
1093
+ operatorObject,
1094
+ operators,
1095
+ parameters,
1096
+ validationResult: getRuleValidationResult(rule, fieldData, options.validationMap, options.id),
1097
+ valueEditorType: getRuleValueEditorType(rule, fieldData, parameters, getValueEditorType),
1098
+ values: getRuleValues(rule, fieldData, fields, parameters, getValues),
1099
+ valueSourceOptions,
1100
+ valueSources: valueSourceOptions.map(({ value }) => value),
1101
+ subQueryBuilderProps: getSubQueryBuilderProps?.(rule.field, { fieldData }) ?? {}
1102
+ };
1103
+ };
1104
+ /**
1105
+ * The effective combinator for a group: its own `combinator` when it has one, otherwise the
1106
+ * first configured combinator (which is the case for groups with independent combinators).
1107
+ *
1108
+ * This intentionally covers only the current property-based API. The `RuleGroup` component
1109
+ * additionally falls back to its deprecated `combinator` prop; that fallback stays in the hook.
1110
+ */
1111
+ const getRuleGroupCombinator = (ruleGroup, combinators) => require_objectUtils.isRuleGroupType(ruleGroup) ? ruleGroup.combinator : require_utils.getFirstOption(combinators) ?? "";
1112
+ /**
1113
+ * Resolves everything about a rule group that depends on the combinator configuration, plus its
1114
+ * validation result.
1115
+ *
1116
+ * Note that unlike {@link deriveRuleContext}, there is no field-level validator fallback—a
1117
+ * group's validation result comes only from the query-level {@link ValidationMap}.
1118
+ *
1119
+ * @group Query Tools
1120
+ */
1121
+ const deriveRuleGroupContext = (ruleGroup, combinators, options = {}) => {
1122
+ const independentCombinators = require_objectUtils.isRuleGroupTypeIC(ruleGroup);
1123
+ const combinator = getRuleGroupCombinator(ruleGroup, combinators);
1124
+ const combinatorObject = require_utils.getOption(combinators, combinator);
1125
+ return {
1126
+ combinator,
1127
+ combinatorObject,
1128
+ combinators,
1129
+ combinatorBasedClassName: independentCombinators ? null : combinatorObject?.className ?? "",
1130
+ independentCombinators,
1131
+ validationResult: (options.validationMap ?? {})[options.id ?? ruleGroup.id ?? ""] ?? null
1132
+ };
1133
+ };
1134
+ //#endregion
1135
+ //#region src/utils/deriveValueEditor.ts
1136
+ /** Operators whose value is a list rather than a single scalar. */
1137
+ const multiValueOperators = /* @__PURE__ */ new Set([
1138
+ "between",
1139
+ "notBetween",
1140
+ "in",
1141
+ "notIn"
1142
+ ]);
1143
+ /**
1144
+ * Whether an operator's value is a list of two bounds.
1145
+ *
1146
+ * @group Value Editors
1147
+ */
1148
+ const isBetweenOperator = (operator) => operator === "between" || operator === "notBetween";
1149
+ /**
1150
+ * Determines whether a rule's `value` needs to be collapsed to a single element because it no
1151
+ * longer represents a list, and what it should become.
1152
+ *
1153
+ * This happens when the value is an array (or a comma-containing string in a `number` input,
1154
+ * which `<input type="number">` can't display) while the operator is not one of the multi-value
1155
+ * operators and the editor is not a multiselect—typically right after the operator changes from
1156
+ * `"in"` or `"between"` to something else.
1157
+ *
1158
+ * The React `useValueEditor` hook applies the result in an effect; other implementations may
1159
+ * apply it wherever is idiomatic.
1160
+ *
1161
+ * @group Value Editors
1162
+ */
1163
+ const getValueEditorReset = ({ skipHook, type, operator, value, inputType }) => {
1164
+ return !skipHook && type !== "multiselect" && !multiValueOperators.has(operator) && (Array.isArray(value) || inputType === "number" && typeof value === "string" && value.includes(",")) ? {
1165
+ reset: true,
1166
+ value: require_utils.toArray(value, { retainEmptyStrings: true })[0] ?? ""
1167
+ } : {
1168
+ reset: false,
1169
+ value
1170
+ };
1171
+ };
1172
+ /**
1173
+ * Produces the next value for a series of value editors when the editor at `index` changes.
1174
+ *
1175
+ * For `between`/`notBetween`, editing the first bound guarantees an array of at least two
1176
+ * elements, seeding the second from the first available option. The result is a comma-joined
1177
+ * string unless `listsAsArrays` is `true`.
1178
+ *
1179
+ * @group Value Editors
1180
+ */
1181
+ const getMultiValueUpdate = ({ value, index, valueAsArray, operator, values, listsAsArrays, parseNumberMethod }) => {
1182
+ const parsedVal = require_utils.parseNumber(value, { parseNumbers: parseNumberMethod });
1183
+ const needsBetweenFix = index === 0 && isBetweenOperator(operator) && (valueAsArray.length < 2 || valueAsArray[1] === void 0);
1184
+ if (valueAsArray[index] === parsedVal && !needsBetweenFix) return listsAsArrays ? valueAsArray : require_utils.joinWith(valueAsArray, ",");
1185
+ const v = [...valueAsArray];
1186
+ v[index] = parsedVal;
1187
+ if (needsBetweenFix) v[1] = require_utils.getFirstOption(values) ?? "";
1188
+ return listsAsArrays ? v : require_utils.joinWith(v, ",");
1189
+ };
1190
+ /**
1191
+ * Coerces a value to a `bigint`, falling back to the parsed number when it can't be represented
1192
+ * as one (an empty string or a decimal, for example).
1193
+ *
1194
+ * @group Value Editors
1195
+ */
1196
+ const coerceBigIntValue = (value, parseNumberMethod) => {
1197
+ const valAsMaybeNumber = require_utils.parseNumber(value, {
1198
+ parseNumbers: parseNumberMethod,
1199
+ bigIntOnOverflow: true
1200
+ });
1201
+ try {
1202
+ return BigInt(valAsMaybeNumber);
1203
+ } catch {
1204
+ return valAsMaybeNumber;
1205
+ }
1206
+ };
1207
+ /**
1208
+ * The `type` attribute an `<input>` should use for a rule. `bigint` values and the `in`/`notIn`
1209
+ * operators (whose value is a comma-separated list) both require a text input.
1210
+ *
1211
+ * @group Value Editors
1212
+ */
1213
+ const coerceInputType = (inputType, operator) => inputType === "bigint" || operator === "in" || operator === "notIn" ? "text" : inputType || "text";
1214
+ /**
1215
+ * Produces the next value for a value selector. Multiselect values are normalized to an array
1216
+ * first, then comma-joined unless `listsAsArrays` is `true`. Single-select values pass through.
1217
+ *
1218
+ * @group Value Editors
1219
+ */
1220
+ const getValueSelectorUpdate = (value, { multiple, listsAsArrays } = {}) => {
1221
+ if (!multiple) return value;
1222
+ const valueAsArray = require_utils.toArray(value);
1223
+ return listsAsArrays ? valueAsArray : require_utils.joinWith(valueAsArray, ",");
1224
+ };
1225
+ /**
1226
+ * Normalizes a value selector's current value for display. Multiselect values become an array of
1227
+ * strings so they match option names, which are always strings (e.g. `[42]` becomes `["42"]`).
1228
+ *
1229
+ * @group Value Editors
1230
+ */
1231
+ const normalizeValueSelectorValue = (value, multiple) => multiple ? require_utils.toArray(value).map(String) : value;
1232
+ //#endregion
1233
+ //#region src/utils/pathUtils.ts
1234
+ /**
1235
+ * Returns the {@link RuleType} or {@link RuleGroupType}/{@link RuleGroupTypeIC}
1236
+ * at the given path within a query.
1237
+ */
1238
+ const findPath = (path, query) => {
1239
+ let target = query;
1240
+ let level = 0;
1241
+ while (level < path.length && target && require_objectUtils.isRuleGroup(target)) {
1242
+ const t = target.rules[path[level]];
1243
+ target = typeof t === "string" ? null : t;
1244
+ level++;
1245
+ }
1246
+ return level < path.length ? null : target;
1247
+ };
1248
+ /**
1249
+ * Returns the {@link RuleType} or {@link RuleGroupType}/{@link RuleGroupTypeIC}
1250
+ * with the given `id` within a query.
1251
+ */
1252
+ const findID = (id, query) => {
1253
+ if (query.id === id) return query;
1254
+ for (const rule of query.rules) {
1255
+ if (typeof rule === "string") continue;
1256
+ if (rule.id === id) return rule;
1257
+ else if (require_objectUtils.isRuleGroup(rule)) {
1258
+ const subRule = findID(id, rule);
1259
+ if (subRule) return subRule;
1260
+ }
1261
+ }
1262
+ return null;
1263
+ };
1264
+ /**
1265
+ * Returns the {@link Path} of the {@link RuleType} or {@link RuleGroupType}/{@link RuleGroupTypeIC}
1266
+ * with the given `id` within a query.
1267
+ */
1268
+ const getPathOfID = (id, query) => {
1269
+ if (query.id === id) return [];
1270
+ const idx = query.rules.findIndex((r) => !(typeof r === "string") && r.id === id);
1271
+ if (idx >= 0) return [idx];
1272
+ for (const [i, r] of Object.entries(query.rules)) if (require_objectUtils.isRuleGroup(r)) {
1273
+ const subPath = getPathOfID(id, r);
1274
+ if (Array.isArray(subPath)) return [Number.parseInt(i), ...subPath];
1275
+ }
1276
+ return null;
1277
+ };
1278
+ /**
1279
+ * Truncates the last element of an array and returns the result as a new array.
1280
+ */
1281
+ const getParentPath = (path) => path.slice(0, -1);
1282
+ /**
1283
+ * Determines if two paths (each `Path`) are equivalent.
1284
+ */
1285
+ const pathsAreEqual = (path1, path2) => {
1286
+ if (path1.length !== path2.length) return false;
1287
+ for (let i = 0; i < path1.length; i++) if (path1[i] !== path2[i]) return false;
1288
+ return true;
1289
+ };
1290
+ /**
1291
+ * Determines if the first path is an ancestor of the second path. The first path must
1292
+ * be shorter and exactly match the second path up through the length of the first path.
1293
+ */
1294
+ const isAncestor = (maybeAncestor, path) => {
1295
+ if (maybeAncestor.length >= path.length) return false;
1296
+ for (let i = 0; i < maybeAncestor.length; i++) if (maybeAncestor[i] !== path[i]) return false;
1297
+ return true;
1298
+ };
1299
+ /**
1300
+ * Finds the deepest/longest path that two paths have in common.
1301
+ */
1302
+ const getCommonAncestorPath = (path1, path2) => {
1303
+ const commonAncestorPath = [];
1304
+ const parentPath1 = getParentPath(path1);
1305
+ const parentPath2 = getParentPath(path2);
1306
+ let i = 0;
1307
+ while (i < parentPath1.length && i < parentPath2.length && parentPath1[i] === parentPath2[i]) {
1308
+ commonAncestorPath.push(parentPath2[i]);
1309
+ i++;
1310
+ }
1311
+ return commonAncestorPath;
1312
+ };
1313
+ /**
1314
+ * Determines if the rule or group at the specified path is either disabled itself
1315
+ * or disabled by an ancestor group.
1316
+ */
1317
+ const pathIsDisabled = (path, query) => {
1318
+ let disabled = !!query.disabled;
1319
+ let target = query;
1320
+ let level = 0;
1321
+ while (level < path.length && !disabled && require_objectUtils.isRuleGroup(target)) {
1322
+ const t = target.rules[path[level]];
1323
+ if (require_objectUtils.isPojo(t) && (require_objectUtils.isRuleGroup(t) || "field" in t && !!t.field)) {
1324
+ disabled = !!t.disabled;
1325
+ target = t;
1326
+ }
1327
+ level++;
1328
+ }
1329
+ return disabled;
1330
+ };
1331
+ /**
1332
+ * Determines if the rule or group at the specified path is disabled by `disabledPaths`—the array
1333
+ * form of the `QueryBuilder` `disabled` prop, which disables nodes by position rather than by a
1334
+ * `disabled` property on the node itself. A path is disabled if it appears in `disabledPaths` or
1335
+ * descends from a path that does.
1336
+ *
1337
+ * @group Paths
1338
+ */
1339
+ const pathIsDisabledByPaths = (path, disabledPaths = []) => disabledPaths.some((p) => pathsAreEqual(p, path) || isAncestor(p, path));
1340
+ /**
1341
+ * Builds the {@link PathInfo} for each child of a group at `path`. A child is disabled if its
1342
+ * parent is disabled or if its own path appears in `disabledPaths`.
1343
+ *
1344
+ * @group Paths
1345
+ */
1346
+ const derivePathInfo = (path, childCount, { disabled = false, disabledPaths = [] } = {}) => {
1347
+ const paths = [];
1348
+ for (let i = 0; i < childCount; i++) {
1349
+ const thisPath = [...path, i];
1350
+ paths[i] = {
1351
+ path: thisPath,
1352
+ disabled: disabled || disabledPaths.some((p) => pathsAreEqual(thisPath, p))
1353
+ };
1354
+ }
1355
+ return paths;
1356
+ };
1357
+ //#endregion
1358
+ //#region src/utils/generateAccessibleDescription.ts
1359
+ /**
1360
+ * The default `accessibleDescriptionGenerator`. Produces the `aria-label` for a rule group:
1361
+ * `"Query builder"` for the root group, `"Rule group at path 0-1"` for any other.
1362
+ *
1363
+ * @group Accessibility
1364
+ */
1365
+ const generateAccessibleDescription = (params) => pathsAreEqual([], params.path) ? `Query builder` : `Rule group at path ${params.path.join("-")}`;
1366
+ //#endregion
1367
+ //#region src/utils/getMatchModesUtil.ts
1368
+ const dummyFD = {
1369
+ name: "name",
1370
+ value: "name",
1371
+ matchModes: null,
1372
+ label: "label"
1373
+ };
1374
+ /**
1375
+ * Utility function to get the match modes array for the given
1376
+ * field. If the field definition does not define a `matchModes`
1377
+ * property, the `getMatchModes` prop is used. Returns
1378
+ * `FullOption<MatchMode>[]` of all match modes by default.
1379
+ */
1380
+ const getMatchModesUtil = (fieldData, getMatchModes) => {
1381
+ const fd = fieldData ? require_utils.toFullOption(fieldData) : /* v8 ignore next -- @preserve */ dummyFD;
1382
+ let matchModes = fd.matchModes ?? false;
1383
+ if (!matchModes && getMatchModes) matchModes = getMatchModes(fd.value, { fieldData: fd });
1384
+ if (matchModes === true) return require_utils.defaultMatchModes;
1385
+ else if (matchModes === false) return [];
1386
+ if (require_utils.isFlexibleOptionArray(matchModes)) return require_utils.toFullOptionList(matchModes);
1387
+ return matchModes?.map((mm) => require_utils.defaultMatchModes.find((dmm) => dmm.value === require_objectUtils.lc(mm)) ?? {
1388
+ name: mm,
1389
+ value: mm,
1390
+ label: mm
1391
+ }) ?? [];
1392
+ };
1393
+ //#endregion
1394
+ //#region src/utils/getRuleDefaultValue.ts
1395
+ const getFirstOptionsFrom = (opts, r, listsAsArrays) => {
1396
+ const firstOption = require_utils.getFirstOption(opts);
1397
+ if (r.operator === "between" || r.operator === "notBetween") {
1398
+ const valueAsArray = [firstOption, firstOption];
1399
+ return listsAsArrays ? valueAsArray : require_utils.joinWith(valueAsArray.map((v) => v ?? /* v8 ignore start -- @preserve */ ""), ",");
1400
+ }
1401
+ return firstOption;
1402
+ };
1403
+ /**
1404
+ * Computes the default `value` for a rule given its `field`/`operator`/`valueSource`, mirroring
1405
+ * the precedence the {@link react-querybuilder!QueryBuilder QueryBuilder} applies: a field's
1406
+ * `defaultValue`, then a `getDefaultValue` override, then a value derived from the field/operator's
1407
+ * value list and editor type (first option for `select`/`radio`, `false` for `checkbox`, paired for
1408
+ * `between`/`notBetween`), or a comparator-valid field when `valueSource` is `'field'`. Falls back
1409
+ * to `''`.
1410
+ *
1411
+ * @group Option Lists
1412
+ */
1413
+ const getRuleDefaultValue = (rule, options) => {
1414
+ const { fieldData, fields, getValueEditorType, getValues, getDefaultValue, getParameters, listsAsArrays } = options;
1415
+ if (fieldData?.defaultValue !== void 0 && fieldData.defaultValue !== null) return fieldData.defaultValue;
1416
+ else if (getDefaultValue) return getDefaultValue(rule, { fieldData });
1417
+ let value = "";
1418
+ const values = getValues(rule.field, rule.operator, { fieldData });
1419
+ if (rule.valueSource === "field") {
1420
+ const filteredFields = require_prepareQueryObjects.filterFieldsByComparator(fieldData, fields, rule.operator);
1421
+ value = filteredFields.length > 0 ? getFirstOptionsFrom(filteredFields, rule, listsAsArrays) : "";
1422
+ } else if (rule.valueSource === "parameter") {
1423
+ const parameters = getParameters ? getParameters(rule.field, rule.operator, { fieldData }) : null;
1424
+ value = parameters && parameters.length > 0 ? require_utils.getFirstOption(parameters) : "";
1425
+ } else if (values.length > 0) {
1426
+ const editorType = getValueEditorType(rule.field, rule.operator, { fieldData });
1427
+ if (editorType === "multiselect") value = listsAsArrays ? [] : "";
1428
+ else if (editorType === "select" || editorType === "radio") value = getFirstOptionsFrom(values, rule, listsAsArrays);
1429
+ } else if (getValueEditorType(rule.field, rule.operator, { fieldData }) === "checkbox") value = false;
1430
+ return value;
1431
+ };
1432
+ //#endregion
1433
+ //#region src/utils/getValidationClassNames.ts
1434
+ /**
1435
+ * Gets the standard classname for valid or invalid components
1436
+ * based on the given validation result.
1437
+ */
1438
+ const getValidationClassNames = (validationResult) => {
1439
+ const valid = typeof validationResult === "boolean" ? validationResult : typeof validationResult === "object" && validationResult !== null ? validationResult.valid : null;
1440
+ return typeof valid === "boolean" ? valid ? require_utils.standardClassnames.valid : require_utils.standardClassnames.invalid : "";
1441
+ };
1442
+ //#endregion
1443
+ //#region src/utils/immerInstances.ts
1444
+ /**
1445
+ * Globally enables or disables immer's auto-freeze, i.e. the deep freeze applied to every query
1446
+ * returned by {@link add}, {@link update}, {@link remove}, {@link move}, {@link insert}, and
1447
+ * {@link group}.
1448
+ *
1449
+ * Re-exported from immer so that consumers mixing these tools with their own `produce` calls can
1450
+ * switch both at once. Prefer the per-call `freeze` option, or the {@link QueryManager} option of
1451
+ * the same name, when the change should not be process-wide. A per-call `freeze: false` wins
1452
+ * regardless of this setting; a per-call `freeze: true` does not re-enable freezing once this has
1453
+ * turned it off, since it selects immer's default instance.
1454
+ *
1455
+ * @group Query Tools
1456
+ */
1457
+ const setAutoFreeze = immer.setAutoFreeze;
1458
+ const unfrozenImmer = new immer.Immer({ autoFreeze: false });
1459
+ /**
1460
+ * The `produce` implementation matching the requested freeze behavior.
1461
+ *
1462
+ * @internal
1463
+ */
1464
+ const producerFor = (freeze = true) => freeze ? immer.produce : unfrozenImmer.produce;
1465
+ //#endregion
1466
+ //#region src/utils/mergeAnyTranslations.ts
1467
+ /**
1468
+ * Merges any number of partial translations into a single definition.
1469
+ */
1470
+ const mergeAnyTranslations = (base, ...otherTranslations) => {
1471
+ const result = { ...base };
1472
+ for (const translations of otherTranslations)
1473
+ // v8 ignore else
1474
+ if (translations) for (const key of require_objectUtils.objectKeys(translations)) {
1475
+ if (require_objectUtils.isUnsafeKey(key)) continue;
1476
+ if (result[key]) result[key] = {
1477
+ ...result[key],
1478
+ ...translations[key]
1479
+ };
1480
+ else result[key] = { ...translations[key] };
1481
+ }
1482
+ return result;
1483
+ };
1484
+ const mergeAnyTranslation = (el, keyPropContextMap, defaults) => {
1485
+ if (require_objectUtils.isUnsafeKey(el)) return void 0;
1486
+ const finalKeys = require_objectUtils.objectEntries(keyPropContextMap).map(([key, [pT, cT]]) => [key, pT ?? cT ?? defaults?.[el]?.[key]]).filter((k) => !require_objectUtils.isUnsafeKey(k[0]) && !!k[1]);
1487
+ if (finalKeys.length > 0 || defaults) {
1488
+ const defaultProperties = defaults?.[el] ?? {};
1489
+ const finalObject = Object.assign({}, defaultProperties, Object.fromEntries(finalKeys));
1490
+ return { [el]: finalObject };
1491
+ }
1492
+ };
1493
+ //#endregion
1494
+ //#region src/utils/mergeClassnames.ts
1495
+ const joinClassnamesByName = (name, args) => {
1496
+ let result = "";
1497
+ for (let i = 0; i < args.length; i++) {
1498
+ const v = args[i]?.[name];
1499
+ if (!v) continue;
1500
+ const s = typeof v === "string" ? v : clsx(v);
1501
+ if (s) result = result ? `${result} ${s}` : s;
1502
+ }
1503
+ return result;
1504
+ };
1505
+ /**
1506
+ * Merges a list of partial {@link Classnames} definitions into a single definition.
1507
+ */
1508
+ const mergeClassnames = (...args) => ({
1509
+ queryBuilder: joinClassnamesByName("queryBuilder", args),
1510
+ ruleGroup: joinClassnamesByName("ruleGroup", args),
1511
+ header: joinClassnamesByName("header", args),
1512
+ body: joinClassnamesByName("body", args),
1513
+ combinators: joinClassnamesByName("combinators", args),
1514
+ addRule: joinClassnamesByName("addRule", args),
1515
+ addGroup: joinClassnamesByName("addGroup", args),
1516
+ cloneRule: joinClassnamesByName("cloneRule", args),
1517
+ cloneGroup: joinClassnamesByName("cloneGroup", args),
1518
+ removeGroup: joinClassnamesByName("removeGroup", args),
1519
+ rule: joinClassnamesByName("rule", args),
1520
+ fields: joinClassnamesByName("fields", args),
1521
+ operators: joinClassnamesByName("operators", args),
1522
+ value: joinClassnamesByName("value", args),
1523
+ removeRule: joinClassnamesByName("removeRule", args),
1524
+ notToggle: joinClassnamesByName("notToggle", args),
1525
+ shiftActions: joinClassnamesByName("shiftActions", args),
1526
+ undoRedoActions: joinClassnamesByName("undoRedoActions", args),
1527
+ undoAction: joinClassnamesByName("undoAction", args),
1528
+ redoAction: joinClassnamesByName("redoAction", args),
1529
+ dragHandle: joinClassnamesByName("dragHandle", args),
1530
+ lockRule: joinClassnamesByName("lockRule", args),
1531
+ lockGroup: joinClassnamesByName("lockGroup", args),
1532
+ muteRule: joinClassnamesByName("muteRule", args),
1533
+ muteGroup: joinClassnamesByName("muteGroup", args),
1534
+ muted: joinClassnamesByName("muted", args),
1535
+ valueSource: joinClassnamesByName("valueSource", args),
1536
+ actionElement: joinClassnamesByName("actionElement", args),
1537
+ valueSelector: joinClassnamesByName("valueSelector", args),
1538
+ betweenRules: joinClassnamesByName("betweenRules", args),
1539
+ valid: joinClassnamesByName("valid", args),
1540
+ invalid: joinClassnamesByName("invalid", args),
1541
+ dndDragging: joinClassnamesByName("dndDragging", args),
1542
+ dndOver: joinClassnamesByName("dndOver", args),
1543
+ dndCopy: joinClassnamesByName("dndCopy", args),
1544
+ dndGroup: joinClassnamesByName("dndGroup", args),
1545
+ dndDropNotAllowed: joinClassnamesByName("dndDropNotAllowed", args),
1546
+ dndPreviewPosition: joinClassnamesByName("dndPreviewPosition", args),
1547
+ dndHidden: joinClassnamesByName("dndHidden", args),
1548
+ disabled: joinClassnamesByName("disabled", args),
1549
+ valueListItem: joinClassnamesByName("valueListItem", args),
1550
+ matchMode: joinClassnamesByName("matchMode", args),
1551
+ matchThreshold: joinClassnamesByName("matchThreshold", args),
1552
+ branches: joinClassnamesByName("branches", args),
1553
+ hasSubQuery: joinClassnamesByName("hasSubQuery", args),
1554
+ loading: joinClassnamesByName("loading", args),
1555
+ valueDateTimeRelative: joinClassnamesByName("valueDateTimeRelative", args)
1556
+ });
1557
+ //#endregion
1558
+ //#region src/utils/optionResolvers.ts
1559
+ /**
1560
+ * Resolves the operator list for a field, applying the same precedence as the `QueryBuilder`
1561
+ * component: the field's own `operators`, then the `getOperators` callback, then the
1562
+ * query-level operator list.
1563
+ *
1564
+ * @group Option Lists
1565
+ */
1566
+ const resolveOperatorList = ({ field, fieldData, getOperators, operators, placeholder, baseOption, autoSelectOption }) => require_utils.prepareOptionList({
1567
+ optionList: fieldData?.operators ?? getOperators?.(field, { fieldData }) ?? operators,
1568
+ placeholder,
1569
+ baseOption,
1570
+ labelMap: require_utils.defaultOperatorLabelMap,
1571
+ autoSelectOption
1572
+ }).optionList;
1573
+ /**
1574
+ * Resolves the default operator for a field, applying the same precedence as the `QueryBuilder`
1575
+ * component: the field's own `defaultOperator`, then the `getDefaultOperator` option (a string or
1576
+ * a function), then the first available operator.
1577
+ *
1578
+ * @group Option Lists
1579
+ */
1580
+ const resolveDefaultOperator = ({ field, fieldData, getDefaultOperator, getOperators }) => {
1581
+ if (fieldData?.defaultOperator) return fieldData.defaultOperator;
1582
+ if (getDefaultOperator) return typeof getDefaultOperator === "function" ? getDefaultOperator(field, { fieldData }) : getDefaultOperator;
1583
+ return require_utils.getFirstOption(getOperators(field, { fieldData })) ?? "";
1584
+ };
1585
+ /**
1586
+ * Resolves the value editor type for a field/operator pair, applying the same precedence as the
1587
+ * `QueryBuilder` component: the field's own `valueEditorType` (a string or a function of the
1588
+ * operator), then the `getValueEditorType` callback, then `"text"`.
1589
+ *
1590
+ * @group Option Lists
1591
+ */
1592
+ const resolveValueEditorType = ({ field, operator, fieldData, getValueEditorType }) => {
1593
+ if (fieldData?.valueEditorType) return typeof fieldData.valueEditorType === "function" ? fieldData.valueEditorType(operator) : fieldData.valueEditorType;
1594
+ return getValueEditorType?.(field, operator, { fieldData }) ?? "text";
1595
+ };
1596
+ /**
1597
+ * Resolves the value option list for a field/operator pair, applying the same precedence as the
1598
+ * `QueryBuilder` component: the field's own `values`, then the `getValues` callback, then an
1599
+ * empty list.
1600
+ *
1601
+ * @group Option Lists
1602
+ */
1603
+ const resolveValueList = ({ field, operator, fieldData, getValues, placeholder, baseOption, autoSelectOption }) => require_utils.prepareOptionList({
1604
+ optionList: fieldData?.values ?? getValues?.(field, operator, { fieldData }) ?? [],
1605
+ placeholder,
1606
+ baseOption,
1607
+ autoSelectOption
1608
+ }).optionList;
1609
+ //#endregion
1610
+ //#region src/utils/optionsEqual.ts
1611
+ const isPlainObject = (x) => {
1612
+ const proto = Object.getPrototypeOf(x);
1613
+ return proto === null || proto === Object.prototype;
1614
+ };
1615
+ /**
1616
+ * Structural equality for {@link QueryManagerOptions} values. Arrays and plain objects are
1617
+ * compared by value; everything else — functions, class instances, `Map`s, `Date`s — by
1618
+ * identity.
1619
+ *
1620
+ * That split is what makes an options object rebuilt on every render compare equal as long as
1621
+ * its _data_ did not change, which is the entire point: a caller that passes object literals
1622
+ * (`fields={[...]}`, `translations={{...}}`) hands a fresh identity to every reconfigure, so an
1623
+ * identity-only comparison would report a change every time.
1624
+ *
1625
+ * Comparing functions by identity is deliberate rather than a limitation. Two functions cannot
1626
+ * be proven equivalent, so a caller that rebuilds `getDefaultValue` per render must either
1627
+ * memoize it or accept the reconfigure.
1628
+ */
1629
+ const valuesEqual = (a, b) => {
1630
+ if (Object.is(a, b)) return true;
1631
+ if (Array.isArray(a) || Array.isArray(b)) return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => valuesEqual(v, b[i]));
1632
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
1633
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b) || !isPlainObject(a)) return false;
1634
+ const aKeys = Object.keys(a);
1635
+ return aKeys.length === Object.keys(b).length && aKeys.every((k) => valuesEqual(a[k], b[k]));
1636
+ };
1637
+ /**
1638
+ * Whether two {@link QueryManagerOptions} objects describe the same configuration, per
1639
+ * {@link valuesEqual}: data by value, functions by identity.
1640
+ *
1641
+ * {@link QueryManager.reconfigure} uses this to gate itself, so most callers never need it
1642
+ * directly. It is exported for framework adapters that decide whether to _call_ `reconfigure`
1643
+ * at all — skipping the call avoids building the merged options object in the first place.
1644
+ *
1645
+ * Nested option objects (`history`, `translations`, …) are descended into rather than compared
1646
+ * by identity, so `{ history: { maxHistory: 10 } }` rebuilt per render compares equal.
1647
+ */
1648
+ const optionsEqual = (a, b) => valuesEqual(a, b);
1649
+ //#endregion
1650
+ //#region src/utils/preferProp.ts
1651
+ const preferPropDefaultTrue = (prop, context) => prop === false ? false : prop ? true : !(context === false);
1652
+ const preferPropDefaultFalse = (prop, context) => prop ? true : prop === false ? false : !!context;
1653
+ /**
1654
+ * For given default, prop, and context values, return the first provided of prop,
1655
+ * context, and default, in that order.
1656
+ */
1657
+ const preferProp = (def, prop, context, doNotFinalize) => !doNotFinalize ? def ? preferPropDefaultTrue(prop, context) : preferPropDefaultFalse(prop, context) : prop ?? context;
1658
+ /**
1659
+ * For given default, prop, and context values, return the first provided of prop,
1660
+ * context, and default, in that order.
1661
+ */
1662
+ const preferAnyProp = (def, prop, context) => prop !== void 0 && prop != null ? prop : context !== void 0 && context != null ? context : def;
1663
+ /**
1664
+ * For a given set of defaults, props, and context values, return the first provided of prop,
1665
+ * context, and default—in that order—for each property in the defaults object.
1666
+ */
1667
+ const preferFlagProps = (props = {}, contextVals = {}, finalize) => require_objectUtils.objectEntries(require_utils.queryBuilderFlagDefaults).reduce((acc, [key, def]) => {
1668
+ acc[key] = preferProp(def, props[key], contextVals[key], !finalize);
1669
+ return acc;
1670
+ }, {});
1671
+ //#endregion
1672
+ //#region src/utils/regenerateIDs.ts
1673
+ /**
1674
+ * Generates a new `id` property for a rule.
1675
+ */
1676
+ const regenerateID = (rule, { idGenerator = require_prepareQueryObjects.generateID } = {}) => structuredClone({
1677
+ ...rule,
1678
+ id: idGenerator()
1679
+ });
1680
+ /**
1681
+ * Recursively generates new `id` properties for a rule group and all its rules and subgroups.
1682
+ */
1683
+ const regenerateIDs = (subject, { idGenerator = require_prepareQueryObjects.generateID } = {}) => {
1684
+ if (!require_objectUtils.isPojo(subject)) return subject;
1685
+ if (!require_objectUtils.isRuleGroup(subject)) return structuredClone({
1686
+ ...subject,
1687
+ id: idGenerator()
1688
+ });
1689
+ const newGroup = {
1690
+ ...subject,
1691
+ id: idGenerator()
1692
+ };
1693
+ // v8 ignore else
1694
+ if (Array.isArray(newGroup.rules)) newGroup.rules = subject.rules.map((r) => typeof r === "string" ? r : require_objectUtils.isRuleGroup(r) ? regenerateIDs(r, { idGenerator }) : regenerateID(r, { idGenerator }));
1695
+ return newGroup;
1696
+ };
1697
+ //#endregion
1698
+ //#region src/utils/queryTools.ts
1699
+ /**
1700
+ * Whether a mutation targeting `pathOrID` is blocked by the given guards, and why.
1701
+ * Returns `null` when the mutation may proceed.
1702
+ *
1703
+ * Exported so that callers which run their own logic before mutating—such as a UI layer that
1704
+ * invokes a confirmation callback—can apply the same rules without duplicating them.
1705
+ *
1706
+ * @group Query Tools
1707
+ */
1708
+ const getGuardAbortReason = (query, pathOrID, guards = {}, { asParent = false } = {}) => {
1709
+ if (guards.queryDisabled) return asParent ? "parent-disabled" : "target-disabled";
1710
+ if (!guards.respectDisabled || pathOrID === void 0) return null;
1711
+ const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
1712
+ if (path && (pathIsDisabled(path, query) || pathIsDisabledByPaths(path, guards.disabledPaths))) return asParent ? "parent-disabled" : "target-disabled";
1713
+ return null;
1714
+ };
1715
+ /**
1716
+ * Whether adding a group beneath `parentPath` would exceed `maxLevels`.
1717
+ *
1718
+ * @group Query Tools
1719
+ */
1720
+ const exceedsMaxLevels = (parentPath, { maxLevels = Infinity } = {}) => !!parentPath && parentPath.length >= maxLevels;
1721
+ /**
1722
+ * Adds a rule or group to a query without mutating the original query.
1723
+ *
1724
+ * @returns A new query with the rule or group added.
1725
+ *
1726
+ * @group Query Tools
1727
+ */
1728
+ const add = (query, ruleOrGroup, parentPathOrID, options = {}) => producerFor(options.freeze)(query, (q) => addInPlace(q, ruleOrGroup, parentPathOrID, options));
1729
+ /**
1730
+ * Adds a rule or group to a query in place.
1731
+ *
1732
+ * @returns The query (mutated in place) with the rule or group added.
1733
+ *
1734
+ * @group Query Tools
1735
+ */
1736
+ const addInPlace = (query, ruleOrGroup, parentPathOrID, options = {}) => {
1737
+ const { combinators = require_utils.defaultCombinators, combinatorPreceding, idGenerator = require_prepareQueryObjects.generateID, onAbort } = options;
1738
+ const parent = Array.isArray(parentPathOrID) ? findPath(parentPathOrID, query) : findID(parentPathOrID, query);
1739
+ if (!parent) {
1740
+ onAbort?.({
1741
+ reason: "parent-not-found",
1742
+ operation: "add",
1743
+ pathOrID: parentPathOrID
1744
+ });
1745
+ return query;
1746
+ }
1747
+ if (!require_objectUtils.isRuleGroup(parent)) {
1748
+ onAbort?.({
1749
+ reason: "parent-not-a-group",
1750
+ operation: "add",
1751
+ pathOrID: parentPathOrID
1752
+ });
1753
+ return query;
1754
+ }
1755
+ const parentPath = Array.isArray(parentPathOrID) ? parentPathOrID : getPathOfID(parentPathOrID, query);
1756
+ const addGuardReason = getGuardAbortReason(query, parentPath, options, { asParent: true });
1757
+ if (addGuardReason) {
1758
+ onAbort?.({
1759
+ reason: addGuardReason,
1760
+ operation: "add",
1761
+ pathOrID: parentPathOrID
1762
+ });
1763
+ return query;
1764
+ }
1765
+ if (require_objectUtils.isRuleGroup(ruleOrGroup) && exceedsMaxLevels(parentPath, options)) {
1766
+ onAbort?.({
1767
+ reason: "max-levels-exceeded",
1768
+ operation: "add",
1769
+ pathOrID: parentPathOrID
1770
+ });
1771
+ return query;
1772
+ }
1773
+ if (require_objectUtils.isRuleGroupTypeIC(parent) && parent.rules.length > 0) {
1774
+ const prevCombinator = parent.rules.at(-2);
1775
+ parent.rules.push(combinatorPreceding ?? (typeof prevCombinator === "string" ? prevCombinator : require_utils.getFirstOption(combinators)));
1776
+ }
1777
+ parent.rules.push(require_prepareQueryObjects.prepareRuleOrGroup(ruleOrGroup, { idGenerator }));
1778
+ return query;
1779
+ };
1780
+ /**
1781
+ * Relative order in which properties are applied during a multi-property update.
1782
+ * Lower ranks apply first; `value` applies last so an explicitly-provided value
1783
+ * is never clobbered by a reset triggered by a `field`/`operator`/`valueSource`
1784
+ * change. Unranked properties default to `3` (between `valueSource` and `value`).
1785
+ */
1786
+ const updatePropRank = {
1787
+ field: 0,
1788
+ operator: 1,
1789
+ valueSource: 2,
1790
+ value: 4
1791
+ };
1792
+ /** Stable-sorts `[prop, value]` entries by {@link updatePropRank}. */
1793
+ const orderUpdateEntries = (entries) => entries.toSorted((x, y) => (updatePropRank[x[0]] ?? 3) - (updatePropRank[y[0]] ?? 3));
1794
+ /**
1795
+ * Normalizes the variadic {@link update}/{@link updateInPlace} arguments (single
1796
+ * prop+value, parallel arrays, or property map) into a canonically-ordered list
1797
+ * of `[prop, value]` entries plus the target path/ID and options.
1798
+ */
1799
+ const normalizeUpdateArgs = (a, b, c, d) => {
1800
+ if (typeof a === "string") return {
1801
+ entries: [[a, b]],
1802
+ pathOrID: c,
1803
+ options: d ?? {}
1804
+ };
1805
+ if (Array.isArray(a)) {
1806
+ const values = b;
1807
+ return {
1808
+ entries: orderUpdateEntries(a.map((prop, i) => [prop, values[i]])),
1809
+ pathOrID: c,
1810
+ options: d ?? {}
1811
+ };
1812
+ }
1813
+ return {
1814
+ entries: orderUpdateEntries(Object.entries(a)),
1815
+ pathOrID: b,
1816
+ options: c ?? {}
1817
+ };
1818
+ };
1819
+ /**
1820
+ * The options argument of an {@link update} call, whose position depends on the argument form.
1821
+ * Cheaper than {@link normalizeUpdateArgs} when only the options are needed.
1822
+ */
1823
+ const updateOptionsOf = (a, b, c, d) => (typeof a === "string" || Array.isArray(a) ? d : c) ?? {};
1824
+ /**
1825
+ * Applies one or more property updates to a query in place. Shared by
1826
+ * {@link update} and {@link updateInPlace}.
1827
+ */
1828
+ const applyUpdatesInPlace = (query, a, b, c, d) => {
1829
+ const { entries, pathOrID, options } = normalizeUpdateArgs(a, b, c, d);
1830
+ for (const [prop, value] of entries) updateInPlaceSingle(query, prop, value, pathOrID, options);
1831
+ return query;
1832
+ };
1833
+ /**
1834
+ * Updates one or more properties of a rule or group within a query without
1835
+ * mutating the original query. Properties may be supplied individually
1836
+ * (`prop`, `value`), as parallel arrays (`props`, `values`), or as a
1837
+ * property-to-value map. For multi-property updates, `field`, `operator`, and
1838
+ * `valueSource` are applied before `value`, so an explicit `value` is never
1839
+ * reset by a change to one of those properties.
1840
+ *
1841
+ * @returns A new query with the rule or group properties updated.
1842
+ *
1843
+ * @group Query Tools
1844
+ */
1845
+ const update = ((query, a, b, c, d) => producerFor(updateOptionsOf(a, b, c, d).freeze)(query, (q) => {
1846
+ applyUpdatesInPlace(q, a, b, c, d);
1847
+ }));
1848
+ /**
1849
+ * Updates one or more properties of a rule or group within a query in place.
1850
+ * See {@link update} for the supported argument forms and ordering semantics.
1851
+ *
1852
+ * @returns The query (mutated in place) with the rule or group properties updated.
1853
+ *
1854
+ * @group Query Tools
1855
+ */
1856
+ const updateInPlace = ((query, a, b, c, d) => applyUpdatesInPlace(query, a, b, c, d));
1857
+ /**
1858
+ * Updates a single property of a rule or group within a query in place.
1859
+ */
1860
+ const updateInPlaceSingle = (query, prop, value, pathOrID, options = {}) => {
1861
+ const { resetOnFieldChange: _resetOnFieldChange = true, resetOnOperatorChange = false, getRuleDefaultOperator = () => "=", getValueSources = () => ["value"], getRuleDefaultValue = () => "", getMatchModes = () => [], onAbort } = options;
1862
+ let resetOnFieldChange = _resetOnFieldChange;
1863
+ const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
1864
+ if (!path) {
1865
+ onAbort?.({
1866
+ reason: "target-not-found",
1867
+ operation: "update",
1868
+ pathOrID
1869
+ });
1870
+ return query;
1871
+ }
1872
+ const updateGuards = prop === "disabled" ? { queryDisabled: options.queryDisabled } : options;
1873
+ const updateGuardReason = getGuardAbortReason(query, path, updateGuards);
1874
+ if (updateGuardReason) {
1875
+ onAbort?.({
1876
+ reason: updateGuardReason,
1877
+ operation: "update",
1878
+ pathOrID
1879
+ });
1880
+ return query;
1881
+ }
1882
+ if (prop === "combinator" && !require_objectUtils.isRuleGroupType(query)) {
1883
+ const parent = findPath(getParentPath(path), query);
1884
+ if (!parent || !require_objectUtils.isRuleGroup(parent)) {
1885
+ onAbort?.({
1886
+ reason: "target-not-found",
1887
+ operation: "update",
1888
+ pathOrID
1889
+ });
1890
+ return query;
1891
+ }
1892
+ const parentRules = parent.rules;
1893
+ if (path.at(-1) % 2 === 1) {
1894
+ if (parentRules[path.at(-1)] === value) onAbort?.({
1895
+ reason: "no-change",
1896
+ operation: "update",
1897
+ pathOrID
1898
+ });
1899
+ else parentRules[path.at(-1)] = value;
1900
+ } else onAbort?.({
1901
+ reason: "not-a-combinator-slot",
1902
+ operation: "update",
1903
+ pathOrID
1904
+ });
1905
+ return query;
1906
+ }
1907
+ const ruleOrGroup = findPath(path, query);
1908
+ if (!ruleOrGroup) {
1909
+ onAbort?.({
1910
+ reason: "target-not-found",
1911
+ operation: "update",
1912
+ pathOrID
1913
+ });
1914
+ return query;
1915
+ }
1916
+ const isGroup = require_objectUtils.isRuleGroup(ruleOrGroup);
1917
+ if (ruleOrGroup[prop] === value) {
1918
+ onAbort?.({
1919
+ reason: "no-change",
1920
+ operation: "update",
1921
+ pathOrID
1922
+ });
1923
+ return query;
1924
+ }
1925
+ if (prop !== "valueSource") ruleOrGroup[prop] = value;
1926
+ if (isGroup) return query;
1927
+ let resetValueSource = false;
1928
+ let resetValue = false;
1929
+ if (prop === "field") {
1930
+ const fromFieldMatchModes = getMatchModes(ruleOrGroup.field);
1931
+ const toFieldMatchModes = getMatchModes(value);
1932
+ if (toFieldMatchModes.length === 0) delete ruleOrGroup.match;
1933
+ else {
1934
+ const nextMatchMode = ruleOrGroup.match?.mode && require_utils.getOption(toFieldMatchModes, ruleOrGroup.match.mode) ? null : require_utils.getFirstOption(toFieldMatchModes);
1935
+ if (nextMatchMode) ruleOrGroup.match = {
1936
+ mode: nextMatchMode,
1937
+ threshold: 1
1938
+ };
1939
+ }
1940
+ if (fromFieldMatchModes.length > 0 || toFieldMatchModes.length > 0) resetOnFieldChange = true;
1941
+ }
1942
+ if (resetOnFieldChange && prop === "field") {
1943
+ ruleOrGroup.operator = getRuleDefaultOperator(value);
1944
+ resetValueSource = true;
1945
+ resetValue = true;
1946
+ }
1947
+ if (resetOnOperatorChange && prop === "operator") {
1948
+ resetValueSource = true;
1949
+ resetValue = true;
1950
+ }
1951
+ const valueSources = require_prepareQueryObjects.getValueSourcesUtil({
1952
+ name: ruleOrGroup.field,
1953
+ value: ruleOrGroup.field,
1954
+ label: ""
1955
+ }, ruleOrGroup.operator, getValueSources);
1956
+ const defaultValueSource = require_utils.getFirstOption(valueSources);
1957
+ if (resetValueSource && ruleOrGroup.valueSource && defaultValueSource !== ruleOrGroup.valueSource || prop === "valueSource" && value !== ruleOrGroup.valueSource) {
1958
+ resetValue = !!ruleOrGroup.valueSource || !ruleOrGroup.valueSource && value !== defaultValueSource;
1959
+ ruleOrGroup.valueSource = resetValueSource ? defaultValueSource : value;
1960
+ }
1961
+ if (resetValue) ruleOrGroup.value = getRuleDefaultValue(ruleOrGroup);
1962
+ return query;
1963
+ };
1964
+ /**
1965
+ * Removes a rule or group from a query without mutating the original query.
1966
+ *
1967
+ * @returns A new query with the rule or group removed.
1968
+ *
1969
+ * @group Query Tools
1970
+ */
1971
+ const remove = (query, pathOrID, options = {}) => producerFor(options.freeze)(query, (q) => removeInPlace(q, pathOrID, options));
1972
+ /**
1973
+ * Removes a rule or group from a query in place.
1974
+ *
1975
+ * @returns The query (mutated in place) with the rule or group removed.
1976
+ *
1977
+ * @group Query Tools
1978
+ */
1979
+ const removeInPlace = (query, pathOrID, options = {}) => {
1980
+ const { onAbort } = options;
1981
+ const path = Array.isArray(pathOrID) ? pathOrID : getPathOfID(pathOrID, query);
1982
+ if (!path) {
1983
+ onAbort?.({
1984
+ reason: "target-not-found",
1985
+ operation: "remove",
1986
+ pathOrID
1987
+ });
1988
+ return query;
1989
+ }
1990
+ if (path.length === 0) {
1991
+ onAbort?.({
1992
+ reason: "root-not-allowed",
1993
+ operation: "remove",
1994
+ pathOrID
1995
+ });
1996
+ return query;
1997
+ }
1998
+ const removeGuardReason = getGuardAbortReason(query, path, options);
1999
+ if (removeGuardReason) {
2000
+ onAbort?.({
2001
+ reason: removeGuardReason,
2002
+ operation: "remove",
2003
+ pathOrID
2004
+ });
2005
+ return query;
2006
+ }
2007
+ if (!findPath(path, query)) {
2008
+ onAbort?.({
2009
+ reason: "target-not-found",
2010
+ operation: "remove",
2011
+ pathOrID
2012
+ });
2013
+ return query;
2014
+ }
2015
+ const index = path.at(-1);
2016
+ const parent = findPath(getParentPath(path), query);
2017
+ if (!require_objectUtils.isRuleGroupType(parent) && parent.rules.length > 1) {
2018
+ const idxStartDelete = index === 0 ? 0 : index - 1;
2019
+ parent.rules.splice(idxStartDelete, 2);
2020
+ } else parent.rules.splice(index, 1);
2021
+ return query;
2022
+ };
2023
+ const getNextPath = (query, currentPath, newPathOrShiftDirection) => {
2024
+ if (Array.isArray(newPathOrShiftDirection)) return newPathOrShiftDirection;
2025
+ const ic = require_objectUtils.isRuleGroupTypeIC(query);
2026
+ if (newPathOrShiftDirection === "up") {
2027
+ if (pathsAreEqual(currentPath, [0])) return currentPath;
2028
+ else if (currentPath.at(-1) === 0) {
2029
+ const parentPath = getParentPath(currentPath);
2030
+ return [...getParentPath(parentPath), Math.max(0, parentPath.at(-1) - (ic ? 1 : 0))];
2031
+ } else {
2032
+ const evaluationPath = [...getParentPath(currentPath), Math.max(0, currentPath.at(-1) - (ic ? 2 : 1))];
2033
+ const entityAtTarget = findPath(evaluationPath, query);
2034
+ if (require_objectUtils.isRuleGroup(entityAtTarget)) return [...evaluationPath, entityAtTarget.rules.length];
2035
+ else return [...getParentPath(currentPath), Math.max(0, currentPath.at(-1) - (ic ? 3 : 1))];
2036
+ }
2037
+ } else if (newPathOrShiftDirection === "down") {
2038
+ if (pathsAreEqual([query.rules.length - 1], currentPath)) return currentPath;
2039
+ else if (currentPath.at(-1) === findPath(getParentPath(currentPath), query).rules.length - 1) {
2040
+ const parentPath = getParentPath(currentPath);
2041
+ return [...getParentPath(parentPath), parentPath.at(-1) + 1];
2042
+ } else {
2043
+ const evaluationPath = [...getParentPath(currentPath), currentPath.at(-1) + (ic ? 2 : 1)];
2044
+ const entityToEvaluate = findPath(evaluationPath, query);
2045
+ if (require_objectUtils.isRuleGroup(entityToEvaluate)) return [...evaluationPath, 0];
2046
+ else return [...getParentPath(currentPath), currentPath.at(-1) + (ic ? 3 : 2)];
2047
+ }
2048
+ }
2049
+ return currentPath;
2050
+ };
2051
+ /**
2052
+ * Moves a rule or group from one path to another without mutating the original query.
2053
+ * In the options parameter, pass `{ clone: true }` to copy instead of move.
2054
+ *
2055
+ * @returns A new query with the rule or group moved or cloned.
2056
+ *
2057
+ * @group Query Tools
2058
+ */
2059
+ const move = (query, oldPathOrID, newPath, options = {}) => producerFor(options.freeze)(query, (q) => moveInPlace(q, oldPathOrID, newPath, options));
2060
+ /**
2061
+ * Moves a rule or group from one path to another in place.
2062
+ * In the options parameter, pass `{ clone: true }` to copy instead of move.
2063
+ *
2064
+ * @returns The query (mutated in place) with the rule or group moved or cloned.
2065
+ *
2066
+ * @group Query Tools
2067
+ */
2068
+ const moveInPlace = (query, oldPathOrID, newPath, options = {}) => {
2069
+ const { clone = false, combinators = require_utils.defaultCombinators, idGenerator = require_prepareQueryObjects.generateID, onAbort } = options;
2070
+ const oldPath = Array.isArray(oldPathOrID) ? oldPathOrID : getPathOfID(oldPathOrID, query);
2071
+ if (!oldPath) {
2072
+ onAbort?.({
2073
+ reason: "target-not-found",
2074
+ operation: "move",
2075
+ pathOrID: oldPathOrID
2076
+ });
2077
+ return query;
2078
+ }
2079
+ const ruleOrGroupOriginal = findPath(oldPath, query);
2080
+ if (!ruleOrGroupOriginal) {
2081
+ onAbort?.({
2082
+ reason: "target-not-found",
2083
+ operation: "move",
2084
+ pathOrID: oldPathOrID
2085
+ });
2086
+ return query;
2087
+ }
2088
+ const nextPath = getNextPath(query, oldPath, newPath);
2089
+ if (oldPath.length === 0) {
2090
+ onAbort?.({
2091
+ reason: "root-not-allowed",
2092
+ operation: "move",
2093
+ pathOrID: oldPathOrID
2094
+ });
2095
+ return query;
2096
+ }
2097
+ const moveGuardReason = getGuardAbortReason(query, oldPath, options);
2098
+ if (moveGuardReason) {
2099
+ onAbort?.({
2100
+ reason: moveGuardReason,
2101
+ operation: "move",
2102
+ pathOrID: oldPathOrID
2103
+ });
2104
+ return query;
2105
+ }
2106
+ if (pathsAreEqual(oldPath, nextPath)) {
2107
+ onAbort?.({
2108
+ reason: "same-location",
2109
+ operation: "move",
2110
+ pathOrID: oldPathOrID
2111
+ });
2112
+ return query;
2113
+ }
2114
+ if (!findPath(getParentPath(nextPath), query)) {
2115
+ onAbort?.({
2116
+ reason: "destination-not-found",
2117
+ operation: "move",
2118
+ pathOrID: newPath
2119
+ });
2120
+ return query;
2121
+ }
2122
+ if (!clone && isAncestor(oldPath, nextPath)) {
2123
+ onAbort?.({
2124
+ reason: "destination-not-found",
2125
+ operation: "move",
2126
+ pathOrID: newPath
2127
+ });
2128
+ return query;
2129
+ }
2130
+ const ruleOrGroup = clone ? regenerateIDs((0, immer.isDraft)(ruleOrGroupOriginal) ? (0, immer.current)(ruleOrGroupOriginal) : ruleOrGroupOriginal, { idGenerator }) : ruleOrGroupOriginal;
2131
+ const independentCombinators = require_objectUtils.isRuleGroupTypeIC(query);
2132
+ const parentOfRuleToRemove = findPath(getParentPath(oldPath), query);
2133
+ const ruleToRemoveIndex = oldPath.at(-1);
2134
+ const oldPrevCombinator = independentCombinators && ruleToRemoveIndex > 0 ? parentOfRuleToRemove.rules[ruleToRemoveIndex - 1] : null;
2135
+ const oldNextCombinator = independentCombinators && ruleToRemoveIndex < parentOfRuleToRemove.rules.length - 1 ? parentOfRuleToRemove.rules[ruleToRemoveIndex + 1] : null;
2136
+ if (!clone) {
2137
+ const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
2138
+ const deleteLength = independentCombinators ? 2 : 1;
2139
+ parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
2140
+ }
2141
+ const newNewPath = [...nextPath];
2142
+ if (independentCombinators && newNewPath.at(-1) % 2 === 1) newNewPath[newNewPath.length - 1] += 1;
2143
+ const commonAncestorPath = getCommonAncestorPath(oldPath, nextPath);
2144
+ if (!clone && oldPath.length === commonAncestorPath.length + 1 && newNewPath[commonAncestorPath.length] > oldPath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
2145
+ const newNewParentPath = getParentPath(newNewPath);
2146
+ const parentToInsertInto = findPath(newNewParentPath, query);
2147
+ const newIndex = newNewPath.at(-1);
2148
+ const spliceIndex = independentCombinators && newIndex > 0 ? newIndex - 1 : newIndex;
2149
+ /**
2150
+ * This function 1) glosses over the need for type assertions to splice directly
2151
+ * into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
2152
+ */
2153
+ const insertRuleOrGroup = (...args) => parentToInsertInto.rules.splice(spliceIndex, 0, ...args);
2154
+ if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(ruleOrGroup);
2155
+ else if (newIndex === 0) {
2156
+ if (ruleToRemoveIndex === 0 && oldNextCombinator) insertRuleOrGroup(ruleOrGroup, oldNextCombinator);
2157
+ else insertRuleOrGroup(ruleOrGroup, parentToInsertInto.rules[1] ?? oldPrevCombinator ?? require_utils.getFirstOption(combinators));
2158
+ } else if (oldPrevCombinator) insertRuleOrGroup(oldPrevCombinator, ruleOrGroup);
2159
+ else insertRuleOrGroup(parentToInsertInto.rules[spliceIndex - 2] ?? oldNextCombinator ?? require_utils.getFirstOption(combinators), ruleOrGroup);
2160
+ return query;
2161
+ };
2162
+ /**
2163
+ * Inserts a rule or group into a query without mutating the original query.
2164
+ *
2165
+ * @returns A new query with the rule or group inserted.
2166
+ *
2167
+ * @group Query Tools
2168
+ */
2169
+ const insert = (query, ruleOrGroup, path, options = {}) => producerFor(options.freeze)(query, (q) => insertInPlace(q, ruleOrGroup, path, options));
2170
+ /**
2171
+ * Inserts a rule or group into a query in place.
2172
+ *
2173
+ * @returns The query (mutated in place) with the rule or group inserted.
2174
+ *
2175
+ * @group Query Tools
2176
+ */
2177
+ const insertInPlace = (query, ruleOrGroup, path, options = {}) => {
2178
+ const { combinators = require_utils.defaultCombinators, combinatorPreceding, combinatorSucceeding, idGenerator = require_prepareQueryObjects.generateID, replace = false, onAbort } = options;
2179
+ const parentToInsertInto = findPath(getParentPath(path), query);
2180
+ if (!parentToInsertInto) {
2181
+ onAbort?.({
2182
+ reason: "parent-not-found",
2183
+ operation: "insert",
2184
+ pathOrID: path
2185
+ });
2186
+ return query;
2187
+ }
2188
+ if (!require_objectUtils.isRuleGroup(parentToInsertInto)) {
2189
+ onAbort?.({
2190
+ reason: "parent-not-a-group",
2191
+ operation: "insert",
2192
+ pathOrID: path
2193
+ });
2194
+ return query;
2195
+ }
2196
+ const parentPath = getParentPath(path);
2197
+ const insertGuardReason = getGuardAbortReason(query, parentPath, options, { asParent: true });
2198
+ if (insertGuardReason) {
2199
+ onAbort?.({
2200
+ reason: insertGuardReason,
2201
+ operation: "insert",
2202
+ pathOrID: path
2203
+ });
2204
+ return query;
2205
+ }
2206
+ if (require_objectUtils.isRuleGroup(ruleOrGroup) && exceedsMaxLevels(parentPath, options)) {
2207
+ onAbort?.({
2208
+ reason: "max-levels-exceeded",
2209
+ operation: "insert",
2210
+ pathOrID: path
2211
+ });
2212
+ return query;
2213
+ }
2214
+ const rorg = regenerateIDs(ruleOrGroup, { idGenerator });
2215
+ const independentCombinators = require_objectUtils.isRuleGroupTypeIC(query);
2216
+ const newIndex = path.at(-1);
2217
+ /**
2218
+ * This function 1) glosses over the need for type assertions to splice directly
2219
+ * into `parentToInsertInto.rules`, and 2) shortens the actual insertion code.
2220
+ */
2221
+ const insertRuleOrGroup = (idx, ...args) => parentToInsertInto.rules.splice(idx, replace ? args.length : 0, ...args);
2222
+ if (parentToInsertInto.rules.length === 0 || !independentCombinators) insertRuleOrGroup(newIndex, rorg);
2223
+ else if (replace && independentCombinators) insertRuleOrGroup(newIndex + newIndex % 2, rorg);
2224
+ else if (newIndex === 0) {
2225
+ if (rorg.path?.at(-1) === 0 && combinatorSucceeding) insertRuleOrGroup(newIndex, rorg, combinatorSucceeding);
2226
+ else insertRuleOrGroup(newIndex, rorg, parentToInsertInto.rules[1] ?? combinatorPreceding ?? require_utils.getFirstOption(combinators));
2227
+ } else {
2228
+ const normalizedNewIndex = newIndex % 2 === 0 ? newIndex - 1 : newIndex;
2229
+ if (combinatorPreceding) insertRuleOrGroup(normalizedNewIndex, combinatorPreceding, rorg);
2230
+ else insertRuleOrGroup(normalizedNewIndex, parentToInsertInto.rules[normalizedNewIndex - 2] ?? combinatorSucceeding ?? require_utils.getFirstOption(combinators), rorg);
2231
+ }
2232
+ return query;
2233
+ };
2234
+ /**
2235
+ * Creates a new group at a target path with its `rules` array containing the current
2236
+ * objects at the target path and the source path without mutating the original query.
2237
+ * In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
2238
+ *
2239
+ * @returns A new query with the rules or groups grouped.
2240
+ *
2241
+ * @group Query Tools
2242
+ */
2243
+ const group = (query, sourcePathOrID, targetPathOrID, options = {}) => producerFor(options.freeze)(query, (q) => groupInPlace(q, sourcePathOrID, targetPathOrID, options));
2244
+ /**
2245
+ * Creates a new group at a target path with its `rules` array containing the current
2246
+ * objects at the target path and the source path in place.
2247
+ * In the options parameter, pass `{ clone: true }` to copy the source rule/group instead of move.
2248
+ *
2249
+ * @returns The query (mutated in place) with the rules or groups grouped.
2250
+ *
2251
+ * @group Query Tools
2252
+ */
2253
+ const groupInPlace = (query, sourcePathOrID, targetPathOrID, options = {}) => {
2254
+ const { clone = false, combinators = require_utils.defaultCombinators, idGenerator = require_prepareQueryObjects.generateID, onAbort } = options;
2255
+ const sourcePath = Array.isArray(sourcePathOrID) ? sourcePathOrID : getPathOfID(sourcePathOrID, query);
2256
+ const targetPath = Array.isArray(targetPathOrID) ? targetPathOrID : getPathOfID(targetPathOrID, query);
2257
+ if (!sourcePath) {
2258
+ onAbort?.({
2259
+ reason: "target-not-found",
2260
+ operation: "group",
2261
+ pathOrID: sourcePathOrID
2262
+ });
2263
+ return query;
2264
+ }
2265
+ if (!targetPath) {
2266
+ onAbort?.({
2267
+ reason: "target-not-found",
2268
+ operation: "group",
2269
+ pathOrID: targetPathOrID
2270
+ });
2271
+ return query;
2272
+ }
2273
+ const nextPath = getNextPath(query, sourcePath, targetPath);
2274
+ if (sourcePath.length === 0) {
2275
+ onAbort?.({
2276
+ reason: "root-not-allowed",
2277
+ operation: "group",
2278
+ pathOrID: sourcePathOrID
2279
+ });
2280
+ return query;
2281
+ }
2282
+ const groupGuardReason = getGuardAbortReason(query, sourcePath, options);
2283
+ if (groupGuardReason) {
2284
+ onAbort?.({
2285
+ reason: groupGuardReason,
2286
+ operation: "group",
2287
+ pathOrID: sourcePathOrID
2288
+ });
2289
+ return query;
2290
+ }
2291
+ if (pathsAreEqual(sourcePath, nextPath)) {
2292
+ onAbort?.({
2293
+ reason: "same-location",
2294
+ operation: "group",
2295
+ pathOrID: sourcePathOrID
2296
+ });
2297
+ return query;
2298
+ }
2299
+ if (!findPath(getParentPath(nextPath), query)) {
2300
+ onAbort?.({
2301
+ reason: "destination-not-found",
2302
+ operation: "group",
2303
+ pathOrID: targetPathOrID
2304
+ });
2305
+ return query;
2306
+ }
2307
+ if (!clone && isAncestor(sourcePath, nextPath)) {
2308
+ onAbort?.({
2309
+ reason: "destination-not-found",
2310
+ operation: "group",
2311
+ pathOrID: targetPathOrID
2312
+ });
2313
+ return query;
2314
+ }
2315
+ const sourceRuleOrGroupOriginal = findPath(sourcePath, query);
2316
+ const targetRuleOrGroup = findPath(targetPath, query);
2317
+ if (!sourceRuleOrGroupOriginal) {
2318
+ onAbort?.({
2319
+ reason: "target-not-found",
2320
+ operation: "group",
2321
+ pathOrID: sourcePathOrID
2322
+ });
2323
+ return query;
2324
+ }
2325
+ if (!targetRuleOrGroup) {
2326
+ onAbort?.({
2327
+ reason: "target-not-found",
2328
+ operation: "group",
2329
+ pathOrID: targetPathOrID
2330
+ });
2331
+ return query;
2332
+ }
2333
+ const sourceRuleOrGroup = clone ? regenerateIDs((0, immer.isDraft)(sourceRuleOrGroupOriginal) ? (0, immer.current)(sourceRuleOrGroupOriginal) : sourceRuleOrGroupOriginal, { idGenerator }) : sourceRuleOrGroupOriginal;
2334
+ const independentCombinators = require_objectUtils.isRuleGroupTypeIC(query);
2335
+ const parentOfRuleToRemove = findPath(getParentPath(sourcePath), query);
2336
+ const ruleToRemoveIndex = sourcePath.at(-1);
2337
+ if (!clone) {
2338
+ const idxStartDelete = independentCombinators ? Math.max(0, ruleToRemoveIndex - 1) : ruleToRemoveIndex;
2339
+ const deleteLength = independentCombinators ? 2 : 1;
2340
+ parentOfRuleToRemove.rules.splice(idxStartDelete, deleteLength);
2341
+ }
2342
+ const newNewPath = [...nextPath];
2343
+ const commonAncestorPath = getCommonAncestorPath(sourcePath, nextPath);
2344
+ if (!clone && sourcePath.length === commonAncestorPath.length + 1 && nextPath[commonAncestorPath.length] > sourcePath[commonAncestorPath.length]) newNewPath[commonAncestorPath.length] -= independentCombinators ? 2 : 1;
2345
+ const newNewParentPath = getParentPath(newNewPath);
2346
+ const parentOfTargetPath = findPath(newNewParentPath, query);
2347
+ const targetPathIndex = newNewPath.at(-1);
2348
+ parentOfTargetPath.rules.splice(targetPathIndex, 1, require_prepareQueryObjects.prepareRuleOrGroup(independentCombinators ? { rules: [
2349
+ targetRuleOrGroup,
2350
+ require_utils.getFirstOption(combinators),
2351
+ sourceRuleOrGroup
2352
+ ] } : {
2353
+ combinator: require_utils.getFirstOption(combinators),
2354
+ rules: [targetRuleOrGroup, sourceRuleOrGroup]
2355
+ }, { idGenerator }));
2356
+ return query;
2357
+ };
2358
+ //#endregion
2359
+ //#region src/utils/queryActions.ts
2360
+ /**
2361
+ * Builds the query builder's six mutation handlers as pure functions of the current query.
2362
+ *
2363
+ * This is the framework-agnostic core of the action handlers in `useQueryBuilderSchema`. It owns
2364
+ * the policy that surrounds the query tools—disabled gating, the confirmation callback protocol,
2365
+ * `maxLevels`, and debug logging—so an implementation only has to supply its own storage: read
2366
+ * the current query, call the action, and apply a non-`undefined` result.
2367
+ *
2368
+ * @group Query Tools
2369
+ */
2370
+ const createQueryActions = (config = {}) => {
2371
+ const { qbId, combinators, idGenerator, maxLevels = Infinity, queryDisabled, respectDisabled = true, disabledPaths, resetOnFieldChange, resetOnOperatorChange, getRuleDefaultOperator, getValueSources, getRuleDefaultValue, getMatchModes, freeze, onAddRule, onAddGroup, onRemove, onMoveRule, onMoveGroup, onGroupRule, onGroupGroup, onLog } = config;
2372
+ const log = (payload) => onLog?.({
2373
+ qbId,
2374
+ ...payload
2375
+ });
2376
+ const guards = {
2377
+ respectDisabled,
2378
+ queryDisabled,
2379
+ disabledPaths
2380
+ };
2381
+ /** Whether the mutation is blocked, using the same rules the query tools apply internally. */
2382
+ const blocked = (query, path, asParent = false) => !!getGuardAbortReason(query, path, guards, { asParent });
2383
+ return {
2384
+ addRule: (query, rule, parentPath, context) => {
2385
+ if (blocked(query, parentPath, true)) {
2386
+ log({
2387
+ type: require_utils.LogType.parentPathDisabled,
2388
+ rule,
2389
+ parentPath,
2390
+ query
2391
+ });
2392
+ return;
2393
+ }
2394
+ const nextRule = onAddRule ? onAddRule(rule, parentPath, query, context) : true;
2395
+ if (!nextRule) {
2396
+ log({
2397
+ type: require_utils.LogType.onAddRuleFalse,
2398
+ rule,
2399
+ parentPath,
2400
+ query
2401
+ });
2402
+ return;
2403
+ }
2404
+ const newRule = nextRule === true ? rule : nextRule;
2405
+ const newQuery = add(query, newRule, parentPath, {
2406
+ combinators,
2407
+ combinatorPreceding: newRule.combinatorPreceding,
2408
+ idGenerator,
2409
+ freeze
2410
+ });
2411
+ log({
2412
+ type: require_utils.LogType.add,
2413
+ query,
2414
+ newQuery,
2415
+ newRule,
2416
+ parentPath
2417
+ });
2418
+ return newQuery;
2419
+ },
2420
+ addGroup: (query, ruleGroup, parentPath, context) => {
2421
+ if (parentPath.length >= maxLevels) return void 0;
2422
+ if (blocked(query, parentPath, true)) {
2423
+ log({
2424
+ type: require_utils.LogType.parentPathDisabled,
2425
+ ruleGroup,
2426
+ parentPath,
2427
+ query
2428
+ });
2429
+ return;
2430
+ }
2431
+ const nextGroup = onAddGroup ? onAddGroup(ruleGroup, parentPath, query, context) : true;
2432
+ if (!nextGroup) {
2433
+ log({
2434
+ type: require_utils.LogType.onAddGroupFalse,
2435
+ ruleGroup,
2436
+ parentPath,
2437
+ query
2438
+ });
2439
+ return;
2440
+ }
2441
+ const newGroup = nextGroup === true ? ruleGroup : nextGroup;
2442
+ const newQuery = add(query, newGroup, parentPath, {
2443
+ combinators,
2444
+ combinatorPreceding: newGroup.combinatorPreceding ?? void 0,
2445
+ idGenerator,
2446
+ freeze
2447
+ });
2448
+ log({
2449
+ type: require_utils.LogType.add,
2450
+ query,
2451
+ newQuery,
2452
+ newGroup,
2453
+ parentPath
2454
+ });
2455
+ return newQuery;
2456
+ },
2457
+ propChange: (query, prop, value, path) => {
2458
+ if (getGuardAbortReason(query, path, prop === "disabled" ? { queryDisabled } : guards)) {
2459
+ log({
2460
+ type: require_utils.LogType.pathDisabled,
2461
+ path,
2462
+ prop,
2463
+ value,
2464
+ query
2465
+ });
2466
+ return;
2467
+ }
2468
+ const newQuery = update(query, prop, value, path, {
2469
+ resetOnFieldChange,
2470
+ resetOnOperatorChange,
2471
+ getRuleDefaultOperator,
2472
+ getValueSources,
2473
+ getRuleDefaultValue,
2474
+ getMatchModes,
2475
+ freeze
2476
+ });
2477
+ log({
2478
+ type: require_utils.LogType.update,
2479
+ query,
2480
+ newQuery,
2481
+ prop,
2482
+ value,
2483
+ path
2484
+ });
2485
+ return newQuery;
2486
+ },
2487
+ removeRuleOrGroup: (query, path, context) => {
2488
+ if (blocked(query, path)) {
2489
+ log({
2490
+ type: require_utils.LogType.pathDisabled,
2491
+ path,
2492
+ query
2493
+ });
2494
+ return;
2495
+ }
2496
+ const ruleOrGroup = findPath(path, query);
2497
+ /* v8 ignore next -- @preserve */
2498
+ if (!ruleOrGroup) return void 0;
2499
+ if (onRemove && !onRemove(ruleOrGroup, path, query, context)) {
2500
+ log({
2501
+ type: require_utils.LogType.onRemoveFalse,
2502
+ ruleOrGroup,
2503
+ path,
2504
+ query
2505
+ });
2506
+ return;
2507
+ }
2508
+ const newQuery = remove(query, path, { freeze });
2509
+ log({
2510
+ type: require_utils.LogType.remove,
2511
+ query,
2512
+ newQuery,
2513
+ path,
2514
+ ruleOrGroup
2515
+ });
2516
+ return newQuery;
2517
+ },
2518
+ moveRule: (query, oldPath, newPath, clone, context) => {
2519
+ if (blocked(query, oldPath)) {
2520
+ log({
2521
+ type: require_utils.LogType.pathDisabled,
2522
+ oldPath,
2523
+ newPath,
2524
+ query
2525
+ });
2526
+ return;
2527
+ }
2528
+ const ruleOrGroup = findPath(oldPath, query);
2529
+ if (!ruleOrGroup) return void 0;
2530
+ const nextQuery = move(query, oldPath, newPath, {
2531
+ clone,
2532
+ combinators,
2533
+ idGenerator,
2534
+ freeze
2535
+ });
2536
+ const isGroup = require_objectUtils.isRuleGroup(ruleOrGroup);
2537
+ const callback = isGroup ? onMoveGroup : onMoveRule;
2538
+ const callbackResult = callback ? callback(ruleOrGroup, oldPath, newPath, query, nextQuery, {
2539
+ clone,
2540
+ combinators
2541
+ }, context) : true;
2542
+ if (!callbackResult) {
2543
+ log({
2544
+ type: isGroup ? require_utils.LogType.onMoveGroupFalse : require_utils.LogType.onMoveRuleFalse,
2545
+ ruleOrGroup,
2546
+ oldPath,
2547
+ newPath,
2548
+ clone,
2549
+ query,
2550
+ nextQuery
2551
+ });
2552
+ return;
2553
+ }
2554
+ const newQuery = require_objectUtils.isRuleGroup(callbackResult) ? callbackResult : nextQuery;
2555
+ log({
2556
+ type: require_utils.LogType.move,
2557
+ query,
2558
+ newQuery,
2559
+ oldPath,
2560
+ newPath,
2561
+ clone
2562
+ });
2563
+ return newQuery;
2564
+ },
2565
+ groupRule: (query, sourcePath, targetPath, clone, context) => {
2566
+ if (blocked(query, sourcePath)) {
2567
+ log({
2568
+ type: require_utils.LogType.pathDisabled,
2569
+ sourcePath,
2570
+ targetPath,
2571
+ query
2572
+ });
2573
+ return;
2574
+ }
2575
+ const ruleOrGroup = findPath(sourcePath, query);
2576
+ if (!ruleOrGroup) return void 0;
2577
+ const nextQuery = group(query, sourcePath, targetPath, {
2578
+ clone,
2579
+ combinators,
2580
+ idGenerator,
2581
+ freeze
2582
+ });
2583
+ const isGroup = require_objectUtils.isRuleGroup(ruleOrGroup);
2584
+ const callback = isGroup ? onGroupGroup : onGroupRule;
2585
+ const callbackResult = callback ? callback(ruleOrGroup, sourcePath, targetPath, query, nextQuery, {
2586
+ clone,
2587
+ combinators
2588
+ }, context) : true;
2589
+ if (!callbackResult) {
2590
+ log({
2591
+ type: isGroup ? require_utils.LogType.onGroupGroupFalse : require_utils.LogType.onGroupRuleFalse,
2592
+ ruleOrGroup,
2593
+ sourcePath,
2594
+ targetPath,
2595
+ clone,
2596
+ query,
2597
+ nextQuery
2598
+ });
2599
+ return;
2600
+ }
2601
+ const newQuery = require_objectUtils.isRuleGroup(callbackResult) ? callbackResult : nextQuery;
2602
+ log({
2603
+ type: require_utils.LogType.group,
2604
+ query,
2605
+ newQuery,
2606
+ sourcePath,
2607
+ targetPath,
2608
+ clone
2609
+ });
2610
+ return newQuery;
2611
+ }
2612
+ };
2613
+ };
2614
+ //#endregion
2615
+ //#region src/utils/ruleFactory.ts
2616
+ /**
2617
+ * Creates a rule from the given configuration, applying the same precedence as the
2618
+ * `QueryBuilder` component. The `value` is computed in a second pass, once `field`, `operator`,
2619
+ * and `valueSource` are known, since the default value depends on all three.
2620
+ *
2621
+ * @group Query Tools
2622
+ */
2623
+ const createRule = ({ fields, getDefaultField, getRuleDefaultOperator, getValueSources, getMatchModes, getRuleDefaultValue, idGenerator = require_prepareQueryObjects.generateID }) => {
2624
+ let field = require_utils.getFirstOption(fields) ?? "";
2625
+ if (getDefaultField) {
2626
+ if (typeof getDefaultField === "function") {
2627
+ const defaultField = getDefaultField(fields);
2628
+ if (defaultField) field = defaultField;
2629
+ } else field = getDefaultField;
2630
+ }
2631
+ const fieldData = require_utils.getOption(fields, field);
2632
+ const operator = getRuleDefaultOperator(field);
2633
+ const valueSource = require_utils.getFirstOption(getValueSources(field, operator, { fieldData })) ?? "value";
2634
+ const matchMode = require_utils.getFirstOption(getMatchModes(field, { fieldData }));
2635
+ const newRule = {
2636
+ id: idGenerator(),
2637
+ field,
2638
+ operator,
2639
+ valueSource,
2640
+ value: "",
2641
+ ...matchMode ? { match: {
2642
+ mode: matchMode,
2643
+ threshold: 1
2644
+ } } : null
2645
+ };
2646
+ return {
2647
+ ...newRule,
2648
+ value: getRuleDefaultValue(newRule)
2649
+ };
2650
+ };
2651
+ /**
2652
+ * Creates a group from the given configuration. Pass `true` for `independentCombinators` to omit
2653
+ * the `combinator` property.
2654
+ *
2655
+ * The group's own `id` is generated _before_ any contained rule's, matching the order the
2656
+ * `QueryBuilder` component has always used. This is observable when `idGenerator` is
2657
+ * deterministic, as it often is in tests.
2658
+ *
2659
+ * @group Query Tools
2660
+ */
2661
+ const createRuleGroup = ({ combinators, addRuleToNewGroups, createRule: createRuleMain, idGenerator = require_prepareQueryObjects.generateID }, independentCombinators) => {
2662
+ const id = idGenerator();
2663
+ const rules = addRuleToNewGroups ? [createRuleMain()] : [];
2664
+ if (independentCombinators) return {
2665
+ id,
2666
+ rules,
2667
+ not: false
2668
+ };
2669
+ return {
2670
+ id,
2671
+ rules,
2672
+ combinator: require_utils.getFirstOption(combinators) ?? "",
2673
+ not: false
2674
+ };
2675
+ };
2676
+ //#endregion
2677
+ exports.LogType = require_utils.LogType;
2678
+ exports.TestID = require_utils.TestID;
2679
+ exports.add = add;
2680
+ exports.addInPlace = addInPlace;
2681
+ exports.betweenOperators = require_utils.betweenOperators;
2682
+ exports.clsx = clsx;
2683
+ exports.coerceBigIntValue = coerceBigIntValue;
2684
+ exports.coerceInputType = coerceInputType;
2685
+ exports.controlKeys = controlKeys;
2686
+ exports.controlKind = controlKind;
2687
+ exports.controlPropKeys = controlPropKeys;
2688
+ exports.convertFromIC = require_convertQuery.convertFromIC;
2689
+ exports.convertQuery = require_convertQuery.convertQuery;
2690
+ exports.convertToIC = require_convertQuery.convertToIC;
2691
+ exports.createQueryActions = createQueryActions;
2692
+ exports.createRule = createRule;
2693
+ exports.createRuleGroup = createRuleGroup;
2694
+ exports.defaultCoalesceMs = require_utils.defaultCoalesceMs;
2695
+ exports.defaultCombinatorLabelMap = require_utils.defaultCombinatorLabelMap;
2696
+ exports.defaultCombinators = require_utils.defaultCombinators;
2697
+ exports.defaultCombinatorsExtended = require_utils.defaultCombinatorsExtended;
2698
+ exports.defaultControlClassnames = require_utils.defaultControlClassnames;
2699
+ exports.defaultJoinChar = require_utils.defaultJoinChar;
2700
+ exports.defaultMatchModes = require_utils.defaultMatchModes;
2701
+ exports.defaultMaxHistory = require_utils.defaultMaxHistory;
2702
+ exports.defaultOperatorLabelMap = require_utils.defaultOperatorLabelMap;
2703
+ exports.defaultOperatorNegationMap = require_utils.defaultOperatorNegationMap;
2704
+ exports.defaultOperators = require_utils.defaultOperators;
2705
+ exports.defaultPlaceholderFieldGroupLabel = require_utils.defaultPlaceholderFieldGroupLabel;
2706
+ exports.defaultPlaceholderFieldLabel = require_utils.defaultPlaceholderFieldLabel;
2707
+ exports.defaultPlaceholderFieldName = require_utils.defaultPlaceholderFieldName;
2708
+ exports.defaultPlaceholderLabel = require_utils.defaultPlaceholderLabel;
2709
+ exports.defaultPlaceholderName = require_utils.defaultPlaceholderName;
2710
+ exports.defaultPlaceholderOperatorGroupLabel = require_utils.defaultPlaceholderOperatorGroupLabel;
2711
+ exports.defaultPlaceholderOperatorLabel = require_utils.defaultPlaceholderOperatorLabel;
2712
+ exports.defaultPlaceholderOperatorName = require_utils.defaultPlaceholderOperatorName;
2713
+ exports.defaultPlaceholderValueGroupLabel = require_utils.defaultPlaceholderValueGroupLabel;
2714
+ exports.defaultPlaceholderValueLabel = require_utils.defaultPlaceholderValueLabel;
2715
+ exports.defaultPlaceholderValueName = require_utils.defaultPlaceholderValueName;
2716
+ exports.defaultTranslations = require_utils.defaultTranslations;
2717
+ exports.defaultValidator = defaultValidator;
2718
+ exports.derivePathInfo = derivePathInfo;
2719
+ exports.deriveQueryBuilderClassNames = deriveQueryBuilderClassNames;
2720
+ exports.deriveRuleClassName = deriveRuleClassName;
2721
+ exports.deriveRuleClassNames = deriveRuleClassNames;
2722
+ exports.deriveRuleContext = deriveRuleContext;
2723
+ exports.deriveRuleGroupClassNames = deriveRuleGroupClassNames;
2724
+ exports.deriveRuleGroupContext = deriveRuleGroupContext;
2725
+ exports.deriveRuleGroupOuterClassName = deriveRuleGroupOuterClassName;
2726
+ exports.deriveRuleOuterClassName = deriveRuleOuterClassName;
2727
+ exports.exceedsMaxLevels = exceedsMaxLevels;
2728
+ exports.filterFieldsByComparator = require_prepareQueryObjects.filterFieldsByComparator;
2729
+ exports.findID = findID;
2730
+ exports.findPath = findPath;
2731
+ exports.generateAccessibleDescription = generateAccessibleDescription;
2732
+ Object.defineProperty(exports, "generateID", {
2733
+ enumerable: true,
2734
+ get: function() {
2735
+ return require_prepareQueryObjects.generateID;
2736
+ }
2737
+ });
2738
+ exports.getCommonAncestorPath = getCommonAncestorPath;
2739
+ exports.getFieldData = getFieldData;
2740
+ exports.getFirstOption = require_utils.getFirstOption;
2741
+ exports.getGuardAbortReason = getGuardAbortReason;
2742
+ exports.getMatchModesUtil = getMatchModesUtil;
2743
+ exports.getMultiValueUpdate = getMultiValueUpdate;
2744
+ exports.getOption = require_utils.getOption;
2745
+ exports.getParametersAsList = getParametersAsList;
2746
+ exports.getParentPath = getParentPath;
2747
+ exports.getParseNumberMethod = require_utils.getParseNumberMethod;
2748
+ exports.getPathOfID = getPathOfID;
2749
+ exports.getRuleDefaultValue = getRuleDefaultValue;
2750
+ exports.getRuleGroupCombinator = getRuleGroupCombinator;
2751
+ exports.getRuleInputType = getRuleInputType;
2752
+ exports.getRuleValidationResult = getRuleValidationResult;
2753
+ exports.getRuleValueEditorType = getRuleValueEditorType;
2754
+ exports.getRuleValueSourceOptions = getRuleValueSourceOptions;
2755
+ exports.getRuleValues = getRuleValues;
2756
+ exports.getValidationClassNames = getValidationClassNames;
2757
+ exports.getValueEditorReset = getValueEditorReset;
2758
+ exports.getValueSelectorUpdate = getValueSelectorUpdate;
2759
+ exports.getValueSourcesUtil = require_prepareQueryObjects.getValueSourcesUtil;
2760
+ exports.group = group;
2761
+ exports.groupInPlace = groupInPlace;
2762
+ exports.groupInvalidReasons = require_utils.groupInvalidReasons;
2763
+ exports.hideValueControlsForOperator = hideValueControlsForOperator;
2764
+ exports.inOperators = require_utils.inOperators;
2765
+ exports.insert = insert;
2766
+ exports.insertInPlace = insertInPlace;
2767
+ exports.isAncestor = isAncestor;
2768
+ exports.isBetweenOperator = isBetweenOperator;
2769
+ exports.isFlexibleOptionArray = require_utils.isFlexibleOptionArray;
2770
+ exports.isFlexibleOptionGroupArray = require_utils.isFlexibleOptionGroupArray;
2771
+ exports.isFullOptionArray = require_utils.isFullOptionArray;
2772
+ exports.isFullOptionGroupArray = require_utils.isFullOptionGroupArray;
2773
+ exports.isOptionGroupArray = require_utils.isOptionGroupArray;
2774
+ exports.isPojo = require_objectUtils.isPojo;
2775
+ exports.isRuleGroup = require_objectUtils.isRuleGroup;
2776
+ exports.isRuleGroupType = require_objectUtils.isRuleGroupType;
2777
+ exports.isRuleGroupTypeIC = require_objectUtils.isRuleGroupTypeIC;
2778
+ exports.isRuleOrGroupValid = require_isRuleOrGroupValid.isRuleOrGroupValid;
2779
+ exports.isRuleType = require_objectUtils.isRuleType;
2780
+ exports.isUnsafeKey = require_objectUtils.isUnsafeKey;
2781
+ exports.isValidationResult = require_isRuleOrGroupValid.isValidationResult;
2782
+ exports.joinWith = require_utils.joinWith;
2783
+ exports.lc = require_objectUtils.lc;
2784
+ exports.mergeAnyTranslation = mergeAnyTranslation;
2785
+ exports.mergeAnyTranslations = mergeAnyTranslations;
2786
+ exports.mergeClassnames = mergeClassnames;
2787
+ exports.move = move;
2788
+ exports.moveInPlace = moveInPlace;
2789
+ exports.normalizeValueSelectorValue = normalizeValueSelectorValue;
2790
+ exports.nullFreeArray = require_utils.nullFreeArray;
2791
+ exports.nullOperators = require_utils.nullOperators;
2792
+ exports.nullOrUndefinedOrEmpty = require_objectUtils.nullOrUndefinedOrEmpty;
2793
+ exports.numericRegex = require_objectUtils.numericRegex;
2794
+ exports.objectEntries = require_objectUtils.objectEntries;
2795
+ exports.objectKeys = require_objectUtils.objectKeys;
2796
+ exports.optionsEqual = optionsEqual;
2797
+ exports.parseNumber = require_utils.parseNumber;
2798
+ exports.pathIsDisabled = pathIsDisabled;
2799
+ exports.pathIsDisabledByPaths = pathIsDisabledByPaths;
2800
+ exports.pathsAreEqual = pathsAreEqual;
2801
+ exports.preferAnyProp = preferAnyProp;
2802
+ exports.preferFlagProps = preferFlagProps;
2803
+ exports.preferProp = preferProp;
2804
+ exports.prepareOptionList = require_utils.prepareOptionList;
2805
+ exports.prepareRule = require_prepareQueryObjects.prepareRule;
2806
+ exports.prepareRuleGroup = require_prepareQueryObjects.prepareRuleGroup;
2807
+ exports.prepareRuleOrGroup = require_prepareQueryObjects.prepareRuleOrGroup;
2808
+ exports.queryBuilderFlagDefaults = require_utils.queryBuilderFlagDefaults;
2809
+ exports.regenerateID = regenerateID;
2810
+ exports.regenerateIDs = regenerateIDs;
2811
+ exports.relationalOperators = require_utils.relationalOperators;
2812
+ exports.remove = remove;
2813
+ exports.removeInPlace = removeInPlace;
2814
+ exports.resolveCandidateQuery = require_prepareQueryObjects.resolveCandidateQuery;
2815
+ exports.resolveDefaultOperator = resolveDefaultOperator;
2816
+ exports.resolveOperatorList = resolveOperatorList;
2817
+ exports.resolveValueEditorType = resolveValueEditorType;
2818
+ exports.resolveValueList = resolveValueList;
2819
+ exports.rootPath = require_utils.rootPath;
2820
+ exports.setAutoFreeze = setAutoFreeze;
2821
+ exports.shouldCoalesce = shouldCoalesce;
2822
+ exports.signatureOf = signatureOf;
2823
+ exports.splitBy = require_utils.splitBy;
2824
+ exports.standardClassnames = require_utils.standardClassnames;
2825
+ exports.strictAbortReasons = strictAbortReasons;
2826
+ exports.structuralSignature = structuralSignature;
2827
+ exports.substringOperators = require_utils.substringOperators;
2828
+ exports.toArray = require_utils.toArray;
2829
+ exports.toFlatOptionArray = require_utils.toFlatOptionArray;
2830
+ exports.toFullOption = require_utils.toFullOption;
2831
+ exports.toFullOptionList = require_utils.toFullOptionList;
2832
+ exports.toFullOptionMap = require_utils.toFullOptionMap;
2833
+ exports.transformQuery = require_transformQuery.transformQuery;
2834
+ exports.trimIfString = require_utils.trimIfString;
2835
+ exports.unchangedSignature = unchangedSignature;
2836
+ exports.uniqByIdentifier = require_utils.uniqByIdentifier;
2837
+ exports.uniqByName = require_utils.uniqByName;
2838
+ exports.uniqOptGroups = require_utils.uniqOptGroups;
2839
+ exports.uniqOptList = require_utils.uniqOptList;
2840
+ exports.update = update;
2841
+ exports.updateInPlace = updateInPlace;
2842
+ exports.uuidV4regex = require_prepareQueryObjects.uuidV4regex;
2843
+ exports.valuesEqual = valuesEqual;
2844
+
2845
+ //# sourceMappingURL=derivations.js.map