@parafin/react 7.0.0 → 7.1.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.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
+ const initStartTime = Date.now();
134
138
  // @ts-ignore
135
139
  const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com');
136
140
  const query = {
@@ -158,6 +162,9 @@ 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,
@@ -170,7 +177,7 @@ const initializeParafinWidget = (iframe, props) => {
170
177
  case 'person-opt-in':
171
178
  if (props.onEvent) {
172
179
  try {
173
- await props.onEvent('opted_in');
180
+ await props.onEvent('opted_in', emptyMetadata);
174
181
  sendMessage({ message: 'person-opt-in', state: 'success' });
175
182
  }
176
183
  catch {
@@ -184,7 +191,7 @@ const initializeParafinWidget = (iframe, props) => {
184
191
  case 'person-opt-out':
185
192
  if (props.onEvent) {
186
193
  try {
187
- await props.onEvent('opted_out');
194
+ await props.onEvent('opted_out', emptyMetadata);
188
195
  sendMessage({ message: 'person-opt-out', state: 'success' });
189
196
  }
190
197
  catch {
@@ -200,6 +207,17 @@ const initializeParafinWidget = (iframe, props) => {
200
207
  iframe.style.height = data.height;
201
208
  }
202
209
  break;
210
+ case 'widget-error':
211
+ if (props.onEvent) {
212
+ props.onEvent('widget_error', emptyMetadata);
213
+ }
214
+ break;
215
+ case 'widget-load-complete':
216
+ if (props.onEvent) {
217
+ const timeToLoadInMs = Date.now() - initStartTime;
218
+ props.onEvent('widget_loaded', { timeToLoadInMs });
219
+ }
220
+ break;
203
221
  }
204
222
  }
205
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parafin/react",
3
- "version": "7.0.0",
3
+ "version": "7.1.0",
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.0"
30
30
  }
31
31
  }