@itwin/presentation-frontend 4.0.0-dev.7 → 4.0.0-dev.72

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 (113) hide show
  1. package/CHANGELOG.md +45 -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 -14
  6. package/lib/cjs/presentation-frontend/Diagnostics.js +61 -61
  7. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  8. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +20 -20
  9. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  10. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +41 -41
  11. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -10
  12. package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -31
  13. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  14. package/lib/cjs/presentation-frontend/Presentation.d.ts +73 -75
  15. package/lib/cjs/presentation-frontend/Presentation.d.ts.map +1 -1
  16. package/lib/cjs/presentation-frontend/Presentation.js +159 -162
  17. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  18. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +205 -186
  19. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  20. package/lib/cjs/presentation-frontend/PresentationManager.js +438 -436
  21. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  22. package/lib/cjs/presentation-frontend/RulesetManager.d.ts +63 -63
  23. package/lib/cjs/presentation-frontend/RulesetManager.js +85 -85
  24. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  25. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
  26. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  27. package/lib/cjs/presentation-frontend/StateTracker.d.ts +38 -38
  28. package/lib/cjs/presentation-frontend/StateTracker.js +128 -129
  29. package/lib/cjs/presentation-frontend/StateTracker.js.map +1 -1
  30. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  31. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  32. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -518
  33. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  34. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +290 -293
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  37. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  38. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
  39. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  40. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
  41. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  42. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
  43. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  44. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
  45. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +17 -14
  46. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  47. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +40 -37
  48. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  49. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  50. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
  51. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  52. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  53. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
  54. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  55. package/lib/cjs/presentation-frontend.d.ts +34 -34
  56. package/lib/cjs/presentation-frontend.js +54 -50
  57. package/lib/cjs/presentation-frontend.js.map +1 -1
  58. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  59. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
  60. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  61. package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -14
  62. package/lib/esm/presentation-frontend/Diagnostics.js +56 -56
  63. package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  64. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
  65. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  66. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +37 -37
  67. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -10
  68. package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -27
  69. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  70. package/lib/esm/presentation-frontend/Presentation.d.ts +73 -75
  71. package/lib/esm/presentation-frontend/Presentation.d.ts.map +1 -1
  72. package/lib/esm/presentation-frontend/Presentation.js +155 -158
  73. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  74. package/lib/esm/presentation-frontend/PresentationManager.d.ts +205 -186
  75. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  76. package/lib/esm/presentation-frontend/PresentationManager.js +433 -431
  77. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  78. package/lib/esm/presentation-frontend/RulesetManager.d.ts +63 -63
  79. package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
  80. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  81. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
  82. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  83. package/lib/esm/presentation-frontend/StateTracker.d.ts +38 -38
  84. package/lib/esm/presentation-frontend/StateTracker.js +124 -125
  85. package/lib/esm/presentation-frontend/StateTracker.js.map +1 -1
  86. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  87. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  88. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +514 -512
  89. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  90. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  91. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +282 -285
  92. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  93. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  94. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
  95. package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  96. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
  97. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  98. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
  99. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  100. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
  101. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +17 -14
  102. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  103. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +36 -33
  104. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  105. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  106. package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
  107. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  109. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
  110. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  111. package/lib/esm/presentation-frontend.d.ts +34 -34
  112. package/lib/esm/presentation-frontend.js +38 -38
  113. package/package.json +20 -20
@@ -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?.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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AAK,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":["/*---------------------------------------------------------------------------------------------\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,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,CAAC,OAAO,QAAQ,CAAC,KAAK,CAAC,C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CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,CAAkB,IAAI,EAAE,CAAC;IAC/F,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,UAAkB,EAAE,KAAmB;QAC3D,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,wCAAkB,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,kCAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAChI,CAAC;CACF;AAvLD,kEAuLC;AAED,SAAS,cAAc,CAAC,GAAoB,EAAE,GAAoB;IAChE,IAAI,GAAG,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":["/*---------------------------------------------------------------------------------------------\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,39 +1,39 @@
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
- /**
16
- * @internal
17
- */
18
- export interface NodeState {
19
- isExpanded?: boolean;
20
- instanceFilter?: string;
21
- }
22
- /**
23
- * The tracker stores up-to-date UI state of the hierarchies on the frontend and reports
24
- * just the state changes to the backend as soon as component sends in a new hierarchy state.
25
- *
26
- * @internal
27
- */
28
- export declare class StateTracker {
29
- private _hierarchyStates;
30
- private _ipcRequestsHandler;
31
- constructor(ipcRequestsHandler: IpcRequestsHandler);
32
- private updateHierarchyStateIfNeeded;
33
- onHierarchyClosed(imodel: IModelConnection, rulesetId: string, sourceId: string): Promise<void>;
34
- onHierarchyStateChanged(imodel: IModelConnection, rulesetId: string, sourceId: string, newHierarchyState: Array<{
35
- node: NodeIdentifier | undefined;
36
- state: NodeState;
37
- }>): Promise<void>;
38
- }
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
+ /**
16
+ * @internal
17
+ */
18
+ export interface NodeState {
19
+ isExpanded?: boolean;
20
+ instanceFilter?: string;
21
+ }
22
+ /**
23
+ * The tracker stores up-to-date UI state of the hierarchies on the frontend and reports
24
+ * just the state changes to the backend as soon as component sends in a new hierarchy state.
25
+ *
26
+ * @internal
27
+ */
28
+ export declare class StateTracker {
29
+ private _hierarchyStates;
30
+ private _ipcRequestsHandler;
31
+ constructor(ipcRequestsHandler: IpcRequestsHandler);
32
+ private updateHierarchyStateIfNeeded;
33
+ onHierarchyClosed(imodel: IModelConnection, rulesetId: string, sourceId: string): Promise<void>;
34
+ onHierarchyStateChanged(imodel: IModelConnection, rulesetId: string, sourceId: string, newHierarchyState: Array<{
35
+ node: NodeIdentifier | undefined;
36
+ state: NodeState;
37
+ }>): Promise<void>;
38
+ }
39
39
  //# sourceMappingURL=StateTracker.d.ts.map