@itwin/core-react 3.2.0-dev.8 → 3.2.1
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 +54 -1
- package/lib/cjs/core-react/UiCore.d.ts.map +1 -1
- package/lib/cjs/core-react/UiCore.js +3 -0
- package/lib/cjs/core-react/UiCore.js.map +1 -1
- package/lib/cjs/core-react/badge/Badge.d.ts.map +1 -1
- package/lib/cjs/core-react/badge/Badge.js +4 -2
- package/lib/cjs/core-react/badge/Badge.js.map +1 -1
- package/lib/cjs/core-react/badge/BetaBadge.js +2 -2
- package/lib/cjs/core-react/badge/BetaBadge.js.map +1 -1
- package/lib/cjs/core-react/badge/NewBadge.js +2 -2
- package/lib/cjs/core-react/badge/NewBadge.js.map +1 -1
- package/lib/cjs/core-react/colorvariables.scss +90 -86
- package/lib/cjs/core-react/icons/IconComponent.d.ts.map +1 -1
- package/lib/cjs/core-react/icons/IconComponent.js +16 -0
- package/lib/cjs/core-react/icons/IconComponent.js.map +1 -1
- package/lib/cjs/core-react/icons/IconComponent.scss +5 -0
- package/lib/cjs/core-react/icons/SvgSprite.d.ts +3 -2
- package/lib/cjs/core-react/icons/SvgSprite.d.ts.map +1 -1
- package/lib/cjs/core-react/icons/SvgSprite.js +3 -1
- package/lib/cjs/core-react/icons/SvgSprite.js.map +1 -1
- package/lib/cjs/core-react/inputs/Input.js +1 -1
- package/lib/cjs/core-react/inputs/Input.js.map +1 -1
- package/lib/cjs/core-react/inputs/Textarea.js +1 -1
- package/lib/cjs/core-react/inputs/Textarea.js.map +1 -1
- package/lib/cjs/core-react/listbox/Listbox.js +4 -4
- package/lib/cjs/core-react/listbox/Listbox.js.map +1 -1
- package/lib/cjs/core-react/notification/MessageRenderer.d.ts.map +1 -1
- package/lib/cjs/core-react/notification/MessageRenderer.js +7 -4
- package/lib/cjs/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/cjs/core-react/utils/IconHelper.d.ts +2 -1
- package/lib/cjs/core-react/utils/IconHelper.d.ts.map +1 -1
- package/lib/cjs/core-react/utils/IconHelper.js.map +1 -1
- package/lib/cjs/core-react/utils/IconWebComponent.d.ts +11 -0
- package/lib/cjs/core-react/utils/IconWebComponent.d.ts.map +1 -0
- package/lib/cjs/core-react/utils/IconWebComponent.js +49 -0
- package/lib/cjs/core-react/utils/IconWebComponent.js.map +1 -0
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.d.ts +8 -0
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.d.ts.map +1 -0
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.js +90 -0
- package/lib/cjs/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -0
- package/lib/cjs/core-react/utils/hooks/useInterval.d.ts +6 -0
- package/lib/cjs/core-react/utils/hooks/useInterval.d.ts.map +1 -0
- package/lib/cjs/core-react/utils/hooks/useInterval.js +37 -0
- package/lib/cjs/core-react/utils/hooks/useInterval.js.map +1 -0
- package/lib/cjs/core-react/utils/hooks/useResizeObserver.js +2 -2
- package/lib/cjs/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/lib/cjs/core-react.d.ts +2 -0
- package/lib/cjs/core-react.d.ts.map +1 -1
- package/lib/cjs/core-react.js +2 -0
- package/lib/cjs/core-react.js.map +1 -1
- package/lib/esm/core-react/UiCore.d.ts.map +1 -1
- package/lib/esm/core-react/UiCore.js +3 -0
- package/lib/esm/core-react/UiCore.js.map +1 -1
- package/lib/esm/core-react/badge/Badge.d.ts.map +1 -1
- package/lib/esm/core-react/badge/Badge.js +4 -2
- package/lib/esm/core-react/badge/Badge.js.map +1 -1
- package/lib/esm/core-react/badge/BetaBadge.js +1 -1
- package/lib/esm/core-react/badge/BetaBadge.js.map +1 -1
- package/lib/esm/core-react/badge/NewBadge.js +1 -1
- package/lib/esm/core-react/badge/NewBadge.js.map +1 -1
- package/lib/esm/core-react/colorvariables.scss +90 -86
- package/lib/esm/core-react/icons/IconComponent.d.ts.map +1 -1
- package/lib/esm/core-react/icons/IconComponent.js +16 -0
- package/lib/esm/core-react/icons/IconComponent.js.map +1 -1
- package/lib/esm/core-react/icons/IconComponent.scss +5 -0
- package/lib/esm/core-react/icons/SvgSprite.d.ts +3 -2
- package/lib/esm/core-react/icons/SvgSprite.d.ts.map +1 -1
- package/lib/esm/core-react/icons/SvgSprite.js +3 -1
- package/lib/esm/core-react/icons/SvgSprite.js.map +1 -1
- package/lib/esm/core-react/inputs/Input.js +1 -1
- package/lib/esm/core-react/inputs/Input.js.map +1 -1
- package/lib/esm/core-react/inputs/Textarea.js +1 -1
- package/lib/esm/core-react/inputs/Textarea.js.map +1 -1
- package/lib/esm/core-react/listbox/Listbox.js +4 -4
- package/lib/esm/core-react/listbox/Listbox.js.map +1 -1
- package/lib/esm/core-react/notification/MessageRenderer.d.ts.map +1 -1
- package/lib/esm/core-react/notification/MessageRenderer.js +7 -4
- package/lib/esm/core-react/notification/MessageRenderer.js.map +1 -1
- package/lib/esm/core-react/utils/IconHelper.d.ts +2 -1
- package/lib/esm/core-react/utils/IconHelper.d.ts.map +1 -1
- package/lib/esm/core-react/utils/IconHelper.js.map +1 -1
- package/lib/esm/core-react/utils/IconWebComponent.d.ts +11 -0
- package/lib/esm/core-react/utils/IconWebComponent.d.ts.map +1 -0
- package/lib/esm/core-react/utils/IconWebComponent.js +45 -0
- package/lib/esm/core-react/utils/IconWebComponent.js.map +1 -0
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.d.ts +8 -0
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.d.ts.map +1 -0
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.js +86 -0
- package/lib/esm/core-react/utils/hooks/useCrossOriginPopup.js.map +1 -0
- package/lib/esm/core-react/utils/hooks/useInterval.d.ts +6 -0
- package/lib/esm/core-react/utils/hooks/useInterval.d.ts.map +1 -0
- package/lib/esm/core-react/utils/hooks/useInterval.js +33 -0
- package/lib/esm/core-react/utils/hooks/useInterval.js.map +1 -0
- package/lib/esm/core-react/utils/hooks/useResizeObserver.js +2 -2
- package/lib/esm/core-react/utils/hooks/useResizeObserver.js.map +1 -1
- package/lib/esm/core-react.d.ts +2 -0
- package/lib/esm/core-react.d.ts.map +1 -1
- package/lib/esm/core-react.js +2 -0
- package/lib/esm/core-react.js.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../../../src/core-react/inputs/Textarea.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2CAAoC;AACpC,+BAA+B;AAC/B,wDAAoE;AACpE,oDAAiD;AAgBjD,0GAA0G;AAC1G,MAAM,kBAAkB,GAAG,KAAK,CAAC,UAAU,CAAyC,8CAA8C;AAChI,SAAS,kBAAkB,CAAC,KAAK,EAAE,GAAG;IACpC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC,wDAAwD;IAC3H,MAAM,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../../../src/core-react/inputs/Textarea.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2CAAoC;AACpC,+BAA+B;AAC/B,wDAAoE;AACpE,oDAAiD;AAgBjD,0GAA0G;AAC1G,MAAM,kBAAkB,GAAG,KAAK,CAAC,UAAU,CAAyC,8CAA8C;AAChI,SAAS,kBAAkB,CAAC,KAAK,EAAE,GAAG;IACpC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC,wDAAwD;IAC3H,MAAM,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,CAAsB,IAAI,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,IAAA,iBAAO,EAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAE,uGAAuG;IAEvJ,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,kBAAkB,CAAC,OAAO,IAAI,QAAQ;YACxC,kBAAkB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAA4C,EAAE,EAAE;QACrF,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,wBAAgB,OAAK,UAAU,EAC9B,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,IAAA,oBAAU,EAAC,wBAAwB,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,GAAI,CAC/E,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;GAGG;AACU,QAAA,QAAQ,GAAiD,kBAAkB,CAAC,CAAG,8CAA8C","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Inputs\r\n */\r\n\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { Textarea as ITwinUI_Textarea } from \"@itwin/itwinui-react\";\r\nimport { useRefs } from \"../utils/hooks/useRefs\";\r\nimport { CommonProps } from \"../utils/Props\";\r\n\r\n/** Properties for [[Textarea]] component\r\n * @public\r\n * @deprecated Use TextareaProps in itwinui-react instead\r\n */\r\nexport interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement>, CommonProps {\r\n /** Number of textarea rows. Default is 3. */\r\n rows?: number;\r\n /** Indicates whether to set focus to the textarea element */\r\n setFocus?: boolean;\r\n /** Provides ability to return reference to HTMLInputElement */\r\n ref?: React.Ref<HTMLTextAreaElement>;\r\n}\r\n\r\n// Defined using following pattern (const Input at bottom) to ensure useful API documentation is extracted\r\nconst ForwardRefTextarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>( // eslint-disable-line deprecation/deprecation\r\n function ForwardRefTextarea(props, ref) {\r\n const { className, style, rows, setFocus, ...otherProps } = props; // eslint-disable-line @typescript-eslint/no-unused-vars\r\n const textRows = undefined !== rows ? rows : 3;\r\n const textAreaElementRef = React.useRef<HTMLTextAreaElement>(null);\r\n const refs = useRefs(textAreaElementRef, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.\r\n\r\n React.useEffect(() => {\r\n if (textAreaElementRef.current && setFocus)\r\n textAreaElementRef.current.focus();\r\n }, [setFocus]);\r\n\r\n const handleFocus = React.useCallback((event: React.FocusEvent<HTMLTextAreaElement>) => {\r\n event.currentTarget.select();\r\n }, []);\r\n\r\n return (\r\n <ITwinUI_Textarea {...otherProps}\r\n ref={refs}\r\n rows={textRows}\r\n onFocus={handleFocus}\r\n className={classnames(\"uicore-inputs-textarea\", className)} style={style} />\r\n );\r\n }\r\n);\r\n\r\n/** Basic textarea component\r\n * @public\r\n * @deprecated Use Textarea in itwinui-react instead\r\n */\r\nexport const Textarea: (props: TextareaProps) => JSX.Element | null = ForwardRefTextarea; // eslint-disable-line deprecation/deprecation\r\n"]}
|
|
@@ -69,7 +69,7 @@ function processKeyboardNavigation(optionValues, itemIndex, key) {
|
|
|
69
69
|
* @alpha
|
|
70
70
|
*/
|
|
71
71
|
function Listbox(props) {
|
|
72
|
-
const { ariaLabel, ariaLabelledBy, id, children, selectedValue, className, onListboxValueChange,
|
|
72
|
+
const { ariaLabel, ariaLabelledBy, id, children, selectedValue, className, onListboxValueChange, onKeyDown, ...otherProps } = props;
|
|
73
73
|
const listRef = React.useRef(null);
|
|
74
74
|
const [listId] = React.useState(() => { return id !== null && id !== void 0 ? id : core_bentley_1.Guid.createValue(); });
|
|
75
75
|
const optionValues = React.useMemo(() => getOptionValueArray(children), [children]);
|
|
@@ -137,9 +137,9 @@ function Listbox(props) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
// istanbul ignore else
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
}, [focusValue, optionValues, focusOption,
|
|
140
|
+
if (onKeyDown)
|
|
141
|
+
onKeyDown(event);
|
|
142
|
+
}, [focusValue, optionValues, focusOption, onKeyDown, handleValueChange]);
|
|
143
143
|
const isInitialMount = React.useRef(true);
|
|
144
144
|
React.useEffect(() => {
|
|
145
145
|
const list = listRef.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Listbox.js","sourceRoot":"","sources":["../../../../src/core-react/listbox/Listbox.tsx"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAA+B;AAC/B,2CAAoC;AAEpC,0BAAwB;AACxB,sDAA2C;AAC3C,0DAAmD;AA6CnD;;;GAGG;AACH,uBAAuB;AACV,QAAA,cAAc,GAAG,KAAK,CAAC,aAAa,CAAsB,EAAE,oBAAoB,EAAE,CAAC,SAAmC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,2DAA2D;AAE3M,SAAS,MAAM,CAAC,GAAG,IAA+C;IAChE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA2B;IACtD,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AS;QACpC,uEAAuE;QACvE,sCAAsC;QACtC,wDAAwD;QACxD,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,OAAO,KACd,UAAU,EACd,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,SAAS,EAAE,gBAEH,KAAK,EACjB,OAAO,EAAE,WAAW,IAEnB,QAAQ,CACN,CACN,CAAC;AACJ,CAAC;AA9DD,kCA8DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport * as React from \"react\";\r\nimport classnames from \"classnames\";\r\n\r\nimport \"./Listbox.scss\";\r\nimport { Guid } from \"@itwin/core-bentley\";\r\nimport { SpecialKey } from \"@itwin/appui-abstract\";\r\n\r\n/** Ideas borrowed from https://reacttraining.com/reach-ui/listbox */\r\n\r\n/**\r\n * `Listbox` value.\r\n * @alpha\r\n */\r\nexport type ListboxValue = string;\r\n\r\n/**\r\n * `Listbox` Props.\r\n * @alpha\r\n */\r\nexport interface ListboxProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement> {\r\n id?: string;\r\n selectedValue?: ListboxValue;\r\n ariaLabel?: any;\r\n ariaLabelledBy?: any;\r\n onListboxValueChange?: ((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => void);\r\n}\r\n\r\n/**\r\n * `ListboxItem` Props.\r\n * @alpha\r\n */\r\nexport interface ListboxItemProps extends React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement> {\r\n /** The unique item's value. */\r\n value: ListboxValue;\r\n /** set if item is disabled. */\r\n disabled?: boolean;\r\n}\r\n\r\n/**\r\n * `Listbox` Context.\r\n * @alpha\r\n */\r\nexport interface ListboxContextProps {\r\n listboxId?: string;\r\n listboxValue?: ListboxValue;\r\n focusValue?: ListboxValue;\r\n onListboxValueChange: ((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => void);\r\n listboxRef?: React.RefObject<HTMLUListElement>;\r\n}\r\n\r\n/**\r\n * Context set up by listbox for use by `ListboxItems` .\r\n * @alpha\r\n */\r\n// istanbul ignore next\r\nexport const ListboxContext = React.createContext<ListboxContextProps>({ onListboxValueChange: (_newValue: ListboxValue | undefined) => { } }); // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\nfunction makeId(...args: Array<string | number | null | undefined>) {\r\n return args.filter((val) => val != null).join(\"--\");\r\n}\r\n\r\nfunction getOptionValueArray(childNodes: React.ReactNode): ListboxItemProps[] {\r\n return React.Children.toArray(childNodes).filter((node) => React.isValidElement(node) && node.props.value).map((optionNode) => ((optionNode as React.ReactElement).props as ListboxItemProps));\r\n}\r\n\r\nfunction processKeyboardNavigation(optionValues: ListboxItemProps[], itemIndex: number, key: string): [number, boolean] {\r\n let keyProcessed = false;\r\n let newIndex = itemIndex >= 0 ? itemIndex : 0;\r\n\r\n // Note: In aria example Page Up/Down just moves up or down by one item. See https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/js/listbox.js\r\n if (key === SpecialKey.ArrowDown || key === SpecialKey.PageDown) {\r\n for (let i = itemIndex + 1; i < optionValues.length; i++) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.ArrowUp || key === SpecialKey.PageUp) {\r\n for (let i = itemIndex - 1; i >= 0; i--) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.Home) {\r\n for (let i = 0; i < optionValues.length; i++) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.End) {\r\n for (let i = optionValues.length - 1; i >= 0; i--) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n }\r\n return [newIndex, keyProcessed];\r\n}\r\n\r\n/**\r\n * Single select `Listbox` component\r\n * @alpha\r\n */\r\nexport function Listbox(props: ListboxProps) {\r\n const { ariaLabel, ariaLabelledBy, id, children, selectedValue, className, onListboxValueChange, onKeyPress, ...otherProps } = props;\r\n const listRef = React.useRef<HTMLUListElement>(null);\r\n const [listId] = React.useState(() => { return id ?? Guid.createValue(); });\r\n const optionValues = React.useMemo(() => getOptionValueArray(children), [children]);\r\n const classes = React.useMemo(() => classnames(\"core-listbox\", className), [className]);\r\n const [currentValue, setCurrentValue] = React.useState<ListboxValue | undefined>(selectedValue);\r\n const [focusValue, setFocusValue] = React.useState<ListboxValue | undefined>(currentValue);\r\n\r\n React.useEffect(() => {\r\n setCurrentValue(selectedValue);\r\n setFocusValue(selectedValue);\r\n }, [selectedValue]);\r\n\r\n const scrollTopRef = React.useRef(0);\r\n const handleValueChange = React.useCallback((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => {\r\n // istanbul ignore else\r\n if (newValue !== currentValue) {\r\n setCurrentValue(newValue);\r\n setFocusValue(newValue);\r\n if (onListboxValueChange)\r\n onListboxValueChange(newValue, isControlOrCommandPressed);\r\n }\r\n }, [setCurrentValue, currentValue, onListboxValueChange]);\r\n\r\n const focusOption = React.useCallback((itemIndex: number) => {\r\n // istanbul ignore else\r\n if (itemIndex >= 0 && itemIndex < optionValues.length) {\r\n const newSelection = optionValues[itemIndex];\r\n const listElement = listRef.current as HTMLUListElement;\r\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\r\n const optionToFocus = listElement.querySelector(`li[data-value=\"${newSelection.value}\"]`) as HTMLLIElement | null;\r\n // istanbul ignore else\r\n if (optionToFocus && listElement) {\r\n let newScrollTop = listElement.scrollTop;\r\n\r\n // istanbul ignore next\r\n if (listElement.scrollHeight > listElement.clientHeight) {\r\n const scrollBottom = listElement.clientHeight + listElement.scrollTop;\r\n const elementBottom = optionToFocus.offsetTop + optionToFocus.offsetHeight;\r\n if (elementBottom > scrollBottom) {\r\n newScrollTop = elementBottom - listElement.clientHeight;\r\n } else if (optionToFocus.offsetTop < listElement.scrollTop) {\r\n newScrollTop = optionToFocus.offsetTop;\r\n }\r\n scrollTopRef.current = newScrollTop;\r\n }\r\n setFocusValue(newSelection.value);\r\n }\r\n }\r\n }, [optionValues]);\r\n\r\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLUListElement>) => {\r\n if (optionValues.length < 1)\r\n return;\r\n\r\n const itemIndex = (undefined === focusValue) ? -1 : optionValues.findIndex((optionValue) => ((optionValue.value === focusValue)));\r\n\r\n if (event.key === SpecialKey.Space) {\r\n event.preventDefault();\r\n // istanbul ignore else\r\n if (focusValue)\r\n handleValueChange(focusValue, event.getModifierState(\"Control\") || event.getModifierState(\"Meta\")); // Control or Command\r\n return;\r\n } else {\r\n const [newItemIndex, keyProcessed] = processKeyboardNavigation(optionValues, itemIndex, event.key);\r\n // istanbul ignore else\r\n if (keyProcessed) {\r\n event.preventDefault();\r\n focusOption(newItemIndex);\r\n return;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (onKeyPress)\r\n onKeyPress(event);\r\n }, [focusValue, optionValues, focusOption, onKeyPress, handleValueChange]);\r\n\r\n const isInitialMount = React.useRef(true);\r\n\r\n React.useEffect(() => {\r\n const list = listRef.current as HTMLUListElement;\r\n\r\n if (isInitialMount.current) {\r\n isInitialMount.current = false;\r\n\r\n if (undefined !== focusValue) {\r\n const itemIndex = optionValues.findIndex((optionValue) => (optionValue.value === focusValue));\r\n focusOption(itemIndex);\r\n }\r\n } else {\r\n list.scrollTop = scrollTopRef.current;\r\n }\r\n }, [focusValue, focusOption, optionValues]);\r\n\r\n // istanbul ignore next\r\n const handleOnScroll = React.useCallback((_event: React.UIEvent<HTMLUListElement, UIEvent>) => {\r\n if (listRef.current)\r\n scrollTopRef.current = listRef.current.scrollTop;\r\n }, []);\r\n\r\n // istanbul ignore next\r\n const handleOnFocus = React.useCallback((_event: React.FocusEvent<HTMLUListElement>) => {\r\n if (!focusValue || 0 === focusValue.length) {\r\n if (currentValue) {\r\n setFocusValue(currentValue);\r\n } else {\r\n if (optionValues.length > 0)\r\n setFocusValue(optionValues[0].value);\r\n }\r\n }\r\n }, [currentValue, focusValue, optionValues]);\r\n\r\n return <ul\r\n className={classes}\r\n // If the listbox is not part of another widget, then it has a visible\r\n // label referenced by `aria-labelledby` on the element with role\r\n // `listbox`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n // If an `aria-label` is passed, we should skip `aria-labelledby` to\r\n // avoid confusion.\r\n aria-labelledby={ariaLabel ? undefined : ariaLabelledBy}\r\n aria-label={ariaLabel}\r\n // An element that contains or owns all the listbox options has role\r\n // listbox.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n role=\"listbox\"\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/examples/listbox/listbox-collapsible.html\r\n tabIndex={0}\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/examples/listbox/listbox-scrollable.html\r\n aria-activedescendant={makeId(currentValue, listId)}\r\n {...otherProps}\r\n ref={listRef}\r\n id={listId}\r\n onKeyDown={handleKeyDown}\r\n onScroll={handleOnScroll}\r\n data-value={currentValue}\r\n data-focusvalue={focusValue}\r\n onFocus={handleOnFocus}\r\n >\r\n <ListboxContext.Provider\r\n value={{\r\n listboxValue: currentValue,\r\n focusValue,\r\n listboxId: listId,\r\n onListboxValueChange: handleValueChange,\r\n listboxRef: listRef,\r\n }}\r\n >\r\n {children}\r\n </ListboxContext.Provider>\r\n </ul>;\r\n}\r\n\r\n/**\r\n * `ListboxItem` component.\r\n * @alpha\r\n */\r\nexport function ListboxItem(props: ListboxItemProps) {\r\n const {\r\n children,\r\n value,\r\n className,\r\n disabled,\r\n ...otherProps\r\n } = props;\r\n\r\n const {\r\n listboxValue,\r\n focusValue,\r\n listboxId,\r\n onListboxValueChange,\r\n } = React.useContext(ListboxContext);\r\n\r\n const hasFocus = focusValue === value;\r\n\r\n const classes = React.useMemo(() => classnames(\"core-listbox-item\", hasFocus && \"focused\", className), [className, hasFocus]);\r\n const itemRef = React.useRef<HTMLLIElement>(null);\r\n const isSelected = listboxValue === value;\r\n\r\n const handleClick = React.useCallback((event: React.MouseEvent<HTMLLIElement, MouseEvent>) => {\r\n event.preventDefault();\r\n // istanbul ignore next\r\n const selectedValue = event.currentTarget?.dataset?.value;\r\n // istanbul ignore else\r\n if (undefined !== selectedValue) {\r\n onListboxValueChange(selectedValue, event.ctrlKey);\r\n }\r\n }, [onListboxValueChange]);\r\n\r\n const getItemId = React.useCallback(() => {\r\n return makeId(value, listboxId);\r\n }, [listboxId, value]);\r\n\r\n return (\r\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\r\n <li\r\n // In a single-select listbox, the selected option has `aria-selected`\r\n // set to `true`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n aria-selected={isSelected}\r\n // Applicable to all host language elements regardless of whether a\r\n // `role` is applied.\r\n // https://www.w3.org/WAI/PF/aria/states_and_properties#global_states_header\r\n aria-disabled={disabled || undefined}\r\n // Each option in the listbox has role `option` and is a DOM descendant\r\n // of the element with role `listbox`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n role=\"option\"\r\n className={classes}\r\n {...otherProps}\r\n ref={itemRef}\r\n id={getItemId()}\r\n // used for css styling\r\n data-value={value}\r\n onClick={handleClick}\r\n >\r\n {children}\r\n </li>\r\n );\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Listbox.js","sourceRoot":"","sources":["../../../../src/core-react/listbox/Listbox.tsx"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAA+B;AAC/B,2CAAoC;AAEpC,0BAAwB;AACxB,sDAA2C;AAC3C,0DAAmD;AA6CnD;;;GAGG;AACH,uBAAuB;AACV,QAAA,cAAc,GAAG,KAAK,CAAC,aAAa,CAAsB,EAAE,oBAAoB,EAAE,CAA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E,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACvC,OAAO,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvB,OAAO;IACL,iEAAiE;IACjE,6CAIiB,UAAU,mBAIV,QAAQ,IAAI,SAAS;QACpC,uEAAuE;QACvE,sCAAsC;QACtC,wDAAwD;QACxD,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,OAAO,KACd,UAAU,EACd,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,SAAS,EAAE,gBAEH,KAAK,EACjB,OAAO,EAAE,WAAW,IAEnB,QAAQ,CACN,CACN,CAAC;AACJ,CAAC;AA9DD,kCA8DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport * as React from \"react\";\r\nimport classnames from \"classnames\";\r\n\r\nimport \"./Listbox.scss\";\r\nimport { Guid } from \"@itwin/core-bentley\";\r\nimport { SpecialKey } from \"@itwin/appui-abstract\";\r\n\r\n/** Ideas borrowed from https://reacttraining.com/reach-ui/listbox */\r\n\r\n/**\r\n * `Listbox` value.\r\n * @alpha\r\n */\r\nexport type ListboxValue = string;\r\n\r\n/**\r\n * `Listbox` Props.\r\n * @alpha\r\n */\r\nexport interface ListboxProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement> {\r\n id?: string;\r\n selectedValue?: ListboxValue;\r\n ariaLabel?: any;\r\n ariaLabelledBy?: any;\r\n onListboxValueChange?: ((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => void);\r\n}\r\n\r\n/**\r\n * `ListboxItem` Props.\r\n * @alpha\r\n */\r\nexport interface ListboxItemProps extends React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement> {\r\n /** The unique item's value. */\r\n value: ListboxValue;\r\n /** set if item is disabled. */\r\n disabled?: boolean;\r\n}\r\n\r\n/**\r\n * `Listbox` Context.\r\n * @alpha\r\n */\r\nexport interface ListboxContextProps {\r\n listboxId?: string;\r\n listboxValue?: ListboxValue;\r\n focusValue?: ListboxValue;\r\n onListboxValueChange: ((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => void);\r\n listboxRef?: React.RefObject<HTMLUListElement>;\r\n}\r\n\r\n/**\r\n * Context set up by listbox for use by `ListboxItems` .\r\n * @alpha\r\n */\r\n// istanbul ignore next\r\nexport const ListboxContext = React.createContext<ListboxContextProps>({ onListboxValueChange: (_newValue: ListboxValue | undefined) => { } }); // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\nfunction makeId(...args: Array<string | number | null | undefined>) {\r\n return args.filter((val) => val != null).join(\"--\");\r\n}\r\n\r\nfunction getOptionValueArray(childNodes: React.ReactNode): ListboxItemProps[] {\r\n return React.Children.toArray(childNodes).filter((node) => React.isValidElement(node) && node.props.value).map((optionNode) => ((optionNode as React.ReactElement).props as ListboxItemProps));\r\n}\r\n\r\nfunction processKeyboardNavigation(optionValues: ListboxItemProps[], itemIndex: number, key: string): [number, boolean] {\r\n let keyProcessed = false;\r\n let newIndex = itemIndex >= 0 ? itemIndex : 0;\r\n\r\n // Note: In aria example Page Up/Down just moves up or down by one item. See https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/js/listbox.js\r\n if (key === SpecialKey.ArrowDown || key === SpecialKey.PageDown) {\r\n for (let i = itemIndex + 1; i < optionValues.length; i++) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.ArrowUp || key === SpecialKey.PageUp) {\r\n for (let i = itemIndex - 1; i >= 0; i--) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.Home) {\r\n for (let i = 0; i < optionValues.length; i++) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n } else if (key === SpecialKey.End) {\r\n for (let i = optionValues.length - 1; i >= 0; i--) {\r\n if (!optionValues[i].disabled) {\r\n newIndex = i;\r\n break;\r\n }\r\n }\r\n keyProcessed = true;\r\n }\r\n return [newIndex, keyProcessed];\r\n}\r\n\r\n/**\r\n * Single select `Listbox` component\r\n * @alpha\r\n */\r\nexport function Listbox(props: ListboxProps) {\r\n const { ariaLabel, ariaLabelledBy, id, children, selectedValue, className, onListboxValueChange, onKeyDown, ...otherProps } = props;\r\n const listRef = React.useRef<HTMLUListElement>(null);\r\n const [listId] = React.useState(() => { return id ?? Guid.createValue(); });\r\n const optionValues = React.useMemo(() => getOptionValueArray(children), [children]);\r\n const classes = React.useMemo(() => classnames(\"core-listbox\", className), [className]);\r\n const [currentValue, setCurrentValue] = React.useState<ListboxValue | undefined>(selectedValue);\r\n const [focusValue, setFocusValue] = React.useState<ListboxValue | undefined>(currentValue);\r\n\r\n React.useEffect(() => {\r\n setCurrentValue(selectedValue);\r\n setFocusValue(selectedValue);\r\n }, [selectedValue]);\r\n\r\n const scrollTopRef = React.useRef(0);\r\n const handleValueChange = React.useCallback((newValue: ListboxValue, isControlOrCommandPressed?: boolean) => {\r\n // istanbul ignore else\r\n if (newValue !== currentValue) {\r\n setCurrentValue(newValue);\r\n setFocusValue(newValue);\r\n if (onListboxValueChange)\r\n onListboxValueChange(newValue, isControlOrCommandPressed);\r\n }\r\n }, [setCurrentValue, currentValue, onListboxValueChange]);\r\n\r\n const focusOption = React.useCallback((itemIndex: number) => {\r\n // istanbul ignore else\r\n if (itemIndex >= 0 && itemIndex < optionValues.length) {\r\n const newSelection = optionValues[itemIndex];\r\n const listElement = listRef.current as HTMLUListElement;\r\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\r\n const optionToFocus = listElement.querySelector(`li[data-value=\"${newSelection.value}\"]`) as HTMLLIElement | null;\r\n // istanbul ignore else\r\n if (optionToFocus && listElement) {\r\n let newScrollTop = listElement.scrollTop;\r\n\r\n // istanbul ignore next\r\n if (listElement.scrollHeight > listElement.clientHeight) {\r\n const scrollBottom = listElement.clientHeight + listElement.scrollTop;\r\n const elementBottom = optionToFocus.offsetTop + optionToFocus.offsetHeight;\r\n if (elementBottom > scrollBottom) {\r\n newScrollTop = elementBottom - listElement.clientHeight;\r\n } else if (optionToFocus.offsetTop < listElement.scrollTop) {\r\n newScrollTop = optionToFocus.offsetTop;\r\n }\r\n scrollTopRef.current = newScrollTop;\r\n }\r\n setFocusValue(newSelection.value);\r\n }\r\n }\r\n }, [optionValues]);\r\n\r\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLUListElement>) => {\r\n if (optionValues.length < 1)\r\n return;\r\n\r\n const itemIndex = (undefined === focusValue) ? -1 : optionValues.findIndex((optionValue) => ((optionValue.value === focusValue)));\r\n\r\n if (event.key === SpecialKey.Space) {\r\n event.preventDefault();\r\n // istanbul ignore else\r\n if (focusValue)\r\n handleValueChange(focusValue, event.getModifierState(\"Control\") || event.getModifierState(\"Meta\")); // Control or Command\r\n return;\r\n } else {\r\n const [newItemIndex, keyProcessed] = processKeyboardNavigation(optionValues, itemIndex, event.key);\r\n // istanbul ignore else\r\n if (keyProcessed) {\r\n event.preventDefault();\r\n focusOption(newItemIndex);\r\n return;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (onKeyDown)\r\n onKeyDown(event);\r\n }, [focusValue, optionValues, focusOption, onKeyDown, handleValueChange]);\r\n\r\n const isInitialMount = React.useRef(true);\r\n\r\n React.useEffect(() => {\r\n const list = listRef.current as HTMLUListElement;\r\n\r\n if (isInitialMount.current) {\r\n isInitialMount.current = false;\r\n\r\n if (undefined !== focusValue) {\r\n const itemIndex = optionValues.findIndex((optionValue) => (optionValue.value === focusValue));\r\n focusOption(itemIndex);\r\n }\r\n } else {\r\n list.scrollTop = scrollTopRef.current;\r\n }\r\n }, [focusValue, focusOption, optionValues]);\r\n\r\n // istanbul ignore next\r\n const handleOnScroll = React.useCallback((_event: React.UIEvent<HTMLUListElement, UIEvent>) => {\r\n if (listRef.current)\r\n scrollTopRef.current = listRef.current.scrollTop;\r\n }, []);\r\n\r\n // istanbul ignore next\r\n const handleOnFocus = React.useCallback((_event: React.FocusEvent<HTMLUListElement>) => {\r\n if (!focusValue || 0 === focusValue.length) {\r\n if (currentValue) {\r\n setFocusValue(currentValue);\r\n } else {\r\n if (optionValues.length > 0)\r\n setFocusValue(optionValues[0].value);\r\n }\r\n }\r\n }, [currentValue, focusValue, optionValues]);\r\n\r\n return <ul\r\n className={classes}\r\n // If the listbox is not part of another widget, then it has a visible\r\n // label referenced by `aria-labelledby` on the element with role\r\n // `listbox`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n // If an `aria-label` is passed, we should skip `aria-labelledby` to\r\n // avoid confusion.\r\n aria-labelledby={ariaLabel ? undefined : ariaLabelledBy}\r\n aria-label={ariaLabel}\r\n // An element that contains or owns all the listbox options has role\r\n // listbox.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n role=\"listbox\"\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/examples/listbox/listbox-collapsible.html\r\n tabIndex={0}\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/examples/listbox/listbox-scrollable.html\r\n aria-activedescendant={makeId(currentValue, listId)}\r\n {...otherProps}\r\n ref={listRef}\r\n id={listId}\r\n onKeyDown={handleKeyDown}\r\n onScroll={handleOnScroll}\r\n data-value={currentValue}\r\n data-focusvalue={focusValue}\r\n onFocus={handleOnFocus}\r\n >\r\n <ListboxContext.Provider\r\n value={{\r\n listboxValue: currentValue,\r\n focusValue,\r\n listboxId: listId,\r\n onListboxValueChange: handleValueChange,\r\n listboxRef: listRef,\r\n }}\r\n >\r\n {children}\r\n </ListboxContext.Provider>\r\n </ul>;\r\n}\r\n\r\n/**\r\n * `ListboxItem` component.\r\n * @alpha\r\n */\r\nexport function ListboxItem(props: ListboxItemProps) {\r\n const {\r\n children,\r\n value,\r\n className,\r\n disabled,\r\n ...otherProps\r\n } = props;\r\n\r\n const {\r\n listboxValue,\r\n focusValue,\r\n listboxId,\r\n onListboxValueChange,\r\n } = React.useContext(ListboxContext);\r\n\r\n const hasFocus = focusValue === value;\r\n\r\n const classes = React.useMemo(() => classnames(\"core-listbox-item\", hasFocus && \"focused\", className), [className, hasFocus]);\r\n const itemRef = React.useRef<HTMLLIElement>(null);\r\n const isSelected = listboxValue === value;\r\n\r\n const handleClick = React.useCallback((event: React.MouseEvent<HTMLLIElement, MouseEvent>) => {\r\n event.preventDefault();\r\n // istanbul ignore next\r\n const selectedValue = event.currentTarget?.dataset?.value;\r\n // istanbul ignore else\r\n if (undefined !== selectedValue) {\r\n onListboxValueChange(selectedValue, event.ctrlKey);\r\n }\r\n }, [onListboxValueChange]);\r\n\r\n const getItemId = React.useCallback(() => {\r\n return makeId(value, listboxId);\r\n }, [listboxId, value]);\r\n\r\n return (\r\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\r\n <li\r\n // In a single-select listbox, the selected option has `aria-selected`\r\n // set to `true`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n aria-selected={isSelected}\r\n // Applicable to all host language elements regardless of whether a\r\n // `role` is applied.\r\n // https://www.w3.org/WAI/PF/aria/states_and_properties#global_states_header\r\n aria-disabled={disabled || undefined}\r\n // Each option in the listbox has role `option` and is a DOM descendant\r\n // of the element with role `listbox`.\r\n // https://www.w3.org/TR/wai-aria-practices-1.2/#Listbox\r\n role=\"option\"\r\n className={classes}\r\n {...otherProps}\r\n ref={itemRef}\r\n id={getItemId()}\r\n // used for css styling\r\n data-value={value}\r\n onClick={handleClick}\r\n >\r\n {children}\r\n </li>\r\n );\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageRenderer.d.ts","sourceRoot":"","sources":["../../../../src/core-react/notification/MessageRenderer.tsx"],"names":[],"mappings":"AAIA;;GAEG;;AAIH,OAAO,EAAiC,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,wBAAwB;IACxB,OAAO,EAAE,WAAW,CAAC;IACrB,uEAAuE;IACvE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"MessageRenderer.d.ts","sourceRoot":"","sources":["../../../../src/core-react/notification/MessageRenderer.tsx"],"names":[],"mappings":"AAIA;;GAEG;;AAIH,OAAO,EAAiC,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,wBAAwB;IACxB,OAAO,EAAE,WAAW,CAAC;IACrB,uEAAuE;IACvE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,sBAmE1D"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.MessageRenderer = void 0;
|
|
11
11
|
const React = require("react");
|
|
12
|
-
const
|
|
12
|
+
const dompurify_1 = require("dompurify"), DOMPurifyNS = dompurify_1;
|
|
13
13
|
const MessageType_1 = require("./MessageType");
|
|
14
14
|
/** React component renders a string, HTMLElement or React node in a `div` or `span`
|
|
15
15
|
* @public
|
|
@@ -21,7 +21,10 @@ function MessageRenderer(props) {
|
|
|
21
21
|
messageNode = React.createElement(OutElement, { className: props.className }, props.message);
|
|
22
22
|
}
|
|
23
23
|
else if ((0, MessageType_1.isHTMLElement)(props.message)) {
|
|
24
|
-
|
|
24
|
+
// the esm build of dompurify has a default import but the cjs build does not
|
|
25
|
+
// if there is a default export, use it (likely esm), otherwise use the namespace
|
|
26
|
+
// istanbul ignore next
|
|
27
|
+
const sanitizer = dompurify_1.default !== null && dompurify_1.default !== void 0 ? dompurify_1.default : DOMPurifyNS; // `sanitizer` is default function name for "jam3/no-sanitizer-with-danger" ESLint rule
|
|
25
28
|
let validAnchors = false;
|
|
26
29
|
let hasAnchors = false;
|
|
27
30
|
// verify that the tag has proper relationships
|
|
@@ -59,10 +62,10 @@ function MessageRenderer(props) {
|
|
|
59
62
|
let sanitizedHtml;
|
|
60
63
|
if (hasAnchors && validAnchors) {
|
|
61
64
|
// all anchors are valid. do not remove the target attr
|
|
62
|
-
sanitizedHtml = sanitizer(props.message.outerHTML, { ADD_ATTR: ["target"] });
|
|
65
|
+
sanitizedHtml = sanitizer.sanitize(props.message.outerHTML, { ADD_ATTR: ["target"] });
|
|
63
66
|
}
|
|
64
67
|
else {
|
|
65
|
-
sanitizedHtml = sanitizer(props.message.outerHTML);
|
|
68
|
+
sanitizedHtml = sanitizer.sanitize(props.message.outerHTML);
|
|
66
69
|
}
|
|
67
70
|
// we can safely disable jam3/no-sanitizer-with-danger as we are sanitizing above
|
|
68
71
|
// eslint-disable-next-line @typescript-eslint/naming-convention, jam3/no-sanitizer-with-danger
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageRenderer.js","sourceRoot":"","sources":["../../../../src/core-react/notification/MessageRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"MessageRenderer.js","sourceRoot":"","sources":["../../../../src/core-react/notification/MessageRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAE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AC,SAAS,CAAc,CAAC;KAChG;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAnED,0CAmEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Notification\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport DOMPurify, * as DOMPurifyNS from \"dompurify\";\r\nimport { isHTMLElement, isReactMessage, MessageType } from \"./MessageType\";\r\nimport { ClassNameProps } from \"../utils/Props\";\r\n\r\n// cSpell:ignore dompurify\r\n\r\n/** Properties for the [[MessageRenderer]] component\r\n * @public\r\n */\r\nexport interface MessageRendererProps extends ClassNameProps {\r\n /** Message to render */\r\n message: MessageType;\r\n /** Indicates whether to use a `span` or `div` element for rendering */\r\n useSpan?: boolean;\r\n}\r\n\r\n/** React component renders a string, HTMLElement or React node in a `div` or `span`\r\n * @public\r\n */\r\nexport function MessageRenderer(props: MessageRendererProps) {\r\n let messageNode = null;\r\n const OutElement = props.useSpan ? \"span\" : \"div\";\r\n\r\n if (typeof props.message === \"string\") {\r\n messageNode = <OutElement className={props.className}>{props.message}</OutElement>;\r\n } else if (isHTMLElement(props.message)) {\r\n // the esm build of dompurify has a default import but the cjs build does not\r\n // if there is a default export, use it (likely esm), otherwise use the namespace\r\n // istanbul ignore next\r\n const sanitizer = DOMPurify ?? DOMPurifyNS; // `sanitizer` is default function name for \"jam3/no-sanitizer-with-danger\" ESLint rule\r\n\r\n let validAnchors = false;\r\n let hasAnchors = false;\r\n\r\n // verify that the tag has proper relationships\r\n const isAnchorValid = (anchor: HTMLAnchorElement): boolean => {\r\n return anchor.hasAttribute(\"rel\") && (anchor.rel.includes(\"noopener\") || anchor.rel.includes(\"noreferrer\"));\r\n };\r\n\r\n // recursively check child elements for valid anchor tags\r\n const checkChildAnchors = (parent: Element) => {\r\n const children = Array.from(parent.children);\r\n for (const child of children){\r\n if (child.hasAttribute(\"target\") && (child as HTMLAnchorElement).target === \"_blank\") {\r\n hasAnchors = true;\r\n validAnchors = isAnchorValid(child as HTMLAnchorElement);\r\n if (!validAnchors) {\r\n return;\r\n }\r\n }\r\n checkChildAnchors(child);\r\n }\r\n };\r\n\r\n // check for anchor tags in the message that have target _blank also have a relationship that avoids security holes\r\n // https://web.dev/external-anchors-use-rel-noopener/\r\n // first check the message element\r\n /* istanbul ignore else */\r\n if (props.message.hasAttribute(\"target\") && (props.message as HTMLAnchorElement).target === \"_blank\") {\r\n hasAnchors = true;\r\n validAnchors = isAnchorValid(props.message as HTMLAnchorElement);\r\n } else {\r\n // if the message element is not an anchor, recursively verify it's children\r\n if (props.message.children) {\r\n checkChildAnchors(props.message);\r\n }\r\n }\r\n\r\n let sanitizedHtml;\r\n if (hasAnchors && validAnchors) {\r\n // all anchors are valid. do not remove the target attr\r\n sanitizedHtml = sanitizer.sanitize(props.message.outerHTML, {ADD_ATTR: [\"target\"]});\r\n } else {\r\n sanitizedHtml = sanitizer.sanitize(props.message.outerHTML);\r\n }\r\n\r\n // we can safely disable jam3/no-sanitizer-with-danger as we are sanitizing above\r\n // eslint-disable-next-line @typescript-eslint/naming-convention, jam3/no-sanitizer-with-danger\r\n messageNode = <OutElement className={props.className} dangerouslySetInnerHTML={{ __html: sanitizedHtml }} />;\r\n } else {\r\n /* istanbul ignore else */\r\n if (isReactMessage(props.message))\r\n messageNode = <OutElement className={props.className}>{props.message.reactNode}</OutElement>;\r\n }\r\n\r\n return messageNode;\r\n}\r\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { ConditionalStringValue } from "@itwin/appui-abstract";
|
|
6
|
+
import { IconSpec } from "../icons/IconComponent";
|
|
6
7
|
/** Icon Helper Class used to store the data needed to generate an <Icon> for use in any control that shows an icon.
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
@@ -18,6 +19,6 @@ export declare class IconHelper {
|
|
|
18
19
|
* @param iconSpec any supported variations of how an icon can be defined in an abstract item or IconProps.
|
|
19
20
|
* @param internalData a map supplied by the caller to store away react element if React.ReactNode
|
|
20
21
|
*/
|
|
21
|
-
static getIconData(iconSpec:
|
|
22
|
+
static getIconData(iconSpec: IconSpec, internalData?: Map<string, any>): string | ConditionalStringValue;
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=IconHelper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconHelper.d.ts","sourceRoot":"","sources":["../../../../src/core-react/utils/IconHelper.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"IconHelper.d.ts","sourceRoot":"","sources":["../../../../src/core-react/utils/IconHelper.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAQ,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAExD;;GAEG;AACH,qBAAa,UAAU;IACrB,WAAkB,YAAY,IAAI,MAAM,CAEvC;IACD;;;OAGG;WACW,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB,GAAG,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,SAAS;IA2BzI;;;;OAIG;WACW,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,sBAAsB;CAYhH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconHelper.js","sourceRoot":"","sources":["../../../../src/core-react/utils/IconHelper.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,0DAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"IconHelper.js","sourceRoot":"","sources":["../../../../src/core-react/utils/IconHelper.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,0DAA+D;AAC/D,0DAAwD;AAExD;;GAEG;AACH,MAAa,UAAU;IACd,MAAM,KAAK,YAAY;QAC5B,OAAO,yBAAyB,CAAC;IACnC,CAAC;IACD;;;OAGG;IACI,MAAM,CAAC,gBAAgB,CAAC,IAAuD,EAAE,YAA+B;QACrH,uBAAuB;QACvB,IAAI,CAAC,IAAI;YACP,OAAO,IAAI,CAAC;QAEd,uBAAuB;QACvB,IAAI,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;YAC5B,OAAO,oBAAC,oBAAI,IAAC,QAAQ,EAAE,IAAI,GAAI,CAAC;QAElC,qBAAqB;QACrB,IAAI,CAAC,CAAC,IAAI,YAAY,uCAAsB,CAAC,IAAI,OAAO,IAAI,KAAK,QAAQ;YACvE,OAAO,IAAI,CAAC;QAEd,MAAM,UAAU,GAAG,uCAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,UAAU;YACb,OAAO,IAAI,CAAC;QAEd,uBAAuB;QACvB,IAAI,UAAU,KAAK,UAAU,CAAC,YAAY,EAAE;YAC1C,uBAAuB;YACvB,IAAI,YAAY;gBACd,OAAO,oBAAC,oBAAI,IAAC,QAAQ,EAAE,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAoB,GAAI,CAAC;YAC1F,OAAO,IAAI,CAAC;SACb;QACD,OAAO,oBAAC,oBAAI,IAAC,QAAQ,EAAE,UAAU,GAAI,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,QAAkB,EAAE,YAA+B;QAC3E,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC;QAEnF,IAAI,YAAY,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,UAAU,CAAC,YAAY,EAAE;YAChF,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;SACrD;QAED,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,YAAY,uCAAsB;YACpE,OAAO,IAAI,CAAC;QAEd,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AApDD,gCAoDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utilities\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { ConditionalStringValue } from \"@itwin/appui-abstract\";\r\nimport { Icon, IconSpec } from \"../icons/IconComponent\";\r\n\r\n/** Icon Helper Class used to store the data needed to generate an <Icon> for use in any control that shows an icon.\r\n * @public\r\n */\r\nexport class IconHelper {\r\n public static get reactIconKey(): string {\r\n return \"#-react-iconspec-node-#\";\r\n }\r\n /** Returns an <Icon> ReactNode from the many ways an icon can be specified.\r\n * @param icon abstract icon specification.\r\n * @param internalData a map that may hold a React.ReactNode stored in an abstract item definition.\r\n */\r\n public static getIconReactNode(icon: string | ConditionalStringValue | React.ReactNode, internalData?: Map<string, any>): React.ReactNode {\r\n // istanbul ignore else\r\n if (!icon)\r\n return null;\r\n\r\n // istanbul ignore else\r\n if (React.isValidElement(icon))\r\n return <Icon iconSpec={icon} />;\r\n\r\n // istanbul ignore if\r\n if (!(icon instanceof ConditionalStringValue) && typeof icon !== \"string\")\r\n return null;\r\n\r\n const iconString = ConditionalStringValue.getValue(icon);\r\n if (!iconString)\r\n return null;\r\n\r\n // istanbul ignore else\r\n if (iconString === IconHelper.reactIconKey) {\r\n // istanbul ignore else\r\n if (internalData)\r\n return <Icon iconSpec={internalData.get(IconHelper.reactIconKey) as React.ReactNode} />;\r\n return null;\r\n }\r\n return <Icon iconSpec={iconString} />;\r\n }\r\n\r\n /** Returns an icon definition that can be stored in an abstract item definition. If the iconSpec specifies a ReactNode\r\n * then the react data is stored in the internalData map and the key to the react data is returned.\r\n * @param iconSpec any supported variations of how an icon can be defined in an abstract item or IconProps.\r\n * @param internalData a map supplied by the caller to store away react element if React.ReactNode\r\n */\r\n public static getIconData(iconSpec: IconSpec, internalData?: Map<string, any>): string | ConditionalStringValue {\r\n const icon = (React.isValidElement(iconSpec)) ? IconHelper.reactIconKey : iconSpec;\r\n\r\n if (internalData && typeof icon === \"string\" && icon === IconHelper.reactIconKey) {\r\n internalData.set(IconHelper.reactIconKey, iconSpec);\r\n }\r\n\r\n if (typeof icon === \"string\" || icon instanceof ConditionalStringValue)\r\n return icon;\r\n\r\n return \"\";\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* IconWebComponent loads icon from an svg path
|
|
6
|
+
*/
|
|
7
|
+
export declare class IconWebComponent extends HTMLElement {
|
|
8
|
+
private connectedCallback;
|
|
9
|
+
private loadSvg;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=IconWebComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconWebComponent.d.ts","sourceRoot":"","sources":["../../../../src/core-react/utils/IconWebComponent.ts"],"names":[],"mappings":"AAMA;;GAEG;AAMH;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;YACjC,iBAAiB;YAKjB,OAAO;CAqBtB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
// istanbul ignore file
|
|
7
|
+
// IconWebComponent requires in-browser testing
|
|
8
|
+
/** @packageDocumentation
|
|
9
|
+
* @module Utilities
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.IconWebComponent = void 0;
|
|
13
|
+
const appui_abstract_1 = require("@itwin/appui-abstract");
|
|
14
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
+
const UiCore_1 = require("../UiCore");
|
|
16
|
+
/**
|
|
17
|
+
* IconWebComponent loads icon from an svg path
|
|
18
|
+
*/
|
|
19
|
+
class IconWebComponent extends HTMLElement {
|
|
20
|
+
async connectedCallback() {
|
|
21
|
+
await this.loadSvg();
|
|
22
|
+
this.dispatchEvent(new CustomEvent("load"));
|
|
23
|
+
}
|
|
24
|
+
async loadSvg() {
|
|
25
|
+
await fetch(this.getAttribute("src") || "")
|
|
26
|
+
.catch((_error) => {
|
|
27
|
+
core_bentley_1.Logger.logError(UiCore_1.UiCore.loggerCategory(this), "Unable to load icon.");
|
|
28
|
+
})
|
|
29
|
+
.then(async (response) => {
|
|
30
|
+
if (response && response.ok) {
|
|
31
|
+
return response.text();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new appui_abstract_1.UiError(UiCore_1.UiCore.loggerCategory(this), "Unable to load icon.");
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.then((str) => {
|
|
38
|
+
if (str !== undefined) {
|
|
39
|
+
return (new window.DOMParser()).parseFromString(str, "text/xml");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new appui_abstract_1.UiError(UiCore_1.UiCore.loggerCategory(this), "Unable to load icon.");
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.then((data) => this.append(data.documentElement));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.IconWebComponent = IconWebComponent;
|
|
49
|
+
//# sourceMappingURL=IconWebComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconWebComponent.js","sourceRoot":"","sources":["../../../../src/core-react/utils/IconWebComponent.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,uBAAuB;AACvB,+CAA+C;AAC/C;;GAEG;;;AAEH,0DAAgD;AAChD,sDAA6C;AAC7C,sCAAmC;AAEnC;;GAEG;AACH,MAAa,gBAAiB,SAAQ,WAAW;IACvC,KAAK,CAAC,iBAAiB;QAC7B,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;aACxC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,qBAAM,CAAC,QAAQ,CAAC,eAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC,CAAC;QACvE,CAAC,CAAC;aACD,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YACvB,IAAI,QAAQ,IAAI,QAAQ,CAAC,EAAE,EAAE;gBAC3B,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;aACxB;iBAAM;gBACL,MAAM,IAAI,wBAAO,CAAE,eAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC,CAAC;aACzE;QACH,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACZ,IAAI,GAAG,KAAK,SAAS,EAAE;gBACrB,OAAO,CAAC,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;aAClE;iBAAM;gBACL,MAAM,IAAI,wBAAO,CAAE,eAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC,CAAC;aACzE;QACH,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IACvD,CAAC;CACF;AA3BD,4CA2BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n// istanbul ignore file\r\n// IconWebComponent requires in-browser testing\r\n/** @packageDocumentation\r\n * @module Utilities\r\n */\r\n\r\nimport { UiError } from \"@itwin/appui-abstract\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport { UiCore } from \"../UiCore\";\r\n\r\n/**\r\n * IconWebComponent loads icon from an svg path\r\n */\r\nexport class IconWebComponent extends HTMLElement {\r\n private async connectedCallback() {\r\n await this.loadSvg();\r\n this.dispatchEvent(new CustomEvent(\"load\"));\r\n }\r\n\r\n private async loadSvg() {\r\n await fetch(this.getAttribute(\"src\") || \"\")\r\n .catch((_error) => {\r\n Logger.logError(UiCore.loggerCategory(this), \"Unable to load icon.\");\r\n })\r\n .then(async (response) => {\r\n if (response && response.ok) {\r\n return response.text();\r\n } else {\r\n throw new UiError (UiCore.loggerCategory(this), \"Unable to load icon.\");\r\n }\r\n })\r\n .then((str) => {\r\n if (str !== undefined) {\r\n return (new window.DOMParser()).parseFromString(str, \"text/xml\");\r\n } else {\r\n throw new UiError (UiCore.loggerCategory(this), \"Unable to load icon.\");\r\n }\r\n })\r\n .then((data) => this.append(data.documentElement));\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
/** Hook that will show a popup window
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export declare function useCrossOriginPopup(visible: boolean, url: string | undefined, title: string, width: number, height: number, onClose: () => void): void;
|
|
8
|
+
//# sourceMappingURL=useCrossOriginPopup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCrossOriginPopup.d.ts","sourceRoot":"","sources":["../../../../../src/core-react/utils/hooks/useCrossOriginPopup.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAKH;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,QAqF/I"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Utilities
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.useCrossOriginPopup = void 0;
|
|
11
|
+
const React = require("react");
|
|
12
|
+
const useInterval_1 = require("./useInterval");
|
|
13
|
+
/** Hook that will show a popup window
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
function useCrossOriginPopup(visible, url, title, width, height, onClose) {
|
|
17
|
+
const [checkPopupAliveDelay, setCheckPopupAliveDelay] = React.useState();
|
|
18
|
+
// ONLY re-render the popup when visibility changes, any other changes get deferred until next visibility change
|
|
19
|
+
// hence the massive use of 'useRef'
|
|
20
|
+
const popupWindow = React.useRef();
|
|
21
|
+
const savedUrl = React.useRef(url);
|
|
22
|
+
const savedTitle = React.useRef(title);
|
|
23
|
+
const savedWidth = React.useRef(width);
|
|
24
|
+
const savedHeight = React.useRef(height);
|
|
25
|
+
const savedOnClose = React.useRef(onClose);
|
|
26
|
+
React.useEffect(() => { savedUrl.current = url; }, [url]);
|
|
27
|
+
React.useEffect(() => { savedTitle.current = title; }, [title]);
|
|
28
|
+
React.useEffect(() => { savedWidth.current = width; }, [width]);
|
|
29
|
+
React.useEffect(() => { savedHeight.current = height; }, [height]);
|
|
30
|
+
React.useEffect(() => { savedOnClose.current = onClose; }, [onClose]);
|
|
31
|
+
// Cleanup method after a popup closure. Also calls the OnClose callback.
|
|
32
|
+
const handleClosedPopup = React.useCallback(() => {
|
|
33
|
+
savedOnClose.current();
|
|
34
|
+
setCheckPopupAliveDelay(undefined);
|
|
35
|
+
popupWindow.current = undefined;
|
|
36
|
+
}, []);
|
|
37
|
+
const closePopup = React.useCallback(() => {
|
|
38
|
+
if (popupWindow.current !== undefined) {
|
|
39
|
+
popupWindow.current.close(); // Manually close the popup
|
|
40
|
+
handleClosedPopup();
|
|
41
|
+
}
|
|
42
|
+
}, [handleClosedPopup]);
|
|
43
|
+
const checkPopupClosed = React.useCallback(() => {
|
|
44
|
+
var _a;
|
|
45
|
+
if ((_a = popupWindow.current) === null || _a === void 0 ? void 0 : _a.closed) {
|
|
46
|
+
// Popup has been closed by end-user, inform our host and cleanup
|
|
47
|
+
handleClosedPopup();
|
|
48
|
+
}
|
|
49
|
+
}, [handleClosedPopup]);
|
|
50
|
+
// Close popup when parent window get closed
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
window.onbeforeunload = (_event) => { closePopup(); };
|
|
53
|
+
return () => {
|
|
54
|
+
window.onbeforeunload = null;
|
|
55
|
+
};
|
|
56
|
+
}, [closePopup]);
|
|
57
|
+
// Whenever the hook is unloaded, make sure the underlying popup get closed.
|
|
58
|
+
// Note: An interval is used to check if popup was closed by user: because we access
|
|
59
|
+
// a cross domain resource inside the popup, we don't have access to popup window events.
|
|
60
|
+
// As a workaround, we periodically check if popup is still alive.
|
|
61
|
+
// Reference: https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
return () => {
|
|
64
|
+
closePopup();
|
|
65
|
+
};
|
|
66
|
+
}, [closePopup]);
|
|
67
|
+
// Timer that checks if popup was closed by end-user
|
|
68
|
+
(0, useInterval_1.useInterval)(checkPopupClosed, checkPopupAliveDelay);
|
|
69
|
+
// ==> Main render effect
|
|
70
|
+
// Monitors visibility changes and open/close the popup accordingly.
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
// If visible and a popup window is not already open, open a new popup window
|
|
73
|
+
if (visible && popupWindow.current === undefined) {
|
|
74
|
+
const popup = window.open(savedUrl.current, savedTitle.current, `width=${savedWidth.current},height=${savedHeight.current}`);
|
|
75
|
+
if (popup) {
|
|
76
|
+
popup.focus();
|
|
77
|
+
popupWindow.current = popup;
|
|
78
|
+
// Start and interval that will check if popup got closed by user
|
|
79
|
+
setCheckPopupAliveDelay(1000);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// If not visible but a previous popup window is still open, close it.
|
|
83
|
+
if (!visible && popupWindow.current !== undefined) {
|
|
84
|
+
popupWindow.current.close();
|
|
85
|
+
handleClosedPopup();
|
|
86
|
+
}
|
|
87
|
+
}, [handleClosedPopup, visible]);
|
|
88
|
+
}
|
|
89
|
+
exports.useCrossOriginPopup = useCrossOriginPopup;
|
|
90
|
+
//# sourceMappingURL=useCrossOriginPopup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCrossOriginPopup.js","sourceRoot":"","sources":["../../../../../src/core-react/utils/hooks/useCrossOriginPopup.tsx"],"names":[],"mappings":";AAAA;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EAAE;YACV,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,oDAAoD;IACpD,IAAA,yBAAW,EAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IAEpD,yBAAyB;IACzB,oEAAoE;IACpE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,6EAA6E;QAC7E,IAAI,OAAO,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS,EAAE;YAChD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,WAAW,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7H,IAAI,KAAK,EAAE;gBACT,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;gBAE5B,iEAAiE;gBACjE,uBAAuB,CAAC,IAAI,CAAC,CAAC;aAC/B;SACF;QAED,sEAAsE;QACtE,IAAI,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS,EAAE;YACjD,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAE5B,iBAAiB,EAAE,CAAC;SACrB;IAEH,CAAC,EAAE,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC;AArFD,kDAqFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utilities\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport {useInterval} from \"./useInterval\";\r\n\r\n/** Hook that will show a popup window\r\n * @beta\r\n */\r\nexport function useCrossOriginPopup(visible: boolean, url: string | undefined, title: string, width: number, height: number, onClose: () => void) {\r\n\r\n const [checkPopupAliveDelay, setCheckPopupAliveDelay] = React.useState<number | undefined>();\r\n\r\n // ONLY re-render the popup when visibility changes, any other changes get deferred until next visibility change\r\n // hence the massive use of 'useRef'\r\n const popupWindow = React.useRef<Window>();\r\n const savedUrl = React.useRef(url);\r\n const savedTitle = React.useRef(title);\r\n const savedWidth = React.useRef(width);\r\n const savedHeight = React.useRef(height);\r\n const savedOnClose = React.useRef(onClose);\r\n\r\n React.useEffect(() => { savedUrl.current = url; }, [url]);\r\n React.useEffect(() => { savedTitle.current = title; }, [title]);\r\n React.useEffect(() => { savedWidth.current = width; }, [width]);\r\n React.useEffect(() => { savedHeight.current = height; }, [height]);\r\n React.useEffect(() => { savedOnClose.current = onClose; }, [onClose]);\r\n\r\n // Cleanup method after a popup closure. Also calls the OnClose callback.\r\n const handleClosedPopup = React.useCallback(() => {\r\n savedOnClose.current();\r\n setCheckPopupAliveDelay(undefined);\r\n popupWindow.current = undefined;\r\n }, []);\r\n\r\n const closePopup = React.useCallback(() => {\r\n if (popupWindow.current !== undefined) {\r\n popupWindow.current.close(); // Manually close the popup\r\n handleClosedPopup();\r\n }\r\n }, [handleClosedPopup]);\r\n\r\n const checkPopupClosed = React.useCallback(() => {\r\n if (popupWindow.current?.closed) {\r\n // Popup has been closed by end-user, inform our host and cleanup\r\n handleClosedPopup();\r\n }\r\n }, [handleClosedPopup]);\r\n\r\n // Close popup when parent window get closed\r\n React.useEffect(() => {\r\n window.onbeforeunload = (_event) => {closePopup();};\r\n return () => {\r\n window.onbeforeunload = null;\r\n };\r\n }, [closePopup]);\r\n\r\n // Whenever the hook is unloaded, make sure the underlying popup get closed.\r\n // Note: An interval is used to check if popup was closed by user: because we access\r\n // a cross domain resource inside the popup, we don't have access to popup window events.\r\n // As a workaround, we periodically check if popup is still alive.\r\n // Reference: https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128\r\n React.useEffect(() => {\r\n return () => {\r\n closePopup();\r\n };\r\n }, [closePopup]);\r\n\r\n // Timer that checks if popup was closed by end-user\r\n useInterval(checkPopupClosed, checkPopupAliveDelay);\r\n\r\n // ==> Main render effect\r\n // Monitors visibility changes and open/close the popup accordingly.\r\n React.useEffect(() => {\r\n // If visible and a popup window is not already open, open a new popup window\r\n if (visible && popupWindow.current === undefined) {\r\n const popup = window.open(savedUrl.current, savedTitle.current, `width=${savedWidth.current},height=${savedHeight.current}`);\r\n if (popup) {\r\n popup.focus();\r\n popupWindow.current = popup;\r\n\r\n // Start and interval that will check if popup got closed by user\r\n setCheckPopupAliveDelay(1000);\r\n }\r\n }\r\n\r\n // If not visible but a previous popup window is still open, close it.\r\n if (!visible && popupWindow.current !== undefined) {\r\n popupWindow.current.close();\r\n\r\n handleClosedPopup();\r\n }\r\n\r\n }, [handleClosedPopup, visible]);\r\n}\r\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Hook that create an interval and clears it when unloaded
|
|
2
|
+
* Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md
|
|
3
|
+
* @beta
|
|
4
|
+
*/
|
|
5
|
+
export declare function useInterval(callback: (...args: any[]) => void, delay: number | undefined): void;
|
|
6
|
+
//# sourceMappingURL=useInterval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../../../../../src/core-react/utils/hooks/useInterval.tsx"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,QAoBxF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterval = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
/** @packageDocumentation
|
|
9
|
+
* @module Utilities
|
|
10
|
+
*/
|
|
11
|
+
const React = require("react");
|
|
12
|
+
/** Hook that create an interval and clears it when unloaded
|
|
13
|
+
* Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
function useInterval(callback, delay) {
|
|
17
|
+
const savedCallback = React.useRef(callback);
|
|
18
|
+
// Remember the latest function.
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
savedCallback.current = callback;
|
|
21
|
+
}, [callback]);
|
|
22
|
+
// Set up the interval.
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
function tick() {
|
|
25
|
+
savedCallback.current();
|
|
26
|
+
}
|
|
27
|
+
if (delay !== undefined) {
|
|
28
|
+
const id = setInterval(tick, delay);
|
|
29
|
+
return (() => { clearInterval(id); });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}, [delay]);
|
|
35
|
+
}
|
|
36
|
+
exports.useInterval = useInterval;
|
|
37
|
+
//# sourceMappingURL=useInterval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../../../../../src/core-react/utils/hooks/useInterval.tsx"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,+BAA+B;AAE/B;;;GAGG;AACH,SAAgB,WAAW,CAAC,QAAkC,EAAE,KAAyB;IACvF,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAA2B,QAAQ,CAAC,CAAC;IAEvE,gCAAgC;IAChC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC;IACnC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,uBAAuB;IACvB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,SAAS,IAAI;YACX,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,CAAC;AApBD,kCAoBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utilities\r\n */\r\nimport * as React from \"react\";\r\n\r\n/** Hook that create an interval and clears it when unloaded\r\n * Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md\r\n * @beta\r\n */\r\nexport function useInterval(callback: (...args: any[]) => void, delay: number | undefined) {\r\n const savedCallback = React.useRef<(...args: any[]) => void>(callback);\r\n\r\n // Remember the latest function.\r\n React.useEffect(() => {\r\n savedCallback.current = callback;\r\n }, [callback]);\r\n\r\n // Set up the interval.\r\n React.useEffect(() => {\r\n function tick() {\r\n savedCallback.current();\r\n }\r\n if (delay !== undefined) {\r\n const id = setInterval(tick, delay);\r\n return (() => { clearInterval(id); });\r\n } else {\r\n return undefined;\r\n }\r\n }, [delay]);\r\n}\r\n"]}
|
|
@@ -58,7 +58,7 @@ function useResizeObserver(onResize) {
|
|
|
58
58
|
owningWindowRef.current = target.ownerDocument.defaultView;
|
|
59
59
|
// istanbul ignore else
|
|
60
60
|
if (owningWindowRef.current) {
|
|
61
|
-
owningWindowRef.current.addEventListener("
|
|
61
|
+
owningWindowRef.current.addEventListener("unload", resizeObserverCleanup);
|
|
62
62
|
// using requestAnimationFrame to stop the "ResizeObserver loop completed with undelivered notifications." and
|
|
63
63
|
// "ResizeObserver loop limit exceeded" messages reported to window.onError
|
|
64
64
|
rafRef.current = owningWindowRef.current.requestAnimationFrame(() => processResize(target));
|
|
@@ -146,7 +146,7 @@ function useLayoutResizeObserver(inElement, onResize) {
|
|
|
146
146
|
owningWindowRef.current = target.ownerDocument.defaultView;
|
|
147
147
|
// istanbul ignore else
|
|
148
148
|
if (owningWindowRef.current) {
|
|
149
|
-
owningWindowRef.current.addEventListener("
|
|
149
|
+
owningWindowRef.current.addEventListener("unload", resizeObserverCleanup);
|
|
150
150
|
// using requestAnimationFrame to stop the "ResizeObserver loop completed with undelivered notifications." and
|
|
151
151
|
// "ResizeObserver loop limit exceeded" messages reported to window.onError
|
|
152
152
|
rafRef.current = owningWindowRef.current.requestAnimationFrame(() => processResize(target));
|