@parafin/react 6.2.2 → 6.3.1
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.d.ts +1 -0
- package/out/index.js +42 -19
- package/package.json +1 -1
package/out/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type WidgetProps = {
|
|
|
10
10
|
/** @deprecated Use onEvent with 'opted_in' event type instead */
|
|
11
11
|
onOptIn?: () => Promise<OptInFields>;
|
|
12
12
|
openInNewTab?: boolean;
|
|
13
|
+
onLinkOpened?: (url: string) => void;
|
|
13
14
|
};
|
|
14
15
|
type USStates = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'DC' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY';
|
|
15
16
|
type USTerritories = 'AS' | 'GU' | 'MP' | 'PR' | 'VI';
|
package/out/index.js
CHANGED
|
@@ -37,9 +37,11 @@ const openParafinDashboard = (props) => {
|
|
|
37
37
|
}
|
|
38
38
|
const frame = document.createElement('iframe');
|
|
39
39
|
frame.id = 'parafin-dashboard';
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (!props.dashboardTargetElementId) {
|
|
41
|
+
frame.style.position = 'fixed';
|
|
42
|
+
frame.style.top = '0';
|
|
43
|
+
frame.style.left = '0';
|
|
44
|
+
}
|
|
43
45
|
frame.style.width = '100%';
|
|
44
46
|
frame.style.height = '100%';
|
|
45
47
|
frame.style.border = 'none';
|
|
@@ -49,25 +51,46 @@ const openParafinDashboard = (props) => {
|
|
|
49
51
|
frame.style.transition = 'opacity 0.2s';
|
|
50
52
|
frame.src = url;
|
|
51
53
|
frame.allow = 'accelerometer; gyroscope; clipboard-read; clipboard-write';
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const dashboardTargetElement = props.dashboardTargetElementId
|
|
55
|
+
? document.getElementById(props.dashboardTargetElementId)
|
|
56
|
+
: document.body;
|
|
57
|
+
if (!dashboardTargetElement) {
|
|
58
|
+
throw new Error('Dashboard target element not found');
|
|
59
|
+
}
|
|
60
|
+
const messageListener = async (event) => {
|
|
61
|
+
if (event.origin === origin) {
|
|
62
|
+
switch (event.data?.message) {
|
|
63
|
+
case 'close-dashboard':
|
|
64
|
+
if ('orderId' in props) {
|
|
65
|
+
props.onExit?.(props.orderId);
|
|
66
|
+
}
|
|
67
|
+
else if ('lineOfCreditApplicationId' in props) {
|
|
68
|
+
props.onExit?.(props.lineOfCreditApplicationId);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
props.onExit?.();
|
|
72
|
+
}
|
|
73
|
+
window.removeEventListener('message', messageListener);
|
|
74
|
+
frame.style.opacity = '0';
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
dashboardTargetElement.removeChild(frame);
|
|
77
|
+
document.body.style.removeProperty('overflow');
|
|
78
|
+
}, 200);
|
|
79
|
+
break;
|
|
80
|
+
case 'link-opened':
|
|
81
|
+
if (props.onLinkOpened && event.data?.url) {
|
|
82
|
+
props.onLinkOpened(event.data.url);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
62
85
|
}
|
|
63
|
-
window.removeEventListener('message', closeParafinDashboard);
|
|
64
|
-
frame.style.opacity = '0';
|
|
65
|
-
setTimeout(() => document.body.removeChild(frame), 200);
|
|
66
86
|
}
|
|
67
87
|
};
|
|
68
|
-
window.addEventListener('message',
|
|
69
|
-
|
|
70
|
-
setTimeout(() =>
|
|
88
|
+
window.addEventListener('message', messageListener);
|
|
89
|
+
dashboardTargetElement.appendChild(frame);
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
frame.style.opacity = '1';
|
|
92
|
+
document.body.style.overflow = 'hidden';
|
|
93
|
+
}, 1);
|
|
71
94
|
}
|
|
72
95
|
catch (error) {
|
|
73
96
|
console.error('Error loading Parafin dashboard', error);
|