@react-awesome-query-builder/core
Version:
User-friendly query builder for React. Core
33 lines • 1.65 kB
JavaScript
import _typeof from "@babel/runtime/helpers/typeof";
import Immutable, { Map } from "immutable";
import { getLightTree, _fixImmutableValue, fixPathsInTree, jsToImmutable } from "../utils/treeUtils";
import { isJsonLogic } from "../utils/stuff";
export { isJsonLogic, jsToImmutable };
export var getTree = function getTree(immutableTree) {
var light = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var children1AsArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (!immutableTree) return undefined;
var tree = immutableTree;
tree = tree.toJS();
tree = getLightTree(tree, light, children1AsArray);
return tree;
};
export var loadTree = function loadTree(serTree) {
if (isImmutableTree(serTree)) {
return serTree;
} else if (isTree(serTree)) {
return fixPathsInTree(jsToImmutable(serTree));
} else if (typeof serTree == "string" && serTree.startsWith('["~#iM"')) {
//tip: old versions of RAQB were saving tree with `transit.toJSON()`
// https://github.com/ukrbublik/react-awesome-query-builder/issues/69
throw new Error("You are trying to load query in obsolete serialization format (Immutable string) which is not supported in versions starting from 2.1.17");
} else if (typeof serTree === "string") {
return fixPathsInTree(jsToImmutable(JSON.parse(serTree)));
} else throw new Error("Can't load tree!");
};
export var isImmutableTree = function isImmutableTree(tree) {
return Map.isMap(tree);
};
export var isTree = function isTree(tree) {
return _typeof(tree) == "object" && (tree.type == "group" || tree.type == "switch_group");
};