@itwin/components-react 4.3.0 → 4.4.0

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 (125) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/components-react/filter-builder/FilterBuilder.d.ts +23 -9
  3. package/lib/cjs/components-react/filter-builder/FilterBuilder.d.ts.map +1 -1
  4. package/lib/cjs/components-react/filter-builder/FilterBuilder.js +19 -8
  5. package/lib/cjs/components-react/filter-builder/FilterBuilder.js.map +1 -1
  6. package/lib/cjs/components-react/filter-builder/FilterBuilderContext.d.ts +8 -5
  7. package/lib/cjs/components-react/filter-builder/FilterBuilderContext.d.ts.map +1 -1
  8. package/lib/cjs/components-react/filter-builder/FilterBuilderContext.js +40 -18
  9. package/lib/cjs/components-react/filter-builder/FilterBuilderContext.js.map +1 -1
  10. package/lib/cjs/components-react/filter-builder/FilterBuilderRule.d.ts.map +1 -1
  11. package/lib/cjs/components-react/filter-builder/FilterBuilderRule.js +7 -4
  12. package/lib/cjs/components-react/filter-builder/FilterBuilderRule.js.map +1 -1
  13. package/lib/cjs/components-react/filter-builder/FilterBuilderRule.scss +8 -1
  14. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.d.ts.map +1 -1
  15. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.js +3 -2
  16. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.js.map +1 -1
  17. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.d.ts +1 -1
  18. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
  19. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.d.ts +11 -2
  20. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.d.ts.map +1 -1
  21. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js +2 -3
  22. package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
  23. package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts +49 -10
  24. package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
  25. package/lib/cjs/components-react/filter-builder/FilterBuilderState.js +106 -13
  26. package/lib/cjs/components-react/filter-builder/FilterBuilderState.js.map +1 -1
  27. package/lib/cjs/components-react/toolbar/InternalToolbarComponent.d.ts +144 -0
  28. package/lib/cjs/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -0
  29. package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js +550 -0
  30. package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js.map +1 -0
  31. package/lib/cjs/components-react/toolbar/ItemWrapper.js +3 -3
  32. package/lib/cjs/components-react/toolbar/ItemWrapper.js.map +1 -1
  33. package/lib/cjs/components-react/toolbar/Items.js +5 -5
  34. package/lib/cjs/components-react/toolbar/Items.js.map +1 -1
  35. package/lib/cjs/components-react/toolbar/Overflow.js +3 -3
  36. package/lib/cjs/components-react/toolbar/Overflow.js.map +1 -1
  37. package/lib/cjs/components-react/toolbar/OverflowPanel.js +5 -5
  38. package/lib/cjs/components-react/toolbar/OverflowPanel.js.map +1 -1
  39. package/lib/cjs/components-react/toolbar/PopupItem.js +4 -4
  40. package/lib/cjs/components-react/toolbar/PopupItem.js.map +1 -1
  41. package/lib/cjs/components-react/toolbar/PopupItemWithDrag.d.ts +1 -1
  42. package/lib/cjs/components-react/toolbar/PopupItemWithDrag.d.ts.map +1 -1
  43. package/lib/cjs/components-react/toolbar/PopupItemWithDrag.js +4 -4
  44. package/lib/cjs/components-react/toolbar/PopupItemWithDrag.js.map +1 -1
  45. package/lib/cjs/components-react/toolbar/PopupItemsPanel.js +2 -2
  46. package/lib/cjs/components-react/toolbar/PopupItemsPanel.js.map +1 -1
  47. package/lib/cjs/components-react/toolbar/Toolbar.d.ts +2 -2
  48. package/lib/cjs/components-react/toolbar/Toolbar.d.ts.map +1 -1
  49. package/lib/cjs/components-react/toolbar/Toolbar.js +2 -69
  50. package/lib/cjs/components-react/toolbar/Toolbar.js.map +1 -1
  51. package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.d.ts +5 -105
  52. package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.d.ts.map +1 -1
  53. package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.js +6 -481
  54. package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.js.map +1 -1
  55. package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.d.ts +14 -0
  56. package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.d.ts.map +1 -0
  57. package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js +119 -0
  58. package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js.map +1 -0
  59. package/lib/cjs/components-react.d.ts +6 -2
  60. package/lib/cjs/components-react.d.ts.map +1 -1
  61. package/lib/cjs/components-react.js +6 -2
  62. package/lib/cjs/components-react.js.map +1 -1
  63. package/lib/esm/components-react/filter-builder/FilterBuilder.d.ts +23 -9
  64. package/lib/esm/components-react/filter-builder/FilterBuilder.d.ts.map +1 -1
  65. package/lib/esm/components-react/filter-builder/FilterBuilder.js +17 -7
  66. package/lib/esm/components-react/filter-builder/FilterBuilder.js.map +1 -1
  67. package/lib/esm/components-react/filter-builder/FilterBuilderContext.d.ts +8 -5
  68. package/lib/esm/components-react/filter-builder/FilterBuilderContext.d.ts.map +1 -1
  69. package/lib/esm/components-react/filter-builder/FilterBuilderContext.js +40 -18
  70. package/lib/esm/components-react/filter-builder/FilterBuilderContext.js.map +1 -1
  71. package/lib/esm/components-react/filter-builder/FilterBuilderRule.d.ts.map +1 -1
  72. package/lib/esm/components-react/filter-builder/FilterBuilderRule.js +8 -5
  73. package/lib/esm/components-react/filter-builder/FilterBuilderRule.js.map +1 -1
  74. package/lib/esm/components-react/filter-builder/FilterBuilderRule.scss +8 -1
  75. package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.d.ts.map +1 -1
  76. package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.js +3 -2
  77. package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.js.map +1 -1
  78. package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.d.ts +1 -1
  79. package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
  80. package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.d.ts +11 -2
  81. package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.d.ts.map +1 -1
  82. package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js +2 -3
  83. package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
  84. package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts +49 -10
  85. package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
  86. package/lib/esm/components-react/filter-builder/FilterBuilderState.js +99 -7
  87. package/lib/esm/components-react/filter-builder/FilterBuilderState.js.map +1 -1
  88. package/lib/esm/components-react/toolbar/InternalToolbarComponent.d.ts +144 -0
  89. package/lib/esm/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -0
  90. package/lib/esm/components-react/toolbar/InternalToolbarComponent.js +514 -0
  91. package/lib/esm/components-react/toolbar/InternalToolbarComponent.js.map +1 -0
  92. package/lib/esm/components-react/toolbar/ItemWrapper.js +1 -1
  93. package/lib/esm/components-react/toolbar/ItemWrapper.js.map +1 -1
  94. package/lib/esm/components-react/toolbar/Items.js +1 -1
  95. package/lib/esm/components-react/toolbar/Items.js.map +1 -1
  96. package/lib/esm/components-react/toolbar/Overflow.js +1 -1
  97. package/lib/esm/components-react/toolbar/Overflow.js.map +1 -1
  98. package/lib/esm/components-react/toolbar/OverflowPanel.js +1 -1
  99. package/lib/esm/components-react/toolbar/OverflowPanel.js.map +1 -1
  100. package/lib/esm/components-react/toolbar/PopupItem.js +1 -1
  101. package/lib/esm/components-react/toolbar/PopupItem.js.map +1 -1
  102. package/lib/esm/components-react/toolbar/PopupItemWithDrag.d.ts +1 -1
  103. package/lib/esm/components-react/toolbar/PopupItemWithDrag.d.ts.map +1 -1
  104. package/lib/esm/components-react/toolbar/PopupItemWithDrag.js +1 -1
  105. package/lib/esm/components-react/toolbar/PopupItemWithDrag.js.map +1 -1
  106. package/lib/esm/components-react/toolbar/PopupItemsPanel.js +1 -1
  107. package/lib/esm/components-react/toolbar/PopupItemsPanel.js.map +1 -1
  108. package/lib/esm/components-react/toolbar/Toolbar.d.ts +2 -2
  109. package/lib/esm/components-react/toolbar/Toolbar.d.ts.map +1 -1
  110. package/lib/esm/components-react/toolbar/Toolbar.js +2 -66
  111. package/lib/esm/components-react/toolbar/Toolbar.js.map +1 -1
  112. package/lib/esm/components-react/toolbar/ToolbarWithOverflow.d.ts +5 -105
  113. package/lib/esm/components-react/toolbar/ToolbarWithOverflow.d.ts.map +1 -1
  114. package/lib/esm/components-react/toolbar/ToolbarWithOverflow.js +5 -471
  115. package/lib/esm/components-react/toolbar/ToolbarWithOverflow.js.map +1 -1
  116. package/lib/esm/components-react/toolbar/useConditionalSynchedItems.d.ts +14 -0
  117. package/lib/esm/components-react/toolbar/useConditionalSynchedItems.d.ts.map +1 -0
  118. package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js +92 -0
  119. package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js.map +1 -0
  120. package/lib/esm/components-react.d.ts +6 -2
  121. package/lib/esm/components-react.d.ts.map +1 -1
  122. package/lib/esm/components-react.js +6 -2
  123. package/lib/esm/components-react.js.map +1 -1
  124. package/lib/public/locales/en/UiComponents.json +4 -1
  125. package/package.json +8 -9
@@ -9,11 +9,13 @@ import { produce } from "immer";
9
9
  import * as React from "react";
10
10
  import { PropertyValueFormat } from "@itwin/appui-abstract";
11
11
  import { Guid } from "@itwin/core-bentley";
12
+ import { PropertyFilterRuleOperator } from "./Operators";
12
13
  import { isUnaryPropertyFilterOperator, PropertyFilterRuleGroupOperator, } from "./Operators";
13
14
  import { isPropertyFilterRuleGroup } from "./Types";
15
+ import { UiComponents } from "../UiComponents";
14
16
  /**
15
17
  * Actions for controlling [[PropertyFilterBuilder]] component state.
16
- * @internal
18
+ * @beta
17
19
  */
18
20
  export class PropertyFilterBuilderActions {
19
21
  constructor(setState) {
@@ -72,6 +74,7 @@ export class PropertyFilterBuilderActions {
72
74
  return;
73
75
  rule.property = property;
74
76
  rule.value = undefined;
77
+ rule.errorMessage = undefined;
75
78
  });
76
79
  }
77
80
  /** Sets operator of rule specified by the path. */
@@ -82,6 +85,10 @@ export class PropertyFilterBuilderActions {
82
85
  return;
83
86
  if (isUnaryPropertyFilterOperator(operator))
84
87
  rule.value = undefined;
88
+ if (operator !== rule.operator &&
89
+ !areOperatorsSimilar(operator, rule.operator)) {
90
+ rule.value = undefined;
91
+ }
85
92
  rule.operator = operator;
86
93
  });
87
94
  }
@@ -94,10 +101,29 @@ export class PropertyFilterBuilderActions {
94
101
  rule.value = value;
95
102
  });
96
103
  }
104
+ /**
105
+ * Sets error messages of the rules specified by id.
106
+ * If rule id is not present in the map, then its error message will be cleared.
107
+ */
108
+ setRuleErrorMessages(ruleIdsAndErrorMessages) {
109
+ this.updateState((state) => {
110
+ const setErrorMessages = (item) => {
111
+ if (isPropertyFilterBuilderRuleGroup(item)) {
112
+ item.items.forEach((itm) => {
113
+ setErrorMessages(itm);
114
+ });
115
+ }
116
+ else {
117
+ item.errorMessage = ruleIdsAndErrorMessages.get(item.id);
118
+ }
119
+ };
120
+ setErrorMessages(state.rootGroup);
121
+ });
122
+ }
97
123
  }
98
124
  /**
99
125
  * Function to check if supplied [[PropertyFilterBuilderRuleGroupItem]] is [[PropertyFilterBuilderRuleGroup]].
100
- * @internal
126
+ * @beta
101
127
  */
102
128
  export function isPropertyFilterBuilderRuleGroup(item) {
103
129
  return item.items !== undefined;
@@ -105,14 +131,64 @@ export function isPropertyFilterBuilderRuleGroup(item) {
105
131
  /**
106
132
  * Custom hook that creates state for [[PropertyFilterBuilder]] component. It creates empty state or initializes
107
133
  * state from supplied initial filter.
108
- * @internal
134
+ * @beta
109
135
  */
110
- export function usePropertyFilterBuilderState(initialFilter) {
111
- const [state, setState] = React.useState(() => initialFilter
136
+ export function usePropertyFilterBuilder(props) {
137
+ const { initialFilter, ruleValidator } = props !== null && props !== void 0 ? props : {
138
+ initialFilter: undefined,
139
+ ruleValidator: undefined,
140
+ };
141
+ const [state, setState] = React.useState(initialFilter
112
142
  ? convertFilterToState(initialFilter)
113
143
  : { rootGroup: createEmptyRuleGroup() });
114
144
  const [actions] = React.useState(() => new PropertyFilterBuilderActions(setState));
115
- return { state, actions };
145
+ const buildFilter = () => {
146
+ const ruleErrors = validateRules(state.rootGroup, ruleValidator);
147
+ actions.setRuleErrorMessages(ruleErrors);
148
+ if (ruleErrors.size > 0) {
149
+ return undefined;
150
+ }
151
+ return buildPropertyFilter(state.rootGroup);
152
+ };
153
+ return { rootGroup: state.rootGroup, actions, buildFilter };
154
+ }
155
+ function validateRules(rule, ruleValidator) {
156
+ const ruleIdsAndErrorMessages = new Map();
157
+ const validateRulesInner = (item) => {
158
+ if (isPropertyFilterBuilderRuleGroup(item)) {
159
+ item.items.forEach((itm) => {
160
+ validateRulesInner(itm);
161
+ });
162
+ }
163
+ else {
164
+ const errorMessage = ruleValidator
165
+ ? ruleValidator(item)
166
+ : defaultPropertyFilterBuilderRuleValidator(item);
167
+ if (errorMessage)
168
+ ruleIdsAndErrorMessages.set(item.id, errorMessage);
169
+ }
170
+ };
171
+ validateRulesInner(rule);
172
+ return ruleIdsAndErrorMessages;
173
+ }
174
+ /**
175
+ * Default rule validator.
176
+ * @beta
177
+ */
178
+ export function defaultPropertyFilterBuilderRuleValidator(item) {
179
+ if (item.property === undefined ||
180
+ item.operator === undefined ||
181
+ isUnaryPropertyFilterOperator(item.operator)) {
182
+ return undefined;
183
+ }
184
+ if (item.value === undefined) {
185
+ return UiComponents.translate("filterBuilder.errorMessages.emptyValue");
186
+ }
187
+ if (item.value.valueFormat === PropertyValueFormat.Primitive &&
188
+ (item.value.value === undefined || item.value.value === "")) {
189
+ return UiComponents.translate("filterBuilder.errorMessages.emptyValue");
190
+ }
191
+ return undefined;
116
192
  }
117
193
  /** @internal */
118
194
  export function buildPropertyFilter(groupItem) {
@@ -143,7 +219,7 @@ function buildPropertyFilterFromRule(rule) {
143
219
  if (!isUnaryPropertyFilterOperator(operator) &&
144
220
  (!value ||
145
221
  value.valueFormat !== PropertyValueFormat.Primitive ||
146
- !value.value))
222
+ value.value === undefined))
147
223
  return undefined;
148
224
  return { property, operator, value };
149
225
  }
@@ -221,4 +297,20 @@ function convertFilterToState(filter) {
221
297
  },
222
298
  };
223
299
  }
300
+ function areOperatorsSimilar(firstOperator, secondOperator) {
301
+ return ((isOperatorEqualOrIsNotEqual(firstOperator) &&
302
+ isOperatorEqualOrIsNotEqual(secondOperator)) ||
303
+ (isInequalityOperator(firstOperator) &&
304
+ isInequalityOperator(secondOperator)));
305
+ }
306
+ function isOperatorEqualOrIsNotEqual(operator) {
307
+ return (operator === PropertyFilterRuleOperator.IsEqual ||
308
+ operator === PropertyFilterRuleOperator.IsNotEqual);
309
+ }
310
+ function isInequalityOperator(operator) {
311
+ return (operator === PropertyFilterRuleOperator.Less ||
312
+ operator === PropertyFilterRuleOperator.LessOrEqual ||
313
+ operator === PropertyFilterRuleOperator.Greater ||
314
+ operator === PropertyFilterRuleOperator.GreaterOrEqual);
315
+ }
224
316
  //# sourceMappingURL=FilterBuilderState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FilterBuilderState.js","sourceRoot":"","sources":["../../../../src/components-react/filter-builder/FilterBuilderState.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EACL,6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AAI,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAI,yBAAyB,CAAC,MAAM,CAAC;QACnC,OAAO;YACL,EAAE;YACF,OAAO,EAAE,QAAQ;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;SAC9D,CAAC;IACJ,OAAO,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,WAAW,CAAC,MAA0B,EAAE,QAAgB;IAC/D,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE;QACtB,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAAsB;IAEtB,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAI,yBAAyB,CAAC,MAAM,CAAC,EAAE;QACrC,OAAO;YACL,SAAS,EAAE;gBACT,EAAE;gBACF,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;aAC9D;SACF,CAAC;KACH;IACD,OAAO;QACL,SAAS,EAAE;YACT,EAAE;YACF,QAAQ,EAAE,+BAA+B,CAAC,GAAG;YAC7C,KAAK,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyFilterBuilder\n */\n\nimport type { Draft } from \"immer\";\nimport { produce } from \"immer\";\nimport * as React from \"react\";\nimport type { PropertyDescription, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport type { PropertyFilterRuleOperator } from \"./Operators\";\nimport {\n isUnaryPropertyFilterOperator,\n PropertyFilterRuleGroupOperator,\n} from \"./Operators\";\nimport type { PropertyFilter, PropertyFilterRule } from \"./Types\";\nimport { isPropertyFilterRuleGroup } from \"./Types\";\n\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component state.\n * @internal\n */\nexport interface PropertyFilterBuilderState {\n /** Root group of rules in [[PropertyFilterBuilder]] component. */\n rootGroup: PropertyFilterBuilderRuleGroup;\n}\n\n/**\n * Type that describes [[PropertyFilterBuilder]] component group item.\n * @internal\n */\nexport type PropertyFilterBuilderRuleGroupItem =\n | PropertyFilterBuilderRuleGroup\n | PropertyFilterBuilderRule;\n\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component rule group.\n * @internal\n */\nexport interface PropertyFilterBuilderRuleGroup {\n /** Id of this rule group. */\n id: string;\n /** Id of rule group that this group is nested in. */\n groupId?: string;\n /** Operator that should join items in this group. */\n operator: PropertyFilterRuleGroupOperator;\n /** Items in this group. */\n items: PropertyFilterBuilderRuleGroupItem[];\n}\n\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component single rule.\n * @internal\n */\nexport interface PropertyFilterBuilderRule {\n /** Id of this rule. */\n id: string;\n /** Id of rule group that this rule is nested in. */\n groupId: string;\n /** Property used in this rule. */\n property?: PropertyDescription;\n /** Operator that should be used to compare property value. */\n operator?: PropertyFilterRuleOperator;\n /** Value that property should be compared to. */\n value?: PropertyValue;\n}\n\n/**\n * Actions for controlling [[PropertyFilterBuilder]] component state.\n * @internal\n */\nexport class PropertyFilterBuilderActions {\n constructor(\n private setState: (\n setter: (\n prevState: PropertyFilterBuilderState\n ) => PropertyFilterBuilderState\n ) => void\n ) {}\n\n private updateState(\n updater: (state: Draft<PropertyFilterBuilderState>) => void\n ) {\n this.setState(produce(updater));\n }\n\n /** Adds new rule or group of rules to the group specified by path. */\n public addItem(path: string[], itemType: \"RULE_GROUP\" | \"RULE\") {\n this.updateState((state) => {\n const parentGroup = findRuleGroup(state.rootGroup, path);\n if (!parentGroup) return;\n const item =\n itemType === \"RULE_GROUP\"\n ? createEmptyRuleGroup(parentGroup.id)\n : createEmptyRule(parentGroup.id);\n parentGroup.items.push(item);\n });\n }\n\n /** Removes item specified by path. */\n public removeItem(path: string[]) {\n function removeItemFromGroup(\n state: Draft<PropertyFilterBuilderState>,\n pathToItem: string[]\n ) {\n const pathToParent = pathToItem.slice(0, -1);\n const parentGroup = findRuleGroup(state.rootGroup, pathToParent);\n if (!parentGroup) return;\n const itemId = pathToItem[pathToItem.length - 1];\n const itemIndex = parentGroup.items.findIndex(\n (item) => item.id === itemId\n );\n if (itemIndex === -1) return;\n if (parentGroup.items.length === 1) {\n parentGroup.items[0] = createEmptyRule(parentGroup.id);\n return;\n }\n parentGroup.items.splice(itemIndex, 1);\n }\n\n this.updateState((state) => {\n removeItemFromGroup(state, path);\n });\n }\n\n /** Sets operator of rule group specified by the path. */\n public setRuleGroupOperator(\n path: string[],\n operator: PropertyFilterRuleGroupOperator\n ) {\n this.updateState((state) => {\n const group = findRuleGroup(state.rootGroup, path);\n if (!group) return;\n group.operator = operator;\n });\n }\n\n /** Sets property of rule specified by the path. */\n public setRuleProperty(path: string[], property?: PropertyDescription) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n rule.property = property;\n rule.value = undefined;\n });\n }\n\n /** Sets operator of rule specified by the path. */\n public setRuleOperator(path: string[], operator: PropertyFilterRuleOperator) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n if (isUnaryPropertyFilterOperator(operator)) rule.value = undefined;\n rule.operator = operator;\n });\n }\n\n /** Sets value of rule specified by the path. */\n public setRuleValue(path: string[], value: PropertyValue) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n rule.value = value;\n });\n }\n}\n\n/**\n * Function to check if supplied [[PropertyFilterBuilderRuleGroupItem]] is [[PropertyFilterBuilderRuleGroup]].\n * @internal\n */\nexport function isPropertyFilterBuilderRuleGroup(\n item: PropertyFilterBuilderRuleGroupItem\n): item is PropertyFilterBuilderRuleGroup {\n return (item as any).items !== undefined;\n}\n\n/**\n * Custom hook that creates state for [[PropertyFilterBuilder]] component. It creates empty state or initializes\n * state from supplied initial filter.\n * @internal\n */\nexport function usePropertyFilterBuilderState(initialFilter?: PropertyFilter) {\n const [state, setState] = React.useState<PropertyFilterBuilderState>(() =>\n initialFilter\n ? convertFilterToState(initialFilter)\n : { rootGroup: createEmptyRuleGroup() }\n );\n const [actions] = React.useState(\n () => new PropertyFilterBuilderActions(setState)\n );\n\n return { state, actions };\n}\n\n/** @internal */\nexport function buildPropertyFilter(\n groupItem: PropertyFilterBuilderRuleGroupItem\n): PropertyFilter | undefined {\n if (isPropertyFilterBuilderRuleGroup(groupItem))\n return buildPropertyFilterFromRuleGroup(groupItem);\n return buildPropertyFilterFromRule(groupItem);\n}\n\nfunction buildPropertyFilterFromRuleGroup(\n rootGroup: PropertyFilterBuilderRuleGroup\n): PropertyFilter | undefined {\n const rules = new Array<PropertyFilter>();\n for (const item of rootGroup.items) {\n const rule = buildPropertyFilter(item);\n if (rule) rules.push(rule);\n }\n\n if (rules.length === 0) return undefined;\n\n if (rules.length === 1) return rules[0];\n\n return {\n operator: rootGroup.operator,\n rules,\n };\n}\n\nfunction buildPropertyFilterFromRule(\n rule: PropertyFilterBuilderRule\n): PropertyFilter | undefined {\n const { property, operator, value } = rule;\n if (!property || operator === undefined) return undefined;\n\n if (\n !isUnaryPropertyFilterOperator(operator) &&\n (!value ||\n value.valueFormat !== PropertyValueFormat.Primitive ||\n !value.value)\n )\n return undefined;\n\n return { property, operator, value };\n}\n\nfunction createEmptyRule(groupId: string): PropertyFilterBuilderRule {\n return {\n id: Guid.createValue(),\n groupId,\n };\n}\n\nfunction createEmptyRuleGroup(\n groupId?: string\n): PropertyFilterBuilderRuleGroup {\n const id = Guid.createValue();\n return {\n id,\n groupId,\n operator: PropertyFilterRuleGroupOperator.And,\n items: [createEmptyRule(id)],\n };\n}\n\nfunction findRuleGroup(\n rootGroup: PropertyFilterBuilderRuleGroup,\n path: string[]\n): PropertyFilterBuilderRuleGroup | undefined {\n if (path.length === 0) return rootGroup;\n\n const [currentItemId, ...rest] = path;\n const currentItem = rootGroup.items.find((item) => item.id === currentItemId);\n if (!currentItem || !isPropertyFilterBuilderRuleGroup(currentItem))\n return undefined;\n\n return findRuleGroup(currentItem, rest);\n}\n\nfunction findRule(\n rootGroup: PropertyFilterBuilderRuleGroup,\n path: string[]\n): PropertyFilterBuilderRule | undefined {\n if (path.length === 0) return undefined;\n\n const [currentItemId, ...rest] = path;\n const currentItem = rootGroup.items.find((item) => item.id === currentItemId);\n if (!currentItem) return undefined;\n\n if (isPropertyFilterBuilderRuleGroup(currentItem))\n return findRule(currentItem, rest);\n\n return currentItem;\n}\n\nfunction getRuleGroupItem(\n filter: PropertyFilter,\n parentId: string\n): PropertyFilterBuilderRuleGroupItem {\n const id = Guid.createValue();\n if (isPropertyFilterRuleGroup(filter))\n return {\n id,\n groupId: parentId,\n operator: filter.operator,\n items: filter.rules.map((rule) => getRuleGroupItem(rule, id)),\n };\n return getRuleItem(filter, id);\n}\n\nfunction getRuleItem(filter: PropertyFilterRule, parentId: string) {\n return {\n id: Guid.createValue(),\n groupId: parentId,\n property: filter.property,\n operator: filter.operator,\n value: filter.value,\n };\n}\n\nfunction convertFilterToState(\n filter: PropertyFilter\n): PropertyFilterBuilderState {\n const id = Guid.createValue();\n if (isPropertyFilterRuleGroup(filter)) {\n return {\n rootGroup: {\n id,\n operator: filter.operator,\n items: filter.rules.map((rule) => getRuleGroupItem(rule, id)),\n },\n };\n }\n return {\n rootGroup: {\n id,\n operator: PropertyFilterRuleGroupOperator.And,\n items: [getRuleItem(filter, id)],\n },\n };\n}\n"]}
1
+ {"version":3,"file":"FilterBuilderState.js","sourceRoot":"","sources":["../../../../src/components-react/filter-builder/FilterBuilderState.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,GAChC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAoD/C;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IACvC,YACU,QAIC;QAJD,aAAQ,GAAR,QAAQ,CAIP;IACR,CAAC;IAEI,WAAW,CACjB,OAA2D;QAE3D,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,sEAAsE;IAC/D,OAAO,CAAC,IAAc,EAAE,QAA+B;QAC5D,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,EAAE;YACzB,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACzD,IAAI,CAAC,WAAW;gBAAE,OAAO;YACzB,MAAM,IAAI,GACR,QAAQ,KAAK,YAAY;gBACvB,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,EAAE,CAA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;KACpB,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAAsB;IAEtB,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAI,yBAAyB,CAAC,MAAM,CAAC,EAAE;QACrC,OAAO;YACL,SAAS,EAAE;gBACT,EAAE;gBACF,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;aAC9D;SACF,CAAC;KACH;IACD,OAAO;QACL,SAAS,EAAE;YACT,EAAE;YACF,QAAQ,EAAE,+BAA+B,CAAC,GAAG;YAC7C,KAAK,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;SACjC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,aAA0C,EAC1C,cAA2C;IAE3C,OAAO,CACL,CAAC,2BAA2B,CAAC,aAAa,CAAC;QACzC,2BAA2B,CAAC,cAAc,CAAC,CAAC;QAC9C,CAAC,oBAAoB,CAAC,aAAa,CAAC;YAClC,oBAAoB,CAAC,cAAc,CAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAqC;IACxE,OAAO,CACL,QAAQ,KAAK,0BAA0B,CAAC,OAAO;QAC/C,QAAQ,KAAK,0BAA0B,CAAC,UAAU,CACnD,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAqC;IACjE,OAAO,CACL,QAAQ,KAAK,0BAA0B,CAAC,IAAI;QAC5C,QAAQ,KAAK,0BAA0B,CAAC,WAAW;QACnD,QAAQ,KAAK,0BAA0B,CAAC,OAAO;QAC/C,QAAQ,KAAK,0BAA0B,CAAC,cAAc,CACvD,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyFilterBuilder\n */\n\nimport type { Draft } from \"immer\";\nimport { produce } from \"immer\";\nimport * as React from \"react\";\nimport type { PropertyDescription, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport { PropertyFilterRuleOperator } from \"./Operators\";\nimport {\n isUnaryPropertyFilterOperator,\n PropertyFilterRuleGroupOperator,\n} from \"./Operators\";\nimport type { PropertyFilter, PropertyFilterRule } from \"./Types\";\nimport { isPropertyFilterRuleGroup } from \"./Types\";\nimport { UiComponents } from \"../UiComponents\";\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component state.\n * @beta\n */\nexport interface PropertyFilterBuilderState {\n /** Root group of rules in [[PropertyFilterBuilder]] component. */\n rootGroup: PropertyFilterBuilderRuleGroup;\n}\n\n/**\n * Type that describes [[PropertyFilterBuilder]] component group item.\n * @beta\n */\nexport type PropertyFilterBuilderRuleGroupItem =\n | PropertyFilterBuilderRuleGroup\n | PropertyFilterBuilderRule;\n\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component rule group.\n * @beta\n */\nexport interface PropertyFilterBuilderRuleGroup {\n /** Id of this rule group. */\n id: string;\n /** Id of rule group that this group is nested in. */\n groupId?: string;\n /** Operator that should join items in this group. */\n operator: PropertyFilterRuleGroupOperator;\n /** Items in this group. */\n items: PropertyFilterBuilderRuleGroupItem[];\n}\n\n/**\n * Data structure that describes [[PropertyFilterBuilder]] component single rule.\n * @beta\n */\nexport interface PropertyFilterBuilderRule {\n /** Id of this rule. */\n id: string;\n /** Id of rule group that this rule is nested in. */\n groupId: string;\n /** Property used in this rule. */\n property?: PropertyDescription;\n /** Operator that should be used to compare property value. */\n operator?: PropertyFilterRuleOperator;\n /** Value that property should be compared to. */\n value?: PropertyValue;\n /** Error message of this rule. */\n errorMessage?: string;\n}\n\n/**\n * Actions for controlling [[PropertyFilterBuilder]] component state.\n * @beta\n */\nexport class PropertyFilterBuilderActions {\n constructor(\n private setState: (\n setter: (\n prevState: PropertyFilterBuilderState\n ) => PropertyFilterBuilderState\n ) => void\n ) {}\n\n private updateState(\n updater: (state: Draft<PropertyFilterBuilderState>) => void\n ) {\n this.setState(produce(updater));\n }\n\n /** Adds new rule or group of rules to the group specified by path. */\n public addItem(path: string[], itemType: \"RULE_GROUP\" | \"RULE\") {\n this.updateState((state) => {\n const parentGroup = findRuleGroup(state.rootGroup, path);\n if (!parentGroup) return;\n const item =\n itemType === \"RULE_GROUP\"\n ? createEmptyRuleGroup(parentGroup.id)\n : createEmptyRule(parentGroup.id);\n parentGroup.items.push(item);\n });\n }\n\n /** Removes item specified by path. */\n public removeItem(path: string[]) {\n function removeItemFromGroup(\n state: Draft<PropertyFilterBuilderState>,\n pathToItem: string[]\n ) {\n const pathToParent = pathToItem.slice(0, -1);\n const parentGroup = findRuleGroup(state.rootGroup, pathToParent);\n if (!parentGroup) return;\n const itemId = pathToItem[pathToItem.length - 1];\n const itemIndex = parentGroup.items.findIndex(\n (item) => item.id === itemId\n );\n if (itemIndex === -1) return;\n if (parentGroup.items.length === 1) {\n parentGroup.items[0] = createEmptyRule(parentGroup.id);\n return;\n }\n parentGroup.items.splice(itemIndex, 1);\n }\n\n this.updateState((state) => {\n removeItemFromGroup(state, path);\n });\n }\n\n /** Sets operator of rule group specified by the path. */\n public setRuleGroupOperator(\n path: string[],\n operator: PropertyFilterRuleGroupOperator\n ) {\n this.updateState((state) => {\n const group = findRuleGroup(state.rootGroup, path);\n if (!group) return;\n group.operator = operator;\n });\n }\n\n /** Sets property of rule specified by the path. */\n public setRuleProperty(path: string[], property?: PropertyDescription) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n rule.property = property;\n rule.value = undefined;\n rule.errorMessage = undefined;\n });\n }\n\n /** Sets operator of rule specified by the path. */\n public setRuleOperator(path: string[], operator: PropertyFilterRuleOperator) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n if (isUnaryPropertyFilterOperator(operator)) rule.value = undefined;\n if (\n operator !== rule.operator &&\n !areOperatorsSimilar(operator, rule.operator)\n ) {\n rule.value = undefined;\n }\n rule.operator = operator;\n });\n }\n\n /** Sets value of rule specified by the path. */\n public setRuleValue(path: string[], value: PropertyValue) {\n this.updateState((state) => {\n const rule = findRule(state.rootGroup, path);\n if (!rule) return;\n rule.value = value;\n });\n }\n\n /**\n * Sets error messages of the rules specified by id.\n * If rule id is not present in the map, then its error message will be cleared.\n */\n public setRuleErrorMessages(ruleIdsAndErrorMessages: Map<string, string>) {\n this.updateState((state) => {\n const setErrorMessages = (item: PropertyFilterBuilderRuleGroupItem) => {\n if (isPropertyFilterBuilderRuleGroup(item)) {\n item.items.forEach((itm) => {\n setErrorMessages(itm);\n });\n } else {\n item.errorMessage = ruleIdsAndErrorMessages.get(item.id);\n }\n };\n\n setErrorMessages(state.rootGroup);\n });\n }\n}\n\n/**\n * Function to check if supplied [[PropertyFilterBuilderRuleGroupItem]] is [[PropertyFilterBuilderRuleGroup]].\n * @beta\n */\nexport function isPropertyFilterBuilderRuleGroup(\n item: PropertyFilterBuilderRuleGroupItem\n): item is PropertyFilterBuilderRuleGroup {\n return (item as any).items !== undefined;\n}\n\n/**\n * Props for [[usePropertyFilterBuilder]]\n * @beta\n */\nexport interface UsePropertyFilterBuilderProps {\n /** Initial filter for [[PropertyFilterBuilder]] */\n initialFilter?: PropertyFilter;\n /** Custom rule validator to be used when [[UsePropertyFilterBuilderResult.buildFilter]] is invoked. Should return error message or `undefined`, if rule is valid. */\n ruleValidator?: (rule: PropertyFilterBuilderRule) => string | undefined;\n}\n\n/**\n * Type for [[usePropertyFilterBuilder]] return object.\n * @beta\n */\nexport interface UsePropertyFilterBuilderResult {\n /** Root group of the [[PropertyFilterBuilder]]. */\n rootGroup: PropertyFilterBuilderRuleGroup;\n /** Actions for manipulating [[PropertyFilterBuilder]] state. */\n actions: PropertyFilterBuilderActions;\n /**\n * Validates and builds [[PropertyFilter]] based on current state. It uses [[defaultPropertyFilterBuilderRuleValidator]] or\n * custom validator provided through [[UsePropertyFilterBuilderProps]] to validate each rule.\n * @returns [[PropertyFilter]] if all rules are valid, `undefined` otherwise.\n */\n buildFilter: () => PropertyFilter | undefined;\n}\n\n/**\n * Custom hook that creates state for [[PropertyFilterBuilder]] component. It creates empty state or initializes\n * state from supplied initial filter.\n * @beta\n */\nexport function usePropertyFilterBuilder(\n props?: UsePropertyFilterBuilderProps\n) {\n const { initialFilter, ruleValidator } = props ?? {\n initialFilter: undefined,\n ruleValidator: undefined,\n };\n const [state, setState] = React.useState<PropertyFilterBuilderState>(\n initialFilter\n ? convertFilterToState(initialFilter)\n : { rootGroup: createEmptyRuleGroup() }\n );\n\n const [actions] = React.useState(\n () => new PropertyFilterBuilderActions(setState)\n );\n\n const buildFilter = () => {\n const ruleErrors = validateRules(state.rootGroup, ruleValidator);\n actions.setRuleErrorMessages(ruleErrors);\n if (ruleErrors.size > 0) {\n return undefined;\n }\n return buildPropertyFilter(state.rootGroup);\n };\n return { rootGroup: state.rootGroup, actions, buildFilter };\n}\n\nfunction validateRules(\n rule: PropertyFilterBuilderRuleGroupItem,\n ruleValidator?: (item: PropertyFilterBuilderRule) => string | undefined\n) {\n const ruleIdsAndErrorMessages = new Map<string, string>();\n\n const validateRulesInner = (item: PropertyFilterBuilderRuleGroupItem) => {\n if (isPropertyFilterBuilderRuleGroup(item)) {\n item.items.forEach((itm) => {\n validateRulesInner(itm);\n });\n } else {\n const errorMessage = ruleValidator\n ? ruleValidator(item)\n : defaultPropertyFilterBuilderRuleValidator(item);\n if (errorMessage) ruleIdsAndErrorMessages.set(item.id, errorMessage);\n }\n };\n\n validateRulesInner(rule);\n\n return ruleIdsAndErrorMessages;\n}\n\n/**\n * Default rule validator.\n * @beta\n */\nexport function defaultPropertyFilterBuilderRuleValidator(\n item: PropertyFilterBuilderRule\n): string | undefined {\n if (\n item.property === undefined ||\n item.operator === undefined ||\n isUnaryPropertyFilterOperator(item.operator)\n ) {\n return undefined;\n }\n if (item.value === undefined) {\n return UiComponents.translate(\"filterBuilder.errorMessages.emptyValue\");\n }\n if (\n item.value.valueFormat === PropertyValueFormat.Primitive &&\n (item.value.value === undefined || item.value.value === \"\")\n ) {\n return UiComponents.translate(\"filterBuilder.errorMessages.emptyValue\");\n }\n return undefined;\n}\n\n/** @internal */\nexport function buildPropertyFilter(\n groupItem: PropertyFilterBuilderRuleGroupItem\n): PropertyFilter | undefined {\n if (isPropertyFilterBuilderRuleGroup(groupItem))\n return buildPropertyFilterFromRuleGroup(groupItem);\n return buildPropertyFilterFromRule(groupItem);\n}\n\nfunction buildPropertyFilterFromRuleGroup(\n rootGroup: PropertyFilterBuilderRuleGroup\n): PropertyFilter | undefined {\n const rules = new Array<PropertyFilter>();\n for (const item of rootGroup.items) {\n const rule = buildPropertyFilter(item);\n if (rule) rules.push(rule);\n }\n\n if (rules.length === 0) return undefined;\n\n if (rules.length === 1) return rules[0];\n\n return {\n operator: rootGroup.operator,\n rules,\n };\n}\n\nfunction buildPropertyFilterFromRule(\n rule: PropertyFilterBuilderRule\n): PropertyFilter | undefined {\n const { property, operator, value } = rule;\n if (!property || operator === undefined) return undefined;\n\n if (\n !isUnaryPropertyFilterOperator(operator) &&\n (!value ||\n value.valueFormat !== PropertyValueFormat.Primitive ||\n value.value === undefined)\n )\n return undefined;\n\n return { property, operator, value };\n}\n\nfunction createEmptyRule(groupId: string): PropertyFilterBuilderRule {\n return {\n id: Guid.createValue(),\n groupId,\n };\n}\n\nfunction createEmptyRuleGroup(\n groupId?: string\n): PropertyFilterBuilderRuleGroup {\n const id = Guid.createValue();\n return {\n id,\n groupId,\n operator: PropertyFilterRuleGroupOperator.And,\n items: [createEmptyRule(id)],\n };\n}\n\nfunction findRuleGroup(\n rootGroup: PropertyFilterBuilderRuleGroup,\n path: string[]\n): PropertyFilterBuilderRuleGroup | undefined {\n if (path.length === 0) return rootGroup;\n\n const [currentItemId, ...rest] = path;\n const currentItem = rootGroup.items.find((item) => item.id === currentItemId);\n if (!currentItem || !isPropertyFilterBuilderRuleGroup(currentItem))\n return undefined;\n\n return findRuleGroup(currentItem, rest);\n}\n\nfunction findRule(\n rootGroup: PropertyFilterBuilderRuleGroup,\n path: string[]\n): PropertyFilterBuilderRule | undefined {\n if (path.length === 0) return undefined;\n\n const [currentItemId, ...rest] = path;\n const currentItem = rootGroup.items.find((item) => item.id === currentItemId);\n if (!currentItem) return undefined;\n\n if (isPropertyFilterBuilderRuleGroup(currentItem))\n return findRule(currentItem, rest);\n\n return currentItem;\n}\n\nfunction getRuleGroupItem(\n filter: PropertyFilter,\n parentId: string\n): PropertyFilterBuilderRuleGroupItem {\n const id = Guid.createValue();\n if (isPropertyFilterRuleGroup(filter))\n return {\n id,\n groupId: parentId,\n operator: filter.operator,\n items: filter.rules.map((rule) => getRuleGroupItem(rule, id)),\n };\n return getRuleItem(filter, id);\n}\n\nfunction getRuleItem(filter: PropertyFilterRule, parentId: string) {\n return {\n id: Guid.createValue(),\n groupId: parentId,\n property: filter.property,\n operator: filter.operator,\n value: filter.value,\n };\n}\n\nfunction convertFilterToState(\n filter: PropertyFilter\n): PropertyFilterBuilderState {\n const id = Guid.createValue();\n if (isPropertyFilterRuleGroup(filter)) {\n return {\n rootGroup: {\n id,\n operator: filter.operator,\n items: filter.rules.map((rule) => getRuleGroupItem(rule, id)),\n },\n };\n }\n return {\n rootGroup: {\n id,\n operator: PropertyFilterRuleGroupOperator.And,\n items: [getRuleItem(filter, id)],\n },\n };\n}\n\nfunction areOperatorsSimilar(\n firstOperator?: PropertyFilterRuleOperator,\n secondOperator?: PropertyFilterRuleOperator\n) {\n return (\n (isOperatorEqualOrIsNotEqual(firstOperator) &&\n isOperatorEqualOrIsNotEqual(secondOperator)) ||\n (isInequalityOperator(firstOperator) &&\n isInequalityOperator(secondOperator))\n );\n}\n\nfunction isOperatorEqualOrIsNotEqual(operator?: PropertyFilterRuleOperator) {\n return (\n operator === PropertyFilterRuleOperator.IsEqual ||\n operator === PropertyFilterRuleOperator.IsNotEqual\n );\n}\n\nfunction isInequalityOperator(operator?: PropertyFilterRuleOperator) {\n return (\n operator === PropertyFilterRuleOperator.Less ||\n operator === PropertyFilterRuleOperator.LessOrEqual ||\n operator === PropertyFilterRuleOperator.Greater ||\n operator === PropertyFilterRuleOperator.GreaterOrEqual\n );\n}\n"]}
@@ -0,0 +1,144 @@
1
+ /** @packageDocumentation
2
+ * @module Toolbar
3
+ */
4
+ import "./Toolbar.scss";
5
+ import * as React from "react";
6
+ import type { ActionButton, CommonToolbarItem, CustomButtonDefinition, GroupButton, OnItemExecutedFunc } from "@itwin/appui-abstract";
7
+ import type { CommonProps, NoChildrenProps } from "@itwin/core-react";
8
+ import { Direction, OrthogonalDirection } from "./utilities/Direction";
9
+ import type { BeEvent } from "@itwin/core-bentley";
10
+ /** Describes the data needed to insert a custom `React` button into an ToolbarWithOverflow.
11
+ * @public
12
+ * @deprecated in 4.0. Use [ToolbarCustomItem]($appui-react) instead.
13
+ */
14
+ export interface CustomToolbarItem extends CustomButtonDefinition {
15
+ /** defines the content to display in popup panel */
16
+ panelContentNode?: React.ReactNode;
17
+ /** If true the popup panel is mounted once and unmounted when button is unmounted. If false the
18
+ * content node is unmounted each time the popup is closed. */
19
+ keepContentsLoaded?: boolean;
20
+ }
21
+ /**
22
+ * Context used by Toolbar items to know if popup panel should be hidden - via AutoHide.
23
+ * @public
24
+ */
25
+ export declare const ToolbarPopupAutoHideContext: React.Context<boolean>;
26
+ /**
27
+ * React hook used to retrieve the ToolbarPopupAutoHideContext.
28
+ * @public
29
+ */
30
+ export declare function useToolbarPopupAutoHideContext(): boolean;
31
+ /** Describes toolbar item.
32
+ * @public
33
+ * @deprecated in 4.0. Use [ToolbarItem]($appui-react) instead.
34
+ */
35
+ export type ToolbarItem = ActionButton | GroupButton | CustomToolbarItem;
36
+ /** CustomToolbarItem type guard.
37
+ * @internal
38
+ */
39
+ export declare function isCustomToolbarItem(item: ToolbarItem): item is CustomToolbarItem;
40
+ /** @internal */
41
+ export declare const getToolbarDirection: (expandsTo: Direction) => OrthogonalDirection;
42
+ /** Available alignment modes of [[Toolbar]] panels.
43
+ * @public
44
+ */
45
+ export declare enum ToolbarPanelAlignment {
46
+ Start = 0,
47
+ End = 1
48
+ }
49
+ /** Enumeration of Toolbar Opacity setting.
50
+ * @public
51
+ */
52
+ export declare enum ToolbarOpacitySetting {
53
+ /** Use the default background, box-shadow opacity and backdrop-filter blur */
54
+ Defaults = 0,
55
+ /** Alter the opacity from transparent to the defaults based on mouse proximity */
56
+ Proximity = 1,
57
+ /** Use a transparent background, box-shadow opacity and backdrop-filter blur */
58
+ Transparent = 2
59
+ }
60
+ /** Helpers for [[ToolbarPanelAlignment]].
61
+ * @internal
62
+ */
63
+ export declare class ToolbarPanelAlignmentHelpers {
64
+ /** Class name of [[ToolbarPanelAlignment.Start]] */
65
+ static readonly START_CLASS_NAME = "components-panel-alignment-start";
66
+ /** Class name of [[ToolbarPanelAlignment.End]] */
67
+ static readonly END_CLASS_NAME = "components-panel-alignment-end";
68
+ /** @returns Class name of specified [[ToolbarPanelAlignment]] */
69
+ static getCssClassName(panelAlignment: ToolbarPanelAlignment): string;
70
+ }
71
+ /** @internal */
72
+ export interface ToolbarOverflowContextProps {
73
+ readonly expandsTo: Direction;
74
+ readonly direction: OrthogonalDirection;
75
+ readonly overflowExpandsTo: Direction;
76
+ readonly overflowDirection: OrthogonalDirection;
77
+ readonly panelAlignment: ToolbarPanelAlignment;
78
+ readonly useDragInteraction: boolean;
79
+ readonly toolbarOpacitySetting: ToolbarOpacitySetting;
80
+ readonly openPopupCount: number;
81
+ readonly onPopupPanelOpenClose: (isOpening: boolean) => void;
82
+ readonly overflowDisplayActive: boolean;
83
+ readonly onItemExecuted: OnItemExecutedFunc;
84
+ readonly onKeyDown: (e: React.KeyboardEvent) => void;
85
+ }
86
+ /**
87
+ * Context used by Toolbar component to provide Direction to child components.
88
+ * @internal
89
+ */
90
+ export declare const ToolbarWithOverflowDirectionContext: React.Context<ToolbarOverflowContextProps>;
91
+ /** @internal */
92
+ export declare function ToolbarItemComponent({ item, addGroupSeparator, }: {
93
+ item: ToolbarItem;
94
+ addGroupSeparator: boolean;
95
+ }): JSX.Element | null;
96
+ /** @internal */
97
+ export declare function useToolbarWithOverflowDirectionContext(): ToolbarOverflowContextProps;
98
+ /** Properties of [[ToolbarComponent]] component.
99
+ * @internal
100
+ */
101
+ export interface InternalToolbarComponentProps extends CommonProps, NoChildrenProps {
102
+ /** Describes to which direction the popup panels are expanded. Defaults to: [[Direction.Bottom]] */
103
+ expandsTo?: Direction;
104
+ /** Describes if items that do not fit available space should move to an expandable panel. Defaults to: false */
105
+ enableOverflow?: boolean | {
106
+ /** Describes to which direction the overflow popup panels are expanded if overflow is enabled. Defaults to: [[Direction.Right]] */
107
+ overflowExpandsTo?: Direction;
108
+ };
109
+ /** Definitions for items of the toolbar. Items are expected to be already sorted by group and item. */
110
+ items: CommonToolbarItem[];
111
+ /** Describes how expanded panels are aligned. Defaults to: [[ToolbarPanelAlignment.Start]] */
112
+ panelAlignment?: ToolbarPanelAlignment;
113
+ /** Use Drag Interaction to open popups with nest action buttons */
114
+ useDragInteraction?: boolean;
115
+ /** Determines whether to use mouse proximity to alter the opacity of the toolbar */
116
+ toolbarOpacitySetting?: ToolbarOpacitySetting;
117
+ /** Optional function to call on any item execution */
118
+ onItemExecuted?: OnItemExecutedFunc;
119
+ /** Optional function to call on any KeyDown events processed by toolbar */
120
+ onKeyDown?: (e: React.KeyboardEvent) => void;
121
+ /** SyncEvents on which the conditional should listen to */
122
+ syncUiEvent?: BeEvent<(args: {
123
+ eventIds: Set<string>;
124
+ }) => void>;
125
+ }
126
+ /** Component that displays toolbar items.
127
+ * @internal
128
+ */
129
+ export declare function InternalToolbarComponent(props: InternalToolbarComponentProps): JSX.Element;
130
+ /** Interface toolbars use to define context for its items.
131
+ * @internal
132
+ */
133
+ export interface ToolbarItemContextArgs {
134
+ readonly hasOverflow: boolean;
135
+ readonly useHeight: boolean;
136
+ readonly onResize: (w: number) => void;
137
+ }
138
+ /** Interface toolbars use to define context for its items.
139
+ * @internal
140
+ */
141
+ export declare const ToolbarItemContext: React.Context<ToolbarItemContextArgs>;
142
+ /** @internal */
143
+ export declare function useToolItemEntryContext(): ToolbarItemContextArgs;
144
+ //# sourceMappingURL=InternalToolbarComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InternalToolbarComponent.d.ts","sourceRoot":"","sources":["../../../../src/components-react/toolbar/InternalToolbarComponent.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AAExB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAUtE,OAAO,EACL,SAAS,EAET,mBAAmB,EAEpB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;IAC/D,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACnC;kEAC8D;IAC9D,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B,wBAAsC,CAAC;AAE/E;;;GAGG;AACH,wBAAgB,8BAA8B,YAE7C;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAEzE;;GAEG;AACH,wBAAgB,mBAAmB,C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