@itwin/map-layers 6.0.0-dev.0 → 6.0.0-dev.2

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 (93) hide show
  1. package/lib/cjs/ui/hooks/useCrossOriginPopup.d.ts +7 -0
  2. package/lib/cjs/ui/hooks/useCrossOriginPopup.d.ts.map +1 -0
  3. package/lib/cjs/ui/hooks/useCrossOriginPopup.js +123 -0
  4. package/lib/cjs/ui/hooks/useCrossOriginPopup.js.map +1 -0
  5. package/lib/cjs/ui/hooks/useInterval.d.ts +7 -0
  6. package/lib/cjs/ui/hooks/useInterval.d.ts.map +1 -0
  7. package/lib/cjs/ui/hooks/useInterval.js +60 -0
  8. package/lib/cjs/ui/hooks/useInterval.js.map +1 -0
  9. package/lib/cjs/ui/hooks/useResizeObserver.d.ts +2 -0
  10. package/lib/cjs/ui/hooks/useResizeObserver.d.ts.map +1 -0
  11. package/lib/cjs/ui/hooks/useResizeObserver.js +66 -0
  12. package/lib/cjs/ui/hooks/useResizeObserver.js.map +1 -0
  13. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  14. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +26 -34
  15. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  16. package/lib/cjs/ui/widget/CustomParamsSettings.d.ts +5 -1
  17. package/lib/cjs/ui/widget/CustomParamsSettings.d.ts.map +1 -1
  18. package/lib/cjs/ui/widget/CustomParamsSettings.js +30 -8
  19. package/lib/cjs/ui/widget/CustomParamsSettings.js.map +1 -1
  20. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  21. package/lib/cjs/ui/widget/FeatureInfoWidget.js +5 -4
  22. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  23. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  24. package/lib/cjs/ui/widget/MapLayerDroppable.js +2 -2
  25. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  26. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  27. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +5 -25
  28. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  29. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +2 -2
  30. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +5 -1
  31. package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
  32. package/lib/cjs/ui/widget/MapManagerSettings.js +9 -7
  33. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  34. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +0 -1
  35. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  36. package/lib/cjs/ui/widget/MapUrlDialog.js +2 -3
  37. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  38. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  39. package/lib/cjs/ui/widget/SubLayersPopupButton.js +1 -13
  40. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  41. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  42. package/lib/cjs/ui/widget/SubLayersTree.js +9 -11
  43. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  44. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  45. package/lib/cjs/ui/widget/TransparencyPopupButton.js +4 -10
  46. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  47. package/lib/esm/ui/hooks/useCrossOriginPopup.d.ts +7 -0
  48. package/lib/esm/ui/hooks/useCrossOriginPopup.d.ts.map +1 -0
  49. package/lib/esm/ui/hooks/useCrossOriginPopup.js +96 -0
  50. package/lib/esm/ui/hooks/useCrossOriginPopup.js.map +1 -0
  51. package/lib/esm/ui/hooks/useInterval.d.ts +7 -0
  52. package/lib/esm/ui/hooks/useInterval.d.ts.map +1 -0
  53. package/lib/esm/ui/hooks/useInterval.js +33 -0
  54. package/lib/esm/ui/hooks/useInterval.js.map +1 -0
  55. package/lib/esm/ui/hooks/useResizeObserver.d.ts +2 -0
  56. package/lib/esm/ui/hooks/useResizeObserver.d.ts.map +1 -0
  57. package/lib/esm/ui/hooks/useResizeObserver.js +39 -0
  58. package/lib/esm/ui/hooks/useResizeObserver.js.map +1 -0
  59. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  60. package/lib/esm/ui/widget/AttachLayerPopupButton.js +27 -35
  61. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  62. package/lib/esm/ui/widget/CustomParamsSettings.d.ts +5 -1
  63. package/lib/esm/ui/widget/CustomParamsSettings.d.ts.map +1 -1
  64. package/lib/esm/ui/widget/CustomParamsSettings.js +30 -8
  65. package/lib/esm/ui/widget/CustomParamsSettings.js.map +1 -1
  66. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  67. package/lib/esm/ui/widget/FeatureInfoWidget.js +5 -4
  68. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  69. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  70. package/lib/esm/ui/widget/MapLayerDroppable.js +2 -2
  71. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  72. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  73. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +7 -27
  74. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  75. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +2 -2
  76. package/lib/esm/ui/widget/MapManagerSettings.d.ts +5 -1
  77. package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
  78. package/lib/esm/ui/widget/MapManagerSettings.js +10 -8
  79. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  80. package/lib/esm/ui/widget/MapUrlDialog.d.ts +0 -1
  81. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  82. package/lib/esm/ui/widget/MapUrlDialog.js +1 -2
  83. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  84. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  85. package/lib/esm/ui/widget/SubLayersPopupButton.js +3 -15
  86. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  87. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  88. package/lib/esm/ui/widget/SubLayersTree.js +10 -12
  89. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  90. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  91. package/lib/esm/ui/widget/TransparencyPopupButton.js +6 -12
  92. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  93. package/package.json +18 -56
@@ -0,0 +1,7 @@
1
+ /** Hook that will show a popup window
2
+ * @internal
3
+ * Reference: https://github.com/iTwin/appui/commit/b8c0ac6eec4b8f1551cde3b7913df135ccd0f4f5
4
+ * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useCrossOriginPopup.tsx
5
+ */
6
+ export declare function useCrossOriginPopup(visible: boolean, url: string | undefined, title: string, width: number, height: number, onClose: () => void): void;
7
+ //# sourceMappingURL=useCrossOriginPopup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCrossOriginPopup.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/useCrossOriginPopup.tsx"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,IAAI,QAsGpB"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useCrossOriginPopup = void 0;
27
+ /*---------------------------------------------------------------------------------------------
28
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
29
+ * See LICENSE.md in the project root for license terms and full copyright notice.
30
+ *--------------------------------------------------------------------------------------------*/
31
+ const React = __importStar(require("react"));
32
+ const useInterval_1 = require("./useInterval");
33
+ /** Hook that will show a popup window
34
+ * @internal
35
+ * Reference: https://github.com/iTwin/appui/commit/b8c0ac6eec4b8f1551cde3b7913df135ccd0f4f5
36
+ * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useCrossOriginPopup.tsx
37
+ */
38
+ function useCrossOriginPopup(visible, url, title, width, height, onClose) {
39
+ const [checkPopupAliveDelay, setCheckPopupAliveDelay] = React.useState();
40
+ // ONLY re-render the popup when visibility changes, any other changes get deferred until next visibility change
41
+ // hence the massive use of 'useRef'
42
+ const popupWindow = React.useRef();
43
+ const savedUrl = React.useRef(url);
44
+ const savedTitle = React.useRef(title);
45
+ const savedWidth = React.useRef(width);
46
+ const savedHeight = React.useRef(height);
47
+ const savedOnClose = React.useRef(onClose);
48
+ React.useEffect(() => {
49
+ savedUrl.current = url;
50
+ }, [url]);
51
+ React.useEffect(() => {
52
+ savedTitle.current = title;
53
+ }, [title]);
54
+ React.useEffect(() => {
55
+ savedWidth.current = width;
56
+ }, [width]);
57
+ React.useEffect(() => {
58
+ savedHeight.current = height;
59
+ }, [height]);
60
+ React.useEffect(() => {
61
+ savedOnClose.current = onClose;
62
+ }, [onClose]);
63
+ // Cleanup method after a popup closure. Also calls the OnClose callback.
64
+ const handleClosedPopup = React.useCallback(() => {
65
+ savedOnClose.current();
66
+ setCheckPopupAliveDelay(undefined);
67
+ popupWindow.current = undefined;
68
+ }, []);
69
+ const closePopup = React.useCallback(() => {
70
+ if (popupWindow.current !== undefined) {
71
+ popupWindow.current.close(); // Manually close the popup
72
+ handleClosedPopup();
73
+ }
74
+ }, [handleClosedPopup]);
75
+ const checkPopupClosed = React.useCallback(() => {
76
+ if (popupWindow.current?.closed) {
77
+ // Popup has been closed by end-user, inform our host and cleanup
78
+ handleClosedPopup();
79
+ }
80
+ }, [handleClosedPopup]);
81
+ // Close popup when parent window get closed
82
+ React.useEffect(() => {
83
+ window.onbeforeunload = (_event) => {
84
+ closePopup();
85
+ };
86
+ return () => {
87
+ window.onbeforeunload = null;
88
+ };
89
+ }, [closePopup]);
90
+ // Whenever the hook is unloaded, make sure the underlying popup get closed.
91
+ // Note: An interval is used to check if popup was closed by user: because we access
92
+ // a cross domain resource inside the popup, we don't have access to popup window events.
93
+ // As a workaround, we periodically check if popup is still alive.
94
+ // Reference: https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
95
+ React.useEffect(() => {
96
+ return () => {
97
+ closePopup();
98
+ };
99
+ }, [closePopup]);
100
+ // Timer that checks if popup was closed by end-user
101
+ (0, useInterval_1.useInterval)(checkPopupClosed, checkPopupAliveDelay);
102
+ // ==> Main render effect
103
+ // Monitors visibility changes and open/close the popup accordingly.
104
+ React.useEffect(() => {
105
+ // If visible and a popup window is not already open, open a new popup window
106
+ if (visible && popupWindow.current === undefined) {
107
+ const popup = window.open(savedUrl.current, savedTitle.current, `width=${savedWidth.current},height=${savedHeight.current}`);
108
+ if (popup) {
109
+ popup.focus();
110
+ popupWindow.current = popup;
111
+ // Start and interval that will check if popup got closed by user
112
+ setCheckPopupAliveDelay(1000);
113
+ }
114
+ }
115
+ // If not visible but a previous popup window is still open, close it.
116
+ if (!visible && popupWindow.current !== undefined) {
117
+ popupWindow.current.close();
118
+ handleClosedPopup();
119
+ }
120
+ }, [handleClosedPopup, visible]);
121
+ }
122
+ exports.useCrossOriginPopup = useCrossOriginPopup;
123
+ //# sourceMappingURL=useCrossOriginPopup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCrossOriginPopup.js","sourceRoot":"","sources":["../../../../src/ui/hooks/useCrossOriginPopup.tsx"],"names":[],"mappings":"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","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 *--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\nimport { useInterval } from \"./useInterval\";\n\n/** Hook that will show a popup window\n * @internal\n * Reference: https://github.com/iTwin/appui/commit/b8c0ac6eec4b8f1551cde3b7913df135ccd0f4f5\n * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useCrossOriginPopup.tsx\n */\nexport function useCrossOriginPopup(\n visible: boolean,\n url: string | undefined,\n title: string,\n width: number,\n height: number,\n onClose: () => void\n) {\n const [checkPopupAliveDelay, setCheckPopupAliveDelay] = React.useState<\n number | undefined\n >();\n\n // ONLY re-render the popup when visibility changes, any other changes get deferred until next visibility change\n // hence the massive use of 'useRef'\n const popupWindow = React.useRef<Window>();\n const savedUrl = React.useRef(url);\n const savedTitle = React.useRef(title);\n const savedWidth = React.useRef(width);\n const savedHeight = React.useRef(height);\n const savedOnClose = React.useRef(onClose);\n\n React.useEffect(() => {\n savedUrl.current = url;\n }, [url]);\n React.useEffect(() => {\n savedTitle.current = title;\n }, [title]);\n React.useEffect(() => {\n savedWidth.current = width;\n }, [width]);\n React.useEffect(() => {\n savedHeight.current = height;\n }, [height]);\n React.useEffect(() => {\n savedOnClose.current = onClose;\n }, [onClose]);\n\n // Cleanup method after a popup closure. Also calls the OnClose callback.\n const handleClosedPopup = React.useCallback(() => {\n savedOnClose.current();\n setCheckPopupAliveDelay(undefined);\n popupWindow.current = undefined;\n }, []);\n\n const closePopup = React.useCallback(() => {\n if (popupWindow.current !== undefined) {\n popupWindow.current.close(); // Manually close the popup\n handleClosedPopup();\n }\n }, [handleClosedPopup]);\n\n const checkPopupClosed = React.useCallback(() => {\n if (popupWindow.current?.closed) {\n // Popup has been closed by end-user, inform our host and cleanup\n handleClosedPopup();\n }\n }, [handleClosedPopup]);\n\n // Close popup when parent window get closed\n React.useEffect(() => {\n window.onbeforeunload = (_event) => {\n closePopup();\n };\n return () => {\n window.onbeforeunload = null;\n };\n }, [closePopup]);\n\n // Whenever the hook is unloaded, make sure the underlying popup get closed.\n // Note: An interval is used to check if popup was closed by user: because we access\n // a cross domain resource inside the popup, we don't have access to popup window events.\n // As a workaround, we periodically check if popup is still alive.\n // Reference: https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128\n React.useEffect(() => {\n return () => {\n closePopup();\n };\n }, [closePopup]);\n\n // Timer that checks if popup was closed by end-user\n useInterval(checkPopupClosed, checkPopupAliveDelay);\n\n // ==> Main render effect\n // Monitors visibility changes and open/close the popup accordingly.\n React.useEffect(() => {\n // If visible and a popup window is not already open, open a new popup window\n if (visible && popupWindow.current === undefined) {\n const popup = window.open(\n savedUrl.current,\n savedTitle.current,\n `width=${savedWidth.current},height=${savedHeight.current}`\n );\n if (popup) {\n popup.focus();\n popupWindow.current = popup;\n\n // Start and interval that will check if popup got closed by user\n setCheckPopupAliveDelay(1000);\n }\n }\n\n // If not visible but a previous popup window is still open, close it.\n if (!visible && popupWindow.current !== undefined) {\n popupWindow.current.close();\n\n handleClosedPopup();\n }\n }, [handleClosedPopup, visible]);\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /** Hook that create an interval and clears it when unloaded
2
+ * Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md
3
+ * @internal
4
+ * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useInterval.tsx
5
+ */
6
+ export declare function useInterval(callback: (...args: any[]) => void, delay: number | undefined): void;
7
+ //# sourceMappingURL=useInterval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/useInterval.tsx"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAClC,KAAK,EAAE,MAAM,GAAG,SAAS,QAuB1B"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useInterval = void 0;
27
+ /*---------------------------------------------------------------------------------------------
28
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
29
+ * See LICENSE.md in the project root for license terms and full copyright notice.
30
+ *--------------------------------------------------------------------------------------------*/
31
+ const React = __importStar(require("react"));
32
+ /** Hook that create an interval and clears it when unloaded
33
+ * Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md
34
+ * @internal
35
+ * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useInterval.tsx
36
+ */
37
+ function useInterval(callback, delay) {
38
+ const savedCallback = React.useRef(callback);
39
+ // Remember the latest function.
40
+ React.useEffect(() => {
41
+ savedCallback.current = callback;
42
+ }, [callback]);
43
+ // Set up the interval.
44
+ React.useEffect(() => {
45
+ function tick() {
46
+ savedCallback.current();
47
+ }
48
+ if (delay !== undefined) {
49
+ const id = setInterval(tick, delay);
50
+ return () => {
51
+ clearInterval(id);
52
+ };
53
+ }
54
+ else {
55
+ return undefined;
56
+ }
57
+ }, [delay]);
58
+ }
59
+ exports.useInterval = useInterval;
60
+ //# sourceMappingURL=useInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../../../../src/ui/hooks/useInterval.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,6CAA+B;AAE/B;;;;GAIG;AACH,SAAgB,WAAW,CACzB,QAAkC,EAClC,KAAyB;IAEzB,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAA2B,QAAQ,CAAC,CAAC;IAEvE,gCAAgC;IAChC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC;IACnC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,uBAAuB;IACvB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,SAAS,IAAI;YACX,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACpC,OAAO,GAAG,EAAE;gBACV,aAAa,CAAC,EAAE,CAAC,CAAC;YACpB,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,CAAC;AAzBD,kCAyBC","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 *--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\n\n/** Hook that create an interval and clears it when unloaded\n * Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md\n * @internal\n * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useInterval.tsx\n */\nexport function useInterval(\n callback: (...args: any[]) => void,\n delay: number | undefined\n) {\n const savedCallback = React.useRef<(...args: any[]) => void>(callback);\n\n // Remember the latest function.\n React.useEffect(() => {\n savedCallback.current = callback;\n }, [callback]);\n\n // Set up the interval.\n React.useEffect(() => {\n function tick() {\n savedCallback.current();\n }\n if (delay !== undefined) {\n const id = setInterval(tick, delay);\n return () => {\n clearInterval(id);\n };\n } else {\n return undefined;\n }\n }, [delay]);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null | undefined) => void, ResizeObserver | undefined];
2
+ //# sourceMappingURL=useResizeObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResizeObserver.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/useResizeObserver.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,iBAAiB,2CACX,eAAe,KAAK,IAAI,yBAK7B,CAAC,GAAG,IAAI,GAAG,SAAS,sCA2BjC,CAAC"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useResizeObserver = void 0;
27
+ /*---------------------------------------------------------------------------------------------
28
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
29
+ * See LICENSE.md in the project root for license terms and full copyright notice.
30
+ *--------------------------------------------------------------------------------------------*/
31
+ const React = __importStar(require("react"));
32
+ /** Hook that will observe Window Resize
33
+ * @internal
34
+ * Reference: https://github.com/iTwin/iTwinUI/blob/87bbc99316c17bd2b763a730135fbb45c84b0e82/packages/itwinui-react/src/utils/hooks/useResizeObserver.tsx
35
+ * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useResizeObserver.tsx
36
+ */
37
+ const getWindow = () => {
38
+ return typeof window === "undefined" ? undefined : window;
39
+ };
40
+ const useResizeObserver = (onResize) => {
41
+ const resizeObserver = React.useRef();
42
+ const elementRef = React.useCallback((element) => {
43
+ if (!getWindow()?.ResizeObserver) {
44
+ return;
45
+ }
46
+ resizeObserver.current?.disconnect?.();
47
+ if (element) {
48
+ resizeObserver.current = new ResizeObserver((entries) => {
49
+ // We wrap onResize with requestAnimationFrame to avoid this error - ResizeObserver loop limit exceeded
50
+ // See: https://github.com/iTwin/iTwinUI/issues/1317
51
+ // See: https://stackoverflow.com/a/58701523/11547064
52
+ window.requestAnimationFrame(() => {
53
+ if (!Array.isArray(entries) || !entries.length) {
54
+ return;
55
+ }
56
+ const [{ contentRect }] = entries;
57
+ return onResize(contentRect);
58
+ });
59
+ });
60
+ resizeObserver.current?.observe?.(element);
61
+ }
62
+ }, [onResize]);
63
+ return [elementRef, resizeObserver.current];
64
+ };
65
+ exports.useResizeObserver = useResizeObserver;
66
+ //# sourceMappingURL=useResizeObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResizeObserver.js","sourceRoot":"","sources":["../../../../src/ui/hooks/useResizeObserver.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,6CAA+B;AAE/B;;;;GAIG;AACH,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5D,CAAC,CAAC;AAEK,MAAM,iBAAiB,GAAG,CAC/B,QAAyC,EACzC,EAAE;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,EAAkB,CAAC;IAEtD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAClC,CAAC,OAA6B,EAAE,EAAE;QAChC,IAAI,CAAC,SAAS,EAAE,EAAE,cAAc,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACZ,cAAc,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;gBACtD,uGAAuG;gBACvG,oDAAoD;gBACpD,qDAAqD;gBACrD,MAAM,CAAC,qBAAqB,CAAC,GAAG,EAAE;oBAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;wBAC/C,OAAO;oBACT,CAAC;oBAED,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC;oBAClC,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAC/B,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC,OAAO,CAAU,CAAC;AACvD,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B","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 *--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\n\n/** Hook that will observe Window Resize\n * @internal\n * Reference: https://github.com/iTwin/iTwinUI/blob/87bbc99316c17bd2b763a730135fbb45c84b0e82/packages/itwinui-react/src/utils/hooks/useResizeObserver.tsx\n * Copied from: https://github.com/iTwin/appui/blob/master/ui/core-react/src/core-react/utils/hooks/useResizeObserver.tsx\n */\nconst getWindow = () => {\n return typeof window === \"undefined\" ? undefined : window;\n};\n\nexport const useResizeObserver = <T extends HTMLElement>(\n onResize: (size: DOMRectReadOnly) => void,\n) => {\n const resizeObserver = React.useRef<ResizeObserver>();\n\n const elementRef = React.useCallback(\n (element: T | null | undefined) => {\n if (!getWindow()?.ResizeObserver) {\n return;\n }\n\n resizeObserver.current?.disconnect?.();\n if (element) {\n resizeObserver.current = new ResizeObserver((entries) => {\n // We wrap onResize with requestAnimationFrame to avoid this error - ResizeObserver loop limit exceeded\n // See: https://github.com/iTwin/iTwinUI/issues/1317\n // See: https://stackoverflow.com/a/58701523/11547064\n window.requestAnimationFrame(() => {\n if (!Array.isArray(entries) || !entries.length) {\n return;\n }\n\n const [{ contentRect }] = entries;\n return onResize(contentRect);\n });\n });\n resizeObserver.current?.observe?.(element);\n }\n },\n [onResize],\n );\n\n return [elementRef, resizeObserver.current] as const;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"AttachLayerPopupButton.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/AttachLayerPopupButton.tsx"],"names":[],"mappings":"AAogBA,gBAAgB;AAChB,oBAAY,qBAAqB;IAC/B,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,IAAI,IAAA;CACL;AACD,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,2CAgIxE"}
1
+ {"version":3,"file":"AttachLayerPopupButton.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/AttachLayerPopupButton.tsx"],"names":[],"mappings":"AA8gBA,gBAAgB;AAChB,oBAAY,qBAAqB;IAC/B,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,IAAI,IAAA;CACL;AACD,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,2CAsGxE"}
@@ -30,10 +30,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
30
30
  * See LICENSE.md in the project root for license terms and full copyright notice.
31
31
  *--------------------------------------------------------------------------------------------*/
32
32
  const React = __importStar(require("react"));
33
- const appui_abstract_1 = require("@itwin/appui-abstract");
34
33
  const appui_react_1 = require("@itwin/appui-react");
35
34
  const core_frontend_1 = require("@itwin/core-frontend");
36
- const UiCore = __importStar(require("@itwin/core-react"));
37
35
  const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
38
36
  const itwinui_react_1 = require("@itwin/itwinui-react");
39
37
  const MapLayerPreferences_1 = require("../../MapLayerPreferences");
@@ -48,7 +46,7 @@ var LayerAction;
48
46
  LayerAction[LayerAction["New"] = 0] = "New";
49
47
  LayerAction[LayerAction["Edit"] = 1] = "Edit";
50
48
  })(LayerAction || (LayerAction = {}));
51
- function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick }) {
49
+ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick, setMapUrlModalOpen }) {
52
50
  const [layerNameToAdd, setLayerNameToAdd] = React.useState();
53
51
  const [sourceFilterString, setSourceFilterString] = React.useState();
54
52
  const { placeholderLabel, addCustomLayerLabel, addCustomLayerToolTip, loadingMapSources, removeLayerDefButtonTitle, editLayerDefButtonTitle, removeLayerDefDialogTitle, } = React.useMemo(() => {
@@ -185,6 +183,7 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
185
183
  validation.subLayers.length > 1);
186
184
  }, []);
187
185
  const handleModalUrlDialogOk = React.useCallback((action, sourceState) => {
186
+ setMapUrlModalOpen(false);
188
187
  appui_react_1.UiFramework.dialogs.modal.close();
189
188
  if (LayerAction.New === action && sourceState && sourceState.validation.status === core_frontend_1.MapLayerSourceStatus.Valid) {
190
189
  if (needsFeatureSelection(sourceState.source, sourceState.validation)) {
@@ -197,13 +196,14 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
197
196
  else {
198
197
  resumeOutsideClick();
199
198
  }
200
- }, [attachLayer, needsFeatureSelection, openFeatureSelectionDialog, resumeOutsideClick]);
199
+ }, [attachLayer, needsFeatureSelection, openFeatureSelectionDialog, resumeOutsideClick, setMapUrlModalOpen]);
201
200
  const handleModalUrlDialogCancel = React.useCallback(() => {
202
201
  // close popup and refresh UI
203
202
  setLoading(false);
203
+ setMapUrlModalOpen(false);
204
204
  appui_react_1.UiFramework.dialogs.modal.close();
205
205
  resumeOutsideClick();
206
- }, [setLoading, resumeOutsideClick]);
206
+ }, [setLoading, resumeOutsideClick, setMapUrlModalOpen]);
207
207
  React.useEffect(() => {
208
208
  async function attemptToAddLayer() {
209
209
  if (layerNameToAdd && activeViewport) {
@@ -232,7 +232,8 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
232
232
  else if (sourceValidation.status === core_frontend_1.MapLayerSourceStatus.RequireAuth && isMounted.current) {
233
233
  const layer = foundSource.toLayerSettings();
234
234
  if (layer) {
235
- appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, signInModeArgs: { layer, validation: sourceValidation, source: foundSource }, onOkResult: (sourceState) => handleModalUrlDialogOk(LayerAction.New, sourceState), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
235
+ setMapUrlModalOpen(true);
236
+ appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, signInModeArgs: { layer, validation: sourceValidation, source: foundSource }, onOkResult: (sourceState) => handleModalUrlDialogOk(LayerAction.New, sourceState), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
236
237
  }
237
238
  if (onHandleOutsideClick) {
238
239
  onHandleOutsideClick(false);
@@ -279,6 +280,7 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
279
280
  onHandleOutsideClick,
280
281
  openFeatureSelectionDialog,
281
282
  mapLayerOptions,
283
+ setMapUrlModalOpen,
282
284
  ]);
283
285
  const options = React.useMemo(() => sources, [sources]);
284
286
  const filteredOptions = React.useMemo(() => {
@@ -289,13 +291,14 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
289
291
  return options?.filter((option) => option.name.toLowerCase().includes(sourceFilterString?.toLowerCase()));
290
292
  }
291
293
  }, [options, sourceFilterString]);
292
- const handleAddNewMapSource = React.useCallback(() => {
293
- appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, onOkResult: (result) => handleModalUrlDialogOk(LayerAction.New, result), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
294
+ const handleAddNewMapSource = React.useCallback((event) => {
295
+ event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
296
+ setMapUrlModalOpen(true);
297
+ appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, onOkResult: (result) => handleModalUrlDialogOk(LayerAction.New, result), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
294
298
  if (onHandleOutsideClick) {
295
299
  onHandleOutsideClick(false);
296
300
  }
297
- return;
298
- }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapLayerOptions, onHandleOutsideClick]);
301
+ }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, mapLayerOptions, onHandleOutsideClick, setMapUrlModalOpen]);
299
302
  const handleAttach = React.useCallback((mapName) => {
300
303
  setLayerNameToAdd(mapName);
301
304
  }, []);
@@ -321,7 +324,7 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
321
324
  }, [iTwinId, iModelId, resumeOutsideClick]);
322
325
  /*
323
326
  Handle Remove layer button clicked
324
- */
327
+ */
325
328
  const onItemRemoveButtonClicked = React.useCallback((source, event) => {
326
329
  event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
327
330
  const layerName = source.name;
@@ -342,12 +345,19 @@ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick })
342
345
  if (matchingSource === undefined) {
343
346
  return;
344
347
  }
345
- appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, mapLayerSourceToEdit: matchingSource, onOkResult: (result) => handleModalUrlDialogOk(LayerAction.Edit, result), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
348
+ setMapUrlModalOpen(true);
349
+ appui_react_1.UiFramework.dialogs.modal.open((0, jsx_runtime_1.jsx)(MapUrlDialog_1.MapUrlDialog, { activeViewport: activeViewport, mapLayerSourceToEdit: matchingSource, onOkResult: (result) => handleModalUrlDialogOk(LayerAction.Edit, result), onCancelResult: handleModalUrlDialogCancel, mapLayerOptions: mapLayerOptions }));
346
350
  if (onHandleOutsideClick) {
347
351
  onHandleOutsideClick(false);
348
352
  }
349
- }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapLayerOptions, onHandleOutsideClick, sources]);
350
- return ((0, jsx_runtime_1.jsxs)("div", { className: "map-manager-header", children: [(loading || loadingSources) && ((0, jsx_runtime_1.jsx)(itwinui_react_1.ProgressRadial, { as: "div", children: (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { variant: 'small', children: loadingMapSources }) })), (0, jsx_runtime_1.jsxs)("div", { className: "map-manager-source-listbox-header", children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged, size: "small" }), (0, jsx_runtime_1.jsx)(itwinui_react_1.Button, { className: "map-manager-add-source-button", title: addCustomLayerToolTip, onClick: handleAddNewMapSource, children: addCustomLayerLabel })] }), (0, jsx_runtime_1.jsx)("div", { className: "map-manager-sources", children: (0, jsx_runtime_1.jsx)(itwinui_react_1.List, { id: "map-sources", as: "div", className: "map-manager-source-list", children: filteredOptions?.map((source) => ((0, jsx_runtime_1.jsxs)(itwinui_react_1.ListItem, { as: "div", className: "map-source-list-entry", actionable: true, onClick: () => handleAttach(source.name), onMouseEnter: () => setLayerNameUnderCursor(source.name), onMouseLeave: () => setLayerNameUnderCursor(undefined), children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.ListItem.Content, { children: source.name }),
353
+ }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, mapLayerOptions, onHandleOutsideClick, setMapUrlModalOpen, sources]);
354
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "map-manager-header", children: [(loading || loadingSources) && ((0, jsx_runtime_1.jsx)("div", { style: {
355
+ position: "absolute",
356
+ inset: 0,
357
+ display: "grid",
358
+ placeItems: "center",
359
+ zIndex: 100,
360
+ }, children: (0, jsx_runtime_1.jsx)(itwinui_react_1.ProgressRadial, { as: "div", children: (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { variant: 'small', children: loadingMapSources }) }) })), (0, jsx_runtime_1.jsxs)("div", { className: "map-manager-source-listbox-header", children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged, size: "small" }), (0, jsx_runtime_1.jsx)(itwinui_react_1.Button, { className: "map-manager-add-source-button", title: addCustomLayerToolTip, onClick: handleAddNewMapSource, children: addCustomLayerLabel })] }), (0, jsx_runtime_1.jsx)("div", { className: "map-manager-sources", children: (0, jsx_runtime_1.jsx)(itwinui_react_1.List, { id: "map-sources", as: "div", className: "map-manager-source-list", children: filteredOptions?.map((source) => ((0, jsx_runtime_1.jsxs)(itwinui_react_1.ListItem, { as: "div", className: "map-source-list-entry", actionable: true, onClick: () => handleAttach(source.name), onMouseEnter: () => setLayerNameUnderCursor(source.name), onMouseLeave: () => setLayerNameUnderCursor(undefined), children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.ListItem.Content, { children: source.name }),
351
361
  // Display the delete icon only when the mouse over a specific item
352
362
  // otherwise list feels cluttered.
353
363
  !!iTwinId && layerNameUnderCursor && layerNameUnderCursor === source.name && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: editLayerDefButtonTitle, onClick: onItemEditButtonClicked, children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgEdit, {}) }), (0, jsx_runtime_1.jsx)(itwinui_react_1.Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: removeLayerDefButtonTitle, onClick: (event) => {
@@ -371,6 +381,7 @@ function AttachLayerPopupButton(props) {
371
381
  };
372
382
  }, []);
373
383
  const [handleOutsideClick, setHandleOutsideClick] = React.useState(true);
384
+ const [mapUrlModalOpen, setMapUrlModalOpen] = React.useState(false);
374
385
  const [popupOpen, setPopupOpen] = React.useState(false);
375
386
  const buttonRef = React.useRef(null);
376
387
  const panelRef = React.useRef(null);
@@ -386,24 +397,6 @@ function AttachLayerPopupButton(props) {
386
397
  const togglePopup = React.useCallback(() => {
387
398
  setPopupOpen(!popupOpen);
388
399
  }, [popupOpen]);
389
- const handleClosePopup = React.useCallback(() => {
390
- setPopupOpen(false);
391
- }, []);
392
- const onHandleOutsideClick = React.useCallback((event) => {
393
- if (!handleOutsideClick) {
394
- return;
395
- }
396
- // If clicking on button that open panel - don't trigger outside click processing
397
- if (buttonRef?.current && buttonRef?.current.contains(event.target)) {
398
- return;
399
- }
400
- // If clicking the panel, this is not an outside clicked
401
- if (panelRef.current && panelRef?.current.contains(event.target)) {
402
- return;
403
- }
404
- // If we reach this point, we got an outside clicked, no close the popup
405
- setPopupOpen(false);
406
- }, [handleOutsideClick]);
407
400
  const { refreshFromStyle } = (0, MapLayerManager_1.useSourceMapContext)();
408
401
  const handleLayerAttached = React.useCallback(() => {
409
402
  if (!isMounted.current) {
@@ -432,8 +425,7 @@ function AttachLayerPopupButton(props) {
432
425
  }
433
426
  return button;
434
427
  }
435
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderButton(), (0, jsx_runtime_1.jsx)(UiCore.Popup // TODO: Replace all deprecated UiCore components with iTwinUI components
436
- , { isOpen: popupOpen, position: appui_abstract_1.RelativePosition.BottomRight, onClose: handleClosePopup, onOutsideClick: onHandleOutsideClick, closeOnWheel: false, target: buttonRef.current, closeOnEnter: false, closeOnContextMenu: false, children: (0, jsx_runtime_1.jsx)("div", { ref: panelRef, className: "map-sources-popup-panel", children: (0, jsx_runtime_1.jsx)(AttachLayerPanel, { isOverlay: props.isOverlay, onLayerAttached: handleLayerAttached, onHandleOutsideClick: setHandleOutsideClick }) }) })] }));
428
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(itwinui_react_1.Popover, { content: (0, jsx_runtime_1.jsx)("div", { ref: panelRef, className: "map-sources-popup-panel", children: (0, jsx_runtime_1.jsx)(AttachLayerPanel, { isOverlay: props.isOverlay, onLayerAttached: handleLayerAttached, onHandleOutsideClick: setHandleOutsideClick, setMapUrlModalOpen: setMapUrlModalOpen }) }), applyBackground: true, visible: popupOpen || mapUrlModalOpen, onVisibleChange: setPopupOpen, closeOnOutsideClick: handleOutsideClick, placement: "bottom-end", children: renderButton() }) }));
437
429
  }
438
430
  exports.AttachLayerPopupButton = AttachLayerPopupButton;
439
431
  //# sourceMappingURL=AttachLayerPopupButton.js.map