@pega/cosmos-react-core 8.9.4 → 8.10.0
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/lib/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/components/Avatar/Avatar.js +10 -4
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.d.ts.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.js +4 -1
- package/lib/components/FieldValueList/FieldValueList.js.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.js +3 -3
- package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.d.ts.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.js +23 -6
- package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.d.ts +4 -4
- package/lib/components/RadioCheckGroup/RadioCheckGroup.d.ts.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js +13 -2
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js.map +1 -1
- package/lib/components/SpeechToTextButton/SpeechToTextButton.d.ts +13 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.d.ts.map +1 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.js +29 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.js.map +1 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.test-ids.d.ts +2 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.test-ids.d.ts.map +1 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.test-ids.js +3 -0
- package/lib/components/SpeechToTextButton/SpeechToTextButton.test-ids.js.map +1 -0
- package/lib/components/SpeechToTextButton/index.d.ts +3 -0
- package/lib/components/SpeechToTextButton/index.d.ts.map +1 -0
- package/lib/components/SpeechToTextButton/index.js +2 -0
- package/lib/components/SpeechToTextButton/index.js.map +1 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useAnimatedText.d.ts +3 -1
- package/lib/hooks/useAnimatedText.d.ts.map +1 -1
- package/lib/hooks/useAnimatedText.js +10 -4
- package/lib/hooks/useAnimatedText.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +14 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useSpeechRecognition.d.ts +21 -0
- package/lib/hooks/useSpeechRecognition.d.ts.map +1 -0
- package/lib/hooks/useSpeechRecognition.js +122 -0
- package/lib/hooks/useSpeechRecognition.js.map +1 -0
- package/lib/i18n/default.d.ts +14 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +17 -1
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +14 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/theme/theme.d.ts +60 -0
- package/lib/theme/theme.d.ts.map +1 -1
- package/lib/theme/themeDefinition.json +32 -0
- package/lib/theme/themeOverrides.schema.json +42 -0
- package/package.json +2 -1
|
@@ -7,7 +7,7 @@ import Flex from '../Flex';
|
|
|
7
7
|
import { useArrows, useConsolidatedRef, useElement, useTestIds, useTheme, useUID } from '../../hooks';
|
|
8
8
|
import Grid from '../Grid';
|
|
9
9
|
import { StyledImageContainer, StyledSelectionCard, StyledSelectionCardInline } from '../SelectionCard/SelectionCard.styles';
|
|
10
|
-
import { withTestIds } from '../../utils';
|
|
10
|
+
import { getActiveElement, withTestIds } from '../../utils';
|
|
11
11
|
import { StyledRadioCheck } from '../RadioCheck/RadioCheck';
|
|
12
12
|
import { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';
|
|
13
13
|
export const StyledRadioCheckGroup = styled.fieldset(() => {
|
|
@@ -89,7 +89,18 @@ const RadioCheckGroup = forwardRef(function RadioCheckGroup(props, ref) {
|
|
|
89
89
|
}
|
|
90
90
|
: child.props.onChange
|
|
91
91
|
})), [children, name, disabled, readOnly, variant, onChange]);
|
|
92
|
-
return (_jsx(FormField, { testId: testIds, as: StyledRadioCheckGroup, labelAs: 'legend', ref: containerRef, name: name, disabled: disabled, required: required, ...restProps, isRadioCheck: true, onClear: onClear,
|
|
92
|
+
return (_jsx(FormField, { testId: testIds, as: StyledRadioCheckGroup, labelAs: 'legend', ref: containerRef, name: name, disabled: disabled, required: required, ...restProps, isRadioCheck: true, onClear: onClear,
|
|
93
|
+
// Prevents blur when any input within the group is actively focused.
|
|
94
|
+
onMouseDown: (e) => {
|
|
95
|
+
restProps.onMouseDown?.(e);
|
|
96
|
+
if (!containerRef.current)
|
|
97
|
+
return;
|
|
98
|
+
if (!containerRef.current.contains(getActiveElement()))
|
|
99
|
+
return;
|
|
100
|
+
if (!(e.target instanceof Element) || !e.target.closest('label'))
|
|
101
|
+
return;
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
}, children: variant === 'card-grid' ? (_jsx(Grid, { container: {
|
|
93
104
|
gap: 1,
|
|
94
105
|
cols: (() => {
|
|
95
106
|
if (!renderInline)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioCheckGroup.js","sourceRoot":"","sources":["../../../src/components/RadioCheckGroup/RadioCheckGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEjG,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,IAAI,MAAM,SAAS,CA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,EACf,EAAE,EAAE,qBAAqB,EACzB,OAAO,EAAC,QAAQ,EAChB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,KACd,SAAS,EACb,YAAY,QACZ,OAAO,EAAE,OAAO,YAEf,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,CACzB,KAAC,IAAI,IACH,SAAS,EAAE;gBACT,GAAG,EAAE,CAAC;gBACN,IAAI,EAAE,CAAC,GAAG,EAAE;oBACV,IAAI,CAAC,YAAY;wBAAE,OAAO,kCAAkC,CAAC;oBAC7D,IAAI,SAAS;wBACX,OAAO,qCAAqC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;oBACvF,OAAO,UAAU,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACpD,CAAC,CAAC,EAAE;gBACJ,QAAQ,EAAE,KAAK;aAChB,YAEA,WAAW,GACP,CACR,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IACH,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE;gBACT,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;gBAC1C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,MAAM;aACb,YAEA,WAAW,GACP,CACR,GACS,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { forwardRef, Children, cloneElement, useState, useEffect, useRef, useMemo } from 'react';\nimport type { Ref, PropsWithoutRef, ReactElement, ChangeEvent } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { ForwardRefForwardPropsComponent, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport type { FormFieldProps } from '../FormField';\nimport { StyledFormField, StyledFormFieldInfo } from '../FormField/FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { RadioCheckProps } from '../RadioCheck';\nimport Flex from '../Flex';\nimport {\n useArrows,\n useConsolidatedRef,\n useElement,\n useTestIds,\n useTheme,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport {\n StyledImageContainer,\n StyledSelectionCard,\n StyledSelectionCardInline\n} from '../SelectionCard/SelectionCard.styles';\nimport { withTestIds } from '../../utils';\nimport type { elements } from '../FormField/FormField.test-ids';\nimport { StyledRadioCheck } from '../RadioCheck/RadioCheck';\n\nimport { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';\n\nexport interface RadioCheckGroupProps extends TestIdProp<typeof elements> {\n /** Accepts Checkboxes or RadioButtons as children. */\n children: ReactElement | ReactElement[];\n /**\n * Conveniently pass an onChange handler to the group to be notified when any of the inputs change.\n * Additionally, onChange can be passed to individual children.\n * Both handlers will be called, child followed by group.\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void;\n /** Callback invoked when the clear button is clicked. If provided will render the clear button. */\n onClear?: FormFieldProps['onClear'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: FormFieldProps['inline'];\n /** Used to toggle the auto stacking feature of an inlined group.\n * @default true\n */\n autoStack?: boolean;\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /**\n * Controls the styling of the child RadioChecks.\n * @default 'simple'\n */\n variant?: RadioCheckProps['variant'] | 'card-grid';\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLElement>;\n}\n\nexport const StyledRadioCheckGroup = styled.fieldset(() => {\n return css`\n flex-wrap: nowrap;\n\n &[disabled] {\n > ${StyledFormField} {\n opacity: unset;\n }\n }\n\n ${StyledSelectionCard} {\n max-width: 100%;\n }\n\n ${StyledSelectionCardInline} ${StyledImageContainer} {\n /* To enlarge the image containers to the size of the biggest one */\n min-height: 100%;\n }\n\n ${StyledRadioCheck} > ${StyledFormFieldInfo} {\n display: none;\n }\n `;\n});\n\nconst RadioCheckGroup: ForwardRefForwardPropsComponent<RadioCheckGroupProps> = forwardRef(\n function RadioCheckGroup(\n props: PropsWithoutRef<RadioCheckGroupProps>,\n ref: RadioCheckGroupProps['ref']\n ) {\n const uid = useUID();\n const {\n testId,\n children,\n name = uid,\n disabled = false,\n required = false,\n onChange,\n readOnly,\n inline = false,\n autoStack = true,\n variant = 'simple',\n onClear,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getRadioCheckGroupTestIds);\n const theme = useTheme();\n const [optionsEl, setOptionsEl] = useElement<HTMLDivElement>();\n const [renderInline, setRenderInline] = useState(inline);\n const renderInlineRef = useRef(inline);\n const minInlineWidth = useRef(0);\n const containerRef = useConsolidatedRef(ref);\n\n useArrows(containerRef, {\n selector: '[data-main-focus]',\n cycle: false,\n dir: 'left-right'\n });\n\n useEffect(() => {\n setRenderInline(inline);\n if (inline && optionsEl && optionsEl.lastChild && autoStack) {\n const intersectionObserver = new IntersectionObserver(\n entries => {\n if (entries[0].intersectionRatio < 1) {\n if (entries[0].rootBounds) minInlineWidth.current = entries[0].rootBounds.width + 1;\n renderInlineRef.current = false;\n setRenderInline(false);\n }\n },\n { root: optionsEl, threshold: 1 }\n );\n\n const resizeObserver = new ResizeObserver(entries => {\n if (!renderInlineRef.current && entries[0].contentRect.width > minInlineWidth.current) {\n renderInlineRef.current = true;\n setRenderInline(true);\n }\n });\n\n intersectionObserver.observe(optionsEl.lastChild as Element);\n resizeObserver.observe(optionsEl);\n\n return () => {\n intersectionObserver.disconnect();\n resizeObserver.disconnect();\n };\n }\n }, [optionsEl, inline, autoStack]);\n\n const mapChildren = useMemo(\n () =>\n Children.map(children, child =>\n cloneElement(child, {\n name,\n status: restProps.status,\n disabled: disabled || child.props.disabled,\n readOnly: readOnly || child.props.readOnly,\n variant: variant === 'card-grid' ? 'card' : variant,\n onChange: onChange\n ? (e: ChangeEvent<HTMLInputElement>) => {\n if (!(readOnly || child.props.readOnly)) {\n child.props.onChange?.(e);\n onChange(e);\n }\n }\n : child.props.onChange\n })\n ),\n [children, name, disabled, readOnly, variant, onChange]\n );\n\n return (\n <FormField\n testId={testIds}\n as={StyledRadioCheckGroup}\n labelAs='legend'\n ref={containerRef}\n name={name}\n disabled={disabled}\n required={required}\n {...restProps}\n isRadioCheck\n onClear={onClear}\n >\n {variant === 'card-grid' ? (\n <Grid\n container={{\n gap: 1,\n cols: (() => {\n if (!renderInline) return 'minmax(min-content, max-content)';\n if (autoStack)\n return `repeat(auto-fit, minmax(min(100%, ${theme.base['content-width'].sm}), 1fr))`;\n return `repeat(${Children.count(children)}, 1fr)`;\n })(),\n autoRows: '1fr'\n }}\n >\n {mapChildren}\n </Grid>\n ) : (\n <Flex\n ref={setOptionsEl}\n container={{\n direction: renderInline ? 'row' : 'column',\n colGap: renderInline ? 1.5 : 2,\n rowGap: variant === 'card' ? 1 : 0,\n wrap: 'wrap'\n }}\n >\n {mapChildren}\n </Flex>\n )}\n </FormField>\n );\n }\n);\n\nexport default withTestIds(RadioCheckGroup, getRadioCheckGroupTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"RadioCheckGroup.js","sourceRoot":"","sources":["../../../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O,qCAAqC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;oBACvF,OAAO,UAAU,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACpD,CAAC,CAAC,EAAE;gBACJ,QAAQ,EAAE,KAAK;aAChB,YAEA,WAAW,GACP,CACR,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IACH,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE;gBACT,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;gBAC1C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,MAAM;aACb,YAEA,WAAW,GACP,CACR,GACS,CACb,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import { forwardRef, Children, cloneElement, useState, useEffect, useRef, useMemo } from 'react';\nimport type {\n Ref,\n PropsWithoutRef,\n ReactElement,\n ChangeEvent,\n MouseEvent as ReactMouseEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { RefElement, TestIdProp, WithAttributes } from '../../types';\nimport FormField from '../FormField';\nimport type { FormFieldProps } from '../FormField';\nimport { StyledFormField, StyledFormFieldInfo } from '../FormField/FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { RadioCheckProps } from '../RadioCheck';\nimport Flex from '../Flex';\nimport {\n useArrows,\n useConsolidatedRef,\n useElement,\n useTestIds,\n useTheme,\n useUID\n} from '../../hooks';\nimport Grid from '../Grid';\nimport {\n StyledImageContainer,\n StyledSelectionCard,\n StyledSelectionCardInline\n} from '../SelectionCard/SelectionCard.styles';\nimport { getActiveElement, withTestIds } from '../../utils';\nimport type { elements } from '../FormField/FormField.test-ids';\nimport { StyledRadioCheck } from '../RadioCheck/RadioCheck';\n\nimport { getRadioCheckGroupTestIds } from './RadioCheckGroup.test-ids';\n\nexport type RadioCheckGroupProps = WithAttributes<\n 'fieldset',\n TestIdProp<typeof elements> & {\n /** Accepts Checkboxes or RadioButtons as children. */\n children: ReactElement | ReactElement[];\n /**\n * Conveniently pass an onChange handler to the group to be notified when any of the inputs change.\n * Additionally, onChange can be passed to individual children.\n * Both handlers will be called, child followed by group.\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void;\n /** Callback invoked when the clear button is clicked. If provided will render the clear button. */\n onClear?: FormFieldProps['onClear'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /**\n * Layout field elements inline in a row.\n * @default false\n */\n inline?: FormFieldProps['inline'];\n /** Used to toggle the auto stacking feature of an inlined group.\n * @default true\n */\n autoStack?: boolean;\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /**\n * Controls the styling of the child RadioChecks.\n * @default 'simple'\n */\n variant?: RadioCheckProps['variant'] | 'card-grid';\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLElement>;\n }\n>;\n\nexport const StyledRadioCheckGroup = styled.fieldset(() => {\n return css`\n flex-wrap: nowrap;\n\n &[disabled] {\n > ${StyledFormField} {\n opacity: unset;\n }\n }\n\n ${StyledSelectionCard} {\n max-width: 100%;\n }\n\n ${StyledSelectionCardInline} ${StyledImageContainer} {\n /* To enlarge the image containers to the size of the biggest one */\n min-height: 100%;\n }\n\n ${StyledRadioCheck} > ${StyledFormFieldInfo} {\n display: none;\n }\n `;\n});\n\nconst RadioCheckGroup = forwardRef<\n RefElement<RadioCheckGroupProps>,\n PropsWithoutRef<RadioCheckGroupProps>\n>(function RadioCheckGroup(props, ref) {\n const uid = useUID();\n const {\n testId,\n children,\n name = uid,\n disabled = false,\n required = false,\n onChange,\n readOnly,\n inline = false,\n autoStack = true,\n variant = 'simple',\n onClear,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getRadioCheckGroupTestIds);\n const theme = useTheme();\n const [optionsEl, setOptionsEl] = useElement<HTMLDivElement>();\n const [renderInline, setRenderInline] = useState(inline);\n const renderInlineRef = useRef(inline);\n const minInlineWidth = useRef(0);\n const containerRef = useConsolidatedRef(ref);\n\n useArrows(containerRef, {\n selector: '[data-main-focus]',\n cycle: false,\n dir: 'left-right'\n });\n\n useEffect(() => {\n setRenderInline(inline);\n if (inline && optionsEl && optionsEl.lastChild && autoStack) {\n const intersectionObserver = new IntersectionObserver(\n entries => {\n if (entries[0].intersectionRatio < 1) {\n if (entries[0].rootBounds) minInlineWidth.current = entries[0].rootBounds.width + 1;\n renderInlineRef.current = false;\n setRenderInline(false);\n }\n },\n { root: optionsEl, threshold: 1 }\n );\n\n const resizeObserver = new ResizeObserver(entries => {\n if (!renderInlineRef.current && entries[0].contentRect.width > minInlineWidth.current) {\n renderInlineRef.current = true;\n setRenderInline(true);\n }\n });\n\n intersectionObserver.observe(optionsEl.lastChild as Element);\n resizeObserver.observe(optionsEl);\n\n return () => {\n intersectionObserver.disconnect();\n resizeObserver.disconnect();\n };\n }\n }, [optionsEl, inline, autoStack]);\n\n const mapChildren = useMemo(\n () =>\n Children.map(children, child =>\n cloneElement(child, {\n name,\n status: restProps.status,\n disabled: disabled || child.props.disabled,\n readOnly: readOnly || child.props.readOnly,\n variant: variant === 'card-grid' ? 'card' : variant,\n onChange: onChange\n ? (e: ChangeEvent<HTMLInputElement>) => {\n if (!(readOnly || child.props.readOnly)) {\n child.props.onChange?.(e);\n onChange(e);\n }\n }\n : child.props.onChange\n })\n ),\n [children, name, disabled, readOnly, variant, onChange]\n );\n\n return (\n <FormField\n testId={testIds}\n as={StyledRadioCheckGroup}\n labelAs='legend'\n ref={containerRef}\n name={name}\n disabled={disabled}\n required={required}\n {...restProps}\n isRadioCheck\n onClear={onClear}\n // Prevents blur when any input within the group is actively focused.\n onMouseDown={(e: ReactMouseEvent<HTMLFieldSetElement>) => {\n restProps.onMouseDown?.(e);\n\n if (!containerRef.current) return;\n\n if (!containerRef.current.contains(getActiveElement())) return;\n\n if (!(e.target instanceof Element) || !e.target.closest('label')) return;\n\n e.preventDefault();\n }}\n >\n {variant === 'card-grid' ? (\n <Grid\n container={{\n gap: 1,\n cols: (() => {\n if (!renderInline) return 'minmax(min-content, max-content)';\n if (autoStack)\n return `repeat(auto-fit, minmax(min(100%, ${theme.base['content-width'].sm}), 1fr))`;\n return `repeat(${Children.count(children)}, 1fr)`;\n })(),\n autoRows: '1fr'\n }}\n >\n {mapChildren}\n </Grid>\n ) : (\n <Flex\n ref={setOptionsEl}\n container={{\n direction: renderInline ? 'row' : 'column',\n colGap: renderInline ? 1.5 : 2,\n rowGap: variant === 'card' ? 1 : 0,\n wrap: 'wrap'\n }}\n >\n {mapChildren}\n </Flex>\n )}\n </FormField>\n );\n});\n\nexport default withTestIds(RadioCheckGroup, getRadioCheckGroupTestIds);\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
import type { NoChildrenProp, TestIdProp, WithAttributes } from '../../types';
|
|
3
|
+
export type SpeechToTextButtonProps = WithAttributes<'button', NoChildrenProp & TestIdProp & {
|
|
4
|
+
/** Whether voice to text is active */
|
|
5
|
+
active: boolean;
|
|
6
|
+
/** Ref to the element */
|
|
7
|
+
ref?: Ref<HTMLButtonElement>;
|
|
8
|
+
}>;
|
|
9
|
+
declare const _default: import("react").ForwardRefExoticComponent<Omit<SpeechToTextButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>> & {
|
|
10
|
+
getTestIds: (testIdProp?: TestIdProp["testId"]) => import("../../types").TestIdsRecord<readonly []>;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=SpeechToTextButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpeechToTextButton.d.ts","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/SpeechToTextButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAMnE,OAAO,KAAK,EAAE,cAAc,EAAc,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAyB1F,MAAM,MAAM,uBAAuB,GAAG,cAAc,CAClD,QAAQ,EACR,cAAc,GACZ,UAAU,GAAG;IACX,sCAAsC;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,yBAAyB;IACzB,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B,CACJ,CAAC;;;;AAyBF,wBAA6E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import styled, { css } from 'styled-components';
|
|
4
|
+
import { mix } from 'polished';
|
|
5
|
+
import * as micIcon from '../Icon/icons/send-solid.icon';
|
|
6
|
+
import * as micSolidIcon from '../Icon/icons/square-solid.icon';
|
|
7
|
+
import { useI18n, useTestIds } from '../../hooks';
|
|
8
|
+
import Button from '../Button';
|
|
9
|
+
import Icon, { registerIcon } from '../Icon';
|
|
10
|
+
import { tryCatch, withTestIds } from '../../utils';
|
|
11
|
+
import { defaultThemeProp } from '../../theme';
|
|
12
|
+
import { getSpeechToTextButtonTestIds } from './SpeechToTextButton.test-ids';
|
|
13
|
+
registerIcon(micIcon, micSolidIcon);
|
|
14
|
+
const StyledSpeechToTextButton = styled(Button)(({ theme }) => {
|
|
15
|
+
const activeColor = tryCatch(() => mix(0.85, theme.base.palette['primary-background'], theme.base.palette.interactive));
|
|
16
|
+
return css `
|
|
17
|
+
&[aria-pressed='true'] {
|
|
18
|
+
background-color: ${activeColor};
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
});
|
|
22
|
+
StyledSpeechToTextButton.defaultProps = defaultThemeProp;
|
|
23
|
+
const SpeechToTextButton = forwardRef(function SpeechToTextButton({ active, testId, ...restProps }, ref) {
|
|
24
|
+
const t = useI18n();
|
|
25
|
+
const testIds = useTestIds(testId, getSpeechToTextButtonTestIds);
|
|
26
|
+
return (_jsx(StyledSpeechToTextButton, { ref: ref, "data-testid": testIds.root, ...restProps, label: active ? t('stop_dictation') : t('dictate'), "aria-pressed": active, variant: 'simple', icon: true, children: _jsx(Icon, { name: active ? 'mic-solid' : 'mic' }) }));
|
|
27
|
+
});
|
|
28
|
+
export default withTestIds(SpeechToTextButton, getSpeechToTextButtonTestIds);
|
|
29
|
+
//# sourceMappingURL=SpeechToTextButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpeechToTextButton.js","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/SpeechToTextButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAkC,MAAM,OAAO,CAAC;AACnE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AACzD,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,MAAM,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,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,GAAI,GACnB,CAC5B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,kBAAkB,EAAE,4BAA4B,CAAC,CAAC","sourcesContent":["import { forwardRef, type PropsWithoutRef, type Ref } from 'react';\nimport styled, { css } from 'styled-components';\nimport { mix } from 'polished';\n\nimport * as micIcon from '../Icon/icons/send-solid.icon';\nimport * as micSolidIcon from '../Icon/icons/square-solid.icon';\nimport type { NoChildrenProp, RefElement, TestIdProp, WithAttributes } from '../../types';\nimport { useI18n, useTestIds } from '../../hooks';\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport { tryCatch, withTestIds } from '../../utils';\nimport { defaultThemeProp } from '../../theme';\n\nimport { getSpeechToTextButtonTestIds } from './SpeechToTextButton.test-ids';\n\nregisterIcon(micIcon, micSolidIcon);\n\nconst StyledSpeechToTextButton = styled(Button)(({ theme }) => {\n const activeColor = tryCatch(() =>\n mix(0.85, theme.base.palette['primary-background'], theme.base.palette.interactive)\n );\n\n return css`\n &[aria-pressed='true'] {\n background-color: ${activeColor};\n }\n `;\n});\n\nStyledSpeechToTextButton.defaultProps = defaultThemeProp;\n\nexport type SpeechToTextButtonProps = WithAttributes<\n 'button',\n NoChildrenProp &\n TestIdProp & {\n /** Whether voice to text is active */\n active: boolean;\n /** Ref to the element */\n ref?: Ref<HTMLButtonElement>;\n }\n>;\n\nconst SpeechToTextButton = forwardRef<\n RefElement<SpeechToTextButtonProps>,\n PropsWithoutRef<SpeechToTextButtonProps>\n>(function SpeechToTextButton({ active, testId, ...restProps }, ref) {\n const t = useI18n();\n\n const testIds = useTestIds(testId, getSpeechToTextButtonTestIds);\n\n return (\n <StyledSpeechToTextButton\n ref={ref}\n data-testid={testIds.root}\n {...restProps}\n label={active ? t('stop_dictation') : t('dictate')}\n aria-pressed={active}\n variant='simple'\n icon\n >\n <Icon name={active ? 'mic-solid' : 'mic'} />\n </StyledSpeechToTextButton>\n );\n});\n\nexport default withTestIds(SpeechToTextButton, getSpeechToTextButtonTestIds);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpeechToTextButton.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/SpeechToTextButton.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,4BAA4B,mGAAsD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpeechToTextButton.test-ids.js","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/SpeechToTextButton.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,aAAa,CAAC,uBAAuB,EAAE,EAAW,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getSpeechToTextButtonTestIds = createTestIds('speech-to-text-button', [] as const);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/SpeechToTextButton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { default } from './SpeechToTextButton';\nexport type { SpeechToTextButtonProps } from './SpeechToTextButton';\n"]}
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { default as useRefMap } from './useRefMap';
|
|
|
30
30
|
export { default as useSimpleStore, createSimpleStore } from './useSimpleStore';
|
|
31
31
|
export type { SimpleStore } from './useSimpleStore';
|
|
32
32
|
export { default as useSimpleStoreInstance } from './useSimpleStoreInstance';
|
|
33
|
+
export { default as useSpeechRecognition } from './useSpeechRecognition';
|
|
33
34
|
export { default as useScrollStick } from './useScrollStick';
|
|
34
35
|
export { default as useScrollToggle } from './useScrollToggle';
|
|
35
36
|
export { default as useShortcut } from './useShortcut';
|
package/lib/hooks/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1F,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa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
29
29
|
export { default as useSimpleStore, createSimpleStore } from './useSimpleStore';
|
|
30
30
|
export { default as useSimpleStoreInstance } from './useSimpleStoreInstance';
|
|
31
|
+
export { default as useSpeechRecognition } from './useSpeechRecognition';
|
|
31
32
|
export { default as useScrollStick } from './useScrollStick';
|
|
32
33
|
export { default as useScrollToggle } from './useScrollToggle';
|
|
33
34
|
export { default as useShortcut } from './useShortcut';
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1F,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OA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MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export { default as useActiveDescendant, useLazyDescendant } from './useActiveDescendant';\nexport type { UseActiveDescendantConfig } from './useActiveDescendant';\nexport { default as useAfterInitialEffect } from './useAfterInitialEffect';\nexport { default as useAnimatedText } from './useAnimatedText';\nexport { default as useArrows } from './useArrows';\nexport { default as useAutoResize } from './useAutoResize';\nexport { default as useBreakpoint } from './useBreakpoint';\nexport { default as useChToPxConversionFactor } from './useChToPxConversionFactor';\nexport { default as useConfiguration } from './useConfiguration';\nexport { default as useConsolidatedRef } from './useConsolidatedRef';\nexport { default as useDirection } from './useDirection';\nexport { default as useDraggable } from './useDraggable';\nexport { default as useElement } from './useElement';\nexport { default as useEscape } from './useEscape';\nexport { default as useEvent } from './useEvent';\nexport { default as useFocusTrap } from './useFocusTrap';\nexport { default as useFocusWithin } from './useFocusWithin';\nexport { default as useI18n } from './useI18n';\nexport { default as useInputFormatter } from './useInputFormatter';\nexport { default as useItemIntersection } from './useItemIntersection';\nexport { default as useLiveLog } from './useLiveLog';\nexport { default as useLongPress } from './useLongPress';\nexport { default as useModalContext } from './useModalContext';\nexport { default as useModalManager } from './useModalManager';\nexport { default as useOS } from './useOS';\nexport { default as useOuterEvent } from './useOuterEvent';\nexport { default as usePopoverMap } from './usePopoverMap';\nexport { default as usePrevious } from './usePrevious';\nexport { default as useRefMap } from './useRefMap';\nexport { default as useSimpleStore, createSimpleStore } from './useSimpleStore';\nexport type { SimpleStore } from './useSimpleStore';\nexport { default as useSimpleStoreInstance } from './useSimpleStoreInstance';\nexport { default as useScrollStick } from './useScrollStick';\nexport { default as useScrollToggle } from './useScrollToggle';\nexport { default as useShortcut } from './useShortcut';\nexport { default as useShortcutManager } from './useShortcutManager';\nexport { default as useTestIds } from './useTestIds';\nexport { default as useTheme } from './useTheme';\nexport { default as useToaster } from './useToaster';\nexport { default as useTransitionState } from './useTransitionState';\nexport { default as useTriggerableEffect } from './useTriggerableEffect';\nexport { default as useElementFocus } from './useElementFocus';\nexport { default as useTriggerableLayoutEffect } from './useTriggerableLayoutEffect';\nexport { default as useUID } from './useUID';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1F,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CA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E,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEhF,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export { default as useActiveDescendant, useLazyDescendant } from './useActiveDescendant';\nexport type { UseActiveDescendantConfig } from './useActiveDescendant';\nexport { default as useAfterInitialEffect } from './useAfterInitialEffect';\nexport { default as useAnimatedText } from './useAnimatedText';\nexport { default as useArrows } from './useArrows';\nexport { default as useAutoResize } from './useAutoResize';\nexport { default as useBreakpoint } from './useBreakpoint';\nexport { default as useChToPxConversionFactor } from './useChToPxConversionFactor';\nexport { default as useConfiguration } from './useConfiguration';\nexport { default as useConsolidatedRef } from './useConsolidatedRef';\nexport { default as useDirection } from './useDirection';\nexport { default as useDraggable } from './useDraggable';\nexport { default as useElement } from './useElement';\nexport { default as useEscape } from './useEscape';\nexport { default as useEvent } from './useEvent';\nexport { default as useFocusTrap } from './useFocusTrap';\nexport { default as useFocusWithin } from './useFocusWithin';\nexport { default as useI18n } from './useI18n';\nexport { default as useInputFormatter } from './useInputFormatter';\nexport { default as useItemIntersection } from './useItemIntersection';\nexport { default as useLiveLog } from './useLiveLog';\nexport { default as useLongPress } from './useLongPress';\nexport { default as useModalContext } from './useModalContext';\nexport { default as useModalManager } from './useModalManager';\nexport { default as useOS } from './useOS';\nexport { default as useOuterEvent } from './useOuterEvent';\nexport { default as usePopoverMap } from './usePopoverMap';\nexport { default as usePrevious } from './usePrevious';\nexport { default as useRefMap } from './useRefMap';\nexport { default as useSimpleStore, createSimpleStore } from './useSimpleStore';\nexport type { SimpleStore } from './useSimpleStore';\nexport { default as useSimpleStoreInstance } from './useSimpleStoreInstance';\nexport { default as useSpeechRecognition } from './useSpeechRecognition';\nexport { default as useScrollStick } from './useScrollStick';\nexport { default as useScrollToggle } from './useScrollToggle';\nexport { default as useShortcut } from './useShortcut';\nexport { default as useShortcutManager } from './useShortcutManager';\nexport { default as useTestIds } from './useTestIds';\nexport { default as useTheme } from './useTheme';\nexport { default as useToaster } from './useToaster';\nexport { default as useTransitionState } from './useTransitionState';\nexport { default as useTriggerableEffect } from './useTriggerableEffect';\nexport { default as useElementFocus } from './useElementFocus';\nexport { default as useTriggerableLayoutEffect } from './useTriggerableLayoutEffect';\nexport { default as useUID } from './useUID';\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
declare const useAnimatedText: ({ text, allContentReceived, enabled, tokenizeMarkdown }: {
|
|
1
|
+
declare const useAnimatedText: ({ text, allContentReceived, enabled, tokenizeMarkdown, cursorStartIndex }: {
|
|
2
2
|
text: string;
|
|
3
3
|
allContentReceived: boolean;
|
|
4
4
|
enabled?: boolean;
|
|
5
5
|
tokenizeMarkdown?: boolean;
|
|
6
|
+
cursorStartIndex?: number;
|
|
6
7
|
}) => {
|
|
7
8
|
text: string;
|
|
8
9
|
isAnimationDone: boolean;
|
|
10
|
+
animatedTillCursor: number;
|
|
9
11
|
};
|
|
10
12
|
export default useAnimatedText;
|
|
11
13
|
//# sourceMappingURL=useAnimatedText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimatedText.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnimatedText.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,eAAe,GAAI,
|
|
1
|
+
{"version":3,"file":"useAnimatedText.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnimatedText.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,eAAe,GAAI,2EAMtB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;;;;CAwHA,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState, useRef } from 'react';
|
|
2
2
|
import tokenizeWithMarkdown from '../utils/markdownTokenizer';
|
|
3
|
-
const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tokenizeMarkdown = false }) => {
|
|
3
|
+
const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tokenizeMarkdown = false, cursorStartIndex }) => {
|
|
4
4
|
const [cursor, setCursor] = useState(0); // End pointer
|
|
5
5
|
const [startingCursor, setStartingCursor] = useState(0); // animation starting point
|
|
6
6
|
const [prevText, setPrevText] = useState(text);
|
|
@@ -20,6 +20,11 @@ const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tok
|
|
|
20
20
|
setStartingCursor(text.startsWith(prevText) ? cursor : 0);
|
|
21
21
|
setIsAnimationDone(false);
|
|
22
22
|
}
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (cursorStartIndex) {
|
|
25
|
+
setStartingCursor(cursorStartIndex);
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
23
28
|
useEffect(() => {
|
|
24
29
|
// If streaming is disabled just return the whole chunk back
|
|
25
30
|
if (!enabled) {
|
|
@@ -42,7 +47,7 @@ const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tok
|
|
|
42
47
|
let intervalId;
|
|
43
48
|
let startTime;
|
|
44
49
|
let isStopped = false;
|
|
45
|
-
let currentSpeed =
|
|
50
|
+
let currentSpeed = 100; // Start with normal speed
|
|
46
51
|
let lastCursor = startingCursor;
|
|
47
52
|
const processTextAnimation = () => {
|
|
48
53
|
if (isStopped)
|
|
@@ -52,7 +57,7 @@ const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tok
|
|
|
52
57
|
startTime = currentTime;
|
|
53
58
|
}
|
|
54
59
|
// When we have all content with us, speed up streaming animation
|
|
55
|
-
const targetSpeed = allContentReceivedRef.current ? 150 :
|
|
60
|
+
const targetSpeed = allContentReceivedRef.current ? 150 : 100;
|
|
56
61
|
// Smoothly transition to target speed
|
|
57
62
|
const speedDiff = targetSpeed - currentSpeed;
|
|
58
63
|
currentSpeed += speedDiff * 0.1; // Smooth transition
|
|
@@ -89,7 +94,8 @@ const useAnimatedText = ({ text, allContentReceived = false, enabled = true, tok
|
|
|
89
94
|
}, [startingCursor, text, tokenizeMarkdown]);
|
|
90
95
|
return {
|
|
91
96
|
text: getTokens(text).slice(0, cursor).join(''),
|
|
92
|
-
isAnimationDone
|
|
97
|
+
isAnimationDone,
|
|
98
|
+
animatedTillCursor: cursor
|
|
93
99
|
};
|
|
94
100
|
};
|
|
95
101
|
export default useAnimatedText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimatedText.js","sourceRoot":"","sources":["../../src/hooks/useAnimatedText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,EACvB,IAAI,EACJ,kBAAkB,GAAG,KAAK,EAC1B,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"useAnimatedText.js","sourceRoot":"","sources":["../../src/hooks/useAnimatedText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,EACvB,IAAI,EACJ,kBAAkB,GAAG,KAAK,EAC1B,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,KAAK,EACxB,gBAAgB,EAOjB,EAAE,EAAE;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc;IACvD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B;IAEpF,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9D,MAAM,qBAAqB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEzD,qBAAqB,CAAC,OAAO,GAAG,kBAAkB,CAAC;IAEnD,uCAAuC;IACvC,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAY,EAAE;QAChD,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,oBA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AAQ,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,uBAAuB;gBACjF,UAAU,GAAG,UAAU,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC;QAEF,yCAAyC;QACzC,UAAU,GAAG,UAAU,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;QAElD,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,UAAU,EAAE,CAAC;gBACf,YAAY,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAE7C,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,eAAe;QACf,kBAAkB,EAAE,MAAM;KAC3B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { useEffect, useState, useRef } from 'react';\n\nimport tokenizeWithMarkdown from '../utils/markdownTokenizer';\n\nconst useAnimatedText = ({\n text,\n allContentReceived = false,\n enabled = true,\n tokenizeMarkdown = false,\n cursorStartIndex\n}: {\n text: string;\n allContentReceived: boolean;\n enabled?: boolean;\n tokenizeMarkdown?: boolean;\n cursorStartIndex?: number;\n}) => {\n const [cursor, setCursor] = useState(0); // End pointer\n const [startingCursor, setStartingCursor] = useState(0); // animation starting point\n\n const [prevText, setPrevText] = useState(text);\n const [isAnimationDone, setIsAnimationDone] = useState(false);\n\n const allContentReceivedRef = useRef(allContentReceived);\n\n allContentReceivedRef.current = allContentReceived;\n\n // Tokenize text based on markdown flag\n const getTokens = (inputText: string): string[] => {\n if (tokenizeMarkdown) {\n return tokenizeWithMarkdown(inputText);\n }\n return inputText.split('');\n };\n\n // A new chunk has arrived\n if (prevText !== text) {\n setPrevText(text);\n setStartingCursor(text.startsWith(prevText) ? cursor : 0);\n setIsAnimationDone(false);\n }\n\n useEffect(() => {\n if (cursorStartIndex) {\n setStartingCursor(cursorStartIndex);\n }\n }, []);\n\n useEffect(() => {\n // If streaming is disabled just return the whole chunk back\n if (!enabled) {\n setCursor(getTokens(text).length);\n setIsAnimationDone(true);\n return;\n }\n\n const tokens = getTokens(text);\n const targetLength = tokens.length;\n const charactersToAnimate = targetLength - startingCursor;\n\n // If there are no more characters to animate\n if (charactersToAnimate <= 0) {\n setCursor(targetLength);\n // Only set animation done if we have all content AND no more characters to animate\n if (allContentReceivedRef.current) {\n setIsAnimationDone(true);\n }\n return;\n }\n\n let intervalId: ReturnType<typeof setTimeout>;\n let startTime: number;\n let isStopped = false;\n let currentSpeed = 100; // Start with normal speed\n let lastCursor = startingCursor;\n\n const processTextAnimation = () => {\n if (isStopped) return;\n\n const currentTime = performance.now();\n\n if (!startTime) {\n startTime = currentTime;\n }\n\n // When we have all content with us, speed up streaming animation\n const targetSpeed = allContentReceivedRef.current ? 150 : 100;\n\n // Smoothly transition to target speed\n const speedDiff = targetSpeed - currentSpeed;\n currentSpeed += speedDiff * 0.1; // Smooth transition\n\n const elapsed = currentTime - startTime;\n const timeStep = elapsed / 1000;\n\n // Calculate how many characters we should have shown by now\n const expectedCursor = Math.min(startingCursor + timeStep * currentSpeed, targetLength);\n\n const newCursor = Math.min(Math.floor(expectedCursor), targetLength);\n\n // Skip update if the cursor is at the same token\n if (newCursor !== lastCursor) {\n setCursor(newCursor);\n lastCursor = newCursor;\n }\n\n // End condition - stop when we reach the target\n if (newCursor >= targetLength && allContentReceivedRef.current) {\n setIsAnimationDone(true);\n return;\n }\n\n // Continue animation if not done\n if (newCursor < targetLength || !allContentReceivedRef.current) {\n // Use adaptive timing based on content state and visibility\n const interval = allContentReceivedRef.current ? 20 : 50; // Faster when complete\n intervalId = setTimeout(processTextAnimation, interval);\n }\n };\n\n // Start the animation with initial delay\n intervalId = setTimeout(processTextAnimation, 16);\n\n return () => {\n isStopped = true;\n if (intervalId) {\n clearTimeout(intervalId);\n }\n };\n }, [startingCursor, text, tokenizeMarkdown]);\n\n return {\n text: getTokens(text).slice(0, cursor).join(''),\n isAnimationDone,\n animatedTillCursor: cursor\n };\n};\n\nexport default useAnimatedText;\n"]}
|
package/lib/hooks/useI18n.d.ts
CHANGED
|
@@ -96,6 +96,12 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
96
96
|
reset: string;
|
|
97
97
|
refresh: string;
|
|
98
98
|
copy: string;
|
|
99
|
+
explain: string;
|
|
100
|
+
generate: string;
|
|
101
|
+
reject: string;
|
|
102
|
+
modify: string;
|
|
103
|
+
start: string;
|
|
104
|
+
stop: string;
|
|
99
105
|
view_all: string;
|
|
100
106
|
view_less: string;
|
|
101
107
|
show_more: string;
|
|
@@ -402,6 +408,7 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
402
408
|
double_checking_results: string;
|
|
403
409
|
finalizing_response: string;
|
|
404
410
|
response_generated: string;
|
|
411
|
+
processing_speech: string;
|
|
405
412
|
good_response: string;
|
|
406
413
|
bad_response: string;
|
|
407
414
|
share_feedback: string;
|
|
@@ -436,6 +443,13 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
436
443
|
shortcut_DismissToast: string;
|
|
437
444
|
configurable_layout_instructions: string;
|
|
438
445
|
page_number: string;
|
|
446
|
+
dictate: string;
|
|
447
|
+
stop_dictation: string;
|
|
448
|
+
no_speech_detected: string;
|
|
449
|
+
no_microphone_found: string;
|
|
450
|
+
microphone_access_denied: string;
|
|
451
|
+
speech_recognition_error: string;
|
|
452
|
+
speech_recognition_not_supported: string;
|
|
439
453
|
drag_handle_activate_description: string;
|
|
440
454
|
drag_handle_drop_description: string;
|
|
441
455
|
drag_handle_cancel_description: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.d.ts","sourceRoot":"","sources":["../../src/hooks/useI18n.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,QAAA,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"useI18n.d.ts","sourceRoot":"","sources":["../../src/hooks/useI18n.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGZ,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="dom-speech-recognition" preserve="true" />
|
|
2
|
+
/**
|
|
3
|
+
* Hook for speech-to-text conversion using the Web Speech API.
|
|
4
|
+
* Provides real-time voice recognition with support for interim results and automatic error handling.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseSpeechRecognitionProps {
|
|
7
|
+
/** onResult handler */
|
|
8
|
+
onResult: (text: string) => void;
|
|
9
|
+
/** onInterimResult handler */
|
|
10
|
+
onInterimResult?: (text: string) => void;
|
|
11
|
+
/** BCP 47 language tag */
|
|
12
|
+
langCode?: string;
|
|
13
|
+
}
|
|
14
|
+
export default function useSpeechRecognition({ onResult, onInterimResult, langCode }: UseSpeechRecognitionProps): {
|
|
15
|
+
supported: boolean;
|
|
16
|
+
active: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
start: () => void;
|
|
19
|
+
stop: () => void;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=useSpeechRecognition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechRecognition.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeechRecognition.ts"],"names":[],"mappings":";AAMA;;;GAGG;AAEH,MAAM,WAAW,yBAAyB;IACxC,uBAAuB;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,8BAA8B;IAC9B,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,QAAQ,EACR,eAAe,EACf,QAAwC,EACzC,EAAE,yBAAyB,GAAG;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB,CA2JA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/// <reference types="dom-speech-recognition" preserve="true" />
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import useI18n from './useI18n';
|
|
4
|
+
export default function useSpeechRecognition({ onResult, onInterimResult, langCode = navigator.language ?? 'en-US' }) {
|
|
5
|
+
const SpeechRecognitionAPI = window.SpeechRecognition ?? window.webkitSpeechRecognition;
|
|
6
|
+
const supported = !!SpeechRecognitionAPI;
|
|
7
|
+
const t = useI18n();
|
|
8
|
+
const [active, setActive] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const speechRecognitionRef = useRef(null);
|
|
11
|
+
const speechRecognitionACRef = useRef(new AbortController());
|
|
12
|
+
const onResultACRef = useRef(new AbortController());
|
|
13
|
+
const keepListeningRef = useRef(false);
|
|
14
|
+
const handleResult = useCallback((event) => {
|
|
15
|
+
let nextValue = '';
|
|
16
|
+
for (let i = event.resultIndex; i < event.results.length; i += 1) {
|
|
17
|
+
const result = event.results[i];
|
|
18
|
+
const processed = result[0].transcript;
|
|
19
|
+
nextValue += processed;
|
|
20
|
+
if (result.isFinal) {
|
|
21
|
+
onResult(nextValue);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
onInterimResult?.(nextValue);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [onResult, onInterimResult]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!speechRecognitionRef.current)
|
|
30
|
+
return;
|
|
31
|
+
onResultACRef.current.abort();
|
|
32
|
+
onResultACRef.current = new AbortController();
|
|
33
|
+
speechRecognitionRef.current.addEventListener('result', handleResult, {
|
|
34
|
+
signal: AbortSignal.any([speechRecognitionACRef.current.signal, onResultACRef.current.signal])
|
|
35
|
+
});
|
|
36
|
+
}, [handleResult]);
|
|
37
|
+
const startRecognition = useCallback(() => {
|
|
38
|
+
if (!supported)
|
|
39
|
+
return;
|
|
40
|
+
// abort previous listeners/session
|
|
41
|
+
speechRecognitionACRef.current.abort();
|
|
42
|
+
speechRecognitionACRef.current = new AbortController();
|
|
43
|
+
const recognition = new SpeechRecognitionAPI();
|
|
44
|
+
recognition.lang = langCode;
|
|
45
|
+
recognition.interimResults = true;
|
|
46
|
+
recognition.maxAlternatives = 1;
|
|
47
|
+
recognition.continuous = true;
|
|
48
|
+
recognition.addEventListener('start', () => {
|
|
49
|
+
setActive(true);
|
|
50
|
+
setError(null);
|
|
51
|
+
}, { signal: speechRecognitionACRef.current.signal });
|
|
52
|
+
recognition.addEventListener('result', handleResult, {
|
|
53
|
+
signal: AbortSignal.any([speechRecognitionACRef.current.signal, onResultACRef.current.signal])
|
|
54
|
+
});
|
|
55
|
+
recognition.addEventListener('error', event => {
|
|
56
|
+
if (event.error === 'no-speech') {
|
|
57
|
+
setError(t('no_speech_detected'));
|
|
58
|
+
}
|
|
59
|
+
else if (event.error === 'audio-capture') {
|
|
60
|
+
setError(t('no_microphone_found'));
|
|
61
|
+
}
|
|
62
|
+
else if (event.error === 'not-allowed') {
|
|
63
|
+
setError(t('microphone_access_denied'));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setError(t('speech_recognition_error', [event.error]));
|
|
67
|
+
}
|
|
68
|
+
setActive(false);
|
|
69
|
+
}, { signal: speechRecognitionACRef.current.signal });
|
|
70
|
+
recognition.addEventListener('end', () => {
|
|
71
|
+
if (keepListeningRef.current) {
|
|
72
|
+
startRecognition();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
setActive(false);
|
|
76
|
+
}
|
|
77
|
+
}, { signal: speechRecognitionACRef.current.signal });
|
|
78
|
+
speechRecognitionRef.current = recognition;
|
|
79
|
+
recognition.start();
|
|
80
|
+
}, [SpeechRecognitionAPI, langCode, t, handleResult, supported]);
|
|
81
|
+
const stop = useCallback(() => {
|
|
82
|
+
keepListeningRef.current = false;
|
|
83
|
+
const recognition = speechRecognitionRef.current;
|
|
84
|
+
if (!recognition) {
|
|
85
|
+
setActive(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
recognition.stop();
|
|
89
|
+
}, []);
|
|
90
|
+
const start = useCallback(() => {
|
|
91
|
+
setError(null);
|
|
92
|
+
if (!supported) {
|
|
93
|
+
setError(t('speech_recognition_not_supported'));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
keepListeningRef.current = true;
|
|
97
|
+
startRecognition();
|
|
98
|
+
}, [startRecognition, supported, t]);
|
|
99
|
+
// Stop recognition on page hide or visibility change
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const ac = new AbortController();
|
|
102
|
+
const handleVisibilityChange = () => {
|
|
103
|
+
if (document.visibilityState !== 'visible') {
|
|
104
|
+
stop();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('pagehide', stop, { signal: ac.signal });
|
|
108
|
+
window.addEventListener('blur', stop, { signal: ac.signal });
|
|
109
|
+
document.addEventListener('visibilitychange', handleVisibilityChange, { signal: ac.signal });
|
|
110
|
+
return () => {
|
|
111
|
+
ac.abort();
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
return {
|
|
115
|
+
supported,
|
|
116
|
+
active,
|
|
117
|
+
error,
|
|
118
|
+
start,
|
|
119
|
+
stop
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=useSpeechRecognition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechRecognition.js","sourceRoot":"","sources":["../../src/hooks/useSpeechRecognition.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,OAAO,MAAM,WAAW,CAAC;AAgBhC,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,QAAQ,EACR,eAAe,EACf,QAAQ,GAAG,SAAS,CAAC,QAAQ,IAAI,OAAO,EACd;IAO1B,MAAM,oBAAoB,GACxB,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC,uBAAuB,CAAC;IAE7D,MAAM,SAAS,GAAG,CAAC,CAAC,oBAAoB,CAAC;IAEzC,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,CAAC,KAAK,EAAE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,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,QAAQ,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC;YAChD,OAAO;QACT,CAAC;QAED,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;QAChC,gBAAgB,EAAE,CAAC;IACrB,CAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;IAErC,qDAAqD;IACrD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;QAEjC,MAAM,sBAAsB,GAAG,GAAG,EAAE;YAClC,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;gBAC3C,IAAI,EAAE,CAAC;YACT,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,sBAAsB,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAE7F,OAAO,GAAG,EAAE;YACV,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,SAAS;QACT,MAAM;QACN,KAAK;QACL,KAAK;QACL,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["/// <reference types=\"dom-speech-recognition\" preserve=\"true\" />\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport useI18n from './useI18n';\n\n/**\n * Hook for speech-to-text conversion using the Web Speech API.\n * Provides real-time voice recognition with support for interim results and automatic error handling.\n */\n\nexport interface UseSpeechRecognitionProps {\n /** onResult handler */\n onResult: (text: string) => void;\n /** onInterimResult handler */\n onInterimResult?: (text: string) => void;\n /** BCP 47 language tag */\n langCode?: string;\n}\n\nexport default function useSpeechRecognition({\n onResult,\n onInterimResult,\n langCode = navigator.language ?? 'en-US'\n}: UseSpeechRecognitionProps): {\n supported: boolean;\n active: boolean;\n error: string | null;\n start: () => void;\n stop: () => void;\n} {\n const SpeechRecognitionAPI: typeof SpeechRecognition | undefined =\n window.SpeechRecognition ?? window.webkitSpeechRecognition;\n\n const supported = !!SpeechRecognitionAPI;\n\n const t = useI18n();\n const [active, setActive] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const speechRecognitionRef = useRef<SpeechRecognition | null>(null);\n const speechRecognitionACRef = useRef(new AbortController());\n const onResultACRef = useRef(new AbortController());\n const keepListeningRef = useRef<boolean>(false);\n\n const handleResult = useCallback(\n (event: SpeechRecognitionEvent) => {\n let nextValue = '';\n\n for (let i = event.resultIndex; i < event.results.length; i += 1) {\n const result = event.results[i];\n const processed = result[0].transcript;\n nextValue += processed;\n\n if (result.isFinal) {\n onResult(nextValue);\n } else {\n onInterimResult?.(nextValue);\n }\n }\n },\n [onResult, onInterimResult]\n );\n\n useEffect(() => {\n if (!speechRecognitionRef.current) return;\n\n onResultACRef.current.abort();\n onResultACRef.current = new AbortController();\n\n speechRecognitionRef.current.addEventListener('result', handleResult, {\n signal: AbortSignal.any([speechRecognitionACRef.current.signal, onResultACRef.current.signal])\n });\n }, [handleResult]);\n\n const startRecognition = useCallback(() => {\n if (!supported) return;\n\n // abort previous listeners/session\n speechRecognitionACRef.current.abort();\n speechRecognitionACRef.current = new AbortController();\n\n const recognition = new SpeechRecognitionAPI();\n recognition.lang = langCode;\n recognition.interimResults = true;\n recognition.maxAlternatives = 1;\n recognition.continuous = true;\n\n recognition.addEventListener(\n 'start',\n () => {\n setActive(true);\n setError(null);\n },\n { signal: speechRecognitionACRef.current.signal }\n );\n\n recognition.addEventListener('result', handleResult, {\n signal: AbortSignal.any([speechRecognitionACRef.current.signal, onResultACRef.current.signal])\n });\n\n recognition.addEventListener(\n 'error',\n event => {\n if (event.error === 'no-speech') {\n setError(t('no_speech_detected'));\n } else if (event.error === 'audio-capture') {\n setError(t('no_microphone_found'));\n } else if (event.error === 'not-allowed') {\n setError(t('microphone_access_denied'));\n } else {\n setError(t('speech_recognition_error', [event.error]));\n }\n setActive(false);\n },\n { signal: speechRecognitionACRef.current.signal }\n );\n\n recognition.addEventListener(\n 'end',\n () => {\n if (keepListeningRef.current) {\n startRecognition();\n } else {\n setActive(false);\n }\n },\n { signal: speechRecognitionACRef.current.signal }\n );\n\n speechRecognitionRef.current = recognition;\n recognition.start();\n }, [SpeechRecognitionAPI, langCode, t, handleResult, supported]);\n\n const stop = useCallback(() => {\n keepListeningRef.current = false;\n\n const recognition = speechRecognitionRef.current;\n\n if (!recognition) {\n setActive(false);\n return;\n }\n\n recognition.stop();\n }, []);\n\n const start = useCallback(() => {\n setError(null);\n\n if (!supported) {\n setError(t('speech_recognition_not_supported'));\n return;\n }\n\n keepListeningRef.current = true;\n startRecognition();\n }, [startRecognition, supported, t]);\n\n // Stop recognition on page hide or visibility change\n useEffect(() => {\n const ac = new AbortController();\n\n const handleVisibilityChange = () => {\n if (document.visibilityState !== 'visible') {\n stop();\n }\n };\n\n window.addEventListener('pagehide', stop, { signal: ac.signal });\n window.addEventListener('blur', stop, { signal: ac.signal });\n document.addEventListener('visibilitychange', handleVisibilityChange, { signal: ac.signal });\n\n return () => {\n ac.abort();\n };\n }, []);\n\n return {\n supported,\n active,\n error,\n start,\n stop\n };\n}\n"]}
|
package/lib/i18n/default.d.ts
CHANGED
|
@@ -92,6 +92,12 @@ declare const _default: {
|
|
|
92
92
|
reset: string;
|
|
93
93
|
refresh: string;
|
|
94
94
|
copy: string;
|
|
95
|
+
explain: string;
|
|
96
|
+
generate: string;
|
|
97
|
+
reject: string;
|
|
98
|
+
modify: string;
|
|
99
|
+
start: string;
|
|
100
|
+
stop: string;
|
|
95
101
|
view_all: string;
|
|
96
102
|
view_less: string;
|
|
97
103
|
show_more: string;
|
|
@@ -398,6 +404,7 @@ declare const _default: {
|
|
|
398
404
|
double_checking_results: string;
|
|
399
405
|
finalizing_response: string;
|
|
400
406
|
response_generated: string;
|
|
407
|
+
processing_speech: string;
|
|
401
408
|
good_response: string;
|
|
402
409
|
bad_response: string;
|
|
403
410
|
share_feedback: string;
|
|
@@ -432,6 +439,13 @@ declare const _default: {
|
|
|
432
439
|
shortcut_DismissToast: string;
|
|
433
440
|
configurable_layout_instructions: string;
|
|
434
441
|
page_number: string;
|
|
442
|
+
dictate: string;
|
|
443
|
+
stop_dictation: string;
|
|
444
|
+
no_speech_detected: string;
|
|
445
|
+
no_microphone_found: string;
|
|
446
|
+
microphone_access_denied: string;
|
|
447
|
+
speech_recognition_error: string;
|
|
448
|
+
speech_recognition_not_supported: string;
|
|
435
449
|
drag_handle_activate_description: string;
|
|
436
450
|
drag_handle_drop_description: string;
|
|
437
451
|
drag_handle_cancel_description: string;
|