@parafin/react 7.0.0 → 7.1.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 CHANGED
@@ -1,3 +1,3 @@
1
- import { LinkOpenedMetadata, WidgetProps, WidgetEvent } from '@parafin/core';
1
+ import { LinkOpenedMetadata, WidgetProps, WidgetEvent, WidgetEventMetadata } from '@parafin/core';
2
2
  declare const ParafinWidget: (props: WidgetProps) => import("react/jsx-runtime").JSX.Element;
3
- export { ParafinWidget, type WidgetEvent, type WidgetProps, type LinkOpenedMetadata, };
3
+ export { ParafinWidget, type WidgetEvent, type WidgetEventMetadata, type WidgetProps, type LinkOpenedMetadata, };
package/out/index.js CHANGED
@@ -130,7 +130,11 @@ const defaultWidgetStyles = {
130
130
  transition: 'border 0.2s, border-radius 0.2s',
131
131
  boxSizing: 'border-box',
132
132
  };
133
+ const emptyMetadata = {
134
+ timeToLoadInMs: null,
135
+ };
133
136
  const initializeParafinWidget = (iframe, props) => {
137
+ let initStartTime = Date.now();
134
138
  // @ts-ignore
135
139
  const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com');
136
140
  const query = {
@@ -158,10 +162,14 @@ const initializeParafinWidget = (iframe, props) => {
158
162
  }
159
163
  break;
160
164
  case 'open-dashboard':
165
+ if (props.onEvent) {
166
+ props.onEvent('dashboard_opened', emptyMetadata);
167
+ }
161
168
  openParafinDashboard({
162
169
  ...props,
163
170
  route: data?.route,
164
171
  onExit: () => {
172
+ initStartTime = Date.now();
165
173
  iframe.src = iframeSrc;
166
174
  props.onExit?.();
167
175
  },
@@ -170,7 +178,7 @@ const initializeParafinWidget = (iframe, props) => {
170
178
  case 'person-opt-in':
171
179
  if (props.onEvent) {
172
180
  try {
173
- await props.onEvent('opted_in');
181
+ await props.onEvent('opted_in', emptyMetadata);
174
182
  sendMessage({ message: 'person-opt-in', state: 'success' });
175
183
  }
176
184
  catch {
@@ -184,7 +192,7 @@ const initializeParafinWidget = (iframe, props) => {
184
192
  case 'person-opt-out':
185
193
  if (props.onEvent) {
186
194
  try {
187
- await props.onEvent('opted_out');
195
+ await props.onEvent('opted_out', emptyMetadata);
188
196
  sendMessage({ message: 'person-opt-out', state: 'success' });
189
197
  }
190
198
  catch {
@@ -200,6 +208,17 @@ const initializeParafinWidget = (iframe, props) => {
200
208
  iframe.style.height = data.height;
201
209
  }
202
210
  break;
211
+ case 'widget-error':
212
+ if (props.onEvent) {
213
+ props.onEvent('widget_error', emptyMetadata);
214
+ }
215
+ break;
216
+ case 'widget-load-complete':
217
+ if (props.onEvent) {
218
+ const timeToLoadInMs = Date.now() - initStartTime;
219
+ props.onEvent('widget_loaded', { timeToLoadInMs });
220
+ }
221
+ break;
203
222
  }
204
223
  }
205
224
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/react",
3
- "version": "7.0.0",
3
+ "version": "7.1.1",
4
4
  "description": "Parafin React widget",
5
5
  "author": "Parafin (https://www.parafin.com)",
6
6
  "module": "out/index.js",
@@ -26,6 +26,6 @@
26
26
  "typescript": "^4.9.5"
27
27
  },
28
28
  "dependencies": {
29
- "@parafin/core": "^3.0.0"
29
+ "@parafin/core": "^3.1.1"
30
30
  }
31
31
  }