@itwin/presentation-frontend 3.4.0-dev.9 → 3.4.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  3. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +47 -47
  4. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  5. package/lib/cjs/presentation-frontend/Diagnostics.d.ts +14 -12
  6. package/lib/cjs/presentation-frontend/Diagnostics.d.ts.map +1 -1
  7. package/lib/cjs/presentation-frontend/Diagnostics.js +61 -59
  8. package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
  9. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  10. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +20 -20
  11. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  13. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +42 -42
  14. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  15. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -14
  16. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts.map +1 -1
  17. package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -57
  18. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  19. package/lib/cjs/presentation-frontend/Presentation.d.ts +75 -75
  20. package/lib/cjs/presentation-frontend/Presentation.js +162 -162
  21. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  22. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +180 -179
  23. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  24. package/lib/cjs/presentation-frontend/PresentationManager.js +419 -413
  25. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  26. package/lib/cjs/presentation-frontend/RulesetManager.d.ts +60 -60
  27. package/lib/cjs/presentation-frontend/RulesetManager.js +85 -85
  28. package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
  29. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  30. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
  31. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  32. package/lib/cjs/presentation-frontend/StateTracker.d.ts +23 -23
  33. package/lib/cjs/presentation-frontend/StateTracker.js +74 -74
  34. package/lib/cjs/presentation-frontend/StateTracker.js.map +1 -1
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +525 -525
  37. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  38. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  39. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +293 -293
  40. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  41. package/lib/cjs/presentation-frontend/selection/HiliteRules.json +172 -172
  42. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  43. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
  44. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  45. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  46. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
  47. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  48. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  49. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
  50. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  51. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  52. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
  53. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  54. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +14 -14
  55. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +37 -37
  56. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  57. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  58. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
  59. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  60. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  61. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
  62. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  63. package/lib/cjs/presentation-frontend.d.ts +34 -34
  64. package/lib/cjs/presentation-frontend.js +50 -50
  65. package/lib/cjs/presentation-frontend.js.map +1 -1
  66. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  67. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
  68. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  69. package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -12
  70. package/lib/esm/presentation-frontend/Diagnostics.d.ts.map +1 -1
  71. package/lib/esm/presentation-frontend/Diagnostics.js +56 -54
  72. package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
  73. package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  74. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
  75. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  76. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  77. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +38 -38
  78. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  79. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -14
  80. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts.map +1 -1
  81. package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -53
  82. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  83. package/lib/esm/presentation-frontend/Presentation.d.ts +75 -75
  84. package/lib/esm/presentation-frontend/Presentation.js +158 -158
  85. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  86. package/lib/esm/presentation-frontend/PresentationManager.d.ts +180 -179
  87. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  88. package/lib/esm/presentation-frontend/PresentationManager.js +414 -408
  89. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  90. package/lib/esm/presentation-frontend/RulesetManager.d.ts +60 -60
  91. package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
  92. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  93. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  94. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
  95. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  96. package/lib/esm/presentation-frontend/StateTracker.d.ts +23 -23
  97. package/lib/esm/presentation-frontend/StateTracker.js +70 -70
  98. package/lib/esm/presentation-frontend/StateTracker.js.map +1 -1
  99. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  100. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -519
  101. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  102. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  103. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +285 -285
  104. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  105. package/lib/esm/presentation-frontend/selection/HiliteRules.json +172 -172
  106. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  107. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
  108. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  109. package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  110. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
  111. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  112. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  113. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
  114. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  115. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  116. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
  117. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  118. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +14 -14
  119. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +33 -33
  120. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  121. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  122. package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
  123. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  124. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  125. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
  126. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  127. package/lib/esm/presentation-frontend.d.ts +34 -34
  128. package/lib/esm/presentation-frontend.js +38 -38
  129. package/lib/esm/presentation-frontend.js.map +1 -1
  130. package/package.json +15 -15
@@ -1,196 +1,196 @@
1
- "use strict";
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
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.RulesetVariablesManagerImpl = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const presentation_common_1 = require("@itwin/presentation-common");
13
- /** @internal */
14
- class RulesetVariablesManagerImpl {
15
- constructor(rulesetId, ipcHandler) {
16
- this._clientValues = new Map();
17
- this.onVariableChanged = new core_bentley_1.BeEvent();
18
- this._rulesetId = rulesetId;
19
- this._ipcHandler = ipcHandler;
20
- }
21
- getAllVariables() {
22
- const variables = [];
23
- for (const entry of this._clientValues)
24
- variables.push(entry[1]);
25
- return variables;
26
- }
27
- changeValueType(variable, toType) {
28
- switch (toType) {
29
- case presentation_common_1.VariableValueTypes.Bool:
30
- switch (variable.type) {
31
- case presentation_common_1.VariableValueTypes.Int: return (0 !== variable.value);
32
- case presentation_common_1.VariableValueTypes.Id64: return core_bentley_1.Id64.isValidId64(variable.value);
33
- default: return undefined;
34
- }
35
- case presentation_common_1.VariableValueTypes.Int:
36
- switch (variable.type) {
37
- case presentation_common_1.VariableValueTypes.Bool: return variable.value ? 1 : 0;
38
- case presentation_common_1.VariableValueTypes.Id64: return core_bentley_1.Id64.getUpperUint32(variable.value);
39
- default: return undefined;
40
- }
41
- case presentation_common_1.VariableValueTypes.IntArray:
42
- switch (variable.type) {
43
- case presentation_common_1.VariableValueTypes.Id64Array: return variable.value.map((id) => core_bentley_1.Id64.getUpperUint32(id));
44
- default: return undefined;
45
- }
46
- case presentation_common_1.VariableValueTypes.Id64:
47
- switch (variable.type) {
48
- case presentation_common_1.VariableValueTypes.Bool: return core_bentley_1.Id64.fromLocalAndBriefcaseIds(variable.value ? 1 : 0, 0);
49
- case presentation_common_1.VariableValueTypes.Int: return core_bentley_1.Id64.fromLocalAndBriefcaseIds(variable.value, 0);
50
- default: return undefined;
51
- }
52
- case presentation_common_1.VariableValueTypes.Id64Array:
53
- switch (variable.type) {
54
- case presentation_common_1.VariableValueTypes.IntArray: return variable.value.map((int) => core_bentley_1.Id64.fromLocalAndBriefcaseIds(int, 0));
55
- default: return undefined;
56
- }
57
- case presentation_common_1.VariableValueTypes.String:
58
- switch (variable.type) {
59
- case presentation_common_1.VariableValueTypes.IntArray:
60
- case presentation_common_1.VariableValueTypes.Id64Array:
61
- return undefined;
62
- default: variable.value.toString();
63
- }
64
- }
65
- return undefined;
66
- }
67
- async getValue(id, type) {
68
- const variable = this._clientValues.get(id);
69
- if (!variable)
70
- return undefined;
71
- if (variable.type !== type)
72
- return this.changeValueType(variable, type);
73
- return variable.value;
74
- }
75
- async setValue(variable) {
76
- const oldVariable = this._clientValues.get(variable.id);
77
- if (oldVariable && variablesEqual(oldVariable, variable))
78
- return;
79
- this._clientValues.set(variable.id, variable);
80
- if (this._ipcHandler) {
81
- await this._ipcHandler.setRulesetVariable({ rulesetId: this._rulesetId, variable });
82
- }
83
- this.onVariableChanged.raiseEvent(variable.id, oldVariable === null || oldVariable === void 0 ? void 0 : oldVariable.value, variable.value);
84
- }
85
- async unset(variableId) {
86
- const variable = this._clientValues.get(variableId);
87
- if (variable === undefined)
88
- return;
89
- this._clientValues.delete(variable.id);
90
- if (this._ipcHandler) {
91
- await this._ipcHandler.unsetRulesetVariable({ rulesetId: this._rulesetId, variableId });
92
- }
93
- this.onVariableChanged.raiseEvent(variable.id, variable.value, undefined);
94
- }
95
- /**
96
- * Retrieves `string` variable value.
97
- * Returns empty string if variable does not exist or does not convert to string.
98
- */
99
- async getString(variableId) {
100
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.String) || "";
101
- }
102
- /**
103
- * Sets `string` variable value
104
- */
105
- async setString(variableId, value) {
106
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.String, value });
107
- }
108
- /**
109
- * Retrieves `boolean` variable value.
110
- * Returns `false` if variable does not exist or does not convert to boolean.
111
- */
112
- async getBool(variableId) {
113
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Bool) || false;
114
- }
115
- /**
116
- * Sets `boolean` variable value
117
- */
118
- async setBool(variableId, value) {
119
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Bool, value });
120
- }
121
- /**
122
- * Retrieves `number` variable value.
123
- * Returns `0` if variable does not exist or does not convert to integer.
124
- */
125
- async getInt(variableId) {
126
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Int) || 0;
127
- }
128
- /**
129
- * Sets `number` variable value
130
- */
131
- async setInt(variableId, value) {
132
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Int, value });
133
- }
134
- /**
135
- * Retrieves `number[]` variable value.
136
- * Returns empty array if variable does not exist or does not convert to integer array.
137
- */
138
- async getInts(variableId) {
139
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.IntArray) || [];
140
- }
141
- /**
142
- * Sets `number[]` variable value
143
- */
144
- async setInts(variableId, value) {
145
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.IntArray, value: [...value] });
146
- }
147
- /**
148
- * Retrieves `Id64String` variable value.
149
- * Returns invalid Id64String if variable does not exist or does not convert to Id64String.
150
- */
151
- async getId64(variableId) {
152
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Id64) || core_bentley_1.Id64.invalid;
153
- }
154
- /**
155
- * Sets `Id64String` variable value
156
- */
157
- async setId64(variableId, value) {
158
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Id64, value });
159
- }
160
- /**
161
- * Retrieves `Id64String[]` variable value.
162
- * Returns empty array if variable does not exist or does not convert to Id64String array.
163
- */
164
- async getId64s(variableId) {
165
- return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Id64Array) || [];
166
- }
167
- /**
168
- * Sets `Id64String[]` variable value
169
- */
170
- async setId64s(variableId, value) {
171
- await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Id64Array, value: [...core_bentley_1.OrderedId64Iterable.sortArray(value)] });
172
- }
173
- }
174
- exports.RulesetVariablesManagerImpl = RulesetVariablesManagerImpl;
175
- function variablesEqual(lhs, rhs) {
176
- if (lhs.type !== rhs.type)
177
- return false;
178
- switch (lhs.type) {
179
- case presentation_common_1.VariableValueTypes.IntArray:
180
- case presentation_common_1.VariableValueTypes.Id64Array:
181
- (0, core_bentley_1.assert)(rhs.type === lhs.type);
182
- return arraysEqual(lhs.value, rhs.value);
183
- default:
184
- return lhs.value === rhs.value;
185
- }
186
- }
187
- function arraysEqual(lhs, rhs) {
188
- if (lhs.length !== rhs.length)
189
- return false;
190
- for (let i = 0; i < lhs.length; ++i) {
191
- if (lhs[i] !== rhs[i])
192
- return false;
193
- }
194
- return true;
195
- }
1
+ "use strict";
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
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.RulesetVariablesManagerImpl = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const presentation_common_1 = require("@itwin/presentation-common");
13
+ /** @internal */
14
+ class RulesetVariablesManagerImpl {
15
+ constructor(rulesetId, ipcHandler) {
16
+ this._clientValues = new Map();
17
+ this.onVariableChanged = new core_bentley_1.BeEvent();
18
+ this._rulesetId = rulesetId;
19
+ this._ipcHandler = ipcHandler;
20
+ }
21
+ getAllVariables() {
22
+ const variables = [];
23
+ for (const entry of this._clientValues)
24
+ variables.push(entry[1]);
25
+ return variables;
26
+ }
27
+ changeValueType(variable, toType) {
28
+ switch (toType) {
29
+ case presentation_common_1.VariableValueTypes.Bool:
30
+ switch (variable.type) {
31
+ case presentation_common_1.VariableValueTypes.Int: return (0 !== variable.value);
32
+ case presentation_common_1.VariableValueTypes.Id64: return core_bentley_1.Id64.isValidId64(variable.value);
33
+ default: return undefined;
34
+ }
35
+ case presentation_common_1.VariableValueTypes.Int:
36
+ switch (variable.type) {
37
+ case presentation_common_1.VariableValueTypes.Bool: return variable.value ? 1 : 0;
38
+ case presentation_common_1.VariableValueTypes.Id64: return core_bentley_1.Id64.getUpperUint32(variable.value);
39
+ default: return undefined;
40
+ }
41
+ case presentation_common_1.VariableValueTypes.IntArray:
42
+ switch (variable.type) {
43
+ case presentation_common_1.VariableValueTypes.Id64Array: return variable.value.map((id) => core_bentley_1.Id64.getUpperUint32(id));
44
+ default: return undefined;
45
+ }
46
+ case presentation_common_1.VariableValueTypes.Id64:
47
+ switch (variable.type) {
48
+ case presentation_common_1.VariableValueTypes.Bool: return core_bentley_1.Id64.fromLocalAndBriefcaseIds(variable.value ? 1 : 0, 0);
49
+ case presentation_common_1.VariableValueTypes.Int: return core_bentley_1.Id64.fromLocalAndBriefcaseIds(variable.value, 0);
50
+ default: return undefined;
51
+ }
52
+ case presentation_common_1.VariableValueTypes.Id64Array:
53
+ switch (variable.type) {
54
+ case presentation_common_1.VariableValueTypes.IntArray: return variable.value.map((int) => core_bentley_1.Id64.fromLocalAndBriefcaseIds(int, 0));
55
+ default: return undefined;
56
+ }
57
+ case presentation_common_1.VariableValueTypes.String:
58
+ switch (variable.type) {
59
+ case presentation_common_1.VariableValueTypes.IntArray:
60
+ case presentation_common_1.VariableValueTypes.Id64Array:
61
+ return undefined;
62
+ default: variable.value.toString();
63
+ }
64
+ }
65
+ return undefined;
66
+ }
67
+ async getValue(id, type) {
68
+ const variable = this._clientValues.get(id);
69
+ if (!variable)
70
+ return undefined;
71
+ if (variable.type !== type)
72
+ return this.changeValueType(variable, type);
73
+ return variable.value;
74
+ }
75
+ async setValue(variable) {
76
+ const oldVariable = this._clientValues.get(variable.id);
77
+ if (oldVariable && variablesEqual(oldVariable, variable))
78
+ return;
79
+ this._clientValues.set(variable.id, variable);
80
+ if (this._ipcHandler) {
81
+ await this._ipcHandler.setRulesetVariable({ rulesetId: this._rulesetId, variable });
82
+ }
83
+ this.onVariableChanged.raiseEvent(variable.id, oldVariable === null || oldVariable === void 0 ? void 0 : oldVariable.value, variable.value);
84
+ }
85
+ async unset(variableId) {
86
+ const variable = this._clientValues.get(variableId);
87
+ if (variable === undefined)
88
+ return;
89
+ this._clientValues.delete(variable.id);
90
+ if (this._ipcHandler) {
91
+ await this._ipcHandler.unsetRulesetVariable({ rulesetId: this._rulesetId, variableId });
92
+ }
93
+ this.onVariableChanged.raiseEvent(variable.id, variable.value, undefined);
94
+ }
95
+ /**
96
+ * Retrieves `string` variable value.
97
+ * Returns empty string if variable does not exist or does not convert to string.
98
+ */
99
+ async getString(variableId) {
100
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.String) || "";
101
+ }
102
+ /**
103
+ * Sets `string` variable value
104
+ */
105
+ async setString(variableId, value) {
106
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.String, value });
107
+ }
108
+ /**
109
+ * Retrieves `boolean` variable value.
110
+ * Returns `false` if variable does not exist or does not convert to boolean.
111
+ */
112
+ async getBool(variableId) {
113
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Bool) || false;
114
+ }
115
+ /**
116
+ * Sets `boolean` variable value
117
+ */
118
+ async setBool(variableId, value) {
119
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Bool, value });
120
+ }
121
+ /**
122
+ * Retrieves `number` variable value.
123
+ * Returns `0` if variable does not exist or does not convert to integer.
124
+ */
125
+ async getInt(variableId) {
126
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Int) || 0;
127
+ }
128
+ /**
129
+ * Sets `number` variable value
130
+ */
131
+ async setInt(variableId, value) {
132
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Int, value });
133
+ }
134
+ /**
135
+ * Retrieves `number[]` variable value.
136
+ * Returns empty array if variable does not exist or does not convert to integer array.
137
+ */
138
+ async getInts(variableId) {
139
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.IntArray) || [];
140
+ }
141
+ /**
142
+ * Sets `number[]` variable value
143
+ */
144
+ async setInts(variableId, value) {
145
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.IntArray, value: [...value] });
146
+ }
147
+ /**
148
+ * Retrieves `Id64String` variable value.
149
+ * Returns invalid Id64String if variable does not exist or does not convert to Id64String.
150
+ */
151
+ async getId64(variableId) {
152
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Id64) || core_bentley_1.Id64.invalid;
153
+ }
154
+ /**
155
+ * Sets `Id64String` variable value
156
+ */
157
+ async setId64(variableId, value) {
158
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Id64, value });
159
+ }
160
+ /**
161
+ * Retrieves `Id64String[]` variable value.
162
+ * Returns empty array if variable does not exist or does not convert to Id64String array.
163
+ */
164
+ async getId64s(variableId) {
165
+ return await this.getValue(variableId, presentation_common_1.VariableValueTypes.Id64Array) || [];
166
+ }
167
+ /**
168
+ * Sets `Id64String[]` variable value
169
+ */
170
+ async setId64s(variableId, value) {
171
+ await this.setValue({ id: variableId, type: presentation_common_1.VariableValueTypes.Id64Array, value: [...core_bentley_1.OrderedId64Iterable.sortArray(value)] });
172
+ }
173
+ }
174
+ exports.RulesetVariablesManagerImpl = RulesetVariablesManagerImpl;
175
+ function variablesEqual(lhs, rhs) {
176
+ if (lhs.type !== rhs.type)
177
+ return false;
178
+ switch (lhs.type) {
179
+ case presentation_common_1.VariableValueTypes.IntArray:
180
+ case presentation_common_1.VariableValueTypes.Id64Array:
181
+ (0, core_bentley_1.assert)(rhs.type === lhs.type);
182
+ return arraysEqual(lhs.value, rhs.value);
183
+ default:
184
+ return lhs.value === rhs.value;
185
+ }
186
+ }
187
+ function arraysEqual(lhs, rhs) {
188
+ if (lhs.length !== rhs.length)
189
+ return false;
190
+ for (let i = 0; i < lhs.length; ++i) {
191
+ if (lhs[i] !== rhs[i])
192
+ return false;
193
+ }
194
+ return true;
195
+ }
196
196
  //# sourceMappingURL=RulesetVariablesManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RulesetVariablesManager.js","sourceRoot":"","sources":["../../../src/presentation-frontend/RulesetVariablesManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6F;AAC7F,oEAAgG;AAmFhG,gBAAgB;AAChB,MAAa,2BAA2B;IAOtC,YAAmB,SAAiB,EAAE,UAA+B;QAL7D,kBAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;QAGpD,sBAAiB,GAAG,IAAI,sBAAO,EAA4G,CAAC;QAGjJ,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAEM,eAAe;QACpB,MAAM,SAAS,GAAsB,EAAE,CAAC;QACxC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa;YACpC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,eAAe,CAAC,QAAyB,EAAE,MAA0B;QAC3E,QAAQ,MAAM,EAAE;YACd,KAAK,wCAAkB,CAAC,IAAI;gBAC1B,QAAQ,QAAQ,CAAC,IAAI,EAAE;oBACrB,KAAK,wCAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAC3D,KAAK,wCAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,mBAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACtE,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC;iBAC3B;YACH,KAAK,wCAAkB,CAAC,GAAG;gBACzB,QAAQ,QAAQ,CAAC,IAAI,EAAE;oBACrB,KAAK,wCAAkB,CAAC,IAAI,CAAC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I,CAAC;AACd,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { assert, BeEvent, Id64, Id64String, OrderedId64Iterable } from \"@itwin/core-bentley\";\r\nimport { RulesetVariable, VariableValue, VariableValueTypes } from \"@itwin/presentation-common\";\r\nimport { IpcRequestsHandler } from \"./IpcRequestsHandler\";\r\n\r\n/**\r\n * Presentation ruleset variables' registry.\r\n * @public\r\n */\r\nexport interface RulesetVariablesManager {\r\n\r\n /**\r\n * An event that is raised when variable changes.\r\n */\r\n onVariableChanged: BeEvent<(variableId: string, prevValue: VariableValue | undefined, currValue: VariableValue | undefined) => void>;\r\n\r\n /**\r\n * Retrieves `string` variable value.\r\n * Returns empty string if variable does not exist or does not convert to string.\r\n */\r\n getString(variableId: string): Promise<string>;\r\n /**\r\n * Sets `string` variable value\r\n */\r\n setString(variableId: string, value: string): Promise<void>;\r\n\r\n /**\r\n * Retrieves `boolean` variable value.\r\n * Returns `false` if variable does not exist or does not convert to boolean.\r\n */\r\n getBool(variableId: string): Promise<boolean>;\r\n /**\r\n * Sets `boolean` variable value\r\n */\r\n setBool(variableId: string, value: boolean): Promise<void>;\r\n\r\n /**\r\n * Retrieves `number` variable value.\r\n * Returns `0` if variable does not exist or does not convert to integer.\r\n */\r\n getInt(variableId: string): Promise<number>;\r\n /**\r\n * Sets `number` variable value\r\n */\r\n setInt(variableId: string, value: number): Promise<void>;\r\n\r\n /**\r\n * Retrieves `number[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to integer array.\r\n */\r\n getInts(variableId: string): Promise<number[]>;\r\n /**\r\n * Sets `number[]` variable value\r\n */\r\n setInts(variableId: string, value: number[]): Promise<void>;\r\n\r\n /**\r\n * Retrieves `Id64String` variable value.\r\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\r\n */\r\n getId64(variableId: string): Promise<Id64String>;\r\n /**\r\n * Sets `Id64String` variable value\r\n */\r\n setId64(variableId: string, value: Id64String): Promise<void>;\r\n\r\n /**\r\n * Retrieves `Id64String[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to Id64String array.\r\n */\r\n getId64s(variableId: string): Promise<Id64String[]>;\r\n /**\r\n * Sets `Id64String[]` variable value\r\n */\r\n setId64s(variableId: string, value: Id64String[]): Promise<void>;\r\n\r\n /** Unsets variable with given id. */\r\n unset(variableId: string): Promise<void>;\r\n\r\n /** Retrieves all variables.\r\n * @internal\r\n */\r\n getAllVariables(): RulesetVariable[];\r\n}\r\n\r\n/** @internal */\r\nexport class RulesetVariablesManagerImpl implements RulesetVariablesManager {\r\n\r\n private _clientValues = new Map<string, RulesetVariable>();\r\n private _rulesetId: string;\r\n private _ipcHandler?: IpcRequestsHandler;\r\n public onVariableChanged = new BeEvent<(variableId: string, prevValue: VariableValue | undefined, currValue: VariableValue | undefined) => void>();\r\n\r\n public constructor(rulesetId: string, ipcHandler?: IpcRequestsHandler) {\r\n this._rulesetId = rulesetId;\r\n this._ipcHandler = ipcHandler;\r\n }\r\n\r\n public getAllVariables(): RulesetVariable[] {\r\n const variables: RulesetVariable[] = [];\r\n for (const entry of this._clientValues)\r\n variables.push(entry[1]);\r\n return variables;\r\n }\r\n\r\n private changeValueType(variable: RulesetVariable, toType: VariableValueTypes): VariableValue | undefined {\r\n switch (toType) {\r\n case VariableValueTypes.Bool:\r\n switch (variable.type) {\r\n case VariableValueTypes.Int: return (0 !== variable.value);\r\n case VariableValueTypes.Id64: return Id64.isValidId64(variable.value);\r\n default: return undefined;\r\n }\r\n case VariableValueTypes.Int:\r\n switch (variable.type) {\r\n case VariableValueTypes.Bool: return variable.value ? 1 : 0;\r\n case VariableValueTypes.Id64: return Id64.getUpperUint32(variable.value);\r\n default: return undefined;\r\n }\r\n case VariableValueTypes.IntArray:\r\n switch (variable.type) {\r\n case VariableValueTypes.Id64Array: return variable.value.map((id) => Id64.getUpperUint32(id));\r\n default: return undefined;\r\n }\r\n case VariableValueTypes.Id64:\r\n switch (variable.type) {\r\n case VariableValueTypes.Bool: return Id64.fromLocalAndBriefcaseIds(variable.value ? 1 : 0, 0);\r\n case VariableValueTypes.Int: return Id64.fromLocalAndBriefcaseIds(variable.value, 0);\r\n default: return undefined;\r\n }\r\n case VariableValueTypes.Id64Array:\r\n switch (variable.type) {\r\n case VariableValueTypes.IntArray: return variable.value.map((int) => Id64.fromLocalAndBriefcaseIds(int, 0));\r\n default: return undefined;\r\n }\r\n case VariableValueTypes.String:\r\n switch (variable.type) {\r\n case VariableValueTypes.IntArray:\r\n case VariableValueTypes.Id64Array:\r\n return undefined;\r\n default: variable.value.toString();\r\n }\r\n }\r\n return undefined;\r\n }\r\n\r\n private async getValue(id: string, type: VariableValueTypes): Promise<VariableValue | undefined> {\r\n const variable = this._clientValues.get(id);\r\n if (!variable)\r\n return undefined;\r\n if (variable.type !== type)\r\n return this.changeValueType(variable, type);\r\n return variable.value;\r\n }\r\n\r\n private async setValue(variable: RulesetVariable): Promise<void> {\r\n const oldVariable = this._clientValues.get(variable.id);\r\n if (oldVariable && variablesEqual(oldVariable, variable))\r\n return;\r\n\r\n this._clientValues.set(variable.id, variable);\r\n if (this._ipcHandler) {\r\n await this._ipcHandler.setRulesetVariable({ rulesetId: this._rulesetId, variable });\r\n }\r\n\r\n this.onVariableChanged.raiseEvent(variable.id, oldVariable?.value, variable.value);\r\n }\r\n\r\n public async unset(variableId: string): Promise<void> {\r\n const variable = this._clientValues.get(variableId);\r\n if (variable === undefined)\r\n return;\r\n\r\n this._clientValues.delete(variable.id);\r\n if (this._ipcHandler) {\r\n await this._ipcHandler.unsetRulesetVariable({ rulesetId: this._rulesetId, variableId });\r\n }\r\n this.onVariableChanged.raiseEvent(variable.id, variable.value, undefined);\r\n }\r\n\r\n /**\r\n * Retrieves `string` variable value.\r\n * Returns empty string if variable does not exist or does not convert to string.\r\n */\r\n public async getString(variableId: string): Promise<string> {\r\n return (await this.getValue(variableId, VariableValueTypes.String) as string) || \"\";\r\n }\r\n\r\n /**\r\n * Sets `string` variable value\r\n */\r\n public async setString(variableId: string, value: string): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.String, value });\r\n }\r\n\r\n /**\r\n * Retrieves `boolean` variable value.\r\n * Returns `false` if variable does not exist or does not convert to boolean.\r\n */\r\n public async getBool(variableId: string): Promise<boolean> {\r\n return (await this.getValue(variableId, VariableValueTypes.Bool) as boolean) || false;\r\n }\r\n\r\n /**\r\n * Sets `boolean` variable value\r\n */\r\n public async setBool(variableId: string, value: boolean): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.Bool, value });\r\n }\r\n\r\n /**\r\n * Retrieves `number` variable value.\r\n * Returns `0` if variable does not exist or does not convert to integer.\r\n */\r\n public async getInt(variableId: string): Promise<number> {\r\n return (await this.getValue(variableId, VariableValueTypes.Int) as number) || 0;\r\n }\r\n\r\n /**\r\n * Sets `number` variable value\r\n */\r\n public async setInt(variableId: string, value: number): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.Int, value });\r\n }\r\n\r\n /**\r\n * Retrieves `number[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to integer array.\r\n */\r\n public async getInts(variableId: string): Promise<number[]> {\r\n return (await this.getValue(variableId, VariableValueTypes.IntArray) as number[]) || [];\r\n }\r\n\r\n /**\r\n * Sets `number[]` variable value\r\n */\r\n public async setInts(variableId: string, value: number[]): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.IntArray, value: [...value] });\r\n }\r\n\r\n /**\r\n * Retrieves `Id64String` variable value.\r\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\r\n */\r\n public async getId64(variableId: string): Promise<Id64String> {\r\n return (await this.getValue(variableId, VariableValueTypes.Id64) as Id64String) || Id64.invalid;\r\n }\r\n\r\n /**\r\n * Sets `Id64String` variable value\r\n */\r\n public async setId64(variableId: string, value: Id64String): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.Id64, value });\r\n }\r\n\r\n /**\r\n * Retrieves `Id64String[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to Id64String array.\r\n */\r\n public async getId64s(variableId: string): Promise<Id64String[]> {\r\n return (await this.getValue(variableId, VariableValueTypes.Id64Array) as Id64String[]) || [];\r\n }\r\n\r\n /**\r\n * Sets `Id64String[]` variable value\r\n */\r\n public async setId64s(variableId: string, value: Id64String[]): Promise<void> {\r\n await this.setValue({ id: variableId, type: VariableValueTypes.Id64Array, value: [...OrderedId64Iterable.sortArray(value)] });\r\n }\r\n}\r\n\r\nfunction variablesEqual(lhs: RulesetVariable, rhs: RulesetVariable) {\r\n if (lhs.type !== rhs.type)\r\n return false;\r\n\r\n switch (lhs.type) {\r\n case VariableValueTypes.IntArray:\r\n case VariableValueTypes.Id64Array:\r\n assert(rhs.type === lhs.type);\r\n return arraysEqual(lhs.value, rhs.value);\r\n\r\n default:\r\n return lhs.value === rhs.value;\r\n }\r\n}\r\n\r\nfunction arraysEqual(lhs: any[], rhs: any[]) {\r\n if (lhs.length !== rhs.length)\r\n return false;\r\n\r\n for (let i = 0; i < lhs.length; ++i) {\r\n if (lhs[i] !== rhs[i])\r\n return false;\r\n }\r\n return true;\r\n}\r\n"]}
1
+ {"version":3,"file":"RulesetVariablesManager.js","sourceRoot":"","sources":["../../../src/presentation-frontend/RulesetVariablesManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6F;AAC7F,oEAAgG;AAmFhG,gBAAgB;AAChB,MAAa,2BAA2B;IAOtC,YAAmB,SAAiB,EAAE,UAA+B;QAL7D,kBAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;QAGpD,sBAAiB,GAAG,IAAI,sBAAO,EAA4G,CAAC;QAGjJ,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW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,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI;QACvB,OAAO,KAAK,CAAC;IAEf,QAAQ,GAAG,CAAC,IAAI,EAAE;QAChB,KAAK,wCAAkB,CAAC,QAAQ,CAAC;QACjC,KAAK,wCAAkB,CAAC,SAAS;YAC/B,IAAA,qBAAM,EAAC,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;YAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3C;YACE,OAAO,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,CAAC;KAClC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAU,EAAE,GAAU;IACzC,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;QAC3B,OAAO,KAAK,CAAC;IAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;KAChB;IACD,OAAO,IAAI,CAAC;AACd,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/** @packageDocumentation\n * @module Core\n */\n\nimport { assert, BeEvent, Id64, Id64String, OrderedId64Iterable } from \"@itwin/core-bentley\";\nimport { RulesetVariable, VariableValue, VariableValueTypes } from \"@itwin/presentation-common\";\nimport { IpcRequestsHandler } from \"./IpcRequestsHandler\";\n\n/**\n * Presentation ruleset variables' registry.\n * @public\n */\nexport interface RulesetVariablesManager {\n\n /**\n * An event that is raised when variable changes.\n */\n onVariableChanged: BeEvent<(variableId: string, prevValue: VariableValue | undefined, currValue: VariableValue | undefined) => void>;\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n getString(variableId: string): Promise<string>;\n /**\n * Sets `string` variable value\n */\n setString(variableId: string, value: string): Promise<void>;\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n getBool(variableId: string): Promise<boolean>;\n /**\n * Sets `boolean` variable value\n */\n setBool(variableId: string, value: boolean): Promise<void>;\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n getInt(variableId: string): Promise<number>;\n /**\n * Sets `number` variable value\n */\n setInt(variableId: string, value: number): Promise<void>;\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n getInts(variableId: string): Promise<number[]>;\n /**\n * Sets `number[]` variable value\n */\n setInts(variableId: string, value: number[]): Promise<void>;\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n getId64(variableId: string): Promise<Id64String>;\n /**\n * Sets `Id64String` variable value\n */\n setId64(variableId: string, value: Id64String): Promise<void>;\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n getId64s(variableId: string): Promise<Id64String[]>;\n /**\n * Sets `Id64String[]` variable value\n */\n setId64s(variableId: string, value: Id64String[]): Promise<void>;\n\n /** Unsets variable with given id. */\n unset(variableId: string): Promise<void>;\n\n /** Retrieves all variables.\n * @internal\n */\n getAllVariables(): RulesetVariable[];\n}\n\n/** @internal */\nexport class RulesetVariablesManagerImpl implements RulesetVariablesManager {\n\n private _clientValues = new Map<string, RulesetVariable>();\n private _rulesetId: string;\n private _ipcHandler?: IpcRequestsHandler;\n public onVariableChanged = new BeEvent<(variableId: string, prevValue: VariableValue | undefined, currValue: VariableValue | undefined) => void>();\n\n public constructor(rulesetId: string, ipcHandler?: IpcRequestsHandler) {\n this._rulesetId = rulesetId;\n this._ipcHandler = ipcHandler;\n }\n\n public getAllVariables(): RulesetVariable[] {\n const variables: RulesetVariable[] = [];\n for (const entry of this._clientValues)\n variables.push(entry[1]);\n return variables;\n }\n\n private changeValueType(variable: RulesetVariable, toType: VariableValueTypes): VariableValue | undefined {\n switch (toType) {\n case VariableValueTypes.Bool:\n switch (variable.type) {\n case VariableValueTypes.Int: return (0 !== variable.value);\n case VariableValueTypes.Id64: return Id64.isValidId64(variable.value);\n default: return undefined;\n }\n case VariableValueTypes.Int:\n switch (variable.type) {\n case VariableValueTypes.Bool: return variable.value ? 1 : 0;\n case VariableValueTypes.Id64: return Id64.getUpperUint32(variable.value);\n default: return undefined;\n }\n case VariableValueTypes.IntArray:\n switch (variable.type) {\n case VariableValueTypes.Id64Array: return variable.value.map((id) => Id64.getUpperUint32(id));\n default: return undefined;\n }\n case VariableValueTypes.Id64:\n switch (variable.type) {\n case VariableValueTypes.Bool: return Id64.fromLocalAndBriefcaseIds(variable.value ? 1 : 0, 0);\n case VariableValueTypes.Int: return Id64.fromLocalAndBriefcaseIds(variable.value, 0);\n default: return undefined;\n }\n case VariableValueTypes.Id64Array:\n switch (variable.type) {\n case VariableValueTypes.IntArray: return variable.value.map((int) => Id64.fromLocalAndBriefcaseIds(int, 0));\n default: return undefined;\n }\n case VariableValueTypes.String:\n switch (variable.type) {\n case VariableValueTypes.IntArray:\n case VariableValueTypes.Id64Array:\n return undefined;\n default: variable.value.toString();\n }\n }\n return undefined;\n }\n\n private async getValue(id: string, type: VariableValueTypes): Promise<VariableValue | undefined> {\n const variable = this._clientValues.get(id);\n if (!variable)\n return undefined;\n if (variable.type !== type)\n return this.changeValueType(variable, type);\n return variable.value;\n }\n\n private async setValue(variable: RulesetVariable): Promise<void> {\n const oldVariable = this._clientValues.get(variable.id);\n if (oldVariable && variablesEqual(oldVariable, variable))\n return;\n\n this._clientValues.set(variable.id, variable);\n if (this._ipcHandler) {\n await this._ipcHandler.setRulesetVariable({ rulesetId: this._rulesetId, variable });\n }\n\n this.onVariableChanged.raiseEvent(variable.id, oldVariable?.value, variable.value);\n }\n\n public async unset(variableId: string): Promise<void> {\n const variable = this._clientValues.get(variableId);\n if (variable === undefined)\n return;\n\n this._clientValues.delete(variable.id);\n if (this._ipcHandler) {\n await this._ipcHandler.unsetRulesetVariable({ rulesetId: this._rulesetId, variableId });\n }\n this.onVariableChanged.raiseEvent(variable.id, variable.value, undefined);\n }\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n public async getString(variableId: string): Promise<string> {\n return (await this.getValue(variableId, VariableValueTypes.String) as string) || \"\";\n }\n\n /**\n * Sets `string` variable value\n */\n public async setString(variableId: string, value: string): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.String, value });\n }\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n public async getBool(variableId: string): Promise<boolean> {\n return (await this.getValue(variableId, VariableValueTypes.Bool) as boolean) || false;\n }\n\n /**\n * Sets `boolean` variable value\n */\n public async setBool(variableId: string, value: boolean): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.Bool, value });\n }\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n public async getInt(variableId: string): Promise<number> {\n return (await this.getValue(variableId, VariableValueTypes.Int) as number) || 0;\n }\n\n /**\n * Sets `number` variable value\n */\n public async setInt(variableId: string, value: number): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.Int, value });\n }\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n public async getInts(variableId: string): Promise<number[]> {\n return (await this.getValue(variableId, VariableValueTypes.IntArray) as number[]) || [];\n }\n\n /**\n * Sets `number[]` variable value\n */\n public async setInts(variableId: string, value: number[]): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.IntArray, value: [...value] });\n }\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n public async getId64(variableId: string): Promise<Id64String> {\n return (await this.getValue(variableId, VariableValueTypes.Id64) as Id64String) || Id64.invalid;\n }\n\n /**\n * Sets `Id64String` variable value\n */\n public async setId64(variableId: string, value: Id64String): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.Id64, value });\n }\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n public async getId64s(variableId: string): Promise<Id64String[]> {\n return (await this.getValue(variableId, VariableValueTypes.Id64Array) as Id64String[]) || [];\n }\n\n /**\n * Sets `Id64String[]` variable value\n */\n public async setId64s(variableId: string, value: Id64String[]): Promise<void> {\n await this.setValue({ id: variableId, type: VariableValueTypes.Id64Array, value: [...OrderedId64Iterable.sortArray(value)] });\n }\n}\n\nfunction variablesEqual(lhs: RulesetVariable, rhs: RulesetVariable) {\n if (lhs.type !== rhs.type)\n return false;\n\n switch (lhs.type) {\n case VariableValueTypes.IntArray:\n case VariableValueTypes.Id64Array:\n assert(rhs.type === lhs.type);\n return arraysEqual(lhs.value, rhs.value);\n\n default:\n return lhs.value === rhs.value;\n }\n}\n\nfunction arraysEqual(lhs: any[], rhs: any[]) {\n if (lhs.length !== rhs.length)\n return false;\n\n for (let i = 0; i < lhs.length; ++i) {\n if (lhs[i] !== rhs[i])\n return false;\n }\n return true;\n}\n"]}
@@ -1,24 +1,24 @@
1
- /** @packageDocumentation
2
- * @module Core
3
- */
4
- import { IModelConnection } from "@itwin/core-frontend";
5
- import { NodeKey } from "@itwin/presentation-common";
6
- import { IpcRequestsHandler } from "./IpcRequestsHandler";
7
- /**
8
- * Data structure that describes information used by [[StateTracker]] to identify node.
9
- * @internal
10
- */
11
- export interface NodeIdentifier {
12
- id: string;
13
- key: NodeKey;
14
- }
15
- /** @internal */
16
- export declare class StateTracker {
17
- private _expandedHierarchies;
18
- private _ipcRequestsHandler;
19
- constructor(ipcRequestsHandler: IpcRequestsHandler);
20
- private updateHierarchyStateIfNeeded;
21
- onHierarchyClosed(imodel: IModelConnection, rulesetId: string, sourceId: string): Promise<void>;
22
- onExpandedNodesChanged(imodel: IModelConnection, rulesetId: string, sourceId: string, expandedNodes: NodeIdentifier[]): Promise<void>;
23
- }
1
+ /** @packageDocumentation
2
+ * @module Core
3
+ */
4
+ import { IModelConnection } from "@itwin/core-frontend";
5
+ import { NodeKey } from "@itwin/presentation-common";
6
+ import { IpcRequestsHandler } from "./IpcRequestsHandler";
7
+ /**
8
+ * Data structure that describes information used by [[StateTracker]] to identify node.
9
+ * @internal
10
+ */
11
+ export interface NodeIdentifier {
12
+ id: string;
13
+ key: NodeKey;
14
+ }
15
+ /** @internal */
16
+ export declare class StateTracker {
17
+ private _expandedHierarchies;
18
+ private _ipcRequestsHandler;
19
+ constructor(ipcRequestsHandler: IpcRequestsHandler);
20
+ private updateHierarchyStateIfNeeded;
21
+ onHierarchyClosed(imodel: IModelConnection, rulesetId: string, sourceId: string): Promise<void>;
22
+ onExpandedNodesChanged(imodel: IModelConnection, rulesetId: string, sourceId: string, expandedNodes: NodeIdentifier[]): Promise<void>;
23
+ }
24
24
  //# sourceMappingURL=StateTracker.d.ts.map