@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.cjs CHANGED
@@ -30,10 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- Flint: () => import_flint_core9.Flint,
33
+ Flint: () => import_flint_core5.Flint,
34
34
  FlintModal: () => FlintModal,
35
35
  FlintWidget: () => FlintWidget,
36
- flint: () => import_flint_core9.flint
36
+ flint: () => import_flint_core5.flint
37
37
  });
38
38
  module.exports = __toCommonJS(index_exports);
39
39
 
@@ -325,7 +325,8 @@ function FlintModal({
325
325
  severity: isText ? "P3" : severity,
326
326
  url: window.location.href,
327
327
  meta: collectedMeta,
328
- label: isText ? "TEXT" : void 0
328
+ label: isText ? "TEXT" : void 0,
329
+ source: isText ? "text_issue" : "widget"
329
330
  };
330
331
  if (onBeforeSubmit) {
331
332
  const proceed = await onBeforeSubmit(payload);
@@ -1181,24 +1182,12 @@ function CheckIcon({ size = 20 }) {
1181
1182
  }
1182
1183
 
1183
1184
  // src/FlintWidget.tsx
1184
- var import_flint_core10 = require("@diegotsi/flint-core");
1185
+ var import_flint_core6 = require("@diegotsi/flint-core");
1185
1186
  var import_react4 = require("react");
1186
1187
  var import_react_i18next3 = require("react-i18next");
1187
1188
 
1188
- // src/collectors/console.ts
1189
- var import_flint_core3 = require("@diegotsi/flint-core");
1190
-
1191
1189
  // src/collectors/environment.ts
1192
- var import_flint_core4 = require("@diegotsi/flint-core");
1193
-
1194
- // src/collectors/formErrors.ts
1195
- var import_flint_core5 = require("@diegotsi/flint-core");
1196
-
1197
- // src/collectors/frustration.ts
1198
- var import_flint_core6 = require("@diegotsi/flint-core");
1199
-
1200
- // src/collectors/network.ts
1201
- var import_flint_core7 = require("@diegotsi/flint-core");
1190
+ var import_flint_core3 = require("@diegotsi/flint-core");
1202
1191
 
1203
1192
  // src/i18n/index.ts
1204
1193
  var import_i18next = require("i18next");
@@ -1250,16 +1239,15 @@ widgetI18n.use(import_react_i18next2.initReactI18next).init({
1250
1239
  var i18n_default = widgetI18n;
1251
1240
 
1252
1241
  // src/store.ts
1253
- var import_flint_core8 = require("@diegotsi/flint-core");
1242
+ var import_flint_core4 = require("@diegotsi/flint-core");
1254
1243
  var import_react3 = require("react");
1255
- var import_flint_core9 = require("@diegotsi/flint-core");
1244
+ var import_flint_core5 = require("@diegotsi/flint-core");
1256
1245
  function useFlintStore() {
1257
- return (0, import_react3.useSyncExternalStore)(import_flint_core8.subscribe, import_flint_core8.getSnapshot);
1246
+ return (0, import_react3.useSyncExternalStore)(import_flint_core4.subscribe, import_flint_core4.getSnapshot);
1258
1247
  }
1259
1248
 
1260
1249
  // src/FlintWidget.tsx
1261
1250
  var import_jsx_runtime3 = require("react/jsx-runtime");
1262
- var REPLAY_WINDOW_MS = 6e4;
1263
1251
  function FlintWidget(props) {
1264
1252
  const { locale = "en-US" } = props;
1265
1253
  (0, import_react4.useEffect)(() => {
@@ -1363,92 +1351,26 @@ function WidgetContent({
1363
1351
  setOpen(true);
1364
1352
  onOpen?.();
1365
1353
  };
1366
- const globalInit = import_flint_core10.Flint.isInitialized();
1367
- const global = import_flint_core10.Flint.getInstance();
1368
- const consoleCollector = (0, import_react4.useRef)(null);
1369
- const networkCollector = (0, import_react4.useRef)(null);
1370
- const replayEvents = (0, import_react4.useRef)([]);
1371
- const stopReplay = (0, import_react4.useRef)(null);
1372
- const formErrorCollector = (0, import_react4.useRef)(null);
1373
- const frustrationCollector = (0, import_react4.useRef)(null);
1374
- if (!globalInit) {
1375
- if (enableConsole && !consoleCollector.current) {
1376
- consoleCollector.current = (0, import_flint_core3.createConsoleCollector)();
1377
- consoleCollector.current.start();
1378
- }
1379
- if (enableNetwork && !networkCollector.current) {
1380
- const flintHost = (() => {
1381
- try {
1382
- return new URL(serverUrl).hostname;
1383
- } catch {
1384
- return "";
1385
- }
1386
- })();
1387
- networkCollector.current = (0, import_flint_core7.createNetworkCollector)(flintHost ? [flintHost] : []);
1388
- networkCollector.current.start();
1389
- }
1390
- if (enableFormErrors && !formErrorCollector.current) {
1391
- formErrorCollector.current = (0, import_flint_core5.createFormErrorCollector)();
1392
- formErrorCollector.current.start();
1393
- (0, import_flint_core9._setFormErrorCollector)(formErrorCollector.current);
1394
- }
1395
- if (enableFrustration && !frustrationCollector.current) {
1396
- frustrationCollector.current = (0, import_flint_core6.createFrustrationCollector)();
1397
- frustrationCollector.current.start();
1398
- }
1399
- }
1400
- (0, import_react4.useEffect)(() => {
1401
- if (globalInit) return;
1402
- let cancelled = false;
1403
- if (enableReplay) {
1404
- import("rrweb").then(({ record }) => {
1405
- if (cancelled) return;
1406
- const stopFn = record({
1407
- emit(event) {
1408
- replayEvents.current.push(event);
1409
- const cutoff = Date.now() - REPLAY_WINDOW_MS;
1410
- while (replayEvents.current.length > 0 && replayEvents.current[0].timestamp < cutoff) {
1411
- replayEvents.current.shift();
1412
- }
1413
- }
1414
- });
1415
- stopReplay.current = stopFn ?? null;
1416
- });
1417
- }
1418
- return () => {
1419
- cancelled = true;
1420
- consoleCollector.current?.stop();
1421
- networkCollector.current?.stop();
1422
- formErrorCollector.current?.stop();
1423
- (0, import_flint_core9._setFormErrorCollector)(null);
1424
- frustrationCollector.current?.stop();
1425
- stopReplay.current?.();
1426
- };
1427
- }, [enableReplay, globalInit]);
1428
- (0, import_react4.useEffect)(() => {
1429
- if (globalInit) return;
1430
- if (!enableFrustration || !autoReportFrustration || !frustrationCollector.current) return;
1431
- const unsubscribe = frustrationCollector.current.onFrustration(async (event) => {
1432
- const user2 = resolvedUser;
1433
- await (0, import_flint_core.submitReport)(serverUrl, projectKey, {
1434
- reporterId: user2?.id ?? "anonymous",
1435
- reporterName: user2?.name ?? "Anonymous",
1436
- reporterEmail: user2?.email,
1437
- description: `[Auto-detected] ${event.type.replace(/_/g, " ")}: ${event.details}`,
1438
- severity: event.type === "error_loop" ? "P1" : event.type === "rage_click" ? "P2" : "P3",
1439
- url: event.url,
1440
- meta: {
1441
- environment: (0, import_flint_core4.collectEnvironment)(),
1442
- consoleLogs: consoleCollector.current?.getEntries() ?? [],
1443
- networkErrors: networkCollector.current?.getEntries() ?? [],
1444
- formErrors: formErrorCollector.current?.getEntries() ?? [],
1445
- frustrationEvent: event
1446
- }
1447
- }).catch(() => {
1448
- });
1354
+ const didAutoInit = (0, import_react4.useRef)(false);
1355
+ if (!import_flint_core6.Flint.isInitialized() && !didAutoInit.current) {
1356
+ import_flint_core6.Flint.init({
1357
+ serverUrl,
1358
+ projectKey,
1359
+ user,
1360
+ enableConsole,
1361
+ enableNetwork,
1362
+ enableFormErrors,
1363
+ enableFrustration,
1364
+ autoReportFrustration,
1365
+ enableReplay,
1366
+ _replayRecorder: enableReplay ? (emit) => import("rrweb").then(({ record }) => {
1367
+ const stop = record({ emit });
1368
+ return stop ?? void 0;
1369
+ }) : void 0
1449
1370
  });
1450
- return unsubscribe;
1451
- }, [enableFrustration, autoReportFrustration, globalInit, projectKey, resolvedUser, serverUrl]);
1371
+ didAutoInit.current = true;
1372
+ }
1373
+ const global = import_flint_core6.Flint.getInstance();
1452
1374
  const label = buttonLabel ?? t("buttonLabel");
1453
1375
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1454
1376
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
@@ -1546,11 +1468,11 @@ function WidgetContent({
1546
1468
  onClose?.();
1547
1469
  pendingSelection.current = "";
1548
1470
  },
1549
- getEnvironment: import_flint_core4.collectEnvironment,
1550
- getConsoleLogs: () => globalInit ? global?.console?.getEntries() ?? [] : consoleCollector.current?.getEntries() ?? [],
1551
- getNetworkErrors: () => globalInit ? global?.network?.getEntries() ?? [] : networkCollector.current?.getEntries() ?? [],
1552
- getFormErrors: () => globalInit ? global?.formErrors?.getEntries() ?? [] : formErrorCollector.current?.getEntries() ?? [],
1553
- getReplayEvents: () => globalInit ? import_flint_core10.Flint.getReplayEvents() : [...replayEvents.current],
1471
+ getEnvironment: import_flint_core3.collectEnvironment,
1472
+ getConsoleLogs: () => global?.console?.getEntries() ?? [],
1473
+ getNetworkErrors: () => global?.network?.getEntries() ?? [],
1474
+ getFormErrors: () => global?.formErrors?.getEntries() ?? [],
1475
+ getReplayEvents: () => import_flint_core6.Flint.getReplayEvents(),
1554
1476
  getExternalReplayUrl,
1555
1477
  initialSelection: pendingSelection.current,
1556
1478
  enableScreenshot,