@aws-amplify/ui-react-notifications 0.0.0-studio-e5b8195-20230912200241 → 0.0.0-test-delay-3b0be8c-20250107175849

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.
Files changed (51) hide show
  1. package/dist/esm/components/InAppMessaging/Backdrop/Backdrop.mjs +9 -0
  2. package/dist/esm/components/InAppMessaging/Backdrop/withBackdrop.mjs +15 -0
  3. package/dist/esm/components/InAppMessaging/BannerMessage/BannerMessage.mjs +27 -0
  4. package/dist/esm/components/InAppMessaging/BannerMessage/constants.mjs +4 -0
  5. package/dist/esm/components/InAppMessaging/CloseIconButton/CloseIconButton.mjs +10 -0
  6. package/dist/esm/components/InAppMessaging/FullScreenMessage/FullScreenMessage.mjs +29 -0
  7. package/dist/esm/components/InAppMessaging/FullScreenMessage/constants.mjs +4 -0
  8. package/dist/esm/components/InAppMessaging/InAppMessageDisplay/InAppMessageDisplay.mjs +50 -0
  9. package/dist/esm/components/InAppMessaging/InAppMessageDisplay/handleMessageLinkAction.mjs +23 -0
  10. package/dist/esm/components/InAppMessaging/MessageLayout/MessageLayout.mjs +33 -0
  11. package/dist/esm/components/InAppMessaging/MessageLayout/constants.mjs +21 -0
  12. package/dist/esm/components/InAppMessaging/MessageLayout/utils.mjs +22 -0
  13. package/dist/esm/components/InAppMessaging/ModalMessage/ModalMessage.mjs +23 -0
  14. package/dist/esm/components/InAppMessaging/ModalMessage/constants.mjs +6 -0
  15. package/dist/esm/components/InAppMessaging/hooks/useMessageImage/types.mjs +9 -0
  16. package/dist/esm/components/InAppMessaging/hooks/useMessageImage/useMessageImage.mjs +40 -0
  17. package/dist/esm/components/InAppMessaging/hooks/useMessageProps/useMessageProps.mjs +33 -0
  18. package/dist/esm/components/InAppMessaging/hooks/useMessageProps/utils.mjs +62 -0
  19. package/dist/esm/components/InAppMessaging/withInAppMessaging/withInAppMessaging.mjs +13 -0
  20. package/dist/esm/index.mjs +3 -0
  21. package/dist/esm/version.mjs +3 -0
  22. package/dist/index.js +393 -1
  23. package/dist/styles.css +1175 -725
  24. package/dist/types/components/InAppMessaging/MessageLayout/constants.d.ts +6 -6
  25. package/dist/types/components/InAppMessaging/MessageLayout/utils.d.ts +1 -1
  26. package/dist/types/components/InAppMessaging/ModalMessage/constants.d.ts +1 -1
  27. package/dist/types/components/InAppMessaging/hooks/useMessageImage/useMessageImage.d.ts +2 -2
  28. package/dist/types/components/InAppMessaging/index.d.ts +1 -1
  29. package/dist/types/version.d.ts +1 -0
  30. package/package.json +14 -37
  31. package/dist/esm/components/InAppMessaging/Backdrop/Backdrop.js +0 -1
  32. package/dist/esm/components/InAppMessaging/Backdrop/withBackdrop.js +0 -1
  33. package/dist/esm/components/InAppMessaging/BannerMessage/BannerMessage.js +0 -1
  34. package/dist/esm/components/InAppMessaging/BannerMessage/constants.js +0 -1
  35. package/dist/esm/components/InAppMessaging/CloseIconButton/CloseIconButton.js +0 -1
  36. package/dist/esm/components/InAppMessaging/FullScreenMessage/FullScreenMessage.js +0 -1
  37. package/dist/esm/components/InAppMessaging/FullScreenMessage/constants.js +0 -1
  38. package/dist/esm/components/InAppMessaging/InAppMessageDisplay/InAppMessageDisplay.js +0 -1
  39. package/dist/esm/components/InAppMessaging/InAppMessageDisplay/handleMessageLinkAction.js +0 -1
  40. package/dist/esm/components/InAppMessaging/MessageLayout/MessageLayout.js +0 -1
  41. package/dist/esm/components/InAppMessaging/MessageLayout/constants.js +0 -1
  42. package/dist/esm/components/InAppMessaging/MessageLayout/utils.js +0 -1
  43. package/dist/esm/components/InAppMessaging/ModalMessage/ModalMessage.js +0 -1
  44. package/dist/esm/components/InAppMessaging/ModalMessage/constants.js +0 -1
  45. package/dist/esm/components/InAppMessaging/hooks/useMessageImage/types.js +0 -1
  46. package/dist/esm/components/InAppMessaging/hooks/useMessageImage/useMessageImage.js +0 -1
  47. package/dist/esm/components/InAppMessaging/hooks/useMessageProps/useMessageProps.js +0 -1
  48. package/dist/esm/components/InAppMessaging/hooks/useMessageProps/utils.js +0 -1
  49. package/dist/esm/components/InAppMessaging/withInAppMessaging/withInAppMessaging.js +0 -1
  50. package/dist/esm/index.js +0 -1
  51. package/dist/esm/node_modules/tslib/tslib.es6.js +0 -1
package/dist/index.js CHANGED
@@ -1 +1,393 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@aws-amplify/ui-react-core-notifications"),t=require("react"),n=require("@aws-amplify/ui-react"),a=require("classnames"),s=require("@aws-amplify/core"),l=require("@aws-amplify/ui"),o=require("@aws-amplify/ui-react/internal"),r=require("tinycolor2");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var u,d=c(t),g=i(t),m=i(a),p=i(r);!function(e){e.Aborted="ABORTED",e.Failure="FAILURE",e.Fetching="FETCHING",e.Success="SUCCESS"}(u||(u={}));const y=new s.ConsoleLogger("Notifications.InAppMessaging");const f=({body:e,container:t,header:n,primaryButton:a,secondaryButton:s})=>{var l,o,r,i,c;return{body:null!==(l=null==e?void 0:e.style)&&void 0!==l?l:{},container:null!==(o=null==t?void 0:t.style)&&void 0!==o?o:{},header:null!==(r=null==n?void 0:n.style)&&void 0!==r?r:{},primaryButton:null!==(i=null==a?void 0:a.style)&&void 0!==i?i:{},secondaryButton:null!==(c=null==s?void 0:s.style)&&void 0!==c?c:{}}};function b(e){const{image:n,onDisplay:a}=e,s=t.useRef(!1),{hasRenderableImage:l,isImageFetching:o}=function(e){const{src:n}=null!=e?e:{},a=!!n,[s,l]=t.useState(a?u.Fetching:null),o=s===u.Fetching,r=s===u.Success;return t.useEffect((()=>{if(!a)return;const e=new Image;e.onload=()=>{l(u.Success)},e.onabort=()=>{y.error(`Image load aborted: ${n}`),l(u.Aborted)},e.onerror=()=>{y.error(`Image failed to load: ${n}`),l(u.Failure)},e.src=n}),[a,n]),{hasRenderableImage:r,isImageFetching:o}}(n),r=!o;t.useEffect((()=>{!s.current&&r&&(null==a||a(),s.current=!0)}),[a,r]);const i=t.useMemo((()=>function({styleParams:e}){var t,n;const{payloadStyle:a,overrideStyle:s}=e;return{body:Object.assign(Object.assign({},null==a?void 0:a.body),null==s?void 0:s.body),closeIconButton:null!==(t=null==s?void 0:s.closeIconButton)&&void 0!==t?t:{},container:Object.assign(Object.assign({},null==a?void 0:a.container),null==s?void 0:s.container),header:Object.assign(Object.assign({},null==a?void 0:a.header),null==s?void 0:s.header),image:null!==(n=null==s?void 0:s.image)&&void 0!==n?n:{},primaryButton:Object.assign(Object.assign({},null==a?void 0:a.primaryButton),null==s?void 0:s.primaryButton),secondaryButton:Object.assign(Object.assign({},null==a?void 0:a.secondaryButton),null==s?void 0:s.secondaryButton)}}({styleParams:{payloadStyle:f(e),overrideStyle:e.style}})),[e]);return{hasRenderableImage:l,shouldRenderMessage:r,styles:i}}function v(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(a=Object.getOwnPropertySymbols(e);s<a.length;s++)t.indexOf(a[s])<0&&Object.prototype.propertyIsEnumerable.call(e,a[s])&&(n[a[s]]=e[a[s]])}return n}function E(e){var{className:t,dismissButtonLabel:a="Dismiss message",onClick:s,style:l}=e,r=v(e,["className","dismissButtonLabel","onClick","style"]);return d.createElement(n.Button,Object.assign({ariaLabel:a,className:t,onClick:s,style:l,variation:"link"},r),d.createElement(o.IconClose,{"aria-hidden":"true",size:"1.5rem"}))}const h="amplify-inappmessaging-messagelayout",O=`${h}__button`,I=`${h}__close-button`,j=`${h}__content`,M=`${h}__header`,B=`${h}__image-container`,$=`${h}__text-container`,x="inappmessaging-messagelayout-bodytext",k="inappmessaging-messagelayout-buttongroup",C="inappmessaging-messagelayout-content",F="inappmessaging-messagelayout-headertext",w="inappmessaging-messagelayout-imagecontainer",N="inappmessaging-messagelayout",A="inappmessaging-messagelayout-primarybutton",_="inappmessaging-messagelayout-secondarybutton",S="inappmessaging-messagelayout-textcontainer",P=(e,t="light")=>{const{backgroundColor:n}=null!=e?e:{};if(!n)return t;return p.default(n).isDark()?"dark":"light"},R=e=>!l.isEmpty(e);function q({body:e,buttonSize:t,hasRenderableImage:a,header:s,image:l,onClose:o,orientation:r="vertical",primaryButton:i,secondaryButton:c,styles:u}){const g=d.useMemo((()=>({primary:P(u.primaryButton),secondary:P(u.secondaryButton)})),[u]),p="horizontal"===r,y=d.createElement(E,{className:I,onClick:o,style:u.closeIconButton}),f=R(i),b=R(c),v=f||b;return d.createElement(n.Flex,{className:h,"data-testid":N,style:u.container},!p&&d.createElement(n.Flex,{justifyContent:"flex-end"},y),d.createElement(n.Flex,{className:m.default(j,`${j}--${r}`),"data-testid":C},a&&d.createElement(n.Flex,{className:m.default(B,`${B}--${r}`),"data-testid":w},d.createElement(n.Image,{alt:"In-App Message Image",src:null==l?void 0:l.src,style:u.image})),d.createElement(n.Flex,{className:m.default($,`${$}--${r}`),"data-testid":S},(null==s?void 0:s.content)&&d.createElement(n.Heading,{className:M,isTruncated:!0,level:2,style:u.header,testId:F},s.content),(null==e?void 0:e.content)&&d.createElement(n.Text,{style:u.body,testId:x},e.content)),p&&d.createElement(n.Flex,{alignItems:"flex-start"},y)),v&&d.createElement(n.ButtonGroup,{size:t,testId:k},b&&d.createElement(n.Button,{className:m.default(O,`${O}--${g.secondary}`),onClick:c.onAction,style:u.secondaryButton,testId:_},c.title),f&&d.createElement(n.Button,{className:m.default(O,`${O}--${g.primary}`),onClick:i.onAction,style:u.primaryButton,testId:A},i.title)))}const L="amplify-inappmessaging-bannermessage";function z(e){const t=b(e),a=n.useBreakpointValue([!0,!0,!1]),{shouldRenderMessage:s,styles:l}=t;if(!s)return null;const{alignment:o="right",position:r="top"}=e,i="center"===o&&"middle"===r;return g.default.createElement(n.Flex,{className:m.default(L,{[`${L}--${r}`]:!i,[`${L}--${o}`]:!i,[`${L}--center-middle`]:i,[`${L}--full-width`]:a}),role:"dialog",testId:`inappmessaging-${r}banner-dialog`},g.default.createElement(q,Object.assign({},e,t,{orientation:"horizontal",buttonSize:"small",styles:l})))}const D="inappmessaging-backdrop";function T(e){var{onClick:t}=e,a=v(e,["onClick"]);return g.default.createElement(n.View,Object.assign({className:"amplify-inappmessaging-backdrop","data-testid":D,onClick:t},a))}const U="amplify-inappmessaging-fullscreenmessage";function V(e){const t=b(e),a=n.useBreakpointValue([!0,!0,!1]),{shouldRenderMessage:s,styles:l}=t,{onClose:o}=e;if(!s)return null;const r=()=>d.createElement(n.Flex,{className:m.default(U,{[`${U}--fullscreen`]:a}),role:"dialog",testId:"inappmessaging-fullscreen-dialog"},d.createElement(q,Object.assign({},e,t,{styles:l})));if(a)return d.createElement(r,null);const i=function(e,t={}){return function(a){return g.default.createElement(g.default.Fragment,null,g.default.createElement(T,Object.assign({},t)),g.default.createElement(n.Flex,{className:"amplify-inappmessaging-backdrop-content-container"},g.default.createElement(n.View,{className:"amplify-inappmessaging-backdrop-content"},g.default.createElement(e,Object.assign({},a)))))}}(r,{onClick:o});return d.createElement(i,null)}const G="amplify-inappmessaging-modalmessage",H=`${G}__dialog`;function J(e){const t=b(e),a=n.useBreakpointValue([!0,!0,!1]),{shouldRenderMessage:s,styles:l}=t;return s?d.createElement(n.Flex,{className:G},d.createElement(n.Flex,{className:m.default(H,{[`${H}--full-width`]:a}),role:"dialog",testId:"inappmessaging-modal-dialog"},d.createElement(q,Object.assign({},e,t,{styles:l})))):null}const K=new s.ConsoleLogger("Notifications.InAppMessaging"),Q=e=>{let t;try{t=new URL(e)}catch(t){return void K.warn(`Unsupported url provided: ${e}`)}const{protocol:n}=t;"http:"===n||"https:"===n?window.open(e):K.warn(`Unsupported url protocol provided: ${n}`)};function W(e){return null}const X={BannerMessage:z,CarouselMessage:W,FullScreenMessage:V,ModalMessage:J},Y=({action:t,url:n})=>{e.handleMessageAction({action:t,url:n,handleMessageLinkAction:Q})};function Z({components:t}){const a=g.default.useMemo((()=>Object.assign(Object.assign({},X),t)),[t]),{Component:s,props:l}=e.useMessage({components:a,onMessageAction:Y});return g.default.createElement(n.ThemeProvider,{colorMode:"light"},g.default.createElement(s,Object.assign({},l)))}Z.BannerMessage=z,Z.CarouselMessage=W,Z.FullScreenMessage=V,Z.ModalMessage=J,Object.defineProperty(exports,"InAppMessagingProvider",{enumerable:!0,get:function(){return e.InAppMessagingProvider}}),Object.defineProperty(exports,"useInAppMessaging",{enumerable:!0,get:function(){return e.useInAppMessaging}}),exports.InAppMessageDisplay=Z,exports.withInAppMessaging=function(t,n){return function(a){return g.default.createElement(e.InAppMessagingProvider,null,g.default.createElement(Z,Object.assign({},n)),g.default.createElement(t,Object.assign({},a)))}};
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var uiReactCoreNotifications = require('@aws-amplify/ui-react-core-notifications');
6
+ var React = require('react');
7
+ var uiReact = require('@aws-amplify/ui-react');
8
+ var uiReactCore = require('@aws-amplify/ui-react-core');
9
+ var ui = require('@aws-amplify/ui');
10
+ var utils = require('aws-amplify/utils');
11
+ var internal = require('@aws-amplify/ui-react/internal');
12
+ var tinycolor = require('tinycolor2');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n["default"] = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
35
+ var tinycolor__default = /*#__PURE__*/_interopDefault(tinycolor);
36
+
37
+ var ImagePrefetchStatus;
38
+ (function (ImagePrefetchStatus) {
39
+ ImagePrefetchStatus["Aborted"] = "ABORTED";
40
+ ImagePrefetchStatus["Failure"] = "FAILURE";
41
+ ImagePrefetchStatus["Fetching"] = "FETCHING";
42
+ ImagePrefetchStatus["Success"] = "SUCCESS";
43
+ })(ImagePrefetchStatus || (ImagePrefetchStatus = {}));
44
+
45
+ const logger$1 = new utils.ConsoleLogger('InAppMessaging');
46
+ /**
47
+ * Handles prefetching for message images
48
+ *
49
+ * @param image contains image source
50
+ * @returns message image dimensions and fetching related booleans
51
+ */
52
+ function useMessageImage(image) {
53
+ const { src } = image ?? {};
54
+ const shouldPrefetch = !!src;
55
+ // set initial status to fetching if prefetch is required
56
+ const [prefetchStatus, setPrefetchStatus] = React.useState(shouldPrefetch ? ImagePrefetchStatus.Fetching : null);
57
+ const isImageFetching = prefetchStatus === ImagePrefetchStatus.Fetching;
58
+ const hasRenderableImage = prefetchStatus === ImagePrefetchStatus.Success;
59
+ React.useEffect(() => {
60
+ if (!shouldPrefetch) {
61
+ return;
62
+ }
63
+ const img = new Image();
64
+ img.onload = () => {
65
+ setPrefetchStatus(ImagePrefetchStatus.Success);
66
+ };
67
+ img.onabort = () => {
68
+ logger$1.error(`Image load aborted: ${src}`);
69
+ setPrefetchStatus(ImagePrefetchStatus.Aborted);
70
+ };
71
+ img.onerror = () => {
72
+ logger$1.error(`Image failed to load: ${src}`);
73
+ setPrefetchStatus(ImagePrefetchStatus.Failure);
74
+ };
75
+ img.src = src;
76
+ }, [shouldPrefetch, src]);
77
+ return { hasRenderableImage, isImageFetching };
78
+ }
79
+
80
+ /**
81
+ * Utility for extracting message payload style
82
+ *
83
+ * @param props message props
84
+ *
85
+ * @returns message payload-specific styles
86
+ */
87
+ const getPayloadStyle = ({ body, container, header, primaryButton, secondaryButton, }) => ({
88
+ body: body?.style ?? {},
89
+ container: container?.style ?? {},
90
+ header: header?.style ?? {},
91
+ primaryButton: primaryButton?.style ?? {},
92
+ secondaryButton: secondaryButton?.style ?? {},
93
+ });
94
+ /**
95
+ * Receives message styling and returns style property values for use with in-app message
96
+ * UI components. Handles resolving style precedence between payload and custom styles
97
+ *
98
+ * Styles resolve precedence from lowest to highest:
99
+ * 1. Payload styles
100
+ * 2. Custom (override) styles
101
+ *
102
+ * @param params message style params
103
+ *
104
+ * @returns message component styles
105
+ */
106
+ function getMessageStyles({ styleParams, }) {
107
+ const { payloadStyle, overrideStyle } = styleParams;
108
+ return {
109
+ // message body style
110
+ body: {
111
+ ...payloadStyle?.body,
112
+ ...overrideStyle?.body,
113
+ },
114
+ // close button style - not defined in payload, override only
115
+ closeIconButton: overrideStyle?.closeIconButton ?? {},
116
+ // message container style
117
+ container: {
118
+ ...payloadStyle?.container,
119
+ ...overrideStyle?.container,
120
+ },
121
+ // message header style
122
+ header: {
123
+ ...payloadStyle?.header,
124
+ ...overrideStyle?.header,
125
+ },
126
+ // image style - not defined in payload, override only
127
+ image: overrideStyle?.image ?? {},
128
+ // message primary button style
129
+ primaryButton: {
130
+ ...payloadStyle?.primaryButton,
131
+ ...overrideStyle?.primaryButton,
132
+ },
133
+ // message secondary button style
134
+ secondaryButton: {
135
+ ...payloadStyle?.secondaryButton,
136
+ ...overrideStyle?.secondaryButton,
137
+ },
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Handle common message UI component prop logic including render booleans, and
143
+ * style resolving
144
+ *
145
+ * @param props message UI component props
146
+ *
147
+ * @returns message UI component render related booleans and styles
148
+ */
149
+ function useMessageProps(props) {
150
+ const { image, onDisplay } = props;
151
+ const hasDisplayed = React.useRef(false);
152
+ const { hasRenderableImage, isImageFetching } = useMessageImage(image);
153
+ const shouldRenderMessage = !isImageFetching;
154
+ React.useEffect(() => {
155
+ if (!hasDisplayed.current && shouldRenderMessage) {
156
+ onDisplay?.();
157
+ hasDisplayed.current = true;
158
+ }
159
+ }, [onDisplay, shouldRenderMessage]);
160
+ const styles = React.useMemo(() => getMessageStyles({
161
+ styleParams: {
162
+ payloadStyle: getPayloadStyle(props),
163
+ overrideStyle: props.style,
164
+ },
165
+ }), [props]);
166
+ return { hasRenderableImage, shouldRenderMessage, styles };
167
+ }
168
+
169
+ function CloseIconButton({ className, dismissButtonLabel = 'Dismiss message', onClick, style, ...rest }) {
170
+ return (React__namespace.createElement(uiReact.Button, { ariaLabel: dismissButtonLabel, className: className, onClick: onClick, style: style, variation: "link", ...rest },
171
+ React__namespace.createElement(internal.IconClose, { "aria-hidden": "true", size: "1.5rem" })));
172
+ }
173
+
174
+ // Base block class for MessageLayout
175
+ const BLOCK_CLASS$3 = 'amplify-inappmessaging-messagelayout';
176
+ // Element classes for MessageLayout
177
+ const BUTTON_CLASS = `${BLOCK_CLASS$3}__button`;
178
+ const CLOSE_BUTTON_CLASS = `${BLOCK_CLASS$3}__close-button`;
179
+ const CONTENT_CLASS = `${BLOCK_CLASS$3}__content`;
180
+ const HEADER_CLASS = `${BLOCK_CLASS$3}__header`;
181
+ const IMAGE_CONTAINER_CLASS = `${BLOCK_CLASS$3}__image-container`;
182
+ const TEXT_CONTAINER_CLASS = `${BLOCK_CLASS$3}__text-container`;
183
+ // Test IDs
184
+ const BODY_TEXT_TEST_ID = 'inappmessaging-messagelayout-bodytext';
185
+ const BUTTON_GROUP_TEST_ID = 'inappmessaging-messagelayout-buttongroup';
186
+ const CONTENT_TEST_ID = 'inappmessaging-messagelayout-content';
187
+ const HEADER_TEXT_TEST_ID = 'inappmessaging-messagelayout-headertext';
188
+ const IMAGE_CONTAINER_TEST_ID = 'inappmessaging-messagelayout-imagecontainer';
189
+ const MESSAGE_LAYOUT_TEST_ID = 'inappmessaging-messagelayout';
190
+ const PRIMARY_BUTTON_TEST_ID = 'inappmessaging-messagelayout-primarybutton';
191
+ const SECONDARY_BUTTON_TEST_ID = 'inappmessaging-messagelayout-secondarybutton';
192
+ const TEXT_CONTAINER_TEST_ID = 'inappmessaging-messagelayout-textcontainer';
193
+
194
+ /**
195
+ * Utility for determining the class modifier for an In-App Messaging button
196
+ * based on its background color
197
+ *
198
+ * @param buttonStyles button styles which should contain the background color
199
+ * @param defaultModifier modifier that should be returned in cases where
200
+ * background color is undefined
201
+ *
202
+ * @returns the modifier - either 'light' or 'dark'
203
+ */
204
+ const getButtonModifier = (buttonStyles, defaultModifier = 'light') => {
205
+ const { backgroundColor } = buttonStyles ?? {};
206
+ if (!backgroundColor) {
207
+ return defaultModifier;
208
+ }
209
+ const color = tinycolor__default["default"](backgroundColor);
210
+ return color.isDark() ? 'dark' : 'light';
211
+ };
212
+
213
+ const isMessageButton = (button) => !ui.isEmpty(button);
214
+ function MessageLayout({ body, buttonSize, hasRenderableImage, header, image, onClose, orientation = 'vertical', primaryButton, secondaryButton, styles, }) {
215
+ const buttonModifiers = React__namespace.useMemo(() => ({
216
+ primary: getButtonModifier(styles.primaryButton),
217
+ secondary: getButtonModifier(styles.secondaryButton),
218
+ }), [styles]);
219
+ const isHorizontal = orientation === 'horizontal';
220
+ const closeButton = (React__namespace.createElement(CloseIconButton, { className: CLOSE_BUTTON_CLASS, onClick: onClose, style: styles.closeIconButton }));
221
+ const hasPrimaryButton = isMessageButton(primaryButton);
222
+ const hasSecondaryButton = isMessageButton(secondaryButton);
223
+ const hasButtons = hasPrimaryButton || hasSecondaryButton;
224
+ return (React__namespace.createElement(uiReact.Flex, { className: BLOCK_CLASS$3, "data-testid": MESSAGE_LAYOUT_TEST_ID, style: styles.container },
225
+ !isHorizontal && React__namespace.createElement(uiReact.Flex, { justifyContent: "flex-end" }, closeButton),
226
+ React__namespace.createElement(uiReact.Flex, { className: ui.classNames(CONTENT_CLASS, `${CONTENT_CLASS}--${orientation}`), "data-testid": CONTENT_TEST_ID },
227
+ hasRenderableImage && (React__namespace.createElement(uiReact.Flex, { className: ui.classNames(IMAGE_CONTAINER_CLASS, `${IMAGE_CONTAINER_CLASS}--${orientation}`), "data-testid": IMAGE_CONTAINER_TEST_ID },
228
+ React__namespace.createElement(uiReact.Image, { alt: "In-App Message Image", src: image?.src, style: styles.image }))),
229
+ React__namespace.createElement(uiReact.Flex, { className: ui.classNames(TEXT_CONTAINER_CLASS, `${TEXT_CONTAINER_CLASS}--${orientation}`), "data-testid": TEXT_CONTAINER_TEST_ID },
230
+ header?.content && (React__namespace.createElement(uiReact.Heading, { className: HEADER_CLASS, isTruncated: true, level: 2, style: styles.header, testId: HEADER_TEXT_TEST_ID }, header.content)),
231
+ body?.content && (React__namespace.createElement(uiReact.Text, { style: styles.body, testId: BODY_TEXT_TEST_ID }, body.content))),
232
+ isHorizontal && React__namespace.createElement(uiReact.Flex, { alignItems: "flex-start" }, closeButton)),
233
+ hasButtons && (React__namespace.createElement(uiReact.ButtonGroup, { size: buttonSize, testId: BUTTON_GROUP_TEST_ID },
234
+ hasSecondaryButton && (React__namespace.createElement(uiReact.Button, { className: ui.classNames(BUTTON_CLASS, `${BUTTON_CLASS}--${buttonModifiers.secondary}`), onClick: secondaryButton.onAction, style: styles.secondaryButton, testId: SECONDARY_BUTTON_TEST_ID }, secondaryButton.title)),
235
+ hasPrimaryButton && (React__namespace.createElement(uiReact.Button, { className: ui.classNames(BUTTON_CLASS, `${BUTTON_CLASS}--${buttonModifiers.primary}`), onClick: primaryButton.onAction, style: styles.primaryButton, testId: PRIMARY_BUTTON_TEST_ID }, primaryButton.title))))));
236
+ }
237
+
238
+ // Base block class for BannerMessage
239
+ const BLOCK_CLASS$2 = 'amplify-inappmessaging-bannermessage';
240
+
241
+ function BannerMessage(props) {
242
+ const messageProps = useMessageProps(props);
243
+ const shouldBeFullWidth = uiReact.useBreakpointValue([true, true, false]);
244
+ const { shouldRenderMessage, styles } = messageProps;
245
+ if (!shouldRenderMessage) {
246
+ return null;
247
+ }
248
+ const { alignment = 'right', position = 'top' } = props;
249
+ const isCenterMiddle = alignment === 'center' && position === 'middle';
250
+ return (React__namespace["default"].createElement(uiReact.Flex, { className: ui.classNames(BLOCK_CLASS$2, {
251
+ [`${BLOCK_CLASS$2}--${position}`]: !isCenterMiddle,
252
+ [`${BLOCK_CLASS$2}--${alignment}`]: !isCenterMiddle,
253
+ [`${BLOCK_CLASS$2}--center-middle`]: isCenterMiddle,
254
+ [`${BLOCK_CLASS$2}--full-width`]: shouldBeFullWidth,
255
+ }), role: "dialog", testId: `inappmessaging-${position}banner-dialog` },
256
+ React__namespace["default"].createElement(MessageLayout, { ...props, ...messageProps, orientation: "horizontal", buttonSize: "small", styles: styles })));
257
+ }
258
+
259
+ const BACKDROP_TEST_ID = 'inappmessaging-backdrop';
260
+ function Backdrop({ onClick, ...rest }) {
261
+ return (React__namespace["default"].createElement(uiReact.View, { className: "amplify-inappmessaging-backdrop", "data-testid": BACKDROP_TEST_ID, onClick: onClick, ...rest }));
262
+ }
263
+
264
+ function withBackdrop(Content, options = {}) {
265
+ return function ContentWithBackdrop(props) {
266
+ return (React__namespace["default"].createElement(React__namespace["default"].Fragment, null,
267
+ React__namespace["default"].createElement(Backdrop, { ...options }),
268
+ React__namespace["default"].createElement(uiReact.Flex, { className: "amplify-inappmessaging-backdrop-content-container" },
269
+ React__namespace["default"].createElement(uiReact.View, { className: "amplify-inappmessaging-backdrop-content" },
270
+ React__namespace["default"].createElement(Content, { ...props })))));
271
+ };
272
+ }
273
+
274
+ // Base block class for FullScreenMessage
275
+ const BLOCK_CLASS$1 = 'amplify-inappmessaging-fullscreenmessage';
276
+
277
+ function FullScreenMessage(props) {
278
+ const messageProps = useMessageProps(props);
279
+ const shouldBeFullScreen = uiReact.useBreakpointValue([true, true, false]);
280
+ const { shouldRenderMessage, styles } = messageProps;
281
+ const { onClose: onClick } = props;
282
+ if (!shouldRenderMessage) {
283
+ return null;
284
+ }
285
+ const Message = () => (React__namespace.createElement(uiReact.Flex, { className: ui.classNames(BLOCK_CLASS$1, {
286
+ [`${BLOCK_CLASS$1}--fullscreen`]: shouldBeFullScreen,
287
+ }), role: "dialog", testId: "inappmessaging-fullscreen-dialog" },
288
+ React__namespace.createElement(MessageLayout, { ...props, ...messageProps, styles: styles })));
289
+ if (shouldBeFullScreen) {
290
+ return React__namespace.createElement(Message, null);
291
+ }
292
+ const MessageWithBackdrop = withBackdrop(Message, { onClick });
293
+ return React__namespace.createElement(MessageWithBackdrop, null);
294
+ }
295
+
296
+ // Base block class for ModalMessage
297
+ const BLOCK_CLASS = 'amplify-inappmessaging-modalmessage';
298
+ // Element classes for ModalMessage
299
+ const DIALOG_CLASS = `${BLOCK_CLASS}__dialog`;
300
+
301
+ function ModalMessage(props) {
302
+ const messageProps = useMessageProps(props);
303
+ const shouldBeFullWidth = uiReact.useBreakpointValue([true, true, false]);
304
+ const { shouldRenderMessage, styles } = messageProps;
305
+ if (!shouldRenderMessage) {
306
+ return null;
307
+ }
308
+ return (React__namespace.createElement(uiReact.Flex, { className: BLOCK_CLASS },
309
+ React__namespace.createElement(uiReact.Flex, { className: ui.classNames(DIALOG_CLASS, {
310
+ [`${DIALOG_CLASS}--full-width`]: shouldBeFullWidth,
311
+ }), role: "dialog", testId: "inappmessaging-modal-dialog" },
312
+ React__namespace.createElement(MessageLayout, { ...props, ...messageProps, styles: styles }))));
313
+ }
314
+
315
+ const logger = new utils.ConsoleLogger('InAppMessaging');
316
+ const handleMessageLinkAction = (input) => {
317
+ let url;
318
+ try {
319
+ url = new URL(input);
320
+ }
321
+ catch {
322
+ logger.warn(`Unsupported url provided: ${input}`);
323
+ return;
324
+ }
325
+ const { protocol } = url;
326
+ const isHttpProtocol = protocol === 'http:';
327
+ const isHttpsProtocol = protocol === 'https:';
328
+ if (!(isHttpProtocol || isHttpsProtocol)) {
329
+ logger.warn(`Unsupported url protocol provided: ${protocol}`);
330
+ return;
331
+ }
332
+ window.open(input);
333
+ };
334
+
335
+ const VERSION = '2.1.1';
336
+
337
+ // TODO: replace below components incrementally as they become available
338
+ function CarouselMessage(_) {
339
+ return null;
340
+ }
341
+ const platformComponents = {
342
+ BannerMessage,
343
+ CarouselMessage,
344
+ FullScreenMessage,
345
+ ModalMessage,
346
+ };
347
+ const onMessageAction = ({ action, url }) => {
348
+ uiReactCoreNotifications.handleMessageAction({
349
+ action,
350
+ url,
351
+ handleMessageLinkAction,
352
+ });
353
+ };
354
+ function InAppMessageDisplay({ components: overrideComponents, }) {
355
+ const components = React__namespace["default"].useMemo(() => ({ ...platformComponents, ...overrideComponents }), [overrideComponents]);
356
+ const { Component, props } = uiReactCoreNotifications.useMessage({
357
+ components,
358
+ onMessageAction,
359
+ });
360
+ uiReactCore.useSetUserAgent({
361
+ componentName: 'InAppMessaging',
362
+ packageName: 'react-notifications',
363
+ version: VERSION,
364
+ });
365
+ // There is currently no way to pass In-App Message payload variants so we
366
+ // will fix the theme around In-App Messaging components to always assume
367
+ // light mode
368
+ return (React__namespace["default"].createElement(uiReact.ThemeProvider, { colorMode: "light" },
369
+ React__namespace["default"].createElement(Component, { ...props })));
370
+ }
371
+ InAppMessageDisplay.BannerMessage = BannerMessage;
372
+ InAppMessageDisplay.CarouselMessage = CarouselMessage;
373
+ InAppMessageDisplay.FullScreenMessage = FullScreenMessage;
374
+ InAppMessageDisplay.ModalMessage = ModalMessage;
375
+
376
+ function withInAppMessaging(Component, options) {
377
+ return function WrappedWithInAppMessaging(props) {
378
+ return (React__namespace["default"].createElement(uiReactCoreNotifications.InAppMessagingProvider, null,
379
+ React__namespace["default"].createElement(InAppMessageDisplay, { ...options }),
380
+ React__namespace["default"].createElement(Component, { ...props })));
381
+ };
382
+ }
383
+
384
+ Object.defineProperty(exports, "InAppMessagingProvider", {
385
+ enumerable: true,
386
+ get: function () { return uiReactCoreNotifications.InAppMessagingProvider; }
387
+ });
388
+ Object.defineProperty(exports, "useInAppMessaging", {
389
+ enumerable: true,
390
+ get: function () { return uiReactCoreNotifications.useInAppMessaging; }
391
+ });
392
+ exports.InAppMessageDisplay = InAppMessageDisplay;
393
+ exports.withInAppMessaging = withInAppMessaging;