@cloudscape-design/components-themeable 3.0.956 → 3.0.957
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/internal/manifest.json +1 -1
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/internal/environment.json +1 -1
- package/lib/internal/template/live-region/internal.d.ts +1 -0
- package/lib/internal/template/live-region/internal.d.ts.map +1 -1
- package/lib/internal/template/live-region/internal.js +15 -2
- package/lib/internal/template/live-region/internal.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,4 +28,5 @@ export interface InternalLiveRegionRef {
|
|
|
28
28
|
}
|
|
29
29
|
declare const _default: React.ForwardRefExoticComponent<InternalLiveRegionProps & React.RefAttributes<InternalLiveRegionRef>>;
|
|
30
30
|
export default _default;
|
|
31
|
+
export declare function extractTextContent(node: HTMLElement): string;
|
|
31
32
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/live-region/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAK/C,UAAU,uBAAwB,SAAQ,0BAA0B,EAAE,eAAe;IACnF;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,UAAU,IAAI,IAAI,CAAC;CACpB;;AAED,wBAyEG"}
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/live-region/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAK/C,UAAU,uBAAwB,SAAQ,0BAA0B,EAAE,eAAe;IACnF;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,UAAU,IAAI,IAAI,CAAC;CACpB;;AAED,wBAyEG;AAcH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAU5D"}
|
|
@@ -57,12 +57,25 @@ export default React.forwardRef(function InternalLiveRegion(_a, ref) {
|
|
|
57
57
|
}));
|
|
58
58
|
return (React.createElement(TagName, Object.assign({ ref: mergedRef }, baseProps, { className: clsx(styles.root, testUtilStyles.root, className), hidden: hidden }), children));
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
const processNode = (childNode) => {
|
|
61
|
+
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
62
|
+
return childNode.textContent || '';
|
|
63
|
+
}
|
|
64
|
+
if (childNode.nodeType === Node.ELEMENT_NODE) {
|
|
65
|
+
return extractTextContent(childNode);
|
|
66
|
+
}
|
|
67
|
+
return '';
|
|
68
|
+
};
|
|
69
|
+
export function extractTextContent(node) {
|
|
70
|
+
var _a;
|
|
61
71
|
// We use the text content of the node as the announcement text.
|
|
62
72
|
// This only extracts text content from the node including all its children which is enough for now.
|
|
63
73
|
// To make it more powerful, it is possible to create a more sophisticated extractor with respect to
|
|
64
74
|
// ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.
|
|
65
|
-
|
|
75
|
+
if (!node || !((_a = node === null || node === void 0 ? void 0 : node.childNodes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
return Array.from(node.childNodes, processNode).join(' ').replace(/\s+/g, ' ').trim();
|
|
66
79
|
}
|
|
67
80
|
function getSourceContent(source) {
|
|
68
81
|
return source
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/live-region/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,cAAc,MAAM,8BAA8B,CAAC;AA8B1D,eAAe,KAAK,CAAC,UAAU,CAAC,SAAS,kBAAkB,CACzD,EAU0B,EAC1B,GAAqC;QAXrC,EACE,SAAS,GAAG,KAAK,EACjB,MAAM,GAAG,KAAK,EACd,OAAO,EAAE,OAAO,GAAG,KAAK,EACxB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,SAAS,OAEe,EADrB,SAAS,cATd,oGAUC,CADa;IAId,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,MAAM,CAAmC,IAAI,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IAE/D,SAAS,CAAC,GAAG,EAAE;QACb,oEAAoE;QACpE,yEAAyE;QACzE,qEAAqE;QACrE,mEAAmE;QACnE,iDAAiD;QACjD,IA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,CAAC;SACb;QACD,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACzC;IACH,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useImperativeHandle, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { LiveRegionController } from './controller';\nimport { LiveRegionProps } from './interfaces';\n\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\ninterface InternalLiveRegionProps extends InternalBaseComponentProps, LiveRegionProps {\n /**\n * The delay between each announcement from this live region. You should\n * leave this set to the default unless this live region is commonly\n * interrupted by other actions (like text entry in text filtering).\n */\n delay?: number;\n\n /**\n * Use a list of strings and/or refs to existing elements for building the\n * announcement text. If this property is set, `children` and `message` will\n * be ignored.\n */\n sources?: ReadonlyArray<string | React.RefObject<HTMLElement> | undefined>;\n}\n\nexport interface InternalLiveRegionRef {\n /**\n * Force the live region to announce the message, even if it's the same as\n * the previously announced message.\n *\n * This is useful when making status updates after a change (e.g. filtering)\n * where the new message might be the same as the old one, but the announcement\n * also serves to tell screen reader users that the action was performed.\n */\n reannounce(): void;\n}\n\nexport default React.forwardRef(function InternalLiveRegion(\n {\n assertive = false,\n hidden = false,\n tagName: TagName = 'div',\n delay,\n sources,\n children,\n __internalRootRef,\n className,\n ...restProps\n }: InternalLiveRegionProps,\n ref: React.Ref<InternalLiveRegionRef>\n) {\n const baseProps = getBaseProps(restProps);\n const childrenRef = useRef<HTMLSpanElement & HTMLDivElement>(null);\n const mergedRef = useMergeRefs(childrenRef, __internalRootRef);\n\n useEffect(() => {\n // We have to do this because `inert` isn't properly supported until\n // React 19 and this seems much more maintainable than version detection.\n // `inert` is better than `hidden` because it also blocks pointer and\n // focus events as well as hiding the contents from screen readers.\n // https://github.com/facebook/react/issues/17157\n if (childrenRef.current) {\n childrenRef.current.inert = hidden;\n }\n }, [hidden]);\n\n // Initialize the live region controller inside an effect. We have to do this\n // because the controller depends on DOM elements, which aren't available on the\n // server.\n const liveRegionControllerRef = useRef<LiveRegionController | undefined>();\n useEffect(() => {\n const liveRegionController = new LiveRegionController(assertive ? 'assertive' : 'polite');\n liveRegionControllerRef.current = liveRegionController;\n return () => {\n liveRegionController.destroy();\n liveRegionControllerRef.current = undefined;\n };\n }, [assertive]);\n\n const getContent = () => {\n if (sources) {\n return getSourceContent(sources);\n }\n if (childrenRef.current) {\n return extractTextContent(childrenRef.current);\n }\n };\n\n // Call the controller on every render. The controller will deduplicate the\n // message against the previous announcement internally.\n useEffect(() => {\n liveRegionControllerRef.current?.announce({ message: getContent(), delay });\n });\n\n useImperativeHandle(ref, () => ({\n reannounce() {\n liveRegionControllerRef.current?.announce({ message: getContent(), delay, forceReannounce: true });\n },\n }));\n\n return (\n <TagName\n ref={mergedRef}\n {...baseProps}\n className={clsx(styles.root, testUtilStyles.root, className)}\n hidden={hidden}\n >\n {children}\n </TagName>\n );\n});\n\nconst processNode = (childNode: Node): string => {\n if (childNode.nodeType === Node.TEXT_NODE) {\n return childNode.textContent || '';\n }\n\n if (childNode.nodeType === Node.ELEMENT_NODE) {\n return extractTextContent(childNode as HTMLElement);\n }\n\n return '';\n};\n\nexport function extractTextContent(node: HTMLElement): string {\n // We use the text content of the node as the announcement text.\n // This only extracts text content from the node including all its children which is enough for now.\n // To make it more powerful, it is possible to create a more sophisticated extractor with respect to\n // ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.\n if (!node || !node?.childNodes?.length) {\n return '';\n }\n\n return Array.from(node.childNodes, processNode).join(' ').replace(/\\s+/g, ' ').trim();\n}\n\nfunction getSourceContent(source: ReadonlyArray<string | React.RefObject<HTMLElement> | undefined>): string {\n return source\n .map(item => {\n if (!item || typeof item === 'string') {\n return item;\n }\n if (item.current) {\n return extractTextContent(item.current);\n }\n })\n .filter(Boolean)\n .join(' ');\n}\n"]}
|