@ndmspc/ndmspc-ui 0.0.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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # ndmspc ui
2
+
3
+ ## Setup keycloak
4
+
5
+ Create file `.env.local` in the project root with the following content:
6
+
7
+ ```
8
+ VITE_KEYCLOAK_URL="http://keycloak.127.0.0.1.nip.io:8008"
9
+ VITE_KEYCLOAK_REALM="ndmspc-dev"
10
+ VITE_KEYCLOAK_CLIENT="ndmspc-dev-client"
11
+ ```
12
+
13
+ ## WebSocket authentication
14
+
15
+ When the NDMSPC server is started with OIDC/Keycloak authentication enabled
16
+ (`NDMSPC_OIDC_ISSUER` / `NDMSPC_OIDC_AUDIENCE`, see the server `http/README.md`),
17
+ each WebSocket connection must authenticate before it can exchange traffic:
18
+
19
+ 1. the UI connects to `/ws/root.websocket` and immediately sends
20
+ `{"event": "authenticate", "token": "<keycloak-access-token>"}` as the first frame;
21
+ 2. the server replies `{"event": "authenticated", ...}` and only then sends
22
+ `welcome`, `clients`, heartbeats and starts honouring API request/reply messages;
23
+ 3. when the Keycloak token is refreshed, the UI re-authenticates on the same
24
+ connection (the refreshed token must keep the same JWT `sub`).
25
+
26
+ This handshake is implemented in `src/lib/wsAuthManager.ts`. A short grace
27
+ period distinguishes anonymous servers (they send `welcome` immediately) from
28
+ auth-enabled ones (they stay silent until authenticated), so servers started
29
+ without Keycloak keep working with no code change. When a server demands
30
+ sign-in and no valid session exists, the UI shows a **Sign in to connect**
31
+ action and starts the Keycloak login flow.
32
+
33
+ ## Install dependencies
34
+
35
+ ```bash
36
+ npm install
37
+ ```
38
+
39
+ ## Run development server
40
+
41
+ ```bash
42
+ npm run dev
43
+ ```
@@ -0,0 +1,5 @@
1
+ import { JSX } from 'react';
2
+
3
+ export declare function AnalyticsConsent(): JSX.Element | null;
4
+
5
+ export { }
@@ -0,0 +1,164 @@
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
3
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
4
+ //#region src/lib/utils/analytics.ts
5
+ function a() {
6
+ return window;
7
+ }
8
+ function o() {
9
+ return "";
10
+ }
11
+ function s() {
12
+ return o().length > 0;
13
+ }
14
+ function c(e) {
15
+ let t = e || o();
16
+ if (!t || a().gtag) return;
17
+ let n = document.createElement("script");
18
+ n.async = !0, n.src = `https://www.googletagmanager.com/gtag/js?id=${t}`, document.head.appendChild(n);
19
+ let r = a(), i = r.dataLayer ?? [];
20
+ r.dataLayer = i;
21
+ function s(...e) {
22
+ i.push(e);
23
+ }
24
+ r.gtag = s, r.gtag("js", /* @__PURE__ */ new Date()), r.gtag("config", t);
25
+ }
26
+ function l() {
27
+ try {
28
+ return localStorage.getItem("analytics_consent") === "granted";
29
+ } catch {
30
+ return !1;
31
+ }
32
+ }
33
+ function u() {
34
+ try {
35
+ return localStorage.getItem("analytics_consent") !== null;
36
+ } catch {
37
+ return !1;
38
+ }
39
+ }
40
+ function d(e) {
41
+ try {
42
+ localStorage.setItem("analytics_consent", e ? "granted" : "denied");
43
+ try {
44
+ window.dispatchEvent(new CustomEvent("analytics-consent", { detail: { granted: e } }));
45
+ } catch {}
46
+ } catch {}
47
+ }
48
+ //#endregion
49
+ //#region src/lib/components/AnalyticsConsent/AnalyticsConsent.tsx
50
+ function f() {
51
+ let a = e(9), [o, f] = n(p), [m, h] = n(null), g, _;
52
+ a[0] === Symbol.for("react.memo_cache_sentinel") ? (g = () => {
53
+ let e = (e) => {
54
+ if (!s()) {
55
+ f(!1);
56
+ return;
57
+ }
58
+ u() ? ((typeof e == "boolean" ? e : l()) && c(), f(!1)) : f(!0);
59
+ };
60
+ l() && c();
61
+ let t = (t) => {
62
+ let n = t?.detail, r = typeof n?.granted == "boolean" ? n.granted : void 0;
63
+ try {
64
+ e(r);
65
+ } catch {
66
+ e();
67
+ }
68
+ };
69
+ window.addEventListener("analytics-consent", t);
70
+ let n = (t) => {
71
+ let n = t?.detail;
72
+ if (n && n.rect) try {
73
+ h(n.rect), f(!0);
74
+ return;
75
+ } catch {}
76
+ e();
77
+ };
78
+ window.addEventListener("analytics-open", n);
79
+ let r = (t) => {
80
+ t.key === "analytics_consent" && e();
81
+ };
82
+ return window.addEventListener("storage", r), () => {
83
+ window.removeEventListener("analytics-consent", t), window.removeEventListener("storage", r), window.removeEventListener("analytics-open", n);
84
+ };
85
+ }, _ = [], a[0] = g, a[1] = _) : (g = a[0], _ = a[1]), t(g, _);
86
+ let v;
87
+ a[2] === Symbol.for("react.memo_cache_sentinel") ? (v = () => {
88
+ d(!0), c(), f(!1);
89
+ }, a[2] = v) : v = a[2];
90
+ let y = v, b;
91
+ a[3] === Symbol.for("react.memo_cache_sentinel") ? (b = () => {
92
+ d(!1), f(!1);
93
+ }, a[3] = b) : b = a[3];
94
+ let x = b;
95
+ if (!o) return null;
96
+ let S;
97
+ if (a[4] !== m) {
98
+ if (S = {
99
+ position: "fixed",
100
+ zIndex: 9999,
101
+ maxWidth: 360
102
+ }, m) {
103
+ let e = window.innerWidth, t = window.innerHeight, n = Math.round(m.left + window.scrollX);
104
+ n + 360 + 8 > e && (n = Math.max(8, e - 360 - 8) + window.scrollX), S.left = n + "px";
105
+ let r = m.bottom + window.scrollY + 8;
106
+ if (r + 160 + 8 > window.scrollY + t) {
107
+ let e = m.top + window.scrollY - 160 - 8;
108
+ S.top = Math.max(8 + window.scrollY, e) + "px";
109
+ } else S.top = r + "px";
110
+ } else S.right = 16, S.bottom = 16;
111
+ a[4] = m, a[5] = S;
112
+ } else S = a[5];
113
+ let C;
114
+ a[6] === Symbol.for("react.memo_cache_sentinel") ? (C = /* @__PURE__ */ i("div", {
115
+ style: {
116
+ display: "flex",
117
+ flexDirection: "column",
118
+ gap: 8
119
+ },
120
+ children: [
121
+ /* @__PURE__ */ r("div", {
122
+ style: {
123
+ fontSize: 14,
124
+ color: "#111"
125
+ },
126
+ children: "Allow anonymous usage analytics?"
127
+ }),
128
+ /* @__PURE__ */ r("div", {
129
+ style: {
130
+ fontSize: 12,
131
+ color: "#444"
132
+ },
133
+ children: "We collect only anonymous, aggregated usage statistics (no personal data, no user tracking). This helps improve the app and lets the ROOT team gather JSROOT usage metrics. Allow anonymous analytics?"
134
+ }),
135
+ /* @__PURE__ */ i("div", {
136
+ style: {
137
+ display: "flex",
138
+ gap: 8,
139
+ justifyContent: "flex-end"
140
+ },
141
+ children: [/* @__PURE__ */ r("button", {
142
+ onClick: x,
143
+ className: "px-3 py-1 rounded-md bg-muted/20",
144
+ children: "Decline"
145
+ }), /* @__PURE__ */ r("button", {
146
+ onClick: y,
147
+ className: "px-3 py-1 rounded-md bg-primary text-white",
148
+ children: "Accept"
149
+ })]
150
+ })
151
+ ]
152
+ }), a[6] = C) : C = a[6];
153
+ let w;
154
+ return a[7] === S ? w = a[8] : (w = /* @__PURE__ */ r("div", {
155
+ style: S,
156
+ className: "rounded-md p-4 bg-white shadow-lg border border-gray-200",
157
+ children: C
158
+ }), a[7] = S, a[8] = w), w;
159
+ }
160
+ function p() {
161
+ return s() && !u();
162
+ }
163
+ //#endregion
164
+ export { f as AnalyticsConsent };
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@ndmspc/ndmspc-ui",
3
+ "version": "0.0.0",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "type": "module",
8
+ "sideEffects": [
9
+ "**/*.css"
10
+ ],
11
+ "main": "./dist/ndmspc-ui.es.js",
12
+ "module": "./dist/ndmspc-ui.es.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/ndmspc-ui.es.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "dev": "vite --config vite.config.app.ts",
25
+ "build": "NODE_OPTIONS=--max-old-space-size=6144 tsc -b && NODE_OPTIONS=--max-old-space-size=6144 vite build",
26
+ "build:app": "NODE_OPTIONS=--max-old-space-size=6144 vite build --config vite.config.app.ts",
27
+ "lint": "eslint .",
28
+ "preview": "vite preview --config vite.config.app.ts"
29
+ },
30
+ "dependencies": {
31
+ "@hookform/resolvers": "^5.4.0",
32
+ "@ndmspc/ndmvr": "v1.2.0-rc.11",
33
+ "@react-three/drei": "^10.7.7",
34
+ "@react-three/fiber": "^9.6.1",
35
+ "@react-three/uikit": "^1.0.73",
36
+ "@react-three/uikit-default": "^1.0.73",
37
+ "@react-three/uikit-lucide": "^1.0.73",
38
+ "@react-three/xr": "^6.6.30",
39
+ "@tailwindcss/vite": "^4.3.0",
40
+ "@types/three": "^0.184.1",
41
+ "axios": "^1.16.1",
42
+ "class-variance-authority": "^0.7.1",
43
+ "clsx": "^2.1.1",
44
+ "framer-motion": "^12.40.0",
45
+ "keycloak-js": "^26.2.4",
46
+ "lucide-react": "^1.17.0",
47
+ "radix-ui": "^1.4.3",
48
+ "react": "^19.2.6",
49
+ "react-compiler-runtime": "^1.0.0",
50
+ "react-dom": "^19.2.6",
51
+ "react-hook-form": "^7.77.0",
52
+ "react-resizable-panels": "^4.11.2",
53
+ "tailwind-merge": "^3.6.0",
54
+ "tailwindcss": "^4.3.0",
55
+ "three": "^0.184.0",
56
+ "zod": "^4.4.3",
57
+ "zustand": "^5.0.14"
58
+ },
59
+ "devDependencies": {
60
+ "@babel/core": "^7.29.7",
61
+ "@eslint/js": "^10.0.1",
62
+ "@microsoft/api-extractor": "^7.57.0",
63
+ "@rolldown/plugin-babel": "^0.2.3",
64
+ "@types/node": "^25.9.1",
65
+ "@types/react": "^19.2.15",
66
+ "@types/react-dom": "^19.2.3",
67
+ "@vitejs/plugin-react": "^6.0.2",
68
+ "babel-plugin-react-compiler": "^1.0.0",
69
+ "esbuild": "^0.28.0",
70
+ "eslint": "^10.4.1",
71
+ "eslint-plugin-react-hooks": "^7.1.1",
72
+ "eslint-plugin-react-refresh": "^0.5.2",
73
+ "globals": "^17.6.0",
74
+ "shadcn": "^4.10.0",
75
+ "tw-animate-css": "^1.4.0",
76
+ "typescript": "~6.0.3",
77
+ "typescript-eslint": "^8.60.0",
78
+ "vite": "^8.0.16",
79
+ "vite-plugin-dts": "^5.0.1"
80
+ },
81
+ "peerDependencies": {
82
+ "react": ">=19 <20",
83
+ "react-dom": ">=19 <20",
84
+ "three": ">=0.184 <0.190"
85
+ }
86
+ }