@react-querybuilder/dnd
Version:
Drag-and-drop-enabled version of react-querybuilder
1,092 lines (1,081 loc) • 63.3 kB
JavaScript
// 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
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 (key && mappedKeys[key] || key || "").trim().toLowerCase().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 _a;
var hk = hotkey.trim().toLowerCase();
return currentlyPressedKeys.has((_a = keyAliases[hk]) != null ? _a : 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"](key2.toLowerCase());
}
}
} 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(hotkey.toLowerCase());
}
} 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"](hotkey.toLowerCase());
}
} 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 _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 _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 _createForOfIteratorHelper2(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray2(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 _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;
}
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = function __defNormalProp2(obj, key, value) {
return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
};
var __spreadValues = function __spreadValues2(a, b) {
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols) {
var _iterator = _createForOfIteratorHelper2(__getOwnPropSymbols(b)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var prop = _step.value;
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return a;
};
var __spreadProps = function __spreadProps2(a, b) {
return __defProps(a, __getOwnPropDescs(b));
};
var __objRest = function __objRest2(source, exclude) {
var target = {};
for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
if (source != null && __getOwnPropSymbols) {
var _iterator2 = _createForOfIteratorHelper2(__getOwnPropSymbols(source)), _step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
var prop = _step2.value;
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
return target;
};
var InlineCombinatorDnD = function InlineCombinatorDnD2(_a) {
var _b = _a, CombinatorSelectorComponent = _b.component, props = __objRest(_b, ["component"]);
var _useContext = useContext(QueryBuilderDndContext), canDrop = _useContext.canDrop, useDrop = _useContext.useDrop, copyModeModifierKey = _useContext.copyModeModifierKey, groupModeModifierKey = _useContext.groupModeModifierKey;
var _useInlineCombinatorD = useInlineCombinatorDnD(__spreadProps(__spreadValues({}, props), { component: CombinatorSelectorComponent, useDrop, canDrop, copyModeModifierKey, groupModeModifierKey })), dropRef = _useInlineCombinatorD.dropRef, dropMonitorId = _useInlineCombinatorD.dropMonitorId, isOver = _useInlineCombinatorD.isOver;
var wrapperClassName = [props.schema.suppressStandardClassnames || standardClassnames.betweenRules, isOver && !props.schema.classNames.dndOver || false, isOver && !props.schema.suppressStandardClassnames && standardClassnames.dndOver || false].filter(function(c2) {
return typeof c2 === "string";
}).join(" ");
return /* @__PURE__ */ jsx("div", { ref: dropRef, className: wrapperClassName, "data-dropmonitorid": dropMonitorId, "data-testid": TestID.inlineCombinator, children: /* @__PURE__ */ jsx(CombinatorSelectorComponent, __spreadProps(__spreadValues({}, props), { testID: TestID.combinators })) }, "dnd");
};
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 : (
/* 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: __spreadProps(__spreadValues({}, 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 _a;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_a = monitor.getHandlerId()) != null ? _a : "", 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 };
};
// ../../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 $ = Array.from({ length: size });
for (var ii = 0; ii < size; ii++) {
$[ii] = $empty;
}
$[$empty] = true;
return $;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);
}
// 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/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 _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 _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 _createForOfIteratorHelper3(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray3(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 _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 _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;
}
var __defProp2 = Object.defineProperty;
var __defProps2 = Object.defineProperties;
var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
var __defNormalProp3 = function __defNormalProp4(obj, key, value) {
return key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
};
var __spreadValues3 = function __spreadValues4(a, b) {
for (var prop in b || (b = {})) if (__hasOwnProp2.call(b, prop)) __defNormalProp3(a, prop, b[prop]);
if (__getOwnPropSymbols2) {
var _iterator = _createForOfIteratorHelper3(__getOwnPropSymbols2(b)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var prop = _step.value;
if (__propIsEnum2.call(b, prop)) __defNormalProp3(a, prop, b[prop]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return a;
};
var __spreadProps3 = function __spreadProps4(a, b) {
return __defProps2(a, __getOwnPropDescs2(b));
};
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 __spreadProps3(__spreadValues3({}, findPath(path, schema.getQuery())), { path, qbId: schema.qbId });
}, canDrag: !disabled, collect: function collect(monitor) {
var _a;
return { isDragging: !disabled && monitor.isDragging(), dragMonitorId: (_a = monitor.getHandlerId()) != null ? _a : "" };
}, 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 _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 _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 _createForOfIteratorHelper4(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray4(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 _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;
}
var __defProp3 = Object.defineProperty;
var __defProps3 = Object.defineProperties;
var __getOwnPropDescs3 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols3 = Object.getOwnPropertySymbols;
var __hasOwnProp3 = Object.prototype.hasOwnProperty;
var __propIsEnum3 = Object.prototype.propertyIsEnumerable;
var __defNormalProp5 = function __defNormalProp6(obj, key, value) {
return key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
};
var __spreadValues5 = function __spreadValues6(a, b) {
for (var prop in b || (b = {})) if (__hasOwnProp3.call(b, prop)) __defNormalProp5(a, prop, b[prop]);
if (__getOwnPropSymbols3) {
var _iterator = _createForOfIteratorHelper4(__getOwnPropSymbols3(b)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var prop = _step.value;
if (__propIsEnum3.call(b, prop)) __defNormalProp5(a, prop, b[prop]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return a;
};
var __spreadProps5 = function __spreadProps6(a, b) {
return __defProps3(a, __getOwnPropDescs3(b));
};
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 = __spreadProps5(__spreadValues5({}, 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, __spreadValues5(__spreadValues5({}, 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: __spreadProps5(__spreadValues5({}, 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 _a;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_a = monitor.getHandlerId()) != null ? _a : "", 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 _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 _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 _createForOfIteratorHelper5(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray5(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 _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;
}
var __defProp4 = Object.defineProperty;
var __defProps4 = Object.defineProperties;
var __getOwnPropDescs4 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols4 = Object.getOwnPropertySymbols;
var __hasOwnProp4 = Object.prototype.hasOwnProperty;
var __propIsEnum4 = Object.prototype.propertyIsEnumerable;
var __defNormalProp7 = function __defNormalProp8(obj, key, value) {
return key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
};
var __spreadValues7 = function __spreadValues8(a, b) {
for (var prop in b || (b = {})) if (__hasOwnProp4.call(b, prop)) __defNormalProp7(a, prop, b[prop]);
if (__getOwnPropSymbols4) {
var _iterator = _createForOfIteratorHelper5(__getOwnPropSymbols4(b)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var prop = _step.value;
if (__propIsEnum4.call(b, prop)) __defNormalProp7(a, prop, b[prop]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return a;
};
var __spreadProps7 = function __spreadProps8(a, b) {
return __defProps4(a, __getOwnPropDescs4(b));
};
var RuleGroupDnD = function RuleGroupDnD2(props) {
var $ = c(11);
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;
if ($[0] !== canDrop || $[1] !== copyModeModifierKey || $[2] !== groupModeModifierKey || $[3] !== props || $[4] !== useDrag || $[5] !== useDrop) {
t1 = __spreadProps7(__spreadValues7({}, props), { disabled: !!props.parentDisabled || !!props.disabled, useDrag, useDrop, canDrop, copyModeModifierKey, groupModeModifierKey });
$[0] = canDrop;
$[1] = copyModeModifierKey;
$[2] = groupModeModifierKey;
$[3] = props;
$[4] = useDrag;
$[5] = useDrop;
$[6] = t1;
} else {
t1 = $[6];
}
var dndRefs = useRuleGroupDnD(t1);
var t2;
if ($[7] !== BaseRuleGroupComponent || $[8] !== dndRefs || $[9] !== props) {
t2 = jsx3(BaseRuleGroupComponent, __spreadValues7(__spreadValues7({}, props), dndRefs));
$[7] = BaseRuleGroupComponent;
$[8] = dndRefs;
$[9] = props;
$[10] = t2;
} else {
t2 = $[10];
}
return t2;
};
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: __spreadProps7(__spreadValues7({}, 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 _a;
return { isOver: monitor.canDrop() && monitor.isOver(), dropMonitorId: (_a = monitor.getHandlerId()) != null ? _a : "", 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/isTouchDevice.ts
var isTouchDevice = function isTouchDevice2() {
return typeof window !== "undefined" && "ontouchstart" in window || typeof navigator !== "undefined" && navigator.maxTouchPoints > 0;
};
// src/QueryBuilderDnD.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);
}
function _regeneratorRuntime() {
"use strict";
_regeneratorRuntime = function _regeneratorRuntime2() {
return e;
};
var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function(t2, e2, r2) {
t2[e2] = r2.value;
}, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c2 = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag";
function define(t2, e2, r2) {
return Object.defineProperty(t2, e2, { value: r2, enumerable: true, configurable: true, writable: true }), t2[e2];
}
try {
define({}, "");
} catch (t2) {
define = function define2(t3, e2, r2) {
return t3[e2] = r2;
};
}
function wrap(t2, e2, r2, n2) {
var i2 = e2 && e2.prototype instanceof Generator ? e2 : Generator, a2 = Object.create(i2.prototype), c3 = new Context(n2 || []);
return o(a2, "_invoke", { value: makeInvokeMethod(t2, r2, c3) }), a2;
}
function tryCatch(t2, e2, r2) {
try {
return { type: "normal", arg: t2.call(e2, r2) };
} catch (t3) {
return { type: "throw", arg: t3 };
}
}
e.wrap = wrap;
var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {};
function Generator() {
}
function GeneratorFunction() {
}
function GeneratorFunctionPrototype() {
}
var p = {};
define(p, a, function() {
return this;
});
var d = Object.getPrototypeOf, v = d && d(d(values([])));
v && v !== r && n.call(v, a) && (p = v);
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
function defineIteratorMethods(t2) {
["next", "throw", "return"].forEach(function(e2) {
define(t2, e2, function(t3) {
return this._invoke(e2, t3);
});
});
}
function AsyncIterator(t2, e2) {
function invoke(r3, o2, i2, a2) {
var c3 = tryCatch(t2[r3], t2, o2);
if ("throw" !== c3.type) {
var u2 = c3.arg, h2 = u2.value;
return h2 && "object" == _typeof(h2) && n.call(h2, "__await") ? e2.resolve(h2.__await).then(function(t3) {
invoke("next", t3, i2, a2);
}, function(t3) {
invoke("throw", t3, i2, a2);
}) : e2.resolve(h2).then(function(t3) {
u2.value = t3, i2(u2);
}, function(t3) {
return invoke("throw", t3, i2, a2);
});
}
a2(c3.arg);
}
var r2;
o(this, "_invoke", { value: function value(t3, n2) {
function callInvokeWithMethodAndArg() {
return new e2(function(e3, r3) {
invoke(t3, n2, e3, r3);
});
}
return r2 = r2 ? r2.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
} });
}
function makeInvokeMethod(e2, r2, n2) {
var o2 = h;
return function(i2, a2) {
if (o2 === f) throw Error("Generator is already running");
if (o2 === s) {
if ("throw" === i2) throw a2;
return { value: t, done: true };
}
for (n2.method = i2, n2.arg = a2; ; ) {
var c3 = n2.delegate;
if (c3) {
var u2 = maybeInvokeDelegate(c3, n2);
if (u2) {
if (u2 === y) continue;
return u2;
}
}
if ("next" === n2.method) n2.sent = n2._sent = n2.arg;
else if ("throw" === n2.method) {
if (o2 === h) throw o2 = s, n2.arg;
n2.dispatchException(n2.arg);
} else "return" === n2.method && n2.abrupt("return", n2.arg);
o2 = f;
var p2 = tryCatch(e2, r2, n2);
if ("normal" === p2.type) {
if (o2 = n2.done ? s : l, p2.arg === y) continue;
return { value: p2.arg, done: n2.done };
}
"throw" === p2.type && (o2 = s, n2.method = "throw", n2.arg = p2.arg);
}
};
}
function maybeInvokeDelegate(e2, r2) {
var n2 = r2.method, o2 = e2.iterator[n2];
if (o2 === t) return r2.delegate = null, "throw" === n2 && e2.iterator["return"] && (r2.method = "return", r2.arg = t, maybeInvokeDelegate(e2, r2), "throw" === r2.method) || "return" !== n2 && (r2.method = "throw", r2.arg = new TypeError("The iterator does not provide a '" + n2 + "' method")), y;
var i2 = tryCatch(o2, e2.iterator, r2.arg);
if ("throw" === i2.type) return r2.method = "throw", r2.arg = i2.arg, r2.delegate = null, y;
var a2 = i2.arg;
return a2 ? a2.done ? (r2[e2.resultName] = a2.value, r2.next = e2.nextLoc, "return" !== r2.method && (r2.method = "next", r2.arg = t), r2.delegate = null, y) : a2 : (r2.method = "throw", r2.arg = new TypeError("iterator result is not an object"), r2.delegate = null, y);
}
function pushTryEntry(t2) {
var e2 = { tryLoc: t2[0] };
1 in t2 && (e2.catchLoc = t2[1]), 2 in t2 && (e2.finallyLoc = t2[2], e2.afterLoc = t2[3]), this.tryEntries.push(e2);
}
function resetTryEntry(t2) {
var e2 = t2.completion || {};
e2.type = "normal", delete e2.arg, t2.completion = e2;
}
function Context(t2) {
this.tryEntries = [{ tryLoc: "root" }], t2.forEach(pushTryEntry, this), this.reset(true);
}
function values(e2) {
if (e2 || "" === e2) {
var r2 = e2[a];
if (r2) return r2.call(e2);
if ("function" == typeof e2.next) return e2;
if (!isNaN(e2.length)) {
var o2 = -1, i2 = function next() {
for (; ++o2 < e2.length; ) if (n.call(e2, o2)) return next.value = e2[o2], next.done = false, next;
return next.value = t, next.done = true, next;
};
return i2.next = i2;
}
}
throw new TypeError(_typeof(e2) + " is not iterable");
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: true }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: true }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function(t2) {
var e2 = "function" == typeof t2 && t2.constructor;
return !!e2 && (e2 === GeneratorFunction || "GeneratorFunction" === (e2.displayName || e2.name));
}, e.mark = function(t2) {
return Object.setPrototypeOf ? Object.setPrototypeOf(t2, GeneratorFunctionPrototype) : (t2.__proto__ = GeneratorFunctionPrototype, define(t2, u, "GeneratorFunction")), t2.prototype = Object.create(g), t2;
}, e.awrap = function(t2) {
return { __await: t2 };
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c2, function() {
return this;
}), e.AsyncIterator = AsyncIterator, e.async = function(t2, r2, n2, o2, i2) {
void 0 === i2 && (i2 = Promise);
var a2 = new AsyncIterator(wrap(t2, r2, n2, o2), i2);
return e.isGeneratorFunction(r2) ? a2 : a2.next().then(function(t3) {
return t3.done ? t3.value : a2.next();
});
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function() {
return this;
}), define(g, "toString", function() {
return "[object Generator]";
}), e.keys = function(t2) {
var e2 = Object(t2), r2 = [];
for (var n2 in e2) r2.push(n2);
return r2.reverse(), function next() {
for (; r2.length; ) {
var t3 = r2.pop();
if (t3 in e2) return next.value = t3, next.done = false, next;
}
return next.done = true, next;
};
}, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e2) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = false, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e2) for (var r2 in this) "t" === r2.charAt(0) && n.call(this, r2) && !isNaN(+r2.slice(1)) && (this[r2] = t);
}, stop: function stop() {
this.done = true;
var t2 = this.tryEntries[0].completion;
if ("throw" === t2.type) throw t2.arg;
return this.rval;
}, dispatchException: function dispatchException(e2) {
if (this.done) throw e2;
var r2 = this;
function handle(n2, o3) {
return a2.type = "throw", a2.arg = e2, r2.next = n2, o3 && (r2.method = "next", r2.arg = t), !!o3;
}
for (var o2 = this.tryEntries.length - 1; o2 >= 0; --o2) {
var i2 = this.tryEntries[o2], a2 = i2.completion;
if ("root" === i2.tryLoc) return handle("end");
if (i2.tryLoc <= this.prev) {
var c3 = n.call(i2, "catchLoc"), u2 = n.call(i2, "finallyLoc");
if (c3 && u2) {
if (this.prev < i2.catchLoc) return handle(i2.catchLoc, true);
if (this.prev < i2.finallyLoc) return handle(i2.finallyLoc);
} else if (c3) {
if (this.prev < i2.catchLoc) return handle(i2.catchLoc, true);
} else {
if (!u2) throw Error("try statement without catch or finally");
if (this.prev < i2.finallyLoc) return handle(i2.finallyLoc);
}
}
}
}, abrupt: function abrupt(t2, e2) {
for (var r2 = this.tryEntries.length - 1; r2 >= 0; --r2) {
var o2 = this.tryEntries[r2];
if (o2.tryLoc <= this.prev && n.call(o2, "finallyLoc") && this.prev < o2.finallyLoc) {
var i2 = o2;
break;
}
}
i2 && ("break" === t2 || "continue" === t2) && i2.tryLoc <= e2 && e2 <= i2.finallyLoc && (i2 = null);
var a2 = i2 ? i2.completion : {};
return a2.type = t2, a2.arg = e2, i2 ? (this.method = "next", this.next = i2.finallyLoc, y) : this.complete(a2);
}, complete: function complete(t2, e2) {
if ("throw" === t2.type) throw t2.arg;
return "break" === t2.type || "continue" === t2.type ? this.next = t2.arg : "return" === t2.type ? (this.rval = this.arg = t2.arg, this.method = "return", this.next = "end") : "normal" === t2.type && e2 && (this.next = e2), y;
}, finish: function finish(t2) {
for (var e2 = this.tryEntries.length - 1; e2 >= 0; --e2) {
var r2 = this.tryEntries[e2];
if (r2.finallyLoc === t2) return this.complete(r2.completion, r2.afterLoc), resetTryEntry(r2), y;
}
}, "catch": function _catch(t2) {
for (var e2 = this.tryEntries.length - 1; e2 >= 0; --e2) {
var r2 = this.tryEntries[e2];
if (r2.tryLoc === t2) {
var n2 = r2.completion;
if ("throw" === n2.type) {
var o2 = n2.arg;
resetTryEntry(r2);
}
return o2;
}
}
throw Error("illegal catch attempt");
}, delegateYield: function delegateYield(e2, r2, n2) {
return this.delegate = { iterator: values(e2), resultName: r2, nextLoc: n2 }, "next" === this.method && (this.arg = t), y;
} }, e;
}
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