@itwin/presentation-hierarchies-react 2.0.0-alpha.6 → 2.0.0-alpha.60

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.
Files changed (163) hide show
  1. package/CHANGELOG.md +1137 -11
  2. package/README.md +93 -160
  3. package/lib/presentation-hierarchies-react/FlatTreeNode.d.ts +49 -0
  4. package/lib/presentation-hierarchies-react/FlatTreeNode.d.ts.map +1 -0
  5. package/lib/presentation-hierarchies-react/FlatTreeNode.js +93 -0
  6. package/lib/presentation-hierarchies-react/FlatTreeNode.js.map +1 -0
  7. package/lib/presentation-hierarchies-react/LocalizationContext.d.ts +24 -0
  8. package/lib/presentation-hierarchies-react/LocalizationContext.d.ts.map +1 -0
  9. package/lib/presentation-hierarchies-react/LocalizationContext.js +40 -0
  10. package/lib/presentation-hierarchies-react/LocalizationContext.js.map +1 -0
  11. package/lib/presentation-hierarchies-react/Renderers.d.ts +92 -0
  12. package/lib/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
  13. package/lib/presentation-hierarchies-react/TreeNode.d.ts +80 -0
  14. package/lib/presentation-hierarchies-react/TreeNode.d.ts.map +1 -0
  15. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseIModelTree.d.ts +28 -15
  16. package/lib/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -0
  17. package/lib/presentation-hierarchies-react/UseIModelTree.js +183 -0
  18. package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -0
  19. package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts +30 -0
  20. package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
  21. package/lib/presentation-hierarchies-react/UseNodeHighlighting.js +57 -0
  22. package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
  23. package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +23 -0
  24. package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -0
  25. package/lib/presentation-hierarchies-react/UseSelectionHandler.js +124 -0
  26. package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -0
  27. package/lib/presentation-hierarchies-react/UseTree.d.ts +112 -0
  28. package/lib/presentation-hierarchies-react/UseTree.d.ts.map +1 -0
  29. package/lib/presentation-hierarchies-react/UseTree.js +297 -0
  30. package/lib/presentation-hierarchies-react/UseTree.js.map +1 -0
  31. package/lib/presentation-hierarchies-react/Utils.js +56 -0
  32. package/lib/presentation-hierarchies-react/Utils.js.map +1 -0
  33. package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js +10 -0
  34. package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -0
  35. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts +9 -0
  36. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts.map +1 -0
  37. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +12 -0
  38. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js.map +1 -0
  39. package/lib/presentation-hierarchies-react/internal/TreeActions.js +294 -0
  40. package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -0
  41. package/lib/presentation-hierarchies-react/internal/TreeLoader.js +98 -0
  42. package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -0
  43. package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +1 -0
  44. package/lib/presentation-hierarchies-react/internal/TreeModel.js +120 -0
  45. package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -0
  46. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +35 -0
  47. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -0
  48. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +141 -0
  49. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -0
  50. package/lib/presentation-hierarchies-react/internal/Utils.js +42 -0
  51. package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -0
  52. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +38 -0
  53. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
  54. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +380 -0
  55. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
  56. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +27 -0
  57. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
  58. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +185 -0
  59. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
  60. package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts +49 -0
  61. package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
  62. package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +88 -0
  63. package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
  64. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +38 -0
  65. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
  66. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +63 -0
  67. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
  68. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +29 -0
  69. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
  70. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +91 -0
  71. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
  72. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +31 -0
  73. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
  74. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +155 -0
  75. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
  76. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.css +25 -0
  77. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +14 -0
  78. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
  79. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +534 -0
  80. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
  81. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +75 -0
  82. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
  83. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js +417 -0
  84. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
  85. package/lib/presentation-hierarchies-react-extract.d.ts +17 -0
  86. package/lib/presentation-hierarchies-react-extract.js +16 -0
  87. package/lib/presentation-hierarchies-react-stratakit.d.ts +8 -0
  88. package/lib/presentation-hierarchies-react-stratakit.js +8 -0
  89. package/lib/presentation-hierarchies-react.d.ts +11 -0
  90. package/lib/presentation-hierarchies-react.js +8 -0
  91. package/lib/public/locales/en/PresentationHierarchies_1.0.json +26 -0
  92. package/package.json +78 -56
  93. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +0 -75
  94. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +0 -1
  95. package/lib/esm/presentation-hierarchies-react/TreeNode.js +0 -12
  96. package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +0 -1
  97. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
  98. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
  99. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
  100. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
  101. package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +0 -1
  102. package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +0 -62
  103. package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +0 -1
  104. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +0 -46
  105. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +0 -1
  106. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +0 -98
  107. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +0 -1
  108. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +0 -132
  109. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +0 -1
  110. package/lib/esm/presentation-hierarchies-react/UseTree.js +0 -242
  111. package/lib/esm/presentation-hierarchies-react/UseTree.js.map +0 -1
  112. package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts +0 -2
  113. package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts.map +0 -1
  114. package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js +0 -11
  115. package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.map +0 -1
  116. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +0 -53
  117. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +0 -1
  118. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +0 -307
  119. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +0 -1
  120. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +0 -44
  121. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +0 -1
  122. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +0 -94
  123. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +0 -1
  124. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +0 -70
  125. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +0 -1
  126. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +0 -153
  127. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +0 -1
  128. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +0 -28
  129. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +0 -1
  130. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +0 -128
  131. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +0 -1
  132. package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts +0 -23
  133. package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +0 -1
  134. package/lib/esm/presentation-hierarchies-react/internal/Utils.js +0 -58
  135. package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +0 -1
  136. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +0 -21
  137. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +0 -1
  138. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +0 -30
  139. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +0 -1
  140. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +0 -73
  141. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +0 -1
  142. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +0 -34
  143. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +0 -1
  144. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -25
  145. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
  146. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
  147. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
  148. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -23
  149. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +0 -1
  150. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +0 -72
  151. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +0 -1
  152. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +0 -40
  153. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
  154. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -80
  155. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +0 -1
  156. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +0 -30
  157. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +0 -1
  158. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +0 -48
  159. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
  160. package/lib/esm/presentation-hierarchies-react.d.ts +0 -13
  161. package/lib/esm/presentation-hierarchies-react.d.ts.map +0 -1
  162. package/lib/esm/presentation-hierarchies-react.js +0 -16
  163. package/lib/esm/presentation-hierarchies-react.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-hierarchies-react",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.60",
4
4
  "description": "React components based on `@itwin/presentation-hierarchies`",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,88 +28,110 @@
28
28
  "Tree"
29
29
  ],
30
30
  "type": "module",
31
- "types": "lib/esm/presentation-hierarchies-react.d.ts",
32
- "module": "lib/esm/presentation-hierarchies-react.js",
31
+ "types": "lib/presentation-hierarchies-react.d.ts",
33
32
  "exports": {
34
33
  ".": {
35
- "import": "./lib/esm/presentation-hierarchies-react.js"
34
+ "types": "./lib/presentation-hierarchies-react.d.ts",
35
+ "import": "./lib/presentation-hierarchies-react.js"
36
+ },
37
+ "./stratakit": {
38
+ "types": "./lib/presentation-hierarchies-react-stratakit.d.ts",
39
+ "import": "./lib/presentation-hierarchies-react-stratakit.js"
36
40
  },
37
41
  "./package.json": "./package.json"
38
42
  },
39
43
  "dependencies": {
40
- "@itwin/core-bentley": "^5.0.0-dev.49",
41
- "@itwin/itwinui-illustrations-react": "^2.1.0",
42
- "@tanstack/react-virtual": "^3.13.0",
44
+ "@itwin/core-bentley": "^5.7.2",
45
+ "@tanstack/react-virtual": "^3.13.13",
43
46
  "classnames": "^2.5.1",
44
- "immer": "^10.1.1",
45
- "react-error-boundary": "^4.0.13",
46
- "rxjs": "^7.8.1",
47
- "@itwin/presentation-hierarchies": "^1.4.1",
48
- "@itwin/presentation-shared": "^1.2.0",
49
- "@itwin/unified-selection": "^1.3.0"
47
+ "immer": "^10.2.0",
48
+ "react-compiler-runtime": "^1.0.0",
49
+ "react-error-boundary": "^4.1.2",
50
+ "rxjs": "^7.8.2",
51
+ "@itwin/presentation-shared": "2.0.0-alpha.9",
52
+ "@itwin/unified-selection": "^1.6.8",
53
+ "@itwin/presentation-hierarchies": "2.0.0-alpha.14"
50
54
  },
51
55
  "peerDependencies": {
52
- "@itwin/itwinui-icons": "5.0.0-alpha.4",
53
- "@itwin/itwinui-react": "5.0.0-alpha.7",
54
- "react": "^17.0.0 || ^18.0.0",
55
- "react-dom": "^17.0.0 || ^18.0.0"
56
+ "@stratakit/bricks": "^0.5.4",
57
+ "@stratakit/foundations": "^0.4.7",
58
+ "@stratakit/icons": "^0.3.1",
59
+ "@stratakit/structures": "^0.5.6",
60
+ "react": "^17.0 || ^18.0",
61
+ "react-dom": "^17.0 || ^18.0"
56
62
  },
57
63
  "peerDependenciesMeta": {
58
- "@itwin/itwinui-icons": {
64
+ "@stratakit/bricks": {
65
+ "optional": true
66
+ },
67
+ "@stratakit/foundations": {
68
+ "optional": true
69
+ },
70
+ "@stratakit/structures": {
59
71
  "optional": true
60
72
  },
61
- "@itwin/itwinui-react": {
73
+ "@stratakit/icons": {
62
74
  "optional": true
63
75
  }
64
76
  },
65
77
  "devDependencies": {
66
- "@itwin/build-tools": "5.0.0-dev.67",
67
- "@itwin/itwinui-icons": "5.0.0-alpha.4",
68
- "@itwin/itwinui-react": "5.0.0-alpha.7",
69
- "@testing-library/dom": "^10.3.2",
70
- "@testing-library/react": "^16.0.0",
71
- "@testing-library/user-event": "^14.5.2",
72
- "@types/chai": "^4.3.16",
73
- "@types/chai-as-promised": "^7.1.8",
74
- "@types/chai-subset": "^1.3.5",
78
+ "@itwin/build-tools": "^5.7.2",
79
+ "@itwin/eslint-plugin": "5.1.0",
80
+ "@rolldown/plugin-babel": "^0.2.2",
81
+ "@stratakit/bricks": "^0.5.4",
82
+ "@stratakit/foundations": "^0.4.7",
83
+ "@stratakit/icons": "^0.3.1",
84
+ "@stratakit/structures": "^0.5.6",
85
+ "@testing-library/dom": "^10.4.1",
86
+ "@testing-library/react": "^16.3.2",
87
+ "@testing-library/user-event": "^14.6.1",
88
+ "@types/chai": "^5.2.3",
89
+ "@types/chai-as-promised": "^8.0.2",
75
90
  "@types/jsdom": "^21.1.7",
76
- "@types/mocha": "^10.0.7",
77
- "@types/react": "^18.3.3",
78
- "@types/react-dom": "^18.3.0",
79
- "@types/sinon": "^17.0.3",
80
- "@types/sinon-chai": "^3.2.12",
81
- "c8": "^10.1.2",
82
- "chai": "^4.4.1",
83
- "chai-as-promised": "^7.1.2",
84
- "chai-subset": "^1.6.0",
85
- "cpx2": "^7.0.1",
91
+ "@types/mocha": "^10.0.10",
92
+ "@types/node": "^24.12.0",
93
+ "@types/react": "^18.3.28",
94
+ "@types/react-dom": "^18.3.7",
95
+ "@types/sinon": "^17.0.4",
96
+ "@types/sinon-chai": "^4.0.0",
97
+ "@vitejs/plugin-react": "^6.0.1",
98
+ "babel-plugin-react-compiler": "^1.0.0",
99
+ "chai": "^5.3.3",
100
+ "chai-as-promised": "^8.0.2",
101
+ "cpx2": "^7.0.2",
86
102
  "cross-env": "^7.0.3",
87
- "eslint": "^9.13.0",
88
- "eslint-plugin-react": "^7.37.2",
89
- "global-jsdom": "^25.0.0",
103
+ "eslint": "^9.39.4",
104
+ "eslint-plugin-react": "^7.37.5",
105
+ "eslint-plugin-react-hooks": "^7.0.1",
106
+ "fast-glob": "^3.3.3",
107
+ "global-jsdom": "^26.0.0",
90
108
  "ignore-styles": "^5.0.1",
91
- "jsdom": "^25.0.1",
92
- "mocha": "^10.7.3",
109
+ "jsdom": "^26.1.0",
110
+ "mocha": "^11.7.5",
93
111
  "react": "^18.3.1",
94
112
  "react-dom": "^18.3.1",
95
- "rimraf": "^6.0.1",
96
- "sinon": "^18.0.0",
97
- "sinon-chai": "^3.7.0",
98
- "testdouble": "^3.20.2",
113
+ "rimraf": "^6.1.3",
114
+ "sinon": "^19.0.5",
115
+ "sinon-chai": "^4.0.1",
116
+ "tsdown": "^0.21.4",
99
117
  "typescript": "~5.7.3",
100
- "presentation-test-utilities": "^0.0.0"
118
+ "vite": "^8.0.0",
119
+ "presentation-test-utilities": "0.0.1"
101
120
  },
102
121
  "scripts": {
103
- "build": "npm run -s build:esm",
104
- "build:esm": "npm run -s copy:esm && tsc -p tsconfig.esm.json",
105
- "copy:esm": "cpx \"./src/**/*.{css,json}\" ./lib/esm",
122
+ "build": "tsdown && npm run -s build:locale && npm run -s copy && npm run -s build:test",
123
+ "build:locale": "tsc -p tsconfig.utils.json && node ./lib/build/utils/BuildLocale.js",
124
+ "copy": "npm run -s copy:css && npm run -s copy:assets",
125
+ "copy:css": "cpx \"./src/**/*.css\" \"./lib\"",
126
+ "copy:assets": "cpx \"./src/public/**/*\" \"./lib/public\"",
127
+ "build:test": "tsdown --config tsdown.test.config.ts",
106
128
  "clean": "rimraf lib build",
107
- "cover": "c8 npm -s test",
108
- "lint": "eslint ./src/**/*.{ts,tsx}",
109
- "test:dev": "cross-env NODE_OPTIONS=\"--import presentation-test-utilities/node-hooks/ignore-styles\" mocha --enable-source-maps --config ./.mocharc.json",
129
+ "cover": "npm -s test",
130
+ "lint": "eslint \"./src/**/*.{ts,tsx}\"",
131
+ "test:dev": "node --experimental-test-module-mocks --enable-source-maps --import presentation-test-utilities/node-hooks/ignore-styles ./node_modules/mocha/bin/mocha.js --config ./.mocharc.json",
110
132
  "test": "npm run test:dev -- --parallel --jobs=4",
111
- "extract-api": "betools extract-api --entry=./lib/esm/presentation-hierarchies-react --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api --includeUnexportedApis",
112
- "check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/presentation-hierarchies-react.api.md",
133
+ "extract-api": "betools extract-api --entry=lib/presentation-hierarchies-react-extract --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api --includeUnexportedApis",
134
+ "check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/presentation-hierarchies-react-extract.api.md",
113
135
  "update-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md",
114
136
  "check-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md --check",
115
137
  "validate-markdowns": "node ../../scripts/validateMarkdowns.js README.md"
@@ -1,75 +0,0 @@
1
- import { HierarchyNode } from "@itwin/presentation-hierarchies";
2
- /**
3
- * A type that defines an actual expandable node in a UI tree component, built with `useTree` hook.
4
- * @public
5
- */
6
- export interface PresentationHierarchyNode {
7
- id: string;
8
- label: string;
9
- children: true | Array<PresentationTreeNode>;
10
- isExpanded: boolean;
11
- isLoading: boolean;
12
- isFilterable: boolean;
13
- isFiltered: boolean;
14
- /** UI-agnostic source of this node object. */
15
- nodeData: HierarchyNode;
16
- /** Additional data that may be assigned to this node. */
17
- extendedData?: {
18
- [key: string]: any;
19
- };
20
- }
21
- /**
22
- * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,
23
- * when none of the child nodes match the filter.
24
- *
25
- * @public
26
- */
27
- export interface PresentationNoFilterMatchesInfoNode {
28
- id: string;
29
- parentNodeId: string | undefined;
30
- type: "NoFilterMatches";
31
- }
32
- /**
33
- * A type of `PresentationInfoNode` that is returned as the single child of a parent node, when the
34
- * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included
35
- * on this node as `resultSetSizeLimit` attribute.
36
- *
37
- * @public
38
- */
39
- export interface PresentationResultSetTooLargeInfoNode {
40
- id: string;
41
- parentNodeId: string | undefined;
42
- type: "ResultSetTooLarge";
43
- resultSetSizeLimit: number;
44
- }
45
- /**
46
- * A type of `PresentationInfoNode` that contains a user-friendly message to be displayed in the UI.
47
- * Generally, this is the only child of a parent node, created in cases like an error loading children. The
48
- * renderer may offer users to re-load the children or the whole component in such cases.
49
- *
50
- * @public
51
- */
52
- export interface PresentationGenericInfoNode {
53
- id: string;
54
- parentNodeId: string | undefined;
55
- type: "Unknown";
56
- message: string;
57
- }
58
- /**
59
- * A type that defines a non-expandable, non-selectable informational node in a UI tree component, built
60
- * with `useTree` hook.
61
- *
62
- * @public
63
- */
64
- export type PresentationInfoNode = PresentationGenericInfoNode | PresentationResultSetTooLargeInfoNode | PresentationNoFilterMatchesInfoNode;
65
- /**
66
- * A type that defines a node in a UI tree component, built with `useTree` hook.
67
- * @public
68
- */
69
- export type PresentationTreeNode = PresentationHierarchyNode | PresentationInfoNode;
70
- /**
71
- * An utility function to check if a node is a `PresentationHierarchyNode`.
72
- * @public
73
- */
74
- export declare function isPresentationHierarchyNode(node: PresentationTreeNode): node is PresentationHierarchyNode;
75
- //# sourceMappingURL=TreeNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,EAAE,aAAa,CAAC;IACxB,yDAAyD;IACzD,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mCAAmC;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qCAAqC;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,GAAG,qCAAqC,GAAG,mCAAmC,CAAC;AAE7I;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,oBAAoB,CAAC;AAEpF;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,IAAI,yBAAyB,CAEzG"}
@@ -1,12 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /**
6
- * An utility function to check if a node is a `PresentationHierarchyNode`.
7
- * @public
8
- */
9
- export function isPresentationHierarchyNode(node) {
10
- return "children" in node;
11
- }
12
- //# sourceMappingURL=TreeNode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AA4EhG;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAA0B;IACpE,OAAO,UAAU,IAAI,IAAI,CAAC;AAC5B,CAAC","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\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\n/**\n * A type that defines an actual expandable node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport interface PresentationHierarchyNode {\n id: string;\n label: string;\n children: true | Array<PresentationTreeNode>;\n isExpanded: boolean;\n isLoading: boolean;\n isFilterable: boolean;\n isFiltered: boolean;\n /** UI-agnostic source of this node object. */\n nodeData: HierarchyNode;\n /** Additional data that may be assigned to this node. */\n extendedData?: { [key: string]: any };\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,\n * when none of the child nodes match the filter.\n *\n * @public\n */\nexport interface PresentationNoFilterMatchesInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"NoFilterMatches\";\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a parent node, when the\n * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included\n * on this node as `resultSetSizeLimit` attribute.\n *\n * @public\n */\nexport interface PresentationResultSetTooLargeInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/**\n * A type of `PresentationInfoNode` that contains a user-friendly message to be displayed in the UI.\n * Generally, this is the only child of a parent node, created in cases like an error loading children. The\n * renderer may offer users to re-load the children or the whole component in such cases.\n *\n * @public\n */\nexport interface PresentationGenericInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"Unknown\";\n message: string;\n}\n\n/**\n * A type that defines a non-expandable, non-selectable informational node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type PresentationInfoNode = PresentationGenericInfoNode | PresentationResultSetTooLargeInfoNode | PresentationNoFilterMatchesInfoNode;\n\n/**\n * A type that defines a node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport type PresentationTreeNode = PresentationHierarchyNode | PresentationInfoNode;\n\n/**\n * An utility function to check if a node is a `PresentationHierarchyNode`.\n * @public\n */\nexport function isPresentationHierarchyNode(node: PresentationTreeNode): node is PresentationHierarchyNode {\n return \"children\" in node;\n}\n"]}
@@ -1,15 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- import { SelectionStorage } from "@itwin/unified-selection";
3
- /**
4
- * A React context provider that makes given selection storage available to all child components. This
5
- * is a requirement for `useUnifiedSelectionTree` to work with unified selection.
6
- *
7
- * @public
8
- * @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.
9
- */
10
- export declare function UnifiedSelectionProvider({ storage, children }: PropsWithChildren<{
11
- storage: SelectionStorage;
12
- }>): import("react/jsx-runtime").JSX.Element;
13
- /** @internal */
14
- export declare function useUnifiedSelectionStorage(): SelectionStorage | undefined;
15
- //# sourceMappingURL=UnifiedSelectionContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnifiedSelectionContext.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UnifiedSelectionContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC;IAAE,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC,2CAE/G;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,iCAEzC"}
@@ -1,22 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- import { createContext, useContext } from "react";
7
- const deprecatedUnifiedSelectionContext = createContext(undefined);
8
- /**
9
- * A React context provider that makes given selection storage available to all child components. This
10
- * is a requirement for `useUnifiedSelectionTree` to work with unified selection.
11
- *
12
- * @public
13
- * @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.
14
- */
15
- export function UnifiedSelectionProvider({ storage, children }) {
16
- return _jsx(deprecatedUnifiedSelectionContext.Provider, { value: storage, children: children });
17
- }
18
- /** @internal */
19
- export function useUnifiedSelectionStorage() {
20
- return useContext(deprecatedUnifiedSelectionContext);
21
- }
22
- //# sourceMappingURL=UnifiedSelectionContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnifiedSelectionContext.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UnifiedSelectionContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAGrE,MAAM,iCAAiC,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAEjG;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAoD;IAC9G,OAAO,KAAC,iCAAiC,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,GAA8C,CAAC;AAC7H,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,0BAA0B;IACxC,OAAO,UAAU,CAAC,iCAAiC,CAAC,CAAC;AACvD,CAAC","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\nimport { createContext, PropsWithChildren, useContext } from \"react\";\nimport { SelectionStorage } from \"@itwin/unified-selection\";\n\nconst deprecatedUnifiedSelectionContext = createContext<SelectionStorage | undefined>(undefined);\n\n/**\n * A React context provider that makes given selection storage available to all child components. This\n * is a requirement for `useUnifiedSelectionTree` to work with unified selection.\n *\n * @public\n * @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.\n */\nexport function UnifiedSelectionProvider({ storage, children }: PropsWithChildren<{ storage: SelectionStorage }>) {\n return <deprecatedUnifiedSelectionContext.Provider value={storage}>{children}</deprecatedUnifiedSelectionContext.Provider>;\n}\n\n/** @internal */\nexport function useUnifiedSelectionStorage() {\n return useContext(deprecatedUnifiedSelectionContext);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAW,YAAY,EAAE,aAAa,EAA2B,MAAM,cAAc,CAAC;AAE7F,cAAc;AACd,KAAK,4BAA4B,GAAG,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEhF,cAAc;AACd,KAAK,YAAY,GAAG,4BAA4B,CAAC,cAAc,CAAC,CAAC;AAEjE;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,sBAAsB,GAAG,kBAAkB,CAAC,GACvF,IAAI,CAAC,4BAA4B,EAAE,kBAAkB,GAAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;KAC5B,KAAK,OAAO,CAAC,sBAAsB,EAAE,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAMtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,GAAG,aAAa,CAMrH"}
@@ -1,62 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- import { useCallback } from "react";
6
- import { createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
7
- import { useTree, useUnifiedSelectionTree } from "./UseTree.js";
8
- /**
9
- * A React hook that creates state for a tree component whose displayed hierarchy is based on
10
- * iModel data.
11
- *
12
- * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a
13
- * component-agnostic result which may be used to render the hierarchy using any UI framework.
14
- *
15
- * See `README.md` for an example
16
- *
17
- * @see `useTree`
18
- * @see `useIModelUnifiedSelectionTree`
19
- * @public
20
- */
21
- export function useIModelTree(props) {
22
- const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;
23
- return useTree({
24
- ...rest,
25
- ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),
26
- });
27
- }
28
- /**
29
- * A React hook that creates state for a tree component whose displayed hierarchy is based on
30
- * iModel data and that is integrated with unified selection through the given selection
31
- * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).
32
- *
33
- * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a
34
- * component-agnostic result which may be used to render the hierarchy using any UI framework.
35
- *
36
- * See `README.md` for an example
37
- *
38
- * @see `useIModelTree`
39
- * @see `useUnifiedSelectionTree`
40
- * @see `UnifiedSelectionProvider`
41
- * @public
42
- */
43
- export function useIModelUnifiedSelectionTree(props) {
44
- const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;
45
- return useUnifiedSelectionTree({
46
- ...rest,
47
- ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),
48
- });
49
- }
50
- function useIModelTreeProps(props) {
51
- const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props;
52
- return {
53
- getHierarchyProvider: useCallback(() => createIModelHierarchyProvider({
54
- imodelAccess,
55
- imodelChanged,
56
- hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
57
- localizedStrings,
58
- }), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
59
- getFilteredPaths: useCallback(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),
60
- };
61
- }
62
- //# sourceMappingURL=UseIModelTree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAA+C,MAAM,iCAAiC,CAAC;AAG7H,OAAO,EAAE,OAAO,EAA+B,uBAAuB,EAAE,MAAM,cAAc,CA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AAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;KAClH,CAAC;AACJ,CAAC","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\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider, HierarchyDefinition, HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport { Props } from \"@itwin/presentation-shared\";\nimport { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { useTree, UseTreeProps, UseTreeResult, useUnifiedSelectionTree } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> &\n Pick<IModelHierarchyProviderProps, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /** Provides the hierarchy definition for the tree. */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: (props: {\n /** Object that provides access to the iModel schema and can run queries against the iModel. */\n imodelAccess: IModelAccess;\n }) => Promise<HierarchyFilteringPath[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getFilteredPaths: useCallback(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),\n };\n}\n"]}
@@ -1,46 +0,0 @@
1
- import { PresentationHierarchyNode } from "./TreeNode.js";
2
- import { useTree } from "./UseTree.js";
3
- /**
4
- * A union of different supported selection modes in a tree component:
5
- * - `none` - no selection is allowed,
6
- * - `single` - only one node can be selected at a time,
7
- * - `extended` - multiple nodes can be selected using shift and ctrl keys,
8
- * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.
9
- *
10
- * @public
11
- */
12
- export type SelectionMode = "none" | "single" | "extended" | "multiple";
13
- /**
14
- * Type of selection change.
15
- * - `add` - a node was added to the selection,
16
- * - `replace` - a selected node was replaced with a different one,
17
- * - `remove` - a node was removed from the selection.
18
- *
19
- * @public
20
- */
21
- export type SelectionChangeType = "add" | "replace" | "remove";
22
- /**
23
- * Props for `useSelectionHandler` hook.
24
- * @public
25
- */
26
- type UseSelectionHandlerProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "selectNodes"> & {
27
- /** Selection mode that the component is working in. */
28
- selectionMode: SelectionMode;
29
- };
30
- /**
31
- * Result of `useSelectionHandler` hook.
32
- * @public
33
- */
34
- interface UseSelectionHandlerResult {
35
- /** Should be called by node renderer when a node component is clicked. */
36
- onNodeClick: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
37
- /** Should be called by node renderer when a keyboard event happens on a node. */
38
- onNodeKeyDown: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;
39
- }
40
- /**
41
- * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
42
- * @public
43
- */
44
- export declare function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult;
45
- export {};
46
- //# sourceMappingURL=UseSelectionHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseSelectionHandler.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,yBAAyB,EAAwB,MAAM,eAAe,CAAC;AAC7G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAExE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/D;;;GAGG;AACH,KAAK,wBAAwB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,GAAG;IAC9F,uDAAuD;IACvD,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,UAAU,yBAAyB;IACjC,0EAA0E;IAC1E,WAAW,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9H,iFAAiF;IACjF,aAAa,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACxH;AAOD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,yBAAyB,CAiE9F"}
@@ -1,98 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- import { useCallback, useEffect, useRef } from "react";
6
- import { isPresentationHierarchyNode } from "./TreeNode.js";
7
- /**
8
- * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
9
- * @public
10
- */
11
- export function useSelectionHandler(props) {
12
- const { rootNodes, selectionMode, selectNodes } = props;
13
- const previousSelectionRef = useRef(undefined);
14
- const state = useRef({
15
- flatNodeList: [],
16
- nodeIdToIndexMap: new Map(),
17
- });
18
- useEffect(() => {
19
- if (!rootNodes) {
20
- return;
21
- }
22
- state.current = computeFlatNodeList(rootNodes);
23
- }, [rootNodes]);
24
- const getNodeRange = (firstId, secondId) => {
25
- const getIndex = (nodeId) => {
26
- return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;
27
- };
28
- const firstIndex = getIndex(firstId);
29
- const secondIndex = getIndex(secondId);
30
- if (firstIndex === undefined || secondIndex === undefined) {
31
- return [];
32
- }
33
- const startingIndex = Math.min(firstIndex, secondIndex);
34
- const endIndex = Math.max(firstIndex, secondIndex);
35
- return state.current.flatNodeList.slice(startingIndex, endIndex + 1);
36
- };
37
- const onNodeSelect = useCallback((nodeId, isSelected, shiftDown, ctrlDown) => {
38
- const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);
39
- if (selection.type === "disabled") {
40
- return;
41
- }
42
- const nodes = selection.select === "range" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];
43
- if (!nodes.length) {
44
- return;
45
- }
46
- selection.select !== "range" && (previousSelectionRef.current = nodeId);
47
- selectNodes(nodes, selection.type);
48
- }, [selectionMode, selectNodes]);
49
- const onNodeClick = useCallback((node, isSelected, event) => {
50
- return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);
51
- }, [onNodeSelect]);
52
- const onNodeKeyDown = useCallback((node, isSelected, event) => {
53
- if (event.key === " " || event.key === "Spacebar" || event.key === "Enter") {
54
- return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);
55
- }
56
- }, [onNodeSelect]);
57
- return { onNodeClick, onNodeKeyDown };
58
- }
59
- function getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown) {
60
- switch (selectionMode) {
61
- case "none":
62
- return { select: "node", type: "disabled" };
63
- case "single":
64
- return { select: "node", type: isSelected ? "replace" : "remove" };
65
- case "multiple":
66
- return { select: "node", type: isSelected ? "add" : "remove" };
67
- case "extended":
68
- return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);
69
- }
70
- }
71
- function getExtendedSelectionAction(isSelected, shiftDown, ctrlDown) {
72
- if (shiftDown) {
73
- return { select: "range", type: "replace" };
74
- }
75
- if (ctrlDown) {
76
- return { select: "node", type: isSelected ? "add" : "remove" };
77
- }
78
- return { select: "node", type: isSelected ? "replace" : "disabled" };
79
- }
80
- function computeFlatNodeList(rootNodes) {
81
- const flatNodeList = [];
82
- const nodeIdToIndexMap = new Map();
83
- const flattenNodeRecursively = (nodes) => {
84
- nodes.forEach((node) => {
85
- if (!isPresentationHierarchyNode(node)) {
86
- return;
87
- }
88
- nodeIdToIndexMap.set(node.id, flatNodeList.length);
89
- flatNodeList.push(node.id);
90
- if (node.isExpanded && typeof node.children !== "boolean") {
91
- flattenNodeRecursively(node.children);
92
- }
93
- });
94
- };
95
- flattenNodeRecursively(rootNodes);
96
- return { flatNodeList, nodeIdToIndexMap };
97
- }
98
- //# sourceMappingURL=UseSelectionHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseSelectionHandler.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAmD,MAAM,eAAe,CAAC;AAiD7G;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IACxD,MAAM,oBAAoB,GAAG,MAAM,CAAqB,SAAS,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,MAAM,CAAgB;QAClC,YAAY,EAAE,EAAE;QAChB,gBAAgB,EAAE,IAAI,GAAG,EAAE;KAC5B,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QACD,KAAK,CAAC,OAAO,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACjD,C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CAAC,EAAE,CAAC,CAAC;YAC3B,IAAI,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC1D,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAC5C,CAAC","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\nimport { useCallback, useEffect, useRef } from \"react\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { useTree } from \"./UseTree.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @public\n */\ntype UseSelectionHandlerProps = Pick<ReturnType<typeof useTree>, \"rootNodes\" | \"selectNodes\"> & {\n /** Selection mode that the component is working in. */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @public\n */\ninterface UseSelectionHandlerResult {\n /** Should be called by node renderer when a node component is clicked. */\n onNodeClick: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Should be called by node renderer when a keyboard event happens on a node. */\n onNodeKeyDown: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @public\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n if (!rootNodes) {\n return;\n }\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const onNodeSelect = useCallback(\n (nodeId: string, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n const onNodeClick = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n },\n [onNodeSelect],\n );\n\n const onNodeKeyDown = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => {\n if (event.key === \" \" || event.key === \"Spacebar\" || event.key === \"Enter\") {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n }\n },\n [onNodeSelect],\n );\n\n return { onNodeClick, onNodeKeyDown };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"replace\" : \"remove\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n }\n return { select: \"node\", type: isSelected ? \"replace\" : \"disabled\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<PresentationTreeNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"]}