@react-awesome-query-builder/core
Advanced tools
Comparing version 6.6.4-alpha.0 to 6.6.4
@@ -113,4 +113,3 @@ "use strict"; | ||
id: (0, _uuid["default"])(), | ||
// todo: use parentRuleGroupField in defaultGroupProperties (for default conj) | ||
properties: (0, _defaultUtils.defaultGroupProperties)(config).merge((0, _immutable.fromJS)(properties) || {}), | ||
properties: (0, _defaultUtils.defaultGroupProperties)(config, parentRuleGroupField).merge((0, _immutable.fromJS)(properties) || {}), | ||
config: config, | ||
@@ -117,0 +116,0 @@ meta: { |
@@ -39,2 +39,4 @@ "use strict"; | ||
groupOperators: ["some", "all", "none"], | ||
defaultConjunction: "AND", | ||
// todo: deprecated, remove this in favour of defaultConjunction | ||
defaultGroupConjunction: "AND", | ||
@@ -41,0 +43,0 @@ // localization |
@@ -112,3 +112,3 @@ "use strict"; | ||
var conjunctionDefinition = config.conjunctions[conjunction]; | ||
var conj = conjunctionDefinition.jsonLogicConj || conjunction.toLowerCase(); | ||
var conj = (conjunctionDefinition === null || conjunctionDefinition === void 0 ? void 0 : conjunctionDefinition.jsonLogicConj) || conjunction.toLowerCase(); | ||
var origNot = !!properties.get("not"); | ||
@@ -115,0 +115,0 @@ var isRuleGroup = type === "rule_group" && !isRoot; |
@@ -741,3 +741,3 @@ "use strict"; | ||
properties: { | ||
conjunction: (0, _defaultUtils.defaultConjunction)(config), | ||
conjunction: (0, _defaultUtils.defaultGroupConjunction)(config), | ||
not: not | ||
@@ -744,0 +744,0 @@ } |
@@ -1524,3 +1524,3 @@ "use strict"; | ||
properties: { | ||
conjunction: (0, _defaultUtils.defaultConjunction)(config), | ||
conjunction: (0, _defaultUtils.defaultGroupConjunction)(config), | ||
not: not || false | ||
@@ -1527,0 +1527,0 @@ } |
@@ -6,2 +6,3 @@ /* eslint-disable no-extra-semi */ | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
import moment from "moment"; | ||
import type { Moment as MomentType } from "moment"; | ||
@@ -177,6 +178,2 @@ import type { i18n } from "i18next"; | ||
export type TypedValueSourceMap<T> = { | ||
[key in ValueSource]: T; | ||
} | ||
interface ExtraActionProperties { | ||
@@ -560,2 +557,5 @@ // note: id can pre-generated for actions addRule, addGroup | ||
defaultRuleProperties(config: Config, parentRuleGroupField?: string, item?: JsonItem, canUseDefaultFieldAndOp?: boolean, canGetFirst?: boolean): ImmutableRuleProperties; | ||
/** | ||
* @deprecated Use defaultGroupConjunction() instead | ||
*/ | ||
defaultConjunction(config: Config): string; | ||
@@ -585,4 +585,5 @@ defaultOperatorOptions(config: Config, operator: string, field: Field): OperatorOptionsI | null; | ||
listValuesToArray(listValues: ListValues): ListItems; // normalize | ||
toListValue(value: string | number | ListItem, title?: string): ListItem; // create | ||
toListValue(value: string | number | ListItem, title?: string): ListItem | undefined; // create | ||
makeCustomListValue(value: string | number): ListItem; // create | ||
mapListValues<T>(listValues : ListValues, mapFn: (item: ListItem | undefined) => T | null) : T[]; | ||
} | ||
@@ -599,3 +600,3 @@ interface TreeUtils { | ||
fixPathsInTree(tree: ImmutableTree): ImmutableTree; | ||
getFlatTree(tree: ImmutableTree): FlatTree; | ||
getFlatTree(tree: ImmutableTree, config?: Config): FlatTree; | ||
getTotalReordableNodesCountInTree(tree: ImmutableTree): number; | ||
@@ -642,3 +643,3 @@ getTotalRulesCountInTree(tree: ImmutableTree): number; | ||
i18n: i18n; | ||
moment: Moment; | ||
moment: typeof moment; | ||
} | ||
@@ -1014,3 +1015,6 @@ | ||
selectedConjunction?: string; | ||
setConjunction(conj: string): void; | ||
setConjunction: { | ||
(conj: string): void; | ||
isDummyFn?: boolean; | ||
}; | ||
conjunctionOptions?: TypedMap<ConjunctionOption>; | ||
@@ -1266,3 +1270,2 @@ config?: Config; | ||
fieldSettings?: FS; | ||
maxNesting?: number; | ||
} | ||
@@ -1280,2 +1283,7 @@ interface FieldGroupExt<FS = NumberFieldSettings<number>> extends BaseField { | ||
conjunctions?: Array<string>; | ||
defaultConjunction?: string; | ||
maxNesting?: number; | ||
maxNumberOfRules?: number; | ||
canRegroup?: boolean; | ||
canReorder?: boolean; | ||
isSpelArray?: boolean; | ||
@@ -1376,2 +1384,3 @@ isSpelItemMap?: boolean; | ||
defaultOperator?: string; | ||
defaultConjunction?: string; | ||
fieldSources?: Array<FieldSource>; | ||
@@ -1378,0 +1387,0 @@ valueSourcesInfo?: ValueSourcesInfo; |
@@ -58,3 +58,3 @@ "use strict"; | ||
if (canAddNewRule) { | ||
state = addItem(state, groupPath, "rule", (0, _uuid["default"])(), (0, _defaultUtils.defaultRuleProperties)(config, meta.parentRuleGroupField), config); | ||
state = addItem(state, groupPath, "rule", (0, _uuid["default"])(), (0, _defaultUtils.defaultRuleProperties)(config, meta === null || meta === void 0 ? void 0 : meta.parentRuleGroupField), config); | ||
} | ||
@@ -218,10 +218,31 @@ } | ||
} else if (type === "group") { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} else if ((targetItem === null || targetItem === void 0 ? void 0 : targetItem.get("type")) === "rule_group") { | ||
// todo | ||
// don't restrict | ||
var ruleGroups = (0, _treeUtils.getAncestorRuleGroups)(state, path); | ||
if (ruleGroups.length) { | ||
// closest rule-group | ||
var _ruleGroups$ = ruleGroups[0], | ||
ruleGroupPath = _ruleGroups$.path, | ||
ruleGroupField = _ruleGroups$.field; | ||
var ruleGroupFieldConfig = (0, _configUtils.getFieldConfig)(config, ruleGroupField); | ||
currentNumber = path.size - ruleGroupPath.length; | ||
maxNumber = ruleGroupFieldConfig === null || ruleGroupFieldConfig === void 0 ? void 0 : ruleGroupFieldConfig.maxNesting; | ||
} else { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} | ||
} else { | ||
currentNumber = isTernary ? (0, _treeUtils.getTotalRulesCountInTree)(caseGroup) : (0, _treeUtils.getTotalRulesCountInTree)(state); | ||
maxNumber = maxNumberOfRules; | ||
// rule or rule_group | ||
var _ruleGroups = (0, _treeUtils.getAncestorRuleGroups)(state, path); | ||
if (_ruleGroups.length) { | ||
// closest rule-group | ||
var _ruleGroups$2 = _ruleGroups[0], | ||
_ruleGroupPath = _ruleGroups$2.path, | ||
_ruleGroupField = _ruleGroups$2.field; | ||
var _ruleGroupFieldConfig = (0, _configUtils.getFieldConfig)(config, _ruleGroupField); | ||
var ruleGroupItem = (0, _treeUtils.getItemByPath)(state, _ruleGroupPath); | ||
maxNumber = _ruleGroupFieldConfig === null || _ruleGroupFieldConfig === void 0 ? void 0 : _ruleGroupFieldConfig.maxNumberOfRules; | ||
currentNumber = (0, _treeUtils.getTotalRulesCountInTree)(ruleGroupItem); | ||
} else { | ||
currentNumber = isTernary ? (0, _treeUtils.getTotalRulesCountInTree)(caseGroup) : (0, _treeUtils.getTotalRulesCountInTree)(state); | ||
maxNumber = maxNumberOfRules; | ||
} | ||
} | ||
@@ -228,0 +249,0 @@ var canAdd = maxNumber && currentNumber ? currentNumber < maxNumber : true; |
@@ -124,10 +124,14 @@ "use strict"; | ||
var defaultGroupConjunction = exports.defaultGroupConjunction = function defaultGroupConjunction(config) { | ||
var _groupFieldConfig, _groupFieldConfig2; | ||
var groupFieldConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
groupFieldConfig = (0, _configUtils.getFieldConfig)(config, groupFieldConfig); // if `groupFieldConfig` is field name, not config | ||
var conjs = groupFieldConfig && groupFieldConfig.conjunctions || Object.keys(config.conjunctions); | ||
var conjs = ((_groupFieldConfig = groupFieldConfig) === null || _groupFieldConfig === void 0 ? void 0 : _groupFieldConfig.conjunctions) || Object.keys(config.conjunctions); | ||
if (conjs.length == 1) return conjs[0]; | ||
return config.settings.defaultGroupConjunction || config.settings.defaultConjunction || conjs[0]; | ||
// todo: config.settings.defaultGroupConjunction is deprecated, defaultConjunction should be used instead | ||
return ((_groupFieldConfig2 = groupFieldConfig) === null || _groupFieldConfig2 === void 0 ? void 0 : _groupFieldConfig2.defaultConjunction) || config.settings.defaultConjunction || config.settings.defaultGroupConjunction || conjs[0]; | ||
}; | ||
// @deprecated Use defaultGroupConjunction | ||
var defaultConjunction = exports.defaultConjunction = function defaultConjunction(config) { | ||
return config.settings.defaultConjunction || Object.keys(config.conjunctions)[0]; | ||
return defaultGroupConjunction(config); | ||
}; | ||
@@ -134,0 +138,0 @@ var defaultGroupProperties = exports.defaultGroupProperties = function defaultGroupProperties(config) { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}); | ||
exports.hasChildren = exports.getTotalRulesCountInTree = exports.getTotalReordableNodesCountInTree = exports.getSwitchValues = exports.getLightTree = exports.getItemByPath = exports.getFlatTree = exports.fixPathsInTree = exports.fixEmptyGroupsInTree = exports.expandTreeSubpath = exports.expandTreePath = exports._fixImmutableValue = void 0; | ||
exports.hasChildren = exports.getTotalRulesCountInTree = exports.getTotalReordableNodesCountInTree = exports.getSwitchValues = exports.getLightTree = exports.getItemByPath = exports.getFlatTree = exports.getAncestorRuleGroups = exports.fixPathsInTree = exports.fixEmptyGroupsInTree = exports.expandTreeSubpath = exports.expandTreePath = exports._fixImmutableValue = void 0; | ||
Object.defineProperty(exports, "immutableToJs", { | ||
@@ -39,2 +39,3 @@ enumerable: true, | ||
var _stuff = require("./stuff"); | ||
var _configUtils = require("./configUtils"); | ||
var _tree = require("../import/tree"); | ||
@@ -82,4 +83,4 @@ var _uuid = _interopRequireDefault(require("./uuid")); | ||
path.forEach(function (id) { | ||
var _res; | ||
res = children.get(id); | ||
var _children, _res; | ||
res = (_children = children) === null || _children === void 0 ? void 0 : _children.get(id); | ||
children = (_res = res) === null || _res === void 0 ? void 0 : _res.get("children1"); | ||
@@ -91,2 +92,32 @@ }); | ||
/** | ||
* @param {Immutable.Map} tree | ||
* @param {Immutable.List} path | ||
* @return {field, path}[] ordered by closest | ||
*/ | ||
var getAncestorRuleGroups = exports.getAncestorRuleGroups = function getAncestorRuleGroups(tree, path) { | ||
var parentRuleGroups = path.map(function (_id, i) { | ||
return path.take(i + 1); | ||
}).reverse().toJS().map(function (path) { | ||
return { | ||
item: getItemByPath(tree, path), | ||
path: path | ||
}; | ||
}).filter(function (_ref) { | ||
var item = _ref.item; | ||
return (item === null || item === void 0 ? void 0 : item.get("type")) === "rule_group"; | ||
}); | ||
if (parentRuleGroups.length) { | ||
return parentRuleGroups.map(function (_ref2) { | ||
var item = _ref2.item, | ||
path = _ref2.path; | ||
return { | ||
path: path, | ||
field: item.get("properties").get("field") | ||
}; | ||
}); | ||
} | ||
return []; | ||
}; | ||
/** | ||
* Remove `path` in every item | ||
@@ -204,3 +235,3 @@ * @param {Immutable.Map} tree | ||
*/ | ||
var getFlatTree = exports.getFlatTree = function getFlatTree(tree) { | ||
var getFlatTree = exports.getFlatTree = function getFlatTree(tree, config) { | ||
var flat = []; | ||
@@ -217,3 +248,4 @@ var items = {}; | ||
function _flatizeTree(item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, caseId, childNo) { | ||
function _flatizeTree(item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, atomicLev, caseId, childNo) { | ||
var _items$closestRuleGro, _items$closestRuleGro2, _items$closestRuleGro3; | ||
var isRoot = item === tree; | ||
@@ -236,2 +268,12 @@ var type = item.get("type"); | ||
var parentId = path.length ? path[path.length - 1] : null; | ||
var closestRuleGroupId = (0, _toConsumableArray2["default"])(path).reverse().find(function (id) { | ||
return items[id].type == "rule_group"; | ||
}); | ||
var field = item.getIn(["properties", "field"]); | ||
var fieldConfig = field && config && (0, _configUtils.getFieldConfig)(config, field); | ||
var canRegroup = fieldConfig ? (fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.canRegroup) !== false : undefined; | ||
var maxNesting = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.maxNesting; | ||
var closestRuleGroupCanRegroup = items === null || items === void 0 || (_items$closestRuleGro = items[closestRuleGroupId]) === null || _items$closestRuleGro === void 0 ? void 0 : _items$closestRuleGro.canRegroup; | ||
var closestRuleGroupMaxNesting = items === null || items === void 0 || (_items$closestRuleGro2 = items[closestRuleGroupId]) === null || _items$closestRuleGro2 === void 0 ? void 0 : _items$closestRuleGro2.maxNesting; | ||
var closestRuleGroupLev = items === null || items === void 0 || (_items$closestRuleGro3 = items[closestRuleGroupId]) === null || _items$closestRuleGro3 === void 0 ? void 0 : _items$closestRuleGro3.lev; | ||
var currentCaseId = isCaseGroup ? id : caseId; | ||
@@ -265,2 +307,3 @@ | ||
} | ||
var nextAtomicLev = insideRuleGroup || isRuleGroup ? atomicLev : atomicLev + 1; | ||
flat.push(id); | ||
@@ -274,3 +317,2 @@ items[id] = { | ||
parent: parentId, | ||
parentType: parentId ? items[parentId].type : null, | ||
children: childrenIds, | ||
@@ -280,5 +322,14 @@ childNo: childNo, | ||
caseNo: caseNo, | ||
closestRuleGroupId: closestRuleGroupId, | ||
closestRuleGroupLev: closestRuleGroupLev, | ||
closestRuleGroupMaxNesting: closestRuleGroupMaxNesting, | ||
closestRuleGroupCanRegroup: closestRuleGroupCanRegroup, | ||
maxNesting: maxNesting, | ||
canRegroup: canRegroup, | ||
path: path.concat(id), | ||
lev: lev, | ||
// depth level (0 for root node) | ||
atomicLev: atomicLev, | ||
// same as lev, but rules inside rule_group retains same number | ||
nextAtomicLev: nextAtomicLev, | ||
isLeaf: !children, | ||
@@ -299,2 +350,3 @@ // is atomic rule OR rule inside rule_group | ||
_top: itemsBefore, | ||
parentType: parentId ? items[parentId].type : null, | ||
// @deprecated use isLeaf instead | ||
@@ -340,3 +392,3 @@ leaf: !children | ||
if (child) { | ||
_flatizeTree(child, path.concat(id), insideCollapsed || collapsed, insideLocked || isLocked, insideRuleGroup || isRuleGroup, lev + 1, currentCaseId, childCount); | ||
_flatizeTree(child, path.concat(id), insideCollapsed || collapsed, insideLocked || isLocked, insideRuleGroup || isRuleGroup, lev + 1, nextAtomicLev, currentCaseId, childCount); | ||
var childItem = items[childId]; | ||
@@ -366,3 +418,3 @@ // Calculations after deep traversing 1 child | ||
// Start recursion | ||
_flatizeTree(tree, [], false, false, false, 0, null, null); | ||
_flatizeTree(tree, [], false, false, false, 0, 0, null, null); | ||
@@ -403,6 +455,6 @@ // Calc after recursion | ||
} | ||
var isRuleGroup = type == "rule_group"; | ||
cnt++; | ||
//tip: rules in rule-group can be reordered only inside | ||
if (children && !isRuleGroup) { | ||
if (type == "rule_group" && lev > 0) { | ||
//tip: rules in rule-group can be reordered only inside | ||
} else if (children) { | ||
children.map(function (child, _childId) { | ||
@@ -438,3 +490,3 @@ if (child) { | ||
} | ||
if (type == "rule" || type == "rule_group") { | ||
if (type == "rule" || type == "rule_group" && lev > 0) { | ||
// tip: count rule_group as 1 rule | ||
@@ -441,0 +493,0 @@ cnt++; |
@@ -104,4 +104,3 @@ import Immutable, { fromJS } from "immutable"; | ||
id: uuid(), | ||
// todo: use parentRuleGroupField in defaultGroupProperties (for default conj) | ||
properties: defaultGroupProperties(config).merge(fromJS(properties) || {}), | ||
properties: defaultGroupProperties(config, parentRuleGroupField).merge(fromJS(properties) || {}), | ||
config: config, | ||
@@ -108,0 +107,0 @@ meta: { |
@@ -33,2 +33,4 @@ export var settings = { | ||
groupOperators: ["some", "all", "none"], | ||
defaultConjunction: "AND", | ||
// todo: deprecated, remove this in favour of defaultConjunction | ||
defaultGroupConjunction: "AND", | ||
@@ -35,0 +37,0 @@ // localization |
@@ -106,3 +106,3 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
var conjunctionDefinition = config.conjunctions[conjunction]; | ||
var conj = conjunctionDefinition.jsonLogicConj || conjunction.toLowerCase(); | ||
var conj = (conjunctionDefinition === null || conjunctionDefinition === void 0 ? void 0 : conjunctionDefinition.jsonLogicConj) || conjunction.toLowerCase(); | ||
var origNot = !!properties.get("not"); | ||
@@ -109,0 +109,0 @@ var isRuleGroup = type === "rule_group" && !isRoot; |
@@ -16,3 +16,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { loadTree } from "./tree"; | ||
import { defaultConjunction, defaultGroupConjunction } from "../utils/defaultUtils"; | ||
import { defaultGroupConjunction } from "../utils/defaultUtils"; | ||
import moment from "moment"; | ||
@@ -736,3 +736,3 @@ | ||
properties: { | ||
conjunction: defaultConjunction(config), | ||
conjunction: defaultGroupConjunction(config), | ||
not: not | ||
@@ -739,0 +739,0 @@ } |
@@ -15,3 +15,3 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import { loadTree } from "./tree"; | ||
import { defaultConjunction, defaultGroupConjunction } from "../utils/defaultUtils"; | ||
import { defaultGroupConjunction } from "../utils/defaultUtils"; | ||
import { getOpCardinality, logger, isJsonCompatible } from "../utils/stuff"; | ||
@@ -1519,3 +1519,3 @@ import moment from "moment"; | ||
properties: { | ||
conjunction: defaultConjunction(config), | ||
conjunction: defaultGroupConjunction(config), | ||
not: not || false | ||
@@ -1522,0 +1522,0 @@ } |
@@ -6,2 +6,3 @@ /* eslint-disable no-extra-semi */ | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
import moment from "moment"; | ||
import type { Moment as MomentType } from "moment"; | ||
@@ -177,6 +178,2 @@ import type { i18n } from "i18next"; | ||
export type TypedValueSourceMap<T> = { | ||
[key in ValueSource]: T; | ||
} | ||
interface ExtraActionProperties { | ||
@@ -560,2 +557,5 @@ // note: id can pre-generated for actions addRule, addGroup | ||
defaultRuleProperties(config: Config, parentRuleGroupField?: string, item?: JsonItem, canUseDefaultFieldAndOp?: boolean, canGetFirst?: boolean): ImmutableRuleProperties; | ||
/** | ||
* @deprecated Use defaultGroupConjunction() instead | ||
*/ | ||
defaultConjunction(config: Config): string; | ||
@@ -585,4 +585,5 @@ defaultOperatorOptions(config: Config, operator: string, field: Field): OperatorOptionsI | null; | ||
listValuesToArray(listValues: ListValues): ListItems; // normalize | ||
toListValue(value: string | number | ListItem, title?: string): ListItem; // create | ||
toListValue(value: string | number | ListItem, title?: string): ListItem | undefined; // create | ||
makeCustomListValue(value: string | number): ListItem; // create | ||
mapListValues<T>(listValues : ListValues, mapFn: (item: ListItem | undefined) => T | null) : T[]; | ||
} | ||
@@ -599,3 +600,3 @@ interface TreeUtils { | ||
fixPathsInTree(tree: ImmutableTree): ImmutableTree; | ||
getFlatTree(tree: ImmutableTree): FlatTree; | ||
getFlatTree(tree: ImmutableTree, config?: Config): FlatTree; | ||
getTotalReordableNodesCountInTree(tree: ImmutableTree): number; | ||
@@ -642,3 +643,3 @@ getTotalRulesCountInTree(tree: ImmutableTree): number; | ||
i18n: i18n; | ||
moment: Moment; | ||
moment: typeof moment; | ||
} | ||
@@ -1014,3 +1015,6 @@ | ||
selectedConjunction?: string; | ||
setConjunction(conj: string): void; | ||
setConjunction: { | ||
(conj: string): void; | ||
isDummyFn?: boolean; | ||
}; | ||
conjunctionOptions?: TypedMap<ConjunctionOption>; | ||
@@ -1266,3 +1270,2 @@ config?: Config; | ||
fieldSettings?: FS; | ||
maxNesting?: number; | ||
} | ||
@@ -1280,2 +1283,7 @@ interface FieldGroupExt<FS = NumberFieldSettings<number>> extends BaseField { | ||
conjunctions?: Array<string>; | ||
defaultConjunction?: string; | ||
maxNesting?: number; | ||
maxNumberOfRules?: number; | ||
canRegroup?: boolean; | ||
canReorder?: boolean; | ||
isSpelArray?: boolean; | ||
@@ -1376,2 +1384,3 @@ isSpelItemMap?: boolean; | ||
defaultOperator?: string; | ||
defaultConjunction?: string; | ||
fieldSources?: Array<FieldSource>; | ||
@@ -1378,0 +1387,0 @@ valueSourcesInfo?: ValueSourcesInfo; |
@@ -9,3 +9,3 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import Immutable, { fromJS } from "immutable"; | ||
import { expandTreePath, expandTreeSubpath, getItemByPath, fixPathsInTree, getTotalRulesCountInTree, fixEmptyGroupsInTree, isEmptyTree, hasChildren, removeIsLockedInTree } from "../utils/treeUtils"; | ||
import { expandTreePath, expandTreeSubpath, getItemByPath, getAncestorRuleGroups, fixPathsInTree, getTotalRulesCountInTree, fixEmptyGroupsInTree, isEmptyTree, hasChildren, removeIsLockedInTree } from "../utils/treeUtils"; | ||
import { defaultRuleProperties, defaultGroupProperties, getDefaultOperator, defaultOperatorOptions, defaultItemProperties } from "../utils/defaultUtils"; | ||
@@ -50,3 +50,3 @@ import * as constants from "./constants"; | ||
if (canAddNewRule) { | ||
state = addItem(state, groupPath, "rule", uuid(), defaultRuleProperties(config, meta.parentRuleGroupField), config); | ||
state = addItem(state, groupPath, "rule", uuid(), defaultRuleProperties(config, meta === null || meta === void 0 ? void 0 : meta.parentRuleGroupField), config); | ||
} | ||
@@ -210,10 +210,31 @@ } | ||
} else if (type === "group") { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} else if ((targetItem === null || targetItem === void 0 ? void 0 : targetItem.get("type")) === "rule_group") { | ||
// todo | ||
// don't restrict | ||
var ruleGroups = getAncestorRuleGroups(state, path); | ||
if (ruleGroups.length) { | ||
// closest rule-group | ||
var _ruleGroups$ = ruleGroups[0], | ||
ruleGroupPath = _ruleGroups$.path, | ||
ruleGroupField = _ruleGroups$.field; | ||
var ruleGroupFieldConfig = getFieldConfig(config, ruleGroupField); | ||
currentNumber = path.size - ruleGroupPath.length; | ||
maxNumber = ruleGroupFieldConfig === null || ruleGroupFieldConfig === void 0 ? void 0 : ruleGroupFieldConfig.maxNesting; | ||
} else { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} | ||
} else { | ||
currentNumber = isTernary ? getTotalRulesCountInTree(caseGroup) : getTotalRulesCountInTree(state); | ||
maxNumber = maxNumberOfRules; | ||
// rule or rule_group | ||
var _ruleGroups = getAncestorRuleGroups(state, path); | ||
if (_ruleGroups.length) { | ||
// closest rule-group | ||
var _ruleGroups$2 = _ruleGroups[0], | ||
_ruleGroupPath = _ruleGroups$2.path, | ||
_ruleGroupField = _ruleGroups$2.field; | ||
var _ruleGroupFieldConfig = getFieldConfig(config, _ruleGroupField); | ||
var ruleGroupItem = getItemByPath(state, _ruleGroupPath); | ||
maxNumber = _ruleGroupFieldConfig === null || _ruleGroupFieldConfig === void 0 ? void 0 : _ruleGroupFieldConfig.maxNumberOfRules; | ||
currentNumber = getTotalRulesCountInTree(ruleGroupItem); | ||
} else { | ||
currentNumber = isTernary ? getTotalRulesCountInTree(caseGroup) : getTotalRulesCountInTree(state); | ||
maxNumber = maxNumberOfRules; | ||
} | ||
} | ||
@@ -220,0 +241,0 @@ var canAdd = maxNumber && currentNumber ? currentNumber < maxNumber : true; |
@@ -117,10 +117,14 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export var defaultGroupConjunction = function defaultGroupConjunction(config) { | ||
var _groupFieldConfig, _groupFieldConfig2; | ||
var groupFieldConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
groupFieldConfig = getFieldConfig(config, groupFieldConfig); // if `groupFieldConfig` is field name, not config | ||
var conjs = groupFieldConfig && groupFieldConfig.conjunctions || Object.keys(config.conjunctions); | ||
var conjs = ((_groupFieldConfig = groupFieldConfig) === null || _groupFieldConfig === void 0 ? void 0 : _groupFieldConfig.conjunctions) || Object.keys(config.conjunctions); | ||
if (conjs.length == 1) return conjs[0]; | ||
return config.settings.defaultGroupConjunction || config.settings.defaultConjunction || conjs[0]; | ||
// todo: config.settings.defaultGroupConjunction is deprecated, defaultConjunction should be used instead | ||
return ((_groupFieldConfig2 = groupFieldConfig) === null || _groupFieldConfig2 === void 0 ? void 0 : _groupFieldConfig2.defaultConjunction) || config.settings.defaultConjunction || config.settings.defaultGroupConjunction || conjs[0]; | ||
}; | ||
// @deprecated Use defaultGroupConjunction | ||
export var defaultConjunction = function defaultConjunction(config) { | ||
return config.settings.defaultConjunction || Object.keys(config.conjunctions)[0]; | ||
return defaultGroupConjunction(config); | ||
}; | ||
@@ -127,0 +131,0 @@ export var defaultGroupProperties = function defaultGroupProperties(config) { |
@@ -5,2 +5,3 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import { toImmutableList, isImmutable, applyToJS as immutableToJs } from "./stuff"; | ||
import { getFieldConfig } from "./configUtils"; | ||
import { jsToImmutable } from "../import/tree"; | ||
@@ -50,4 +51,4 @@ import uuid from "./uuid"; | ||
path.forEach(function (id) { | ||
var _res; | ||
res = children.get(id); | ||
var _children, _res; | ||
res = (_children = children) === null || _children === void 0 ? void 0 : _children.get(id); | ||
children = (_res = res) === null || _res === void 0 ? void 0 : _res.get("children1"); | ||
@@ -59,2 +60,32 @@ }); | ||
/** | ||
* @param {Immutable.Map} tree | ||
* @param {Immutable.List} path | ||
* @return {field, path}[] ordered by closest | ||
*/ | ||
export var getAncestorRuleGroups = function getAncestorRuleGroups(tree, path) { | ||
var parentRuleGroups = path.map(function (_id, i) { | ||
return path.take(i + 1); | ||
}).reverse().toJS().map(function (path) { | ||
return { | ||
item: getItemByPath(tree, path), | ||
path: path | ||
}; | ||
}).filter(function (_ref) { | ||
var item = _ref.item; | ||
return (item === null || item === void 0 ? void 0 : item.get("type")) === "rule_group"; | ||
}); | ||
if (parentRuleGroups.length) { | ||
return parentRuleGroups.map(function (_ref2) { | ||
var item = _ref2.item, | ||
path = _ref2.path; | ||
return { | ||
path: path, | ||
field: item.get("properties").get("field") | ||
}; | ||
}); | ||
} | ||
return []; | ||
}; | ||
/** | ||
* Remove `path` in every item | ||
@@ -172,3 +203,3 @@ * @param {Immutable.Map} tree | ||
*/ | ||
export var getFlatTree = function getFlatTree(tree) { | ||
export var getFlatTree = function getFlatTree(tree, config) { | ||
var flat = []; | ||
@@ -185,3 +216,4 @@ var items = {}; | ||
function _flatizeTree(item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, caseId, childNo) { | ||
function _flatizeTree(item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, atomicLev, caseId, childNo) { | ||
var _items$closestRuleGro, _items$closestRuleGro2, _items$closestRuleGro3; | ||
var isRoot = item === tree; | ||
@@ -204,2 +236,12 @@ var type = item.get("type"); | ||
var parentId = path.length ? path[path.length - 1] : null; | ||
var closestRuleGroupId = _toConsumableArray(path).reverse().find(function (id) { | ||
return items[id].type == "rule_group"; | ||
}); | ||
var field = item.getIn(["properties", "field"]); | ||
var fieldConfig = field && config && getFieldConfig(config, field); | ||
var canRegroup = fieldConfig ? (fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.canRegroup) !== false : undefined; | ||
var maxNesting = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.maxNesting; | ||
var closestRuleGroupCanRegroup = items === null || items === void 0 || (_items$closestRuleGro = items[closestRuleGroupId]) === null || _items$closestRuleGro === void 0 ? void 0 : _items$closestRuleGro.canRegroup; | ||
var closestRuleGroupMaxNesting = items === null || items === void 0 || (_items$closestRuleGro2 = items[closestRuleGroupId]) === null || _items$closestRuleGro2 === void 0 ? void 0 : _items$closestRuleGro2.maxNesting; | ||
var closestRuleGroupLev = items === null || items === void 0 || (_items$closestRuleGro3 = items[closestRuleGroupId]) === null || _items$closestRuleGro3 === void 0 ? void 0 : _items$closestRuleGro3.lev; | ||
var currentCaseId = isCaseGroup ? id : caseId; | ||
@@ -233,2 +275,3 @@ | ||
} | ||
var nextAtomicLev = insideRuleGroup || isRuleGroup ? atomicLev : atomicLev + 1; | ||
flat.push(id); | ||
@@ -242,3 +285,2 @@ items[id] = { | ||
parent: parentId, | ||
parentType: parentId ? items[parentId].type : null, | ||
children: childrenIds, | ||
@@ -248,5 +290,14 @@ childNo: childNo, | ||
caseNo: caseNo, | ||
closestRuleGroupId: closestRuleGroupId, | ||
closestRuleGroupLev: closestRuleGroupLev, | ||
closestRuleGroupMaxNesting: closestRuleGroupMaxNesting, | ||
closestRuleGroupCanRegroup: closestRuleGroupCanRegroup, | ||
maxNesting: maxNesting, | ||
canRegroup: canRegroup, | ||
path: path.concat(id), | ||
lev: lev, | ||
// depth level (0 for root node) | ||
atomicLev: atomicLev, | ||
// same as lev, but rules inside rule_group retains same number | ||
nextAtomicLev: nextAtomicLev, | ||
isLeaf: !children, | ||
@@ -267,2 +318,3 @@ // is atomic rule OR rule inside rule_group | ||
_top: itemsBefore, | ||
parentType: parentId ? items[parentId].type : null, | ||
// @deprecated use isLeaf instead | ||
@@ -308,3 +360,3 @@ leaf: !children | ||
if (child) { | ||
_flatizeTree(child, path.concat(id), insideCollapsed || collapsed, insideLocked || isLocked, insideRuleGroup || isRuleGroup, lev + 1, currentCaseId, childCount); | ||
_flatizeTree(child, path.concat(id), insideCollapsed || collapsed, insideLocked || isLocked, insideRuleGroup || isRuleGroup, lev + 1, nextAtomicLev, currentCaseId, childCount); | ||
var childItem = items[childId]; | ||
@@ -334,3 +386,3 @@ // Calculations after deep traversing 1 child | ||
// Start recursion | ||
_flatizeTree(tree, [], false, false, false, 0, null, null); | ||
_flatizeTree(tree, [], false, false, false, 0, 0, null, null); | ||
@@ -371,6 +423,6 @@ // Calc after recursion | ||
} | ||
var isRuleGroup = type == "rule_group"; | ||
cnt++; | ||
//tip: rules in rule-group can be reordered only inside | ||
if (children && !isRuleGroup) { | ||
if (type == "rule_group" && lev > 0) { | ||
//tip: rules in rule-group can be reordered only inside | ||
} else if (children) { | ||
children.map(function (child, _childId) { | ||
@@ -406,3 +458,3 @@ if (child) { | ||
} | ||
if (type == "rule" || type == "rule_group") { | ||
if (type == "rule" || type == "rule_group" && lev > 0) { | ||
// tip: count rule_group as 1 rule | ||
@@ -409,0 +461,0 @@ cnt++; |
@@ -87,4 +87,3 @@ import Immutable, {fromJS} from "immutable"; | ||
id: uuid(), | ||
// todo: use parentRuleGroupField in defaultGroupProperties (for default conj) | ||
properties: defaultGroupProperties(config).merge(fromJS(properties) || {}), | ||
properties: defaultGroupProperties(config, parentRuleGroupField).merge(fromJS(properties) || {}), | ||
config: config, | ||
@@ -91,0 +90,0 @@ meta: { |
@@ -36,2 +36,4 @@ export const settings = { | ||
defaultConjunction: "AND", | ||
// todo: deprecated, remove this in favour of defaultConjunction | ||
defaultGroupConjunction: "AND", | ||
@@ -38,0 +40,0 @@ |
@@ -94,3 +94,3 @@ import {getOpCardinality, widgetDefKeysToOmit, opDefKeysToOmit, omit} from "../utils/stuff"; | ||
const conjunctionDefinition = config.conjunctions[conjunction]; | ||
const conj = conjunctionDefinition.jsonLogicConj || conjunction.toLowerCase(); | ||
const conj = conjunctionDefinition?.jsonLogicConj || conjunction.toLowerCase(); | ||
const origNot = !!properties.get("not"); | ||
@@ -97,0 +97,0 @@ |
@@ -6,3 +6,3 @@ import uuid from "../utils/uuid"; | ||
import {loadTree} from "./tree"; | ||
import {defaultConjunction, defaultGroupConjunction} from "../utils/defaultUtils"; | ||
import {defaultGroupConjunction} from "../utils/defaultUtils"; | ||
@@ -693,3 +693,3 @@ import moment from "moment"; | ||
properties: { | ||
conjunction: defaultConjunction(config), | ||
conjunction: defaultGroupConjunction(config), | ||
not: not | ||
@@ -696,0 +696,0 @@ } |
@@ -6,3 +6,3 @@ import { SpelExpressionEvaluator } from "spel2js"; | ||
import {loadTree} from "./tree"; | ||
import {defaultConjunction, defaultGroupConjunction} from "../utils/defaultUtils"; | ||
import {defaultGroupConjunction} from "../utils/defaultUtils"; | ||
import {getOpCardinality, logger, isJsonCompatible} from "../utils/stuff"; | ||
@@ -1326,3 +1326,3 @@ import moment from "moment"; | ||
properties: { | ||
conjunction: defaultConjunction(config), | ||
conjunction: defaultGroupConjunction(config), | ||
not: not || false | ||
@@ -1329,0 +1329,0 @@ } |
@@ -6,2 +6,3 @@ /* eslint-disable no-extra-semi */ | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
import moment from "moment"; | ||
import type { Moment as MomentType } from "moment"; | ||
@@ -177,6 +178,2 @@ import type { i18n } from "i18next"; | ||
export type TypedValueSourceMap<T> = { | ||
[key in ValueSource]: T; | ||
} | ||
interface ExtraActionProperties { | ||
@@ -560,2 +557,5 @@ // note: id can pre-generated for actions addRule, addGroup | ||
defaultRuleProperties(config: Config, parentRuleGroupField?: string, item?: JsonItem, canUseDefaultFieldAndOp?: boolean, canGetFirst?: boolean): ImmutableRuleProperties; | ||
/** | ||
* @deprecated Use defaultGroupConjunction() instead | ||
*/ | ||
defaultConjunction(config: Config): string; | ||
@@ -585,4 +585,5 @@ defaultOperatorOptions(config: Config, operator: string, field: Field): OperatorOptionsI | null; | ||
listValuesToArray(listValues: ListValues): ListItems; // normalize | ||
toListValue(value: string | number | ListItem, title?: string): ListItem; // create | ||
toListValue(value: string | number | ListItem, title?: string): ListItem | undefined; // create | ||
makeCustomListValue(value: string | number): ListItem; // create | ||
mapListValues<T>(listValues : ListValues, mapFn: (item: ListItem | undefined) => T | null) : T[]; | ||
} | ||
@@ -599,3 +600,3 @@ interface TreeUtils { | ||
fixPathsInTree(tree: ImmutableTree): ImmutableTree; | ||
getFlatTree(tree: ImmutableTree): FlatTree; | ||
getFlatTree(tree: ImmutableTree, config?: Config): FlatTree; | ||
getTotalReordableNodesCountInTree(tree: ImmutableTree): number; | ||
@@ -642,3 +643,3 @@ getTotalRulesCountInTree(tree: ImmutableTree): number; | ||
i18n: i18n; | ||
moment: Moment; | ||
moment: typeof moment; | ||
} | ||
@@ -1014,3 +1015,6 @@ | ||
selectedConjunction?: string; | ||
setConjunction(conj: string): void; | ||
setConjunction: { | ||
(conj: string): void; | ||
isDummyFn?: boolean; | ||
}; | ||
conjunctionOptions?: TypedMap<ConjunctionOption>; | ||
@@ -1266,3 +1270,2 @@ config?: Config; | ||
fieldSettings?: FS; | ||
maxNesting?: number; | ||
} | ||
@@ -1280,2 +1283,7 @@ interface FieldGroupExt<FS = NumberFieldSettings<number>> extends BaseField { | ||
conjunctions?: Array<string>; | ||
defaultConjunction?: string; | ||
maxNesting?: number; | ||
maxNumberOfRules?: number; | ||
canRegroup?: boolean; | ||
canReorder?: boolean; | ||
isSpelArray?: boolean; | ||
@@ -1376,2 +1384,3 @@ isSpelItemMap?: boolean; | ||
defaultOperator?: string; | ||
defaultConjunction?: string; | ||
fieldSources?: Array<FieldSource>; | ||
@@ -1378,0 +1387,0 @@ valueSourcesInfo?: ValueSourcesInfo; |
import Immutable, { fromJS } from "immutable"; | ||
import { | ||
expandTreePath, expandTreeSubpath, getItemByPath, fixPathsInTree, | ||
expandTreePath, expandTreeSubpath, getItemByPath, getAncestorRuleGroups, fixPathsInTree, | ||
getTotalRulesCountInTree, fixEmptyGroupsInTree, isEmptyTree, hasChildren, removeIsLockedInTree | ||
@@ -53,3 +53,3 @@ } from "../utils/treeUtils"; | ||
if (canAddNewRule) { | ||
state = addItem(state, groupPath, "rule", uuid(), defaultRuleProperties(config, meta.parentRuleGroupField), config); | ||
state = addItem(state, groupPath, "rule", uuid(), defaultRuleProperties(config, meta?.parentRuleGroupField), config); | ||
} | ||
@@ -230,10 +230,26 @@ } | ||
} else if (type === "group") { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} else if (targetItem?.get("type") === "rule_group") { | ||
// todo | ||
// don't restrict | ||
} else { | ||
currentNumber = isTernary ? getTotalRulesCountInTree(caseGroup) : getTotalRulesCountInTree(state); | ||
maxNumber = maxNumberOfRules; | ||
const ruleGroups = getAncestorRuleGroups(state, path); | ||
if (ruleGroups.length) { | ||
// closest rule-group | ||
const { path: ruleGroupPath, field: ruleGroupField } = ruleGroups[0]; | ||
const ruleGroupFieldConfig = getFieldConfig(config, ruleGroupField); | ||
currentNumber = path.size - ruleGroupPath.length; | ||
maxNumber = ruleGroupFieldConfig?.maxNesting; | ||
} else { | ||
currentNumber = path.size; | ||
maxNumber = maxNesting; | ||
} | ||
} else { // rule or rule_group | ||
const ruleGroups = getAncestorRuleGroups(state, path); | ||
if (ruleGroups.length) { | ||
// closest rule-group | ||
const { path: ruleGroupPath, field: ruleGroupField } = ruleGroups[0]; | ||
const ruleGroupFieldConfig = getFieldConfig(config, ruleGroupField); | ||
const ruleGroupItem = getItemByPath(state, ruleGroupPath); | ||
maxNumber = ruleGroupFieldConfig?.maxNumberOfRules; | ||
currentNumber = getTotalRulesCountInTree(ruleGroupItem); | ||
} else { | ||
currentNumber = isTernary ? getTotalRulesCountInTree(caseGroup) : getTotalRulesCountInTree(state); | ||
maxNumber = maxNumberOfRules; | ||
} | ||
} | ||
@@ -240,0 +256,0 @@ const canAdd = maxNumber && currentNumber ? (currentNumber < maxNumber) : true; |
@@ -121,10 +121,11 @@ import Immutable from "immutable"; | ||
groupFieldConfig = getFieldConfig(config, groupFieldConfig); // if `groupFieldConfig` is field name, not config | ||
const conjs = groupFieldConfig && groupFieldConfig.conjunctions || Object.keys(config.conjunctions); | ||
const conjs = groupFieldConfig?.conjunctions || Object.keys(config.conjunctions); | ||
if (conjs.length == 1) | ||
return conjs[0]; | ||
return config.settings.defaultGroupConjunction || config.settings.defaultConjunction || conjs[0]; | ||
// todo: config.settings.defaultGroupConjunction is deprecated, defaultConjunction should be used instead | ||
return groupFieldConfig?.defaultConjunction || config.settings.defaultConjunction || config.settings.defaultGroupConjunction || conjs[0]; | ||
}; | ||
export const defaultConjunction = (config) => | ||
config.settings.defaultConjunction || Object.keys(config.conjunctions)[0]; | ||
// @deprecated Use defaultGroupConjunction | ||
export const defaultConjunction = (config) => defaultGroupConjunction(config); | ||
@@ -131,0 +132,0 @@ export const defaultGroupProperties = (config, groupFieldConfig = null) => { |
import Immutable from "immutable"; | ||
import {toImmutableList, isImmutable, applyToJS as immutableToJs} from "./stuff"; | ||
import {getFieldConfig} from "./configUtils"; | ||
import {jsToImmutable} from "../import/tree"; | ||
@@ -44,3 +45,3 @@ import uuid from "./uuid"; | ||
path.forEach((id) => { | ||
res = children.get(id); | ||
res = children?.get(id); | ||
children = res?.get("children1"); | ||
@@ -53,2 +54,23 @@ }); | ||
/** | ||
* @param {Immutable.Map} tree | ||
* @param {Immutable.List} path | ||
* @return {field, path}[] ordered by closest | ||
*/ | ||
export const getAncestorRuleGroups = (tree, path) => { | ||
const parentRuleGroups = path | ||
.map((_id, i) => path.take(i+1)) | ||
.reverse() | ||
.toJS() | ||
.map(path => ({ item: getItemByPath(tree, path), path })) | ||
.filter(({ item }) => item?.get("type") === "rule_group"); | ||
if (parentRuleGroups.length) { | ||
return parentRuleGroups.map(({ item, path }) => ({ | ||
path, | ||
field: item.get("properties").get("field"), | ||
})); | ||
} | ||
return []; | ||
}; | ||
/** | ||
* Remove `path` in every item | ||
@@ -183,3 +205,3 @@ * @param {Immutable.Map} tree | ||
*/ | ||
export const getFlatTree = (tree) => { | ||
export const getFlatTree = (tree, config) => { | ||
let flat = []; | ||
@@ -197,3 +219,3 @@ let items = {}; | ||
function _flatizeTree ( | ||
item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, caseId, childNo | ||
item, path, insideCollapsed, insideLocked, insideRuleGroup, lev, atomicLev, caseId, childNo | ||
) { | ||
@@ -215,2 +237,10 @@ const isRoot = item === tree; | ||
const parentId = path.length ? path[path.length-1] : null; | ||
const closestRuleGroupId = [...path].reverse().find(id => items[id].type == "rule_group"); | ||
const field = item.getIn(["properties", "field"]); | ||
const fieldConfig = field && config && getFieldConfig(config, field); | ||
const canRegroup = fieldConfig ? fieldConfig?.canRegroup !== false : undefined; | ||
const maxNesting = fieldConfig?.maxNesting; | ||
const closestRuleGroupCanRegroup = items?.[closestRuleGroupId]?.canRegroup; | ||
const closestRuleGroupMaxNesting = items?.[closestRuleGroupId]?.maxNesting; | ||
const closestRuleGroupLev = items?.[closestRuleGroupId]?.lev; | ||
const currentCaseId = isCaseGroup ? id : caseId; | ||
@@ -243,2 +273,3 @@ | ||
} | ||
const nextAtomicLev = insideRuleGroup || isRuleGroup ? atomicLev : atomicLev + 1; | ||
@@ -252,3 +283,2 @@ flat.push(id); | ||
parent: parentId, | ||
parentType: parentId ? items[parentId].type : null, | ||
children: childrenIds, | ||
@@ -258,4 +288,12 @@ childNo, | ||
caseNo, | ||
closestRuleGroupId, | ||
closestRuleGroupLev, | ||
closestRuleGroupMaxNesting, | ||
closestRuleGroupCanRegroup, | ||
maxNesting, | ||
canRegroup, | ||
path: path.concat(id), | ||
lev: lev, // depth level (0 for root node) | ||
atomicLev, // same as lev, but rules inside rule_group retains same number | ||
nextAtomicLev, | ||
isLeaf: !children, // is atomic rule OR rule inside rule_group | ||
@@ -274,2 +312,3 @@ isAtomicRule, // is atomic (rule or rule_group, but not rules inside rule_group) | ||
_top: itemsBefore, | ||
parentType: parentId ? items[parentId].type : null, | ||
// @deprecated use isLeaf instead | ||
@@ -319,3 +358,4 @@ leaf: !children, | ||
insideCollapsed || collapsed, insideLocked || isLocked, insideRuleGroup || isRuleGroup, | ||
lev + 1, currentCaseId, childCount | ||
lev + 1, nextAtomicLev, | ||
currentCaseId, childCount | ||
); | ||
@@ -347,3 +387,3 @@ const childItem = items[childId]; | ||
// Start recursion | ||
_flatizeTree(tree, [], false, false, false, 0, null, null); | ||
_flatizeTree(tree, [], false, false, false, 0, 0, null, null); | ||
@@ -384,6 +424,6 @@ // Calc after recursion | ||
} | ||
const isRuleGroup = type == "rule_group"; | ||
cnt++; | ||
//tip: rules in rule-group can be reordered only inside | ||
if (children && !isRuleGroup) { | ||
if (type == "rule_group" && lev > 0) { | ||
//tip: rules in rule-group can be reordered only inside | ||
} else if (children) { | ||
children.map((child, _childId) => { | ||
@@ -424,3 +464,3 @@ if (child) { | ||
if (type == "rule" || type == "rule_group") { | ||
if (type == "rule" || type == "rule_group" && lev > 0) { | ||
// tip: count rule_group as 1 rule | ||
@@ -427,0 +467,0 @@ cnt++; |
@@ -250,3 +250,3 @@ import omit from "lodash/omit"; | ||
if (includeItemsPositions) { | ||
flatItems = getFlatTree(fixedTree).items; | ||
flatItems = getFlatTree(fixedTree, config).items; | ||
} | ||
@@ -280,3 +280,3 @@ for (const id in meta.errors) { | ||
if (!oldFlatItems) { | ||
oldFlatItems = getFlatTree(tree).items; | ||
oldFlatItems = getFlatTree(tree, config).items; | ||
} | ||
@@ -1388,3 +1388,3 @@ flatItem = oldFlatItems[id]; | ||
let newValue = currentValue; | ||
if (valueFixes.length > 0 || !canReuseValue) { | ||
if (valueFixes.length > 0 || !canReuseValue || operatorCardinality < currentOperatorCardinality) { | ||
newValue = new Immutable.List(Array.from({length: operatorCardinality}, (_ignore, i) => { | ||
@@ -1395,3 +1395,3 @@ return valueFixes[i] !== undefined ? valueFixes[i] : (canReuseValue ? currentValue.get(i) : undefined); | ||
let newValueSrc = currentValueSrc; | ||
if (valueSrcFixes.length > 0 || !canReuseValue) { | ||
if (valueSrcFixes.length > 0 || !canReuseValue || operatorCardinality < currentOperatorCardinality) { | ||
newValueSrc = new Immutable.List(Array.from({length: operatorCardinality}, (_ignore, i) => { | ||
@@ -1402,3 +1402,3 @@ return valueSrcFixes[i] ?? (canReuseValue && currentValueSrc.get(i) || null); | ||
let newValueType = currentValueType; | ||
if (valueTypeFixes.length > 0 || !canReuseValue) { | ||
if (valueTypeFixes.length > 0 || !canReuseValue || operatorCardinality < currentOperatorCardinality) { | ||
newValueType = new Immutable.List(Array.from({length: operatorCardinality}, (_ignore, i) => { | ||
@@ -1405,0 +1405,0 @@ return valueTypeFixes[i] ?? (canReuseValue && currentValueType.get(i) || null); |
{ | ||
"name": "@react-awesome-query-builder/core", | ||
"version": "6.6.4-alpha.0", | ||
"version": "6.6.4", | ||
"description": "User-friendly query builder for React. Core", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1942894
47146
1