@itwin/core-react 4.6.0 → 4.6.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.
- package/CHANGELOG.md +13 -1
- package/lib/cjs/core-react/base/Gap.js +1 -1
- package/lib/cjs/core-react/base/Gap.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenu.js +1 -2
- package/lib/cjs/core-react/contextmenu/ContextMenu.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/GlobalContextMenu.js +3 -5
- package/lib/cjs/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/cjs/core-react/dialog/Dialog.js +2 -2
- package/lib/cjs/core-react/dialog/Dialog.js.map +1 -1
- package/lib/cjs/core-react/dialog/GlobalDialog.js +1 -2
- package/lib/cjs/core-react/dialog/GlobalDialog.js.map +1 -1
- package/lib/cjs/core-react/elementseparator/ElementSeparator.js +2 -2
- package/lib/cjs/core-react/elementseparator/ElementSeparator.js.map +1 -1
- package/lib/cjs/core-react/hocs/withOnOutsideClick.js +1 -2
- package/lib/cjs/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/cjs/core-react/icons/IconComponent.js +1 -1
- package/lib/cjs/core-react/icons/IconComponent.js.map +1 -1
- package/lib/cjs/core-react/listbox/Listbox.js +2 -3
- package/lib/cjs/core-react/listbox/Listbox.js.map +1 -1
- package/lib/cjs/core-react/notification/MessageRenderer.js +1 -1
- package/lib/cjs/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/cjs/core-react/popup/Popup.js +4 -8
- package/lib/cjs/core-react/popup/Popup.js.map +1 -1
- package/lib/cjs/core-react/tree/Node.js +1 -2
- package/lib/cjs/core-react/tree/Node.js.map +1 -1
- package/lib/cjs/core-react/utils/IconWebComponent.d.ts.map +1 -1
- package/lib/cjs/core-react/utils/IconWebComponent.js +13 -5
- package/lib/cjs/core-react/utils/IconWebComponent.js.map +1 -1
- package/lib/cjs/core-react/utils/getCssVariable.js +1 -1
- package/lib/cjs/core-react/utils/getCssVariable.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.js +1 -2
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useResizeObserver.js +8 -14
- package/lib/cjs/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/lib/esm/core-react/base/Gap.js +1 -1
- package/lib/esm/core-react/base/Gap.js.map +1 -1
- package/lib/esm/core-react/contextmenu/ContextMenu.js +1 -2
- package/lib/esm/core-react/contextmenu/ContextMenu.js.map +1 -1
- package/lib/esm/core-react/contextmenu/GlobalContextMenu.js +3 -5
- package/lib/esm/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/esm/core-react/dialog/Dialog.js +2 -2
- package/lib/esm/core-react/dialog/Dialog.js.map +1 -1
- package/lib/esm/core-react/dialog/GlobalDialog.js +1 -2
- package/lib/esm/core-react/dialog/GlobalDialog.js.map +1 -1
- package/lib/esm/core-react/elementseparator/ElementSeparator.js +2 -2
- package/lib/esm/core-react/elementseparator/ElementSeparator.js.map +1 -1
- package/lib/esm/core-react/hocs/withOnOutsideClick.js +1 -2
- package/lib/esm/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/esm/core-react/icons/IconComponent.js +1 -1
- package/lib/esm/core-react/icons/IconComponent.js.map +1 -1
- package/lib/esm/core-react/listbox/Listbox.js +2 -3
- package/lib/esm/core-react/listbox/Listbox.js.map +1 -1
- package/lib/esm/core-react/notification/MessageRenderer.js +1 -1
- package/lib/esm/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/esm/core-react/popup/Popup.js +4 -8
- package/lib/esm/core-react/popup/Popup.js.map +1 -1
- package/lib/esm/core-react/tree/Node.js +1 -2
- package/lib/esm/core-react/tree/Node.js.map +1 -1
- package/lib/esm/core-react/utils/IconWebComponent.d.ts.map +1 -1
- package/lib/esm/core-react/utils/IconWebComponent.js +13 -5
- package/lib/esm/core-react/utils/IconWebComponent.js.map +1 -1
- package/lib/esm/core-react/utils/getCssVariable.js +1 -1
- package/lib/esm/core-react/utils/getCssVariable.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.js +1 -2
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useResizeObserver.js +8 -14
- package/lib/esm/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @itwin/core-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 17 Oct 2023 19:16:23 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.6.2
|
|
6
|
+
Tue, 17 Oct 2023 19:16:23 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Support `data:image/svg+xml` web component icons. (base64 already supported)
|
|
11
|
+
|
|
12
|
+
## 4.6.1
|
|
13
|
+
Thu, 12 Oct 2023 16:59:20 GMT
|
|
14
|
+
|
|
15
|
+
_Version update only_
|
|
4
16
|
|
|
5
17
|
## 4.6.0
|
|
6
18
|
Wed, 04 Oct 2023 18:05:34 GMT
|
|
@@ -14,7 +14,7 @@ const React = require("react");
|
|
|
14
14
|
*/
|
|
15
15
|
function Gap(props) {
|
|
16
16
|
const { size, style, ...rest } = props;
|
|
17
|
-
const paddingLeft = size
|
|
17
|
+
const paddingLeft = size ?? "10px";
|
|
18
18
|
return React.createElement("span", { style: { ...style, paddingLeft }, ...rest });
|
|
19
19
|
}
|
|
20
20
|
exports.Gap = Gap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gap.js","sourceRoot":"","sources":["../../../../src/core-react/base/Gap.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAU/B;;GAEG;AACH,SAAgB,GAAG,CAAC,KAAe;IACjC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACvC,MAAM,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"Gap.js","sourceRoot":"","sources":["../../../../src/core-react/base/Gap.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAU/B;;GAEG;AACH,SAAgB,GAAG,CAAC,KAAe;IACjC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACvC,MAAM,WAAW,GAAG,IAAI,IAAI,MAAM,CAAC;IAEnC,OAAO,8BAAM,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,KAAM,IAAI,GAAI,CAAC;AAC9D,CAAC;AALD,kBAKC","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 Base\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"../utils/Props\";\n\n/** Properties for the [[Gap]] component.\n * @public\n */\nexport interface GapProps extends CommonProps {\n size?: string;\n}\n\n/** Horizontal gap or space React component. Defaults to 10px.\n * @public\n */\nexport function Gap(props: GapProps) {\n const { size, style, ...rest } = props;\n const paddingLeft = size ?? \"10px\";\n\n return <span style={{ ...style, paddingLeft }} {...rest} />;\n}\n"]}
|
|
@@ -222,13 +222,12 @@ class ContextMenu extends React.PureComponent {
|
|
|
222
222
|
React.createElement("div", { ref: this._menuRef, role: "menu", tabIndex: 0, "data-testid": "core-context-menu-container", className: (0, classnames_1.default)("core-context-menu-container", opened && "core-context-menu-opened", floating && "core-context-menu-floating", ContextMenu.getCSSClassNameFromDirection(renderDirection)) }, this._injectedChildren))));
|
|
223
223
|
}
|
|
224
224
|
getWindow() {
|
|
225
|
-
var _a;
|
|
226
225
|
const el = this._rootElement
|
|
227
226
|
? this._rootElement
|
|
228
227
|
: /* istanbul ignore next */ this._menuElement;
|
|
229
228
|
const parentDocument = el.ownerDocument;
|
|
230
229
|
// istanbul ignore next
|
|
231
|
-
return
|
|
230
|
+
return parentDocument.defaultView ?? window;
|
|
232
231
|
}
|
|
233
232
|
/** @internal */
|
|
234
233
|
componentDidMount() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/core-react/contextmenu/ContextMenu.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,8BAA4B;AAC5B,2CAAoC;AACpC,+BAA+B;AAC/B,0DAA4E;AAE5E,qEAAkE;AAClE,iEAA8D;AAE9D,uDAAoD;AAEpD,qDAAkD;AA2ClD;;;;GAIG;AACH,MAAa,WAAY,SAAQ,KAAK,CAAC,aAGtC;IA0BC,YAAY,KAAuB;QACjC,KAAK,CAAC,KAAK,CAAC,CAAC;QA1BP,iBAAY,GAAuB,IAAI,CAAC;QACxC,iBAAY,GAAuB,IAAI,CAAC;QACxC,qBAAgB,GAA4C,IAAI,CAAC;QACjE,YAAO,GAAW,CAAC,CAAC;QACpB,eAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;QAG5C,mBAAc,GACpB,2CAAoB,CAAC,WAAW,CAAC;QAC3B,uBAAkB,GAAW,CAAC,CAAC;QAE/B,wBAAmB,GAAW,CAAC,CAAC;QAChC,uBAAkB,GAAW,CAAC,CAAC;QAoF/B,wBAAmB,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,EAAE;YAC9D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,uBAAuB;QACf,0BAAqB,GAAG,CAAC,KAAiB,EAAQ,EAAE;YAC1D,IAAI,IAAI,CAAC,KAAK,CAAC,MAA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C,MAAM;QACR,KAAK,2CAAoB,CAAC,QAAQ;YAChC,SAAS,GAAG,+CAA+C,CAAC;YAC5D,MAAM;QACR,KAAK,2CAAoB,CAAC,IAAI;YAC5B,SAAS,GAAG,wBAAwB,CAAC;YACrC,MAAM;QACR,KAAK,2CAAoB,CAAC,MAAM;YAC9B,SAAS,GAAG,0BAA0B,CAAC;YACvC,MAAM;QACR,KAAK,2CAAoB,CAAC,KAAK;YAC7B,SAAS,GAAG,yBAAyB,CAAC;YACtC,MAAM;QACR,KAAK,2CAAoB,CAAC,UAAU;YAClC,SAAS,GAAG,iDAAiD,CAAC;YAC9D,MAAM;QACR,KAAK,2CAAoB,CAAC,MAAM;YAC9B,SAAS,GAAG,0BAA0B,CAAC;YACvC,MAAM;QACR,KAAK,2CAAoB,CAAC,WAAW;YACnC,SAAS,GAAG,kDAAkD,CAAC;YAC/D,MAAM;KACT;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,AAzCyC,CAyCxC;AA7NS,kCAAW","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 ContextMenu\n */\n\nimport \"./ContextMenu.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ConditionalBooleanValue, SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"../utils/Props\";\nimport { DivWithOutsideClick } from \"../base/DivWithOutsideClick\";\nimport { ContextMenuDirection } from \"./ContextMenuDirection\";\nimport type { ContextMenuItemProps } from \"./ContextMenuItem\";\nimport { ContextMenuItem } from \"./ContextMenuItem\";\nimport type { ContextSubMenuProps } from \"./ContextSubMenu\";\nimport { ContextSubMenu } from \"./ContextSubMenu\";\n\n/** Properties for the [[ContextMenu]] component\n * @public\n */\nexport interface ContextMenuProps extends CommonProps {\n /** Whether ContextMenu is currently opened. */\n opened: boolean;\n /** Which direction the menu opens. Default: ContextMenuDirection.BottomRight */\n direction?: ContextMenuDirection;\n /** When click is registered outside of ContextMenu. */\n onOutsideClick?: (event: MouseEvent) => any;\n /** When list item or submenu is selected */\n onSelect?: (event: any) => any;\n /** when Escape button is pressed */\n onEsc?: (data: any) => any;\n /** Whether menu flips directions based on screen edge. Default: true */\n autoflip?: boolean;\n /** Whether menu hugs screen edge when autoflip is off. Default: true */\n edgeLimit?: boolean;\n /** Whether Hotkey press selects item, or just highlights item. Default: true */\n hotkeySelect?: boolean;\n /** starting menu item selected index Default: -1 */\n selectedIndex?: number;\n /** whether menu floats on the viewport, or the page. When false, container elements can clip menu with overflow: hidden; Default: true */\n floating?: boolean;\n /** @internal */\n parentMenu?: ContextMenu;\n /** @internal */\n parentSubmenu?: ContextSubMenu;\n /** @internal */\n ignoreNextKeyUp?: boolean;\n /** Content */\n children?: React.ReactNode;\n}\n\n/** @internal */\ninterface ContextMenuState {\n selectedIndex: number;\n direction: ContextMenuDirection;\n ignoreNextKeyUp: boolean;\n}\n\n/**\n * A context menu populated with [[ContextMenuItem]] components.\n * Can be nested using [[ContextSubMenu]] component.\n * @public\n */\nexport class ContextMenu extends React.PureComponent<\n ContextMenuProps,\n ContextMenuState\n> {\n private _rootElement: HTMLElement | null = null;\n private _menuElement: HTMLElement | null = null;\n private _selectedElement: ContextMenuItem | ContextSubMenu | null = null;\n private _length: number = 0;\n private _hotKeyMap: Map<number, string> = new Map();\n\n private _lastChildren: React.ReactNode;\n private _lastDirection: ContextMenuDirection | undefined =\n ContextMenuDirection.BottomRight;\n private _lastSelectedIndex: number = 0;\n private _injectedChildren: React.ReactNode;\n private _parentWindowHeight: number = 0;\n private _parentWindowWidth: number = 0;\n\n public static defaultProps: Partial<ContextMenuProps> = {\n direction: ContextMenuDirection.BottomRight,\n autoflip: true,\n edgeLimit: true,\n hotkeySelect: true,\n selectedIndex: -1,\n floating: true,\n };\n\n /** @internal */\n public override readonly state: Readonly<ContextMenuState>;\n constructor(props: ContextMenuProps) {\n super(props);\n this.state = {\n selectedIndex: this.props.selectedIndex!,\n direction: props.direction!,\n ignoreNextKeyUp: props.ignoreNextKeyUp!,\n };\n }\n\n /** @internal */\n public static autoFlip = (\n dir: ContextMenuDirection,\n rect: DOMRectReadOnly,\n windowWidth: number,\n windowHeight: number\n ): ContextMenuDirection => {\n if (rect.right > windowWidth) {\n switch (dir) {\n case ContextMenuDirection.TopRight:\n dir = ContextMenuDirection.TopLeft;\n break;\n case ContextMenuDirection.Right:\n dir = ContextMenuDirection.Left;\n break;\n case ContextMenuDirection.BottomRight:\n dir = ContextMenuDirection.BottomLeft;\n break;\n }\n }\n if (rect.left < 0) {\n switch (dir) {\n case ContextMenuDirection.TopLeft:\n dir = ContextMenuDirection.TopRight;\n break;\n case ContextMenuDirection.Left:\n dir = ContextMenuDirection.Right;\n break;\n case ContextMenuDirection.BottomLeft:\n dir = ContextMenuDirection.BottomRight;\n break;\n }\n }\n if (rect.bottom > windowHeight) {\n switch (dir) {\n case ContextMenuDirection.BottomLeft:\n dir = ContextMenuDirection.TopLeft;\n break;\n case ContextMenuDirection.Bottom:\n dir = ContextMenuDirection.Top;\n break;\n case ContextMenuDirection.BottomRight:\n dir = ContextMenuDirection.TopRight;\n break;\n }\n }\n if (rect.top < 0) {\n switch (dir) {\n case ContextMenuDirection.TopLeft:\n dir = ContextMenuDirection.BottomLeft;\n break;\n case ContextMenuDirection.Top:\n dir = ContextMenuDirection.Bottom;\n break;\n case ContextMenuDirection.TopRight:\n dir = ContextMenuDirection.BottomRight;\n break;\n }\n }\n return dir;\n };\n\n private _handleHotKeyParsed = (index: number, hotKey: string) => {\n this._hotKeyMap.set(index, hotKey);\n };\n\n // istanbul ignore next\n private _handleOnOutsideClick = (event: MouseEvent): void => {\n if (this.props.opened && this.props.onOutsideClick)\n this.props.onOutsideClick(event);\n };\n\n public override render(): React.ReactElement {\n const {\n opened,\n direction,\n onOutsideClick,\n onSelect,\n onEsc,\n autoflip,\n edgeLimit,\n hotkeySelect,\n selectedIndex,\n floating,\n parentMenu,\n parentSubmenu,\n children,\n className,\n ignoreNextKeyUp,\n ...props\n } = this.props;\n const renderDirection =\n parentMenu === undefined ? this.state.direction : direction;\n\n if (\n this._lastChildren !== children ||\n this._lastDirection !== renderDirection ||\n this._lastSelectedIndex !== this.state.selectedIndex\n ) {\n this._injectedChildren = this._injectMenuItemProps(\n children,\n renderDirection,\n this.state.selectedIndex\n );\n this._lastChildren = children;\n this._lastDirection = renderDirection;\n this._lastSelectedIndex = this.state.selectedIndex;\n }\n\n const classNames = classnames(\"core-context-menu\", className);\n\n return (\n <div\n role=\"presentation\"\n className={classNames}\n onKeyUp={this._handleKeyUp}\n onClick={this._handleClick}\n data-testid=\"core-context-menu-root\"\n {...props}\n ref={this._rootRef}\n >\n <DivWithOutsideClick onOutsideClick={this._handleOnOutsideClick}>\n <div\n ref={this._menuRef}\n role=\"menu\"\n tabIndex={0}\n data-testid=\"core-context-menu-container\"\n className={classnames(\n \"core-context-menu-container\",\n opened && \"core-context-menu-opened\",\n floating && \"core-context-menu-floating\",\n ContextMenu.getCSSClassNameFromDirection(renderDirection)\n )}\n >\n {this._injectedChildren}\n </div>\n </DivWithOutsideClick>\n </div>\n );\n }\n\n /** @internal */\n public static getCSSClassNameFromDirection = (\n direction?: ContextMenuDirection\n ): string => {\n let className = \"\";\n\n // istanbul ignore next\n if (direction === undefined) direction = ContextMenuDirection.BottomRight;\n\n if (direction === ContextMenuDirection.None) return \"\";\n\n switch (direction) {\n case ContextMenuDirection.TopLeft:\n className = \"core-context-menu-top core-context-menu-left\";\n break;\n case ContextMenuDirection.Top:\n className = \"core-context-menu-top\";\n break;\n case ContextMenuDirection.TopRight:\n className = \"core-context-menu-top core-context-menu-right\";\n break;\n case ContextMenuDirection.Left:\n className = \"core-context-menu-left\";\n break;\n case ContextMenuDirection.Center:\n className = \"core-context-menu-center\";\n break;\n case ContextMenuDirection.Right:\n className = \"core-context-menu-right\";\n break;\n case ContextMenuDirection.BottomLeft:\n className = \"core-context-menu-bottom core-context-menu-left\";\n break;\n case ContextMenuDirection.Bottom:\n className = \"core-context-menu-bottom\";\n break;\n case ContextMenuDirection.BottomRight:\n className = \"core-context-menu-bottom core-context-menu-right\";\n break;\n }\n\n return className;\n };\n\n private _injectMenuItemProps = (\n children: React.ReactNode,\n direction: ContextMenuDirection | undefined,\n selectedIndex: number\n ) => {\n let index = 0;\n // add inheritance data to submenu children\n const ch = React.Children.map(children, (child: React.ReactNode) => {\n // Capture only ContextSubMenus and ContextMenuItems.\n if (\n child &&\n typeof child === \"object\" &&\n \"props\" in child &&\n (child.type === ContextSubMenu || child.type === ContextMenuItem) &&\n !ConditionalBooleanValue.getValue(child.props.disabled) &&\n !ConditionalBooleanValue.getValue(child.props.hidden)\n ) {\n const id = index; // get separate id variable so value stays the same when onHover is called later.\n const onHover = () => {\n this.setState({ selectedIndex: id });\n this.focus();\n };\n const ref = (el: ContextSubMenu | ContextMenuItem | null) => {\n if (selectedIndex === id)\n // only save to this._selectedElement if previously captured bool is true\n this._selectedElement = el;\n };\n const boundHandleHotKeyParse = this._handleHotKeyParsed.bind(this, id); // bind local callback for specific index\n const childProps: Partial<\n ContextSubMenuProps & ContextMenuItemProps & { ref: typeof ref }\n > = {\n parentMenu: this,\n ref,\n onHover,\n isSelected: selectedIndex === id,\n onHotKeyParsed: boundHandleHotKeyParse,\n };\n if (child.type === ContextSubMenu) {\n // add direction only to sub-menus\n childProps.direction =\n child.props.direction || /* istanbul ignore next */ direction;\n }\n index++;\n return React.cloneElement(child, childProps);\n } else return child; // Else, pass through unmodified\n });\n this._length = index;\n return ch;\n };\n\n private _rootRef = (el: HTMLDivElement | null) => {\n this._rootElement = el;\n };\n\n private _menuRef = (el: HTMLDivElement | null) => {\n this._menuElement = el;\n };\n\n private getWindow() {\n const el = this._rootElement\n ? this._rootElement\n : /* istanbul ignore next */ this._menuElement;\n const parentDocument = el!.ownerDocument;\n // istanbul ignore next\n return parentDocument.defaultView ?? window;\n }\n\n /** @internal */\n public override componentDidMount() {\n const parentWindow = this.getWindow();\n parentWindow.addEventListener(\"focus\", this._handleFocusChange);\n parentWindow.addEventListener(\"mouseup\", this._handleFocusChange);\n\n this.checkRenderDirection();\n\n if (this.props.opened) this.focus();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n const parentWindow = this.getWindow();\n parentWindow.removeEventListener(\"focus\", this._handleFocusChange);\n parentWindow.removeEventListener(\"mouseup\", this._handleFocusChange);\n }\n\n private checkRenderDirection() {\n const { direction, autoflip, parentMenu } = this.props;\n const parentWindow = this.getWindow();\n\n let renderDirection =\n parentMenu === undefined ? this.state.direction : direction;\n\n if (\n parentWindow.innerHeight === this._parentWindowHeight &&\n parentWindow.innerWidth === this._parentWindowWidth\n )\n return;\n this._parentWindowHeight = parentWindow.innerHeight;\n this._parentWindowWidth = parentWindow.innerWidth;\n\n // check if menu should flip\n if (parentWindow && autoflip && parentMenu === undefined) {\n const menuRect = this.getRect();\n renderDirection = ContextMenu.autoFlip(\n renderDirection!,\n menuRect,\n parentWindow.innerWidth,\n parentWindow.innerHeight\n );\n // istanbul ignore next\n if (renderDirection !== this.state.direction)\n this.setState({ direction: renderDirection });\n }\n }\n\n public focus = () => {\n // istanbul ignore else\n if (this._menuElement) this._menuElement.focus();\n };\n\n public blur = () => {\n // istanbul ignore else\n if (this._menuElement) this._menuElement.blur();\n };\n\n public getRect = (): DOMRect => {\n let clientRect = DOMRect.fromRect({ x: 0, y: 0, width: 0, height: 0 });\n\n // istanbul ignore else\n if (this._menuElement) {\n clientRect = this._menuElement.getBoundingClientRect();\n }\n return clientRect;\n };\n\n private _handleFocusChange = (event: any): void => {\n // istanbul ignore else\n if (\n this._rootElement &&\n this.props.opened &&\n event.target instanceof Node &&\n this.props.onOutsideClick &&\n !this._rootElement.contains(event.target)\n )\n this.props.onOutsideClick(event);\n };\n\n private _handleClick = (event: React.MouseEvent<HTMLDivElement>): void => {\n if (this.props.onSelect) this.props.onSelect(event);\n };\n\n private _handleKeyUp = (event: React.KeyboardEvent<HTMLDivElement>): void => {\n if (this.state.ignoreNextKeyUp) {\n this.setState({ ignoreNextKeyUp: false });\n return;\n }\n\n // istanbul ignore else\n if (event.key) {\n for (const [key, value] of this._hotKeyMap) {\n if (!this.props.hotkeySelect! && key > this.state.selectedIndex) {\n // Start search at current index.\n if (event.key.toUpperCase() === value) {\n this.setState({ selectedIndex: key });\n return;\n }\n }\n }\n for (const [key, value] of this._hotKeyMap) {\n if (event.key.toUpperCase() === value) {\n this.setState({ selectedIndex: key }, () => {\n if (this.props.hotkeySelect && this._selectedElement) {\n this._selectedElement.select();\n }\n });\n event.stopPropagation();\n return;\n }\n }\n }\n\n if (event.key === SpecialKey.ArrowLeft) {\n event.stopPropagation();\n if (this.props.parentMenu && this.props.parentSubmenu) {\n this.props.parentSubmenu.close();\n this.props.parentMenu.focus();\n }\n if (this.props.onEsc) this.props.onEsc(event);\n }\n\n if (event.key === SpecialKey.Escape) {\n // istanbul ignore else\n if (this.props.onEsc) this.props.onEsc(event);\n }\n\n if (\n (event.key === SpecialKey.Enter || event.key === SpecialKey.ArrowRight) &&\n this._selectedElement\n ) {\n event.stopPropagation();\n\n // istanbul ignore else\n if (\n event.key === SpecialKey.Enter ||\n /* istanbul ignore next */ this._selectedElement instanceof\n ContextSubMenu\n ) {\n // istanbul ignore else\n if (this._selectedElement.select) this._selectedElement.select();\n }\n }\n\n let { selectedIndex } = this.state;\n if (\n event.key === SpecialKey.ArrowUp ||\n event.key === SpecialKey.ArrowDown\n ) {\n event.stopPropagation();\n if (selectedIndex === -1) {\n selectedIndex = 0;\n } else {\n if (event.key === SpecialKey.ArrowUp) {\n if (this.state.selectedIndex === 0) selectedIndex = this._length - 1;\n else selectedIndex--;\n }\n if (event.key === SpecialKey.ArrowDown) {\n if (this.state.selectedIndex === this._length - 1) selectedIndex = 0;\n else selectedIndex++;\n }\n }\n }\n this.setState({ selectedIndex });\n };\n\n public override componentDidUpdate(prevProps: ContextMenuProps) {\n if (prevProps.selectedIndex !== this.props.selectedIndex) {\n this.setState((_, props) => ({ selectedIndex: props.selectedIndex! }));\n }\n if (!prevProps.opened && this.props.opened) {\n this.setState((_, props) => ({ selectedIndex: props.selectedIndex! }));\n }\n if (!this.props.parentMenu) {\n // const direction = this.props.direction!;\n // if ((!this.props.opened && prevProps.opened && direction !== this.state.direction) || prevProps.direction !== direction)\n this.checkRenderDirection();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/core-react/contextmenu/ContextMenu.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,8BAA4B;AAC5B,2CAAoC;AACpC,+BAA+B;AAC/B,0DAA4E;AAE5E,qEAAkE;AAClE,iEAA8D;AAE9D,uDAAoD;AAEpD,qDAAkD;AA2ClD;;;;GAIG;AACH,MAAa,WAAY,SAAQ,KAAK,CAAC,aAGtC;IA0BC,YAAY,KAAuB;QACjC,KAAK,CAAC,KAAK,CAAC,CAAC;QA1BP,iBAAY,GAAuB,IAAI,CAAC;QACxC,iBAAY,GAAuB,IAAI,CAAC;QACxC,qBAAgB,GAA4C,IAAI,CAAC;QACjE,YAAO,GAAW,CAAC,CAAC;QACpB,eAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;QAG5C,mBAAc,GACpB,2CAAoB,CAAC,WAAW,CAAC;QAC3B,uBAAkB,GAAW,CAAC,CAAC;QAE/B,wBAAmB,GAAW,CAAC,CAAC;QAChC,uBAAkB,GAAW,CAAC,CAAC;QAoF/B,wBAAmB,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,EAAE;YAC9D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,uBAAuB;QACf,0BAAqB,GAAG,CAAC,KAAiB,EAAQ,EAAE;YAC1D,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAA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,QAAQ;YAChC,SAAS,GAAG,+CAA+C,CAAC;YAC5D,MAAM;QACR,KAAK,2CAAoB,CAAC,IAAI;YAC5B,SAAS,GAAG,wBAAwB,CAAC;YACrC,MAAM;QACR,KAAK,2CAAoB,CAAC,MAAM;YAC9B,SAAS,GAAG,0BAA0B,CAAC;YACvC,MAAM;QACR,KAAK,2CAAoB,CAAC,KAAK;YAC7B,SAAS,GAAG,yBAAyB,CAAC;YACtC,MAAM;QACR,KAAK,2CAAoB,CAAC,UAAU;YAClC,SAAS,GAAG,iDAAiD,CAAC;YAC9D,MAAM;QACR,KAAK,2CAAoB,CAAC,MAAM;YAC9B,SAAS,GAAG,0BAA0B,CAAC;YACvC,MAAM;QACR,KAAK,2CAAoB,CAAC,WAAW;YACnC,SAAS,GAAG,kDAAkD,CAAC;YAC/D,MAAM;KACT;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,AAzCyC,CAyCxC;AA7NS,kCAAW","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 ContextMenu\n */\n\nimport \"./ContextMenu.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ConditionalBooleanValue, SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"../utils/Props\";\nimport { DivWithOutsideClick } from \"../base/DivWithOutsideClick\";\nimport { ContextMenuDirection } from \"./ContextMenuDirection\";\nimport type { ContextMenuItemProps } from \"./ContextMenuItem\";\nimport { ContextMenuItem } from \"./ContextMenuItem\";\nimport type { ContextSubMenuProps } from \"./ContextSubMenu\";\nimport { ContextSubMenu } from \"./ContextSubMenu\";\n\n/** Properties for the [[ContextMenu]] component\n * @public\n */\nexport interface ContextMenuProps extends CommonProps {\n /** Whether ContextMenu is currently opened. */\n opened: boolean;\n /** Which direction the menu opens. Default: ContextMenuDirection.BottomRight */\n direction?: ContextMenuDirection;\n /** When click is registered outside of ContextMenu. */\n onOutsideClick?: (event: MouseEvent) => any;\n /** When list item or submenu is selected */\n onSelect?: (event: any) => any;\n /** when Escape button is pressed */\n onEsc?: (data: any) => any;\n /** Whether menu flips directions based on screen edge. Default: true */\n autoflip?: boolean;\n /** Whether menu hugs screen edge when autoflip is off. Default: true */\n edgeLimit?: boolean;\n /** Whether Hotkey press selects item, or just highlights item. Default: true */\n hotkeySelect?: boolean;\n /** starting menu item selected index Default: -1 */\n selectedIndex?: number;\n /** whether menu floats on the viewport, or the page. When false, container elements can clip menu with overflow: hidden; Default: true */\n floating?: boolean;\n /** @internal */\n parentMenu?: ContextMenu;\n /** @internal */\n parentSubmenu?: ContextSubMenu;\n /** @internal */\n ignoreNextKeyUp?: boolean;\n /** Content */\n children?: React.ReactNode;\n}\n\n/** @internal */\ninterface ContextMenuState {\n selectedIndex: number;\n direction: ContextMenuDirection;\n ignoreNextKeyUp: boolean;\n}\n\n/**\n * A context menu populated with [[ContextMenuItem]] components.\n * Can be nested using [[ContextSubMenu]] component.\n * @public\n */\nexport class ContextMenu extends React.PureComponent<\n ContextMenuProps,\n ContextMenuState\n> {\n private _rootElement: HTMLElement | null = null;\n private _menuElement: HTMLElement | null = null;\n private _selectedElement: ContextMenuItem | ContextSubMenu | null = null;\n private _length: number = 0;\n private _hotKeyMap: Map<number, string> = new Map();\n\n private _lastChildren: React.ReactNode;\n private _lastDirection: ContextMenuDirection | undefined =\n ContextMenuDirection.BottomRight;\n private _lastSelectedIndex: number = 0;\n private _injectedChildren: React.ReactNode;\n private _parentWindowHeight: number = 0;\n private _parentWindowWidth: number = 0;\n\n public static defaultProps: Partial<ContextMenuProps> = {\n direction: ContextMenuDirection.BottomRight,\n autoflip: true,\n edgeLimit: true,\n hotkeySelect: true,\n selectedIndex: -1,\n floating: true,\n };\n\n /** @internal */\n public override readonly state: Readonly<ContextMenuState>;\n constructor(props: ContextMenuProps) {\n super(props);\n this.state = {\n selectedIndex: this.props.selectedIndex!,\n direction: props.direction!,\n ignoreNextKeyUp: props.ignoreNextKeyUp!,\n };\n }\n\n /** @internal */\n public static autoFlip = (\n dir: ContextMenuDirection,\n rect: DOMRectReadOnly,\n windowWidth: number,\n windowHeight: number\n ): ContextMenuDirection => {\n if (rect.right > windowWidth) {\n switch (dir) {\n case ContextMenuDirection.TopRight:\n dir = ContextMenuDirection.TopLeft;\n break;\n case ContextMenuDirection.Right:\n dir = ContextMenuDirection.Left;\n break;\n case ContextMenuDirection.BottomRight:\n dir = ContextMenuDirection.BottomLeft;\n break;\n }\n }\n if (rect.left < 0) {\n switch (dir) {\n case ContextMenuDirection.TopLeft:\n dir = ContextMenuDirection.TopRight;\n break;\n case ContextMenuDirection.Left:\n dir = ContextMenuDirection.Right;\n break;\n case ContextMenuDirection.BottomLeft:\n dir = ContextMenuDirection.BottomRight;\n break;\n }\n }\n if (rect.bottom > windowHeight) {\n switch (dir) {\n case ContextMenuDirection.BottomLeft:\n dir = ContextMenuDirection.TopLeft;\n break;\n case ContextMenuDirection.Bottom:\n dir = ContextMenuDirection.Top;\n break;\n case ContextMenuDirection.BottomRight:\n dir = ContextMenuDirection.TopRight;\n break;\n }\n }\n if (rect.top < 0) {\n switch (dir) {\n case ContextMenuDirection.TopLeft:\n dir = ContextMenuDirection.BottomLeft;\n break;\n case ContextMenuDirection.Top:\n dir = ContextMenuDirection.Bottom;\n break;\n case ContextMenuDirection.TopRight:\n dir = ContextMenuDirection.BottomRight;\n break;\n }\n }\n return dir;\n };\n\n private _handleHotKeyParsed = (index: number, hotKey: string) => {\n this._hotKeyMap.set(index, hotKey);\n };\n\n // istanbul ignore next\n private _handleOnOutsideClick = (event: MouseEvent): void => {\n if (this.props.opened && this.props.onOutsideClick)\n this.props.onOutsideClick(event);\n };\n\n public override render(): React.ReactElement {\n const {\n opened,\n direction,\n onOutsideClick,\n onSelect,\n onEsc,\n autoflip,\n edgeLimit,\n hotkeySelect,\n selectedIndex,\n floating,\n parentMenu,\n parentSubmenu,\n children,\n className,\n ignoreNextKeyUp,\n ...props\n } = this.props;\n const renderDirection =\n parentMenu === undefined ? this.state.direction : direction;\n\n if (\n this._lastChildren !== children ||\n this._lastDirection !== renderDirection ||\n this._lastSelectedIndex !== this.state.selectedIndex\n ) {\n this._injectedChildren = this._injectMenuItemProps(\n children,\n renderDirection,\n this.state.selectedIndex\n );\n this._lastChildren = children;\n this._lastDirection = renderDirection;\n this._lastSelectedIndex = this.state.selectedIndex;\n }\n\n const classNames = classnames(\"core-context-menu\", className);\n\n return (\n <div\n role=\"presentation\"\n className={classNames}\n onKeyUp={this._handleKeyUp}\n onClick={this._handleClick}\n data-testid=\"core-context-menu-root\"\n {...props}\n ref={this._rootRef}\n >\n <DivWithOutsideClick onOutsideClick={this._handleOnOutsideClick}>\n <div\n ref={this._menuRef}\n role=\"menu\"\n tabIndex={0}\n data-testid=\"core-context-menu-container\"\n className={classnames(\n \"core-context-menu-container\",\n opened && \"core-context-menu-opened\",\n floating && \"core-context-menu-floating\",\n ContextMenu.getCSSClassNameFromDirection(renderDirection)\n )}\n >\n {this._injectedChildren}\n </div>\n </DivWithOutsideClick>\n </div>\n );\n }\n\n /** @internal */\n public static getCSSClassNameFromDirection = (\n direction?: ContextMenuDirection\n ): string => {\n let className = \"\";\n\n // istanbul ignore next\n if (direction === undefined) direction = ContextMenuDirection.BottomRight;\n\n if (direction === ContextMenuDirection.None) return \"\";\n\n switch (direction) {\n case ContextMenuDirection.TopLeft:\n className = \"core-context-menu-top core-context-menu-left\";\n break;\n case ContextMenuDirection.Top:\n className = \"core-context-menu-top\";\n break;\n case ContextMenuDirection.TopRight:\n className = \"core-context-menu-top core-context-menu-right\";\n break;\n case ContextMenuDirection.Left:\n className = \"core-context-menu-left\";\n break;\n case ContextMenuDirection.Center:\n className = \"core-context-menu-center\";\n break;\n case ContextMenuDirection.Right:\n className = \"core-context-menu-right\";\n break;\n case ContextMenuDirection.BottomLeft:\n className = \"core-context-menu-bottom core-context-menu-left\";\n break;\n case ContextMenuDirection.Bottom:\n className = \"core-context-menu-bottom\";\n break;\n case ContextMenuDirection.BottomRight:\n className = \"core-context-menu-bottom core-context-menu-right\";\n break;\n }\n\n return className;\n };\n\n private _injectMenuItemProps = (\n children: React.ReactNode,\n direction: ContextMenuDirection | undefined,\n selectedIndex: number\n ) => {\n let index = 0;\n // add inheritance data to submenu children\n const ch = React.Children.map(children, (child: React.ReactNode) => {\n // Capture only ContextSubMenus and ContextMenuItems.\n if (\n child &&\n typeof child === \"object\" &&\n \"props\" in child &&\n (child.type === ContextSubMenu || child.type === ContextMenuItem) &&\n !ConditionalBooleanValue.getValue(child.props.disabled) &&\n !ConditionalBooleanValue.getValue(child.props.hidden)\n ) {\n const id = index; // get separate id variable so value stays the same when onHover is called later.\n const onHover = () => {\n this.setState({ selectedIndex: id });\n this.focus();\n };\n const ref = (el: ContextSubMenu | ContextMenuItem | null) => {\n if (selectedIndex === id)\n // only save to this._selectedElement if previously captured bool is true\n this._selectedElement = el;\n };\n const boundHandleHotKeyParse = this._handleHotKeyParsed.bind(this, id); // bind local callback for specific index\n const childProps: Partial<\n ContextSubMenuProps & ContextMenuItemProps & { ref: typeof ref }\n > = {\n parentMenu: this,\n ref,\n onHover,\n isSelected: selectedIndex === id,\n onHotKeyParsed: boundHandleHotKeyParse,\n };\n if (child.type === ContextSubMenu) {\n // add direction only to sub-menus\n childProps.direction =\n child.props.direction || /* istanbul ignore next */ direction;\n }\n index++;\n return React.cloneElement(child, childProps);\n } else return child; // Else, pass through unmodified\n });\n this._length = index;\n return ch;\n };\n\n private _rootRef = (el: HTMLDivElement | null) => {\n this._rootElement = el;\n };\n\n private _menuRef = (el: HTMLDivElement | null) => {\n this._menuElement = el;\n };\n\n private getWindow() {\n const el = this._rootElement\n ? this._rootElement\n : /* istanbul ignore next */ this._menuElement;\n const parentDocument = el!.ownerDocument;\n // istanbul ignore next\n return parentDocument.defaultView ?? window;\n }\n\n /** @internal */\n public override componentDidMount() {\n const parentWindow = this.getWindow();\n parentWindow.addEventListener(\"focus\", this._handleFocusChange);\n parentWindow.addEventListener(\"mouseup\", this._handleFocusChange);\n\n this.checkRenderDirection();\n\n if (this.props.opened) this.focus();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n const parentWindow = this.getWindow();\n parentWindow.removeEventListener(\"focus\", this._handleFocusChange);\n parentWindow.removeEventListener(\"mouseup\", this._handleFocusChange);\n }\n\n private checkRenderDirection() {\n const { direction, autoflip, parentMenu } = this.props;\n const parentWindow = this.getWindow();\n\n let renderDirection =\n parentMenu === undefined ? this.state.direction : direction;\n\n if (\n parentWindow.innerHeight === this._parentWindowHeight &&\n parentWindow.innerWidth === this._parentWindowWidth\n )\n return;\n this._parentWindowHeight = parentWindow.innerHeight;\n this._parentWindowWidth = parentWindow.innerWidth;\n\n // check if menu should flip\n if (parentWindow && autoflip && parentMenu === undefined) {\n const menuRect = this.getRect();\n renderDirection = ContextMenu.autoFlip(\n renderDirection!,\n menuRect,\n parentWindow.innerWidth,\n parentWindow.innerHeight\n );\n // istanbul ignore next\n if (renderDirection !== this.state.direction)\n this.setState({ direction: renderDirection });\n }\n }\n\n public focus = () => {\n // istanbul ignore else\n if (this._menuElement) this._menuElement.focus();\n };\n\n public blur = () => {\n // istanbul ignore else\n if (this._menuElement) this._menuElement.blur();\n };\n\n public getRect = (): DOMRect => {\n let clientRect = DOMRect.fromRect({ x: 0, y: 0, width: 0, height: 0 });\n\n // istanbul ignore else\n if (this._menuElement) {\n clientRect = this._menuElement.getBoundingClientRect();\n }\n return clientRect;\n };\n\n private _handleFocusChange = (event: any): void => {\n // istanbul ignore else\n if (\n this._rootElement &&\n this.props.opened &&\n event.target instanceof Node &&\n this.props.onOutsideClick &&\n !this._rootElement.contains(event.target)\n )\n this.props.onOutsideClick(event);\n };\n\n private _handleClick = (event: React.MouseEvent<HTMLDivElement>): void => {\n if (this.props.onSelect) this.props.onSelect(event);\n };\n\n private _handleKeyUp = (event: React.KeyboardEvent<HTMLDivElement>): void => {\n if (this.state.ignoreNextKeyUp) {\n this.setState({ ignoreNextKeyUp: false });\n return;\n }\n\n // istanbul ignore else\n if (event.key) {\n for (const [key, value] of this._hotKeyMap) {\n if (!this.props.hotkeySelect! && key > this.state.selectedIndex) {\n // Start search at current index.\n if (event.key.toUpperCase() === value) {\n this.setState({ selectedIndex: key });\n return;\n }\n }\n }\n for (const [key, value] of this._hotKeyMap) {\n if (event.key.toUpperCase() === value) {\n this.setState({ selectedIndex: key }, () => {\n if (this.props.hotkeySelect && this._selectedElement) {\n this._selectedElement.select();\n }\n });\n event.stopPropagation();\n return;\n }\n }\n }\n\n if (event.key === SpecialKey.ArrowLeft) {\n event.stopPropagation();\n if (this.props.parentMenu && this.props.parentSubmenu) {\n this.props.parentSubmenu.close();\n this.props.parentMenu.focus();\n }\n if (this.props.onEsc) this.props.onEsc(event);\n }\n\n if (event.key === SpecialKey.Escape) {\n // istanbul ignore else\n if (this.props.onEsc) this.props.onEsc(event);\n }\n\n if (\n (event.key === SpecialKey.Enter || event.key === SpecialKey.ArrowRight) &&\n this._selectedElement\n ) {\n event.stopPropagation();\n\n // istanbul ignore else\n if (\n event.key === SpecialKey.Enter ||\n /* istanbul ignore next */ this._selectedElement instanceof\n ContextSubMenu\n ) {\n // istanbul ignore else\n if (this._selectedElement.select) this._selectedElement.select();\n }\n }\n\n let { selectedIndex } = this.state;\n if (\n event.key === SpecialKey.ArrowUp ||\n event.key === SpecialKey.ArrowDown\n ) {\n event.stopPropagation();\n if (selectedIndex === -1) {\n selectedIndex = 0;\n } else {\n if (event.key === SpecialKey.ArrowUp) {\n if (this.state.selectedIndex === 0) selectedIndex = this._length - 1;\n else selectedIndex--;\n }\n if (event.key === SpecialKey.ArrowDown) {\n if (this.state.selectedIndex === this._length - 1) selectedIndex = 0;\n else selectedIndex++;\n }\n }\n }\n this.setState({ selectedIndex });\n };\n\n public override componentDidUpdate(prevProps: ContextMenuProps) {\n if (prevProps.selectedIndex !== this.props.selectedIndex) {\n this.setState((_, props) => ({ selectedIndex: props.selectedIndex! }));\n }\n if (!prevProps.opened && this.props.opened) {\n this.setState((_, props) => ({ selectedIndex: props.selectedIndex! }));\n }\n if (!this.props.parentMenu) {\n // const direction = this.props.direction!;\n // if ((!this.props.opened && prevProps.opened && direction !== this.state.direction) || prevProps.direction !== direction)\n this.checkRenderDirection();\n }\n }\n}\n"]}
|
|
@@ -21,8 +21,7 @@ class GlobalContextMenu extends React.PureComponent {
|
|
|
21
21
|
parentDocument: null,
|
|
22
22
|
};
|
|
23
23
|
this._handleRefSet = (popupDiv) => {
|
|
24
|
-
|
|
25
|
-
const parentDocument = (_a = popupDiv === null || popupDiv === void 0 ? void 0 : popupDiv.ownerDocument) !== null && _a !== void 0 ? _a : null;
|
|
24
|
+
const parentDocument = popupDiv?.ownerDocument ?? null;
|
|
26
25
|
if (parentDocument) {
|
|
27
26
|
this._container = parentDocument.createElement("div");
|
|
28
27
|
this._container.id =
|
|
@@ -34,7 +33,7 @@ class GlobalContextMenu extends React.PureComponent {
|
|
|
34
33
|
rt = parentDocument.createElement("div");
|
|
35
34
|
rt.id = "core-global-context-menu-root";
|
|
36
35
|
// istanbul ignore next
|
|
37
|
-
(
|
|
36
|
+
(parentDocument.body.querySelector('[data-root-container="iui-root-id"]') ?? parentDocument.body).appendChild(rt);
|
|
38
37
|
}
|
|
39
38
|
rt.appendChild(this._container);
|
|
40
39
|
// used to support component rendering in pop-out window
|
|
@@ -50,7 +49,6 @@ class GlobalContextMenu extends React.PureComponent {
|
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
render() {
|
|
53
|
-
var _a;
|
|
54
52
|
const { x, y, identifier, contextMenuComponent, ...props } = this.props;
|
|
55
53
|
const positioningStyle = {
|
|
56
54
|
left: x,
|
|
@@ -61,7 +59,7 @@ class GlobalContextMenu extends React.PureComponent {
|
|
|
61
59
|
ReactDOM.createPortal(React.createElement("div", { className: "core-context-menu-global", style: positioningStyle },
|
|
62
60
|
React.createElement(CtxMenu, { ...props })),
|
|
63
61
|
// istanbul ignore next
|
|
64
|
-
|
|
62
|
+
this.state.parentDocument.body.querySelector('[data-root-container="iui-root-id"]') ?? this.state.parentDocument.body)));
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
exports.GlobalContextMenu = GlobalContextMenu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalContextMenu.js","sourceRoot":"","sources":["../../../../src/core-react/contextmenu/GlobalContextMenu.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAC/B,sCAAsC;AAEtC,+CAA4C;AAqB5C;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK,CAAC,aAG5C;IAOC,YAAY,KAA6B;QACvC,KAAK,CAAC,KAAK,CAAC,CAAC;QALU,UAAK,GAA2B;YACvD,cAAc,EAAE,IAAI;SACrB,CAAC;QAcM,kBAAa,GAAG,CAAC,QAA4B,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"GlobalContextMenu.js","sourceRoot":"","sources":["../../../../src/core-react/contextmenu/GlobalContextMenu.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAC/B,sCAAsC;AAEtC,+CAA4C;AAqB5C;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK,CAAC,aAG5C;IAOC,YAAY,KAA6B;QACvC,KAAK,CAAC,KAAK,CAAC,CAAC;QALU,UAAK,GAA2B;YACvD,cAAc,EAAE,IAAI;SACrB,CAAC;QAcM,kBAAa,GAAG,CAAC,QAA4B,EAAE,EAAE;YACvD,MAAM,cAAc,GAAG,QAAQ,EAAE,aAAa,IAAI,IAAI,CAAC;YACvD,IAAI,cAAc,EAAE;gBAClB,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBACtD,IAAI,CAAC,UAAU,CAAC,EAAE;oBAChB,IAAI,CAAC,KAAK,CAAC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,IACrD,IAAI,CAAC,KAAK,CAAC,cAAc;YACxB,QAAQ,CAAC,YAAY,CACnB,6BAAK,SAAS,EAAC,0BAA0B,EAAC,KAAK,EAAE,gBAAgB;gBAC/D,oBAAC,OAAO,OAAK,KAAK,GAAI,CAClB;YACN,uBAAuB;YACvB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAC1C,qCAAqC,CACtC,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CACpC,CACC,CACP,CAAC;IACJ,CAAC;CACF;AA1ED,8CA0EC","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 ContextMenu\n */\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport type { ContextMenuProps } from \"./ContextMenu\";\nimport { ContextMenu } from \"./ContextMenu\";\n\n/** Properties for the [[GlobalContextMenu]] component\n * @public\n */\nexport interface GlobalContextMenuProps extends ContextMenuProps {\n /** Unique identifier, to distinguish from other GlobalContextMenu components. Needed only if multiple GlobalContextMenus are used simultaneously. */\n identifier?: string;\n /** Specifies the x/horizontal position on the viewport. */\n x: number | string;\n /** Specifies the y/vertical position on the viewport. */\n y: number | string;\n /** Context menu element. Default: ContextMenu */\n contextMenuComponent?: React.ComponentType<ContextMenuProps>;\n}\n\n/** @internal */\ninterface GlobalContextMenuState {\n parentDocument: Document | null;\n}\n\n/** GlobalContextMenu React component used to display a [[ContextMenu]] at the cursor\n * @public\n */\nexport class GlobalContextMenu extends React.PureComponent<\n GlobalContextMenuProps,\n GlobalContextMenuState\n> {\n private _container?: HTMLDivElement;\n\n public override readonly state: GlobalContextMenuState = {\n parentDocument: null,\n };\n\n constructor(props: GlobalContextMenuProps) {\n super(props);\n }\n\n public override componentWillUnmount() {\n // istanbul ignore else\n if (this._container && this._container.parentElement) {\n // cleanup\n this._container.parentElement.removeChild(this._container);\n }\n }\n\n private _handleRefSet = (popupDiv: HTMLElement | null) => {\n const parentDocument = popupDiv?.ownerDocument ?? null;\n if (parentDocument) {\n this._container = parentDocument.createElement(\"div\");\n this._container.id =\n this.props.identifier !== undefined\n ? `dialog-${this.props.identifier}`\n : \"core-global-context-menu\";\n let rt = parentDocument.getElementById(\n \"core-global-context-menu-root\"\n ) as HTMLDivElement;\n if (!rt) {\n rt = parentDocument.createElement(\"div\");\n rt.id = \"core-global-context-menu-root\";\n // istanbul ignore next\n (\n parentDocument.body.querySelector(\n '[data-root-container=\"iui-root-id\"]'\n ) ?? parentDocument.body\n ).appendChild(rt);\n }\n rt.appendChild(this._container);\n\n // used to support component rendering in pop-out window\n this.setState({ parentDocument });\n }\n };\n\n public override render(): React.ReactNode {\n const { x, y, identifier, contextMenuComponent, ...props } = this.props;\n const positioningStyle: React.CSSProperties = {\n left: x,\n top: y,\n };\n\n const CtxMenu = contextMenuComponent || ContextMenu;\n\n return (\n <div ref={this._handleRefSet} style={{ display: \"none\" }}>\n {this.state.parentDocument &&\n ReactDOM.createPortal(\n <div className=\"core-context-menu-global\" style={positioningStyle}>\n <CtxMenu {...props} />\n </div>,\n // istanbul ignore next\n this.state.parentDocument.body.querySelector(\n '[data-root-container=\"iui-root-id\"]'\n ) ?? this.state.parentDocument.body\n )}\n </div>\n );\n }\n}\n"]}
|
|
@@ -71,8 +71,8 @@ class Dialog extends React.Component {
|
|
|
71
71
|
let initialOffset = {};
|
|
72
72
|
if (x || y) {
|
|
73
73
|
initialOffset = {
|
|
74
|
-
left: x
|
|
75
|
-
top: y
|
|
74
|
+
left: x ?? 0,
|
|
75
|
+
top: y ?? 0,
|
|
76
76
|
transform: "none",
|
|
77
77
|
};
|
|
78
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../../src/core-react/dialog/Dialog.tsx"],"names":[],"mappings":";A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AM","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 Dialog\n */\n\nimport \"./Dialog.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { DialogButtonDef } from \"@itwin/appui-abstract\";\nimport { DialogButtonType, SpecialKey } from \"@itwin/appui-abstract\";\nimport { DivWithOutsideClick } from \"../base/DivWithOutsideClick\";\nimport { UiCore } from \"../UiCore\";\nimport type { CommonProps } from \"../utils/Props\";\nimport type { Omit } from \"../utils/typeUtils\";\nimport { Dialog as BaseDialog } from \"@itwin/itwinui-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport type { ButtonProps } from \"@itwin/itwinui-react\";\n\n// cspell:ignore focustrap\n\n/** Enum for dialog alignment\n * @public\n */\nexport enum DialogAlignment {\n TopLeft = \"top-left\",\n Top = \"top\",\n TopRight = \"top-right\",\n Left = \"left\",\n Center = \"center\",\n Right = \"right\",\n BottomLeft = \"bottom-left\",\n Bottom = \"bottom\",\n BottomRight = \"bottom-right\",\n}\n\n/** Properties for the [[Dialog]] component\n * @public\n */\nexport interface DialogProps\n extends Omit<React.AllHTMLAttributes<HTMLDivElement>, \"title\">,\n CommonProps {\n /** Indicates whether to show dialog or not */\n opened: boolean;\n\n /** Indicates whether the user can resize dialog with cursor. Default: false */\n resizable?: boolean;\n /** Indicates whether the user can move dialog with cursor. Default: false */\n movable?: boolean;\n /** Indicates whether the content should be inset. Default: true */\n inset?: boolean;\n /** Indicates whether the focus should be trapped within the dialog. Default: false */\n trapFocus?: boolean;\n\n /** Whether the hide the header. Default: false */\n hideHeader?: boolean;\n /** Override for the header */\n header?: React.ReactNode;\n /** Title to show in title bar of dialog */\n title?: string | React.ReactElement;\n /** Footer to show at bottom of dialog. Note: will override buttonCluster */\n footer?: string | React.ReactElement;\n /** List of DialogButtonDef objects specifying buttons and associated onClick events */\n buttonCluster?: DialogButtonDef[];\n\n /** Default alignment of dialog. */\n alignment?: DialogAlignment;\n /** Initial x/left position of dialog in px. */\n x?: number;\n /** Initial y/top position of dialog in px. */\n y?: number;\n\n /** onClick event for X button for dialog */\n onClose?: () => void;\n /** 'keyup' event for Esc key */\n onEscape?: () => void;\n /** Triggered when a click is triggered outside of this dialog. */\n onOutsideClick?: (event: MouseEvent) => any;\n\n /** Initial width of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: \"50%\" */\n width?: string | number;\n /** Initial height of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */\n height?: string | number;\n /** Minimum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 300px */\n minWidth?: string | number;\n /** Minimum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 135px */\n minHeight?: string | number;\n /** Maximum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 100% */\n maxWidth?: string | number;\n /** Maximum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */\n maxHeight?: string | number;\n\n /** Whether to show background overlay. Default: true.\n * @note Modeless dialogs require an id and an implementation of onModelessPointerDown.\n */\n modal?: boolean;\n /** An id for a modeless dialog */\n modelessId?: string;\n /** Pointer Down event handler when modeless (modal = false) */\n onModelessPointerDown?: (event: React.PointerEvent, id: string) => void;\n\n /** Custom CSS Style for overlay */\n backgroundStyle?: React.CSSProperties;\n /** Custom CSS Style for title */\n titleStyle?: React.CSSProperties;\n /** Custom CSS Style for footer */\n footerStyle?: React.CSSProperties;\n /** Custom CSS class name for the content */\n contentClassName?: string;\n /** Custom CSS Style for the content */\n contentStyle?: React.CSSProperties;\n}\n\n/** @internal */\ninterface DialogState {\n rightResizing: boolean;\n downResizing: boolean;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n}\n\n/**\n * Dialog React component with optional resizing and dragging functionality\n * @public\n */\nexport class Dialog extends React.Component<DialogProps, DialogState> {\n private _parentDocument = document;\n public static defaultProps: Partial<DialogProps> = {\n maxWidth: \"100%\",\n width: \"50%\",\n hideHeader: false,\n resizable: false,\n movable: false,\n modal: true,\n inset: true,\n trapFocus: false,\n };\n\n constructor(props: DialogProps) {\n super(props);\n }\n\n public override componentWillUnmount(): void {\n this._parentDocument.removeEventListener(\"keyup\", this._handleKeyUp, true);\n }\n\n public override componentDidMount(): void {\n this._parentDocument.addEventListener(\"keyup\", this._handleKeyUp, true);\n }\n\n // istanbul ignore next\n public handleRefSet = (containerDiv: HTMLDivElement | null) => {\n if (containerDiv) this._parentDocument = containerDiv.ownerDocument;\n };\n\n public override render(): React.ReactElement {\n const {\n opened,\n title,\n footer,\n buttonCluster,\n onClose,\n onEscape,\n onOutsideClick,\n minWidth,\n minHeight,\n x,\n y,\n width,\n height,\n maxHeight,\n maxWidth,\n backgroundStyle,\n titleStyle,\n footerStyle,\n style,\n contentStyle,\n contentClassName,\n modal,\n resizable,\n movable,\n className,\n alignment,\n inset,\n trapFocus,\n modelessId,\n onModelessPointerDown,\n hideHeader,\n header,\n ...props\n } = this.props;\n\n let initialOffset: React.CSSProperties = {};\n if (x || y) {\n initialOffset = {\n left: x ?? 0,\n top: y ?? 0,\n transform: \"none\",\n };\n }\n\n const containerStyle: React.CSSProperties = {\n ...initialOffset,\n margin: \"\",\n width,\n height,\n };\n\n const minMaxStyle: React.CSSProperties = {\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n };\n const dialogBaseContainerStyle: React.CSSProperties = {\n ...containerStyle,\n ...minMaxStyle,\n };\n\n const buttons = this.getFooterButtons(\n buttonCluster,\n \"high-visibility\",\n true\n );\n\n return (\n <BaseDialog\n isOpen={opened}\n onClose={onClose}\n closeOnExternalClick={false}\n closeOnEsc={false}\n style={style}\n className={classnames(\"core-dialog\", className)}\n isDraggable={movable}\n isResizable={resizable}\n trapFocus={trapFocus && /* istanbul ignore next */ modal}\n preventDocumentScroll={true}\n data-testid=\"core-dialog-root\"\n {...props}\n >\n {modal && <BaseDialog.Backdrop style={backgroundStyle} />}\n <DivWithOutsideClick onOutsideClick={onOutsideClick}>\n <BaseDialog.Main\n className={classnames(\n \"core-dialog-main\",\n alignment && this.getCSSClassNameFromAlignment(alignment)\n )}\n data-testid=\"core-dialog-container\"\n style={dialogBaseContainerStyle}\n onPointerDown={this._handleContainerPointerDown}\n >\n {!hideHeader &&\n (header || (\n <BaseDialog.TitleBar\n titleText={title}\n style={titleStyle}\n data-testid=\"core-dialog-head\"\n />\n ))}\n <BaseDialog.Content\n className={contentClassName}\n style={{ padding: inset ? undefined : 0, ...contentStyle }}\n >\n {this.props.children}\n </BaseDialog.Content>\n {footer || (\n <BaseDialog.ButtonBar style={footerStyle}>\n {buttons}\n </BaseDialog.ButtonBar>\n )}\n </BaseDialog.Main>\n </DivWithOutsideClick>\n </BaseDialog>\n );\n }\n\n private getCSSClassNameFromAlignment(alignment: DialogAlignment): string {\n switch (alignment) {\n case DialogAlignment.TopLeft:\n return \"core-align-top-left\";\n case DialogAlignment.Top:\n return \"core-align-top\";\n case DialogAlignment.TopRight:\n return \"core-align-top-right\";\n case DialogAlignment.Left:\n return \"core-align-left\";\n case DialogAlignment.Center:\n return \"core-align-center\";\n case DialogAlignment.Right:\n return \"core-align-right\";\n case DialogAlignment.BottomLeft:\n return \"core-align-bottom-left\";\n case DialogAlignment.Bottom:\n return \"core-align-bottom\";\n case DialogAlignment.BottomRight:\n return \"core-align-bottom-right\";\n }\n }\n\n protected getFooterButtons(\n buttonCluster: DialogButtonDef[] | undefined,\n /* istanbul ignore next */ primaryStyleType: ButtonProps[\"styleType\"] = \"cta\",\n /* istanbul ignore next */ noCoreButtonClasses: boolean = false\n ): React.ReactNode[] | undefined {\n if (buttonCluster === undefined) return undefined;\n\n const buttons: React.ReactNode[] = [];\n buttonCluster.forEach((button: DialogButtonDef, index: number) => {\n let buttonText = \"\";\n // istanbul ignore next\n let buttonClass = classnames(\n !noCoreButtonClasses && \"core-dialog-button\",\n !noCoreButtonClasses && `dialog-button-${button.type}`,\n button.className\n );\n let usePrimaryStyleType = false;\n\n switch (button.type) {\n case DialogButtonType.OK:\n buttonText = UiCore.translate(\"dialog.ok\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Retry:\n buttonText = UiCore.translate(\"dialog.retry\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Yes:\n buttonText = UiCore.translate(\"dialog.yes\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.No:\n buttonText = UiCore.translate(\"dialog.no\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Cancel:\n buttonText = UiCore.translate(\"dialog.cancel\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Close:\n buttonText = UiCore.translate(\"dialog.close\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Next:\n buttonText = UiCore.translate(\"dialog.next\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Previous:\n buttonText = UiCore.translate(\"dialog.previous\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n }\n\n if (button.label) buttonText = button.label;\n\n buttons.push(\n <Button\n className={buttonClass}\n disabled={button.disabled}\n styleType={usePrimaryStyleType ? primaryStyleType : undefined}\n key={index.toString()}\n onClick={button.onClick}\n >\n {buttonText}\n </Button>\n );\n });\n return buttons;\n }\n\n private _handleKeyUp = (event: KeyboardEvent) => {\n if (\n event.key === SpecialKey.Escape &&\n this.props.opened &&\n this.props.onEscape\n ) {\n this.props.onEscape();\n }\n };\n\n protected _handleContainerPointerDown = (event: React.PointerEvent): void => {\n // istanbul ignore next\n if (!this.props.modal) {\n if (this.props.onModelessPointerDown && this.props.modelessId)\n this.props.onModelessPointerDown(event, this.props.modelessId);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../../src/core-react/dialog/Dialog.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,yBAAuB;AACvB,2CAAoC;AACpC,+BAA+B;AAE/B,0DAAqE;AACrE,qEAAkE;AAClE,sCAAmC;AAGnC,wDAA4D;AAC5D,wDAA8C;AAG9C,0BAA0B;AAE1B;;GAEG;AACH,IAAY,eAUX;AAVD,WAAY,eAAe;IACzB,uCAAoB,CAAA;IACpB,8BAAW,CAAA;IACX,yCAAsB,CAAA;IACtB,gCAAa,CAAA;IACb,oCAAiB,CAAA;IACjB,kCAAe,CAAA;IACf,6CAA0B,CAAA;IAC1B,oCAAiB,CAAA;IACjB,+CAA4B,CAAA;AAC9B,CAAC,EAVW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAU1B;AAyFD;;;GAGG;AACH,MAAa,MAAO,SAAQ,KAAK,CAAC,SAAmC;IAanE,YAAY,KAAkB;QAC5B,KAAK,CAAC,KAAK,CAAC,CAAC;QAbP,oBAAe,GAAG,QAAQ,CAAC;QAwBnC,uBAAuB;QAChB,iBAAY,GAAG,CAAC,YAAmC,EAAE,EAAE;YAC5D,IAAI,YAAY;gBAAE,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC,aAAa,CAAC;QACtE,CAAC,CAAC;QA6NM,iBAAY,GAAG,CAAC,KAAoB,EAAE,EAAE;YAC9C,IACE,KAAK,CAAC,GAAG,KAAK,2BAAU,CAAC,MAAM;gBAC/B,IAAI,CAAC,KAAK,CAAC,MAAM;gBACjB,IAAI,CAAC,KAAK,CAAC,QAAQ,EACnB;gBACA,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;aACvB;QACH,CAAC,CAAC;QAEQ,gCAA2B,GAAG,CAAC,KAAyB,EAAQ,EAAE;YAC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;IAChB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,KAAK;CACjB,AATyB,CASxB;AAXS,wBAAM","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 Dialog\n */\n\nimport \"./Dialog.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { DialogButtonDef } from \"@itwin/appui-abstract\";\nimport { DialogButtonType, SpecialKey } from \"@itwin/appui-abstract\";\nimport { DivWithOutsideClick } from \"../base/DivWithOutsideClick\";\nimport { UiCore } from \"../UiCore\";\nimport type { CommonProps } from \"../utils/Props\";\nimport type { Omit } from \"../utils/typeUtils\";\nimport { Dialog as BaseDialog } from \"@itwin/itwinui-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport type { ButtonProps } from \"@itwin/itwinui-react\";\n\n// cspell:ignore focustrap\n\n/** Enum for dialog alignment\n * @public\n */\nexport enum DialogAlignment {\n TopLeft = \"top-left\",\n Top = \"top\",\n TopRight = \"top-right\",\n Left = \"left\",\n Center = \"center\",\n Right = \"right\",\n BottomLeft = \"bottom-left\",\n Bottom = \"bottom\",\n BottomRight = \"bottom-right\",\n}\n\n/** Properties for the [[Dialog]] component\n * @public\n */\nexport interface DialogProps\n extends Omit<React.AllHTMLAttributes<HTMLDivElement>, \"title\">,\n CommonProps {\n /** Indicates whether to show dialog or not */\n opened: boolean;\n\n /** Indicates whether the user can resize dialog with cursor. Default: false */\n resizable?: boolean;\n /** Indicates whether the user can move dialog with cursor. Default: false */\n movable?: boolean;\n /** Indicates whether the content should be inset. Default: true */\n inset?: boolean;\n /** Indicates whether the focus should be trapped within the dialog. Default: false */\n trapFocus?: boolean;\n\n /** Whether the hide the header. Default: false */\n hideHeader?: boolean;\n /** Override for the header */\n header?: React.ReactNode;\n /** Title to show in title bar of dialog */\n title?: string | React.ReactElement;\n /** Footer to show at bottom of dialog. Note: will override buttonCluster */\n footer?: string | React.ReactElement;\n /** List of DialogButtonDef objects specifying buttons and associated onClick events */\n buttonCluster?: DialogButtonDef[];\n\n /** Default alignment of dialog. */\n alignment?: DialogAlignment;\n /** Initial x/left position of dialog in px. */\n x?: number;\n /** Initial y/top position of dialog in px. */\n y?: number;\n\n /** onClick event for X button for dialog */\n onClose?: () => void;\n /** 'keyup' event for Esc key */\n onEscape?: () => void;\n /** Triggered when a click is triggered outside of this dialog. */\n onOutsideClick?: (event: MouseEvent) => any;\n\n /** Initial width of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: \"50%\" */\n width?: string | number;\n /** Initial height of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */\n height?: string | number;\n /** Minimum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 300px */\n minWidth?: string | number;\n /** Minimum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 135px */\n minHeight?: string | number;\n /** Maximum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. Default: 100% */\n maxWidth?: string | number;\n /** Maximum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */\n maxHeight?: string | number;\n\n /** Whether to show background overlay. Default: true.\n * @note Modeless dialogs require an id and an implementation of onModelessPointerDown.\n */\n modal?: boolean;\n /** An id for a modeless dialog */\n modelessId?: string;\n /** Pointer Down event handler when modeless (modal = false) */\n onModelessPointerDown?: (event: React.PointerEvent, id: string) => void;\n\n /** Custom CSS Style for overlay */\n backgroundStyle?: React.CSSProperties;\n /** Custom CSS Style for title */\n titleStyle?: React.CSSProperties;\n /** Custom CSS Style for footer */\n footerStyle?: React.CSSProperties;\n /** Custom CSS class name for the content */\n contentClassName?: string;\n /** Custom CSS Style for the content */\n contentStyle?: React.CSSProperties;\n}\n\n/** @internal */\ninterface DialogState {\n rightResizing: boolean;\n downResizing: boolean;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n}\n\n/**\n * Dialog React component with optional resizing and dragging functionality\n * @public\n */\nexport class Dialog extends React.Component<DialogProps, DialogState> {\n private _parentDocument = document;\n public static defaultProps: Partial<DialogProps> = {\n maxWidth: \"100%\",\n width: \"50%\",\n hideHeader: false,\n resizable: false,\n movable: false,\n modal: true,\n inset: true,\n trapFocus: false,\n };\n\n constructor(props: DialogProps) {\n super(props);\n }\n\n public override componentWillUnmount(): void {\n this._parentDocument.removeEventListener(\"keyup\", this._handleKeyUp, true);\n }\n\n public override componentDidMount(): void {\n this._parentDocument.addEventListener(\"keyup\", this._handleKeyUp, true);\n }\n\n // istanbul ignore next\n public handleRefSet = (containerDiv: HTMLDivElement | null) => {\n if (containerDiv) this._parentDocument = containerDiv.ownerDocument;\n };\n\n public override render(): React.ReactElement {\n const {\n opened,\n title,\n footer,\n buttonCluster,\n onClose,\n onEscape,\n onOutsideClick,\n minWidth,\n minHeight,\n x,\n y,\n width,\n height,\n maxHeight,\n maxWidth,\n backgroundStyle,\n titleStyle,\n footerStyle,\n style,\n contentStyle,\n contentClassName,\n modal,\n resizable,\n movable,\n className,\n alignment,\n inset,\n trapFocus,\n modelessId,\n onModelessPointerDown,\n hideHeader,\n header,\n ...props\n } = this.props;\n\n let initialOffset: React.CSSProperties = {};\n if (x || y) {\n initialOffset = {\n left: x ?? 0,\n top: y ?? 0,\n transform: \"none\",\n };\n }\n\n const containerStyle: React.CSSProperties = {\n ...initialOffset,\n margin: \"\",\n width,\n height,\n };\n\n const minMaxStyle: React.CSSProperties = {\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n };\n const dialogBaseContainerStyle: React.CSSProperties = {\n ...containerStyle,\n ...minMaxStyle,\n };\n\n const buttons = this.getFooterButtons(\n buttonCluster,\n \"high-visibility\",\n true\n );\n\n return (\n <BaseDialog\n isOpen={opened}\n onClose={onClose}\n closeOnExternalClick={false}\n closeOnEsc={false}\n style={style}\n className={classnames(\"core-dialog\", className)}\n isDraggable={movable}\n isResizable={resizable}\n trapFocus={trapFocus && /* istanbul ignore next */ modal}\n preventDocumentScroll={true}\n data-testid=\"core-dialog-root\"\n {...props}\n >\n {modal && <BaseDialog.Backdrop style={backgroundStyle} />}\n <DivWithOutsideClick onOutsideClick={onOutsideClick}>\n <BaseDialog.Main\n className={classnames(\n \"core-dialog-main\",\n alignment && this.getCSSClassNameFromAlignment(alignment)\n )}\n data-testid=\"core-dialog-container\"\n style={dialogBaseContainerStyle}\n onPointerDown={this._handleContainerPointerDown}\n >\n {!hideHeader &&\n (header || (\n <BaseDialog.TitleBar\n titleText={title}\n style={titleStyle}\n data-testid=\"core-dialog-head\"\n />\n ))}\n <BaseDialog.Content\n className={contentClassName}\n style={{ padding: inset ? undefined : 0, ...contentStyle }}\n >\n {this.props.children}\n </BaseDialog.Content>\n {footer || (\n <BaseDialog.ButtonBar style={footerStyle}>\n {buttons}\n </BaseDialog.ButtonBar>\n )}\n </BaseDialog.Main>\n </DivWithOutsideClick>\n </BaseDialog>\n );\n }\n\n private getCSSClassNameFromAlignment(alignment: DialogAlignment): string {\n switch (alignment) {\n case DialogAlignment.TopLeft:\n return \"core-align-top-left\";\n case DialogAlignment.Top:\n return \"core-align-top\";\n case DialogAlignment.TopRight:\n return \"core-align-top-right\";\n case DialogAlignment.Left:\n return \"core-align-left\";\n case DialogAlignment.Center:\n return \"core-align-center\";\n case DialogAlignment.Right:\n return \"core-align-right\";\n case DialogAlignment.BottomLeft:\n return \"core-align-bottom-left\";\n case DialogAlignment.Bottom:\n return \"core-align-bottom\";\n case DialogAlignment.BottomRight:\n return \"core-align-bottom-right\";\n }\n }\n\n protected getFooterButtons(\n buttonCluster: DialogButtonDef[] | undefined,\n /* istanbul ignore next */ primaryStyleType: ButtonProps[\"styleType\"] = \"cta\",\n /* istanbul ignore next */ noCoreButtonClasses: boolean = false\n ): React.ReactNode[] | undefined {\n if (buttonCluster === undefined) return undefined;\n\n const buttons: React.ReactNode[] = [];\n buttonCluster.forEach((button: DialogButtonDef, index: number) => {\n let buttonText = \"\";\n // istanbul ignore next\n let buttonClass = classnames(\n !noCoreButtonClasses && \"core-dialog-button\",\n !noCoreButtonClasses && `dialog-button-${button.type}`,\n button.className\n );\n let usePrimaryStyleType = false;\n\n switch (button.type) {\n case DialogButtonType.OK:\n buttonText = UiCore.translate(\"dialog.ok\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Retry:\n buttonText = UiCore.translate(\"dialog.retry\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Yes:\n buttonText = UiCore.translate(\"dialog.yes\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.No:\n buttonText = UiCore.translate(\"dialog.no\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Cancel:\n buttonText = UiCore.translate(\"dialog.cancel\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Close:\n buttonText = UiCore.translate(\"dialog.close\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n break;\n case DialogButtonType.Next:\n buttonText = UiCore.translate(\"dialog.next\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n case DialogButtonType.Previous:\n buttonText = UiCore.translate(\"dialog.previous\");\n buttonClass = classnames(buttonClass, button.buttonStyle);\n usePrimaryStyleType = true;\n break;\n }\n\n if (button.label) buttonText = button.label;\n\n buttons.push(\n <Button\n className={buttonClass}\n disabled={button.disabled}\n styleType={usePrimaryStyleType ? primaryStyleType : undefined}\n key={index.toString()}\n onClick={button.onClick}\n >\n {buttonText}\n </Button>\n );\n });\n return buttons;\n }\n\n private _handleKeyUp = (event: KeyboardEvent) => {\n if (\n event.key === SpecialKey.Escape &&\n this.props.opened &&\n this.props.onEscape\n ) {\n this.props.onEscape();\n }\n };\n\n protected _handleContainerPointerDown = (event: React.PointerEvent): void => {\n // istanbul ignore next\n if (!this.props.modal) {\n if (this.props.onModelessPointerDown && this.props.modelessId)\n this.props.onModelessPointerDown(event, this.props.modelessId);\n }\n };\n}\n"]}
|
|
@@ -21,8 +21,7 @@ class GlobalDialog extends React.Component {
|
|
|
21
21
|
parentDocument: null,
|
|
22
22
|
};
|
|
23
23
|
this._handleRefSet = (popupDiv) => {
|
|
24
|
-
|
|
25
|
-
const parentDocument = (_a = popupDiv === null || popupDiv === void 0 ? void 0 : popupDiv.ownerDocument) !== null && _a !== void 0 ? _a : null;
|
|
24
|
+
const parentDocument = popupDiv?.ownerDocument ?? null;
|
|
26
25
|
if (parentDocument) {
|
|
27
26
|
this._container = parentDocument.createElement("div");
|
|
28
27
|
this._container.id =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalDialog.js","sourceRoot":"","sources":["../../../../src/core-react/dialog/GlobalDialog.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAC/B,sCAAsC;AAEtC,qCAAkC;AAgBlC;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK,CAAC,SAGvC;IAOC,YAAY,KAAwB;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;QALU,UAAK,GAAsB;YAClD,cAAc,EAAE,IAAI;SACrB,CAAC;QAMM,kBAAa,GAAG,CAAC,QAA4B,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"GlobalDialog.js","sourceRoot":"","sources":["../../../../src/core-react/dialog/GlobalDialog.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAC/B,sCAAsC;AAEtC,qCAAkC;AAgBlC;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK,CAAC,SAGvC;IAOC,YAAY,KAAwB;QAClC,KAAK,CAAC,KAAK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GAAG,EAAE,IAAI,CAAC,aAAa,IACzB,IAAI,CAAC,KAAK,CAAC,cAAc;YACxB,QAAQ,CAAC,YAAY,CACnB,oBAAC,eAAM,OAAK,KAAK,GAAI,EACrB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAC/B,CACC,CACP,CAAC;IACJ,CAAC;CACF;AAzDD,oCAyDC","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 Dialog\n */\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport type { DialogProps } from \"./Dialog\";\nimport { Dialog } from \"./Dialog\";\n\n/** Properties for the [[GlobalDialog]] component\n * @public\n */\nexport interface GlobalDialogProps extends DialogProps {\n identifier?: string;\n}\n\n/** State properties for the [[GlobalDialog]] component\n * @public\n */\nexport interface GlobalDialogState {\n parentDocument: Document | null;\n}\n\n/** GlobalDialog React component used to display a [[Dialog]] on the top of screen\n * @public\n */\nexport class GlobalDialog extends React.Component<\n GlobalDialogProps,\n GlobalDialogState\n> {\n private _container?: HTMLDivElement;\n\n public override readonly state: GlobalDialogState = {\n parentDocument: null,\n };\n\n constructor(props: GlobalDialogProps) {\n super(props);\n }\n\n private _handleRefSet = (popupDiv: HTMLElement | null) => {\n const parentDocument = popupDiv?.ownerDocument ?? null;\n if (parentDocument) {\n this._container = parentDocument.createElement(\"div\");\n this._container.id =\n this.props.identifier !== undefined\n ? `dialog-${this.props.identifier}`\n : \"core-dialog\";\n let rt = parentDocument.getElementById(\n \"core-dialog-root\"\n ) as HTMLDivElement;\n if (!rt) {\n rt = parentDocument.createElement(\"div\");\n rt.id = \"core-dialog-root\";\n parentDocument.body.appendChild(rt);\n }\n rt.appendChild(this._container);\n\n // used to support component rendering in pop-out window\n this.setState({ parentDocument });\n }\n };\n\n public override componentWillUnmount() {\n // istanbul ignore else\n if (this._container && this._container.parentElement) {\n // cleanup\n this._container.parentElement.removeChild(this._container);\n }\n }\n\n public override render(): React.ReactNode {\n const { identifier, ...props } = this.props;\n return (\n <div ref={this._handleRefSet}>\n {this.state.parentDocument &&\n ReactDOM.createPortal(\n <Dialog {...props} />,\n this.state.parentDocument.body\n )}\n </div>\n );\n }\n}\n"]}
|
|
@@ -35,8 +35,8 @@ const useElementSeparatorPointerHandler = ({ onResizeHandleDragChanged, onResize
|
|
|
35
35
|
const pointerOutOfBounds = (0, react_1.useRef)(false);
|
|
36
36
|
const [isElementDragged, setIsDragged] = (0, react_1.useState)(false);
|
|
37
37
|
const [isElementHovered, setIsHovered] = (0, react_1.useState)(false);
|
|
38
|
-
const isGroupDragged = isResizeHandleBeingDragged
|
|
39
|
-
const isGroupHovered = isResizeHandleHovered
|
|
38
|
+
const isGroupDragged = isResizeHandleBeingDragged ?? isElementDragged;
|
|
39
|
+
const isGroupHovered = isResizeHandleHovered ?? isElementHovered;
|
|
40
40
|
useConditionalCleanup(isElementDragged && !!onResizeHandleDragChanged, () => onResizeHandleDragChanged(false));
|
|
41
41
|
useConditionalCleanup(isElementHovered && !!onResizeHandleHoverChanged, () => onResizeHandleHoverChanged(false));
|
|
42
42
|
if (isGroupHovered && pointerOutOfBounds.current)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementSeparator.js","sourceRoot":"","sources":["../../../../src/core-react/elementseparator/ElementSeparator.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,mCAAiC;AACjC,+BAA+B;AAC/B,iCAOe;AACf,2CAAoC;AACpC,sDAAmD;AAEnD,kEAA+D;AAC/D,sCAAmC;AAkCnC,SAAS,wBAAwB,CAC/B,WAAwB,EACxB,CAAoC;IAEpC,OAAO,WAAW,KAAK,yBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;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ACf,CAAC;IAEF,OAAO,CACL,gCACE,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,EACrB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,gBACd,KAAK,CAAC,OAAO,GACzB,CACH,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,gBAAgB,oBA4C3B","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 ElementSeparator\n */\n\nimport \"./ElementSeparator.scss\";\nimport * as React from \"react\";\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport classnames from \"classnames\";\nimport { Orientation } from \"../enums/Orientation\";\nimport type { CommonProps } from \"../utils/Props\";\nimport { useThrottledFn } from \"../utils/hooks/useThrottledFn\";\nimport { UiCore } from \"../UiCore\";\n\n/**\n * Results returned by onRatioChanged callback for determining new ratio and whether the ratio was updated.\n * @public\n */\nexport interface RatioChangeResult {\n ratio: number;\n}\n\n/** Properties of [[ElementSeparator]] React component\n * @public\n */\nexport interface ElementSeparatorProps extends CommonProps {\n /** Separator orientation */\n orientation: Orientation;\n /** Ratio between left cell and right cell */\n ratio: number;\n /** Area width or height (depending on orientation) in pixels */\n movableArea?: number;\n /** Separator width or height in pixels. 30 by default */\n separatorSize?: number;\n /** Callback to ratio changed event */\n onRatioChanged?: (ratio: number) => void | RatioChangeResult;\n /** Is resize handle hovered */\n isResizeHandleHovered?: boolean;\n /** Callback to hover event change */\n onResizeHandleHoverChanged?: (isHovered: boolean) => void;\n /** Is resize handle being dragged */\n isResizeHandleBeingDragged?: boolean;\n /** Callback to drag event change */\n onResizeHandleDragChanged?: (isDragStarted: boolean) => void;\n}\n\nfunction getCurrentGlobalPosition(\n orientation: Orientation,\n e: PointerEvent | React.PointerEvent\n) {\n return orientation === Orientation.Horizontal ? e.clientX : e.clientY;\n}\n\nconst useConditionalCleanup = (condition: boolean, cleanup: () => void) => {\n const conditionRef = useRef(condition);\n const cleanupRef = useRef(cleanup);\n\n conditionRef.current = condition;\n cleanupRef.current = cleanup;\n\n useEffect(() => {\n return () => {\n if (conditionRef.current) cleanupRef.current();\n };\n }, []);\n};\n\nconst useElementSeparatorPointerHandler = ({\n onResizeHandleDragChanged,\n onResizeHandleHoverChanged,\n isResizeHandleBeingDragged,\n isResizeHandleHovered,\n movableArea,\n ratio,\n orientation,\n onRatioChanged,\n}: ElementSeparatorProps) => {\n const globalPosition = useRef(0);\n const pointerOutOfBounds = useRef(false);\n\n const [isElementDragged, setIsDragged] = useState(false);\n const [isElementHovered, setIsHovered] = useState(false);\n const isGroupDragged = isResizeHandleBeingDragged ?? isElementDragged;\n const isGroupHovered = isResizeHandleHovered ?? isElementHovered;\n\n useConditionalCleanup(isElementDragged && !!onResizeHandleDragChanged, () =>\n onResizeHandleDragChanged!(false)\n );\n useConditionalCleanup(isElementHovered && !!onResizeHandleHoverChanged, () =>\n onResizeHandleHoverChanged!(false)\n );\n\n if (isGroupHovered && pointerOutOfBounds.current)\n pointerOutOfBounds.current = false;\n\n const stopDrag = useCallback(() => {\n // istanbul ignore else\n if (isGroupDragged) {\n setIsDragged(false);\n if (onResizeHandleDragChanged) onResizeHandleDragChanged(false);\n }\n }, [isGroupDragged, onResizeHandleDragChanged]);\n\n const startDrag = useCallback(\n (e: PointerEvent | React.PointerEvent) => {\n globalPosition.current = getCurrentGlobalPosition(orientation, e);\n\n // istanbul ignore else\n if (!isGroupDragged) {\n setIsDragged(true);\n if (onResizeHandleDragChanged) onResizeHandleDragChanged(true);\n }\n },\n [isGroupDragged, orientation, onResizeHandleDragChanged]\n );\n\n const onPointerUp = useCallback(() => {\n stopDrag();\n }, [stopDrag]);\n\n const onThrottledPointerMove = useThrottledFn(\n (e: PointerEvent | React.PointerEvent) => {\n if (!movableArea) {\n stopDrag();\n return;\n }\n\n const currentPosition = getCurrentGlobalPosition(orientation, e);\n const positionChange = currentPosition - globalPosition.current;\n\n // Should not need to recalculate if position on our movement axis does not change\n if (Math.abs(positionChange) < 1) return;\n\n const currentLocalPosition = movableArea * ratio + positionChange;\n const newRatio = currentLocalPosition / movableArea;\n\n globalPosition.current = currentPosition;\n if (pointerOutOfBounds.current || !onRatioChanged) return;\n\n const result = onRatioChanged(newRatio);\n if (\n result &&\n result.ratio === ratio &&\n !isGroupHovered &&\n !pointerOutOfBounds.current\n )\n pointerOutOfBounds.current = true;\n },\n 16,\n [stopDrag, isGroupHovered, ratio, movableArea, onRatioChanged, orientation]\n );\n\n useEffect(() => {\n return () => onThrottledPointerMove.cancel();\n }, [onThrottledPointerMove]);\n\n useLayoutEffect(() => {\n if (isElementDragged) {\n document.addEventListener(\"pointerup\", onPointerUp);\n document.addEventListener(\"pointermove\", onThrottledPointerMove);\n }\n\n return () => {\n document.removeEventListener(\"pointerup\", onPointerUp);\n document.removeEventListener(\"pointermove\", onThrottledPointerMove);\n };\n }, [isElementDragged, onPointerUp, onThrottledPointerMove]);\n\n const onPointerDown = useCallback(\n (e: PointerEvent | React.PointerEvent) => {\n if (!isGroupDragged) {\n startDrag(e);\n } else {\n stopDrag();\n }\n },\n [isGroupDragged, startDrag, stopDrag]\n );\n\n const onPointerOver = useCallback(() => {\n // istanbul ignore next\n if (isGroupHovered) return;\n\n setIsHovered(true);\n if (onResizeHandleHoverChanged) onResizeHandleHoverChanged(true);\n }, [isGroupHovered, onResizeHandleHoverChanged]);\n\n const onPointerOut = useCallback(() => {\n // istanbul ignore next\n if (!isGroupHovered) return;\n\n setIsHovered(false);\n if (onResizeHandleHoverChanged) onResizeHandleHoverChanged(false);\n }, [isGroupHovered, onResizeHandleHoverChanged]);\n\n return {\n isHovered: isGroupHovered,\n isDragged: isGroupDragged,\n onPointerDown,\n onPointerOver,\n onPointerOut,\n };\n};\n\nfunction getStyle(\n orientation: Orientation,\n separatorSize?: number\n): React.CSSProperties {\n separatorSize = separatorSize || 30;\n\n if (orientation === Orientation.Horizontal)\n return {\n width: separatorSize,\n margin: `0px ${-Math.floor(separatorSize / 2)}px`,\n };\n return {\n height: separatorSize,\n margin: `${-Math.floor(separatorSize / 2)}px 1px`,\n };\n}\n\n/** A movable button, which allows to change the ratio between left element and right element\n * @public\n */\nexport const ElementSeparator = (props: ElementSeparatorProps) => {\n const label = useRef(UiCore.translate(\"elementSeparator.label\"));\n const [hasHoverHappened, setHasHoverHappened] = useState(false);\n const { isDragged, isHovered, onPointerDown, onPointerOver, onPointerOut } =\n useElementSeparatorPointerHandler(props);\n\n const isHoverNeeded = isHovered || isDragged;\n if (!hasHoverHappened && isHoverNeeded) setHasHoverHappened(isHoverNeeded);\n\n // This is done to avoid fade-out animation when first rendering.\n const unhoverClass = hasHoverHappened\n ? \"core-element-separator-group-unhovered\"\n : \"\";\n\n const classNames = classnames(\n \"core-element-separator\",\n props.orientation === Orientation.Horizontal\n ? \"core-element-separator--horizontal\"\n : \"core-element-separator--vertical\",\n props.className,\n isHoverNeeded ? \"core-element-separator-group-hovered\" : unhoverClass\n );\n\n const orientation = props.orientation;\n const separatorSize = props.separatorSize;\n const style = useMemo(\n () => getStyle(orientation, separatorSize),\n [orientation, separatorSize]\n );\n const styles: React.CSSProperties = {\n ...style,\n ...props.style,\n };\n\n return (\n <button\n style={styles}\n className={classNames}\n onPointerDown={onPointerDown}\n onPointerOver={onPointerOver}\n onPointerOut={onPointerOut}\n aria-label={label.current}\n />\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ElementSeparator.js","sourceRoot":"","sources":["../../../../src/core-react/elementseparator/ElementSeparator.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,mCAAiC;AACjC,+BAA+B;AAC/B,iCAOe;AACf,2CAAoC;AACpC,sDAAmD;AAEnD,kEAA+D;AAC/D,sCAAmC;AAkCnC,SAAS,wBAAwB,CAC/B,WAAwB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AAC;IACF,MAAM,MAAM,GAAwB;QAClC,GAAG,KAAK;QACR,GAAG,KAAK,CAAC,KAAK;KACf,CAAC;IAEF,OAAO,CACL,gCACE,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,EACrB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,gBACd,KAAK,CAAC,OAAO,GACzB,CACH,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,gBAAgB,oBA4C3B","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 ElementSeparator\n */\n\nimport \"./ElementSeparator.scss\";\nimport * as React from \"react\";\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport classnames from \"classnames\";\nimport { Orientation } from \"../enums/Orientation\";\nimport type { CommonProps } from \"../utils/Props\";\nimport { useThrottledFn } from \"../utils/hooks/useThrottledFn\";\nimport { UiCore } from \"../UiCore\";\n\n/**\n * Results returned by onRatioChanged callback for determining new ratio and whether the ratio was updated.\n * @public\n */\nexport interface RatioChangeResult {\n ratio: number;\n}\n\n/** Properties of [[ElementSeparator]] React component\n * @public\n */\nexport interface ElementSeparatorProps extends CommonProps {\n /** Separator orientation */\n orientation: Orientation;\n /** Ratio between left cell and right cell */\n ratio: number;\n /** Area width or height (depending on orientation) in pixels */\n movableArea?: number;\n /** Separator width or height in pixels. 30 by default */\n separatorSize?: number;\n /** Callback to ratio changed event */\n onRatioChanged?: (ratio: number) => void | RatioChangeResult;\n /** Is resize handle hovered */\n isResizeHandleHovered?: boolean;\n /** Callback to hover event change */\n onResizeHandleHoverChanged?: (isHovered: boolean) => void;\n /** Is resize handle being dragged */\n isResizeHandleBeingDragged?: boolean;\n /** Callback to drag event change */\n onResizeHandleDragChanged?: (isDragStarted: boolean) => void;\n}\n\nfunction getCurrentGlobalPosition(\n orientation: Orientation,\n e: PointerEvent | React.PointerEvent\n) {\n return orientation === Orientation.Horizontal ? e.clientX : e.clientY;\n}\n\nconst useConditionalCleanup = (condition: boolean, cleanup: () => void) => {\n const conditionRef = useRef(condition);\n const cleanupRef = useRef(cleanup);\n\n conditionRef.current = condition;\n cleanupRef.current = cleanup;\n\n useEffect(() => {\n return () => {\n if (conditionRef.current) cleanupRef.current();\n };\n }, []);\n};\n\nconst useElementSeparatorPointerHandler = ({\n onResizeHandleDragChanged,\n onResizeHandleHoverChanged,\n isResizeHandleBeingDragged,\n isResizeHandleHovered,\n movableArea,\n ratio,\n orientation,\n onRatioChanged,\n}: ElementSeparatorProps) => {\n const globalPosition = useRef(0);\n const pointerOutOfBounds = useRef(false);\n\n const [isElementDragged, setIsDragged] = useState(false);\n const [isElementHovered, setIsHovered] = useState(false);\n const isGroupDragged = isResizeHandleBeingDragged ?? isElementDragged;\n const isGroupHovered = isResizeHandleHovered ?? isElementHovered;\n\n useConditionalCleanup(isElementDragged && !!onResizeHandleDragChanged, () =>\n onResizeHandleDragChanged!(false)\n );\n useConditionalCleanup(isElementHovered && !!onResizeHandleHoverChanged, () =>\n onResizeHandleHoverChanged!(false)\n );\n\n if (isGroupHovered && pointerOutOfBounds.current)\n pointerOutOfBounds.current = false;\n\n const stopDrag = useCallback(() => {\n // istanbul ignore else\n if (isGroupDragged) {\n setIsDragged(false);\n if (onResizeHandleDragChanged) onResizeHandleDragChanged(false);\n }\n }, [isGroupDragged, onResizeHandleDragChanged]);\n\n const startDrag = useCallback(\n (e: PointerEvent | React.PointerEvent) => {\n globalPosition.current = getCurrentGlobalPosition(orientation, e);\n\n // istanbul ignore else\n if (!isGroupDragged) {\n setIsDragged(true);\n if (onResizeHandleDragChanged) onResizeHandleDragChanged(true);\n }\n },\n [isGroupDragged, orientation, onResizeHandleDragChanged]\n );\n\n const onPointerUp = useCallback(() => {\n stopDrag();\n }, [stopDrag]);\n\n const onThrottledPointerMove = useThrottledFn(\n (e: PointerEvent | React.PointerEvent) => {\n if (!movableArea) {\n stopDrag();\n return;\n }\n\n const currentPosition = getCurrentGlobalPosition(orientation, e);\n const positionChange = currentPosition - globalPosition.current;\n\n // Should not need to recalculate if position on our movement axis does not change\n if (Math.abs(positionChange) < 1) return;\n\n const currentLocalPosition = movableArea * ratio + positionChange;\n const newRatio = currentLocalPosition / movableArea;\n\n globalPosition.current = currentPosition;\n if (pointerOutOfBounds.current || !onRatioChanged) return;\n\n const result = onRatioChanged(newRatio);\n if (\n result &&\n result.ratio === ratio &&\n !isGroupHovered &&\n !pointerOutOfBounds.current\n )\n pointerOutOfBounds.current = true;\n },\n 16,\n [stopDrag, isGroupHovered, ratio, movableArea, onRatioChanged, orientation]\n );\n\n useEffect(() => {\n return () => onThrottledPointerMove.cancel();\n }, [onThrottledPointerMove]);\n\n useLayoutEffect(() => {\n if (isElementDragged) {\n document.addEventListener(\"pointerup\", onPointerUp);\n document.addEventListener(\"pointermove\", onThrottledPointerMove);\n }\n\n return () => {\n document.removeEventListener(\"pointerup\", onPointerUp);\n document.removeEventListener(\"pointermove\", onThrottledPointerMove);\n };\n }, [isElementDragged, onPointerUp, onThrottledPointerMove]);\n\n const onPointerDown = useCallback(\n (e: PointerEvent | React.PointerEvent) => {\n if (!isGroupDragged) {\n startDrag(e);\n } else {\n stopDrag();\n }\n },\n [isGroupDragged, startDrag, stopDrag]\n );\n\n const onPointerOver = useCallback(() => {\n // istanbul ignore next\n if (isGroupHovered) return;\n\n setIsHovered(true);\n if (onResizeHandleHoverChanged) onResizeHandleHoverChanged(true);\n }, [isGroupHovered, onResizeHandleHoverChanged]);\n\n const onPointerOut = useCallback(() => {\n // istanbul ignore next\n if (!isGroupHovered) return;\n\n setIsHovered(false);\n if (onResizeHandleHoverChanged) onResizeHandleHoverChanged(false);\n }, [isGroupHovered, onResizeHandleHoverChanged]);\n\n return {\n isHovered: isGroupHovered,\n isDragged: isGroupDragged,\n onPointerDown,\n onPointerOver,\n onPointerOut,\n };\n};\n\nfunction getStyle(\n orientation: Orientation,\n separatorSize?: number\n): React.CSSProperties {\n separatorSize = separatorSize || 30;\n\n if (orientation === Orientation.Horizontal)\n return {\n width: separatorSize,\n margin: `0px ${-Math.floor(separatorSize / 2)}px`,\n };\n return {\n height: separatorSize,\n margin: `${-Math.floor(separatorSize / 2)}px 1px`,\n };\n}\n\n/** A movable button, which allows to change the ratio between left element and right element\n * @public\n */\nexport const ElementSeparator = (props: ElementSeparatorProps) => {\n const label = useRef(UiCore.translate(\"elementSeparator.label\"));\n const [hasHoverHappened, setHasHoverHappened] = useState(false);\n const { isDragged, isHovered, onPointerDown, onPointerOver, onPointerOut } =\n useElementSeparatorPointerHandler(props);\n\n const isHoverNeeded = isHovered || isDragged;\n if (!hasHoverHappened && isHoverNeeded) setHasHoverHappened(isHoverNeeded);\n\n // This is done to avoid fade-out animation when first rendering.\n const unhoverClass = hasHoverHappened\n ? \"core-element-separator-group-unhovered\"\n : \"\";\n\n const classNames = classnames(\n \"core-element-separator\",\n props.orientation === Orientation.Horizontal\n ? \"core-element-separator--horizontal\"\n : \"core-element-separator--vertical\",\n props.className,\n isHoverNeeded ? \"core-element-separator-group-hovered\" : unhoverClass\n );\n\n const orientation = props.orientation;\n const separatorSize = props.separatorSize;\n const style = useMemo(\n () => getStyle(orientation, separatorSize),\n [orientation, separatorSize]\n );\n const styles: React.CSSProperties = {\n ...style,\n ...props.style,\n };\n\n return (\n <button\n style={styles}\n className={classNames}\n onPointerDown={onPointerDown}\n onPointerOver={onPointerOver}\n onPointerOut={onPointerOut}\n aria-label={label.current}\n />\n );\n};\n"]}
|
|
@@ -87,9 +87,8 @@ const withOnOutsideClick = (Component, defaultOnOutsideClick, useCapture = true,
|
|
|
87
87
|
return defaultOnOutsideClick(e);
|
|
88
88
|
}
|
|
89
89
|
getParentDocument() {
|
|
90
|
-
var _a, _b;
|
|
91
90
|
// istanbul ignore next
|
|
92
|
-
return
|
|
91
|
+
return this.outsideClickContainerDiv?.ownerDocument ?? document;
|
|
93
92
|
}
|
|
94
93
|
componentDidMount() {
|
|
95
94
|
const outsideClickParentDocument = this.getParentDocument();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withOnOutsideClick.js","sourceRoot":"","sources":["../../../../src/core-react/hocs/withOnOutsideClick.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,+BAA+B;AAY/B;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,SAA8C,EAC9C,qBAAkD,EAClD,aAAsB,IAAI,EAC1B,mBAA4B,IAAI,EAChC,EAAE;IACF,OAAO,MAAM,kBAAmB,SAAQ,KAAK,CAAC,aAE7C;QAFM;;YAGL,gBAAgB;YACT,6BAAwB,GAA2B,IAAI,CAAC;YAC/D,gBAAgB;YACT,kBAAa,GAAG,KAAK,CAAC;YAiC7B,gBAAgB;YACT,wBAAmB,GAAG,CAAC,CAAa,EAAE,EAAE;gBAC7C,IACE,CAAC,IAAI,CAAC,wBAAwB;oBAC9B,CAAC,CAAC,CAAC,CAAC,MAAM,YAAY,IAAI,CAAC;oBAC3B,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;oBAEhD,OAAO;gBAET,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YAChC,CAAC,CAAC;YAEF,gBAAgB;YACT,8BAAyB,GAAG,CAAC,CAAe,EAAE,EAAE;gBACrD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC1B,uBAAuB;gBACvB,IAAI,IAAI,CAAC,wBAAwB,EAAE;oBACjC,6FAA6F;oBAC7F,IAAI,CAAC,aAAa;wBAChB,CAAC,CAAC,CAAC,CAAC,MAAM;4BACV,CAAC,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAa,CAAC,CAAC;iBAC5D;YACH,CAAC,CAAC;YAE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BAAmB,CAC5C,aAAa,EACb,IAAI,CAAC,yBAAyB,EAC9B,UAAU,CACX,CAAC;gBACF,0BAA0B,CAAC,mBAAmB,CAC5C,WAAW,EACX,IAAI,CAAC,uBAAuB,EAC5B,UAAU,CACX,CAAC;aACH;;gBACC,0BAA0B,CAAC,mBAAmB,CAC5C,OAAO,EACP,IAAI,CAAC,mBAAmB,EACxB,UAAU,CACX,CAAC;QACN,CAAC;QAEe,MAAM;YACpB,MAAM,EAAE,cAAc,EAAE,8BAA8B,EAAE,GAAG,KAAK,EAAE,GAChE,IAAI,CAAC,KAAK,CAAC;YACb,OAAO,CACL,6BAAK,GAAG,EAAE,IAAI,CAAC,iCAAiC;gBAC9C,oBAAC,SAAS,OAAM,KAAwB,GAAI,CACxC,CACP,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AArJW,QAAA,kBAAkB,sBAqJ7B","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 Common\n */\n\nimport * as React from \"react\";\n\n/** Properties for [[withOnOutsideClick]] React higher-order component\n * @public\n */\nexport interface WithOnOutsideClickProps {\n /** Outside click callback function */\n onOutsideClick?: (event: MouseEvent) => any;\n /** If false outside click processing and closing are skipped if click occurs in another Popup component, default to false. */\n closeOnNestedPopupOutsideClick?: boolean;\n}\n\n/** withOnOutsideClick is a React higher-order component that adds outside click support.\n * @public\n */\nexport const withOnOutsideClick = <ComponentProps extends {}>(\n Component: React.ComponentType<ComponentProps>,\n defaultOnOutsideClick?: (event: MouseEvent) => any,\n useCapture: boolean = true,\n usePointerEvents: boolean = true\n) => {\n return class WithOnOutsideClick extends React.PureComponent<\n ComponentProps & WithOnOutsideClickProps\n > {\n /** @internal */\n public outsideClickContainerDiv?: HTMLDivElement | null = null;\n /** @internal */\n public isDownOutside = false;\n\n /** @internal */\n public isInCorePopup(element: HTMLElement): boolean {\n if (element.nodeName === \"DIV\") {\n if (element.classList && element.classList.contains(\"core-popup\"))\n return true;\n if (element.parentElement && this.isInCorePopup(element.parentElement))\n return true;\n } else {\n // istanbul ignore else\n if (element.parentElement && this.isInCorePopup(element.parentElement))\n return true;\n }\n return false;\n }\n\n /** @internal */\n public onOutsideClick(e: MouseEvent) {\n // istanbul ignore else\n if (e.target instanceof Node && e.target.nodeType === Node.ELEMENT_NODE) {\n // istanbul ignore else\n if (\n !this.props.closeOnNestedPopupOutsideClick &&\n this.isInCorePopup(e.target as HTMLElement)\n )\n return;\n }\n\n if (this.props.onOutsideClick) return this.props.onOutsideClick(e);\n else if (defaultOnOutsideClick) return defaultOnOutsideClick(e);\n }\n\n /** @internal */\n public handleDocumentClick = (e: MouseEvent) => {\n if (\n !this.outsideClickContainerDiv ||\n !(e.target instanceof Node) ||\n this.outsideClickContainerDiv.contains(e.target)\n )\n return;\n\n return this.onOutsideClick(e);\n };\n\n /** @internal */\n public handleDocumentPointerDown = (e: PointerEvent) => {\n this.isDownOutside = true;\n // istanbul ignore else\n if (this.outsideClickContainerDiv) {\n // typically e.target test for instance of Node, but this is not working from pop out windows\n this.isDownOutside =\n !!e.target &&\n !this.outsideClickContainerDiv.contains(e.target as any);\n }\n };\n\n /** @internal */\n public handleDocumentPointerUp = (e: PointerEvent) => {\n let isUpOutside = true;\n // istanbul ignore else\n if (this.outsideClickContainerDiv) {\n // typically e.target test for instance of Node, but this is not working from pop out windows\n isUpOutside =\n !!e.target &&\n !this.outsideClickContainerDiv.contains(e.target as any);\n }\n\n const isOutsideClick = isUpOutside && this.isDownOutside;\n this.isDownOutside = false;\n isOutsideClick && this.onOutsideClick(e);\n };\n\n public handleOutsideClickContainerDivSet = (\n outsideClickContainerDiv: HTMLDivElement | null\n ) => {\n this.outsideClickContainerDiv = outsideClickContainerDiv;\n };\n\n public getParentDocument() {\n // istanbul ignore next\n return this.outsideClickContainerDiv?.ownerDocument ?? document;\n }\n\n public override componentDidMount() {\n const outsideClickParentDocument = this.getParentDocument();\n if (usePointerEvents) {\n outsideClickParentDocument.addEventListener(\n \"pointerdown\",\n this.handleDocumentPointerDown,\n useCapture\n );\n outsideClickParentDocument.addEventListener(\n \"pointerup\",\n this.handleDocumentPointerUp,\n useCapture\n );\n } else\n outsideClickParentDocument.addEventListener(\n \"click\",\n this.handleDocumentClick,\n useCapture\n );\n }\n\n /** @internal */\n public override componentWillUnmount() {\n const outsideClickParentDocument = this.getParentDocument();\n if (usePointerEvents) {\n outsideClickParentDocument.removeEventListener(\n \"pointerdown\",\n this.handleDocumentPointerDown,\n useCapture\n );\n outsideClickParentDocument.removeEventListener(\n \"pointerup\",\n this.handleDocumentPointerUp,\n useCapture\n );\n } else\n outsideClickParentDocument.removeEventListener(\n \"click\",\n this.handleDocumentClick,\n useCapture\n );\n }\n\n public override render() {\n const { onOutsideClick, closeOnNestedPopupOutsideClick, ...props } =\n this.props;\n return (\n <div ref={this.handleOutsideClickContainerDivSet}>\n <Component {...(props as ComponentProps)} />\n </div>\n );\n }\n };\n};\n"]}
|
|
@@ -32,7 +32,7 @@ function Icon(props) {
|
|
|
32
32
|
// the esm build of dompurify has a default import but the cjs build does not
|
|
33
33
|
// if there is a default export, use it (likely esm), otherwise use the namespace
|
|
34
34
|
// istanbul ignore next
|
|
35
|
-
const sanitizer = dompurify_1.default
|
|
35
|
+
const sanitizer = dompurify_1.default ?? DOMPurifyNS;
|
|
36
36
|
const sanitizerConfig = {
|
|
37
37
|
ALLOWED_TAGS: ["svg-loader"],
|
|
38
38
|
ADD_URI_SAFE_ATTR: webComponentString.startsWith("data:")
|