@mcp-fe/react-event-tracker 0.1.4 → 0.1.6
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/index.js +1 -0
- package/package.json +6 -2
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react"),x=require("@mcp-fe/mcp-worker");function ue(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const y=ue(E),ae=Object.prototype.hasOwnProperty;function J(e,t,r=0){if(e===t)return e;if(r>500)return t;const n=t,u=U(e)&&U(n);if(!u&&!(M(e)&&M(n)))return n;const p=u?e:z(e);if(!p)return n;const m=u?n:z(n);if(!m)return n;const f=p.length,d=m.length,o=u?new Array(d):{};let i=0;for(let c=0;c<d;c++){const v=u?c:m[c],a=e[v],s=n[v];if(a===s){o[v]=a,(u?c<f:ae.call(e,v))&&i++;continue}if(a===null||s===null||typeof a!="object"||typeof s!="object"){o[v]=s;continue}const l=J(a,s,r+1);o[v]=l,l===a&&i++}return f===d&&i===f?e:o}function z(e){const t=[],r=Object.getOwnPropertyNames(e);for(const u of r){if(!Object.prototype.propertyIsEnumerable.call(e,u))return!1;t.push(u)}const n=Object.getOwnPropertySymbols(e);for(const u of n){if(!Object.prototype.propertyIsEnumerable.call(e,u))return!1;t.push(u)}return t}function M(e){if(!G(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const r=t.prototype;return!(!G(r)||!r.hasOwnProperty("isPrototypeOf"))}function G(e){return Object.prototype.toString.call(e)==="[object Object]"}function U(e){return Array.isArray(e)&&e.length===Object.keys(e).length}var ce=process.env.NODE_ENV==="production";function ie(e,t){if(!ce){if(e)return;var r="Warning: "+t;typeof console<"u"&&console.warn(r);try{throw Error(r)}catch{}}}var k={exports:{}},C={},L={exports:{}},D={};var W;function se(){if(W)return D;W=1;var e=E;function t(c,v){return c===v&&(c!==0||1/c===1/v)||c!==c&&v!==v}var r=typeof Object.is=="function"?Object.is:t,n=e.useState,u=e.useEffect,p=e.useLayoutEffect,m=e.useDebugValue;function f(c,v){var a=v(),s=n({inst:{value:a,getSnapshot:v}}),l=s[0].inst,_=s[1];return p(function(){l.value=a,l.getSnapshot=v,d(l)&&_({inst:l})},[c,a,v]),u(function(){return d(l)&&_({inst:l}),c(function(){d(l)&&_({inst:l})})},[c]),m(a),a}function d(c){var v=c.getSnapshot;c=c.value;try{var a=v();return!r(c,a)}catch{return!0}}function o(c,v){return v()}var i=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?o:f;return D.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:i,D}var I={};var K;function fe(){return K||(K=1,process.env.NODE_ENV!=="production"&&(function(){function e(a,s){return a===s&&(a!==0||1/a===1/s)||a!==a&&s!==s}function t(a,s){i||u.startTransition===void 0||(i=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=s();if(!c){var _=s();p(l,_)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}_=m({inst:{value:l,getSnapshot:s}});var h=_[0].inst,R=_[1];return d(function(){h.value=l,h.getSnapshot=s,r(h)&&R({inst:h})},[a,l,s]),f(function(){return r(h)&&R({inst:h}),a(function(){r(h)&&R({inst:h})})},[a]),o(l),l}function r(a){var s=a.getSnapshot;a=a.value;try{var l=s();return!p(a,l)}catch{return!0}}function n(a,s){return s()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var u=E,p=typeof Object.is=="function"?Object.is:e,m=u.useState,f=u.useEffect,d=u.useLayoutEffect,o=u.useDebugValue,i=!1,c=!1,v=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?n:t;I.useSyncExternalStore=u.useSyncExternalStore!==void 0?u.useSyncExternalStore:v,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),I}var H;function Q(){return H||(H=1,process.env.NODE_ENV==="production"?L.exports=se():L.exports=fe()),L.exports}var q;function le(){if(q)return C;q=1;var e=E,t=Q();function r(o,i){return o===i&&(o!==0||1/o===1/i)||o!==o&&i!==i}var n=typeof Object.is=="function"?Object.is:r,u=t.useSyncExternalStore,p=e.useRef,m=e.useEffect,f=e.useMemo,d=e.useDebugValue;return C.useSyncExternalStoreWithSelector=function(o,i,c,v,a){var s=p(null);if(s.current===null){var l={hasValue:!1,value:null};s.current=l}else l=s.current;s=f(function(){function h(O){if(!R){if(R=!0,T=O,O=v(O),a!==void 0&&l.hasValue){var S=l.value;if(a(S,O))return g=S}return g=O}if(S=g,n(T,O))return S;var N=v(O);return a!==void 0&&a(S,N)?(T=O,S):(T=O,g=N)}var R=!1,T,g,w=c===void 0?null:c;return[function(){return h(i())},w===null?void 0:function(){return h(w())}]},[i,c,v,a]);var _=u(o,s[0],s[1]);return m(function(){l.hasValue=!0,l.value=_},[_]),d(_),_},C}var V={};var j;function de(){return j||(j=1,process.env.NODE_ENV!=="production"&&(function(){function e(o,i){return o===i&&(o!==0||1/o===1/i)||o!==o&&i!==i}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var t=E,r=Q(),n=typeof Object.is=="function"?Object.is:e,u=r.useSyncExternalStore,p=t.useRef,m=t.useEffect,f=t.useMemo,d=t.useDebugValue;V.useSyncExternalStoreWithSelector=function(o,i,c,v,a){var s=p(null);if(s.current===null){var l={hasValue:!1,value:null};s.current=l}else l=s.current;s=f(function(){function h(O){if(!R){if(R=!0,T=O,O=v(O),a!==void 0&&l.hasValue){var S=l.value;if(a(S,O))return g=S}return g=O}if(S=g,n(T,O))return S;var N=v(O);return a!==void 0&&a(S,N)?(T=O,S):(T=O,g=N)}var R=!1,T,g,w=c===void 0?null:c;return[function(){return h(i())},w===null?void 0:function(){return h(w())}]},[i,c,v,a]);var _=u(o,s[0],s[1]);return m(function(){l.hasValue=!0,l.value=_},[_]),d(_),_},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),V}var $;function pe(){return $||($=1,process.env.NODE_ENV==="production"?k.exports=le():k.exports=de()),k.exports}var ve=pe();function Ee(e,t=n=>n,r={}){const n=r.equal??me;return ve.useSyncExternalStoreWithSelector(e.subscribe,()=>e.state,()=>e.state,t,n)}function me(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[n,u]of e)if(!t.has(n)||!Object.is(u,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();const r=F(e);if(r.length!==F(t).length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(t,r[n])||!Object.is(e[r[n]],t[r[n]]))return!1;return!0}function F(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}const b=y.createContext(null);function _e(){return typeof document>"u"?b:window.__TSR_ROUTER_CONTEXT__?window.__TSR_ROUTER_CONTEXT__:(window.__TSR_ROUTER_CONTEXT__=b,b)}function Oe(e){const t=y.useContext(_e());return ie(!((e?.warn??!0)&&!t),"useRouter must be used inside a <RouterProvider> component!"),t}function he(e){const t=Oe({warn:e?.router===void 0}),r=e?.router||t,n=E.useRef(void 0);return Ee(r.__store,u=>{if(e?.select){if(e.structuralSharing??r.options.defaultStructuralSharing){const p=J(n.current,e.select(u));return n.current=p,p}return e.select(u)}return u})}function Se(e){return he({select:t=>t.location})}async function Z(e){return x.workerClient.init(e)}async function P(e){const t={...e,timestamp:Date.now()};await x.workerClient.request("STORE_EVENT",{event:t})}function ee(e){x.workerClient.setAuthToken(e)}async function te(e,t,r){return P({type:"navigation",from:e,to:t,path:r||t})}async function re(e,t,r){const n=e.id||void 0,u=e.className||void 0,p=e.textContent?.trim().substring(0,100)||void 0,m=e.tagName.toLowerCase();return P({type:"click",element:m,elementId:n,elementClass:u,elementText:p,path:t||window.location.pathname,metadata:r})}async function ne(e,t,r){const n=e.id||void 0,u=e.className||void 0,p=e.tagName.toLowerCase();return P({type:"input",element:p,elementId:n,elementClass:u,path:r||window.location.pathname,metadata:{valueLength:t?.length||0,value:t}})}function ye(e){const t=Se(),[r,n]=E.useState(!1),u=E.useRef(!1),p=E.useRef(t.pathname),m=E.useRef(null);return E.useEffect(()=>{m.current=p.current,p.current=t.pathname},[t.pathname]),E.useEffect(()=>{u.current||(u.current=!0,Z(e).then(()=>{n(!0)}).catch(f=>{console.error("[TanstackEventTracker] Worker initialization failed:",f)}))},[e]),E.useEffect(()=>{if(!r)return;const f=m.current,d=p.current;f&&f!==d&&te(f,d,d).catch(o=>{console.error("[TanstackEventTracker] Failed to track navigation:",o)})},[t.pathname,r]),E.useEffect(()=>{if(!r)return;const f=d=>{const o=d.target;if(!o)return;o.tagName==="BUTTON"||o.tagName==="A"||o.closest("button")||o.closest("a")||re(o,p.current).catch(c=>{console.error("[TanstackEventTracker] Failed to track click:",c)})};return document.addEventListener("click",f,!0),()=>document.removeEventListener("click",f,!0)},[r]),E.useEffect(()=>{if(!r)return;let f;const d=o=>{const i=o.target;i&&(i.tagName==="INPUT"||i.tagName==="TEXTAREA")&&(clearTimeout(f),f=setTimeout(()=>{ne(i,i.value,p.current).catch(c=>{console.error("[TanstackEventTracker] Failed to track input:",c)})},1e3))};return document.addEventListener("input",d,!0),()=>{clearTimeout(f),document.removeEventListener("input",d,!0)}},[r]),{setAuthToken:ee}}var X;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(X||(X={}));function Y(e,t){throw new Error(t)}var B;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(B||(B={}));const oe=["post","put","patch","delete"];new Set(oe);const Re=["get",...oe];new Set(Re);const Te=y.createContext(null);process.env.NODE_ENV!=="production"&&(Te.displayName="DataRouter");const ge=y.createContext(null);process.env.NODE_ENV!=="production"&&(ge.displayName="DataRouterState");const we=y.createContext(null);process.env.NODE_ENV!=="production"&&(we.displayName="Await");const Ne=y.createContext(null);process.env.NODE_ENV!=="production"&&(Ne.displayName="Navigation");const A=y.createContext(null);process.env.NODE_ENV!=="production"&&(A.displayName="Location");const ke=y.createContext({outlet:null,matches:[],isDataRoute:!1});process.env.NODE_ENV!=="production"&&(ke.displayName="Route");const Le=y.createContext(null);process.env.NODE_ENV!=="production"&&(Le.displayName="RouteError");function Ce(){return y.useContext(A)!=null}function De(){return Ce()||(process.env.NODE_ENV!=="production"?Y(!1,"useLocation() may be used only in the context of a <Router> component."):Y()),y.useContext(A).location}new Promise(()=>{});function Ie(e){const t=De(),[r,n]=E.useState(!1),u=E.useRef(!1),p=E.useRef(t.pathname),m=E.useRef(null);return E.useEffect(()=>{m.current=p.current,p.current=t.pathname},[t.pathname]),E.useEffect(()=>{u.current||(u.current=!0,Z(e).then(()=>{n(!0)}).catch(f=>{console.error("[ReactEventTracker] Worker initialization failed:",f)}))},[e]),E.useEffect(()=>{if(!r)return;const f=m.current,d=p.current;f&&f!==d&&te(f,d,d).catch(o=>{console.error("[ReactEventTracker] Failed to track navigation:",o)})},[t.pathname,r]),E.useEffect(()=>{if(!r)return;const f=d=>{const o=d.target;if(!o)return;o.tagName==="BUTTON"||o.tagName==="A"||o.closest("button")||o.closest("a")||re(o,p.current).catch(c=>{console.error("[ReactEventTracker] Failed to track click:",c)})};return document.addEventListener("click",f,!0),()=>document.removeEventListener("click",f,!0)},[r]),E.useEffect(()=>{if(!r)return;let f;const d=o=>{const i=o.target;i&&(i.tagName==="INPUT"||i.tagName==="TEXTAREA")&&(clearTimeout(f),f=setTimeout(()=>{ne(i,i.value,p.current).catch(c=>{console.error("[ReactEventTracker] Failed to track input:",c)})},1e3))};return document.addEventListener("input",d,!0),()=>{clearTimeout(f),document.removeEventListener("input",d,!0)}},[r]),{setAuthToken:ee}}exports.useReactRouterEventTracker=Ie;exports.useTanstackRouterEventTracker=ye;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-fe/react-event-tracker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://mcp-fe.ai",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"directory": "libs/react-event-tracker"
|
|
10
10
|
},
|
|
11
11
|
"main": "./index.js",
|
|
12
|
+
"module": "./index.mjs",
|
|
12
13
|
"types": "./index.d.ts",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
@@ -17,12 +18,15 @@
|
|
|
17
18
|
"require": "./index.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@mcp-fe/event-tracker": "^0.1.6"
|
|
23
|
+
},
|
|
20
24
|
"peerDependencies": {
|
|
21
25
|
"react": ">=19.0.0",
|
|
22
26
|
"react-dom": ">=19.0.0",
|
|
23
27
|
"react-router-dom": ">=6.0.0",
|
|
24
28
|
"@tanstack/react-router": ">=1.0.0",
|
|
25
|
-
"@mcp-fe/
|
|
29
|
+
"@mcp-fe/mcp-worker": "^0.1.6"
|
|
26
30
|
},
|
|
27
31
|
"publishConfig": {
|
|
28
32
|
"access": "public"
|