@itwin/imodel-components-react 5.19.0 → 5.21.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 (34) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/imodel-components-react/UiIModelComponents.js +1 -1
  3. package/lib/imodel-components-react/UiIModelComponents.js.map +1 -1
  4. package/lib/imodel-components-react/color/AlphaSlider.js +100 -100
  5. package/lib/imodel-components-react/color/AlphaSlider.js.map +1 -1
  6. package/lib/imodel-components-react/editors/ColorEditor.js +20 -23
  7. package/lib/imodel-components-react/editors/ColorEditor.js.map +1 -1
  8. package/lib/imodel-components-react/editors/WeightEditor.js +21 -21
  9. package/lib/imodel-components-react/editors/WeightEditor.js.map +1 -1
  10. package/lib/imodel-components-react/inputs/new-editors/QuantityEditor.js +3 -2
  11. package/lib/imodel-components-react/inputs/new-editors/QuantityEditor.js.map +1 -1
  12. package/lib/imodel-components-react/inputs/new-editors/UseQuantityInfo.d.ts +2 -1
  13. package/lib/imodel-components-react/inputs/new-editors/UseQuantityInfo.d.ts.map +1 -1
  14. package/lib/imodel-components-react/inputs/new-editors/UseQuantityInfo.js +31 -11
  15. package/lib/imodel-components-react/inputs/new-editors/UseQuantityInfo.js.map +1 -1
  16. package/lib/imodel-components-react/lineweight/WeightPickerButton.js +53 -53
  17. package/lib/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  18. package/lib/imodel-components-react/navigationaids/Cube.js +1 -4
  19. package/lib/imodel-components-react/navigationaids/Cube.js.map +1 -1
  20. package/lib/imodel-components-react/navigationaids/CubeNavigationAid.js +296 -302
  21. package/lib/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  22. package/lib/imodel-components-react/navigationaids/DrawingNavigationAid.js +428 -425
  23. package/lib/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  24. package/lib/imodel-components-react/timeline/BaseSolarDataProvider.js +20 -17
  25. package/lib/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  26. package/lib/imodel-components-react/timeline/BaseTimelineDataProvider.js +13 -10
  27. package/lib/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  28. package/lib/imodel-components-react/timeline/InlineEdit.js +20 -20
  29. package/lib/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  30. package/lib/imodel-components-react/timeline/SolarTimeline.js +144 -144
  31. package/lib/imodel-components-react/timeline/SolarTimeline.js.map +1 -1
  32. package/lib/imodel-components-react/viewport/ViewportComponentEvents.js +16 -15
  33. package/lib/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  34. package/package.json +7 -7
@@ -11,27 +11,33 @@ import { useIModelConnection } from "../../IModelConnectionContext.js";
11
11
  * @internal
12
12
  */
13
13
  export function useQuantityInfo({ type }) {
14
- const [{ formatter, parser }, setState] = React.useState(() => ({
15
- formatter: undefined,
14
+ const [{ defaultFormatter, highPrecisionFormatter, parser }, setState] = React.useState(() => ({
15
+ defaultFormatter: undefined,
16
+ highPrecisionFormatter: undefined,
16
17
  parser: undefined,
17
18
  }));
18
19
  const imodel = useIModelConnection();
19
20
  React.useEffect(() => {
20
21
  if (type === undefined) {
21
22
  setState({
22
- formatter: undefined,
23
+ defaultFormatter: undefined,
24
+ highPrecisionFormatter: undefined,
23
25
  parser: undefined,
24
26
  });
25
27
  return;
26
28
  }
27
29
  let disposed = false;
28
30
  const loadFormatterParser = async () => {
29
- const { formatterSpec, parserSpec } = await getFormatterParserSpec({
31
+ const { defaultFormatterSpec, highPrecisionFormatterSpec, parserSpec } = await getFormatterParserSpec({
30
32
  imodel,
31
33
  type,
32
34
  });
33
35
  if (!disposed) {
34
- setState({ formatter: formatterSpec, parser: parserSpec });
36
+ setState({
37
+ defaultFormatter: defaultFormatterSpec,
38
+ highPrecisionFormatter: highPrecisionFormatterSpec,
39
+ parser: parserSpec,
40
+ });
35
41
  }
36
42
  };
37
43
  void loadFormatterParser();
@@ -53,7 +59,7 @@ export function useQuantityInfo({ type }) {
53
59
  });
54
60
  };
55
61
  }, [imodel, type]);
56
- return { formatter, parser };
62
+ return { defaultFormatter, highPrecisionFormatter, parser };
57
63
  }
58
64
  async function getFormatterParserSpec({ imodel, type, }) {
59
65
  // fallback to IModelApp.quantityFormatter:
@@ -64,23 +70,32 @@ async function getFormatterParserSpec({ imodel, type, }) {
64
70
  const quantityFormatterSpec = IModelApp.quantityFormatter.findFormatterSpecByQuantityType(type);
65
71
  const quantityParserSpec = IModelApp.quantityFormatter.findParserSpecByQuantityType(type);
66
72
  return {
67
- formatterSpec: quantityFormatterSpec,
73
+ highPrecisionFormatterSpec: quantityFormatterSpec,
74
+ defaultFormatterSpec: quantityFormatterSpec,
68
75
  parserSpec: quantityParserSpec,
69
76
  };
70
77
  }
71
78
  const koq = await imodel.schemaContext.getSchemaItem(type);
72
79
  if (!koq) {
73
- return { formatter: undefined, parser: undefined };
80
+ return {
81
+ highPrecisionFormatterSpec: undefined,
82
+ defaultFormatterSpec: undefined,
83
+ parser: undefined,
84
+ };
74
85
  }
75
86
  // TODO: `KindOfQuantity` here is used only as a type because we don't have peerDep on `ecschema-metadata`
76
87
  // It should be added when dropping `itwinjs-core` v4 support
77
88
  const persistenceUnit = await koq.persistenceUnit;
78
89
  const formatProps = await IModelApp.formatsProvider.getFormat(type);
79
90
  if (!persistenceUnit || !formatProps) {
80
- return { formatter: undefined, parser: undefined };
91
+ return {
92
+ highPrecisionFormatterSpec: undefined,
93
+ defaultFormatterSpec: undefined,
94
+ parser: undefined,
95
+ };
81
96
  }
82
97
  const persistenceUnitName = persistenceUnit.fullName;
83
- const formatterSpec = await IModelApp.quantityFormatter.createFormatterSpec({
98
+ const highPrecisionFormatterSpec = await IModelApp.quantityFormatter.createFormatterSpec({
84
99
  formatProps: {
85
100
  ...formatProps,
86
101
  precision: parseFormatType(formatProps.type, "") === FormatType.Decimal
@@ -89,12 +104,17 @@ async function getFormatterParserSpec({ imodel, type, }) {
89
104
  },
90
105
  persistenceUnitName,
91
106
  });
107
+ const defaultFormatterSpec = await IModelApp.quantityFormatter.createFormatterSpec({
108
+ formatProps,
109
+ persistenceUnitName,
110
+ });
92
111
  const parserSpec = await IModelApp.quantityFormatter.createParserSpec({
93
112
  formatProps,
94
113
  persistenceUnitName,
95
114
  });
96
115
  return {
97
- formatterSpec,
116
+ highPrecisionFormatterSpec,
117
+ defaultFormatterSpec,
98
118
  parserSpec,
99
119
  };
100
120
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UseQuantityInfo.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/new-editors/UseQuantityInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAEL,UAAU,EACV,eAAe,GAEhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AASvE;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,EAAwB;IAC5D,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAGrD,GAAG,EAAE,CAAC,CAAC;QACR,SAAS,EAAE,SAAS;QACpB,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC,CAAC;IAEJ,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;IAErC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,QAAQ,CAAC;gBACP,SAAS,EAAE,SAAS;gBACpB,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;YACrC,MAAM,EAAE,aAAa,EAAE,UAAU,E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E,WAAW;QACX,mBAAmB;KACpB,CAAC,CAAC;IACH,OAAO;QACL,aAAa;QACb,UAAU;KACX,CAAC;AACJ,CAAC;AAED,oBAAoB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { IModelConnection, QuantityTypeArg } from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport {\n type FormatterSpec,\n FormatType,\n parseFormatType,\n type ParserSpec,\n} from \"@itwin/core-quantity\";\nimport * as React from \"react\";\nimport { useIModelConnection } from \"../../IModelConnectionContext.js\";\nimport type { KindOfQuantity } from \"@itwin/ecschema-metadata\";\n\n/* v8 ignore start */\n\ninterface UseQuantityInfoProps {\n type: QuantityTypeArg | undefined;\n}\n\n/**\n * Hook that finds the formatter and parser in `IModelApp.quantityFormatter` for a given quantity type.\n * @internal\n */\nexport function useQuantityInfo({ type }: UseQuantityInfoProps) {\n const [{ formatter, parser }, setState] = React.useState<{\n formatter: FormatterSpec | undefined;\n parser: ParserSpec | undefined;\n }>(() => ({\n formatter: undefined,\n parser: undefined,\n }));\n\n const imodel = useIModelConnection();\n\n React.useEffect(() => {\n if (type === undefined) {\n setState({\n formatter: undefined,\n parser: undefined,\n });\n return;\n }\n\n let disposed = false;\n const loadFormatterParser = async () => {\n const { formatterSpec, parserSpec } = await getFormatterParserSpec({\n imodel,\n type,\n });\n if (!disposed) {\n setState({ formatter: formatterSpec, parser: parserSpec });\n }\n };\n\n void loadFormatterParser();\n\n const removeListeners = [\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n loadFormatterParser\n ),\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n ({ quantityType }) => {\n if (quantityType === type) {\n void loadFormatterParser();\n }\n }\n ),\n ];\n if (IModelApp.formatsProvider) {\n removeListeners.push(\n IModelApp.formatsProvider.onFormatsChanged.addListener(async () =>\n loadFormatterParser()\n )\n );\n }\n\n return () => {\n disposed = true;\n removeListeners.forEach((remove) => {\n remove();\n });\n };\n }, [imodel, type]);\n\n return { formatter, parser };\n}\n\nasync function getFormatterParserSpec({\n imodel,\n type,\n}: {\n imodel?: IModelConnection;\n type: QuantityTypeArg;\n}) {\n // fallback to IModelApp.quantityFormatter:\n // - if `itwinjs-core` v4 is used\n // - don't have an iModelConnection to look up KOQ\n // - old quantity type enum is used instead of KOQ name\n if (!IModelApp.formatsProvider || !imodel || typeof type !== \"string\") {\n const quantityFormatterSpec =\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(type);\n const quantityParserSpec =\n IModelApp.quantityFormatter.findParserSpecByQuantityType(type);\n\n return {\n formatterSpec: quantityFormatterSpec,\n parserSpec: quantityParserSpec,\n };\n }\n\n const koq = await imodel.schemaContext.getSchemaItem(type);\n if (!koq) {\n return { formatter: undefined, parser: undefined };\n }\n\n // TODO: `KindOfQuantity` here is used only as a type because we don't have peerDep on `ecschema-metadata`\n // It should be added when dropping `itwinjs-core` v4 support\n const persistenceUnit = await (koq as KindOfQuantity).persistenceUnit;\n const formatProps = await IModelApp.formatsProvider.getFormat(type);\n if (!persistenceUnit || !formatProps) {\n return { formatter: undefined, parser: undefined };\n }\n\n const persistenceUnitName = persistenceUnit.fullName;\n const formatterSpec = await IModelApp.quantityFormatter.createFormatterSpec({\n formatProps: {\n ...formatProps,\n precision:\n parseFormatType(formatProps.type, \"\") === FormatType.Decimal\n ? 12\n : formatProps.precision,\n },\n persistenceUnitName,\n });\n const parserSpec = await IModelApp.quantityFormatter.createParserSpec({\n formatProps,\n persistenceUnitName,\n });\n return {\n formatterSpec,\n parserSpec,\n };\n}\n\n/* v8 ignore stop */\n"]}
1
+ {"version":3,"file":"UseQuantityInfo.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/new-editors/UseQuantityInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE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1B,oBAAoB;QACpB,UAAU;KACX,CAAC;AACJ,CAAC;AAED,oBAAoB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { IModelConnection, QuantityTypeArg } from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport {\n type FormatterSpec,\n FormatType,\n parseFormatType,\n type ParserSpec,\n} from \"@itwin/core-quantity\";\nimport * as React from \"react\";\nimport { useIModelConnection } from \"../../IModelConnectionContext.js\";\nimport type { KindOfQuantity } from \"@itwin/ecschema-metadata\";\n\n/* v8 ignore start */\n\ninterface UseQuantityInfoProps {\n type: QuantityTypeArg | undefined;\n}\n\n/**\n * Hook that finds the formatter and parser in `IModelApp.quantityFormatter` for a given quantity type.\n * @internal\n */\nexport function useQuantityInfo({ type }: UseQuantityInfoProps) {\n const [{ defaultFormatter, highPrecisionFormatter, parser }, setState] =\n React.useState<{\n defaultFormatter: FormatterSpec | undefined;\n highPrecisionFormatter: FormatterSpec | undefined;\n parser: ParserSpec | undefined;\n }>(() => ({\n defaultFormatter: undefined,\n highPrecisionFormatter: undefined,\n parser: undefined,\n }));\n\n const imodel = useIModelConnection();\n\n React.useEffect(() => {\n if (type === undefined) {\n setState({\n defaultFormatter: undefined,\n highPrecisionFormatter: undefined,\n parser: undefined,\n });\n return;\n }\n\n let disposed = false;\n const loadFormatterParser = async () => {\n const { defaultFormatterSpec, highPrecisionFormatterSpec, parserSpec } =\n await getFormatterParserSpec({\n imodel,\n type,\n });\n\n if (!disposed) {\n setState({\n defaultFormatter: defaultFormatterSpec,\n highPrecisionFormatter: highPrecisionFormatterSpec,\n parser: parserSpec,\n });\n }\n };\n\n void loadFormatterParser();\n\n const removeListeners = [\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n loadFormatterParser\n ),\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n ({ quantityType }) => {\n if (quantityType === type) {\n void loadFormatterParser();\n }\n }\n ),\n ];\n if (IModelApp.formatsProvider) {\n removeListeners.push(\n IModelApp.formatsProvider.onFormatsChanged.addListener(async () =>\n loadFormatterParser()\n )\n );\n }\n\n return () => {\n disposed = true;\n removeListeners.forEach((remove) => {\n remove();\n });\n };\n }, [imodel, type]);\n\n return { defaultFormatter, highPrecisionFormatter, parser };\n}\n\nasync function getFormatterParserSpec({\n imodel,\n type,\n}: {\n imodel?: IModelConnection;\n type: QuantityTypeArg;\n}) {\n // fallback to IModelApp.quantityFormatter:\n // - if `itwinjs-core` v4 is used\n // - don't have an iModelConnection to look up KOQ\n // - old quantity type enum is used instead of KOQ name\n if (!IModelApp.formatsProvider || !imodel || typeof type !== \"string\") {\n const quantityFormatterSpec =\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(type);\n const quantityParserSpec =\n IModelApp.quantityFormatter.findParserSpecByQuantityType(type);\n\n return {\n highPrecisionFormatterSpec: quantityFormatterSpec,\n defaultFormatterSpec: quantityFormatterSpec,\n parserSpec: quantityParserSpec,\n };\n }\n\n const koq = await imodel.schemaContext.getSchemaItem(type);\n if (!koq) {\n return {\n highPrecisionFormatterSpec: undefined,\n defaultFormatterSpec: undefined,\n parser: undefined,\n };\n }\n\n // TODO: `KindOfQuantity` here is used only as a type because we don't have peerDep on `ecschema-metadata`\n // It should be added when dropping `itwinjs-core` v4 support\n const persistenceUnit = await (koq as KindOfQuantity).persistenceUnit;\n const formatProps = await IModelApp.formatsProvider.getFormat(type);\n if (!persistenceUnit || !formatProps) {\n return {\n highPrecisionFormatterSpec: undefined,\n defaultFormatterSpec: undefined,\n parser: undefined,\n };\n }\n\n const persistenceUnitName = persistenceUnit.fullName;\n const highPrecisionFormatterSpec =\n await IModelApp.quantityFormatter.createFormatterSpec({\n formatProps: {\n ...formatProps,\n precision:\n parseFormatType(formatProps.type, \"\") === FormatType.Decimal\n ? 12\n : formatProps.precision,\n },\n persistenceUnitName,\n });\n const defaultFormatterSpec =\n await IModelApp.quantityFormatter.createFormatterSpec({\n formatProps,\n\n persistenceUnitName,\n });\n const parserSpec = await IModelApp.quantityFormatter.createParserSpec({\n formatProps,\n persistenceUnitName,\n });\n return {\n highPrecisionFormatterSpec,\n defaultFormatterSpec,\n parserSpec,\n };\n}\n\n/* v8 ignore stop */\n"]}
@@ -16,63 +16,32 @@ import { LineWeightSwatch } from "./Swatch.js";
16
16
  * @public
17
17
  */
18
18
  export class WeightPickerButton extends React.PureComponent {
19
+ _target = React.createRef();
20
+ _weightsContainer = null;
21
+ _focusTarget = React.createRef(); // weight button that should receive focus after popup is open
19
22
  constructor(props) {
20
23
  super(props);
21
- this._target = React.createRef();
22
- this._weightsContainer = null;
23
- this._focusTarget = React.createRef(); // weight button that should receive focus after popup is open
24
- this._togglePopup = () => {
25
- if (this.props.readonly)
26
- return;
27
- this.setState((prevState) => ({ showPopup: !prevState.showPopup }));
28
- };
29
- this._onPopupOpened = () => { };
30
- this._closePopup = () => {
31
- this.setState((_prevState) => ({ showPopup: false }));
32
- };
33
- this._handleWeightPicked = (weight) => {
34
- this._closePopup();
35
- this.props.onLineWeightPick && this.props.onLineWeightPick(weight);
36
- };
37
- this._handleKeyDown = (event) => {
38
- if (event.key === Key.Enter.valueOf()) {
39
- event.preventDefault();
40
- event.stopPropagation();
41
- const weightButton = document.activeElement;
42
- if (weightButton.tagName === "BUTTON") {
43
- try {
44
- const values = weightButton.id.split("-");
45
- if (values.length) {
46
- const weight = parseInt(values[values.length - 1], 10);
47
- if (!isNaN(weight)) {
48
- if (this.props.onLineWeightPick)
49
- this.props.onLineWeightPick(weight);
50
- }
51
- }
52
- }
53
- catch { }
54
- }
55
- this._closePopup();
56
- }
57
- else {
58
- switch (event.key) {
59
- case Key.ArrowDown.valueOf():
60
- this.moveFocusInPopup(false, event);
61
- break;
62
- case Key.ArrowUp.valueOf():
63
- this.moveFocusInPopup(true, event);
64
- break;
65
- }
66
- }
67
- };
68
- this._setWeightContainer = (el) => {
69
- this._weightsContainer = el;
70
- };
71
24
  this.state = { showPopup: false, targetElement: null };
72
25
  }
73
26
  setFocus() {
74
27
  this._focusTarget.current && this._focusTarget.current.focus();
75
28
  }
29
+ static defaultProps = {
30
+ weights: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
31
+ };
32
+ _togglePopup = () => {
33
+ if (this.props.readonly)
34
+ return;
35
+ this.setState((prevState) => ({ showPopup: !prevState.showPopup }));
36
+ };
37
+ _onPopupOpened = () => { };
38
+ _closePopup = () => {
39
+ this.setState((_prevState) => ({ showPopup: false }));
40
+ };
41
+ _handleWeightPicked = (weight) => {
42
+ this._closePopup();
43
+ this.props.onLineWeightPick && this.props.onLineWeightPick(weight);
44
+ };
76
45
  componentDidMount() {
77
46
  this.setState({ targetElement: this._target.current });
78
47
  }
@@ -106,6 +75,40 @@ export class WeightPickerButton extends React.PureComponent {
106
75
  }
107
76
  }
108
77
  }
78
+ _handleKeyDown = (event) => {
79
+ if (event.key === Key.Enter.valueOf()) {
80
+ event.preventDefault();
81
+ event.stopPropagation();
82
+ const weightButton = document.activeElement;
83
+ if (weightButton.tagName === "BUTTON") {
84
+ try {
85
+ const values = weightButton.id.split("-");
86
+ if (values.length) {
87
+ const weight = parseInt(values[values.length - 1], 10);
88
+ if (!isNaN(weight)) {
89
+ if (this.props.onLineWeightPick)
90
+ this.props.onLineWeightPick(weight);
91
+ }
92
+ }
93
+ }
94
+ catch { }
95
+ }
96
+ this._closePopup();
97
+ }
98
+ else {
99
+ switch (event.key) {
100
+ case Key.ArrowDown.valueOf():
101
+ this.moveFocusInPopup(false, event);
102
+ break;
103
+ case Key.ArrowUp.valueOf():
104
+ this.moveFocusInPopup(true, event);
105
+ break;
106
+ }
107
+ }
108
+ };
109
+ _setWeightContainer = (el) => {
110
+ this._weightsContainer = el;
111
+ };
109
112
  renderPopup(title) {
110
113
  return (React.createElement("div", { className: "components-weightpicker-popup-container" },
111
114
  title && React.createElement("h4", null, title),
@@ -124,7 +127,4 @@ export class WeightPickerButton extends React.PureComponent {
124
127
  React.createElement(Popup, { className: "components-weightpicker-popup", style: { width: `${width}px` }, isOpen: this.state.showPopup, position: RelativePosition.Bottom, offset: 0, showShadow: false, onClose: this._closePopup, onOpen: this._onPopupOpened, focusTarget: `#${this.buildIdForWeight(this.props.activeWeight)}`, moveFocus: true, target: this.state.targetElement, closeOnNestedPopupOutsideClick: true }, this.renderPopup(this.props.dropDownTitle))) })));
125
128
  }
126
129
  }
127
- WeightPickerButton.defaultProps = {
128
- weights: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
129
- };
130
130
  //# sourceMappingURL=WeightPickerButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WeightPickerButton.js","sourceRoot":"","sources":["../../../src/imodel-components-react/lineweight/WeightPickerButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAiC/C;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,aAG7C;IAKC,YAAY,KAAwB;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;QALP,YAAO,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAC5C,sBAAiB,GAA0B,IAAI,CAAC;QAChD,iBAAY,GAAG,KAAK,CAAC,SAAS,EAAqB,CAAC,CAAC,8DAA8D;QAgBnH,iBAAY,GAAG,GAAG,EAAE;YAC1B,IAAI,IAAI,CAAC,KAAK,CA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AAE,CAAC,EAAE,EAAE,CAAC;CACzC,AAFyB,CAExB","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 LineWeight\n */\n\nimport \"./WeightPickerButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type { ColorDef } from \"@itwin/core-common\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { ElementResizeObserver, Popup } from \"@itwin/core-react\";\nimport { LineWeightSwatch } from \"./Swatch.js\";\n\n/** Properties for the [[WeightPickerButton]] React component\n * @public\n */\nexport interface WeightPickerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n CommonProps {\n /** active weight */\n activeWeight: number;\n /** available weights */\n weights: number[];\n /** color specification */\n colorDef?: ColorDef;\n /** function to run when user selects weight swatch */\n onLineWeightPick?: ((weight: number) => void) | undefined;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n /** hide the weight label */\n hideLabel?: boolean;\n /** Title to show at top of DropDown */\n dropDownTitle?: string;\n}\n\n/** @internal */\ninterface WeightPickerState {\n showPopup: boolean;\n targetElement: HTMLDivElement | null;\n}\n\n/** WeightPickerButton component\n * @public\n */\nexport class WeightPickerButton extends React.PureComponent<\n WeightPickerProps,\n WeightPickerState\n> {\n private _target = React.createRef<HTMLDivElement>();\n private _weightsContainer: HTMLDivElement | null = null;\n private _focusTarget = React.createRef<HTMLButtonElement>(); // weight button that should receive focus after popup is open\n\n constructor(props: WeightPickerProps) {\n super(props);\n\n this.state = { showPopup: false, targetElement: null };\n }\n\n public setFocus(): void {\n this._focusTarget.current && this._focusTarget.current.focus();\n }\n\n public static defaultProps = {\n weights: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n };\n\n private _togglePopup = () => {\n if (this.props.readonly) return;\n this.setState((prevState) => ({ showPopup: !prevState.showPopup }));\n };\n\n private _onPopupOpened = () => {};\n\n private _closePopup = () => {\n this.setState((_prevState) => ({ showPopup: false }));\n };\n\n private _handleWeightPicked = (weight: number) => {\n this._closePopup();\n this.props.onLineWeightPick && this.props.onLineWeightPick(weight);\n };\n\n public override componentDidMount() {\n this.setState({ targetElement: this._target.current });\n }\n\n private buildIdForWeight(weight: number): string {\n return `ui-core-lineweight-${weight}`;\n }\n\n private moveFocusInPopup(moveUp: boolean, event: React.KeyboardEvent<any>) {\n const activeElement = document.activeElement;\n if (\n this._weightsContainer &&\n activeElement &&\n activeElement.tagName === \"BUTTON\"\n ) {\n const values = activeElement.id.split(\"-\");\n if (values.length === 4 && values[2] === \"lineweight\") {\n const weight = parseInt(values[3], 10);\n const foundIndex = this.props.weights.findIndex(\n (val) => val === weight\n );\n if (foundIndex < 0) return;\n\n const nextWeight = moveUp\n ? foundIndex <= 0\n ? this.props.weights[this.props.weights.length - 1]\n : this.props.weights[foundIndex - 1]\n : foundIndex < this.props.weights.length - 1\n ? this.props.weights[foundIndex + 1]\n : this.props.weights[0];\n\n const focusLocation = this._weightsContainer.querySelector(\n `#${this.buildIdForWeight(nextWeight)}`\n ) as HTMLButtonElement;\n if (focusLocation) {\n focusLocation.focus();\n event.preventDefault();\n event.stopPropagation();\n }\n }\n }\n }\n\n private _handleKeyDown = (event: React.KeyboardEvent<any>) => {\n if (event.key === Key.Enter.valueOf()) {\n event.preventDefault();\n event.stopPropagation();\n const weightButton = document.activeElement as HTMLElement;\n if (weightButton.tagName === \"BUTTON\") {\n try {\n const values = weightButton.id.split(\"-\");\n if (values.length) {\n const weight = parseInt(values[values.length - 1], 10);\n if (!isNaN(weight)) {\n if (this.props.onLineWeightPick)\n this.props.onLineWeightPick(weight);\n }\n }\n } catch {}\n }\n this._closePopup();\n } else {\n switch (event.key) {\n case Key.ArrowDown.valueOf():\n this.moveFocusInPopup(false, event);\n break;\n case Key.ArrowUp.valueOf():\n this.moveFocusInPopup(true, event);\n break;\n }\n }\n };\n\n private _setWeightContainer = (el: any) => {\n this._weightsContainer = el;\n };\n\n private renderPopup(title: string | undefined) {\n return (\n <div className=\"components-weightpicker-popup-container\">\n {title && <h4>{title}</h4>}\n {/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}\n <ul\n data-testid=\"components-weightpicker-popup-lines\"\n className=\"components-weightpicker-popup-lines\"\n onKeyDown={this._handleKeyDown}\n ref={this._setWeightContainer}\n >\n {this.props.weights.map((weight, index) => {\n const classNames = classnames(\n \"components-weightpicker-swatch\",\n weight === this.props.activeWeight && \"active\"\n );\n return (\n <LineWeightSwatch\n className={classNames}\n key={index}\n colorDef={this.props.colorDef}\n id={this.buildIdForWeight(weight)}\n hideLabel={this.props.hideLabel}\n onClick={this._handleWeightPicked.bind(this, weight)}\n weight={weight}\n />\n );\n })}\n </ul>\n </div>\n );\n }\n\n public override render() {\n const buttonClassNames = classnames(\n \"components-weightpicker-button\",\n this.props.className\n );\n\n return (\n <>\n <div ref={this._target} style={this.props.style}>\n <LineWeightSwatch\n data-testid=\"components-weightpicker-button\"\n className={buttonClassNames}\n weight={this.props.activeWeight}\n colorDef={this.props.colorDef}\n readonly={this.props.readonly}\n disabled={this.props.disabled}\n hideLabel={this.props.hideLabel}\n aria-haspopup=\"listbox\"\n aria-expanded={this.state.showPopup}\n onClick={this._togglePopup}\n />\n </div>\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <ElementResizeObserver\n watchedElement={this.state.targetElement}\n render={({ width }) => (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Popup\n className=\"components-weightpicker-popup\"\n style={{ width: `${width}px` }}\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n offset={0}\n showShadow={false}\n onClose={this._closePopup}\n onOpen={this._onPopupOpened}\n focusTarget={`#${this.buildIdForWeight(this.props.activeWeight)}`}\n moveFocus={true}\n target={this.state.targetElement}\n closeOnNestedPopupOutsideClick\n >\n {this.renderPopup(this.props.dropDownTitle)}\n </Popup>\n )}\n />\n </>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"WeightPickerButton.js","sourceRoot":"","sources":["../../../src/imodel-components-react/lineweight/WeightPickerButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAiC/C;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,aAG7C;IACS,OAAO,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;IAC5C,iBAAiB,GAA0B,IAAI,CAAC;IAChD,YAAY,GAAG,KAAK,CAAC,SAAS,EAAqB,CAAC,CAAC,8DAA8D;IAE3H,YAAY,KAAwB;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,KAAK,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IACzD,CAAC;IAEM,QAAQ;QACb,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACjE,CAAC;IAEM,MAAM,CAAC,YAAY,GAAG;QAC3B,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,E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AQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,mBACjB,SAAS,mBACR,IAAI,CAAC,KAAK,CAAC,SAAS,EACnC,OAAO,EAAE,IAAI,CAAC,YAAY,GAC1B,CACE;YAEN,oBAAC,qBAAqB,IACpB,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EACxC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;gBACrB,4DAA4D;gBAC5D,oBAAC,KAAK,IACJ,SAAS,EAAC,+BAA+B,EACzC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAAE,EAC9B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC5B,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EACjC,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,MAAM,EAAE,IAAI,CAAC,cAAc,EAC3B,WAAW,EAAE,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,EACjE,SAAS,EAAE,IAAI,EACf,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EAChC,8BAA8B,UAE7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CACrC,CACT,GACD,CACD,CACJ,CAAC;IACJ,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 LineWeight\n */\n\nimport \"./WeightPickerButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type { ColorDef } from \"@itwin/core-common\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { ElementResizeObserver, Popup } from \"@itwin/core-react\";\nimport { LineWeightSwatch } from \"./Swatch.js\";\n\n/** Properties for the [[WeightPickerButton]] React component\n * @public\n */\nexport interface WeightPickerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n CommonProps {\n /** active weight */\n activeWeight: number;\n /** available weights */\n weights: number[];\n /** color specification */\n colorDef?: ColorDef;\n /** function to run when user selects weight swatch */\n onLineWeightPick?: ((weight: number) => void) | undefined;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n /** hide the weight label */\n hideLabel?: boolean;\n /** Title to show at top of DropDown */\n dropDownTitle?: string;\n}\n\n/** @internal */\ninterface WeightPickerState {\n showPopup: boolean;\n targetElement: HTMLDivElement | null;\n}\n\n/** WeightPickerButton component\n * @public\n */\nexport class WeightPickerButton extends React.PureComponent<\n WeightPickerProps,\n WeightPickerState\n> {\n private _target = React.createRef<HTMLDivElement>();\n private _weightsContainer: HTMLDivElement | null = null;\n private _focusTarget = React.createRef<HTMLButtonElement>(); // weight button that should receive focus after popup is open\n\n constructor(props: WeightPickerProps) {\n super(props);\n\n this.state = { showPopup: false, targetElement: null };\n }\n\n public setFocus(): void {\n this._focusTarget.current && this._focusTarget.current.focus();\n }\n\n public static defaultProps = {\n weights: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n };\n\n private _togglePopup = () => {\n if (this.props.readonly) return;\n this.setState((prevState) => ({ showPopup: !prevState.showPopup }));\n };\n\n private _onPopupOpened = () => {};\n\n private _closePopup = () => {\n this.setState((_prevState) => ({ showPopup: false }));\n };\n\n private _handleWeightPicked = (weight: number) => {\n this._closePopup();\n this.props.onLineWeightPick && this.props.onLineWeightPick(weight);\n };\n\n public override componentDidMount() {\n this.setState({ targetElement: this._target.current });\n }\n\n private buildIdForWeight(weight: number): string {\n return `ui-core-lineweight-${weight}`;\n }\n\n private moveFocusInPopup(moveUp: boolean, event: React.KeyboardEvent<any>) {\n const activeElement = document.activeElement;\n if (\n this._weightsContainer &&\n activeElement &&\n activeElement.tagName === \"BUTTON\"\n ) {\n const values = activeElement.id.split(\"-\");\n if (values.length === 4 && values[2] === \"lineweight\") {\n const weight = parseInt(values[3], 10);\n const foundIndex = this.props.weights.findIndex(\n (val) => val === weight\n );\n if (foundIndex < 0) return;\n\n const nextWeight = moveUp\n ? foundIndex <= 0\n ? this.props.weights[this.props.weights.length - 1]\n : this.props.weights[foundIndex - 1]\n : foundIndex < this.props.weights.length - 1\n ? this.props.weights[foundIndex + 1]\n : this.props.weights[0];\n\n const focusLocation = this._weightsContainer.querySelector(\n `#${this.buildIdForWeight(nextWeight)}`\n ) as HTMLButtonElement;\n if (focusLocation) {\n focusLocation.focus();\n event.preventDefault();\n event.stopPropagation();\n }\n }\n }\n }\n\n private _handleKeyDown = (event: React.KeyboardEvent<any>) => {\n if (event.key === Key.Enter.valueOf()) {\n event.preventDefault();\n event.stopPropagation();\n const weightButton = document.activeElement as HTMLElement;\n if (weightButton.tagName === \"BUTTON\") {\n try {\n const values = weightButton.id.split(\"-\");\n if (values.length) {\n const weight = parseInt(values[values.length - 1], 10);\n if (!isNaN(weight)) {\n if (this.props.onLineWeightPick)\n this.props.onLineWeightPick(weight);\n }\n }\n } catch {}\n }\n this._closePopup();\n } else {\n switch (event.key) {\n case Key.ArrowDown.valueOf():\n this.moveFocusInPopup(false, event);\n break;\n case Key.ArrowUp.valueOf():\n this.moveFocusInPopup(true, event);\n break;\n }\n }\n };\n\n private _setWeightContainer = (el: any) => {\n this._weightsContainer = el;\n };\n\n private renderPopup(title: string | undefined) {\n return (\n <div className=\"components-weightpicker-popup-container\">\n {title && <h4>{title}</h4>}\n {/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}\n <ul\n data-testid=\"components-weightpicker-popup-lines\"\n className=\"components-weightpicker-popup-lines\"\n onKeyDown={this._handleKeyDown}\n ref={this._setWeightContainer}\n >\n {this.props.weights.map((weight, index) => {\n const classNames = classnames(\n \"components-weightpicker-swatch\",\n weight === this.props.activeWeight && \"active\"\n );\n return (\n <LineWeightSwatch\n className={classNames}\n key={index}\n colorDef={this.props.colorDef}\n id={this.buildIdForWeight(weight)}\n hideLabel={this.props.hideLabel}\n onClick={this._handleWeightPicked.bind(this, weight)}\n weight={weight}\n />\n );\n })}\n </ul>\n </div>\n );\n }\n\n public override render() {\n const buttonClassNames = classnames(\n \"components-weightpicker-button\",\n this.props.className\n );\n\n return (\n <>\n <div ref={this._target} style={this.props.style}>\n <LineWeightSwatch\n data-testid=\"components-weightpicker-button\"\n className={buttonClassNames}\n weight={this.props.activeWeight}\n colorDef={this.props.colorDef}\n readonly={this.props.readonly}\n disabled={this.props.disabled}\n hideLabel={this.props.hideLabel}\n aria-haspopup=\"listbox\"\n aria-expanded={this.state.showPopup}\n onClick={this._togglePopup}\n />\n </div>\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <ElementResizeObserver\n watchedElement={this.state.targetElement}\n render={({ width }) => (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Popup\n className=\"components-weightpicker-popup\"\n style={{ width: `${width}px` }}\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n offset={0}\n showShadow={false}\n onClose={this._closePopup}\n onOpen={this._onPopupOpened}\n focusTarget={`#${this.buildIdForWeight(this.props.activeWeight)}`}\n moveFocus={true}\n target={this.state.targetElement}\n closeOnNestedPopupOutsideClick\n >\n {this.renderPopup(this.props.dropDownTitle)}\n </Popup>\n )}\n />\n </>\n );\n }\n}\n"]}
@@ -43,10 +43,7 @@ export class Cube extends React.PureComponent {
43
43
  }
44
44
  /** @internal */
45
45
  export class CubeFace extends React.Component {
46
- constructor() {
47
- super(...arguments);
48
- this._faceWidth = 0;
49
- }
46
+ _faceWidth = 0;
50
47
  render() {
51
48
  const { rotMatrix, face, style, children, ...props } = this.props;
52
49
  if (face === Face.None)
@@ -1 +1 @@
1
- {"version":3,"file":"Cube.js","sourceRoot":"","sources":["../../../src/imodel-components-react/navigationaids/Cube.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,aAAa,CAAC;AACrB,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;GAEG;AACH,MAAM,CAAN,IAAY,IAQX;AARD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,yBAAiB,CAAA;IACjB,mBAAW,CAAA;AACb,CAAC,EARW,IAAI,KAAJ,IAAI,QAQf;AAaD;;GAEG;AACH,MAAM,OAAO,IAAK,SAAQ,KAAK,CAAC,aAAwB;IACtC,MAAM;QACpB,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7D,OAAO,CACL,6BACE,SAAS,EAAE,UAAU,CAAC,uBAAuB,EAAE,SAAS,CAAC,iBAC7C,iBAAiB,KACzB,KAAK,IAER;YACC,IAAI,CAAC,KAAK;YACV,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,KAAK;YACV,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,GAAG;YACR,IAAI,CAAC,MAAM;SACZ,CAAC,GAAG,CAAC,CAAC,IAAU,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,OAAO,CACL,oBAAC,QAAQ,IAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,IAClD,OAAO,CACC,CACZ,CAAC;QACJ,CAAC,CAAC,CACE,CACP,CAAC;IACJ,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AS;YACT,eAAe,EAAE,SAAS;YAC1B,GAAG,KAAK;SACT,CAAC;QAEF,OAAO,CACL,6BACE,KAAK,EAAE,CAAC,iBACK,wBAAwB,IAAI,EAAE,EAC3C,SAAS,EAAE,OAAO,EAClB,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;gBACT,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC,KACG,KAAK,IAER,QAAQ,CACL,CACP,CAAC;IACJ,CAAC;IAEO,uBAAuB,CAAC,IAAU;QACxC,IAAI,SAAS,GAAG,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI;YAAE,SAAS,GAAG,QAAQ,IAAI,EAAE,CAAC;QAEnD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Cube\n */\n\nimport \"./Cube.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Matrix3d } from \"@itwin/core-geometry\";\nimport type { CommonProps } from \"@itwin/core-react\";\n\n/** Cube Face enumeration\n * @public\n */\nexport enum Face {\n None = \"\",\n Left = \"left\",\n Right = \"right\",\n Back = \"back\",\n Front = \"front\",\n Bottom = \"bottom\",\n Top = \"top\",\n}\n\n/** Properties for the [[Cube]] React component\n * @public\n */\nexport interface CubeProps\n extends React.AllHTMLAttributes<HTMLDivElement>,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n CommonProps {\n faces?: { [key: string]: React.ReactNode };\n rotMatrix: Matrix3d;\n}\n\n/** Cube React component used by the 3d Cube Navigation Aid\n * @public\n */\nexport class Cube extends React.PureComponent<CubeProps> {\n public override render(): React.ReactNode {\n const { faces, rotMatrix, className, ...props } = this.props;\n return (\n <div\n className={classnames(\"components-cube-css3d\", className)}\n data-testid=\"components-cube\"\n {...props}\n >\n {[\n Face.Front,\n Face.Back,\n Face.Right,\n Face.Left,\n Face.Top,\n Face.Bottom,\n ].map((face: Face) => {\n const content = faces && faces[face];\n return (\n <CubeFace key={face} rotMatrix={rotMatrix} face={face}>\n {content}\n </CubeFace>\n );\n })}\n </div>\n );\n }\n}\n\n/** @internal */\nexport interface CubeFaceProps extends React.AllHTMLAttributes<HTMLDivElement> {\n rotMatrix: Matrix3d;\n face: Face;\n}\n\n/** @internal */\nexport class CubeFace extends React.Component<CubeFaceProps> {\n private _faceWidth: number = 0;\n public override render(): React.ReactNode {\n const { rotMatrix, face, style, children, ...props } = this.props;\n if (face === Face.None) return null;\n const classes = classnames(\"face\", this.getCSSClassNameFromFace(face));\n // orient face (flip because of y axis reversal, rotate as necessary)\n let reorient: Matrix3d = Matrix3d.createRowValues(\n 1,\n 0,\n 0,\n 0,\n -1,\n 0,\n 0,\n 0,\n 1\n );\n // Position face correctly (applies to rotation, as well as translation)\n let reposition: Matrix3d = Matrix3d.createIdentity();\n switch (this.props.face) {\n case Face.Bottom:\n reposition = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, -1);\n reorient = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, 1);\n break;\n case Face.Right:\n reposition = Matrix3d.createRowValues(0, 0, 1, 0, 1, 0, -1, 0, 0);\n reorient = Matrix3d.createRowValues(0, 1, 0, 1, 0, 0, 0, 0, 1);\n break;\n case Face.Left:\n reposition = Matrix3d.createRowValues(0, 0, -1, 0, 1, 0, 1, 0, 0);\n reorient = Matrix3d.createRowValues(0, -1, 0, -1, 0, 0, 0, 0, 1);\n break;\n case Face.Back:\n reposition = Matrix3d.createRowValues(1, 0, 0, 0, 0, 1, 0, -1, 0);\n reorient = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, 1);\n break;\n case Face.Front:\n reposition = Matrix3d.createRowValues(1, 0, 0, 0, 0, -1, 0, 1, 0);\n reorient = Matrix3d.createRowValues(1, 0, 0, 0, -1, 0, 0, 0, 1);\n break;\n }\n const repositioned = rotMatrix.multiplyMatrixMatrix(reposition);\n const vect = repositioned.multiplyXYZ(0, 0, this._faceWidth);\n const m = repositioned.multiplyMatrixMatrix(reorient);\n const list = [\n m.at(0, 0),\n -m.at(1, 0),\n m.at(2, 0),\n 0,\n m.at(0, 1),\n -m.at(1, 1),\n m.at(2, 1),\n 0,\n m.at(0, 2),\n -m.at(1, 2),\n m.at(2, 2),\n 0,\n vect.at(0),\n -vect.at(1),\n vect.at(2) -\n this._faceWidth /* move back faceWidth so face is on screen level */,\n 1,\n ];\n const transform = `matrix3d(${list.join(\", \")})`;\n const s: React.CSSProperties = {\n transform,\n WebkitTransform: transform,\n ...style,\n };\n\n return (\n <div\n style={s}\n data-testid={`components-cube-face-${face}`}\n className={classes}\n ref={(e) => {\n this._faceWidth = (e && e.clientWidth / 2) || 0;\n }}\n {...props}\n >\n {children}\n </div>\n );\n }\n\n private getCSSClassNameFromFace(face: Face): string {\n let className = \"\";\n\n if (face !== Face.None) className = `cube-${face}`;\n\n return className;\n }\n}\n"]}
1
+ {"version":3,"file":"Cube.js","sourceRoot":"","sources":["../../../src/imodel-components-react/navigationaids/Cube.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,aAAa,CAAC;AACrB,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;GAEG;AACH,MAAM,CAAN,IAAY,IAQX;AARD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,yBAAiB,CAAA;IACjB,mBAAW,CAAA;AACb,CAAC,EARW,IAAI,KAA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nB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Cube\n */\n\nimport \"./Cube.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Matrix3d } from \"@itwin/core-geometry\";\nimport type { CommonProps } from \"@itwin/core-react\";\n\n/** Cube Face enumeration\n * @public\n */\nexport enum Face {\n None = \"\",\n Left = \"left\",\n Right = \"right\",\n Back = \"back\",\n Front = \"front\",\n Bottom = \"bottom\",\n Top = \"top\",\n}\n\n/** Properties for the [[Cube]] React component\n * @public\n */\nexport interface CubeProps\n extends React.AllHTMLAttributes<HTMLDivElement>,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n CommonProps {\n faces?: { [key: string]: React.ReactNode };\n rotMatrix: Matrix3d;\n}\n\n/** Cube React component used by the 3d Cube Navigation Aid\n * @public\n */\nexport class Cube extends React.PureComponent<CubeProps> {\n public override render(): React.ReactNode {\n const { faces, rotMatrix, className, ...props } = this.props;\n return (\n <div\n className={classnames(\"components-cube-css3d\", className)}\n data-testid=\"components-cube\"\n {...props}\n >\n {[\n Face.Front,\n Face.Back,\n Face.Right,\n Face.Left,\n Face.Top,\n Face.Bottom,\n ].map((face: Face) => {\n const content = faces && faces[face];\n return (\n <CubeFace key={face} rotMatrix={rotMatrix} face={face}>\n {content}\n </CubeFace>\n );\n })}\n </div>\n );\n }\n}\n\n/** @internal */\nexport interface CubeFaceProps extends React.AllHTMLAttributes<HTMLDivElement> {\n rotMatrix: Matrix3d;\n face: Face;\n}\n\n/** @internal */\nexport class CubeFace extends React.Component<CubeFaceProps> {\n private _faceWidth: number = 0;\n public override render(): React.ReactNode {\n const { rotMatrix, face, style, children, ...props } = this.props;\n if (face === Face.None) return null;\n const classes = classnames(\"face\", this.getCSSClassNameFromFace(face));\n // orient face (flip because of y axis reversal, rotate as necessary)\n let reorient: Matrix3d = Matrix3d.createRowValues(\n 1,\n 0,\n 0,\n 0,\n -1,\n 0,\n 0,\n 0,\n 1\n );\n // Position face correctly (applies to rotation, as well as translation)\n let reposition: Matrix3d = Matrix3d.createIdentity();\n switch (this.props.face) {\n case Face.Bottom:\n reposition = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, -1);\n reorient = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, 1);\n break;\n case Face.Right:\n reposition = Matrix3d.createRowValues(0, 0, 1, 0, 1, 0, -1, 0, 0);\n reorient = Matrix3d.createRowValues(0, 1, 0, 1, 0, 0, 0, 0, 1);\n break;\n case Face.Left:\n reposition = Matrix3d.createRowValues(0, 0, -1, 0, 1, 0, 1, 0, 0);\n reorient = Matrix3d.createRowValues(0, -1, 0, -1, 0, 0, 0, 0, 1);\n break;\n case Face.Back:\n reposition = Matrix3d.createRowValues(1, 0, 0, 0, 0, 1, 0, -1, 0);\n reorient = Matrix3d.createRowValues(-1, 0, 0, 0, 1, 0, 0, 0, 1);\n break;\n case Face.Front:\n reposition = Matrix3d.createRowValues(1, 0, 0, 0, 0, -1, 0, 1, 0);\n reorient = Matrix3d.createRowValues(1, 0, 0, 0, -1, 0, 0, 0, 1);\n break;\n }\n const repositioned = rotMatrix.multiplyMatrixMatrix(reposition);\n const vect = repositioned.multiplyXYZ(0, 0, this._faceWidth);\n const m = repositioned.multiplyMatrixMatrix(reorient);\n const list = [\n m.at(0, 0),\n -m.at(1, 0),\n m.at(2, 0),\n 0,\n m.at(0, 1),\n -m.at(1, 1),\n m.at(2, 1),\n 0,\n m.at(0, 2),\n -m.at(1, 2),\n m.at(2, 2),\n 0,\n vect.at(0),\n -vect.at(1),\n vect.at(2) -\n this._faceWidth /* move back faceWidth so face is on screen level */,\n 1,\n ];\n const transform = `matrix3d(${list.join(\", \")})`;\n const s: React.CSSProperties = {\n transform,\n WebkitTransform: transform,\n ...style,\n };\n\n return (\n <div\n style={s}\n data-testid={`components-cube-face-${face}`}\n className={classes}\n ref={(e) => {\n this._faceWidth = (e && e.clientWidth / 2) || 0;\n }}\n {...props}\n >\n {children}\n </div>\n );\n }\n\n private getCSSClassNameFromFace(face: Face): string {\n let className = \"\";\n\n if (face !== Face.None) className = `cube-${face}`;\n\n return className;\n }\n}\n"]}