@itwin/components-react 4.2.0-dev.1 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.d.ts +2 -0
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js +5 -7
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.d.ts +2 -0
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js +5 -7
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
# Change Log - @itwin/components-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 05 Jul 2023 07:56:27 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.2.1
|
|
6
|
+
Wed, 05 Jul 2023 07:56:27 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Fix possible runtime issue due to a symbol property in a SparseTree
|
|
11
|
+
|
|
12
|
+
## 4.2.0
|
|
13
|
+
Tue, 27 Jun 2023 14:50:22 GMT
|
|
14
|
+
|
|
15
|
+
### Updates
|
|
16
|
+
|
|
17
|
+
- `PropertyFilterBuilder`: Make `contains` default operator for string and text properties.
|
|
18
|
+
- `PropertyFilterBuilder`: Delete button will clear rule instead of removing it when there is only one rule left in the rule group.
|
|
19
|
+
- Promoted `TreeNodeContent` and `TreeNodeIcon` to `public`.
|
|
20
|
+
- ControlledTree: Improved context menu support by exposing `onContextMenu` callback through `TreeNodeRendererProps`.
|
|
21
|
+
- `PropertyFilterBuilder`: Set focus on property selector on `+ Rule` and `+ Rule Group` buttons click.
|
|
22
|
+
- `PropertyFilterBuilder`: Allow filtering when there are empty filter rules.
|
|
23
|
+
- Remove non-public API calls.
|
|
24
|
+
- `VirtualizedPropertyGrid`: Improved property layout to make sure action buttons does not overflow on small screens.
|
|
25
|
+
- Update `@itwin/itwinui-react` version to 2.11.6.
|
|
4
26
|
|
|
5
27
|
## 4.1.0
|
|
6
28
|
Mon, 29 May 2023 14:05:04 GMT
|
|
@@ -17,6 +17,7 @@ export declare class SparseTree<T extends Node> {
|
|
|
17
17
|
private _rootNodes;
|
|
18
18
|
private _parentToChildren;
|
|
19
19
|
private _idToNode;
|
|
20
|
+
constructor();
|
|
20
21
|
getNode(nodeId: string): T | undefined;
|
|
21
22
|
getChildOffset(parentId: string | undefined, childId: string): number | undefined;
|
|
22
23
|
getChildren(parentId: string | undefined, createIfNotExist?: boolean): SparseArray<string> | undefined;
|
|
@@ -39,6 +40,7 @@ export declare class SparseArray<T> implements Iterable<T | undefined> {
|
|
|
39
40
|
[immerable]: boolean;
|
|
40
41
|
private _length;
|
|
41
42
|
private _array;
|
|
43
|
+
constructor();
|
|
42
44
|
/** Returns length of array including intermediate 'undefined' values */
|
|
43
45
|
getLength(): number;
|
|
44
46
|
/** Sets length of array. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparseTree.d.ts","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,gBAAgB;AAChB,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,IAAI;IAC7B,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"SparseTree.d.ts","sourceRoot":"","sources":["../../../../../../src/components-react/t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seArray = exports.SparseTree = void 0;
|
|
12
11
|
const immer_1 = require("immer");
|
|
@@ -19,10 +18,10 @@ const core_bentley_1 = require("@itwin/core-bentley");
|
|
|
19
18
|
*/
|
|
20
19
|
class SparseTree {
|
|
21
20
|
constructor() {
|
|
22
|
-
this[_a] = true;
|
|
23
21
|
this._rootNodes = new SparseArray();
|
|
24
22
|
this._parentToChildren = {};
|
|
25
23
|
this._idToNode = {};
|
|
24
|
+
this[immer_1.immerable] = true;
|
|
26
25
|
}
|
|
27
26
|
getNode(nodeId) {
|
|
28
27
|
return this._idToNode[nodeId];
|
|
@@ -59,8 +58,8 @@ class SparseTree {
|
|
|
59
58
|
this._idToNode[child.id] = child;
|
|
60
59
|
}
|
|
61
60
|
setNodeId(parentId, index, newId) {
|
|
62
|
-
var
|
|
63
|
-
const previousNodeId = (
|
|
61
|
+
var _a;
|
|
62
|
+
const previousNodeId = (_a = this.getChildren(parentId)) === null || _a === void 0 ? void 0 : _a.get(index);
|
|
64
63
|
if (previousNodeId === undefined) {
|
|
65
64
|
return false;
|
|
66
65
|
}
|
|
@@ -139,7 +138,6 @@ class SparseTree {
|
|
|
139
138
|
}
|
|
140
139
|
}
|
|
141
140
|
exports.SparseTree = SparseTree;
|
|
142
|
-
_a = immer_1.immerable;
|
|
143
141
|
/**
|
|
144
142
|
* Structure for sparse array value storage.
|
|
145
143
|
* The main advantage of this class over the standard javascript array is that
|
|
@@ -149,9 +147,9 @@ _a = immer_1.immerable;
|
|
|
149
147
|
*/
|
|
150
148
|
class SparseArray {
|
|
151
149
|
constructor() {
|
|
152
|
-
this[_b] = true;
|
|
153
150
|
this._length = 0;
|
|
154
151
|
this._array = [];
|
|
152
|
+
this[immer_1.immerable] = true;
|
|
155
153
|
}
|
|
156
154
|
/** Returns length of array including intermediate 'undefined' values */
|
|
157
155
|
getLength() {
|
|
@@ -217,7 +215,7 @@ class SparseArray {
|
|
|
217
215
|
return this._array[Symbol.iterator]();
|
|
218
216
|
}
|
|
219
217
|
/** Iterates the array with all intermediate `undefined` values */
|
|
220
|
-
[
|
|
218
|
+
[Symbol.iterator]() {
|
|
221
219
|
const array = this._array;
|
|
222
220
|
const length = this._length;
|
|
223
221
|
return (function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparseTree.js","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;AAEH,iCAAkC;AAClC,sDAAyE;AAOzE;;;;;GAKG;AACH,MAAa,UAAU;IAAvB;QACS,QAAW,GAAG,IAAI,CAAC;QAElB,eAAU,GAAG,IAAI,WAAW,EAAU,CAAC;QACvC,sBAAiB,GAAwC,EAAE,CAAC;QAC5D,cAAS,GAAsB,EAAE,CAAC;IAiK5C,CAAC;IA/JQ,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAEM,cAAc,CACnB,QAA4B,EAC5B,OAAe;QAEf,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEhC,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAEM,WAAW,CAChB,QAA4B,EAC5B,mBAA4B,KAAK;QAEjC,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,OAAO,IAAI,CAAC,UAAU,CAAC;SACxB;QAED,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,SAAS,IAAI,gBAAgB,EAAE;YACtE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,IAAI,WAAW,EAAU,CAAC;SAC9D;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAEM,WAAW,CAChB,QAA4B,EAC5B,QAA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MAAM,CAAC,OAAO,CAAI,KAAa,EAAE,KAAkB;QACzD,OAAO,IAAA,6BAAc,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AAhHD,kCAgHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable] = true;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable] = true;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SparseTree.js","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,iCAAkC;AAClC,sDAAyE;AAOzE;;;;;GAKG;AACH,MAAa,UAAU;IAOrB;QAJQ,eAAU,GAAG,IAAI,WAAW,EAAU,CAAC;QACvC,sBAAiB,GAAwC,EAAE,CAAC;QAC5D,cAAS,GAAsB,EAAE,CAAC;QAGxC,IAAI,CAAC,iBAAS,CAAC,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAEM,cAAc,CACnB,QAA4B,EAC5B,OAAe;QAEf,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEhC,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAE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K,EAAE,EAAE,YAAY,EAAE;oBAC3C,MAAM,SAAS,CAAC;iBACjB;gBAED,MAAM,KAAK,CAAC;gBACZ,EAAE,YAAY,CAAC;aAChB;YAED,OAAO,YAAY,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE;gBAC5C,MAAM,SAAS,CAAC;aACjB;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAEO,UAAU,CAAC,KAAa;QAI9B,OAAO,IAAA,yBAAU,EAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IAEO,MAAM,CAAC,OAAO,CAAI,KAAa,EAAE,KAAkB;QACzD,OAAO,IAAA,6BAAc,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AApHD,kCAoHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable]: boolean;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n constructor() {\n this[immerable] = true;\n }\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable]: boolean;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n constructor() {\n this[immerable] = true;\n }\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
|
@@ -17,6 +17,7 @@ export declare class SparseTree<T extends Node> {
|
|
|
17
17
|
private _rootNodes;
|
|
18
18
|
private _parentToChildren;
|
|
19
19
|
private _idToNode;
|
|
20
|
+
constructor();
|
|
20
21
|
getNode(nodeId: string): T | undefined;
|
|
21
22
|
getChildOffset(parentId: string | undefined, childId: string): number | undefined;
|
|
22
23
|
getChildren(parentId: string | undefined, createIfNotExist?: boolean): SparseArray<string> | undefined;
|
|
@@ -39,6 +40,7 @@ export declare class SparseArray<T> implements Iterable<T | undefined> {
|
|
|
39
40
|
[immerable]: boolean;
|
|
40
41
|
private _length;
|
|
41
42
|
private _array;
|
|
43
|
+
constructor();
|
|
42
44
|
/** Returns length of array including intermediate 'undefined' values */
|
|
43
45
|
getLength(): number;
|
|
44
46
|
/** Sets length of array. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparseTree.d.ts","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,gBAAgB;AAChB,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,IAAI;IAC7B,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"SparseTree.d.ts","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,gBAAgB;AAChB,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,IAAI;IAC7B,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAE5B,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,iBAAiB,CAA2C;IACpE,OAAO,CAAC,SAAS,CAAyB;;IAMnC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAItC,cAAc,CACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS;IAOd,WAAW,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AAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAKxC,qEAAqE;IAC9D,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAMlC,yEAAyE;IAClE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAWrC,wEAAwE;IACjE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAelC;;;OAGG;IACI,aAAa,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAIrD,kEAAkE;IAC3D,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC;IAoB3D,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,MAAM,CAAC,OAAO;CAGvB"}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Tree
|
|
7
7
|
*/
|
|
8
|
-
var _a, _b;
|
|
9
8
|
import { immerable } from "immer";
|
|
10
9
|
import { assert, compareNumbers, lowerBound } from "@itwin/core-bentley";
|
|
11
10
|
/**
|
|
@@ -16,10 +15,10 @@ import { assert, compareNumbers, lowerBound } from "@itwin/core-bentley";
|
|
|
16
15
|
*/
|
|
17
16
|
export class SparseTree {
|
|
18
17
|
constructor() {
|
|
19
|
-
this[_a] = true;
|
|
20
18
|
this._rootNodes = new SparseArray();
|
|
21
19
|
this._parentToChildren = {};
|
|
22
20
|
this._idToNode = {};
|
|
21
|
+
this[immerable] = true;
|
|
23
22
|
}
|
|
24
23
|
getNode(nodeId) {
|
|
25
24
|
return this._idToNode[nodeId];
|
|
@@ -56,8 +55,8 @@ export class SparseTree {
|
|
|
56
55
|
this._idToNode[child.id] = child;
|
|
57
56
|
}
|
|
58
57
|
setNodeId(parentId, index, newId) {
|
|
59
|
-
var
|
|
60
|
-
const previousNodeId = (
|
|
58
|
+
var _a;
|
|
59
|
+
const previousNodeId = (_a = this.getChildren(parentId)) === null || _a === void 0 ? void 0 : _a.get(index);
|
|
61
60
|
if (previousNodeId === undefined) {
|
|
62
61
|
return false;
|
|
63
62
|
}
|
|
@@ -135,7 +134,6 @@ export class SparseTree {
|
|
|
135
134
|
delete this._parentToChildren[parentId];
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
|
-
_a = immerable;
|
|
139
137
|
/**
|
|
140
138
|
* Structure for sparse array value storage.
|
|
141
139
|
* The main advantage of this class over the standard javascript array is that
|
|
@@ -145,9 +143,9 @@ _a = immerable;
|
|
|
145
143
|
*/
|
|
146
144
|
export class SparseArray {
|
|
147
145
|
constructor() {
|
|
148
|
-
this[_b] = true;
|
|
149
146
|
this._length = 0;
|
|
150
147
|
this._array = [];
|
|
148
|
+
this[immerable] = true;
|
|
151
149
|
}
|
|
152
150
|
/** Returns length of array including intermediate 'undefined' values */
|
|
153
151
|
getLength() {
|
|
@@ -213,7 +211,7 @@ export class SparseArray {
|
|
|
213
211
|
return this._array[Symbol.iterator]();
|
|
214
212
|
}
|
|
215
213
|
/** Iterates the array with all intermediate `undefined` values */
|
|
216
|
-
[
|
|
214
|
+
[Symbol.iterator]() {
|
|
217
215
|
const array = this._array;
|
|
218
216
|
const length = this._length;
|
|
219
217
|
return (function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparseTree.js","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAOzE;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IAAvB;QACS,QAAW,GAAG,IAAI,CAAC;QAElB,eAAU,GAAG,IAAI,WAAW,EAAU,CAAC;QACvC,sBAAiB,GAAwC,EAAE,CAAC;QAC5D,cAAS,GAAsB,E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AAC;IAED,kEAAkE;IAC3D,OAjFC,SAAS,EAiFT,MAAM,CAAC,QAAQ,EAAC;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,YAAY,GAAG,CAAC,CAAC;YACrB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE;gBAClC,OAAO,YAAY,GAAG,KAAK,EAAE,EAAE,YAAY,EAAE;oBAC3C,MAAM,SAAS,CAAC;iBACjB;gBAED,MAAM,KAAK,CAAC;gBACZ,EAAE,YAAY,CAAC;aAChB;YAED,OAAO,YAAY,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE;gBAC5C,MAAM,SAAS,CAAC;aACjB;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAEO,UAAU,CAAC,KAAa;QAI9B,OAAO,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IAEO,MAAM,CAAC,OAAO,CAAI,KAAa,EAAE,KAAkB;QACzD,OAAO,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable] = true;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable] = true;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
|
1
|
+
{"version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CAAC;IACzC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable]: boolean;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n constructor() {\n this[immerable] = true;\n }\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable]: boolean;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n constructor() {\n this[immerable] = true;\n }\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/components-react",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "iTwin.js UI complex components",
|
|
5
5
|
"main": "lib/cjs/components-react.js",
|
|
6
6
|
"module": "lib/esm/components-react.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@itwin/appui-abstract": "^3.7.0 || ^4.0.0",
|
|
26
26
|
"@itwin/core-bentley": "^3.7.0 || ^4.0.0",
|
|
27
|
-
"@itwin/core-react": "^4.2.
|
|
27
|
+
"@itwin/core-react": "^4.2.1",
|
|
28
28
|
"react": "^17.0.0 || ^18.0.0",
|
|
29
29
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
30
30
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@itwin/core-common": "^3.7.0",
|
|
40
40
|
"@itwin/core-geometry": "^3.7.0",
|
|
41
41
|
"@itwin/core-i18n": "^3.7.0",
|
|
42
|
-
"@itwin/core-react": "4.2.
|
|
42
|
+
"@itwin/core-react": "4.2.1",
|
|
43
43
|
"@itwin/eslint-plugin": "^3.7.0",
|
|
44
44
|
"@testing-library/dom": "^8.11.2",
|
|
45
45
|
"@testing-library/react": "^12.0.0",
|