@parafin/react 6.1.1 → 6.2.1-alpha.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/out/index.js +37 -6
- package/package.json +1 -1
package/out/index.js
CHANGED
|
@@ -85,12 +85,12 @@ const initializeWidget = (iframe, props) => {
|
|
|
85
85
|
externalBusinessId: props.externalBusinessId ?? '',
|
|
86
86
|
...Object.fromEntries(url.searchParams),
|
|
87
87
|
};
|
|
88
|
+
const iframeSrc = `${url.origin}?${new URLSearchParams(query).toString()}`;
|
|
88
89
|
iframe.id = `parafin-${props.product}-widget`;
|
|
89
|
-
iframe.src =
|
|
90
|
-
const
|
|
91
|
-
iframe.
|
|
90
|
+
iframe.src = iframeSrc;
|
|
91
|
+
const sendMessageToWidget = (message, data) => {
|
|
92
|
+
iframe.contentWindow?.postMessage({ message, data }, url.origin);
|
|
92
93
|
};
|
|
93
|
-
// Message handler
|
|
94
94
|
const messageListener = async ({ data, origin }) => {
|
|
95
95
|
if (origin === url.origin && data?.product === props.product) {
|
|
96
96
|
switch (data?.message) {
|
|
@@ -107,7 +107,7 @@ const initializeWidget = (iframe, props) => {
|
|
|
107
107
|
...props,
|
|
108
108
|
route: data?.route,
|
|
109
109
|
onExit: () => {
|
|
110
|
-
|
|
110
|
+
iframe.src = iframeSrc;
|
|
111
111
|
props.onExit?.();
|
|
112
112
|
},
|
|
113
113
|
});
|
|
@@ -115,7 +115,38 @@ const initializeWidget = (iframe, props) => {
|
|
|
115
115
|
case 'opt-in':
|
|
116
116
|
if (props.onOptIn) {
|
|
117
117
|
const optInFields = await props.onOptIn();
|
|
118
|
-
|
|
118
|
+
sendMessageToWidget('opt-in', optInFields);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
sendMessageToWidget('opt-in', undefined);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'person-opt-in':
|
|
125
|
+
if (props.onEvent) {
|
|
126
|
+
try {
|
|
127
|
+
await props.onEvent('opted_in');
|
|
128
|
+
sendMessageToWidget('person-opt-in', { state: 'success' });
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
sendMessageToWidget('person-opt-in', { state: 'error' });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
sendMessageToWidget('person-opt-in', { state: 'noop' });
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case 'person-opt-out':
|
|
139
|
+
if (props.onEvent) {
|
|
140
|
+
try {
|
|
141
|
+
await props.onEvent?.('opted_out');
|
|
142
|
+
sendMessageToWidget('person-opt-out', { state: 'success' });
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
sendMessageToWidget('person-opt-out', { state: 'error' });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
sendMessageToWidget('person-opt-out', { state: 'noop' });
|
|
119
150
|
}
|
|
120
151
|
break;
|
|
121
152
|
case 'set-height':
|