@itwin/core-react 4.13.2 → 4.13.3
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 +8 -1
- package/lib/cjs/core-react/UiCore.js +1 -1
- package/lib/cjs/core-react/UiCore.js.map +1 -1
- package/lib/cjs/core-react/autosuggest/AutoSuggest.js.map +1 -1
- package/lib/cjs/core-react/button/UnderlinedButton.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenu.js +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenu.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenuDirection.js +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenuDirection.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenuItem.js +1 -1
- package/lib/cjs/core-react/contextmenu/ContextMenuItem.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/ContextSubMenu.js +1 -1
- package/lib/cjs/core-react/contextmenu/ContextSubMenu.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/PopupContextMenu.js.map +1 -1
- package/lib/cjs/core-react/contextmenu/TildeFinder.js +1 -1
- package/lib/cjs/core-react/contextmenu/TildeFinder.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.map +1 -1
- package/lib/cjs/core-react/elementseparator/ElementSeparator.js.map +1 -1
- package/lib/cjs/core-react/enums/Alignment.js +2 -2
- package/lib/cjs/core-react/enums/Alignment.js.map +1 -1
- package/lib/cjs/core-react/enums/CheckBoxState.js +1 -1
- package/lib/cjs/core-react/enums/CheckBoxState.js.map +1 -1
- package/lib/cjs/core-react/enums/Orientation.js +1 -1
- package/lib/cjs/core-react/enums/Orientation.js.map +1 -1
- package/lib/cjs/core-react/enums/SortDirection.js +1 -1
- package/lib/cjs/core-react/enums/SortDirection.js.map +1 -1
- package/lib/cjs/core-react/enums/TimeFormat.js +1 -1
- package/lib/cjs/core-react/enums/TimeFormat.js.map +1 -1
- package/lib/cjs/core-react/expandable/ExpandableList.js +1 -1
- package/lib/cjs/core-react/expandable/ExpandableList.js.map +1 -1
- package/lib/cjs/core-react/focus/ItemKeyboardNavigator.js.map +1 -1
- package/lib/cjs/core-react/focustrap/FocusTrap.js.map +1 -1
- package/lib/cjs/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/cjs/core-react/icons/ConditionalIconItem.js.map +1 -1
- package/lib/cjs/core-react/icons/IconComponent.js.map +1 -1
- package/lib/cjs/core-react/imagecheckbox/ImageCheckBox.js.map +1 -1
- package/lib/cjs/core-react/inputs/Input.js.map +1 -1
- package/lib/cjs/core-react/inputs/InputStatus.js +1 -1
- package/lib/cjs/core-react/inputs/InputStatus.js.map +1 -1
- package/lib/cjs/core-react/inputs/numberinput/NumberInput.js.map +1 -1
- package/lib/cjs/core-react/l10n/usePackageTranslation.js.map +1 -1
- package/lib/cjs/core-react/l10n/useTranslation.js.map +1 -1
- package/lib/cjs/core-react/listbox/Listbox.js.map +1 -1
- package/lib/cjs/core-react/loading/LoadingBar.js +1 -1
- package/lib/cjs/core-react/loading/LoadingBar.js.map +1 -1
- package/lib/cjs/core-react/loading/LoadingPrompt.js +1 -1
- package/lib/cjs/core-react/loading/LoadingPrompt.js.map +1 -1
- package/lib/cjs/core-react/loading/LoadingSpinner.js +1 -1
- package/lib/cjs/core-react/loading/LoadingSpinner.js.map +1 -1
- package/lib/cjs/core-react/loading/LoadingStatus.js +1 -1
- package/lib/cjs/core-react/loading/LoadingStatus.js.map +1 -1
- package/lib/cjs/core-react/messagebox/MessageBox.js +1 -1
- package/lib/cjs/core-react/messagebox/MessageBox.js.map +1 -1
- package/lib/cjs/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/cjs/core-react/popup/Popup.js +1 -1
- package/lib/cjs/core-react/popup/Popup.js.map +1 -1
- package/lib/cjs/core-react/radialmenu/RadialMenu.js +2 -2
- package/lib/cjs/core-react/radialmenu/RadialMenu.js.map +1 -1
- package/lib/cjs/core-react/searchbox/SearchBox.js.map +1 -1
- package/lib/cjs/core-react/settings/SettingsContainer.js.map +1 -1
- package/lib/cjs/core-react/settings/SettingsManager.js.map +1 -1
- package/lib/cjs/core-react/tabs/Tabs.js.map +1 -1
- package/lib/cjs/core-react/text/FilteredText.js.map +1 -1
- package/lib/cjs/core-react/tree/Node.js.map +1 -1
- package/lib/cjs/core-react/tree/Tree.js.map +1 -1
- package/lib/cjs/core-react/uistate/UiStateEntry.js.map +1 -1
- package/lib/cjs/core-react/uistate/UiStateStorage.js +1 -1
- package/lib/cjs/core-react/uistate/UiStateStorage.js.map +1 -1
- package/lib/cjs/core-react/utils/IconHelper.js.map +1 -1
- package/lib/cjs/core-react/utils/IconWebComponent.js.map +1 -1
- package/lib/cjs/core-react/utils/Rectangle.js +1 -1
- package/lib/cjs/core-react/utils/Rectangle.js.map +1 -1
- package/lib/cjs/core-react/utils/ScrollPositionMaintainer.js.map +1 -1
- package/lib/cjs/core-react/utils/flattenChildren.js.map +1 -1
- package/lib/cjs/core-react/utils/getUserColor.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useDisposable.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useEffectSkipFirst.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useEventListener.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useInterval.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useLifecycleLogging.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useOnOutsideClick.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useProximityToMouse.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useRefs.js.map +1 -1
- package/lib/cjs/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/lib/cjs/core-react/utils/reuseOrCreatePromise.js.map +1 -1
- package/lib/cjs/core-react/utils/shallowDiffers.js.map +1 -1
- package/lib/esm/core-react/UiCore.js +1 -2
- package/lib/esm/core-react/UiCore.js.map +1 -1
- package/lib/esm/core-react/autosuggest/AutoSuggest.js.map +1 -1
- package/lib/esm/core-react/button/UnderlinedButton.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/ContextMenuItem.js +1 -2
- package/lib/esm/core-react/contextmenu/ContextMenuItem.js.map +1 -1
- package/lib/esm/core-react/contextmenu/ContextSubMenu.js +1 -2
- package/lib/esm/core-react/contextmenu/ContextSubMenu.js.map +1 -1
- package/lib/esm/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/esm/core-react/contextmenu/PopupContextMenu.js.map +1 -1
- package/lib/esm/core-react/contextmenu/TildeFinder.js +1 -2
- package/lib/esm/core-react/contextmenu/TildeFinder.js.map +1 -1
- package/lib/esm/core-react/dialog/Dialog.js +1 -2
- package/lib/esm/core-react/dialog/Dialog.js.map +1 -1
- package/lib/esm/core-react/dialog/GlobalDialog.js.map +1 -1
- package/lib/esm/core-react/elementseparator/ElementSeparator.js.map +1 -1
- package/lib/esm/core-react/expandable/ExpandableList.js +1 -2
- package/lib/esm/core-react/expandable/ExpandableList.js.map +1 -1
- package/lib/esm/core-react/focus/ItemKeyboardNavigator.js.map +1 -1
- package/lib/esm/core-react/focustrap/FocusTrap.js.map +1 -1
- package/lib/esm/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/esm/core-react/icons/ConditionalIconItem.js.map +1 -1
- package/lib/esm/core-react/icons/IconComponent.js.map +1 -1
- package/lib/esm/core-react/imagecheckbox/ImageCheckBox.js.map +1 -1
- package/lib/esm/core-react/inputs/Input.js.map +1 -1
- package/lib/esm/core-react/inputs/numberinput/NumberInput.js.map +1 -1
- package/lib/esm/core-react/l10n/usePackageTranslation.js.map +1 -1
- package/lib/esm/core-react/l10n/useTranslation.js.map +1 -1
- package/lib/esm/core-react/listbox/Listbox.js.map +1 -1
- package/lib/esm/core-react/loading/LoadingBar.js +1 -2
- package/lib/esm/core-react/loading/LoadingBar.js.map +1 -1
- package/lib/esm/core-react/loading/LoadingPrompt.js +1 -2
- package/lib/esm/core-react/loading/LoadingPrompt.js.map +1 -1
- package/lib/esm/core-react/loading/LoadingSpinner.js +1 -2
- package/lib/esm/core-react/loading/LoadingSpinner.js.map +1 -1
- package/lib/esm/core-react/loading/LoadingStatus.js +1 -2
- package/lib/esm/core-react/loading/LoadingStatus.js.map +1 -1
- package/lib/esm/core-react/messagebox/MessageBox.js +1 -2
- package/lib/esm/core-react/messagebox/MessageBox.js.map +1 -1
- package/lib/esm/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/esm/core-react/popup/Popup.js +1 -2
- package/lib/esm/core-react/popup/Popup.js.map +1 -1
- package/lib/esm/core-react/radialmenu/RadialMenu.js +2 -3
- package/lib/esm/core-react/radialmenu/RadialMenu.js.map +1 -1
- package/lib/esm/core-react/searchbox/SearchBox.js.map +1 -1
- package/lib/esm/core-react/settings/SettingsContainer.js.map +1 -1
- package/lib/esm/core-react/settings/SettingsManager.js.map +1 -1
- package/lib/esm/core-react/tabs/Tabs.js.map +1 -1
- package/lib/esm/core-react/text/FilteredText.js.map +1 -1
- package/lib/esm/core-react/tree/Node.js.map +1 -1
- package/lib/esm/core-react/tree/Tree.js.map +1 -1
- package/lib/esm/core-react/uistate/UiStateEntry.js.map +1 -1
- package/lib/esm/core-react/utils/IconHelper.js.map +1 -1
- package/lib/esm/core-react/utils/IconWebComponent.js.map +1 -1
- package/lib/esm/core-react/utils/Rectangle.js.map +1 -1
- package/lib/esm/core-react/utils/ScrollPositionMaintainer.js.map +1 -1
- package/lib/esm/core-react/utils/flattenChildren.js.map +1 -1
- package/lib/esm/core-react/utils/getUserColor.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useDisposable.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useEffectSkipFirst.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useEventListener.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useInterval.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useLifecycleLogging.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useOnOutsideClick.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useProximityToMouse.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useRefs.js.map +1 -1
- package/lib/esm/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/lib/esm/core-react/utils/reuseOrCreatePromise.js.map +1 -1
- package/lib/esm/core-react/utils/shallowDiffers.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementSeparator.js","sourceRoot":"","sources":["../../../../src/core-react/elementseparator/ElementSeparator.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAoCxD,SAAS,wBAAwB,CAC/B,WAAwB,EACxB,CAAoC;IAEpC,OAAO,WAAW,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACxE,CAA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C","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 { useTranslation } from \"../l10n/useTranslation\";\n\n/** Results returned by onRatioChanged callback for determining new ratio and whether the ratio was updated.\n * @public\n * @deprecated in 4.12.x. Interface used in a deprecated component {@link ElementSeparator}.\n */\nexport interface RatioChangeResult {\n ratio: number;\n}\n\n/** Properties of [[ElementSeparator]] React component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link ElementSeparator}.\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 // eslint-disable-next-line deprecation/deprecation\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}: // eslint-disable-next-line deprecation/deprecation\nElementSeparatorProps) => {\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 * @deprecated in 4.12.x. Basic components that need to be user-resized support this out of the box. Use {@link https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent pointer events} API to implement a custom resizer.\n */\n// eslint-disable-next-line deprecation/deprecation\nexport const ElementSeparator = (props: ElementSeparatorProps) => {\n const { translate } = useTranslation();\n\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={translate(\"elementSeparator.label\")}\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,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,WAAW,EACX,SAAS,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,GAAG,KAAK,CAAC,WAAW,CAAC;IACtC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,EAC1C,CAAC,WAAW,EAAE,aAAa,CAAC,CAC7B,CAAC;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,SAAS,CAAC,wBAAwB,CAAC,GAC/C,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module 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 { useTranslation } from \"../l10n/useTranslation\";\n\n/** Results returned by onRatioChanged callback for determining new ratio and whether the ratio was updated.\n * @public\n * @deprecated in 4.12.x. Interface used in a deprecated component {@link ElementSeparator}.\n */\nexport interface RatioChangeResult {\n ratio: number;\n}\n\n/** Properties of [[ElementSeparator]] React component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link ElementSeparator}.\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 // eslint-disable-next-line deprecation/deprecation\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}: // eslint-disable-next-line deprecation/deprecation\nElementSeparatorProps) => {\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 * @deprecated in 4.12.x. Basic components that need to be user-resized support this out of the box. Use {@link https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent pointer events} API to implement a custom resizer.\n */\n// eslint-disable-next-line deprecation/deprecation\nexport const ElementSeparator = (props: ElementSeparatorProps) => {\n const { translate } = useTranslation();\n\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={translate(\"elementSeparator.label\")}\n />\n );\n};\n"]}
|
|
@@ -11,7 +11,7 @@ import * as React from "react";
|
|
|
11
11
|
* @public
|
|
12
12
|
* @deprecated in 4.12.x. Use a custom container and manage {@link https://itwinui.bentley.com/docs/expandableblock expandable block} state manually.
|
|
13
13
|
*/
|
|
14
|
-
class ExpandableList extends React.PureComponent {
|
|
14
|
+
export class ExpandableList extends React.PureComponent {
|
|
15
15
|
// eslint-disable-next-line deprecation/deprecation
|
|
16
16
|
constructor(props) {
|
|
17
17
|
super(props);
|
|
@@ -56,5 +56,4 @@ ExpandableList.defaultProps = {
|
|
|
56
56
|
singleExpandOnly: false,
|
|
57
57
|
defaultActiveBlock: 0,
|
|
58
58
|
};
|
|
59
|
-
export { ExpandableList };
|
|
60
59
|
//# sourceMappingURL=ExpandableList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpandableList.js","sourceRoot":"","sources":["../../../../src/core-react/expandable/ExpandableList.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"ExpandableList.js","sourceRoot":"","sources":["../../../../src/core-react/expandable/ExpandableList.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAsB/B;;;GAGG;AACH,MAAM,OAAO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AkB,CAAC,SAA8B;QAC/D,IACE,IAAI,CAAC,KAAK,CAAC,kBAAkB,KAAK,SAAS,CAAC,kBAAkB;YAC9D,IAAI,CAAC,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAAC,KAAK,CAAC,WAAW,EACxD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,kBAAmB,EAAE,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAEe,MAAM;QACpB,OAAO,CACL,6BACE,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,IAAI,CAAC,KAAK,CAAC,SAAS,CACrB,EACD,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAEtB,IAAI,CAAC,YAAY,EAAE,CAChB,CACP,CAAC;IACJ,CAAC;;AA3DD,mDAAmD;AACrC,2BAAY,GAAiC;IACzD,gBAAgB,EAAE,KAAK;IACvB,kBAAkB,EAAE,CAAC;CACtB,AAHyB,CAGxB","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 Expandable\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"../utils/Props\";\n\n/** Properties for [[ExpandableList]] component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link ExpandableList}.\n */\nexport interface ExpandableListProps extends CommonProps {\n /** Index of the default active block */\n defaultActiveBlock?: number;\n /** Indicates whether to allow only one expanded block */\n singleExpandOnly?: boolean;\n /** Indicates whether the single expanded block is collapsible */\n singleIsCollapsible?: boolean;\n /** Content */\n children?: React.ReactNode;\n}\n\ninterface ExpandableListState {\n activeBlock: number;\n}\n\n/** ExpandableList React component is a container for ExpandableBlock components.\n * @public\n * @deprecated in 4.12.x. Use a custom container and manage {@link https://itwinui.bentley.com/docs/expandableblock expandable block} state manually.\n */\nexport class ExpandableList extends React.PureComponent<\n // eslint-disable-next-line deprecation/deprecation\n ExpandableListProps,\n ExpandableListState\n> {\n // eslint-disable-next-line deprecation/deprecation\n constructor(props: ExpandableListProps) {\n super(props);\n\n this.state = { activeBlock: this.props.defaultActiveBlock! };\n }\n\n // eslint-disable-next-line deprecation/deprecation\n public static defaultProps: Partial<ExpandableListProps> = {\n singleExpandOnly: false,\n defaultActiveBlock: 0,\n };\n\n // set active block\n private _handleBlockToggle = (\n index: number,\n onToggle: (isExpanding: boolean) => any\n ) => {\n let activeBlock = index;\n\n if (this.props.singleIsCollapsible && index === this.state.activeBlock)\n activeBlock = -1;\n\n this.setState({ activeBlock });\n\n // istanbul ignore else\n if (onToggle) {\n onToggle(activeBlock === index); // fire the ExpandableBlock onToggle\n }\n };\n\n private renderBlocks() {\n return React.Children.map(this.props.children, (child: any, i) => {\n return React.cloneElement(child, {\n key: i,\n isExpanded: this.props.singleExpandOnly\n ? i === this.state.activeBlock\n : child.props.isExpanded,\n onToggle: this._handleBlockToggle.bind(this, i, child.props.onToggle),\n });\n });\n }\n\n /** @internal */\n // eslint-disable-next-line deprecation/deprecation\n public override componentDidUpdate(prevProps: ExpandableListProps) {\n if (\n this.props.defaultActiveBlock !== prevProps.defaultActiveBlock &&\n this.props.defaultActiveBlock !== this.state.activeBlock\n ) {\n this.setState((_, props) => ({ activeBlock: props.defaultActiveBlock! }));\n }\n }\n\n public override render(): React.ReactElement {\n return (\n <div\n className={classnames(\n \"uicore-expandable-blocks-list\",\n this.props.className\n )}\n style={this.props.style}\n >\n {this.renderBlocks()}\n </div>\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemKeyboardNavigator.js","sourceRoot":"","sources":["../../../../src/core-react/focus/ItemKeyboardNavigator.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,O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AACJ,CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,CACL,GAAG,KAAK,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE;QAC/B,GAAG,KAAK,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;QAChC,GAAG,KAAK,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,GAAG,KAAK,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAChC,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Focus\n */\n\nimport { Key } from \"ts-key-enum\";\nimport { Orientation } from \"../enums/Orientation\";\n\n/** Cross-Axis Arrow Key Callback\n * @internal\n */\nexport type CrossAxisArrowKeyFunc = (forward: boolean) => void;\n\n/** Keyboard Navigator for parent components\n * @internal\n */\nexport class ItemKeyboardNavigator {\n private _direction: Map<string, number>;\n private _itemCount = 0;\n private _orientation = Orientation.Horizontal;\n private _allowWrap = true;\n private _crossAxisArrowKeyHandler?: CrossAxisArrowKeyFunc;\n\n constructor(\n public onFocusItem: (index: number) => void,\n public onActivateItem: (index: number) => void\n ) {\n this._direction = new Map<string, number>([\n [Key.ArrowLeft, -1],\n [Key.ArrowUp, -1],\n [Key.ArrowRight, 1],\n [Key.ArrowDown, 1],\n ]);\n }\n\n /** The item count */\n public get itemCount(): number {\n return this._itemCount;\n }\n public set itemCount(count: number) {\n this._itemCount = count;\n }\n\n /** The primary orientation */\n public get orientation(): Orientation {\n return this._orientation;\n }\n public set orientation(orientation: Orientation) {\n this._orientation = orientation;\n }\n\n /** The allow wrap property controls whether the movement will stop at the first and last items or wrap */\n public get allowWrap(): boolean {\n return this._allowWrap;\n }\n public set allowWrap(v: boolean) {\n this._allowWrap = v;\n }\n\n /** Called when the arrow keys that run perpendicular to the primary orientation are pressed */\n public get crossAxisArrowKeyHandler(): CrossAxisArrowKeyFunc | undefined {\n return this._crossAxisArrowKeyHandler;\n }\n public set crossAxisArrowKeyHandler(v: CrossAxisArrowKeyFunc | undefined) {\n this._crossAxisArrowKeyHandler = v;\n }\n\n /** Handle KeyDown on items */\n public handleKeyDownEvent(event: React.KeyboardEvent, index: number): void {\n const key = event.key;\n\n switch (key) {\n case Key.Home.valueOf():\n event.preventDefault();\n // Activate first item\n this.focusFirstItem();\n break;\n case Key.End.valueOf():\n event.preventDefault();\n // Activate last item\n this.focusLastItem();\n break;\n\n // Up and down are in keydown\n // because we need to prevent page scroll >:)\n case Key.ArrowUp.valueOf():\n case Key.ArrowDown.valueOf():\n this.determineOrientation(event, index);\n break;\n\n case Key.Enter.valueOf():\n case \" \":\n this.activateItem(index);\n break;\n }\n }\n\n /** Handle KeyUp on items */\n public handleKeyUpEvent(event: React.KeyboardEvent, index: number): void {\n const key = event.key;\n\n switch (key) {\n case Key.ArrowLeft.valueOf():\n case Key.ArrowRight.valueOf():\n this.determineOrientation(event, index);\n break;\n }\n }\n\n private focusFirstItem(): void {\n this.onFocusItem(0);\n }\n\n private focusLastItem(): void {\n const index = this._itemCount - 1;\n this.onFocusItem(index);\n }\n\n /** When an item list's orientation is set to vertical,\n * only up and down arrow should function.\n * In all other cases only left and right arrow function.\n */\n private determineOrientation(\n event: React.KeyboardEvent,\n index: number\n ): void {\n const key = event.key;\n const vertical = this._orientation === Orientation.Vertical;\n let proceed = false;\n\n if (vertical) {\n if (key === Key.ArrowUp.valueOf() || key === Key.ArrowDown.valueOf()) {\n event.preventDefault();\n proceed = true;\n } else if (\n this.crossAxisArrowKeyHandler &&\n (key === Key.ArrowLeft.valueOf() || key === Key.ArrowRight.valueOf())\n ) {\n this.crossAxisArrowKeyHandler(key === Key.ArrowRight.valueOf());\n }\n } else {\n if (key === Key.ArrowLeft.valueOf() || key === Key.ArrowRight.valueOf()) {\n proceed = true;\n } else if (\n this.crossAxisArrowKeyHandler &&\n (key === Key.ArrowUp.valueOf() || key === Key.ArrowDown.valueOf())\n ) {\n this.crossAxisArrowKeyHandler(key === Key.ArrowDown.valueOf());\n }\n }\n\n if (proceed) {\n this.switchItemOnArrowPress(event, index);\n }\n }\n\n /** Either focus the next, previous, first, or last item depending on key pressed\n */\n private switchItemOnArrowPress(\n event: React.KeyboardEvent,\n index: number\n ): void {\n // Add or subtract depending on key pressed\n const pressed = event.key;\n const targetDirection = this._direction.get(pressed);\n\n // istanbul ignore else\n if (targetDirection) {\n const newIndex = index + targetDirection;\n\n if (0 <= newIndex && newIndex < this._itemCount) {\n this.onFocusItem(newIndex);\n } else {\n // istanbul ignore else\n if (this._allowWrap) {\n if (\n pressed === Key.ArrowLeft.valueOf() ||\n pressed === Key.ArrowUp.valueOf()\n ) {\n this.focusLastItem();\n } else {\n this.focusFirstItem();\n }\n }\n }\n }\n }\n\n private activateItem(index: number): void {\n this.onActivateItem(index);\n }\n}\n\n/** Determines if a KeyboardEvent.key is an Item Navigation key\n * @internal\n */\nexport function isNavigationKey(key: string): boolean {\n return (\n isArrowKey(key) ||\n key === Key.Home.valueOf() ||\n key === Key.End.valueOf() ||\n key === \" \" ||\n key === Key.Enter.valueOf()\n );\n}\n\nfunction isArrowKey(key: string): boolean {\n return (\n key === Key.ArrowLeft.valueOf() ||\n key === Key.ArrowRight.valueOf() ||\n key === Key.ArrowUp.valueOf() ||\n key === Key.ArrowDown.valueOf()\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ItemKeyboardNavigator.js","sourceRoot":"","sources":["../../../../src/core-react/focus/ItemKeyboardNavigator.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAOnD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAOhC,YACS,WAAoC,EACpC,cAAuC;QADvC,gBAAW,GAAX,WAAW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CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,CACL,GAAG,KAAK,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE;QAC/B,GAAG,KAAK,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;QAChC,GAAG,KAAK,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,GAAG,KAAK,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAChC,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Focus\n */\n\nimport { Key } from \"ts-key-enum\";\nimport { Orientation } from \"../enums/Orientation\";\n\n/** Cross-Axis Arrow Key Callback\n * @internal\n */\nexport type CrossAxisArrowKeyFunc = (forward: boolean) => void;\n\n/** Keyboard Navigator for parent components\n * @internal\n */\nexport class ItemKeyboardNavigator {\n private _direction: Map<string, number>;\n private _itemCount = 0;\n private _orientation = Orientation.Horizontal;\n private _allowWrap = true;\n private _crossAxisArrowKeyHandler?: CrossAxisArrowKeyFunc;\n\n constructor(\n public onFocusItem: (index: number) => void,\n public onActivateItem: (index: number) => void\n ) {\n this._direction = new Map<string, number>([\n [Key.ArrowLeft, -1],\n [Key.ArrowUp, -1],\n [Key.ArrowRight, 1],\n [Key.ArrowDown, 1],\n ]);\n }\n\n /** The item count */\n public get itemCount(): number {\n return this._itemCount;\n }\n public set itemCount(count: number) {\n this._itemCount = count;\n }\n\n /** The primary orientation */\n public get orientation(): Orientation {\n return this._orientation;\n }\n public set orientation(orientation: Orientation) {\n this._orientation = orientation;\n }\n\n /** The allow wrap property controls whether the movement will stop at the first and last items or wrap */\n public get allowWrap(): boolean {\n return this._allowWrap;\n }\n public set allowWrap(v: boolean) {\n this._allowWrap = v;\n }\n\n /** Called when the arrow keys that run perpendicular to the primary orientation are pressed */\n public get crossAxisArrowKeyHandler(): CrossAxisArrowKeyFunc | undefined {\n return this._crossAxisArrowKeyHandler;\n }\n public set crossAxisArrowKeyHandler(v: CrossAxisArrowKeyFunc | undefined) {\n this._crossAxisArrowKeyHandler = v;\n }\n\n /** Handle KeyDown on items */\n public handleKeyDownEvent(event: React.KeyboardEvent, index: number): void {\n const key = event.key;\n\n switch (key) {\n case Key.Home.valueOf():\n event.preventDefault();\n // Activate first item\n this.focusFirstItem();\n break;\n case Key.End.valueOf():\n event.preventDefault();\n // Activate last item\n this.focusLastItem();\n break;\n\n // Up and down are in keydown\n // because we need to prevent page scroll >:)\n case Key.ArrowUp.valueOf():\n case Key.ArrowDown.valueOf():\n this.determineOrientation(event, index);\n break;\n\n case Key.Enter.valueOf():\n case \" \":\n this.activateItem(index);\n break;\n }\n }\n\n /** Handle KeyUp on items */\n public handleKeyUpEvent(event: React.KeyboardEvent, index: number): void {\n const key = event.key;\n\n switch (key) {\n case Key.ArrowLeft.valueOf():\n case Key.ArrowRight.valueOf():\n this.determineOrientation(event, index);\n break;\n }\n }\n\n private focusFirstItem(): void {\n this.onFocusItem(0);\n }\n\n private focusLastItem(): void {\n const index = this._itemCount - 1;\n this.onFocusItem(index);\n }\n\n /** When an item list's orientation is set to vertical,\n * only up and down arrow should function.\n * In all other cases only left and right arrow function.\n */\n private determineOrientation(\n event: React.KeyboardEvent,\n index: number\n ): void {\n const key = event.key;\n const vertical = this._orientation === Orientation.Vertical;\n let proceed = false;\n\n if (vertical) {\n if (key === Key.ArrowUp.valueOf() || key === Key.ArrowDown.valueOf()) {\n event.preventDefault();\n proceed = true;\n } else if (\n this.crossAxisArrowKeyHandler &&\n (key === Key.ArrowLeft.valueOf() || key === Key.ArrowRight.valueOf())\n ) {\n this.crossAxisArrowKeyHandler(key === Key.ArrowRight.valueOf());\n }\n } else {\n if (key === Key.ArrowLeft.valueOf() || key === Key.ArrowRight.valueOf()) {\n proceed = true;\n } else if (\n this.crossAxisArrowKeyHandler &&\n (key === Key.ArrowUp.valueOf() || key === Key.ArrowDown.valueOf())\n ) {\n this.crossAxisArrowKeyHandler(key === Key.ArrowDown.valueOf());\n }\n }\n\n if (proceed) {\n this.switchItemOnArrowPress(event, index);\n }\n }\n\n /** Either focus the next, previous, first, or last item depending on key pressed\n */\n private switchItemOnArrowPress(\n event: React.KeyboardEvent,\n index: number\n ): void {\n // Add or subtract depending on key pressed\n const pressed = event.key;\n const targetDirection = this._direction.get(pressed);\n\n // istanbul ignore else\n if (targetDirection) {\n const newIndex = index + targetDirection;\n\n if (0 <= newIndex && newIndex < this._itemCount) {\n this.onFocusItem(newIndex);\n } else {\n // istanbul ignore else\n if (this._allowWrap) {\n if (\n pressed === Key.ArrowLeft.valueOf() ||\n pressed === Key.ArrowUp.valueOf()\n ) {\n this.focusLastItem();\n } else {\n this.focusFirstItem();\n }\n }\n }\n }\n }\n\n private activateItem(index: number): void {\n this.onActivateItem(index);\n }\n}\n\n/** Determines if a KeyboardEvent.key is an Item Navigation key\n * @internal\n */\nexport function isNavigationKey(key: string): boolean {\n return (\n isArrowKey(key) ||\n key === Key.Home.valueOf() ||\n key === Key.End.valueOf() ||\n key === \" \" ||\n key === Key.Enter.valueOf()\n );\n}\n\nfunction isArrowKey(key: string): boolean {\n return (\n key === Key.ArrowLeft.valueOf() ||\n key === Key.ArrowRight.valueOf() ||\n key === Key.ArrowUp.valueOf() ||\n key === Key.ArrowDown.valueOf()\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusTrap.js","sourceRoot":"","sources":["../../../../src/core-react/focustrap/FocusTrap.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,0BAA0B;AAE1B,SAAS,WAAW,CAAC,OAAoB;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AO,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,IAEnE,KAAK,CAAC,QAAQ,CACX;QACN,4CACc,sBAAsB,EAClC,OAAO,EAAE,iBAAiB;YAC1B,kEAAkE;YAClE,QAAQ,EAAE,CAAC,GACX,CACD,CACJ,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Popup\n */\n\nimport * as React from \"react\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { UiCore } from \"../UiCore\";\n\n// cSpell:ignore focusable\n\nfunction isFocusable(element: HTMLElement): boolean {\n if (!element || element.tabIndex < 0) return false;\n\n if (\n element.classList &&\n element.classList.contains(\"core-focus-trap-ignore-initial\")\n )\n return false;\n\n if (\n element.getAttribute &&\n typeof element.getAttribute === \"function\" &&\n element.getAttribute(\"disabled\") !== null\n )\n return false;\n\n if (\n element.tabIndex > 0 ||\n (element.tabIndex === 0 && element.getAttribute(\"tabIndex\") !== null)\n )\n return true;\n\n switch (element.nodeName) {\n case \"A\":\n const anchorElement = element as HTMLAnchorElement;\n return !!anchorElement.href && anchorElement.rel !== \"ignore\";\n case \"INPUT\":\n const inputElement = element as HTMLInputElement;\n return inputElement.type !== \"hidden\" && inputElement.type !== \"file\";\n case \"BUTTON\":\n case \"SELECT\":\n case \"TEXTAREA\":\n return true;\n default:\n return false;\n }\n}\n\nfunction processFindFocusableDescendant(\n element: HTMLElement | null\n): HTMLElement | null {\n // istanbul ignore next\n if (!element) return null;\n\n for (const child of element.childNodes) {\n // istanbul ignore else\n if (isFocusable(child as HTMLElement)) return child as HTMLElement;\n\n const focusable = processFindFocusableDescendant(child as HTMLElement);\n if (focusable) return focusable;\n }\n return null;\n}\n\nfunction findFirstFocusableDescendant(\n focusContainer: HTMLDivElement | null\n): HTMLElement | null {\n return processFindFocusableDescendant(focusContainer);\n}\n\nfunction processFindLastFocusableDescendant(\n element: HTMLElement\n): HTMLElement | null {\n for (let i = element.childNodes.length - 1; i >= 0; i--) {\n const child = element.childNodes[i] as HTMLElement;\n\n const focusable = processFindLastFocusableDescendant(child);\n // istanbul ignore else\n if (focusable) return focusable;\n\n // istanbul ignore else\n if (isFocusable(child)) return child;\n }\n return null;\n}\n\nfunction findLastFocusableDescendant(\n focusContainer: HTMLDivElement\n): HTMLElement | null {\n return processFindLastFocusableDescendant(focusContainer);\n}\n\nfunction getInitialFocusElement(\n focusContainer: HTMLDivElement | null,\n initialFocusSpec: React.RefObject<HTMLElement> | string | undefined\n): HTMLElement | null {\n // istanbul ignore next\n if (!focusContainer) return null;\n\n if (initialFocusSpec) {\n if (typeof initialFocusSpec === \"string\") {\n const node = focusContainer.querySelector(initialFocusSpec);\n if (node) {\n return node as HTMLElement;\n } else {\n Logger.logError(\n `${UiCore.packageName}.FocusTrap`,\n `Unable to locate element via selector ${initialFocusSpec}`\n );\n }\n } else {\n return initialFocusSpec.current;\n }\n }\n return findFirstFocusableDescendant(focusContainer);\n}\n\nfunction attemptFocus(element: HTMLElement, preventScroll: boolean): boolean {\n // istanbul ignore next\n if (!isFocusable(element)) return false;\n\n try {\n // istanbul ignore else\n if (document.activeElement !== element)\n element.focus({\n preventScroll: preventScroll ? true : /* istanbul ignore next */ false,\n });\n } catch (e) {\n // istanbul ignore next\n return false;\n }\n return document.activeElement === element;\n} // end attemptFocus\n\n/** Focus into first focusable element of a container.\n * @internal\n */\nexport function focusIntoContainer(\n focusContainer: HTMLDivElement,\n initialFocusElement?: React.RefObject<HTMLElement> | string\n): boolean {\n let result = false;\n const focusElement = getInitialFocusElement(\n focusContainer,\n initialFocusElement\n );\n if (focusElement) {\n // delay setting focus immediately because in some browsers other focus events happen when popup is initially opened.\n setTimeout(() => {\n attemptFocus(focusElement, true);\n }, 60);\n result = true;\n }\n return result;\n}\n\n/** Properties supported by [[FocusTrap]] component.\n * @internal\n */\nexport interface FocusTrapProps extends React.AllHTMLAttributes<any> {\n /** child components */\n children: React.ReactNode;\n /** if active is not true then no trapping of focus is attempted. */\n active?: boolean;\n /** restore focus to element that had focus before trap was activated */\n returnFocusOnDeactivate: boolean;\n /** Optional reference to element to receive focus when trap is activated. Optionally a CSS Selector\n * string can be supplied to locate an element in the FocusTrap container. If no specification is defined\n * the first focusable element is used.\n */\n initialFocusElement?: React.RefObject<HTMLElement> | string;\n}\n\n/** Trap Focus in container while trap is active.\n * @internal\n */\nexport function FocusTrap(props: FocusTrapProps) {\n const restoreFocusElement = React.useRef<Element | null>(null);\n const initialFocusElement = React.useRef<Element | null>(null);\n const focusContainer = React.useRef<HTMLDivElement | null>(null);\n const isInitialMount = React.useRef(true);\n const timeoutRef = React.useRef<number | undefined>();\n\n // Run on initial mount and when dependencies change. which could happen often.\n React.useEffect(() => {\n // istanbul ignore else\n if (isInitialMount.current) {\n isInitialMount.current = false;\n if (props.active) {\n if (props.returnFocusOnDeactivate) {\n restoreFocusElement.current = document.activeElement;\n }\n\n initialFocusElement.current = getInitialFocusElement(\n focusContainer.current,\n props.initialFocusElement\n );\n if (initialFocusElement.current) {\n // delay setting focus immediately because in some browsers other focus events happen when popup is initially opened.\n timeoutRef.current = window.setTimeout(() => {\n attemptFocus(initialFocusElement.current as HTMLElement, true);\n }, 60);\n }\n }\n }\n }, [\n props.children,\n props.initialFocusElement,\n props.active,\n props.returnFocusOnDeactivate,\n ]);\n\n // Return function to run only when FocusTrap is unmounted to restore focus\n React.useEffect(() => {\n return () => {\n window.clearTimeout(timeoutRef.current);\n if (restoreFocusElement.current)\n (restoreFocusElement.current as HTMLElement).focus({\n preventScroll: true,\n });\n };\n }, []);\n\n // this is hit if Shift tab is used.\n const cycleFocusToEnd = React.useCallback(\n (event: React.FocusEvent<HTMLDivElement>) => {\n // istanbul ignore next\n if (!props.active) return;\n\n if (focusContainer.current && event.target === focusContainer.current) {\n event.stopPropagation();\n event.preventDefault();\n const focusable = findLastFocusableDescendant(focusContainer.current);\n\n // istanbul ignore else\n if (focusable) {\n focusable.focus();\n } else {\n if (\n initialFocusElement.current &&\n initialFocusElement.current !== document.activeElement\n )\n attemptFocus(initialFocusElement.current as HTMLElement, true);\n }\n }\n },\n [props.active]\n );\n\n // this is hit if tab is used on last focusable item in child container.\n const cycleFocusToStart = React.useCallback(\n (event: React.FocusEvent<HTMLDivElement>) => {\n // istanbul ignore next\n if (!props.active) return;\n\n event.stopPropagation();\n // istanbul ignore else\n if (\n initialFocusElement.current &&\n initialFocusElement.current !== document.activeElement\n )\n (initialFocusElement.current as HTMLElement).focus();\n },\n [props.active]\n );\n\n if (!props.children) return null;\n return (\n <>\n <div\n data-testid=\"focus-trap-div\"\n onFocus={cycleFocusToEnd}\n ref={focusContainer}\n /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */\n tabIndex={0}\n style={{ outline: \"none\", WebkitTapHighlightColor: \"rgba(0,0,0,0)\" }}\n >\n {props.children}\n </div>\n <div\n data-testid=\"focus-trap-limit-div\"\n onFocus={cycleFocusToStart}\n /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */\n tabIndex={0}\n />\n </>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FocusTrap.js","sourceRoot":"","sources":["../../../../src/core-react/focustrap/FocusTrap.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,0BAA0B;AAE1B,SAAS,WAAW,CAAC,OAAoB;IACvC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAEnD,IACE,OAAO,CAAC,SAAS;QACjB,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,gCAAgC,CAAC;Q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AAQ,EAAE,CAAC,EACX,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,IAEnE,KAAK,CAAC,QAAQ,CACX;QACN,4CACc,sBAAsB,EAClC,OAAO,EAAE,iBAAiB;YAC1B,kEAAkE;YAClE,QAAQ,EAAE,CAAC,GACX,CACD,CACJ,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Popup\n */\n\nimport * as React from \"react\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { UiCore } from \"../UiCore\";\n\n// cSpell:ignore focusable\n\nfunction isFocusable(element: HTMLElement): boolean {\n if (!element || element.tabIndex < 0) return false;\n\n if (\n element.classList &&\n element.classList.contains(\"core-focus-trap-ignore-initial\")\n )\n return false;\n\n if (\n element.getAttribute &&\n typeof element.getAttribute === \"function\" &&\n element.getAttribute(\"disabled\") !== null\n )\n return false;\n\n if (\n element.tabIndex > 0 ||\n (element.tabIndex === 0 && element.getAttribute(\"tabIndex\") !== null)\n )\n return true;\n\n switch (element.nodeName) {\n case \"A\":\n const anchorElement = element as HTMLAnchorElement;\n return !!anchorElement.href && anchorElement.rel !== \"ignore\";\n case \"INPUT\":\n const inputElement = element as HTMLInputElement;\n return inputElement.type !== \"hidden\" && inputElement.type !== \"file\";\n case \"BUTTON\":\n case \"SELECT\":\n case \"TEXTAREA\":\n return true;\n default:\n return false;\n }\n}\n\nfunction processFindFocusableDescendant(\n element: HTMLElement | null\n): HTMLElement | null {\n // istanbul ignore next\n if (!element) return null;\n\n for (const child of element.childNodes) {\n // istanbul ignore else\n if (isFocusable(child as HTMLElement)) return child as HTMLElement;\n\n const focusable = processFindFocusableDescendant(child as HTMLElement);\n if (focusable) return focusable;\n }\n return null;\n}\n\nfunction findFirstFocusableDescendant(\n focusContainer: HTMLDivElement | null\n): HTMLElement | null {\n return processFindFocusableDescendant(focusContainer);\n}\n\nfunction processFindLastFocusableDescendant(\n element: HTMLElement\n): HTMLElement | null {\n for (let i = element.childNodes.length - 1; i >= 0; i--) {\n const child = element.childNodes[i] as HTMLElement;\n\n const focusable = processFindLastFocusableDescendant(child);\n // istanbul ignore else\n if (focusable) return focusable;\n\n // istanbul ignore else\n if (isFocusable(child)) return child;\n }\n return null;\n}\n\nfunction findLastFocusableDescendant(\n focusContainer: HTMLDivElement\n): HTMLElement | null {\n return processFindLastFocusableDescendant(focusContainer);\n}\n\nfunction getInitialFocusElement(\n focusContainer: HTMLDivElement | null,\n initialFocusSpec: React.RefObject<HTMLElement> | string | undefined\n): HTMLElement | null {\n // istanbul ignore next\n if (!focusContainer) return null;\n\n if (initialFocusSpec) {\n if (typeof initialFocusSpec === \"string\") {\n const node = focusContainer.querySelector(initialFocusSpec);\n if (node) {\n return node as HTMLElement;\n } else {\n Logger.logError(\n `${UiCore.packageName}.FocusTrap`,\n `Unable to locate element via selector ${initialFocusSpec}`\n );\n }\n } else {\n return initialFocusSpec.current;\n }\n }\n return findFirstFocusableDescendant(focusContainer);\n}\n\nfunction attemptFocus(element: HTMLElement, preventScroll: boolean): boolean {\n // istanbul ignore next\n if (!isFocusable(element)) return false;\n\n try {\n // istanbul ignore else\n if (document.activeElement !== element)\n element.focus({\n preventScroll: preventScroll ? true : /* istanbul ignore next */ false,\n });\n } catch (e) {\n // istanbul ignore next\n return false;\n }\n return document.activeElement === element;\n} // end attemptFocus\n\n/** Focus into first focusable element of a container.\n * @internal\n */\nexport function focusIntoContainer(\n focusContainer: HTMLDivElement,\n initialFocusElement?: React.RefObject<HTMLElement> | string\n): boolean {\n let result = false;\n const focusElement = getInitialFocusElement(\n focusContainer,\n initialFocusElement\n );\n if (focusElement) {\n // delay setting focus immediately because in some browsers other focus events happen when popup is initially opened.\n setTimeout(() => {\n attemptFocus(focusElement, true);\n }, 60);\n result = true;\n }\n return result;\n}\n\n/** Properties supported by [[FocusTrap]] component.\n * @internal\n */\nexport interface FocusTrapProps extends React.AllHTMLAttributes<any> {\n /** child components */\n children: React.ReactNode;\n /** if active is not true then no trapping of focus is attempted. */\n active?: boolean;\n /** restore focus to element that had focus before trap was activated */\n returnFocusOnDeactivate: boolean;\n /** Optional reference to element to receive focus when trap is activated. Optionally a CSS Selector\n * string can be supplied to locate an element in the FocusTrap container. If no specification is defined\n * the first focusable element is used.\n */\n initialFocusElement?: React.RefObject<HTMLElement> | string;\n}\n\n/** Trap Focus in container while trap is active.\n * @internal\n */\nexport function FocusTrap(props: FocusTrapProps) {\n const restoreFocusElement = React.useRef<Element | null>(null);\n const initialFocusElement = React.useRef<Element | null>(null);\n const focusContainer = React.useRef<HTMLDivElement | null>(null);\n const isInitialMount = React.useRef(true);\n const timeoutRef = React.useRef<number | undefined>();\n\n // Run on initial mount and when dependencies change. which could happen often.\n React.useEffect(() => {\n // istanbul ignore else\n if (isInitialMount.current) {\n isInitialMount.current = false;\n if (props.active) {\n if (props.returnFocusOnDeactivate) {\n restoreFocusElement.current = document.activeElement;\n }\n\n initialFocusElement.current = getInitialFocusElement(\n focusContainer.current,\n props.initialFocusElement\n );\n if (initialFocusElement.current) {\n // delay setting focus immediately because in some browsers other focus events happen when popup is initially opened.\n timeoutRef.current = window.setTimeout(() => {\n attemptFocus(initialFocusElement.current as HTMLElement, true);\n }, 60);\n }\n }\n }\n }, [\n props.children,\n props.initialFocusElement,\n props.active,\n props.returnFocusOnDeactivate,\n ]);\n\n // Return function to run only when FocusTrap is unmounted to restore focus\n React.useEffect(() => {\n return () => {\n window.clearTimeout(timeoutRef.current);\n if (restoreFocusElement.current)\n (restoreFocusElement.current as HTMLElement).focus({\n preventScroll: true,\n });\n };\n }, []);\n\n // this is hit if Shift tab is used.\n const cycleFocusToEnd = React.useCallback(\n (event: React.FocusEvent<HTMLDivElement>) => {\n // istanbul ignore next\n if (!props.active) return;\n\n if (focusContainer.current && event.target === focusContainer.current) {\n event.stopPropagation();\n event.preventDefault();\n const focusable = findLastFocusableDescendant(focusContainer.current);\n\n // istanbul ignore else\n if (focusable) {\n focusable.focus();\n } else {\n if (\n initialFocusElement.current &&\n initialFocusElement.current !== document.activeElement\n )\n attemptFocus(initialFocusElement.current as HTMLElement, true);\n }\n }\n },\n [props.active]\n );\n\n // this is hit if tab is used on last focusable item in child container.\n const cycleFocusToStart = React.useCallback(\n (event: React.FocusEvent<HTMLDivElement>) => {\n // istanbul ignore next\n if (!props.active) return;\n\n event.stopPropagation();\n // istanbul ignore else\n if (\n initialFocusElement.current &&\n initialFocusElement.current !== document.activeElement\n )\n (initialFocusElement.current as HTMLElement).focus();\n },\n [props.active]\n );\n\n if (!props.children) return null;\n return (\n <>\n <div\n data-testid=\"focus-trap-div\"\n onFocus={cycleFocusToEnd}\n ref={focusContainer}\n /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */\n tabIndex={0}\n style={{ outline: \"none\", WebkitTapHighlightColor: \"rgba(0,0,0,0)\" }}\n >\n {props.children}\n </div>\n <div\n data-testid=\"focus-trap-limit-div\"\n onFocus={cycleFocusToStart}\n /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */\n tabIndex={0}\n />\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withOnOutsideClick.js","sourceRoot":"","sources":["../../../../src/core-react/hocs/withOnOutsideClick.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAY/B;;GAEG;AACH,MAAM,CAAC,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,gBAAg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;;gBACC,0BAA0B,CAAC,gBAAgB,CACzC,OAAO,EACP,IAAI,CAAC,mBAAmB,EACxB,UAAU,CACX,CAAC;QACN,CAAC;QAED,gBAAgB;QACA,oBAAoB;YAClC,MAAM,0BAA0B,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5D,IAAI,gBAAgB,EAAE,CAAC;gBACrB,0BAA0B,CAAC,mBAAmB,CAC5C,aAAa,EACb,IAAI,CAAC,yBAAyB,EAC9B,UAAU,CACX,CAAC;gBACF,0BAA0B,CAAC,mBAAmB,CAC5C,WAAW,EACX,IAAI,CAAC,uBAAuB,EAC5B,UAAU,CACX,CAAC;YACJ,CAAC;;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","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionalIconItem.js","sourceRoot":"","sources":["../../../../src/core-react/icons/ConditionalIconItem.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAIH;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAG9B;;;;OAIG;IACH,YACkB,UAA0B,EAC1B,YAAsB,EACtC,KAAgB;QAFA,eAAU,GAAV,UAAU,CAAgB;QAC1B,iBAAY,GAAZ,YAAY,CAAU;QAGtC,IAA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Q,CACpB,gBAA0D;QAE1D,0BAA0B;QAC1B,IAAI,SAAS,KAAK,gBAAgB;YAAE,OAAO,SAAS,CAAC;QAErD,0BAA0B;QAC1B,IAAI,mBAAmB,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAChE,MAAM,QAAQ,GAAG,gBAAgB,CAAC;YAClC,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Icon\n */\n\nimport type { IconSpec } from \"./IconComponent\";\n\n/** Class used to return an icon. The icon is variable and can be changed in response to subscribed event ids.\n * @public\n */\nexport class ConditionalIconItem {\n private _value?: IconSpec;\n\n /** Constructor for ConditionalIconItem\n * @param iconGetter Function to retrieve the icon that matches the condition. Returns an IconSpec.\n * @param syncEventIds The array of event ids to be monitored. These events are triggered when the condition(s) that control the icon change.\n * @param value The default IconSpec. If this is not specified, the function is run to get the initial value.\n */\n constructor(\n public readonly iconGetter: () => IconSpec,\n public readonly syncEventIds: string[],\n value?: IconSpec\n ) {\n this._value = value;\n }\n\n /** A work-around for instanceOf\n * @internal\n */\n public static isConditionalIconItem(item: any): item is ConditionalIconItem {\n /* istanbul ignore else */\n if (!item || typeof item !== \"object\") return false;\n const itemPrototype = Object.getPrototypeOf(item);\n /* istanbul ignore else */\n if (itemPrototype.constructor.name !== \"ConditionalIconItem\") return false;\n\n return true;\n }\n /** The current IconSpec according to conditions */\n public get value(): IconSpec {\n /* istanbul ignore else */\n if (undefined !== this._value) return this._value;\n this._value = this.iconGetter();\n return this._value;\n }\n\n /** Called to update the value by running the iconGetter */\n public refresh(): boolean {\n const newValue = this.iconGetter();\n /* istanbul ignore else */\n if (newValue !== this._value) {\n this._value = newValue;\n return true;\n }\n return false;\n }\n\n /** A helper function that updates the IconSpec value when the specified events are triggered */\n public static refreshValue(\n conditionalValue: ConditionalIconItem | string | undefined,\n eventIds: Set<string>\n ): boolean {\n /* istanbul ignore else */\n if (\n undefined === conditionalValue ||\n !ConditionalIconItem.isConditionalIconItem(conditionalValue)\n )\n return false;\n\n const iconItem = conditionalValue;\n /* istanbul ignore else */\n if (\n iconItem.syncEventIds.some((value: string): boolean =>\n eventIds.has(value.toLowerCase())\n )\n )\n return iconItem.refresh();\n\n return false;\n }\n /** helper function to get the iconSpec from a ConditionIconItem as IconSpec | undefined*/\n public static getValue(\n conditionalValue: ConditionalIconItem | string | undefined\n ): IconSpec | undefined {\n /* istanbul ignore else */\n if (undefined === conditionalValue) return undefined;\n\n /* istanbul ignore else */\n if (ConditionalIconItem.isConditionalIconItem(conditionalValue)) {\n const iconItem = conditionalValue;\n return iconItem.value;\n }\n\n return conditionalValue;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconComponent.js","sourceRoot":"","sources":["../../../../src/core-react/icons/IconComponent.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,SAAS,EAAE,KAAK,WAAW,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AA0B5D,qDAAqD;AACrD,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"IconComponent.js","sourceRoot":"","sources":["../../../../src/core-react/icons/IconComponent.tsx"],"names":[],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,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;YAC5C,KAAK,GAAG,sBAAsB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/C,MAAM;QACR,CAAC;QACD,MAAM;IACR,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Icon\n */\n\nimport \"./IconComponent.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport { ConditionalStringValue } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"../utils/Props\";\nimport DOMPurify, * as DOMPurifyNS from \"dompurify\";\nimport { ConditionalIconItem } from \"./ConditionalIconItem\";\n\n/** Prototype for an IconSpec which can be a string, ReactNode or ConditionalStringValue.\n * Strings are expected to be one of the following:\n * - Created by `IconSpecUtilities.createWebComponentIconSpec` in appui-abstract (deprecated).\n * - A URL to a SVG file (must end with \".svg\").\n * - A dataURI with MimeTypes `image/svg+xml` (ensure valid dataURI encoding) or `image/svg+xml;base64`;\n * - Anything else will be treated as a class name and be directly added to the `class` attribute.\n * @public\n */\nexport type IconSpec =\n | string\n | ConditionalStringValue\n | React.ReactNode\n | ConditionalIconItem;\n\n/** Properties for the [[Icon]] React component\n * @public\n */\nexport interface IconProps extends CommonProps {\n /** CSS class name or SvgPath for icon. This is optional because it is improperly\n * used to extend other interfaces and changing it would break existing API.\n */\n iconSpec?: IconSpec;\n}\n\n/** Get the SVG Source from an svg-loader IconSpec */\nfunction getWebComponentSource(iconSpec: string): string | undefined {\n if (iconSpec.startsWith(\"webSvg:\") && iconSpec.length > 7) {\n return iconSpec.slice(7);\n }\n\n return undefined;\n}\n\n/** Icon Functional component displays an icon based on an [[IconSpec]].\n * @public\n */\nexport function Icon(props: IconProps) {\n if (!props.iconSpec) return null;\n\n const iconSpecValue = getIconSpecValue(props.iconSpec);\n if (typeof iconSpecValue === \"string\") {\n const iconString = iconSpecValue;\n const webComponentString = getWebComponentSource(iconString);\n\n if (\n iconString.startsWith(\"data:\") ||\n iconString.endsWith(\".svg\") ||\n webComponentString\n ) {\n const definitiveIconString = webComponentString\n ? webComponentString\n : iconString;\n const svgLoader = `<svg-loader src=\"${definitiveIconString}\"></svg-loader>`;\n const svgDiv = `<div>${svgLoader}</div>`;\n // the esm build of dompurify has a default import but the cjs build does not\n // if there is a default export, use it (likely esm), otherwise use the namespace\n // istanbul ignore next\n const sanitizer = DOMPurify ?? DOMPurifyNS;\n\n const sanitizerConfig = {\n ALLOWED_TAGS: [\"svg-loader\"],\n ADD_URI_SAFE_ATTR: definitiveIconString.startsWith(\"data:\")\n ? [\"src\"]\n : [],\n };\n\n const sanitizedIconString = sanitizer.sanitize(svgDiv, sanitizerConfig);\n const webComponentNode = (\n // we can safely disable jam3/no-sanitizer-with-danger as we are sanitizing above\n // eslint-disable-next-line jam3/no-sanitizer-with-danger\n <div dangerouslySetInnerHTML={{ __html: sanitizedIconString }}></div>\n );\n return (\n <i className={classnames(\"icon\", \"core-svg-icon\", props.className)}>\n {webComponentNode}\n </i>\n );\n }\n\n // CSS icon\n return (\n <i\n className={classnames(\"icon\", iconString, props.className)}\n style={props.style}\n />\n );\n }\n\n // ReactNode icon\n return (\n <i\n className={classnames(\"icon\", \"core-svg-icon\", props.className)}\n style={props.style}\n >\n {iconSpecValue}\n </i>\n );\n}\n\nfunction getIconSpecValue(\n iconSpec: IconSpec\n): Exclude<IconSpec, ConditionalIconItem | ConditionalStringValue> {\n let value = iconSpec;\n while (true) {\n if (ConditionalIconItem.isConditionalIconItem(value)) {\n value = ConditionalIconItem.getValue(value);\n continue;\n }\n if (value instanceof ConditionalStringValue) {\n value = ConditionalStringValue.getValue(value);\n break;\n }\n break;\n }\n return value;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageCheckBox.js","sourceRoot":"","sources":["../../../../src/core-react/imagecheckbox/ImageCheckBox.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AA8B9C;;;GAGG;AACH,mDAAmD;AACnD,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAiC;IAA1E;;QACU,cAAS,GAAG,CAAC,CAAsC,EAAE,EAAE;YAC7D,uBAAuB;YACvB,IAAI,CAAC,IAAI,CAAC,CAAC,eAAe;gBAAE,CAAC,CAAC,eAAe,EAAE,CAAC;YAEhD,uBAAuB;YACvB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"ImageCheckBox.js","sourceRoot":"","sources":["../../../../src/core-react/imagecheckbox/ImageCheckBox.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AA8B9C;;;GAGG;AACH,mDAAmD;AACnD,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,aAAiC;IAA1E;;QACU,cAAS,GAAG,CAAC,CAAsC,EAAE,EAAE;YAC7D,uBAAuB;YACvB,IAAI,CAAC,IAAI,CAAC,CAAC,eAAe;gBAAE,CAAC,CAAC,eAAe,EAAE,CAAC;YAEhD,uBAAuB;YACvB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACvB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACvC,CAA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AG,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GACxB;YACF,8BAAM,SAAS,EAAE,UAAU;gBACzB,oBAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,GAAI,CACvB,CACD,CACT,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Checkbox\n */\n\nimport \"./ImageCheckBox.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Icon } from \"../icons/IconComponent\";\nimport type { CommonProps } from \"../utils/Props\";\n\n/** Properties for the [[ImageCheckBox]] component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link ImageCheckBox}.\n */\nexport interface ImageCheckBoxProps extends CommonProps {\n /** Image for the \"checked\" state */\n imageOn: string | React.ReactNode;\n /** Image for the \"unchecked\" (default) state */\n imageOff: string | React.ReactNode;\n /** Determine if the item is checked or not */\n checked?: boolean;\n /** Determine if the item is disabled or not */\n disabled?: boolean;\n /** Function called when item is clicked. */\n onClick?: (checked: boolean) => any;\n /** Custom CSS class name for the checkbox input element */\n inputClassName?: string;\n /** Custom CSS Style for the checkbox input element */\n inputStyle?: React.CSSProperties;\n /** Tooltip to be displayed when mouse is hovered over the checkbox */\n tooltip?: string;\n /** If true, draw a border around the image checkbox */\n border?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n inputRef?: React.Ref<HTMLInputElement>;\n}\n\n/** ImageCheckBox React component shows a checked or unchecked image\n * @public\n * @deprecated in 4.12.x. Use {@link https://itwinui.bentley.com/docs/checkbox iTwinUI checkbox} instead (custom icons are not supported at the moment, but feel free to submit your use cases).\n */\n// eslint-disable-next-line deprecation/deprecation\nexport class ImageCheckBox extends React.PureComponent<ImageCheckBoxProps> {\n private _onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n // istanbul ignore next\n if (e && e.stopPropagation) e.stopPropagation();\n\n // istanbul ignore else\n if (this.props.onClick) {\n this.props.onClick(e.target.checked);\n }\n };\n\n private _onInputClick = (e: React.MouseEvent<HTMLInputElement>) => {\n // istanbul ignore next\n if (e && e.stopPropagation) e.stopPropagation();\n };\n\n private _onLabelClick = (e: React.MouseEvent<HTMLLabelElement>) => {\n // istanbul ignore next\n if (e && e.stopPropagation) e.stopPropagation();\n };\n\n /** @internal */\n public override render() {\n const checkBoxClass = classnames(\n \"core-image-checkbox\",\n this.props.className\n );\n const imageClass = classnames(\n \"image\",\n this.props.border && \"image-checkbox-border\"\n );\n const iconSpec = this.props.checked\n ? this.props.imageOn\n : this.props.imageOff;\n\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/label-has-associated-control, jsx-a11y/no-noninteractive-element-interactions\n <label\n className={checkBoxClass}\n style={this.props.style}\n onClick={this._onLabelClick}\n title={this.props.tooltip}\n >\n <input\n type=\"checkbox\"\n className={this.props.inputClassName}\n style={this.props.inputStyle}\n checked={this.props.checked}\n disabled={this.props.disabled}\n onChange={this._onChange}\n onClick={this._onInputClick}\n ref={this.props.inputRef}\n />\n <span className={imageClass}>\n <Icon iconSpec={iconSpec} />\n </span>\n </label>\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../../src/core-react/inputs/Input.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAiBjD,0GAA0G;AAC1G,MAAM,eAAe,GAAG,KAAK,CAAC,UAAU,CACtC,SAAS,eAAe,CAAC,KAAK,EAAE,GAAG;IACjC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AExC,IAAI,cAAc,IAAI,cAAc,EAAE,CAAC;YACrC,cAAc,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,GAAG,EAAE;YACV,IAAI,cAAc,IAAI,cAAc,EAAE,CAAC;gBACrC,cAAc,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YAChE,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,eAAe,CAAC,OAAO,IAAI,QAAQ;YAAE,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC3E,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACnC,CAAC,KAAyC,EAAE,EAAE;QAC5C,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO,CACL,oBAAC,aAAa,IACZ,GAAG,EAAE,IAAI,EACT,IAAI,EAAC,MAAM,KACP,UAAU,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,UAAU,CAAC,qBAAqB,EAAE,SAAS,CAAC,EACvD,KAAK,EAAE,KAAK,GACZ,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAChB,eAAe,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Inputs\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Input as ITwinUI_Input } from \"@itwin/itwinui-react\";\nimport { useRefs } from \"../utils/hooks/useRefs\";\nimport type { CommonProps } from \"../utils/Props\";\n\n/** Properties for the [[Input]] component\n * @internal\n */\nexport interface InputProps\n extends React.InputHTMLAttributes<HTMLInputElement>,\n CommonProps {\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n /** Native keydown event handler */\n nativeKeyHandler?: (e: KeyboardEvent) => void;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n// Defined using following pattern (const Input at bottom) to ensure useful API documentation is extracted\nconst ForwardRefInput = React.forwardRef<HTMLInputElement, InputProps>(\n function ForwardRefInput(props, ref) {\n const {\n className,\n style,\n setFocus,\n nativeKeyHandler,\n size,\n ...otherProps\n } = props;\n const inputElementRef = React.useRef<HTMLInputElement>(null);\n const refs = useRefs(inputElementRef, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.\n\n React.useEffect(() => {\n const currentElement = inputElementRef.current;\n const currentHandler = nativeKeyHandler;\n\n if (currentElement && currentHandler) {\n currentElement.addEventListener(\"keydown\", currentHandler);\n }\n return () => {\n if (currentHandler && currentElement) {\n currentElement.removeEventListener(\"keydown\", currentHandler);\n }\n };\n }, [nativeKeyHandler]);\n\n React.useEffect(() => {\n if (inputElementRef.current && setFocus) inputElementRef.current.focus();\n }, [setFocus]);\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n return (\n <ITwinUI_Input\n ref={refs}\n type=\"text\"\n {...otherProps}\n onFocus={handleFocus}\n className={classnames(\"uicore-inputs-input\", className)}\n style={style}\n />\n );\n }\n);\n\n/** Basic text input, is a wrapper for the `<input type=\"text\">` HTML element.\n * @internal\n */\nexport const Input: (props: InputProps) => React.ReactElement | null =\n ForwardRefInput;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../../../../src/core-react/inputs/numberinput/NumberInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG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AAY,EACtB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAC,OAAO,EACZ,SAAS,EAAE,UAAU,CAAC,YAAY,EAAE,SAAS,CAAC,KAC1C,UAAU,GACd;QACF,6BACE,SAAS,EAAE,UAAU,CACnB,qCAAqC,EACrC,gBAAgB,IAAI,+BAA+B,CACpD;YAGD,6BACE,SAAS,EAAC,sDAAsD,EAChE,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa,EACtB,IAAI,EAAC,cAAc;gBAEnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;YAEN,6BACE,SAAS,EAAC,wDAAwD,EAClE,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe,EACxB,IAAI,EAAC,cAAc;gBAEnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAGS,qBAAqB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Inputs\n */\n\nimport \"./NumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Icon } from \"../../icons/IconComponent\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** Step function prototype for [[NumberInput]] component\n * @public\n * @deprecated in 4.12.x. Interface used in a deprecated component {@link NumberInput}.\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[NumberInput]] component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link NumberInput}.\n */\nexport interface NumberInputProps\n extends Omit<InputProps, \"min\" | \"max\" | \"step\" | \"onChange\"> {\n /** Numeric value, set to `undefined` to show placeholder text */\n value?: number;\n /** CSS class name for the NumberInput component container div */\n containerClassName?: string;\n /** Style for component container div. */\n containerStyle?: React.CSSProperties;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n // eslint-disable-next-line deprecation/deprecation\n step?: StepFunctionProp;\n /** number of decimal places, defaults to 0 */\n precision?: number;\n /** function parseFloat */\n parse?: (value: string) => number | null | undefined;\n /** function optional formatting function that takes the number value and the internal formatted value in case function just adds prefix or suffix. */\n format?: (num: number | null | undefined, formattedValue: string) => string;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when value is changed. */\n onChange?: (value: number | undefined, stringValue: string) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /**\n * Makes this component behave as controlled component.\n * @internal\n */\n isControlled?: boolean;\n}\n\nconst ForwardRefNumberInput = React.forwardRef<\n HTMLInputElement,\n // eslint-disable-next-line deprecation/deprecation\n NumberInputProps\n>(function ForwardRefNumberInput(props, ref) {\n const {\n containerClassName,\n className,\n value,\n min,\n max,\n precision,\n format,\n parse,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n containerStyle,\n isControlled,\n ...otherProps\n } = props;\n const currentValueRef = React.useRef(value);\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string) => {\n let n: number | undefined | null;\n\n if (parse) n = parse(x);\n if (undefined === n || null === n) {\n n = parseFloat(x);\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n }\n\n const localPrecision = undefined === precision ? 10 : precision;\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [parse, precision, min, max]\n );\n\n /**\n * This is used internally to format a number to its display representation.\n * It will invoke the format function if one is provided.\n */\n const formatInternal = React.useCallback(\n (num: number | undefined | null) => {\n const localPrecision =\n undefined === precision || null === precision ? 0 : precision;\n const str =\n undefined === num || null === num ? \"\" : num.toFixed(localPrecision);\n\n if (format) return format(num, str);\n\n return str;\n },\n [format, precision]\n );\n\n const [formattedValue, setFormattedValue] = React.useState(() =>\n formatInternal(value)\n );\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n currentValueRef.current = value;\n const currentFormattedValue = formatInternal(currentValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatInternal, value]);\n\n const handleChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newVal = event.currentTarget.value;\n setFormattedValue(newVal);\n isControlled && onChange && onChange(parseInternal(newVal), newVal);\n },\n [isControlled, onChange, parseInternal]\n );\n\n const updateValue = React.useCallback(\n (newVal: number) => {\n const newFormattedVal = formatInternal(newVal);\n onChange && onChange(newVal, newFormattedVal);\n setFormattedValue(newFormattedVal);\n },\n [onChange, formatInternal]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n const newVal = parseInternal(strValue);\n updateValue(newVal);\n },\n [parseInternal, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.Enter.valueOf()) {\n updateValueFromString(event.currentTarget.value);\n event.preventDefault();\n event.stopPropagation();\n } else if (event.key === Key.Escape.valueOf()) {\n setFormattedValue(formatInternal(currentValueRef.current));\n event.preventDefault();\n } else if (event.key === Key.ArrowDown.valueOf()) {\n applyStep(false);\n event.preventDefault();\n event.stopPropagation();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n applyStep(true);\n event.preventDefault();\n event.stopPropagation();\n }\n onKeyDown && onKeyDown(event);\n },\n [applyStep, formatInternal, updateValueFromString, onKeyDown]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"core-number-input-container\",\n containerClassName,\n showTouchButtons && \"core-number-buttons-for-touch\",\n isDisabled && \"core-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses} style={containerStyle}>\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n size=\"small\"\n className={classnames(\"core-input\", className)}\n {...otherProps}\n />\n <div\n className={classnames(\n \"core-number-input-buttons-container\",\n showTouchButtons && \"core-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"core-number-input-button core-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n role=\"presentation\"\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"core-number-input-button core-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n role=\"presentation\"\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n );\n});\n\n/** Input component for numbers with up and down buttons to increment and decrement the value.\n * @public\n * @deprecated in 4.12.x. Use {@link https://itwinui.bentley.com/docs/input iTwinUI input} instead.\n */\nexport const NumberInput: (\n // eslint-disable-next-line deprecation/deprecation\n props: NumberInputProps\n) => React.ReactElement | null = ForwardRefNumberInput;\n"]}
|
|
1
|
+
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../../../../src/core-react/inputs/numberinput/NumberInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO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,oBAAC,KAAK,IACJ,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAC,OAAO,EACZ,SAAS,EAAE,UAAU,CAAC,YAAY,EAAE,SAAS,CAAC,KAC1C,UAAU,GACd;QACF,6BACE,SAAS,EAAE,UAAU,CACnB,qCAAqC,EACrC,gBAAgB,IAAI,+BAA+B,CACpD;YAGD,6BACE,SAAS,EAAC,sDAAsD,EAChE,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa,EACtB,IAAI,EAAC,cAAc;gBAEnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;YAEN,6BACE,SAAS,EAAC,wDAAwD,EAClE,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe,EACxB,IAAI,EAAC,cAAc;gBAEnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAGS,qBAAqB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Inputs\n */\n\nimport \"./NumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { Icon } from \"../../icons/IconComponent\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** Step function prototype for [[NumberInput]] component\n * @public\n * @deprecated in 4.12.x. Interface used in a deprecated component {@link NumberInput}.\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[NumberInput]] component\n * @public\n * @deprecated in 4.12.x. Props of deprecated component {@link NumberInput}.\n */\nexport interface NumberInputProps\n extends Omit<InputProps, \"min\" | \"max\" | \"step\" | \"onChange\"> {\n /** Numeric value, set to `undefined` to show placeholder text */\n value?: number;\n /** CSS class name for the NumberInput component container div */\n containerClassName?: string;\n /** Style for component container div. */\n containerStyle?: React.CSSProperties;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n // eslint-disable-next-line deprecation/deprecation\n step?: StepFunctionProp;\n /** number of decimal places, defaults to 0 */\n precision?: number;\n /** function parseFloat */\n parse?: (value: string) => number | null | undefined;\n /** function optional formatting function that takes the number value and the internal formatted value in case function just adds prefix or suffix. */\n format?: (num: number | null | undefined, formattedValue: string) => string;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when value is changed. */\n onChange?: (value: number | undefined, stringValue: string) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /**\n * Makes this component behave as controlled component.\n * @internal\n */\n isControlled?: boolean;\n}\n\nconst ForwardRefNumberInput = React.forwardRef<\n HTMLInputElement,\n // eslint-disable-next-line deprecation/deprecation\n NumberInputProps\n>(function ForwardRefNumberInput(props, ref) {\n const {\n containerClassName,\n className,\n value,\n min,\n max,\n precision,\n format,\n parse,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n containerStyle,\n isControlled,\n ...otherProps\n } = props;\n const currentValueRef = React.useRef(value);\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string) => {\n let n: number | undefined | null;\n\n if (parse) n = parse(x);\n if (undefined === n || null === n) {\n n = parseFloat(x);\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n }\n\n const localPrecision = undefined === precision ? 10 : precision;\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [parse, precision, min, max]\n );\n\n /**\n * This is used internally to format a number to its display representation.\n * It will invoke the format function if one is provided.\n */\n const formatInternal = React.useCallback(\n (num: number | undefined | null) => {\n const localPrecision =\n undefined === precision || null === precision ? 0 : precision;\n const str =\n undefined === num || null === num ? \"\" : num.toFixed(localPrecision);\n\n if (format) return format(num, str);\n\n return str;\n },\n [format, precision]\n );\n\n const [formattedValue, setFormattedValue] = React.useState(() =>\n formatInternal(value)\n );\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n currentValueRef.current = value;\n const currentFormattedValue = formatInternal(currentValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatInternal, value]);\n\n const handleChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const newVal = event.currentTarget.value;\n setFormattedValue(newVal);\n isControlled && onChange && onChange(parseInternal(newVal), newVal);\n },\n [isControlled, onChange, parseInternal]\n );\n\n const updateValue = React.useCallback(\n (newVal: number) => {\n const newFormattedVal = formatInternal(newVal);\n onChange && onChange(newVal, newFormattedVal);\n setFormattedValue(newFormattedVal);\n },\n [onChange, formatInternal]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n const newVal = parseInternal(strValue);\n updateValue(newVal);\n },\n [parseInternal, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.Enter.valueOf()) {\n updateValueFromString(event.currentTarget.value);\n event.preventDefault();\n event.stopPropagation();\n } else if (event.key === Key.Escape.valueOf()) {\n setFormattedValue(formatInternal(currentValueRef.current));\n event.preventDefault();\n } else if (event.key === Key.ArrowDown.valueOf()) {\n applyStep(false);\n event.preventDefault();\n event.stopPropagation();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n applyStep(true);\n event.preventDefault();\n event.stopPropagation();\n }\n onKeyDown && onKeyDown(event);\n },\n [applyStep, formatInternal, updateValueFromString, onKeyDown]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"core-number-input-container\",\n containerClassName,\n showTouchButtons && \"core-number-buttons-for-touch\",\n isDisabled && \"core-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses} style={containerStyle}>\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n size=\"small\"\n className={classnames(\"core-input\", className)}\n {...otherProps}\n />\n <div\n className={classnames(\n \"core-number-input-buttons-container\",\n showTouchButtons && \"core-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"core-number-input-button core-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n role=\"presentation\"\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"core-number-input-button core-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n role=\"presentation\"\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n );\n});\n\n/** Input component for numbers with up and down buttons to increment and decrement the value.\n * @public\n * @deprecated in 4.12.x. Use {@link https://itwinui.bentley.com/docs/input iTwinUI input} instead.\n */\nexport const NumberInput: (\n // eslint-disable-next-line deprecation/deprecation\n props: NumberInputProps\n) => React.ReactElement | null = ForwardRefNumberInput;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePackageTranslation.js","sourceRoot":"","sources":["../../../../src/core-react/l10n/usePackageTranslation.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,SAAS,EACT,QAAQ,EACR,QAAQ,GAKT;IACC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,YAAY;YAAE,OAAO;QAE1B,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,aAAa,CAAC,KAAK,CAAC,CAAC;QACrB,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,YAAY,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAChD,IAAI,MAAM;gBAAE,OAAO;YACnB,aAAa,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CACjC,CAAC,GAAW,EAAE,EAAE;QACd,IAAI,YAAY,IAAI,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"usePackageTranslation.js","sourceRoot":"","sources":["../../../../src/core-react/l10n/usePackageTranslation.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,qBAAq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AE,CAAC;AACvB,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB,EAAE,WAAmB;IAC5D,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,IAAI,GAAQ,QAAQ,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;YACnB,IAAI,GAAG,SAAS,CAAC;YACjB,MAAM;QACR,CAAC;QACD,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\nimport { useLocalization } from \"./LocalizationProvider\";\n\n/** Used by AppUI packages internally to define package specific `useTranslation` hook.\n * Uses a localization provider to translate the provided key with a specified namespace. Multiple fallback layers are used to resolve the translation:\n * - Return value of a specified `fallback` function.\n * - Default value looked up from a specified `defaults` object.\n * - Lastly `key` argument of the translation function is returned.\n * @internal\n */\nexport function usePackageTranslation({\n namespace,\n fallback,\n defaults,\n}: {\n namespace: string;\n fallback: (key: string) => string | undefined;\n defaults: object;\n}) {\n const localization = useLocalization();\n const [registered, setRegistered] = React.useState(false);\n React.useEffect(() => {\n if (!localization) return;\n\n let ignore = false;\n setRegistered(false);\n void (async () => {\n await localization.registerNamespace(namespace);\n if (ignore) return;\n setRegistered(true);\n })();\n return () => {\n ignore = true;\n };\n }, [localization, namespace]);\n const translate = React.useCallback(\n (key: string) => {\n if (localization && registered) {\n return localization.getLocalizedString(`${namespace}:${key}`);\n }\n\n const fallbackTranslation = fallback(key);\n if (fallbackTranslation !== undefined) {\n return fallbackTranslation;\n }\n\n const defaultValue = getDefaultValue(defaults, key);\n return defaultValue ?? key;\n },\n [localization, namespace, fallback, defaults, registered]\n );\n return { translate };\n}\n\nfunction getDefaultValue(defaults: object, propertyKey: string) {\n const keys = propertyKey.split(\".\");\n let prop: any = defaults;\n for (const key of keys) {\n if (!(key in prop)) {\n prop = undefined;\n break;\n }\n prop = prop[key];\n }\n if (typeof prop !== \"string\") {\n return undefined;\n }\n return prop;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslation.js","sourceRoot":"","sources":["../../../../src/core-react/l10n/useTranslation.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,GAAW,EAAE,EAAE;QACjD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"useTranslation.js","sourceRoot":"","sources":["../../../../src/core-react/l10n/useTranslation.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,GAAW,EAAE,EAAE;QACjD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,mDAAmD;QACnD,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,qBAAqB,CAAC;QAC3B,SAAS,EAAE,MAAM,CAAC,qBAAqB;QACvC,QAAQ;QACR,QAAQ;KACT,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nimport * as defaults from \"../UiCore.json\";\nimport * as React from \"react\";\nimport { UiCore } from \"../UiCore\";\nimport { usePackageTranslation } from \"./usePackageTranslation\";\n\n/** Returns a translation function to localize package components.\n * @internal\n */\nexport function useTranslation() {\n const fallback = React.useCallback((key: string) => {\n if (!UiCore.initialized) {\n return undefined;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return UiCore.translate(key);\n }, []);\n return usePackageTranslation({\n namespace: UiCore.localizationNamespace,\n fallback,\n defaults,\n });\n}\n"]}
|