@orbs-network/spot-react 0.0.3
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.d.ts +2 -0
- package/dist/spot-react/src/components/SpotEventList.d.ts +7 -0
- package/dist/spot-react/src/components/SpotEventList.d.ts.map +1 -0
- package/dist/spot-react/src/components/SpotTracker.d.ts +9 -0
- package/dist/spot-react/src/components/SpotTracker.d.ts.map +1 -0
- package/dist/spot-react/src/context/SpotContext.d.ts +16 -0
- package/dist/spot-react/src/context/SpotContext.d.ts.map +1 -0
- package/dist/spot-react/src/index.d.ts +5 -0
- package/dist/spot-react/src/index.d.ts.map +1 -0
- package/dist/spot-react.css +1 -0
- package/dist/spot-react.js +66 -0
- package/dist/spot-react.umd.cjs +1 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpotEventList.d.ts","sourceRoot":"","sources":["../../../../src/components/SpotEventList.tsx"],"names":[],"mappings":"AAGA,OAAO,qBAAqB,CAAA;AAE5B,UAAU,kBAAkB;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,aAAa,CAAC,EAAE,SAAc,EAAE,SAAc,EAAE,EAAE,kBAAkB,2CAwCnF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
interface SpotTrackerProps {
|
|
3
|
+
eventType?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function SpotTracker({ eventType, children, className, }: SpotTrackerProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=SpotTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpotTracker.d.ts","sourceRoot":"","sources":["../../../../src/components/SpotTracker.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEhD,OAAO,mBAAmB,CAAA;AAE1B,UAAU,gBAAgB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,WAAW,CAAC,EAC1B,SAAmB,EACnB,QAAQ,EACR,SAAc,GACf,EAAE,gBAAgB,2CAkBlB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Spot, SpotConfig, SpotEvent } from '../../../spot-sdk/src/index.ts';
|
|
3
|
+
interface SpotContextValue {
|
|
4
|
+
spot: Spot;
|
|
5
|
+
track: (type: string, payload?: Record<string, unknown>) => SpotEvent;
|
|
6
|
+
getEvents: () => SpotEvent[];
|
|
7
|
+
clearEvents: () => void;
|
|
8
|
+
}
|
|
9
|
+
interface SpotProviderProps {
|
|
10
|
+
config?: SpotConfig;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function SpotProvider({ config, children }: SpotProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function useSpot(): SpotContextValue;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=SpotContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpotContext.d.ts","sourceRoot":"","sources":["../../../../src/context/SpotContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1E,OAAO,EAAE,IAAI,EAAc,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE1F,UAAU,gBAAgB;IACxB,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,SAAS,CAAA;IACrE,SAAS,EAAE,MAAM,SAAS,EAAE,CAAA;IAC5B,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAID,UAAU,iBAAiB;IACzB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAanE;AAED,wBAAgB,OAAO,IAAI,gBAAgB,CAM1C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SpotProvider, useSpot } from './context/SpotContext';
|
|
2
|
+
export { SpotTracker } from './components/SpotTracker';
|
|
3
|
+
export { SpotEventList } from './components/SpotEventList';
|
|
4
|
+
export type { SpotConfig, SpotEvent } from '../../spot-sdk/src/index.ts';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAG1D,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.spot-tracker{cursor:pointer;transition:transform .15s ease-out}.spot-tracker--tracked{transform:scale(.98)}.spot-event-list{font-family:system-ui,-apple-system,sans-serif;border:1px solid #e0e0e0;border-radius:8px;padding:16px;background:#fafafa}.spot-event-list__header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.spot-event-list__header h3{margin:0;font-size:14px;font-weight:600;color:#333}.spot-event-list__clear{padding:4px 12px;font-size:12px;border:1px solid #ddd;border-radius:4px;background:#fff;cursor:pointer;transition:background .15s}.spot-event-list__clear:hover{background:#f0f0f0}.spot-event-list__empty{color:#888;font-size:13px;text-align:center;padding:20px;margin:0}.spot-event-list__items{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:8px}.spot-event-list__item{background:#fff;border:1px solid #eee;border-radius:6px;padding:10px}.spot-event-list__type{font-weight:600;color:#2563eb;font-size:13px}.spot-event-list__time{font-size:11px;color:#888;margin-left:8px}.spot-event-list__payload{margin:6px 0 0;font-size:11px;background:#f5f5f5;padding:6px;border-radius:4px;overflow-x:auto;color:#555}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as d, useMemo as h, useContext as _, useState as p, useEffect as k } from "react";
|
|
3
|
+
import { createSpot as f } from "@orbs-network/spot-sdk";
|
|
4
|
+
const m = d(null);
|
|
5
|
+
function y({ config: t, children: a }) {
|
|
6
|
+
const r = h(() => {
|
|
7
|
+
const s = f(t);
|
|
8
|
+
return {
|
|
9
|
+
spot: s,
|
|
10
|
+
track: (o, c) => s.track(o, c),
|
|
11
|
+
getEvents: () => s.getEvents(),
|
|
12
|
+
clearEvents: () => s.clearEvents()
|
|
13
|
+
};
|
|
14
|
+
}, [t]);
|
|
15
|
+
return /* @__PURE__ */ e(m.Provider, { value: r, children: a });
|
|
16
|
+
}
|
|
17
|
+
function u() {
|
|
18
|
+
const t = _(m);
|
|
19
|
+
if (!t)
|
|
20
|
+
throw new Error("useSpot must be used within a SpotProvider");
|
|
21
|
+
return t;
|
|
22
|
+
}
|
|
23
|
+
function C({
|
|
24
|
+
eventType: t = "click",
|
|
25
|
+
children: a,
|
|
26
|
+
className: r = ""
|
|
27
|
+
}) {
|
|
28
|
+
const { track: s } = u(), [o, c] = p(!1), l = () => {
|
|
29
|
+
s(t, { component: "SpotTracker" }), c(!0), setTimeout(() => c(!1), 300);
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ e(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
className: `spot-tracker ${o ? "spot-tracker--tracked" : ""} ${r}`,
|
|
35
|
+
onClick: l,
|
|
36
|
+
children: a
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function x({ maxEvents: t = 10, className: a = "" }) {
|
|
41
|
+
const { getEvents: r, clearEvents: s } = u(), [o, c] = p([]);
|
|
42
|
+
k(() => {
|
|
43
|
+
const n = setInterval(() => {
|
|
44
|
+
c(r().slice(-t));
|
|
45
|
+
}, 100);
|
|
46
|
+
return () => clearInterval(n);
|
|
47
|
+
}, [r, t]);
|
|
48
|
+
const l = (n) => new Date(n).toLocaleTimeString();
|
|
49
|
+
return /* @__PURE__ */ i("div", { className: `spot-event-list ${a}`, children: [
|
|
50
|
+
/* @__PURE__ */ i("div", { className: "spot-event-list__header", children: [
|
|
51
|
+
/* @__PURE__ */ e("h3", { children: "Spot Events" }),
|
|
52
|
+
/* @__PURE__ */ e("button", { onClick: s, className: "spot-event-list__clear", children: "Clear" })
|
|
53
|
+
] }),
|
|
54
|
+
o.length === 0 ? /* @__PURE__ */ e("p", { className: "spot-event-list__empty", children: "No events tracked yet" }) : /* @__PURE__ */ e("ul", { className: "spot-event-list__items", children: o.map((n, v) => /* @__PURE__ */ i("li", { className: "spot-event-list__item", children: [
|
|
55
|
+
/* @__PURE__ */ e("span", { className: "spot-event-list__type", children: n.type }),
|
|
56
|
+
/* @__PURE__ */ e("span", { className: "spot-event-list__time", children: l(n.timestamp) }),
|
|
57
|
+
/* @__PURE__ */ e("pre", { className: "spot-event-list__payload", children: JSON.stringify(n.payload, null, 2) })
|
|
58
|
+
] }, `${n.timestamp}-${v}`)) })
|
|
59
|
+
] });
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
x as SpotEventList,
|
|
63
|
+
y as SpotProvider,
|
|
64
|
+
C as SpotTracker,
|
|
65
|
+
u as useSpot
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@orbs-network/spot-sdk")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@orbs-network/spot-sdk"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.SpotReact={},t.jsxRuntime,t.React,t.SpotSDK))})(this,(function(t,e,o,v){"use strict";const u=o.createContext(null);function S({config:s,children:l}){const c=o.useMemo(()=>{const n=v.createSpot(s);return{spot:n,track:(a,i)=>n.track(a,i),getEvents:()=>n.getEvents(),clearEvents:()=>n.clearEvents()}},[s]);return e.jsx(u.Provider,{value:c,children:l})}function p(){const s=o.useContext(u);if(!s)throw new Error("useSpot must be used within a SpotProvider");return s}function f({eventType:s="click",children:l,className:c=""}){const{track:n}=p(),[a,i]=o.useState(!1),d=()=>{n(s,{component:"SpotTracker"}),i(!0),setTimeout(()=>i(!1),300)};return e.jsx("div",{className:`spot-tracker ${a?"spot-tracker--tracked":""} ${c}`,onClick:d,children:l})}function k({maxEvents:s=10,className:l=""}){const{getEvents:c,clearEvents:n}=p(),[a,i]=o.useState([]);o.useEffect(()=>{const r=setInterval(()=>{i(c().slice(-s))},100);return()=>clearInterval(r)},[c,s]);const d=r=>new Date(r).toLocaleTimeString();return e.jsxs("div",{className:`spot-event-list ${l}`,children:[e.jsxs("div",{className:"spot-event-list__header",children:[e.jsx("h3",{children:"Spot Events"}),e.jsx("button",{onClick:n,className:"spot-event-list__clear",children:"Clear"})]}),a.length===0?e.jsx("p",{className:"spot-event-list__empty",children:"No events tracked yet"}):e.jsx("ul",{className:"spot-event-list__items",children:a.map((r,m)=>e.jsxs("li",{className:"spot-event-list__item",children:[e.jsx("span",{className:"spot-event-list__type",children:r.type}),e.jsx("span",{className:"spot-event-list__time",children:d(r.timestamp)}),e.jsx("pre",{className:"spot-event-list__payload",children:JSON.stringify(r.payload,null,2)})]},`${r.timestamp}-${m}`))})]})}t.SpotEventList=k,t.SpotProvider=S,t.SpotTracker=f,t.useSpot=p,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orbs-network/spot-react",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Spot React Components - React components for Spot SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/spot-react.umd.cjs",
|
|
7
|
+
"module": "./dist/spot-react.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/spot-react.js",
|
|
13
|
+
"require": "./dist/spot-react.umd.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./styles.css": "./dist/style.css"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"spot",
|
|
22
|
+
"ui",
|
|
23
|
+
"react",
|
|
24
|
+
"components"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
29
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@orbs-network/spot-sdk": "0.0.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^19.0.2",
|
|
36
|
+
"@types/react-dom": "^19.0.2",
|
|
37
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
38
|
+
"react": "^19.0.0",
|
|
39
|
+
"react-dom": "^19.0.0",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"vite": "^6.0.5",
|
|
42
|
+
"vite-plugin-dts": "^4.4.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "vite build --watch",
|
|
46
|
+
"build": "tsc && vite build"
|
|
47
|
+
}
|
|
48
|
+
}
|