@pega/cosmos-react-core 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSelectInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ComboBox/MultiSelectInput/MultiSelectInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAWlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAiB9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,eAAO,MAAM,sBAAsB,yGA4BjC,CAAC;AAIH,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CAkO7E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"MultiSelectInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ComboBox/MultiSelectInput/MultiSelectInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAWlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAiB9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,eAAO,MAAM,sBAAsB,yGA4BjC,CAAC;AAIH,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CAmO7E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -59,6 +59,7 @@ const MultiSelectInput = forwardRef(function MultiSelectInput(props, ref) {
59
59
  setFocusDescendant(null);
60
60
  },
61
61
  pauseDescendantEvaluation,
62
+ preventInitialScroll: true,
62
63
  onClick: (el) => {
63
64
  el.click();
64
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSelectInput.js","sourceRoot":"","sources":["../../../../src/components/ComboBox/MultiSelectInput/MultiSelectInput.ts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ACV,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,KAAK;wBACZ,0CAA0C;wBAC1C,QAAQ,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,EAChC,SAAS,EAAE,cAAc,EACzB,QAAQ,EAAE,QAAQ,IAAI,CAAC,QAAQ,EAC/B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EACvD,YAAY,EAAC,KAAK,EAClB,SAAS,EAAE,SAAS,mBACL,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,KACzD,SAAS,EACb,QAAQ,EAAE,SAAS,GACnB,IACG,EACN,OAAO,EAER,KAAC,kBAAkB,IAAC,EAAE,EAAE,GAAG,EAAE,mBAAmB,YAC7C,GAAG,CAAC,CAAC,qBAAqB,CAAC,GAAG,GACZ,EACrB,KAAC,kBAAkB,IAAC,EAAE,EAAE,GAAG,EAAE,oBAAoB,YAC9C,CAAC,CAAC,8BAA8B,CAAC,GACf,IAChB,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import {\n FunctionComponent,\n forwardRef,\n Ref,\n PropsWithoutRef,\n KeyboardEvent,\n useRef,\n useCallback,\n useMemo,\n useState,\n useEffect,\n MouseEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport { ForwardProps } from '../../../types';\nimport { defaultThemeProp } from '../../../theme';\nimport Selectable, { StyledSelectable } from '../../Badges/Selection';\nimport { StyledFormControl } from '../../FormControl';\nimport Flex from '../../Flex';\nimport {\n useConsolidatedRef,\n useActiveDescendant,\n useDirection,\n useI18n,\n useUID\n} from '../../../hooks';\nimport { cap, tryCatch } from '../../../utils';\nimport { StyledBareButton } from '../../Button/BareButton';\nimport VisuallyHiddenText from '../../VisuallyHiddenText';\nimport { StyledSelectInput } from '../ComboBox.styles';\n\nimport { MultiSelectInputProps } from './MultiSelectInput.types';\n\nexport const StyledMultiSelectInput = styled(StyledSelectInput)(({ theme }) => {\n const { background } = theme.components.badges.selectable.base;\n const { 'foreground-color': foreground } = theme.base.palette;\n const boxShadowColor = tryCatch(() => transparentize(0.45, foreground));\n\n return css`\n cursor: text;\n\n ul {\n list-style: none;\n display: contents;\n\n &[data-active-scope='true'] ${StyledSelectable}[data-current='true'] {\n color: ${theme.base.palette.interactive};\n box-shadow: 0 0 0.5rem -0.125rem ${boxShadowColor}, inset 0 0 0 0.125rem ${background};\n outline: none;\n\n ${StyledBareButton} {\n color: ${theme.base.palette.interactive};\n }\n }\n }\n\n input {\n width: 8ch;\n height: 1.125rem;\n }\n `;\n});\n\nStyledMultiSelectInput.defaultProps = defaultThemeProp;\n\nconst MultiSelectInput: FunctionComponent<MultiSelectInputProps & ForwardProps> = forwardRef(\n function MultiSelectInput(\n props: PropsWithoutRef<MultiSelectInputProps>,\n ref: Ref<HTMLInputElement>\n ) {\n const {\n selected = [],\n value,\n onRemove,\n onChange,\n onKeyDown,\n onResolveSuggestion,\n actions,\n readOnly,\n disabled,\n status,\n placeholder,\n autoFocus,\n pauseDescendantEvaluation,\n onSelectedFocus,\n onSelectedBlur,\n 'aria-controls': ariaControls,\n ...restProps\n } = props;\n const t = useI18n();\n const id = useUID();\n\n const inputRef = useConsolidatedRef<HTMLInputElement>(ref);\n const listRef = useRef<HTMLUListElement>(null);\n const [focusDescendant, setFocusDescendant] = useState<HTMLElement | null>(null);\n const [activeItemId, setActiveItemId] = useState<string | null>(null);\n const { start, end } = useDirection();\n\n const uadConfig = useMemo(\n () => ({\n focusEl: inputRef.current,\n scope: listRef.current,\n selector: 'li[role=\"option\"]',\n orientation: 'horizontal' as const,\n focusReturnEl: focusDescendant,\n clearFocusReturn: () => {\n setFocusDescendant(null);\n },\n pauseDescendantEvaluation,\n onClick: (el: HTMLElement) => {\n el.click();\n }\n }),\n [pauseDescendantEvaluation, selected, focusDescendant]\n );\n\n const { activeDescendant } = useActiveDescendant(uadConfig, [selected]);\n\n const handleSelectedRemoval = useCallback(\n (selectionId, idx) => {\n if (!pauseDescendantEvaluation) {\n if (idx === selected.length - 1) {\n // If removing last selected item\n if (selected.length > 1) {\n // If other selected items, focus previous\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[idx - 1] as HTMLElement) ||\n null\n );\n } else {\n // Blur selected if final only item removed\n onSelectedBlur?.();\n }\n } else if (selected.length > 1) {\n // If not last item removed and other selected items, focus next\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[idx + 1] as HTMLElement) ||\n null\n );\n }\n }\n onRemove?.(selectionId, idx);\n inputRef.current?.focus();\n },\n [selected, onRemove, onSelectedBlur, uadConfig]\n );\n\n useEffect(() => {\n // Maintain active item & prev. val only as it changes.\n if (activeDescendant?.id && activeDescendant.id !== activeItemId) {\n setActiveItemId(activeDescendant.id);\n }\n }, [activeDescendant]);\n\n const onInputKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (selected.length && inputRef.current?.selectionStart === 0) {\n const lastIndex = selected.length - 1;\n if (pauseDescendantEvaluation && e.key === `Arrow${cap(start)}`) {\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[lastIndex] as HTMLElement) ||\n null\n );\n onSelectedFocus?.();\n }\n\n const lastSelectableId = listRef.current?.querySelectorAll(uadConfig.selector)[lastIndex]\n ?.id;\n const onLastItem = activeItemId === lastSelectableId;\n\n if (\n !pauseDescendantEvaluation &&\n ((onLastItem && e.key === `Arrow${cap(end)}`) || e.key === 'ArrowDown')\n ) {\n onSelectedBlur?.();\n }\n\n if (['Backspace', 'Delete'].includes(e.key) && !(readOnly || disabled)) {\n handleSelectedRemoval(selected[lastIndex].id, lastIndex);\n }\n }\n onKeyDown?.(e);\n },\n [\n pauseDescendantEvaluation,\n activeItemId,\n onKeyDown,\n handleSelectedRemoval,\n selected,\n readOnly,\n disabled\n ]\n );\n\n const ariaDescribedBy = useMemo(() => {\n return onChange\n ? `${id}-inputDescription ${id}-searchDescription`\n : `${id}-inputDescription`;\n }, [id]);\n\n return (\n <Flex\n as={StyledMultiSelectInput}\n forwardedAs={StyledFormControl}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', justify: 'between' }}\n {...{\n readOnly,\n disabled,\n status\n }}\n >\n <Flex\n container={{ alignContent: 'center', wrap: 'wrap', rowGap: 0.5, colGap: 0.25, pad: 0.25 }}\n item={{ grow: 1 }}\n onClick={(e: MouseEvent<HTMLDivElement>) => {\n if (\n e.target instanceof HTMLElement &&\n !e.currentTarget.contains(e.target.closest('li'))\n ) {\n inputRef.current?.focus();\n inputRef.current?.click();\n }\n }}\n >\n {selected.length > 0 && (\n <ul ref={listRef} id={id} role='listbox' aria-label={t('selected_items')}>\n {selected.map((element, idx) => {\n return (\n <Selectable\n as='li'\n key={element.id}\n role='option'\n id={element.id.toString()}\n status={status}\n onClick={e => {\n const mouseClick = e.detail !== 0;\n\n if (!readOnly && !disabled && !mouseClick) {\n handleSelectedRemoval(element.id, idx);\n }\n }}\n onRemove={() => {\n if (!readOnly && !disabled) {\n handleSelectedRemoval(element.id, idx);\n }\n }}\n onKeyDown={(e: KeyboardEvent<Element>) => {\n // prevent browser's Back on FF\n if (e.key === 'Backspace') e.preventDefault();\n }}\n tabIndex='-1'\n aria-label={`${t('remove')} ${element.text}`}\n aria-describedby={ariaDescribedBy}\n >\n {element.text}\n </Selectable>\n );\n })}\n </ul>\n )}\n <Flex\n item={{ grow: 1 }}\n as='input'\n size={1}\n ref={inputRef}\n value={value}\n // no-op avoids react uncontrolled warning\n onChange={onChange || (() => {})}\n onKeyDown={onInputKeyDown}\n readOnly={readOnly || !onChange}\n disabled={disabled}\n placeholder={selected?.length ? undefined : placeholder}\n autoComplete='off'\n autoFocus={autoFocus}\n aria-controls={!pauseDescendantEvaluation ? id : ariaControls}\n {...restProps}\n required={undefined}\n />\n </Flex>\n {actions}\n\n <VisuallyHiddenText id={`${id}-inputDescription`}>\n {`${t('combobox_open_close')} `}\n </VisuallyHiddenText>\n <VisuallyHiddenText id={`${id}-searchDescription`}>\n {t('combobox_search_instructions')}\n </VisuallyHiddenText>\n </Flex>\n );\n }\n);\n\nexport default MultiSelectInput;\n"]}
1
+ {"version":3,"file":"MultiSelectInput.js","sourceRoot":"","sources":["../../../../src/components/ComboBox/MultiSelectInput/MultiSelectInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,MAAM,EACN,WAAW,EACX,OAAO,EACP,QAAQ,EACR,SAAS,EAEV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,OAAO,EACP,MAAM,EACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5E,MAAM,EAAE,UAAU,EAAE,GAAG,KAA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o,\n useState,\n useEffect,\n MouseEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport { ForwardProps } from '../../../types';\nimport { defaultThemeProp } from '../../../theme';\nimport Selectable, { StyledSelectable } from '../../Badges/Selection';\nimport { StyledFormControl } from '../../FormControl';\nimport Flex from '../../Flex';\nimport {\n useConsolidatedRef,\n useActiveDescendant,\n useDirection,\n useI18n,\n useUID\n} from '../../../hooks';\nimport { cap, tryCatch } from '../../../utils';\nimport { StyledBareButton } from '../../Button/BareButton';\nimport VisuallyHiddenText from '../../VisuallyHiddenText';\nimport { StyledSelectInput } from '../ComboBox.styles';\n\nimport { MultiSelectInputProps } from './MultiSelectInput.types';\n\nexport const StyledMultiSelectInput = styled(StyledSelectInput)(({ theme }) => {\n const { background } = theme.components.badges.selectable.base;\n const { 'foreground-color': foreground } = theme.base.palette;\n const boxShadowColor = tryCatch(() => transparentize(0.45, foreground));\n\n return css`\n cursor: text;\n\n ul {\n list-style: none;\n display: contents;\n\n &[data-active-scope='true'] ${StyledSelectable}[data-current='true'] {\n color: ${theme.base.palette.interactive};\n box-shadow: 0 0 0.5rem -0.125rem ${boxShadowColor}, inset 0 0 0 0.125rem ${background};\n outline: none;\n\n ${StyledBareButton} {\n color: ${theme.base.palette.interactive};\n }\n }\n }\n\n input {\n width: 8ch;\n height: 1.125rem;\n }\n `;\n});\n\nStyledMultiSelectInput.defaultProps = defaultThemeProp;\n\nconst MultiSelectInput: FunctionComponent<MultiSelectInputProps & ForwardProps> = forwardRef(\n function MultiSelectInput(\n props: PropsWithoutRef<MultiSelectInputProps>,\n ref: Ref<HTMLInputElement>\n ) {\n const {\n selected = [],\n value,\n onRemove,\n onChange,\n onKeyDown,\n onResolveSuggestion,\n actions,\n readOnly,\n disabled,\n status,\n placeholder,\n autoFocus,\n pauseDescendantEvaluation,\n onSelectedFocus,\n onSelectedBlur,\n 'aria-controls': ariaControls,\n ...restProps\n } = props;\n const t = useI18n();\n const id = useUID();\n\n const inputRef = useConsolidatedRef<HTMLInputElement>(ref);\n const listRef = useRef<HTMLUListElement>(null);\n const [focusDescendant, setFocusDescendant] = useState<HTMLElement | null>(null);\n const [activeItemId, setActiveItemId] = useState<string | null>(null);\n const { start, end } = useDirection();\n\n const uadConfig = useMemo(\n () => ({\n focusEl: inputRef.current,\n scope: listRef.current,\n selector: 'li[role=\"option\"]',\n orientation: 'horizontal' as const,\n focusReturnEl: focusDescendant,\n clearFocusReturn: () => {\n setFocusDescendant(null);\n },\n pauseDescendantEvaluation,\n preventInitialScroll: true,\n onClick: (el: HTMLElement) => {\n el.click();\n }\n }),\n [pauseDescendantEvaluation, selected, focusDescendant]\n );\n\n const { activeDescendant } = useActiveDescendant(uadConfig, [selected]);\n\n const handleSelectedRemoval = useCallback(\n (selectionId, idx) => {\n if (!pauseDescendantEvaluation) {\n if (idx === selected.length - 1) {\n // If removing last selected item\n if (selected.length > 1) {\n // If other selected items, focus previous\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[idx - 1] as HTMLElement) ||\n null\n );\n } else {\n // Blur selected if final only item removed\n onSelectedBlur?.();\n }\n } else if (selected.length > 1) {\n // If not last item removed and other selected items, focus next\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[idx + 1] as HTMLElement) ||\n null\n );\n }\n }\n onRemove?.(selectionId, idx);\n inputRef.current?.focus();\n },\n [selected, onRemove, onSelectedBlur, uadConfig]\n );\n\n useEffect(() => {\n // Maintain active item & prev. val only as it changes.\n if (activeDescendant?.id && activeDescendant.id !== activeItemId) {\n setActiveItemId(activeDescendant.id);\n }\n }, [activeDescendant]);\n\n const onInputKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (selected.length && inputRef.current?.selectionStart === 0) {\n const lastIndex = selected.length - 1;\n if (pauseDescendantEvaluation && e.key === `Arrow${cap(start)}`) {\n setFocusDescendant(\n (listRef.current?.querySelectorAll(uadConfig.selector)[lastIndex] as HTMLElement) ||\n null\n );\n onSelectedFocus?.();\n }\n\n const lastSelectableId = listRef.current?.querySelectorAll(uadConfig.selector)[lastIndex]\n ?.id;\n const onLastItem = activeItemId === lastSelectableId;\n\n if (\n !pauseDescendantEvaluation &&\n ((onLastItem && e.key === `Arrow${cap(end)}`) || e.key === 'ArrowDown')\n ) {\n onSelectedBlur?.();\n }\n\n if (['Backspace', 'Delete'].includes(e.key) && !(readOnly || disabled)) {\n handleSelectedRemoval(selected[lastIndex].id, lastIndex);\n }\n }\n onKeyDown?.(e);\n },\n [\n pauseDescendantEvaluation,\n activeItemId,\n onKeyDown,\n handleSelectedRemoval,\n selected,\n readOnly,\n disabled\n ]\n );\n\n const ariaDescribedBy = useMemo(() => {\n return onChange\n ? `${id}-inputDescription ${id}-searchDescription`\n : `${id}-inputDescription`;\n }, [id]);\n\n return (\n <Flex\n as={StyledMultiSelectInput}\n forwardedAs={StyledFormControl}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', justify: 'between' }}\n {...{\n readOnly,\n disabled,\n status\n }}\n >\n <Flex\n container={{ alignContent: 'center', wrap: 'wrap', rowGap: 0.5, colGap: 0.25, pad: 0.25 }}\n item={{ grow: 1 }}\n onClick={(e: MouseEvent<HTMLDivElement>) => {\n if (\n e.target instanceof HTMLElement &&\n !e.currentTarget.contains(e.target.closest('li'))\n ) {\n inputRef.current?.focus();\n inputRef.current?.click();\n }\n }}\n >\n {selected.length > 0 && (\n <ul ref={listRef} id={id} role='listbox' aria-label={t('selected_items')}>\n {selected.map((element, idx) => {\n return (\n <Selectable\n as='li'\n key={element.id}\n role='option'\n id={element.id.toString()}\n status={status}\n onClick={e => {\n const mouseClick = e.detail !== 0;\n\n if (!readOnly && !disabled && !mouseClick) {\n handleSelectedRemoval(element.id, idx);\n }\n }}\n onRemove={() => {\n if (!readOnly && !disabled) {\n handleSelectedRemoval(element.id, idx);\n }\n }}\n onKeyDown={(e: KeyboardEvent<Element>) => {\n // prevent browser's Back on FF\n if (e.key === 'Backspace') e.preventDefault();\n }}\n tabIndex='-1'\n aria-label={`${t('remove')} ${element.text}`}\n aria-describedby={ariaDescribedBy}\n >\n {element.text}\n </Selectable>\n );\n })}\n </ul>\n )}\n <Flex\n item={{ grow: 1 }}\n as='input'\n size={1}\n ref={inputRef}\n value={value}\n // no-op avoids react uncontrolled warning\n onChange={onChange || (() => {})}\n onKeyDown={onInputKeyDown}\n readOnly={readOnly || !onChange}\n disabled={disabled}\n placeholder={selected?.length ? undefined : placeholder}\n autoComplete='off'\n autoFocus={autoFocus}\n aria-controls={!pauseDescendantEvaluation ? id : ariaControls}\n {...restProps}\n required={undefined}\n />\n </Flex>\n {actions}\n\n <VisuallyHiddenText id={`${id}-inputDescription`}>\n {`${t('combobox_open_close')} `}\n </VisuallyHiddenText>\n <VisuallyHiddenText id={`${id}-searchDescription`}>\n {t('combobox_search_instructions')}\n </VisuallyHiddenText>\n </Flex>\n );\n }\n);\n\nexport default MultiSelectInput;\n"]}
@@ -193,7 +193,7 @@ const HTML = forwardRef(function HTML({ content, customTags, ...restProps }, ref
193
193
  return mounted
194
194
  ? dompurify.sanitize(content, {
195
195
  CUSTOM_ELEMENT_HANDLING: {
196
- tagNameCheck: customTags ? tagName => customTags.includes(tagName) : null
196
+ tagNameCheck: customTags ? tagName => customTags.includes(tagName) : undefined
197
197
  }
198
198
  })
199
199
  : '';
@@ -1 +1 @@
1
- {"version":3,"file":"HTML.js","sourceRoot":"","sources":["../../../src/components/HTML/HTML.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAIV,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAgB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C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QACjC,6CAA6C;QAC7C,OAAO,OAAO;YACZ,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE;gBAC1B,uBAAuB,EAAE;oBACvB,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI;iBAC1E;aACF,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;IACT,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,KAAC,UAAU,OAAK,SAAS,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,GAAI,CAC5F,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,IAAI,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n useState,\n useEffect,\n useMemo\n} from 'react';\nimport styled, { css, DefaultTheme } from 'styled-components';\nimport dompurify from 'dompurify';\n\nimport { StyledPopover } from '../Popover';\nimport { defaultThemeProp } from '../../theme';\nimport { calculateFontSize, FontSize } from '../../styles';\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { sameOrigin } from '../../utils';\n\nexport interface HTMLProps extends BaseProps, NoChildrenProp {\n content: string;\n customTags?: string[];\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const listStyles = css`\n ul,\n ol {\n padding-inline-start: 2.5rem;\n }\n\n li {\n margin: 0.5rem 0;\n }\n\n ul li {\n ul {\n margin-inline-start: 1rem;\n list-style-type: circle;\n }\n\n ul ul {\n margin-inline-start: 2rem;\n list-style-type: square;\n }\n\n ul ul ul {\n margin-inline-start: 3rem;\n list-style-type: disc;\n }\n }\n\n ol li {\n ol {\n margin-inline-start: 1rem;\n list-style-type: lower-alpha;\n }\n\n ol ol {\n margin-inline-start: 2rem;\n list-style-type: lower-roman;\n }\n\n ol ol ol {\n margin-inline-start: 3rem;\n list-style-type: decimal;\n }\n }\n`;\n\nexport const getTableStyles = (theme: DefaultTheme) => css`\n border-collapse: collapse;\n\n td {\n border: 0.0625rem solid ${theme.base.palette['border-line']};\n min-width: 6.25rem;\n }\n\n tr:first-child {\n td:first-child {\n border-top-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-top-right-radius: 0.125rem;\n }\n }\n\n tr:last-child {\n td:first-child {\n border-bottom-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-bottom-right-radius: 0.125rem;\n }\n }\n`;\n\nexport const getHtmlStyles = (theme: DefaultTheme) => {\n const {\n base: { 'font-size': baseFontSize, 'font-scale': baseFontScale, palette },\n components: { text }\n } = theme;\n const fontSize = calculateFontSize(baseFontSize, baseFontScale);\n return `\n ${listStyles}\n table {\n ${getTableStyles(theme)}\n }\n img {\n max-width: 100%;\n height: auto;\n border-radius: 0.25rem;\n }\n a {\n color: ${palette.interactive};\n }\n pre {\n white-space: break-spaces;\n }\n p {\n min-height: ${fontSize[text.primary['font-size'] as FontSize]};\n }\n h1 {\n font-size: ${fontSize[text.h1['font-size'] as FontSize]};\n font-weight: ${text.h1['font-weight']};\n min-height: ${fontSize[text.h1['font-size'] as FontSize]};\n }\n h2 {\n font-size: ${fontSize[text.h2['font-size'] as FontSize]};\n font-weight: ${text.h2['font-weight']};\n min-height: ${fontSize[text.h2['font-size'] as FontSize]};\n }\n h3 {\n font-size: ${fontSize[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n min-height: ${fontSize[text.h3['font-size'] as FontSize]};\n }\n h4 {\n font-size: ${fontSize[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n min-height: ${fontSize[text.h4['font-size'] as FontSize]};\n }\n h5 {\n font-size: ${fontSize[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n min-height: ${fontSize[text.h5['font-size'] as FontSize]};\n }\n h6 {\n font-size: ${fontSize[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n min-height: ${fontSize[text.h6['font-size'] as FontSize]};\n }\n `;\n};\n\nexport const StyledHTML = styled.div(({ theme }) => {\n return css`\n width: 100%;\n overflow-x: auto;\n overflow-wrap: break-word;\n ${getHtmlStyles(theme)}\n\n ${StyledPopover} ul {\n ul {\n padding-inline-start: 0;\n }\n ol {\n padding-inline-start: 0;\n }\n }\n\n ${StyledPopover} li {\n margin: 0;\n }\n `;\n});\n\nStyledHTML.defaultProps = defaultThemeProp;\n\nconst targetBlankSet = new WeakSet<HTMLAnchorElement>();\n\ndompurify.addHook('beforeSanitizeAttributes', node => {\n // Can be passed text nodes\n if (!(node instanceof HTMLElement || node instanceof SVGElement)) return;\n\n node.removeAttribute('class');\n\n if (\n node.tagName === 'A' &&\n node.hasAttribute('href') &&\n node.getAttribute('target') === '_blank'\n ) {\n targetBlankSet.add(node as HTMLAnchorElement);\n }\n});\n\ndompurify.addHook('afterSanitizeAttributes', node => {\n if (node.tagName === 'A' && node.hasAttribute('href')) {\n const href = node.getAttribute('href')!;\n\n let fullURL: URL;\n try {\n fullURL = new URL(href, window.location.href);\n } catch (e) {\n return;\n }\n\n if (!sameOrigin(window.location, fullURL)) {\n node.setAttribute('target', '_blank');\n node.setAttribute('rel', 'noopener');\n } else if (targetBlankSet.has(node as HTMLAnchorElement)) {\n node.setAttribute('target', '_blank');\n targetBlankSet.delete(node as HTMLAnchorElement);\n }\n }\n});\n\nconst HTML: FunctionComponent<HTMLProps & ForwardProps> = forwardRef(function HTML(\n { content, customTags, ...restProps }: PropsWithoutRef<HTMLProps>,\n ref: HTMLProps['ref']\n) {\n const [mounted, setMounted] = useState(false);\n const sanitizedHtml = useMemo(() => {\n // Don't render content on the server at all.\n return mounted\n ? dompurify.sanitize(content, {\n CUSTOM_ELEMENT_HANDLING: {\n tagNameCheck: customTags ? tagName => customTags.includes(tagName) : null\n }\n })\n : '';\n }, [content, customTags, mounted]);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n return (\n <StyledHTML {...restProps} dangerouslySetInnerHTML={{ __html: sanitizedHtml }} ref={ref} />\n );\n});\n\nexport default HTML;\n"]}
1
+ {"version":3,"file":"HTML.js","sourceRoot":"","sources":["../../../src/components/HTML/HTML.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAIV,QAAQ,EACR,SAAS,EACT,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAgB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAY,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2C5B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAmB,EAAE,EAAE,CAAC,GAAG,CAAA;;;;8BAI5B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuB9D,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAmB,EAAE,EAAE;IACnD,MAAM,EACJ,IAAI,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,EACzE,UAAU,EAAE,EAAE,IAAI,EAAE,EACrB,GAAG,KAAK,CAAC;IACV,MAAM,QAAQ,GAAG,iBAAiB,CAAC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","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n useState,\n useEffect,\n useMemo\n} from 'react';\nimport styled, { css, DefaultTheme } from 'styled-components';\nimport dompurify from 'dompurify';\n\nimport { StyledPopover } from '../Popover';\nimport { defaultThemeProp } from '../../theme';\nimport { calculateFontSize, FontSize } from '../../styles';\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { sameOrigin } from '../../utils';\n\nexport interface HTMLProps extends BaseProps, NoChildrenProp {\n content: string;\n customTags?: string[];\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const listStyles = css`\n ul,\n ol {\n padding-inline-start: 2.5rem;\n }\n\n li {\n margin: 0.5rem 0;\n }\n\n ul li {\n ul {\n margin-inline-start: 1rem;\n list-style-type: circle;\n }\n\n ul ul {\n margin-inline-start: 2rem;\n list-style-type: square;\n }\n\n ul ul ul {\n margin-inline-start: 3rem;\n list-style-type: disc;\n }\n }\n\n ol li {\n ol {\n margin-inline-start: 1rem;\n list-style-type: lower-alpha;\n }\n\n ol ol {\n margin-inline-start: 2rem;\n list-style-type: lower-roman;\n }\n\n ol ol ol {\n margin-inline-start: 3rem;\n list-style-type: decimal;\n }\n }\n`;\n\nexport const getTableStyles = (theme: DefaultTheme) => css`\n border-collapse: collapse;\n\n td {\n border: 0.0625rem solid ${theme.base.palette['border-line']};\n min-width: 6.25rem;\n }\n\n tr:first-child {\n td:first-child {\n border-top-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-top-right-radius: 0.125rem;\n }\n }\n\n tr:last-child {\n td:first-child {\n border-bottom-left-radius: 0.125rem;\n }\n\n td:last-child {\n border-bottom-right-radius: 0.125rem;\n }\n }\n`;\n\nexport const getHtmlStyles = (theme: DefaultTheme) => {\n const {\n base: { 'font-size': baseFontSize, 'font-scale': baseFontScale, palette },\n components: { text }\n } = theme;\n const fontSize = calculateFontSize(baseFontSize, baseFontScale);\n return `\n ${listStyles}\n table {\n ${getTableStyles(theme)}\n }\n img {\n max-width: 100%;\n height: auto;\n border-radius: 0.25rem;\n }\n a {\n color: ${palette.interactive};\n }\n pre {\n white-space: break-spaces;\n }\n p {\n min-height: ${fontSize[text.primary['font-size'] as FontSize]};\n }\n h1 {\n font-size: ${fontSize[text.h1['font-size'] as FontSize]};\n font-weight: ${text.h1['font-weight']};\n min-height: ${fontSize[text.h1['font-size'] as FontSize]};\n }\n h2 {\n font-size: ${fontSize[text.h2['font-size'] as FontSize]};\n font-weight: ${text.h2['font-weight']};\n min-height: ${fontSize[text.h2['font-size'] as FontSize]};\n }\n h3 {\n font-size: ${fontSize[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n min-height: ${fontSize[text.h3['font-size'] as FontSize]};\n }\n h4 {\n font-size: ${fontSize[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n min-height: ${fontSize[text.h4['font-size'] as FontSize]};\n }\n h5 {\n font-size: ${fontSize[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n min-height: ${fontSize[text.h5['font-size'] as FontSize]};\n }\n h6 {\n font-size: ${fontSize[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n min-height: ${fontSize[text.h6['font-size'] as FontSize]};\n }\n `;\n};\n\nexport const StyledHTML = styled.div(({ theme }) => {\n return css`\n width: 100%;\n overflow-x: auto;\n overflow-wrap: break-word;\n ${getHtmlStyles(theme)}\n\n ${StyledPopover} ul {\n ul {\n padding-inline-start: 0;\n }\n ol {\n padding-inline-start: 0;\n }\n }\n\n ${StyledPopover} li {\n margin: 0;\n }\n `;\n});\n\nStyledHTML.defaultProps = defaultThemeProp;\n\nconst targetBlankSet = new WeakSet<HTMLAnchorElement>();\n\ndompurify.addHook('beforeSanitizeAttributes', node => {\n // Can be passed text nodes\n if (!(node instanceof HTMLElement || node instanceof SVGElement)) return;\n\n node.removeAttribute('class');\n\n if (\n node.tagName === 'A' &&\n node.hasAttribute('href') &&\n node.getAttribute('target') === '_blank'\n ) {\n targetBlankSet.add(node as HTMLAnchorElement);\n }\n});\n\ndompurify.addHook('afterSanitizeAttributes', node => {\n if (node.tagName === 'A' && node.hasAttribute('href')) {\n const href = node.getAttribute('href')!;\n\n let fullURL: URL;\n try {\n fullURL = new URL(href, window.location.href);\n } catch (e) {\n return;\n }\n\n if (!sameOrigin(window.location, fullURL)) {\n node.setAttribute('target', '_blank');\n node.setAttribute('rel', 'noopener');\n } else if (targetBlankSet.has(node as HTMLAnchorElement)) {\n node.setAttribute('target', '_blank');\n targetBlankSet.delete(node as HTMLAnchorElement);\n }\n }\n});\n\nconst HTML: FunctionComponent<HTMLProps & ForwardProps> = forwardRef(function HTML(\n { content, customTags, ...restProps }: PropsWithoutRef<HTMLProps>,\n ref: HTMLProps['ref']\n) {\n const [mounted, setMounted] = useState(false);\n const sanitizedHtml = useMemo(() => {\n // Don't render content on the server at all.\n return mounted\n ? dompurify.sanitize(content, {\n CUSTOM_ELEMENT_HANDLING: {\n tagNameCheck: customTags ? tagName => customTags.includes(tagName) : undefined\n }\n })\n : '';\n }, [content, customTags, mounted]);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n return (\n <StyledHTML {...restProps} dangerouslySetInnerHTML={{ __html: sanitizedHtml }} ref={ref} />\n );\n});\n\nexport default HTML;\n"]}
@@ -35,7 +35,7 @@ export interface UseActiveDescendantConfig {
35
35
  /** Explicit onClick handler called on keydown 'enter' event */
36
36
  onClick?: (currentDescendantEl: HTMLElement) => void;
37
37
  /** Prevent scrolling to the active descendant on the initial render.
38
- * Include `preventInitialScroll` for cleanup.
38
+ * Include `clearPreventScroll` to scroll on subsequent interactions if applicable.
39
39
  */
40
40
  preventInitialScroll?: boolean;
41
41
  /** Callback to clear preventInitialScroll after use. */
@@ -1 +1 @@
1
- {"version":3,"file":"useActiveDescendant.js","sourceRoot":"","sources":["../../src/hooks/useActiveDescendant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAk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,YAAY,CAAC;iBACpE;gBAED,IAAI,aAAa,EAAE,EAAE,KAAK,gBAAgB,CAAC,EAAE,EAAE;oBAC7C,uEAAuE;oBACvE,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;wBAC1B,gBAAgB,CAAC,QAAQ,CAAC,CAAC;oBAC7B,CAAC,EAAE,CAAC,CAAC,CAAC;iBACP;aACF;YACD,mBAAmB;iBACd,IAAI,aAAa,EAAE,EAAE,KAAK,gBAAgB,CAAC,EAAE,EAAE;gBAClD,sEAAsE;gBACtE,2EAA2E;gBAC3E,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;oBAC1B,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;gBACrC,CAAC,EAAE,CAAC,CAAC,CAAC;aACP;YAED,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;SACtC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;AAClG,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["import { useEffect, useState, DependencyList, useCallback, useRef } from 'react';\n\nimport { createUID, getActiveElement } from '../utils';\n\nimport useDirection from './useDirection';\n\nexport interface UseActiveDescendantConfig {\n /** DOM element which controls and has active descendants */\n focusEl: HTMLElement | null;\n /** Root scope for descendant options */\n scope: HTMLElement | null;\n /** Custom selector for specific descendant scope in root descendant scope */\n scopeSelector?: string;\n /** Custom selector for descendant options */\n selector?: string;\n /** Orientation of descendant navigation\n * @default 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n /** One-time override for the focused descendant, triggers re-evaluation.\n * Include `clearFocusDescendantEl` for cleanup.\n */\n focusDescendantEl?: HTMLElement | null;\n /** Callback to clear focusDescendantEl after use. */\n clearFocusDescendant?: () => void;\n /** One-time override for focused element on NEXT re-evaluation of active descendants.\n * Include `clearFocusReturn` for cleanup.\n */\n focusReturnEl?: HTMLElement | null;\n /** Callback to clear focusReturnEl after use. */\n clearFocusReturn?: () => void;\n /**\n * Descendant ID used for continuous override of current active descendant,\n * used for external focus control / keyDown bindings (see RTE).\n * NOTE: setting currentDescendantId once effectively disables the keybindings of this hook.\n * If you only need to set the current element once, use focusReturnEl & clearFocusReturn.\n * @deprecated\n */\n currentDescendantId?: string;\n /** Explicit onClick handler called on keydown 'enter' event */\n onClick?: (currentDescendantEl: HTMLElement) => void;\n /** Prevent scrolling to the active descendant on the initial render.\n * Include `preventInitialScroll` for cleanup.\n */\n preventInitialScroll?: boolean;\n /** Callback to clear preventInitialScroll after use. */\n clearPreventScroll?: () => void;\n /** Boolean to prevent descendant evaluation.\n * @default false\n */\n pauseDescendantEvaluation?: boolean;\n}\n\ntype CurrentDescendant = HTMLElement | undefined;\ntype Descendants = HTMLElement[] | null;\ntype InteractiveElementTypes =\n | HTMLButtonElement\n | HTMLAnchorElement\n | HTMLInputElement\n | HTMLLIElement\n | HTMLLegendElement;\n\nconst interactiveNodeNames = ['button', 'a', 'input', 'li', 'legend'];\n\nconst useActiveDescendant = (\n {\n focusEl,\n scope,\n scopeSelector,\n selector,\n orientation = 'vertical',\n focusDescendantEl,\n clearFocusDescendant,\n focusReturnEl,\n clearFocusReturn,\n currentDescendantId,\n onClick,\n preventInitialScroll,\n pauseDescendantEvaluation = false,\n clearPreventScroll\n }: UseActiveDescendantConfig,\n dependencyArray: DependencyList = []\n): {\n activeDescendant: CurrentDescendant;\n descendants: Descendants;\n} => {\n const [resetId, setResetId] = useState(0);\n const previousActiveId = useRef('');\n const paused = useRef(pauseDescendantEvaluation);\n const [focusDescendantElIndex, setFocusDescendantElIndex] = useState<number | null>(null);\n const [currentIndex, setCurrentIndex] = useState<number | null>(null);\n const [descendants, setDescendants] = useState<Descendants>();\n const { rtl } = useDirection();\n\n const clearDescendants = useCallback(() => {\n descendants?.forEach(node => {\n node.setAttribute('data-current', 'false');\n });\n }, [descendants]);\n\n const clearThenSetDescendants = useCallback(\n (setVal: NodeListOf<Element> | null) => {\n clearDescendants();\n setDescendants(\n setVal\n ? Array.from(setVal).filter((item): item is HTMLElement => item instanceof HTMLElement)\n : null\n );\n },\n [descendants]\n );\n\n const setIdsAndOwns = useCallback(\n ({ clear }: { clear: boolean } = { clear: false }) => {\n const ownedIds: string[] = [];\n\n if (descendants && descendants.length) {\n descendants.forEach(node => {\n node.id = node.id || createUID();\n ownedIds.push(node.id);\n });\n }\n\n if (clear) {\n const currentOwnedIds = focusEl?.getAttribute('aria-owns')?.split(' ');\n const clearedIds = currentOwnedIds?.filter(id => !ownedIds.includes(id));\n focusEl?.setAttribute('aria-owns', clearedIds?.join(' ') || '');\n } else {\n focusEl?.setAttribute('aria-owns', ownedIds.join(' '));\n }\n },\n [focusEl, descendants]\n );\n\n const updateDescendants = useCallback(() => {\n if (pauseDescendantEvaluation) return;\n\n let hasScope = scope;\n\n if (hasScope && hasScope instanceof HTMLElement) {\n if (scopeSelector) {\n hasScope = hasScope.querySelector(scopeSelector);\n }\n\n if (!hasScope) {\n clearThenSetDescendants(null);\n return;\n }\n\n if (selector) {\n const setVal = hasScope.querySelectorAll(selector);\n clearThenSetDescendants(setVal);\n } else {\n const setVal = hasScope.querySelectorAll(\n 'a, button, input, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])'\n );\n clearThenSetDescendants(setVal);\n }\n } else {\n clearThenSetDescendants(null);\n }\n }, [scope, scopeSelector, selector, pauseDescendantEvaluation]);\n\n // Update paused ref\n useEffect(() => {\n paused.current = pauseDescendantEvaluation;\n }, [pauseDescendantEvaluation]);\n\n // Toggle active scope data attr.\n useEffect(() => {\n if (!scope || !focusEl) return;\n\n scope.setAttribute('data-active-scope', getActiveElement() === focusEl ? 'true' : 'false');\n\n const onFocus = () => {\n scope.setAttribute('data-active-scope', 'true');\n };\n const onBlur = () => {\n scope.setAttribute('data-active-scope', 'false');\n };\n\n focusEl.addEventListener('focus', onFocus);\n focusEl.addEventListener('blur', onBlur);\n\n return () => {\n focusEl.removeEventListener('focus', onFocus);\n focusEl.removeEventListener('blur', onBlur);\n };\n }, [scope, focusEl]);\n\n // Update descendants when un-paused\n useEffect(() => {\n if (!pauseDescendantEvaluation) {\n updateDescendants();\n }\n }, [pauseDescendantEvaluation]);\n\n // Update descendants & reset current index when dependencies change\n useEffect(() => {\n /**\n * 0 second timeout added because descendantScope needs to be\n * up to date before running query after dependencyArray change\n */\n const timeoutId = setTimeout(() => {\n updateDescendants();\n if (!paused.current) {\n setCurrentIndex(0);\n }\n }, 0);\n\n return () => clearTimeout(timeoutId);\n }, [...dependencyArray]);\n\n // Set IDs and aria-owns\n useEffect(() => {\n if (!pauseDescendantEvaluation) {\n setIdsAndOwns();\n setResetId(Math.random());\n } else {\n clearDescendants();\n setIdsAndOwns({ clear: true });\n }\n }, [pauseDescendantEvaluation, focusEl, descendants]);\n\n // Bind focus el keyDown\n useEffect(() => {\n const nextIndex = () => {\n // Focus next or first\n clearFocusReturn?.();\n clearPreventScroll?.();\n if (currentIndex !== null && currentIndex + 1 < descendants!.length) {\n setCurrentIndex(currentIndex + 1);\n } else {\n setCurrentIndex(0);\n }\n };\n const prevIndex = () => {\n // Focus previous or last\n clearFocusReturn?.();\n clearPreventScroll?.();\n if (currentIndex !== null && currentIndex - 1 > -1) {\n setCurrentIndex(currentIndex - 1);\n } else {\n setCurrentIndex(descendants!.length - 1);\n }\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (descendants?.length) {\n if (['ArrowDown', 'ArrowUp'].includes(e.key) && orientation === 'vertical') {\n e.preventDefault();\n }\n\n if (['ArrowLeft', 'ArrowRight'].includes(e.key) && orientation === 'horizontal') {\n e.preventDefault();\n }\n\n // 0 second timeout to execute after explicitly defined onKeyDown event handlers.\n setTimeout(() => {\n switch (e.key) {\n case 'ArrowDown':\n if (orientation === 'vertical') {\n nextIndex();\n }\n break;\n case 'ArrowUp':\n if (orientation === 'vertical') {\n prevIndex();\n }\n break;\n case 'ArrowRight':\n if (orientation === 'horizontal') {\n if (rtl) {\n prevIndex();\n } else {\n nextIndex();\n }\n }\n break;\n case 'ArrowLeft':\n if (orientation === 'horizontal') {\n if (rtl) {\n nextIndex();\n } else {\n prevIndex();\n }\n }\n break;\n case 'Enter':\n // Click focused item\n if (currentIndex !== null) {\n if (onClick) {\n onClick(descendants[currentIndex]);\n break;\n }\n\n const nodeName = descendants[currentIndex].nodeName.toLowerCase();\n if (interactiveNodeNames.includes(nodeName)) {\n descendants[currentIndex].click();\n } else {\n descendants[currentIndex]\n .querySelector<InteractiveElementTypes>(`${interactiveNodeNames.join(',')}`)\n ?.click();\n }\n }\n break;\n default:\n break;\n }\n }, 0);\n }\n };\n\n // Do not rebind once / if `currentDescendantId` (deprecated) control is defined\n if (!pauseDescendantEvaluation && focusEl && descendants?.length && !currentDescendantId) {\n focusEl.addEventListener('keydown', onKeyDown);\n }\n\n return () => {\n focusEl?.removeEventListener('keydown', onKeyDown);\n };\n }, [focusEl, currentIndex, descendants, pauseDescendantEvaluation]);\n\n // Handle independent control update (deprecated)\n useEffect(() => {\n if (!pauseDescendantEvaluation && descendants && currentDescendantId) {\n descendants.forEach((node, index) => {\n if (node.id === currentDescendantId) {\n setCurrentIndex(index);\n }\n });\n }\n }, [currentDescendantId, descendants, pauseDescendantEvaluation]);\n\n // Set and scroll to current descendant\n useEffect(() => {\n if (paused.current) {\n return;\n }\n const nextIndex = focusDescendantElIndex || currentIndex;\n const focusReturnId = focusReturnEl?.id;\n let focusReturnIndex;\n const focusDescendantElId = focusDescendantEl?.id;\n let focusDescendantIndex;\n let foundFocusDescendantEl = false;\n\n if (descendants && descendants.length) {\n // clear previous & catch focusReturn / focusDescendantEl index\n descendants.forEach((node, index) => {\n if (focusDescendantElIndex === null && node.id === focusDescendantElId) {\n focusDescendantIndex = index;\n foundFocusDescendantEl = true;\n setFocusDescendantElIndex(index);\n }\n if (node.id === focusReturnId) {\n focusReturnIndex = index;\n }\n node.setAttribute('data-current', 'false');\n });\n\n // early return for focusReturn / focusDescendantEl\n if (focusReturnIndex && focusReturnIndex !== currentIndex) {\n setCurrentIndex(focusReturnIndex);\n clearFocusReturn?.();\n return;\n }\n if (foundFocusDescendantEl && focusDescendantIndex !== undefined) {\n // hard reset to continue focusDescendantEl process even if it is the active descendant\n setResetId(Math.random());\n setCurrentIndex(focusDescendantIndex);\n return;\n }\n\n // set new\n if (nextIndex !== null && descendants[nextIndex]) {\n const itemEl = descendants[nextIndex!];\n itemEl.setAttribute('data-current', 'true');\n focusEl?.setAttribute('aria-activedescendant', itemEl.id);\n\n // scroll to element\n if (itemEl.id !== previousActiveId.current && !preventInitialScroll) {\n const scrollTo: (this: Element, arg: boolean) => void =\n Element.prototype.scrollIntoViewIfNeeded ?? Element.prototype.scrollIntoView;\n\n scrollTo?.call(itemEl, false);\n }\n\n // focusDescendantEl cleanup\n if (focusDescendantElIndex !== null) {\n setFocusDescendantElIndex(null);\n clearFocusDescendant?.();\n }\n\n previousActiveId.current = itemEl.id;\n }\n }\n\n return () => {\n focusEl?.removeAttribute('aria-activedescendant');\n };\n }, [descendants, currentIndex, focusDescendantEl, focusEl, resetId]);\n\n return {\n activeDescendant: currentIndex !== null && descendants ? descendants[currentIndex] : undefined,\n descendants: descendants || null\n };\n};\n\nexport const useLazyDescendant = ({\n loading,\n descendants,\n previousActiveDescendant,\n activeDescendant,\n focusReturnEl,\n setFocusReturnEl,\n scrollEl\n}: {\n loading: boolean;\n descendants: Descendants;\n previousActiveDescendant: CurrentDescendant;\n activeDescendant: CurrentDescendant;\n focusReturnEl: UseActiveDescendantConfig['focusReturnEl'];\n setFocusReturnEl: (el: HTMLElement | null | undefined) => void;\n scrollEl?: HTMLElement | null;\n}) => {\n // Bump scroll & set return element when descendant focused in loading state.\n useEffect(() => {\n if (loading && descendants && descendants.length && activeDescendant) {\n const descendantList = [...descendants];\n const lastItem = descendantList.pop();\n const lastId = lastItem?.id || undefined;\n let timeoutId: ReturnType<typeof setTimeout>;\n\n if (lastId === activeDescendant.id) {\n if (scrollEl) {\n scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight;\n }\n\n if (focusReturnEl?.id !== activeDescendant.id) {\n // Set focus return to AD on 'nextTick', to avoid reset of AD on update\n timeoutId = setTimeout(() => {\n setFocusReturnEl(lastItem);\n }, 0);\n }\n }\n // If not last item\n else if (focusReturnEl?.id !== activeDescendant.id) {\n // Set focus return to AD on 'nextTick' to avoid reset of AD on update\n // Do not D.R.Y to avoid conflicting calls with immediately prior elements.\n timeoutId = setTimeout(() => {\n setFocusReturnEl(activeDescendant);\n }, 0);\n }\n\n return () => clearTimeout(timeoutId);\n }\n }, [loading, descendants, previousActiveDescendant, activeDescendant, scrollEl, focusReturnEl]);\n};\n\nexport default useActiveDescendant;\n"]}
1
+ {"version":3,"file":"useActiveDescendant.js","sourceRoot":"","sources":["../../src/hooks/useActiveDescendant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEvD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AA0D1C,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AAEtE,MAAM,mBAAmB,GAAG,CAC1B,EACE,OAAO,EACP,KAAK,EACL,aAAa,EACb,QAAQ,EACR,WAAW,GAAG,UAAU,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EACP,oBAAoB,EACpB,yBAAyB,GAAG,KAAK,EACjC,kBAAkB,EACQ,EAC5B,kBAAkC,EAAE,EAIpC,EAAE;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,gBAAgB,GAAG,MAAM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AC,CAAC;AAClG,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["import { useEffect, useState, DependencyList, useCallback, useRef } from 'react';\n\nimport { createUID, getActiveElement } from '../utils';\n\nimport useDirection from './useDirection';\n\nexport interface UseActiveDescendantConfig {\n /** DOM element which controls and has active descendants */\n focusEl: HTMLElement | null;\n /** Root scope for descendant options */\n scope: HTMLElement | null;\n /** Custom selector for specific descendant scope in root descendant scope */\n scopeSelector?: string;\n /** Custom selector for descendant options */\n selector?: string;\n /** Orientation of descendant navigation\n * @default 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n /** One-time override for the focused descendant, triggers re-evaluation.\n * Include `clearFocusDescendantEl` for cleanup.\n */\n focusDescendantEl?: HTMLElement | null;\n /** Callback to clear focusDescendantEl after use. */\n clearFocusDescendant?: () => void;\n /** One-time override for focused element on NEXT re-evaluation of active descendants.\n * Include `clearFocusReturn` for cleanup.\n */\n focusReturnEl?: HTMLElement | null;\n /** Callback to clear focusReturnEl after use. */\n clearFocusReturn?: () => void;\n /**\n * Descendant ID used for continuous override of current active descendant,\n * used for external focus control / keyDown bindings (see RTE).\n * NOTE: setting currentDescendantId once effectively disables the keybindings of this hook.\n * If you only need to set the current element once, use focusReturnEl & clearFocusReturn.\n * @deprecated\n */\n currentDescendantId?: string;\n /** Explicit onClick handler called on keydown 'enter' event */\n onClick?: (currentDescendantEl: HTMLElement) => void;\n /** Prevent scrolling to the active descendant on the initial render.\n * Include `clearPreventScroll` to scroll on subsequent interactions if applicable.\n */\n preventInitialScroll?: boolean;\n /** Callback to clear preventInitialScroll after use. */\n clearPreventScroll?: () => void;\n /** Boolean to prevent descendant evaluation.\n * @default false\n */\n pauseDescendantEvaluation?: boolean;\n}\n\ntype CurrentDescendant = HTMLElement | undefined;\ntype Descendants = HTMLElement[] | null;\ntype InteractiveElementTypes =\n | HTMLButtonElement\n | HTMLAnchorElement\n | HTMLInputElement\n | HTMLLIElement\n | HTMLLegendElement;\n\nconst interactiveNodeNames = ['button', 'a', 'input', 'li', 'legend'];\n\nconst useActiveDescendant = (\n {\n focusEl,\n scope,\n scopeSelector,\n selector,\n orientation = 'vertical',\n focusDescendantEl,\n clearFocusDescendant,\n focusReturnEl,\n clearFocusReturn,\n currentDescendantId,\n onClick,\n preventInitialScroll,\n pauseDescendantEvaluation = false,\n clearPreventScroll\n }: UseActiveDescendantConfig,\n dependencyArray: DependencyList = []\n): {\n activeDescendant: CurrentDescendant;\n descendants: Descendants;\n} => {\n const [resetId, setResetId] = useState(0);\n const previousActiveId = useRef('');\n const paused = useRef(pauseDescendantEvaluation);\n const [focusDescendantElIndex, setFocusDescendantElIndex] = useState<number | null>(null);\n const [currentIndex, setCurrentIndex] = useState<number | null>(null);\n const [descendants, setDescendants] = useState<Descendants>();\n const { rtl } = useDirection();\n\n const clearDescendants = useCallback(() => {\n descendants?.forEach(node => {\n node.setAttribute('data-current', 'false');\n });\n }, [descendants]);\n\n const clearThenSetDescendants = useCallback(\n (setVal: NodeListOf<Element> | null) => {\n clearDescendants();\n setDescendants(\n setVal\n ? Array.from(setVal).filter((item): item is HTMLElement => item instanceof HTMLElement)\n : null\n );\n },\n [descendants]\n );\n\n const setIdsAndOwns = useCallback(\n ({ clear }: { clear: boolean } = { clear: false }) => {\n const ownedIds: string[] = [];\n\n if (descendants && descendants.length) {\n descendants.forEach(node => {\n node.id = node.id || createUID();\n ownedIds.push(node.id);\n });\n }\n\n if (clear) {\n const currentOwnedIds = focusEl?.getAttribute('aria-owns')?.split(' ');\n const clearedIds = currentOwnedIds?.filter(id => !ownedIds.includes(id));\n focusEl?.setAttribute('aria-owns', clearedIds?.join(' ') || '');\n } else {\n focusEl?.setAttribute('aria-owns', ownedIds.join(' '));\n }\n },\n [focusEl, descendants]\n );\n\n const updateDescendants = useCallback(() => {\n if (pauseDescendantEvaluation) return;\n\n let hasScope = scope;\n\n if (hasScope && hasScope instanceof HTMLElement) {\n if (scopeSelector) {\n hasScope = hasScope.querySelector(scopeSelector);\n }\n\n if (!hasScope) {\n clearThenSetDescendants(null);\n return;\n }\n\n if (selector) {\n const setVal = hasScope.querySelectorAll(selector);\n clearThenSetDescendants(setVal);\n } else {\n const setVal = hasScope.querySelectorAll(\n 'a, button, input, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])'\n );\n clearThenSetDescendants(setVal);\n }\n } else {\n clearThenSetDescendants(null);\n }\n }, [scope, scopeSelector, selector, pauseDescendantEvaluation]);\n\n // Update paused ref\n useEffect(() => {\n paused.current = pauseDescendantEvaluation;\n }, [pauseDescendantEvaluation]);\n\n // Toggle active scope data attr.\n useEffect(() => {\n if (!scope || !focusEl) return;\n\n scope.setAttribute('data-active-scope', getActiveElement() === focusEl ? 'true' : 'false');\n\n const onFocus = () => {\n scope.setAttribute('data-active-scope', 'true');\n };\n const onBlur = () => {\n scope.setAttribute('data-active-scope', 'false');\n };\n\n focusEl.addEventListener('focus', onFocus);\n focusEl.addEventListener('blur', onBlur);\n\n return () => {\n focusEl.removeEventListener('focus', onFocus);\n focusEl.removeEventListener('blur', onBlur);\n };\n }, [scope, focusEl]);\n\n // Update descendants when un-paused\n useEffect(() => {\n if (!pauseDescendantEvaluation) {\n updateDescendants();\n }\n }, [pauseDescendantEvaluation]);\n\n // Update descendants & reset current index when dependencies change\n useEffect(() => {\n /**\n * 0 second timeout added because descendantScope needs to be\n * up to date before running query after dependencyArray change\n */\n const timeoutId = setTimeout(() => {\n updateDescendants();\n if (!paused.current) {\n setCurrentIndex(0);\n }\n }, 0);\n\n return () => clearTimeout(timeoutId);\n }, [...dependencyArray]);\n\n // Set IDs and aria-owns\n useEffect(() => {\n if (!pauseDescendantEvaluation) {\n setIdsAndOwns();\n setResetId(Math.random());\n } else {\n clearDescendants();\n setIdsAndOwns({ clear: true });\n }\n }, [pauseDescendantEvaluation, focusEl, descendants]);\n\n // Bind focus el keyDown\n useEffect(() => {\n const nextIndex = () => {\n // Focus next or first\n clearFocusReturn?.();\n clearPreventScroll?.();\n if (currentIndex !== null && currentIndex + 1 < descendants!.length) {\n setCurrentIndex(currentIndex + 1);\n } else {\n setCurrentIndex(0);\n }\n };\n const prevIndex = () => {\n // Focus previous or last\n clearFocusReturn?.();\n clearPreventScroll?.();\n if (currentIndex !== null && currentIndex - 1 > -1) {\n setCurrentIndex(currentIndex - 1);\n } else {\n setCurrentIndex(descendants!.length - 1);\n }\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (descendants?.length) {\n if (['ArrowDown', 'ArrowUp'].includes(e.key) && orientation === 'vertical') {\n e.preventDefault();\n }\n\n if (['ArrowLeft', 'ArrowRight'].includes(e.key) && orientation === 'horizontal') {\n e.preventDefault();\n }\n\n // 0 second timeout to execute after explicitly defined onKeyDown event handlers.\n setTimeout(() => {\n switch (e.key) {\n case 'ArrowDown':\n if (orientation === 'vertical') {\n nextIndex();\n }\n break;\n case 'ArrowUp':\n if (orientation === 'vertical') {\n prevIndex();\n }\n break;\n case 'ArrowRight':\n if (orientation === 'horizontal') {\n if (rtl) {\n prevIndex();\n } else {\n nextIndex();\n }\n }\n break;\n case 'ArrowLeft':\n if (orientation === 'horizontal') {\n if (rtl) {\n nextIndex();\n } else {\n prevIndex();\n }\n }\n break;\n case 'Enter':\n // Click focused item\n if (currentIndex !== null) {\n if (onClick) {\n onClick(descendants[currentIndex]);\n break;\n }\n\n const nodeName = descendants[currentIndex].nodeName.toLowerCase();\n if (interactiveNodeNames.includes(nodeName)) {\n descendants[currentIndex].click();\n } else {\n descendants[currentIndex]\n .querySelector<InteractiveElementTypes>(`${interactiveNodeNames.join(',')}`)\n ?.click();\n }\n }\n break;\n default:\n break;\n }\n }, 0);\n }\n };\n\n // Do not rebind once / if `currentDescendantId` (deprecated) control is defined\n if (!pauseDescendantEvaluation && focusEl && descendants?.length && !currentDescendantId) {\n focusEl.addEventListener('keydown', onKeyDown);\n }\n\n return () => {\n focusEl?.removeEventListener('keydown', onKeyDown);\n };\n }, [focusEl, currentIndex, descendants, pauseDescendantEvaluation]);\n\n // Handle independent control update (deprecated)\n useEffect(() => {\n if (!pauseDescendantEvaluation && descendants && currentDescendantId) {\n descendants.forEach((node, index) => {\n if (node.id === currentDescendantId) {\n setCurrentIndex(index);\n }\n });\n }\n }, [currentDescendantId, descendants, pauseDescendantEvaluation]);\n\n // Set and scroll to current descendant\n useEffect(() => {\n if (paused.current) {\n return;\n }\n const nextIndex = focusDescendantElIndex || currentIndex;\n const focusReturnId = focusReturnEl?.id;\n let focusReturnIndex;\n const focusDescendantElId = focusDescendantEl?.id;\n let focusDescendantIndex;\n let foundFocusDescendantEl = false;\n\n if (descendants && descendants.length) {\n // clear previous & catch focusReturn / focusDescendantEl index\n descendants.forEach((node, index) => {\n if (focusDescendantElIndex === null && node.id === focusDescendantElId) {\n focusDescendantIndex = index;\n foundFocusDescendantEl = true;\n setFocusDescendantElIndex(index);\n }\n if (node.id === focusReturnId) {\n focusReturnIndex = index;\n }\n node.setAttribute('data-current', 'false');\n });\n\n // early return for focusReturn / focusDescendantEl\n if (focusReturnIndex && focusReturnIndex !== currentIndex) {\n setCurrentIndex(focusReturnIndex);\n clearFocusReturn?.();\n return;\n }\n if (foundFocusDescendantEl && focusDescendantIndex !== undefined) {\n // hard reset to continue focusDescendantEl process even if it is the active descendant\n setResetId(Math.random());\n setCurrentIndex(focusDescendantIndex);\n return;\n }\n\n // set new\n if (nextIndex !== null && descendants[nextIndex]) {\n const itemEl = descendants[nextIndex!];\n itemEl.setAttribute('data-current', 'true');\n focusEl?.setAttribute('aria-activedescendant', itemEl.id);\n\n // scroll to element\n if (itemEl.id !== previousActiveId.current && !preventInitialScroll) {\n const scrollTo: (this: Element, arg: boolean) => void =\n Element.prototype.scrollIntoViewIfNeeded ?? Element.prototype.scrollIntoView;\n\n scrollTo?.call(itemEl, false);\n }\n\n // focusDescendantEl cleanup\n if (focusDescendantElIndex !== null) {\n setFocusDescendantElIndex(null);\n clearFocusDescendant?.();\n }\n\n previousActiveId.current = itemEl.id;\n }\n }\n\n return () => {\n focusEl?.removeAttribute('aria-activedescendant');\n };\n }, [descendants, currentIndex, focusDescendantEl, focusEl, resetId]);\n\n return {\n activeDescendant: currentIndex !== null && descendants ? descendants[currentIndex] : undefined,\n descendants: descendants || null\n };\n};\n\nexport const useLazyDescendant = ({\n loading,\n descendants,\n previousActiveDescendant,\n activeDescendant,\n focusReturnEl,\n setFocusReturnEl,\n scrollEl\n}: {\n loading: boolean;\n descendants: Descendants;\n previousActiveDescendant: CurrentDescendant;\n activeDescendant: CurrentDescendant;\n focusReturnEl: UseActiveDescendantConfig['focusReturnEl'];\n setFocusReturnEl: (el: HTMLElement | null | undefined) => void;\n scrollEl?: HTMLElement | null;\n}) => {\n // Bump scroll & set return element when descendant focused in loading state.\n useEffect(() => {\n if (loading && descendants && descendants.length && activeDescendant) {\n const descendantList = [...descendants];\n const lastItem = descendantList.pop();\n const lastId = lastItem?.id || undefined;\n let timeoutId: ReturnType<typeof setTimeout>;\n\n if (lastId === activeDescendant.id) {\n if (scrollEl) {\n scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight;\n }\n\n if (focusReturnEl?.id !== activeDescendant.id) {\n // Set focus return to AD on 'nextTick', to avoid reset of AD on update\n timeoutId = setTimeout(() => {\n setFocusReturnEl(lastItem);\n }, 0);\n }\n }\n // If not last item\n else if (focusReturnEl?.id !== activeDescendant.id) {\n // Set focus return to AD on 'nextTick' to avoid reset of AD on update\n // Do not D.R.Y to avoid conflicting calls with immediately prior elements.\n timeoutId = setTimeout(() => {\n setFocusReturnEl(activeDescendant);\n }, 0);\n }\n\n return () => clearTimeout(timeoutId);\n }\n }, [loading, descendants, previousActiveDescendant, activeDescendant, scrollEl, focusReturnEl]);\n};\n\nexport default useActiveDescendant;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-core",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@popperjs/core": "^2.11.6",
29
- "@types/dompurify": "^3.0.2",
29
+ "@types/dompurify": "^3.0.5",
30
30
  "@types/emoji-mart": "^3.0.4",
31
31
  "@types/emoji-regex": "^8.0.0",
32
32
  "@types/google.maps": "^3.49.2",
@@ -36,7 +36,7 @@
36
36
  "@types/styled-components": "^5.1.26",
37
37
  "bignumber.js": "^9.0.1",
38
38
  "credit-card-type": "^9.1.0",
39
- "dompurify": "^3.0.5",
39
+ "dompurify": "^3.0.7",
40
40
  "emoji-mart": "^3.0.1",
41
41
  "emoji-regex": "^9.2.0",
42
42
  "libphonenumber-js": "^1.9.9",