@react-querybuilder/dnd
Version:
Drag-and-drop-enabled version of react-querybuilder
1,043 lines (1,032 loc) • 56.5 kB
JavaScript
// ../../utils/react-compiler/react-compiler-runtime.ts
import * as React from "react";
var $empty = Symbol["for"]("react.memo_cache_sentinel");
function c(size) {
return React.useMemo(
function() {
var $ = new Array(size);
for (var ii = 0; ii < size; ii++) {
$[ii] = $empty;
}
$[$empty] = true;
return $;
},
// oxlint-disable-next-line exhaustive-deps
[]
);
}
// src/InlineCombinatorDnD.tsx
import { jsx } from "react/jsx-runtime";
import { useContext, useRef } from "react";
import { getParentPath, isAncestor, pathsAreEqual, standardClassnames, TestID } from "react-querybuilder";
// src/isHotkeyPressed.ts
import { lc } from "react-querybuilder";
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var _n = 0, F = function F2() {
};
return { s: F, n: function n() {
return _n >= r.length ? { done: true } : { done: false, value: r[_n++] };
}, e: function e2(r2) {
throw r2;
}, f: F };
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o, a = true, u = false;
return { s: function s() {
t = t.call(r);
}, n: function n() {
var r2 = t.next();
return a = r2.done, r2;
}, e: function e2(r2) {
u = true, o = r2;
}, f: function f() {
try {
a || null == t["return"] || t["return"]();
} finally {
if (u) throw o;
}
} };
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
var reservedModifierKeywords = /* @__PURE__ */ new Set(["shift", "alt", "meta", "mod", "ctrl"]);
var mappedKeys = { esc: "escape", "return": "enter", ".": "period", ",": "comma", "-": "slash", " ": "space", "`": "backquote", "#": "backslash", "+": "bracketright", ShiftLeft: "shift", ShiftRight: "shift", AltLeft: "alt", AltRight: "alt", MetaLeft: "meta", MetaRight: "meta", OSLeft: "meta", OSRight: "meta", ControlLeft: "ctrl", ControlRight: "ctrl" };
var mapKey = function mapKey2(key) {
return lc((key && mappedKeys[key] || key || "").trim()).replace(/key|digit|numpad|arrow/, "");
};
var isHotkeyModifier = function isHotkeyModifier2(key) {
return reservedModifierKeywords.has(key);
};
var keyAliases = { "\u2318": "meta", cmd: "meta", command: "meta", "\u229E": "meta", win: "meta", windows: "meta", "\u21E7": "shift", "\u2325": "alt", "\u2303": "ctrl", control: "ctrl" };
(function() {
if (typeof document !== "undefined") {
document.addEventListener("keydown", function(e) {
if (e.key === void 0) {
return;
}
pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)]);
});
document.addEventListener("keyup", function(e) {
if (e.key === void 0) {
return;
}
removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)]);
});
}
if (typeof window !== "undefined") {
window.addEventListener("blur", function() {
currentlyPressedKeys.clear();
});
}
})();
var currentlyPressedKeys = /* @__PURE__ */ new Set();
var isReadonlyArray = function isReadonlyArray2(value) {
return Array.isArray(value);
};
var isHotkeyPressed = function isHotkeyPressed2(key) {
var splitKey = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ",";
return (isReadonlyArray(key) ? key : key.split(splitKey)).every(function(hotkey) {
var _keyAliases$hk;
var hk = lc(hotkey.trim());
return currentlyPressedKeys.has((_keyAliases$hk = keyAliases[hk]) !== null && _keyAliases$hk !== void 0 ? _keyAliases$hk : hk);
});
};
var pushToCurrentlyPressedKeys = function pushToCurrentlyPressedKeys2(key) {
var hotkeyArray = Array.isArray(key) ? key : [key];
if (currentlyPressedKeys.has("meta")) {
var _iterator = _createForOfIteratorHelper(currentlyPressedKeys), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var key2 = _step.value;
if (!isHotkeyModifier(key2)) {
currentlyPressedKeys["delete"](lc(key2));
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
var _iterator2 = _createForOfIteratorHelper(hotkeyArray), _step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
var hotkey = _step2.value;
currentlyPressedKeys.add(lc(hotkey));
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
};
var removeFromCurrentlyPressedKeys = function removeFromCurrentlyPressedKeys2(key) {
var hotkeyArray = Array.isArray(key) ? key : [key];
if (key === "meta") {
currentlyPressedKeys.clear();
} else {
var _iterator3 = _createForOfIteratorHelper(hotkeyArray), _step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done; ) {
var hotkey = _step3.value;
currentlyPressedKeys["delete"](lc(hotkey));
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
};
// src/QueryBuilderDndContext.ts
import { createContext } from "react";
import { defaultControlElements } from "react-querybuilder";
var rule = defaultControlElements.rule;
var ruleGroup = defaultControlElements.ruleGroup;
var combinatorSelector = defaultControlElements.combinatorSelector;
var QueryBuilderDndContext = /* @__PURE__ */ createContext({ baseControls: { rule, ruleGroup, combinatorSelector } });
// src/InlineCombinatorDnD.tsx
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof(o);
}
var _excluded = ["component"];
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray2(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray2(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray2(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray2(r, a) : void 0;
}
}
function _arrayLikeToArray2(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e, n, i, u, a = [], f = true, o = false;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = false;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
} catch (r2) {
o = true, n = r2;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function(r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
_defineProperty(e, r2, t[r2]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
});
}
return e;
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _objectWithoutProperties(e, t) {
if (null == e) return {};
var o, r, i = _objectWithoutPropertiesLoose(e, t);
if (Object.getOwnPropertySymbols) {
var n = Object.getOwnPropertySymbols(e);
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
}
return i;
}
function _objectWithoutPropertiesLoose(r, e) {
if (null == r) return {};
var t = {};
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
if (-1 !== e.indexOf(n)) continue;
t[n] = r[n];
}
return t;
}
var InlineCombinatorDnD = function InlineCombinatorDnD2(t0) {
var $ = c(20);
var CombinatorSelectorComponent;
var props;
if ($[0] !== t0) {
var _t = t0;
CombinatorSelectorComponent = _t.component;
props = _objectWithoutProperties(_t, _excluded);
_t;
$[0] = t0;
$[1] = CombinatorSelectorComponent;
$[2] = props;
} else {
CombinatorSelectorComponent = $[1];
props = $[2];
}
var _useContext = useContext(QueryBuilderDndContext), canDrop = _useContext.canDrop, useDrop = _useContext.useDrop, copyModeModifierKey = _useContext.copyModeModifierKey, groupModeModifierKey = _useContext.groupModeModifierKey;
var t1;
if ($[3] !== CombinatorSelectorComponent || $[4] !== canDrop || $[5] !== copyModeModifierKey || $[6] !== groupModeModifierKey || $[7] !== props || $[8] !== useDrop) {
t1 = _objectSpread(_objectSpread({}, props), {}, { component: CombinatorSelectorComponent, useDrop, canDrop, copyModeModifierKey, groupModeModifierKey });
$[3] = CombinatorSelectorComponent;
$[4] = canDrop;
$[5] = copyModeModifierKey;
$[6] = groupModeModifierKey;
$[7] = props;
$[8] = useDrop;
$[9] = t1;
} else {
t1 = $[9];
}
var _useInlineCombinatorD = useInlineCombinatorDnD(t1), dropRef = _useInlineCombinatorD.dropRef, dropMonitorId = _useInlineCombinatorD.dropMonitorId, isOver = _useInlineCombinatorD.isOver;
var t2 = props.schema.suppressStandardClassnames || standardClassnames.betweenRules;
var t3 = isOver && !props.schema.classNames.dndOver || false;
var t4 = isOver && !props.schema.suppressStandardClassnames && standardClassnames.dndOver || false;
var t5;
if ($[10] !== t2 || $[11] !== t3 || $[12] !== t4) {
t5 = [t2, t3, t4].filter(_temp);
$[10] = t2;
$[11] = t3;
$[12] = t4;
$[13] = t5;
} else {
t5 = $[13];
}
var wrapperClassName = t5.join(" ");
var t6;
if ($[14] !== CombinatorSelectorComponent || $[15] !== dropMonitorId || $[16] !== dropRef || $[17] !== props || $[18] !== wrapperClassName) {
t6 = jsx("div", { ref: dropRef, className: wrapperClassName, "data-dropmonitorid": dropMonitorId, "data-testid": TestID.inlineCombinator, children: jsx(CombinatorSelectorComponent, _objectSpread(_objectSpread({}, props), {}, { testID: TestID.combinators })) }, "dnd");
$[14] = CombinatorSelectorComponent;
$[15] = dropMonitorId;
$[16] = dropRef;
$[17] = props;
$[18] = wrapperClassName;
$[19] = t6;
} else {
t6 = $[19];
}
return t6;
};
var useInlineCombinatorDnD = function useInlineCombinatorDnD2(params) {
var dropRef = useRef(null);
var path = params.path, _canDrop = params.canDrop, schema = params.schema, useDrop = params.useDrop, rules = params.rules, _params$copyModeModif = params.copyModeModifierKey, copyModeModifierKey = _params$copyModeModif === void 0 ? "alt" : _params$copyModeModif, _params$groupModeModi = params.groupModeModifierKey, groupModeModifierKey = _params$groupModeModi === void 0 ? "ctrl" : _params$groupModeModi;
var hoveringItem = (rules !== null && rules !== void 0 ? rules : (
/* istanbul ignore next */
[]
))[path.at(-1) - 1];
var _useDrop = useDrop(function() {
return { accept: ["rule", "ruleGroup"], canDrop: function canDrop(dragging) {
var itemPath = dragging.path;
if (isHotkeyPressed(groupModeModifierKey) || dragging && typeof _canDrop === "function" && !_canDrop({ dragging, hovering: _objectSpread(_objectSpread({}, hoveringItem), {}, { path, qbId: schema.qbId }) })) {
return false;
}
var parentHoverPath = getParentPath(path);
var parentItemPath = getParentPath(itemPath);
var hoverIndex = path.at(-1);
var itemIndex = itemPath.at(-1);
return !// 1) the item is an ancestor of the drop target,
(isAncestor(itemPath, path) || // 2) the item is hovered over itself (which should never
// happen since combinators don't have drag handles),
pathsAreEqual(itemPath, path) || pathsAreEqual(parentHoverPath, parentItemPath) && hoverIndex - 1 === itemIndex || // 3) independentCombinators is true and the drop target is just above the hovering item
schema.independentCombinators && pathsAreEqual(parentHoverPath, parentItemPath) && hoverIndex === itemIndex - 1);
}, collect: function collect(monitor) {
var _monitor$getHandlerId;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_monitor$getHandlerId = monitor.getHandlerId()) !== null && _monitor$getHandlerId !== void 0 ? _monitor$getHandlerId : "", dropEffect: isHotkeyPressed(copyModeModifierKey) ? "copy" : "move", groupItems: isHotkeyPressed(groupModeModifierKey) };
}, drop: function drop2() {
var qbId = schema.qbId, getQuery = schema.getQuery, dispatchQuery = schema.dispatchQuery;
var dropEffect2 = isHotkeyPressed(copyModeModifierKey) ? "copy" : "move";
var groupItems = isHotkeyPressed(groupModeModifierKey);
return { type: "inlineCombinator", path, qbId, getQuery, dispatchQuery, groupItems, dropEffect: dropEffect2 };
} };
}, [_canDrop, hoveringItem, path, schema]), _useDrop2 = _slicedToArray(_useDrop, 2), _useDrop2$ = _useDrop2[0], isOver = _useDrop2$.isOver, dropMonitorId = _useDrop2$.dropMonitorId, dropEffect = _useDrop2$.dropEffect, drop = _useDrop2[1];
drop(dropRef);
return { dropRef, dropMonitorId, isOver, dropEffect };
};
function _temp(c2) {
return typeof c2 === "string";
}
// src/QueryBuilderDnD.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
import { useContext as useContext4, useEffect, useMemo as useMemo2, useState } from "react";
import { messages, QueryBuilderContext, useMergedContext, usePreferAnyProp, usePreferProp } from "react-querybuilder";
// src/isTouchDevice.ts
var isTouchDevice = function isTouchDevice2() {
return typeof window !== "undefined" && "ontouchstart" in window || typeof navigator !== "undefined" && navigator.maxTouchPoints > 0;
};
// src/RuleDnD.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
import { useContext as useContext2, useRef as useRef2 } from "react";
import { getParentPath as getParentPath3, isAncestor as isAncestor2, pathsAreEqual as pathsAreEqual2 } from "react-querybuilder";
// src/useDragCommon.ts
import { add, findPath, getParentPath as getParentPath2, group, insert } from "react-querybuilder";
function _typeof2(o) {
"@babel/helpers - typeof";
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof2(o);
}
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray3(r) || _nonIterableSpread();
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray3(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray3(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray3(r, a) : void 0;
}
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray3(r);
}
function _arrayLikeToArray3(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function ownKeys2(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function(r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys2(Object(t), true).forEach(function(r2) {
_defineProperty2(e, r2, t[r2]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys2(Object(t)).forEach(function(r2) {
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
});
}
return e;
}
function _defineProperty2(e, r, t) {
return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey2(t) {
var i = _toPrimitive2(t, "string");
return "symbol" == _typeof2(i) ? i : i + "";
}
function _toPrimitive2(t, r) {
if ("object" != _typeof2(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof2(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var useDragCommon = function useDragCommon2(_ref) {
var type = _ref.type, path = _ref.path, disabled = _ref.disabled, actions = _ref.actions, schema = _ref.schema, useDrag = _ref.useDrag, copyModeModifierKey = _ref.copyModeModifierKey, groupModeModifierKey = _ref.groupModeModifierKey;
return useDrag(function() {
return { type, item: function item() {
return _objectSpread2(_objectSpread2({}, findPath(path, schema.getQuery())), {}, { path, qbId: schema.qbId });
}, canDrag: !disabled, collect: function collect(monitor) {
var _monitor$getHandlerId;
return { isDragging: !disabled && monitor.isDragging(), dragMonitorId: (_monitor$getHandlerId = monitor.getHandlerId()) !== null && _monitor$getHandlerId !== void 0 ? _monitor$getHandlerId : "" };
}, end: function end(item, monitor_0) {
var dropResult = monitor_0.getDropResult();
if (!dropResult) return;
var dropEffect = isHotkeyPressed(copyModeModifierKey) ? "copy" : "move";
var groupItems = isHotkeyPressed(groupModeModifierKey);
var parentHoverPath = getParentPath2(dropResult.path);
var hoverIndex = dropResult.path.at(-1);
var destinationPath = groupItems ? dropResult.path : dropResult.type === "ruleGroup" ? [].concat(_toConsumableArray(dropResult.path), [0]) : dropResult.type === "inlineCombinator" ? [].concat(_toConsumableArray(parentHoverPath), [hoverIndex]) : [].concat(_toConsumableArray(parentHoverPath), [hoverIndex + 1]);
if (schema.qbId === dropResult.qbId) {
if (groupItems) {
actions.groupRule(item.path, destinationPath, dropEffect === "copy");
} else {
actions.moveRule(item.path, destinationPath, dropEffect === "copy");
}
} else {
var otherBuilderQuery = dropResult.getQuery();
if (otherBuilderQuery) {
if (groupItems) {
dropResult.dispatchQuery(group(add(otherBuilderQuery, item, []), [otherBuilderQuery.rules.length], destinationPath, { clone: false }));
} else {
dropResult.dispatchQuery(insert(otherBuilderQuery, item, destinationPath));
}
if (dropEffect !== "copy") {
actions.onRuleRemove(item.path);
}
}
}
} };
}, [actions.groupRule, actions.moveRule, disabled, path]);
};
// src/RuleDnD.tsx
function _typeof3(o) {
"@babel/helpers - typeof";
return _typeof3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof3(o);
}
function _slicedToArray2(r, e) {
return _arrayWithHoles2(r) || _iterableToArrayLimit2(r, e) || _unsupportedIterableToArray4(r, e) || _nonIterableRest2();
}
function _nonIterableRest2() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray4(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray4(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray4(r, a) : void 0;
}
}
function _arrayLikeToArray4(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _iterableToArrayLimit2(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e, n, i, u, a = [], f = true, o = false;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = false;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
} catch (r2) {
o = true, n = r2;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _arrayWithHoles2(r) {
if (Array.isArray(r)) return r;
}
function ownKeys3(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function(r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread3(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys3(Object(t), true).forEach(function(r2) {
_defineProperty3(e, r2, t[r2]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys3(Object(t)).forEach(function(r2) {
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
});
}
return e;
}
function _defineProperty3(e, r, t) {
return (r = _toPropertyKey3(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey3(t) {
var i = _toPrimitive3(t, "string");
return "symbol" == _typeof3(i) ? i : i + "";
}
function _toPrimitive3(t, r) {
if ("object" != _typeof3(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof3(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var RuleDnD = function RuleDnD2(props) {
var $ = c(13);
var rqbDndContext = useContext2(QueryBuilderDndContext);
var canDrop = rqbDndContext.canDrop, useDrag = rqbDndContext.useDrag, useDrop = rqbDndContext.useDrop, copyModeModifierKey = rqbDndContext.copyModeModifierKey, groupModeModifierKey = rqbDndContext.groupModeModifierKey;
var disabled = !!props.parentDisabled || !!props.disabled;
var t0;
if ($[0] !== canDrop || $[1] !== copyModeModifierKey || $[2] !== disabled || $[3] !== groupModeModifierKey || $[4] !== props || $[5] !== useDrag || $[6] !== useDrop) {
t0 = _objectSpread3(_objectSpread3({}, props), {}, { disabled, useDrag, useDrop, canDrop, copyModeModifierKey, groupModeModifierKey });
$[0] = canDrop;
$[1] = copyModeModifierKey;
$[2] = disabled;
$[3] = groupModeModifierKey;
$[4] = props;
$[5] = useDrag;
$[6] = useDrop;
$[7] = t0;
} else {
t0 = $[7];
}
var dndRefs = useRuleDnD(t0);
var BaseRuleComponent = rqbDndContext.baseControls.rule;
var t1;
if ($[8] !== BaseRuleComponent || $[9] !== dndRefs || $[10] !== props || $[11] !== rqbDndContext) {
t1 = jsx2(QueryBuilderDndContext.Provider, { value: rqbDndContext, children: jsx2(BaseRuleComponent, _objectSpread3(_objectSpread3({}, props), dndRefs)) });
$[8] = BaseRuleComponent;
$[9] = dndRefs;
$[10] = props;
$[11] = rqbDndContext;
$[12] = t1;
} else {
t1 = $[12];
}
return t1;
};
var accept = ["rule", "ruleGroup"];
var useRuleDnD = function useRuleDnD2(params) {
var dndRef = useRef2(null);
var dragRef = useRef2(null);
var path = params.path, rule2 = params.rule, disabled = params.disabled, schema = params.schema, actions = params.actions, useDrag = params.useDrag, useDrop = params.useDrop, _canDrop = params.canDrop, _params$copyModeModif = params.copyModeModifierKey, copyModeModifierKey = _params$copyModeModif === void 0 ? "alt" : _params$copyModeModif, _params$groupModeModi = params.groupModeModifierKey, groupModeModifierKey = _params$groupModeModi === void 0 ? "ctrl" : _params$groupModeModi;
var _useDragCommon = useDragCommon({ type: "rule", path, disabled, independentCombinators: schema.independentCombinators, schema, actions, useDrag, copyModeModifierKey, groupModeModifierKey }), _useDragCommon2 = _slicedToArray2(_useDragCommon, 3), _useDragCommon2$ = _useDragCommon2[0], isDragging = _useDragCommon2$.isDragging, dragMonitorId = _useDragCommon2$.dragMonitorId, drag = _useDragCommon2[1], preview = _useDragCommon2[2];
var _useDrop = useDrop(function() {
return { accept, canDrop: function canDrop(dragging) {
if (isHotkeyPressed(groupModeModifierKey) && disabled || dragging && typeof _canDrop === "function" && !_canDrop({ dragging, hovering: _objectSpread3(_objectSpread3({}, rule2), {}, { path, qbId: schema.qbId }) })) {
return false;
}
if (schema.qbId !== dragging.qbId) return true;
var parentHoverPath = getParentPath3(path);
var parentItemPath = getParentPath3(dragging.path);
var hoverIndex = path.at(-1);
var itemIndex = dragging.path.at(-1);
return !// 1) item is ancestor of drop target, OR
(isAncestor2(dragging.path, path) || // 2) item is hovered over itself, OR
pathsAreEqual2(path, dragging.path) || // 3) item is hovered over the previous item AND this is a move, not a group
!isHotkeyPressed(groupModeModifierKey) && pathsAreEqual2(parentHoverPath, parentItemPath) && (hoverIndex === itemIndex - 1 || schema.independentCombinators && hoverIndex === itemIndex - 2));
}, collect: function collect(monitor) {
var _monitor$getHandlerId;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_monitor$getHandlerId = monitor.getHandlerId()) !== null && _monitor$getHandlerId !== void 0 ? _monitor$getHandlerId : "", dropEffect: isHotkeyPressed(copyModeModifierKey) ? "copy" : "move", groupItems: isHotkeyPressed(groupModeModifierKey) };
}, drop: function drop2() {
var qbId = schema.qbId, getQuery = schema.getQuery, dispatchQuery = schema.dispatchQuery;
var dropEffect2 = isHotkeyPressed(copyModeModifierKey) ? "copy" : "move";
var groupItems2 = isHotkeyPressed(groupModeModifierKey);
return { type: "rule", path, qbId, getQuery, dispatchQuery, groupItems: groupItems2, dropEffect: dropEffect2 };
} };
}, [disabled, actions.moveRule, path, _canDrop, rule2, schema]), _useDrop2 = _slicedToArray2(_useDrop, 2), _useDrop2$ = _useDrop2[0], isOver = _useDrop2$.isOver, dropMonitorId = _useDrop2$.dropMonitorId, dropEffect = _useDrop2$.dropEffect, groupItems = _useDrop2$.groupItems, drop = _useDrop2[1];
drag(dragRef);
preview(drop(dndRef));
return { isDragging, dragMonitorId, isOver, dropMonitorId, dndRef, dragRef, dropEffect, groupItems };
};
// src/RuleGroupDnD.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
import { useContext as useContext3, useRef as useRef3 } from "react";
import { getParentPath as getParentPath4, isAncestor as isAncestor3, pathsAreEqual as pathsAreEqual3 } from "react-querybuilder";
function _typeof4(o) {
"@babel/helpers - typeof";
return _typeof4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof4(o);
}
function _slicedToArray3(r, e) {
return _arrayWithHoles3(r) || _iterableToArrayLimit3(r, e) || _unsupportedIterableToArray5(r, e) || _nonIterableRest3();
}
function _nonIterableRest3() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray5(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray5(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray5(r, a) : void 0;
}
}
function _arrayLikeToArray5(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _iterableToArrayLimit3(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e, n, i, u, a = [], f = true, o = false;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = false;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
} catch (r2) {
o = true, n = r2;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _arrayWithHoles3(r) {
if (Array.isArray(r)) return r;
}
function ownKeys4(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function(r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread4(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys4(Object(t), true).forEach(function(r2) {
_defineProperty4(e, r2, t[r2]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys4(Object(t)).forEach(function(r2) {
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
});
}
return e;
}
function _defineProperty4(e, r, t) {
return (r = _toPropertyKey4(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey4(t) {
var i = _toPrimitive4(t, "string");
return "symbol" == _typeof4(i) ? i : i + "";
}
function _toPrimitive4(t, r) {
if ("object" != _typeof4(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof4(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var RuleGroupDnD = function RuleGroupDnD2(props) {
var $ = c(12);
var rqbDndContext = useContext3(QueryBuilderDndContext);
var canDrop = rqbDndContext.canDrop, t0 = rqbDndContext.baseControls, useDrag = rqbDndContext.useDrag, useDrop = rqbDndContext.useDrop, copyModeModifierKey = rqbDndContext.copyModeModifierKey, groupModeModifierKey = rqbDndContext.groupModeModifierKey;
var BaseRuleGroupComponent = t0.ruleGroup;
var t1 = !!props.parentDisabled || !!props.disabled;
var t2;
if ($[0] !== canDrop || $[1] !== copyModeModifierKey || $[2] !== groupModeModifierKey || $[3] !== props || $[4] !== t1 || $[5] !== useDrag || $[6] !== useDrop) {
t2 = _objectSpread4(_objectSpread4({}, props), {}, { disabled: t1, useDrag, useDrop, canDrop, copyModeModifierKey, groupModeModifierKey });
$[0] = canDrop;
$[1] = copyModeModifierKey;
$[2] = groupModeModifierKey;
$[3] = props;
$[4] = t1;
$[5] = useDrag;
$[6] = useDrop;
$[7] = t2;
} else {
t2 = $[7];
}
var dndRefs = useRuleGroupDnD(t2);
var t3;
if ($[8] !== BaseRuleGroupComponent || $[9] !== dndRefs || $[10] !== props) {
t3 = jsx3(BaseRuleGroupComponent, _objectSpread4(_objectSpread4({}, props), dndRefs));
$[8] = BaseRuleGroupComponent;
$[9] = dndRefs;
$[10] = props;
$[11] = t3;
} else {
t3 = $[11];
}
return t3;
};
var accept2 = ["rule", "ruleGroup"];
var useRuleGroupDnD = function useRuleGroupDnD2(params) {
var previewRef = useRef3(null);
var dragRef = useRef3(null);
var dropRef = useRef3(null);
var disabled = params.disabled, path = params.path, ruleGroup2 = params.ruleGroup, schema = params.schema, actions = params.actions, useDrag = params.useDrag, useDrop = params.useDrop, _canDrop = params.canDrop, _params$copyModeModif = params.copyModeModifierKey, copyModeModifierKey = _params$copyModeModif === void 0 ? "alt" : _params$copyModeModif, _params$groupModeModi = params.groupModeModifierKey, groupModeModifierKey = _params$groupModeModi === void 0 ? "ctrl" : _params$groupModeModi;
var _useDragCommon = useDragCommon({ type: "ruleGroup", path, disabled, independentCombinators: schema.independentCombinators, schema, actions, useDrag, copyModeModifierKey, groupModeModifierKey }), _useDragCommon2 = _slicedToArray3(_useDragCommon, 3), _useDragCommon2$ = _useDragCommon2[0], isDragging = _useDragCommon2$.isDragging, dragMonitorId = _useDragCommon2$.dragMonitorId, drag = _useDragCommon2[1], preview = _useDragCommon2[2];
var _useDrop = useDrop(function() {
return { accept: accept2, canDrop: function canDrop(dragging) {
if (disabled || dragging && typeof _canDrop === "function" && !_canDrop({ dragging, hovering: _objectSpread4(_objectSpread4({}, ruleGroup2), {}, { path, qbId: schema.qbId }) })) {
return false;
}
if (schema.qbId !== dragging.qbId) return true;
var parentItemPath = getParentPath4(dragging.path);
var itemIndex = dragging.path.at(-1);
return !// 1) item is ancestor of drop target, OR
(isAncestor3(dragging.path, path) || // 2) item is first child and is dropped on its own group header, OR
pathsAreEqual3(path, parentItemPath) && itemIndex === 0 || // 3) the group is dropped on itself
pathsAreEqual3(path, dragging.path));
}, collect: function collect(monitor) {
var _monitor$getHandlerId;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_monitor$getHandlerId = monitor.getHandlerId()) !== null && _monitor$getHandlerId !== void 0 ? _monitor$getHandlerId : "", dropEffect: isHotkeyPressed(copyModeModifierKey) ? "copy" : "move", groupItems: isHotkeyPressed(groupModeModifierKey) };
}, drop: function drop2() {
var qbId = schema.qbId, getQuery = schema.getQuery, dispatchQuery = schema.dispatchQuery;
var dropEffect2 = isHotkeyPressed(copyModeModifierKey) ? "copy" : "move";
var groupItems2 = isHotkeyPressed(groupModeModifierKey);
return { type: "ruleGroup", path, qbId, getQuery, dispatchQuery, groupItems: groupItems2, dropEffect: dropEffect2 };
} };
}, [disabled, actions.groupRule, actions.moveRule, path, _canDrop, ruleGroup2, schema]), _useDrop2 = _slicedToArray3(_useDrop, 2), _useDrop2$ = _useDrop2[0], isOver = _useDrop2$.isOver, dropMonitorId = _useDrop2$.dropMonitorId, dropEffect = _useDrop2$.dropEffect, groupItems = _useDrop2$.groupItems, drop = _useDrop2[1];
if (path.length > 0) {
drag(dragRef);
preview(previewRef);
}
drop(dropRef);
return { isDragging, dragMonitorId, isOver, dropMonitorId, previewRef, dragRef, dropRef, dropEffect, groupItems };
};
// src/QueryBuilderDnD.tsx
function _typeof5(o) {
"@babel/helpers - typeof";
return _typeof5 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
return typeof o2;
} : function(o2) {
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
}, _typeof5(o);
}
function _regenerator() {
var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag";
function i(r2, n2, o2, i2) {
var c3 = n2 && n2.prototype instanceof Generator ? n2 : Generator, u2 = Object.create(c3.prototype);
return _regeneratorDefine2(u2, "_invoke", function(r3, n3, o3) {
var i3, c4, u3, f2 = 0, p = o3 || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d2(t2, r4) {
return i3 = t2, c4 = 0, u3 = e, G.n = r4, a;
} };
function d(r4, n4) {
for (c4 = r4, u3 = n4, t = 0; !y && f2 && !o4 && t < p.length; t++) {
var o4, i4 = p[t], d2 = G.p, l = i4[2];
r4 > 3 ? (o4 = l === n4) && (u3 = i4[(c4 = i4[4]) ? 5 : (c4 = 3, 3)], i4[4] = i4[5] = e) : i4[0] <= d2 && ((o4 = r4 < 2 && d2 < i4[1]) ? (c4 = 0, G.v = n4, G.n = i4[1]) : d2 < l && (o4 = r4 < 3 || i4[0] > n4 || n4 > l) && (i4[4] = r4, i4[5] = n4, G.n = l, c4 = 0));
}
if (o4 || r4 > 1) return a;
throw y = true, n4;
}
return function(o4, p2, l) {
if (f2 > 1) throw TypeError("Generator is already running");
for (y && 1 === p2 && d(p2, l), c4 = p2, u3 = l; (t = c4 < 2 ? e : u3) || !y; ) {
i3 || (c4 ? c4 < 3 ? (c4 > 1 && (G.n = -1), d(c4, u3)) : G.n = u3 : G.v = u3);
try {
if (f2 = 2, i3) {
if (c4 || (o4 = "next"), t = i3[o4]) {
if (!(t = t.call(i3, u3))) throw TypeError("iterator result is not an object");
if (!t.done) return t;
u3 = t.value, c4 < 2 && (c4 = 0);
} else 1 === c4 && (t = i3["return"]) && t.call(i3), c4 < 2 && (u3 = TypeError("The iterator does not provide a '" + o4 + "' method"), c4 = 1);
i3 = e;
} else if ((t = (y = G.n < 0) ? u3 : r3.call(n3, G)) !== a) break;
} catch (t2) {
i3 = e, c4 = 1, u3 = t2;
} finally {
f2 = 1;
}
}
return { value: t, done: y };
};
}(r2, o2, i2), true), u2;
}
var a = {};
function Generator() {
}
function GeneratorFunction() {
}
function GeneratorFunctionPrototype() {
}
t = Object.getPrototypeOf;
var c2 = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function() {
return this;
}), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c2);
function f(e2) {
return Object.setPrototypeOf ? Object.setPrototypeOf(e2, GeneratorFunctionPrototype) : (e2.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e2, o, "GeneratorFunction")), e2.prototype = Object.create(u), e2;
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function() {
return this;
}), _regeneratorDefine2(u, "toString", function() {
return "[object Generator]";
}), (_regenerator = function _regenerator2() {
return { w: i, m: f };
})();
}
function _regeneratorDefine2(e, r, n, t) {
var i = Object.defineProperty;
try {
i({}, "", {});
} catch (e2) {
i = 0;
}
_regeneratorDefine2 = function _regeneratorDefine(e2, r2, n2, t2) {
if (r2) i ? i(e2, r2, { value: n2, enumerable: !t2, configurable: !t2, writable: !t2 }) : e2[r2] = n2;
else {
var o = function o2(r3, n3) {
_regeneratorDefine2(e2, r3, function(e3) {
return this._invoke(r3, n3, e3);
});
};
o("next", 0), o("throw", 1), o("return", 2);
}
}, _regeneratorDefine2(e, r, n, t);
}
function asyncGeneratorStep(n, t, e, r, o, a, c2) {
try {
var i = n[a](c2), u = i.value;
} catch (n2) {
return void e(n2);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function() {
var t = this, e = arguments;
return new Promise(function(r, o) {
var a = n.apply(t, e);
function _next(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n2);
}
function _throw(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n2);
}
_next(void 0);
});
};
}
function _slicedToArray4(r, e) {
return _arrayWithHoles4(r) || _iterableToArrayLimit4(r, e) || _unsupportedIterableToArray6(r, e) || _nonIterableRest4();
}
function _nonIterableRest4() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray6(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray6(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray6(r, a) : void 0;
}
}
function _arrayLikeToArray6(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _iterableToArrayLimit4(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e, n, i, u, a = [], f = true, o = false;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = false;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
} catch (r2) {
o = true, n = r2;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _arrayWithHoles4(r) {
if (Array.isArray(r)) return r;
}
function ownKeys5(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function(r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread5(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys5(Object(t), true).forEach(function(r2) {
_defineProperty5(e, r2, t[r2]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys5(Object(t)).forEach(function(r2) {
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
});
}
return e;
}
function _defineProperty5(e, r, t) {
return (r = _toPropertyKey5(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey5(t) {
var i = _toPrimitive5(t, "string");
return "symbol" == _typeof5(i) ? i : i + "";
}
function _toPrimitive5(t, r) {
if ("object" != _typeof5(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof5(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var emptyObject = {};
var QueryBuilderDnD = function QueryBuilderDnD2(props) {
var controlClassnames = props.controlClassnames, controlElements = props.controlElements, debugMode = props.debugMode, enableDragAndDropProp = props.enableDragAndDrop, enableMountQueryChange = props.enableMountQueryChange, translations = props.translations, canDrop = props.canDrop, copyModeModifierKey = props.copyModeModifierKey, groupModeModifierKey = props.groupModeModifierKey;
var rqbContext = useMergedContext({ controlClassnames, controlElements, debugMode, enableDragAndDrop: enableDragAndDropProp !== null && enableDragAndDropProp !== void 0 ? enableDragAndDropProp : true, enableMountQueryChange, translations: translations !== null && translations !== void 0 ? translations : {} });
var enableDragAndDrop = rqbContext.enableDragAndDrop;
var dnd = useReactDnD(props.dnd);
var key = enableDragAndDrop && dnd ? "dnd" : "no-dnd";
var _ref = dnd !== null && dnd !== void 0 ? dnd : emptyObject, DndProvider = _ref.DndProvider, ReactDndBackend = _ref.ReactDndBackend;
var contextWithoutDnD = useMemo2(function() {
return _objectSpread5(_objectSpread5({}, rqbContext), {}, { enableDragAndDrop: false, debugMode });
}, [rqbContext, debugMode]);
var contextWithDnD = useMemo2(function() {
return _objectSpread5(_objectSpread5({}, rqbContext), {}, { enableDragAndDrop, debugMode });
}, [rqbContext, debugMode, enableDragAndDrop]);
if (!enableDragAndDrop || !dnd || !DndProvider || !ReactDndBackend) {
return /* @__PURE__ */ jsx4(QueryBuilderContext.Provider, { value: contextWithoutDnD, children: props.children }, key);
}
return /* @__PURE__ */ jsx4(DndProvider, { backend: ReactDndBackend, debugMode, children: /* @__PURE__ */ jsx4(QueryBuilderContext.Provider, { value: contextWithDnD, children: /* @__PURE__ */ jsx4(QueryBuilderDndWithoutProvider, { dnd, canDrop, copyModeModifierKey, groupModeModifierKey, children: props.children }) }, key) }, key);
};
var QueryBuilderDndWithoutProvider = function QueryBuilderDndWithoutProvider2(props) {
var _props$controlElement7, _props$controlElement8, _props$controlElement9, _rqbContext$controlEl4, _rqbContext$controlEl5, _rqbContext$controlEl6;
var rqbContext = useContext4(QueryBuilderContext);
var rqbDndContext = useContext4(QueryBuilderDndContext);
var dnd = useReactDnD(props.dnd);
var debugMode = usePreferProp(false, props.debugMode, rqbContext.debugMode);
var canDrop = usePreferAnyProp(void 0, props.canDrop, rqbDndContext.canDrop);
var copyModeModifierKey = usePreferAnyProp(void 0, props.copyModeModifierKey, rqbDndContext.copyModeModifierKey);
var groupModeModifierKey = usePreferAnyProp(void 0, props.groupModeModifierKey, rqbDndContext.groupModeModifierKey);
var enableDragAndDrop = usePreferProp(true, props.enableDragAndDrop, rqbContext.enableDragAndDrop);
var key = enableDragAndDrop && dnd ? "dnd" : "no-dnd";
var baseControls = useMemo2(function() {
var _ref2, _props$controlElement, _props$controlElement2, _rqbContext$controlEl, _ref3, _props$controlElement3, _props$controlElement4, _rqbContext$controlEl2, _ref4, _props$controlElement5, _props$controlElement6, _rqbContext$controlEl3;
return { rule: (_ref2 = (_props$controlElement = (_props$controlElement2 = props.controlElements) === null || _props$controlElement2 === void 0 ? void 0 : _props$controlElement2.rule) !== null && _props$controlElement !== void 0 ? _props$controlElement : (_rqbContext$controlEl = rqbContext.controlElements) === null || _rqbContext$controlEl === void 0 ? void 0 : _rqbContext$controlEl.rule) !== null && _ref2 !== void 0 ? _ref2 : rqbDndContext.baseControls.rule, ruleGroup: (_ref3 = (_props$controlElement3 = (_props$controlElement4 = props.controlElements) === null || _props$controlElement4 === void 0 ? void 0 : _props$controlElement4.ruleGroup) !== null && _props$controlElement3 !== void 0 ? _props$controlElement3 : (_rqbContext$controlEl2 = rqbContext.controlEleme