@diegotsi/flint-react 2.1.3 → 2.2.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/dist/index.js CHANGED
@@ -286,7 +286,8 @@ function FlintModal({
286
286
  severity: isText ? "P3" : severity,
287
287
  url: window.location.href,
288
288
  meta: collectedMeta,
289
- label: isText ? "TEXT" : void 0
289
+ label: isText ? "TEXT" : void 0,
290
+ source: isText ? "text_issue" : "widget"
290
291
  };
291
292
  if (onBeforeSubmit) {
292
293
  const proceed = await onBeforeSubmit(payload);
@@ -1146,21 +1147,9 @@ import { Flint as Flint2 } from "@diegotsi/flint-core";
1146
1147
  import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
1147
1148
  import { I18nextProvider, useTranslation as useTranslation2 } from "react-i18next";
1148
1149
 
1149
- // src/collectors/console.ts
1150
- import { createConsoleCollector } from "@diegotsi/flint-core";
1151
-
1152
1150
  // src/collectors/environment.ts
1153
1151
  import { collectEnvironment } from "@diegotsi/flint-core";
1154
1152
 
1155
- // src/collectors/formErrors.ts
1156
- import { createFormErrorCollector } from "@diegotsi/flint-core";
1157
-
1158
- // src/collectors/frustration.ts
1159
- import { createFrustrationCollector } from "@diegotsi/flint-core";
1160
-
1161
- // src/collectors/network.ts
1162
- import { createNetworkCollector } from "@diegotsi/flint-core";
1163
-
1164
1153
  // src/i18n/index.ts
1165
1154
  import { createInstance } from "i18next";
1166
1155
  import { initReactI18next } from "react-i18next";
@@ -1220,7 +1209,6 @@ function useFlintStore() {
1220
1209
 
1221
1210
  // src/FlintWidget.tsx
1222
1211
  import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1223
- var REPLAY_WINDOW_MS = 6e4;
1224
1212
  function FlintWidget(props) {
1225
1213
  const { locale = "en-US" } = props;
1226
1214
  useEffect3(() => {
@@ -1324,92 +1312,26 @@ function WidgetContent({
1324
1312
  setOpen(true);
1325
1313
  onOpen?.();
1326
1314
  };
1327
- const globalInit = Flint2.isInitialized();
1328
- const global = Flint2.getInstance();
1329
- const consoleCollector = useRef3(null);
1330
- const networkCollector = useRef3(null);
1331
- const replayEvents = useRef3([]);
1332
- const stopReplay = useRef3(null);
1333
- const formErrorCollector = useRef3(null);
1334
- const frustrationCollector = useRef3(null);
1335
- if (!globalInit) {
1336
- if (enableConsole && !consoleCollector.current) {
1337
- consoleCollector.current = createConsoleCollector();
1338
- consoleCollector.current.start();
1339
- }
1340
- if (enableNetwork && !networkCollector.current) {
1341
- const flintHost = (() => {
1342
- try {
1343
- return new URL(serverUrl).hostname;
1344
- } catch {
1345
- return "";
1346
- }
1347
- })();
1348
- networkCollector.current = createNetworkCollector(flintHost ? [flintHost] : []);
1349
- networkCollector.current.start();
1350
- }
1351
- if (enableFormErrors && !formErrorCollector.current) {
1352
- formErrorCollector.current = createFormErrorCollector();
1353
- formErrorCollector.current.start();
1354
- _setFormErrorCollector(formErrorCollector.current);
1355
- }
1356
- if (enableFrustration && !frustrationCollector.current) {
1357
- frustrationCollector.current = createFrustrationCollector();
1358
- frustrationCollector.current.start();
1359
- }
1360
- }
1361
- useEffect3(() => {
1362
- if (globalInit) return;
1363
- let cancelled = false;
1364
- if (enableReplay) {
1365
- import("rrweb").then(({ record }) => {
1366
- if (cancelled) return;
1367
- const stopFn = record({
1368
- emit(event) {
1369
- replayEvents.current.push(event);
1370
- const cutoff = Date.now() - REPLAY_WINDOW_MS;
1371
- while (replayEvents.current.length > 0 && replayEvents.current[0].timestamp < cutoff) {
1372
- replayEvents.current.shift();
1373
- }
1374
- }
1375
- });
1376
- stopReplay.current = stopFn ?? null;
1377
- });
1378
- }
1379
- return () => {
1380
- cancelled = true;
1381
- consoleCollector.current?.stop();
1382
- networkCollector.current?.stop();
1383
- formErrorCollector.current?.stop();
1384
- _setFormErrorCollector(null);
1385
- frustrationCollector.current?.stop();
1386
- stopReplay.current?.();
1387
- };
1388
- }, [enableReplay, globalInit]);
1389
- useEffect3(() => {
1390
- if (globalInit) return;
1391
- if (!enableFrustration || !autoReportFrustration || !frustrationCollector.current) return;
1392
- const unsubscribe = frustrationCollector.current.onFrustration(async (event) => {
1393
- const user2 = resolvedUser;
1394
- await submitReport(serverUrl, projectKey, {
1395
- reporterId: user2?.id ?? "anonymous",
1396
- reporterName: user2?.name ?? "Anonymous",
1397
- reporterEmail: user2?.email,
1398
- description: `[Auto-detected] ${event.type.replace(/_/g, " ")}: ${event.details}`,
1399
- severity: event.type === "error_loop" ? "P1" : event.type === "rage_click" ? "P2" : "P3",
1400
- url: event.url,
1401
- meta: {
1402
- environment: collectEnvironment(),
1403
- consoleLogs: consoleCollector.current?.getEntries() ?? [],
1404
- networkErrors: networkCollector.current?.getEntries() ?? [],
1405
- formErrors: formErrorCollector.current?.getEntries() ?? [],
1406
- frustrationEvent: event
1407
- }
1408
- }).catch(() => {
1409
- });
1315
+ const didAutoInit = useRef3(false);
1316
+ if (!Flint2.isInitialized() && !didAutoInit.current) {
1317
+ Flint2.init({
1318
+ serverUrl,
1319
+ projectKey,
1320
+ user,
1321
+ enableConsole,
1322
+ enableNetwork,
1323
+ enableFormErrors,
1324
+ enableFrustration,
1325
+ autoReportFrustration,
1326
+ enableReplay,
1327
+ _replayRecorder: enableReplay ? (emit) => import("rrweb").then(({ record }) => {
1328
+ const stop = record({ emit });
1329
+ return stop ?? void 0;
1330
+ }) : void 0
1410
1331
  });
1411
- return unsubscribe;
1412
- }, [enableFrustration, autoReportFrustration, globalInit, projectKey, resolvedUser, serverUrl]);
1332
+ didAutoInit.current = true;
1333
+ }
1334
+ const global = Flint2.getInstance();
1413
1335
  const label = buttonLabel ?? t("buttonLabel");
1414
1336
  return /* @__PURE__ */ jsxs3(Fragment2, { children: [
1415
1337
  /* @__PURE__ */ jsxs3(
@@ -1508,10 +1430,10 @@ function WidgetContent({
1508
1430
  pendingSelection.current = "";
1509
1431
  },
1510
1432
  getEnvironment: collectEnvironment,
1511
- getConsoleLogs: () => globalInit ? global?.console?.getEntries() ?? [] : consoleCollector.current?.getEntries() ?? [],
1512
- getNetworkErrors: () => globalInit ? global?.network?.getEntries() ?? [] : networkCollector.current?.getEntries() ?? [],
1513
- getFormErrors: () => globalInit ? global?.formErrors?.getEntries() ?? [] : formErrorCollector.current?.getEntries() ?? [],
1514
- getReplayEvents: () => globalInit ? Flint2.getReplayEvents() : [...replayEvents.current],
1433
+ getConsoleLogs: () => global?.console?.getEntries() ?? [],
1434
+ getNetworkErrors: () => global?.network?.getEntries() ?? [],
1435
+ getFormErrors: () => global?.formErrors?.getEntries() ?? [],
1436
+ getReplayEvents: () => Flint2.getReplayEvents(),
1515
1437
  getExternalReplayUrl,
1516
1438
  initialSelection: pendingSelection.current,
1517
1439
  enableScreenshot,