@cloudscape-design/components 3.0.310 → 3.0.312
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/button/internal.d.ts +6 -0
- package/button/internal.d.ts.map +1 -1
- package/button/internal.js +6 -8
- package/button/internal.js.map +1 -1
- package/code-editor/resizable-box/styles.css.js +3 -3
- package/code-editor/resizable-box/styles.scoped.css +10 -8
- package/code-editor/resizable-box/styles.selectors.js +3 -3
- package/code-editor/styles.css.js +32 -32
- package/code-editor/styles.scoped.css +189 -157
- package/code-editor/styles.selectors.js +32 -32
- package/collection-preferences/content-display/index.js +1 -1
- package/collection-preferences/content-display/index.js.map +1 -1
- package/container/interfaces.d.ts +50 -0
- package/container/interfaces.d.ts.map +1 -1
- package/container/interfaces.js.map +1 -1
- package/container/internal.d.ts +1 -1
- package/container/internal.d.ts.map +1 -1
- package/container/internal.js +24 -18
- package/container/internal.js.map +1 -1
- package/container/styles.css.js +28 -18
- package/container/styles.scoped.css +93 -36
- package/container/styles.selectors.js +28 -18
- package/date-range-picker/calendar/header/index.d.ts.map +1 -1
- package/date-range-picker/calendar/header/index.js +4 -2
- package/date-range-picker/calendar/header/index.js.map +1 -1
- package/date-range-picker/calendar/index.js +1 -1
- package/date-range-picker/calendar/index.js.map +1 -1
- package/expandable-section/expandable-section-header.d.ts +2 -1
- package/expandable-section/expandable-section-header.d.ts.map +1 -1
- package/expandable-section/expandable-section-header.js +6 -16
- package/expandable-section/expandable-section-header.js.map +1 -1
- package/expandable-section/internal.d.ts.map +1 -1
- package/expandable-section/internal.js +3 -2
- package/expandable-section/internal.js.map +1 -1
- package/form/index.d.ts.map +1 -1
- package/form/index.js +14 -1
- package/form/index.js.map +1 -1
- package/form/internal.d.ts.map +1 -1
- package/form/internal.js +3 -4
- package/form/internal.js.map +1 -1
- package/form-field/internal.js +2 -3
- package/form-field/internal.js.map +1 -1
- package/help-panel/styles.css.js +4 -4
- package/help-panel/styles.scoped.css +135 -95
- package/help-panel/styles.selectors.js +4 -4
- package/i18n/context.d.ts +14 -7
- package/i18n/context.d.ts.map +1 -1
- package/i18n/context.js.map +1 -1
- package/i18n/messages/all.all.js +3692 -538
- package/i18n/messages/all.all.json +3756 -577
- package/i18n/messages/all.de.js +317 -22
- package/i18n/messages/all.de.json +324 -27
- package/i18n/messages/all.en-GB.js +306 -21
- package/i18n/messages/all.en-GB.json +309 -24
- package/i18n/messages/all.en.js +11 -11
- package/i18n/messages/all.en.json +11 -11
- package/i18n/messages/all.es.js +311 -22
- package/i18n/messages/all.es.json +318 -25
- package/i18n/messages/all.fr.js +335 -27
- package/i18n/messages/all.fr.json +343 -30
- package/i18n/messages/all.id.js +319 -28
- package/i18n/messages/all.id.json +322 -31
- package/i18n/messages/all.it.js +320 -27
- package/i18n/messages/all.it.json +326 -30
- package/i18n/messages/all.ja.js +312 -28
- package/i18n/messages/all.ja.json +315 -30
- package/i18n/messages/all.ko.js +304 -24
- package/i18n/messages/all.ko.json +312 -25
- package/i18n/messages/all.pt-BR.js +313 -28
- package/i18n/messages/all.pt-BR.json +325 -31
- package/i18n/messages/all.zh-CN.js +301 -29
- package/i18n/messages/all.zh-CN.json +300 -31
- package/i18n/messages/all.zh-TW.js +295 -23
- package/i18n/messages/all.zh-TW.json +294 -25
- package/i18n/messages-types.d.ts +435 -0
- package/i18n/messages-types.d.ts.map +1 -0
- package/i18n/messages-types.js +5 -0
- package/i18n/messages-types.js.map +1 -0
- package/i18n/provider.d.ts.map +1 -1
- package/i18n/provider.js +2 -0
- package/i18n/provider.js.map +1 -1
- package/internal/analytics/components/analytics-funnel.d.ts +2 -1
- package/internal/analytics/components/analytics-funnel.d.ts.map +1 -1
- package/internal/analytics/components/analytics-funnel.js +6 -4
- package/internal/analytics/components/analytics-funnel.js.map +1 -1
- package/internal/analytics/context/analytics-context.d.ts +2 -0
- package/internal/analytics/context/analytics-context.d.ts.map +1 -1
- package/internal/analytics/context/analytics-context.js +2 -0
- package/internal/analytics/context/analytics-context.js.map +1 -1
- package/internal/analytics/hooks/use-funnel.d.ts +3 -7
- package/internal/analytics/hooks/use-funnel.d.ts.map +1 -1
- package/internal/analytics/hooks/use-funnel.js +2 -7
- package/internal/analytics/hooks/use-funnel.js.map +1 -1
- package/internal/base-component/styles.scoped.css +382 -379
- package/internal/components/cartesian-chart/bottom-labels.js +1 -1
- package/internal/components/cartesian-chart/bottom-labels.js.map +1 -1
- package/internal/components/cartesian-chart/left-labels.js +1 -1
- package/internal/components/cartesian-chart/left-labels.js.map +1 -1
- package/internal/components/focus-lock/index.js +20 -19
- package/internal/components/focus-lock/index.js.map +1 -1
- package/internal/context/button-context.d.ts +10 -0
- package/internal/context/button-context.d.ts.map +1 -0
- package/internal/context/button-context.js +10 -0
- package/internal/context/button-context.js.map +1 -0
- package/internal/environment.js +1 -1
- package/internal/generated/theming/index.cjs +2 -1
- package/internal/generated/theming/index.js +2 -1
- package/internal/hooks/use-visual-mode/index.d.ts.map +1 -1
- package/internal/hooks/use-visual-mode/index.js +3 -0
- package/internal/hooks/use-visual-mode/index.js.map +1 -1
- package/internal/i18n/messages/all.all.js +3692 -538
- package/internal/i18n/messages/all.all.json +3756 -577
- package/internal/i18n/messages/all.de.js +317 -22
- package/internal/i18n/messages/all.de.json +324 -27
- package/internal/i18n/messages/all.en-GB.js +306 -21
- package/internal/i18n/messages/all.en-GB.json +309 -24
- package/internal/i18n/messages/all.en.js +11 -11
- package/internal/i18n/messages/all.en.json +11 -11
- package/internal/i18n/messages/all.es.js +311 -22
- package/internal/i18n/messages/all.es.json +318 -25
- package/internal/i18n/messages/all.fr.js +335 -27
- package/internal/i18n/messages/all.fr.json +343 -30
- package/internal/i18n/messages/all.id.js +319 -28
- package/internal/i18n/messages/all.id.json +322 -31
- package/internal/i18n/messages/all.it.js +320 -27
- package/internal/i18n/messages/all.it.json +326 -30
- package/internal/i18n/messages/all.ja.js +312 -28
- package/internal/i18n/messages/all.ja.json +315 -30
- package/internal/i18n/messages/all.ko.js +304 -24
- package/internal/i18n/messages/all.ko.json +312 -25
- package/internal/i18n/messages/all.pt-BR.js +313 -28
- package/internal/i18n/messages/all.pt-BR.json +325 -31
- package/internal/i18n/messages/all.zh-CN.js +301 -29
- package/internal/i18n/messages/all.zh-CN.json +300 -31
- package/internal/i18n/messages/all.zh-TW.js +295 -23
- package/internal/i18n/messages/all.zh-TW.json +294 -25
- package/internal/manifest.json +1 -1
- package/package.json +1 -2
- package/pagination/internal.d.ts.map +1 -1
- package/pagination/internal.js +4 -4
- package/pagination/internal.js.map +1 -1
- package/pie-chart/utils.d.ts +1 -1
- package/pie-chart/utils.d.ts.map +1 -1
- package/pie-chart/utils.js.map +1 -1
- package/property-filter/index.d.ts.map +1 -1
- package/property-filter/index.js +1 -1
- package/property-filter/index.js.map +1 -1
- package/s3-resource-selector/interfaces.d.ts +3 -0
- package/s3-resource-selector/interfaces.d.ts.map +1 -1
- package/s3-resource-selector/interfaces.js.map +1 -1
- package/s3-resource-selector/s3-in-context/index.js +1 -1
- package/s3-resource-selector/s3-in-context/index.js.map +1 -1
- package/s3-resource-selector/s3-in-context/validation.d.ts +1 -1
- package/s3-resource-selector/s3-in-context/validation.d.ts.map +1 -1
- package/s3-resource-selector/s3-in-context/validation.js.map +1 -1
- package/s3-resource-selector/s3-modal/basic-table.d.ts +3 -1
- package/s3-resource-selector/s3-modal/basic-table.d.ts.map +1 -1
- package/s3-resource-selector/s3-modal/basic-table.js +2 -1
- package/s3-resource-selector/s3-modal/basic-table.js.map +1 -1
- package/s3-resource-selector/s3-modal/index.js +1 -1
- package/s3-resource-selector/s3-modal/index.js.map +1 -1
- package/s3-resource-selector/s3-modal/table-utils.d.ts +1 -1
- package/s3-resource-selector/s3-modal/table-utils.d.ts.map +1 -1
- package/s3-resource-selector/s3-modal/table-utils.js.map +1 -1
- package/select/parts/filter.d.ts +1 -1
- package/space-between/interfaces.d.ts +5 -0
- package/space-between/interfaces.d.ts.map +1 -1
- package/space-between/interfaces.js.map +1 -1
- package/space-between/internal.d.ts +1 -1
- package/space-between/internal.d.ts.map +1 -1
- package/space-between/internal.js +2 -2
- package/space-between/internal.js.map +1 -1
- package/space-between/styles.css.js +21 -20
- package/space-between/styles.scoped.css +25 -21
- package/space-between/styles.selectors.js +21 -20
- package/tag-editor/interfaces.d.ts +1 -0
- package/tag-editor/interfaces.d.ts.map +1 -1
- package/tag-editor/interfaces.js.map +1 -1
- package/tag-editor/validation.d.ts +1 -1
- package/tag-editor/validation.d.ts.map +1 -1
- package/tag-editor/validation.js.map +1 -1
- package/test-utils/dom/container/index.d.ts +1 -0
- package/test-utils/dom/container/index.js +3 -0
- package/test-utils/dom/container/index.js.map +1 -1
- package/test-utils/dom/expandable-section/index.js +1 -1
- package/test-utils/dom/expandable-section/index.js.map +1 -1
- package/test-utils/selectors/container/index.d.ts +1 -0
- package/test-utils/selectors/container/index.js +3 -0
- package/test-utils/selectors/container/index.js.map +1 -1
- package/test-utils/selectors/expandable-section/index.js +1 -1
- package/test-utils/selectors/expandable-section/index.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/text-content/styles.css.js +1 -1
- package/text-content/styles.scoped.css +65 -64
- package/text-content/styles.selectors.js +1 -1
- package/top-navigation/parts/overflow-menu/views/submenu.js +2 -2
- package/top-navigation/parts/overflow-menu/views/submenu.js.map +1 -1
- package/top-navigation/parts/overflow-menu/views/utilities.js +2 -2
- package/top-navigation/parts/overflow-menu/views/utilities.js.map +1 -1
- package/wizard/internal.d.ts.map +1 -1
- package/wizard/internal.js +4 -2
- package/wizard/internal.js.map +1 -1
- package/wizard/wizard-form.d.ts.map +1 -1
- package/wizard/wizard-form.js +1 -2
- package/wizard/wizard-form.js.map +1 -1
|
@@ -8,11 +8,11 @@ import { useUniqueId } from '../../hooks/use-unique-id';
|
|
|
8
8
|
import { useVisualRefresh } from '../../hooks/use-visual-mode';
|
|
9
9
|
import { PACKAGE_VERSION } from '../../environment';
|
|
10
10
|
import { FunnelMetrics } from '../';
|
|
11
|
-
import { getFunnelNameSelector, getSubStepAllSelector, getSubStepNameSelector, getSubStepSelector } from '../selectors';
|
|
11
|
+
import { DATA_ATTR_FUNNEL_STEP, getFunnelNameSelector, getSubStepAllSelector, getSubStepNameSelector, getSubStepSelector, } from '../selectors';
|
|
12
12
|
export const FUNNEL_VERSION = '1.0';
|
|
13
13
|
export const AnalyticsFunnel = (_a) => {
|
|
14
14
|
var { children } = _a, props = __rest(_a, ["children"]);
|
|
15
|
-
const [funnelInteractionId, setFunnelInteractionId] = useState();
|
|
15
|
+
const [funnelInteractionId, setFunnelInteractionId] = useState('');
|
|
16
16
|
const funnelResultRef = useRef(false);
|
|
17
17
|
const isVisualRefresh = useVisualRefresh();
|
|
18
18
|
// This useEffect hook is run once on component mount to initiate the funnel analytics.
|
|
@@ -37,7 +37,6 @@ export const AnalyticsFunnel = (_a) => {
|
|
|
37
37
|
});
|
|
38
38
|
setFunnelInteractionId(funnelInteractionId);
|
|
39
39
|
return () => {
|
|
40
|
-
FunnelMetrics.funnelComplete({ funnelInteractionId });
|
|
41
40
|
if (funnelResultRef.current === true) {
|
|
42
41
|
FunnelMetrics.funnelSuccessful({ funnelInteractionId });
|
|
43
42
|
}
|
|
@@ -48,6 +47,7 @@ export const AnalyticsFunnel = (_a) => {
|
|
|
48
47
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
48
|
}, []);
|
|
50
49
|
const funnelSubmit = () => {
|
|
50
|
+
FunnelMetrics.funnelComplete({ funnelInteractionId });
|
|
51
51
|
funnelResultRef.current = true;
|
|
52
52
|
};
|
|
53
53
|
const funnelCancel = () => {
|
|
@@ -66,6 +66,7 @@ export const AnalyticsFunnel = (_a) => {
|
|
|
66
66
|
};
|
|
67
67
|
export const AnalyticsFunnelStep = ({ children, stepNumber, stepNameSelector }) => {
|
|
68
68
|
const { funnelInteractionId } = useFunnel();
|
|
69
|
+
const funnelStepProps = { [DATA_ATTR_FUNNEL_STEP]: stepNumber };
|
|
69
70
|
// This useEffect hook is used to track the start and completion of interaction with the step.
|
|
70
71
|
// On mount, if there is a valid funnel interaction id, it calls the 'funnelStepStart' method from FunnelMetrics
|
|
71
72
|
// to record the beginning of the interaction with the current step.
|
|
@@ -90,7 +91,8 @@ export const AnalyticsFunnelStep = ({ children, stepNumber, stepNameSelector })
|
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
}, [funnelInteractionId, stepNumber, stepNameSelector]);
|
|
93
|
-
|
|
94
|
+
const contextValue = { funnelInteractionId, stepNumber, stepNameSelector, funnelStepProps };
|
|
95
|
+
return (React.createElement(FunnelStepContext.Provider, { value: contextValue }, typeof children === 'function' ? children(contextValue) : children));
|
|
94
96
|
};
|
|
95
97
|
export const AnalyticsFunnelSubStep = ({ children }) => {
|
|
96
98
|
const { funnelInteractionId } = useFunnel();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-funnel.js","sourceRoot":"lib/default/","sources":["internal/analytics/components/analytics-funnel.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,
|
|
1
|
+
{"version":3,"file":"analytics-funnel.js","sourceRoot":"lib/default/","sources":["internal/analytics/components/analytics-funnel.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,GAGd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA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// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport {\n FunnelStepContext,\n FunnelSubStepContext,\n FunnelContext,\n FunnelContextValue,\n FunnelStepContextValue,\n} from '../context/analytics-context';\nimport { useFunnel, useFunnelStep } from '../hooks/use-funnel';\nimport { useUniqueId } from '../../hooks/use-unique-id';\nimport { useVisualRefresh } from '../../hooks/use-visual-mode';\n\nimport { PACKAGE_VERSION } from '../../environment';\n\nimport { FunnelMetrics } from '../';\nimport { FunnelProps, FunnelStepProps } from '../interfaces';\n\nimport {\n DATA_ATTR_FUNNEL_STEP,\n getFunnelNameSelector,\n getSubStepAllSelector,\n getSubStepNameSelector,\n getSubStepSelector,\n} from '../selectors';\n\nexport const FUNNEL_VERSION = '1.0';\n\ntype AnalyticsFunnelProps = { children?: React.ReactNode } & Pick<\n FunnelProps,\n 'funnelType' | 'optionalStepNumbers' | 'totalFunnelSteps'\n>;\n\nexport const AnalyticsFunnel = ({ children, ...props }: AnalyticsFunnelProps) => {\n const [funnelInteractionId, setFunnelInteractionId] = useState<string>('');\n const funnelResultRef = useRef<boolean>(false);\n const isVisualRefresh = useVisualRefresh();\n\n // This useEffect hook is run once on component mount to initiate the funnel analytics.\n // It first calls the 'funnelStart' method from FunnelMetrics, providing all necessary details\n // about the funnel, and receives a unique interaction id.\n // This unique interaction id is then stored in the state for further use.\n //\n // On component unmount, it checks whether the funnel was successfully completed.\n // Based on this, it either calls 'funnelComplete' or 'funnelCancelled' method from FunnelMetrics.\n //\n // The eslint-disable is required as we deliberately want this effect to run only once on mount and unmount,\n // hence we do not provide any dependencies.\n useEffect(() => {\n const funnelInteractionId = FunnelMetrics.funnelStart({\n funnelNameSelector: getFunnelNameSelector(),\n optionalStepNumbers: props.optionalStepNumbers,\n funnelType: props.funnelType,\n totalFunnelSteps: props.totalFunnelSteps,\n componentVersion: PACKAGE_VERSION,\n theme: isVisualRefresh ? 'vr' : 'classic',\n funnelVersion: FUNNEL_VERSION,\n });\n\n setFunnelInteractionId(funnelInteractionId);\n\n return () => {\n if (funnelResultRef.current === true) {\n FunnelMetrics.funnelSuccessful({ funnelInteractionId });\n } else {\n FunnelMetrics.funnelCancelled({ funnelInteractionId });\n }\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const funnelSubmit = () => {\n FunnelMetrics.funnelComplete({ funnelInteractionId });\n funnelResultRef.current = true;\n };\n\n const funnelCancel = () => {\n funnelResultRef.current = false;\n };\n\n const funnelContextValue: FunnelContextValue = {\n funnelInteractionId,\n setFunnelInteractionId,\n funnelType: props.funnelType,\n optionalStepNumbers: props.optionalStepNumbers,\n totalFunnelSteps: props.totalFunnelSteps,\n funnelSubmit,\n funnelCancel,\n };\n\n return <FunnelContext.Provider value={funnelContextValue}>{children}</FunnelContext.Provider>;\n};\n\ntype AnalyticsFunnelStepProps = {\n children?: React.ReactNode | ((props: FunnelStepContextValue) => React.ReactNode);\n} & Pick<FunnelStepProps, 'stepNumber' | 'stepNameSelector'>;\n\nexport const AnalyticsFunnelStep = ({ children, stepNumber, stepNameSelector }: AnalyticsFunnelStepProps) => {\n const { funnelInteractionId } = useFunnel();\n\n const funnelStepProps = { [DATA_ATTR_FUNNEL_STEP]: stepNumber };\n\n // This useEffect hook is used to track the start and completion of interaction with the step.\n // On mount, if there is a valid funnel interaction id, it calls the 'funnelStepStart' method from FunnelMetrics\n // to record the beginning of the interaction with the current step.\n // On unmount, it does a similar thing but this time calling 'funnelStepComplete' to record the completion of the interaction.\n useEffect(() => {\n if (funnelInteractionId) {\n FunnelMetrics.funnelStepStart({\n funnelInteractionId,\n stepNumber,\n stepNameSelector,\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n\n return () => {\n if (funnelInteractionId) {\n FunnelMetrics.funnelStepComplete({\n funnelInteractionId,\n stepNumber,\n stepNameSelector,\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n };\n }, [funnelInteractionId, stepNumber, stepNameSelector]);\n\n const contextValue: FunnelStepContextValue = { funnelInteractionId, stepNumber, stepNameSelector, funnelStepProps };\n return (\n <FunnelStepContext.Provider value={contextValue}>\n {typeof children === 'function' ? children(contextValue) : children}\n </FunnelStepContext.Provider>\n );\n};\ninterface AnalyticsFunnelSubStepProps {\n children?: React.ReactNode;\n}\n\nexport const AnalyticsFunnelSubStep = ({ children }: AnalyticsFunnelSubStepProps) => {\n const { funnelInteractionId } = useFunnel();\n const { stepNumber, stepNameSelector } = useFunnelStep();\n\n const subStepId = useUniqueId('substep');\n const subStepSelector = getSubStepSelector(subStepId);\n const subStepNameSelector = getSubStepNameSelector(subStepId);\n\n return (\n <FunnelSubStepContext.Provider\n value={{\n funnelInteractionId,\n stepNumber,\n stepNameSelector,\n subStepSelector,\n subStepNameSelector,\n subStepId,\n }}\n >\n {children}\n </FunnelSubStepContext.Provider>\n );\n};\n"]}
|
|
@@ -14,12 +14,14 @@ export interface FunnelContextValue extends BaseContextProps {
|
|
|
14
14
|
export interface FunnelStepContextValue extends BaseContextProps {
|
|
15
15
|
stepNameSelector: string;
|
|
16
16
|
stepNumber: number;
|
|
17
|
+
funnelStepProps?: Record<string, string | number | boolean | undefined>;
|
|
17
18
|
}
|
|
18
19
|
export interface FunnelSubStepContextValue extends FunnelStepContextValue {
|
|
19
20
|
subStepId: string;
|
|
20
21
|
subStepSelector: string;
|
|
21
22
|
subStepNameSelector: string;
|
|
22
23
|
stepNumber: number;
|
|
24
|
+
funnelSubStepProps?: Record<string, string | number | boolean | undefined>;
|
|
23
25
|
}
|
|
24
26
|
export declare const FunnelContext: import("react").Context<FunnelContextValue>;
|
|
25
27
|
export declare const FunnelStepContext: import("react").Context<FunnelStepContextValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-context.d.ts","sourceRoot":"lib/default/","sources":["internal/analytics/context/analytics-context.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,UAAU,EAAE,UAAU,CAAC;IACvB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,sBAAsB,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"analytics-context.d.ts","sourceRoot":"lib/default/","sources":["internal/analytics/context/analytics-context.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,UAAU,EAAE,UAAU,CAAC;IACvB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,sBAAsB,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5E;AAED,eAAO,MAAM,aAAa,6CAQxB,CAAC;AAEH,eAAO,MAAM,iBAAiB,iDAK5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,oDAQ/B,CAAC"}
|
|
@@ -14,6 +14,7 @@ export const FunnelStepContext = createContext({
|
|
|
14
14
|
funnelInteractionId: undefined,
|
|
15
15
|
stepNameSelector: '',
|
|
16
16
|
stepNumber: 0,
|
|
17
|
+
funnelStepProps: {},
|
|
17
18
|
});
|
|
18
19
|
export const FunnelSubStepContext = createContext({
|
|
19
20
|
funnelInteractionId: undefined,
|
|
@@ -22,5 +23,6 @@ export const FunnelSubStepContext = createContext({
|
|
|
22
23
|
stepNameSelector: '',
|
|
23
24
|
subStepSelector: '',
|
|
24
25
|
subStepNameSelector: '',
|
|
26
|
+
funnelStepProps: {},
|
|
25
27
|
});
|
|
26
28
|
//# sourceMappingURL=analytics-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-context.js","sourceRoot":"lib/default/","sources":["internal/analytics/context/analytics-context.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"analytics-context.js","sourceRoot":"lib/default/","sources":["internal/analytics/context/analytics-context.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AA8BtC,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAqB;IAC7D,mBAAmB,EAAE,SAAS;IAC9B,sBAAsB,EAAE,GAAG,EAAE,GAAE,CAAC;IAChC,UAAU,EAAE,aAAa;IACzB,mBAAmB,EAAE,EAAE;IACvB,gBAAgB,EAAE,CAAC;IACnB,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAyB;IACrE,mBAAmB,EAAE,SAAS;IAC9B,gBAAgB,EAAE,EAAE;IACpB,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B;IAC3E,mBAAmB,EAAE,SAAS;IAC9B,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,CAAC;IACb,gBAAgB,EAAE,EAAE;IACpB,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,EAAE;IACvB,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createContext } from 'react';\nimport { FunnelType } from '../interfaces';\n\nexport interface BaseContextProps {\n funnelInteractionId: string | undefined;\n}\n\nexport interface FunnelContextValue extends BaseContextProps {\n funnelType: FunnelType;\n optionalStepNumbers: number[];\n totalFunnelSteps: number;\n funnelSubmit: () => void;\n funnelCancel: () => void;\n setFunnelInteractionId: (funnelInteractionId: string) => void;\n}\n\nexport interface FunnelStepContextValue extends BaseContextProps {\n stepNameSelector: string;\n stepNumber: number;\n funnelStepProps?: Record<string, string | number | boolean | undefined>;\n}\n\nexport interface FunnelSubStepContextValue extends FunnelStepContextValue {\n subStepId: string;\n subStepSelector: string;\n subStepNameSelector: string;\n stepNumber: number;\n funnelSubStepProps?: Record<string, string | number | boolean | undefined>;\n}\n\nexport const FunnelContext = createContext<FunnelContextValue>({\n funnelInteractionId: undefined,\n setFunnelInteractionId: () => {},\n funnelType: 'single-page',\n optionalStepNumbers: [],\n totalFunnelSteps: 0,\n funnelSubmit: () => {},\n funnelCancel: () => {},\n});\n\nexport const FunnelStepContext = createContext<FunnelStepContextValue>({\n funnelInteractionId: undefined,\n stepNameSelector: '',\n stepNumber: 0,\n funnelStepProps: {},\n});\n\nexport const FunnelSubStepContext = createContext<FunnelSubStepContextValue>({\n funnelInteractionId: undefined,\n subStepId: '',\n stepNumber: 0,\n stepNameSelector: '',\n subStepSelector: '',\n subStepNameSelector: '',\n funnelStepProps: {},\n});\n"]}
|
|
@@ -14,9 +14,10 @@ export declare const useFunnelSubStep: () => {
|
|
|
14
14
|
subStepSelector: string;
|
|
15
15
|
subStepNameSelector: string;
|
|
16
16
|
stepNumber: number;
|
|
17
|
+
funnelSubStepProps: Record<string, any>;
|
|
17
18
|
stepNameSelector: string;
|
|
19
|
+
funnelStepProps?: Record<string, string | number | boolean | undefined> | undefined;
|
|
18
20
|
funnelInteractionId: string | undefined;
|
|
19
|
-
funnelSubStepProps: Record<string, any>;
|
|
20
21
|
subStepRef: import("react").MutableRefObject<HTMLDivElement | null>;
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
@@ -27,12 +28,7 @@ export declare const useFunnelSubStep: () => {
|
|
|
27
28
|
* The 'data-analytics-funnel-step' property of funnelStepProps is used to track the index of the current step in the funnel.
|
|
28
29
|
* The context contains additional properties of the FunnelStep.
|
|
29
30
|
*/
|
|
30
|
-
export declare const useFunnelStep: () =>
|
|
31
|
-
stepNameSelector: string;
|
|
32
|
-
stepNumber: number;
|
|
33
|
-
funnelInteractionId: string | undefined;
|
|
34
|
-
funnelStepProps: Record<string, string | number | boolean | undefined>;
|
|
35
|
-
};
|
|
31
|
+
export declare const useFunnelStep: () => import("../context/analytics-context").FunnelStepContextValue;
|
|
36
32
|
/**
|
|
37
33
|
* Custom React Hook to manage and interact with Funnel.
|
|
38
34
|
* This hook will provide necessary properties required to track
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-funnel.d.ts","sourceRoot":"lib/default/","sources":["internal/analytics/hooks/use-funnel.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"use-funnel.d.ts","sourceRoot":"lib/default/","sources":["internal/analytics/hooks/use-funnel.ts"],"names":[],"mappings":";AAQA;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;CA6C5B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,qEAGzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;;;;;;;;CASrB,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { useContext, useRef } from 'react';
|
|
4
4
|
import { FunnelContext, FunnelStepContext, FunnelSubStepContext } from '../context/analytics-context';
|
|
5
|
-
import { DATA_ATTR_FUNNEL_INTERACTION_ID,
|
|
5
|
+
import { DATA_ATTR_FUNNEL_INTERACTION_ID, DATA_ATTR_FUNNEL_SUBSTEP, getSubStepAllSelector } from '../selectors';
|
|
6
6
|
import { FunnelMetrics } from '../';
|
|
7
7
|
/**
|
|
8
8
|
* Custom React Hook to manage and interact with FunnelSubStep.
|
|
@@ -63,12 +63,7 @@ export const useFunnelSubStep = () => {
|
|
|
63
63
|
*/
|
|
64
64
|
export const useFunnelStep = () => {
|
|
65
65
|
const context = useContext(FunnelStepContext);
|
|
66
|
-
|
|
67
|
-
? {
|
|
68
|
-
[DATA_ATTR_FUNNEL_STEP]: context.stepNumber,
|
|
69
|
-
}
|
|
70
|
-
: {};
|
|
71
|
-
return Object.assign({ funnelStepProps }, context);
|
|
66
|
+
return context;
|
|
72
67
|
};
|
|
73
68
|
/**
|
|
74
69
|
* Custom React Hook to manage and interact with Funnel.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-funnel.js","sourceRoot":"lib/default/","sources":["internal/analytics/hooks/use-funnel.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAC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C;SACJ;IACH,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,KAAuC,EAAE,EAAE;QACzD,IAAI,mBAAmB,IAAI,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;YAClG,aAAa,CAAC,qBAAqB,CAAC;gBAClC,mBAAmB;gBACnB,eAAe;gBACf,mBAAmB;gBACnB,UAAU;gBACV,gBAAgB;gBAChB,kBAAkB,EAAE,qBAAqB,EAAE;aAC5C,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;IAEF,MAAM,kBAAkB,GAAwB,mBAAmB;QACjE,CAAC,CAAC;YACE,CAAC,wBAAwB,CAAC,EAAE,SAAS;YACrC,OAAO;YACP,MAAM;SACP;QACH,CAAC,CAAC,EAAE,CAAC;IAEP,uBAAS,kBAAkB,EAAE,UAAU,IAAK,OAAO,EAAG;AACxD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,WAAW,GAA0D,OAAO,CAAC,mBAAmB;QACpG,CAAC,CAAC;YACE,CAAC,+BAA+B,CAAC,EAAE,OAAO,CAAC,mBAAmB;SAC/D;QACH,CAAC,CAAC,EAAE,CAAC;IAEP,uBAAS,WAAW,IAAK,OAAO,EAAG;AACrC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext, useRef } from 'react';\nimport { FunnelContext, FunnelStepContext, FunnelSubStepContext } from '../context/analytics-context';\nimport { DATA_ATTR_FUNNEL_INTERACTION_ID, DATA_ATTR_FUNNEL_SUBSTEP, getSubStepAllSelector } from '../selectors';\nimport { FunnelMetrics } from '../';\n\n/**\n * Custom React Hook to manage and interact with FunnelSubStep.\n * This hook will provide necessary properties and methods required\n * to track and manage interactions with a FunnelSubStep component.\n *\n * The `onFocus` method is used to track the beginning of interaction with the FunnelSubStep.\n * The `onBlur` method is used to track the completion of interaction with the FunnelSubStep.\n * The subStepId is a unique identifier for the funnel sub-step.\n * The subStepRef is a reference to the DOM element of the funnel sub-step.\n */\nexport const useFunnelSubStep = () => {\n const subStepRef = useRef<HTMLDivElement | null>(null);\n const context = useContext(FunnelSubStepContext);\n const { funnelInteractionId, subStepId, subStepSelector, subStepNameSelector, stepNumber, stepNameSelector } =\n context;\n\n const onFocus = (event: React.FocusEvent<HTMLDivElement>) => {\n if (\n funnelInteractionId &&\n subStepRef.current &&\n (!event.relatedTarget || !subStepRef.current.contains(event.relatedTarget as Node))\n ) {\n FunnelMetrics.funnelSubStepStart({\n funnelInteractionId,\n subStepSelector,\n subStepNameSelector,\n stepNumber,\n stepNameSelector,\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n };\n\n const onBlur = (event: React.FocusEvent<HTMLDivElement>) => {\n if (funnelInteractionId && subStepRef.current && !subStepRef.current.contains(event.relatedTarget)) {\n FunnelMetrics.funnelSubStepComplete({\n funnelInteractionId,\n subStepSelector,\n subStepNameSelector,\n stepNumber,\n stepNameSelector,\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n };\n\n const funnelSubStepProps: Record<string, any> = funnelInteractionId\n ? {\n [DATA_ATTR_FUNNEL_SUBSTEP]: subStepId,\n onFocus,\n onBlur,\n }\n : {};\n\n return { funnelSubStepProps, subStepRef, ...context };\n};\n\n/**\n * Custom React Hook to manage and interact with FunnelStep.\n * This hook will provide necessary properties required to track\n * and manage interactions with a FunnelStep component.\n *\n * The 'data-analytics-funnel-step' property of funnelStepProps is used to track the index of the current step in the funnel.\n * The context contains additional properties of the FunnelStep.\n */\nexport const useFunnelStep = () => {\n const context = useContext(FunnelStepContext);\n return context;\n};\n\n/**\n * Custom React Hook to manage and interact with Funnel.\n * This hook will provide necessary properties required to track\n * and manage interactions with a Funnel component.\n *\n * The 'data-analytics-funnel-interaction-id' property of funnelProps is used to track the unique identifier of the current interaction with the funnel.\n */\nexport const useFunnel = () => {\n const context = useContext(FunnelContext);\n const funnelProps: Record<string, string | number | boolean | undefined> = context.funnelInteractionId\n ? {\n [DATA_ATTR_FUNNEL_INTERACTION_ID]: context.funnelInteractionId,\n }\n : {};\n\n return { funnelProps, ...context };\n};\n"]}
|