UNPKG

@itwin/presentation-common

Version:

Common pieces for iModel.js presentation packages

117 lines 5.54 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /* eslint-disable @typescript-eslint/no-deprecated */ /** @packageDocumentation * @module Hierarchies */ Object.defineProperty(exports, "__esModule", { value: true }); exports.NodeKey = exports.StandardNodeTypes = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const EC_js_1 = require("../EC.js"); /** * Standard node types * @public * @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md) * package for creating hierarchies. */ var StandardNodeTypes; (function (StandardNodeTypes) { StandardNodeTypes["ECInstancesNode"] = "ECInstancesNode"; StandardNodeTypes["ECClassGroupingNode"] = "ECClassGroupingNode"; StandardNodeTypes["ECPropertyGroupingNode"] = "ECPropertyGroupingNode"; StandardNodeTypes["DisplayLabelGroupingNode"] = "DisplayLabelGroupingNode"; })(StandardNodeTypes || (exports.StandardNodeTypes = StandardNodeTypes = {})); /** * @public * @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md) * package for creating hierarchies. */ // eslint-disable-next-line @typescript-eslint/no-redeclare var NodeKey; (function (NodeKey) { /** Checks if the supplied key is an [[ECInstancesNodeKey]] */ function isInstancesNodeKey(key) { return key.type === StandardNodeTypes.ECInstancesNode; } NodeKey.isInstancesNodeKey = isInstancesNodeKey; /** Checks if the supplied key is an [[ECClassGroupingNodeKey]] */ function isClassGroupingNodeKey(key) { return key.type === StandardNodeTypes.ECClassGroupingNode; } NodeKey.isClassGroupingNodeKey = isClassGroupingNodeKey; /** Checks if the supplied key is an [[ECPropertyGroupingNodeKey]] */ function isPropertyGroupingNodeKey(key) { return key.type === StandardNodeTypes.ECPropertyGroupingNode; } NodeKey.isPropertyGroupingNodeKey = isPropertyGroupingNodeKey; /** Checks if the supplied key is a [[LabelGroupingNodeKey]] */ function isLabelGroupingNodeKey(key) { return key.type === StandardNodeTypes.DisplayLabelGroupingNode; } NodeKey.isLabelGroupingNodeKey = isLabelGroupingNodeKey; /** Checks if the supplied key is a grouping node key */ function isGroupingNodeKey(key) { return isClassGroupingNodeKey(key) || isPropertyGroupingNodeKey(key) || isLabelGroupingNodeKey(key); } NodeKey.isGroupingNodeKey = isGroupingNodeKey; /** * Checks if two given node keys are equal, taking their versions into account. * * When comparing two keys of the same version, the algorithm uses [[NodeKey.pathFromRoot]] array * which is the most accurate way of checking equality. However, when version are different, * [[NodeKey.pathFromRoot]] array may contain different strings even though keys represent the same node. * In that case equality is checked using other key attributes, depending on the type of the node (type, * label, grouping class, property name, etc.). */ function equals(lhs, rhs) { // types must always be equal if (lhs.type !== rhs.type) { return false; } // `pathFromRoot` lengths must always be equal if (lhs.pathFromRoot.length !== rhs.pathFromRoot.length) { return false; } // when versions are equal, compare using contents of `pathFromRoot` array if (lhs.version === rhs.version) { for (let i = 0; i < lhs.pathFromRoot.length; ++i) { if (lhs.pathFromRoot[i] !== rhs.pathFromRoot[i]) { return false; } } return true; } // when versions aren't equal, compare using other key information, because key hashes // of different key versions can't be compared if (isInstancesNodeKey(lhs)) { (0, core_bentley_1.assert)(isInstancesNodeKey(rhs)); if (lhs.instanceKeys.length !== rhs.instanceKeys.length) { return false; } for (let i = 0; i < lhs.instanceKeys.length; ++i) { if (0 !== EC_js_1.InstanceKey.compare(lhs.instanceKeys[i], rhs.instanceKeys[i])) { return false; } } return true; } if (isClassGroupingNodeKey(lhs)) { (0, core_bentley_1.assert)(isClassGroupingNodeKey(rhs)); return lhs.className === rhs.className; } if (isPropertyGroupingNodeKey(lhs)) { (0, core_bentley_1.assert)(isPropertyGroupingNodeKey(rhs)); return lhs.className === rhs.className && lhs.propertyName === rhs.propertyName; } if (isLabelGroupingNodeKey(lhs)) { (0, core_bentley_1.assert)(isLabelGroupingNodeKey(rhs)); return lhs.label === rhs.label; } return true; } NodeKey.equals = equals; })(NodeKey || (exports.NodeKey = NodeKey = {})); //# sourceMappingURL=Key.js.map