@nivaro/react 0.3.45 → 0.3.46

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.
Files changed (40) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +42 -7
  4. package/dist/shared/components/BaseMap.js +149 -103
  5. package/dist/shared/components/command-center/CommandCenterView.js +313 -69
  6. package/dist/shared/components/command-center/Customize.js +353 -0
  7. package/dist/shared/components/command-center/Header.js +279 -53
  8. package/dist/shared/components/command-center/KioskLinks.js +198 -0
  9. package/dist/shared/components/command-center/PeekPanel.js +143 -3
  10. package/dist/shared/components/command-center/announce.js +13 -0
  11. package/dist/shared/components/command-center/board-prefs.js +99 -0
  12. package/dist/shared/components/command-center/freshness.js +29 -0
  13. package/dist/shared/components/command-center/layout.js +56 -0
  14. package/dist/shared/components/command-center/panels/AttentionPanel.js +132 -3
  15. package/dist/shared/components/command-center/panels/Banner.js +75 -0
  16. package/dist/shared/components/command-center/panels/BoardSettings.js +223 -0
  17. package/dist/shared/components/command-center/panels/FeedPanel.js +145 -29
  18. package/dist/shared/components/command-center/panels/FlowPanel.js +154 -56
  19. package/dist/shared/components/command-center/panels/ForecastPanel.js +244 -3
  20. package/dist/shared/components/command-center/panels/MapLegend.js +266 -0
  21. package/dist/shared/components/command-center/panels/MapPanel.js +216 -66
  22. package/dist/shared/components/command-center/panels/PartnersPanel.js +49 -3
  23. package/dist/shared/components/command-center/panels/PeoplePanel.js +257 -40
  24. package/dist/shared/components/command-center/panels/RegionPicker.js +88 -3
  25. package/dist/shared/components/command-center/panels/SystemPanel.js +158 -38
  26. package/dist/shared/components/command-center/panels/ThroughputPanel.js +307 -3
  27. package/dist/shared/components/command-center/panels/TimeBar.js +227 -6
  28. package/dist/shared/components/command-center/panels/TrafficPanel.js +12 -8
  29. package/dist/shared/components/command-center/panels/WorkloadPanel.js +82 -3
  30. package/dist/shared/components/command-center/panels/attention-actions.js +267 -0
  31. package/dist/shared/components/command-center/panels/map-shared.js +95 -0
  32. package/dist/shared/components/command-center/panels/registry.js +87 -19
  33. package/dist/shared/components/command-center/shell-hooks.js +118 -0
  34. package/dist/shared/components/command-center/shortcuts.js +37 -0
  35. package/dist/shared/components/command-center/theme.js +39 -21
  36. package/dist/shared/components/command-center/time.js +52 -0
  37. package/dist/shared/components/command-center/url-state.js +54 -0
  38. package/dist/shared/components/command-center/work-links.js +32 -0
  39. package/dist/shared/components/monitoring/TrafficMiniMap.js +111 -70
  40. package/package.json +1 -1
@@ -1,96 +1,340 @@
1
- import { jsx as t, jsxs as b } from "react/jsx-runtime";
2
- import { useState as n, useMemo as y, useContext as F } from "react";
3
- import { useNavigation as Q } from "../../context.js";
4
- import { useCcQuery as P } from "./api.js";
5
- import { Header as T } from "./Header.js";
6
- import { PeekPanel as D } from "./PeekPanel.js";
7
- import { CC_PANELS as I } from "./panels/registry.js";
8
- import { EMPTY_FILTERS as S, CcContext as g } from "./state.js";
9
- import { useAppIsDark as j, ccVars as H } from "./theme.js";
10
- function G({
1
+ import { jsx as t, jsxs as u } from "react/jsx-runtime";
2
+ import { useQueryClient as ge } from "@tanstack/react-query";
3
+ import { MapPinned as ve } from "lucide-react";
4
+ import { useState as i, useRef as K, useEffect as B, useMemo as Q, useCallback as J, useContext as xe } from "react";
5
+ import { createPortal as ye } from "react-dom";
6
+ import { useNavigation as we } from "../../context.js";
7
+ import { attentionCount as ke, attentionAnnouncement as be } from "./announce.js";
8
+ import { useCcQuery as Z } from "./api.js";
9
+ import { useCcPrefs as Ce, useKioskInfo as Ne, DEFAULT_PREFS as Ee } from "./board-prefs.js";
10
+ import { CustomizeSheet as _e } from "./Customize.js";
11
+ import { countFailures as Ae } from "./freshness.js";
12
+ import { Header as Pe } from "./Header.js";
13
+ import { effectiveLayout as Te, resolvePanels as Fe, arrangeBoard as Me, boardSizeFor as Oe } from "./layout.js";
14
+ import { PeekPanel as Se } from "./PeekPanel.js";
15
+ import { BoardBanner as De } from "./panels/Banner.js";
16
+ import { CC_PANELS as Ue } from "./panels/registry.js";
17
+ import { useFullscreen as Ie, useWindowWidth as Re, usePeekFocus as $e, useRegionCycle as ze } from "./shell-hooks.js";
18
+ import { shortcutFor as Le, regionForIndex as Ke, FOCUS_REGION_EVENT as Be, REGION_PICKER_ATTR as Qe } from "./shortcuts.js";
19
+ import { EMPTY_FILTERS as He, CcContext as X } from "./state.js";
20
+ import { useAppIsDark as je, boardMode as Ve, MUTED as qe, ccVars as ue, BUTTON as ce, FOCUS as de } from "./theme.js";
21
+ import { EMPTY_URL_STATE as Ge, parseBoardUrl as We, windowUrlAdapter as Ye, writeBoardUrl as Ze } from "./url-state.js";
22
+ function Ct({
11
23
  /** Fallback map collections when the instance has no Command Center config yet. */
12
- geoCollections: p = ["locations"],
13
- recordUrl: i,
14
- isAdmin: s = !1,
15
- kiosk: a = null
24
+ geoCollections: H = ["locations"],
25
+ recordUrl: A,
26
+ isAdmin: C = !1,
27
+ kiosk: s = null,
28
+ urlAdapter: j
16
29
  }) {
17
- const { navigate: m } = Q(), u = j(), [r, f] = n(null), [d, c] = n(null), [o, e] = n(null), [v, E] = n(S), [x, A] = n(null), [C, N] = n(!1), [k, _] = n(null), h = y(
18
- () => i ?? ((l, M) => `/collections/${l}/${M}`),
19
- [i]
20
- ), w = y(
30
+ var L, c;
31
+ const { navigate: U } = we(), P = ge(), d = je(), y = s ? null : j ?? Ye, [f] = i(() => y ? We(y.read()) : Ge), [p, I] = i(f.region), [n, N] = i(f.at), [m, R] = i(f.map), [$, V] = i(He), [E, T] = i(f.peek), [h, q] = i(f.tv || !!s), [F, G] = i(null), [ee, g] = i(!1), v = Ie(), M = Ce(!s), x = s ? null : M.data ?? null, w = Ne(s), a = K(!1);
32
+ B(() => {
33
+ const r = w.data;
34
+ !r || a.current || (a.current = !0, r.region && I(r.region), r.map_collection && R(r.map_collection));
35
+ }, [w.data]), B(() => {
36
+ y && y.replace(Ze(y.read(), { region: p, at: n, map: m, peek: E, tv: h }));
37
+ }, [y, p, n, m, E, h]);
38
+ const O = Q(
39
+ () => A ?? ((r, b) => `/collections/${r}/${b}`),
40
+ [A]
41
+ ), z = J(
42
+ (r) => {
43
+ s || U(r);
44
+ },
45
+ [s, U]
46
+ ), k = J(
47
+ () => void P.invalidateQueries({ queryKey: ["command-center"] }),
48
+ [P]
49
+ ), S = Ve({ appDark: d, theme: x == null ? void 0 : x.theme, tv: h, kiosk: !!s }), W = Q(
21
50
  () => ({
22
- isAdmin: s,
23
- kiosk: a,
51
+ isAdmin: C,
52
+ kiosk: s,
24
53
  config: null,
25
54
  snapshot: null,
26
55
  snapshotError: !1,
27
56
  updatedAt: null,
28
- region: r,
29
- setRegion: f,
30
- at: d,
31
- setAt: c,
32
- mapCollection: o,
33
- setMapCollection: e,
34
- filters: v,
35
- setFilters: E,
36
- peek: x,
37
- setPeek: (l) => {
38
- l && m(h(l.collection, l.id)), A(null);
39
- },
40
- focusMap: (l) => _({ ...l, nonce: Date.now() }),
41
- mapFocus: k,
42
- tv: C,
43
- setTv: N,
44
- navigate: m,
45
- recordUrl: h
57
+ snapshotLoading: !0,
58
+ snapshotFailures: 0,
59
+ refresh: k,
60
+ prefs: x,
61
+ mode: S,
62
+ region: p,
63
+ setRegion: I,
64
+ at: n,
65
+ setAt: N,
66
+ mapCollection: m,
67
+ setMapCollection: R,
68
+ filters: $,
69
+ setFilters: V,
70
+ peek: E,
71
+ // A wallboard opens no record (the server refuses /peek for a link as well).
72
+ setPeek: s ? Xe : T,
73
+ focusMap: (r) => G({ ...r, nonce: Date.now() }),
74
+ mapFocus: F,
75
+ tv: h,
76
+ setTv: (r) => q(s ? !0 : r),
77
+ fullscreen: v.on,
78
+ toggleFullscreen: v.toggle,
79
+ openCustomize: () => g(!0),
80
+ navigate: z,
81
+ recordUrl: O
46
82
  }),
47
- [s, a, r, d, o, v, x, k, C, m, h]
83
+ [
84
+ C,
85
+ s,
86
+ k,
87
+ x,
88
+ S,
89
+ p,
90
+ n,
91
+ m,
92
+ $,
93
+ E,
94
+ F,
95
+ h,
96
+ v.on,
97
+ v.toggle,
98
+ z,
99
+ O
100
+ ]
101
+ );
102
+ return s && w.isError ? /* @__PURE__ */ t(et, {}) : /* @__PURE__ */ t(X.Provider, { value: W, children: /* @__PURE__ */ t(
103
+ tt,
104
+ {
105
+ fallbackCollections: H,
106
+ exitFullscreen: v.exit,
107
+ customizeOpen: ee,
108
+ setCustomizeOpen: g,
109
+ kioskLabel: ((L = w.data) == null ? void 0 : L.label) ?? null,
110
+ kioskRegionPinned: !!((c = w.data) != null && c.region)
111
+ }
112
+ ) });
113
+ }
114
+ const Je = /* @__PURE__ */ new Set(["feed", "workload"]), Xe = () => {
115
+ };
116
+ function et() {
117
+ return /* @__PURE__ */ u(
118
+ "main",
119
+ {
120
+ className: "flex min-h-screen flex-col items-center justify-center gap-2 bg-[var(--cc-bg)] p-6 text-center",
121
+ style: ue("dark"),
122
+ children: [
123
+ /* @__PURE__ */ t("h1", { className: "text-[18px] font-semibold text-[var(--cc-strong)]", children: "This wallboard link no longer works" }),
124
+ /* @__PURE__ */ t("p", { className: `max-w-md text-[14px] ${qe}`, children: "It may have expired or been turned off. Ask an administrator for a new link." })
125
+ ]
126
+ }
48
127
  );
49
- return /* @__PURE__ */ t(g.Provider, { value: w, children: /* @__PURE__ */ t(L, { fallbackCollections: p, appDark: u }) });
50
128
  }
51
- function L({
52
- fallbackCollections: p,
53
- appDark: i
129
+ const me = 1.25;
130
+ function tt({
131
+ fallbackCollections: H,
132
+ exitFullscreen: A,
133
+ customizeOpen: C,
134
+ setCustomizeOpen: s,
135
+ kioskLabel: j,
136
+ kioskRegionPinned: U
54
137
  }) {
55
- const s = F(g);
56
- if (!s) throw new Error("Command Center board outside its provider");
57
- const a = P("/snapshot", void 0, { refetchInterval: 2e4 }), u = P("/config", void 0, {
138
+ var oe, re, ae, se;
139
+ const P = xe(X);
140
+ if (!P) throw new Error("Command Center board outside its provider");
141
+ const d = Z("/snapshot", void 0, {
142
+ refetchInterval: 2e4,
143
+ retry: 1
144
+ }), f = Z("/config", void 0, {
58
145
  staleTime: 5 * 6e4,
59
146
  lenses: !1,
60
147
  retry: !1
61
148
  }).data ?? {
62
- geo_collections: p.map((o) => ({ key: o, label: "" })),
149
+ geo_collections: H.map((o) => ({ key: o, label: "" })),
63
150
  regions: [],
64
151
  region_label: null,
65
152
  stuck_days: 7
66
- }, r = {
67
- ...s,
68
- config: u,
69
- snapshot: a.data ?? null,
70
- snapshotError: a.isError,
71
- updatedAt: a.dataUpdatedAt || null
72
- }, f = i || s.tv ? "dark" : "light", d = I.filter((o) => {
73
- var e;
74
- return !o.adminOnly || r.isAdmin || !!((e = r.snapshot) != null && e.health);
75
- }), c = (o) => d.filter((e) => e.area === o).map((e) => /* @__PURE__ */ t(e.component, {}, e.key));
76
- return /* @__PURE__ */ t(g.Provider, { value: r, children: /* @__PURE__ */ b(
153
+ }, p = K({ dataAt: 0, errors: 0 });
154
+ d.dataUpdatedAt !== p.current.dataAt && (p.current = { dataAt: d.dataUpdatedAt, errors: d.errorUpdateCount });
155
+ const I = Ae(d.errorUpdateCount, p.current.errors), n = {
156
+ ...P,
157
+ config: f,
158
+ snapshot: d.data ?? null,
159
+ snapshotError: d.isError,
160
+ updatedAt: d.dataUpdatedAt || null,
161
+ snapshotLoading: d.isPending,
162
+ snapshotFailures: I
163
+ }, { tv: N, kiosk: m, peek: R, fullscreen: $, region: V, setRegion: E } = n, [T, h] = i(!1), [q, F] = i(!1), G = Re(), g = Oe(G / (N ? me : 1)), v = J(
164
+ (o) => {
165
+ var e;
166
+ return !(n.kiosk && Je.has(o.key)) && (!o.adminOnly || n.isAdmin || !!((e = n.snapshot) != null && e.health));
167
+ },
168
+ [n.isAdmin, n.kiosk, (oe = n.snapshot) == null ? void 0 : oe.health]
169
+ ), M = Q(() => Ue.filter(v), [v]), x = Te((re = n.prefs) == null ? void 0 : re.layout, (ae = n.prefs) == null ? void 0 : ae.role_default), w = Q(() => {
170
+ const o = new Map(M.map((e) => [e.key, e]));
171
+ return Fe(
172
+ M.map((e) => e.key),
173
+ x
174
+ ).filter((e) => e.visible).map((e) => o.get(e.key)).filter((e) => !!e);
175
+ }, [M, x]), a = Me(w, g);
176
+ $e(!!R), ze({
177
+ // A wallboard stays on the board its link opens on (the server pins it too).
178
+ enabled: N && !m && !U,
179
+ regionIds: f.regions.map((o) => o.id),
180
+ current: V,
181
+ setRegion: E,
182
+ intervalMs: (((se = n.prefs) == null ? void 0 : se.tv_cycle_seconds) ?? Ee.tv_cycle_seconds ?? 30) * 1e3
183
+ });
184
+ const O = K({ state: n, helpOpen: T, customizeOpen: C });
185
+ O.current = { state: n, helpOpen: T, customizeOpen: C }, B(() => {
186
+ const o = (e) => {
187
+ var le, ie;
188
+ const Y = Le(e);
189
+ if (!Y) return;
190
+ const { state: l, helpOpen: pe, customizeOpen: he } = O.current;
191
+ if (he || pe) return;
192
+ const D = e.target;
193
+ if (!((le = D == null ? void 0 : D.closest) != null && le.call(D, '[role="dialog"]:not([data-cc-peek]), [role="menu"], [role="listbox"]')))
194
+ switch (Y.kind) {
195
+ case "escape":
196
+ l.peek ? (e.preventDefault(), l.setPeek(null)) : l.fullscreen ? A() : l.tv && !l.kiosk && l.setTv(!1);
197
+ return;
198
+ case "fullscreen":
199
+ e.preventDefault(), l.toggleFullscreen();
200
+ return;
201
+ case "tv":
202
+ e.preventDefault(), l.setTv(!l.tv);
203
+ return;
204
+ case "refresh":
205
+ e.preventDefault(), l.refresh();
206
+ return;
207
+ case "focus-region": {
208
+ if (l.kiosk) return;
209
+ e.preventDefault(), window.dispatchEvent(new CustomEvent(Be));
210
+ const _ = document.querySelector(`[${Qe}]`);
211
+ _ && !_.contains(document.activeElement) && _.focus();
212
+ return;
213
+ }
214
+ case "region": {
215
+ if (l.kiosk) return;
216
+ const _ = Ke(((ie = l.config) == null ? void 0 : ie.regions) ?? [], Y.index);
217
+ if (_ === void 0) return;
218
+ e.preventDefault(), l.setRegion(_);
219
+ return;
220
+ }
221
+ case "help":
222
+ e.preventDefault(), h(!0);
223
+ return;
224
+ }
225
+ };
226
+ return window.addEventListener("keydown", o), () => window.removeEventListener("keydown", o);
227
+ }, [A]);
228
+ const z = Z("/attention", void 0, { enabled: !1 }), k = ke(z.data), S = K(null), [W, L] = i("");
229
+ B(() => {
230
+ if (k === null) return;
231
+ const o = be(S.current, k);
232
+ S.current = k, o && L(o);
233
+ }, [k]);
234
+ const c = (o) => o.map((e) => /* @__PURE__ */ t("div", { className: "min-w-0", "data-cc-slot": e.key, children: /* @__PURE__ */ t(e.component, {}) }, e.key)), r = (o) => a.main.map(
235
+ (e) => g === "phone" && !q ? /* @__PURE__ */ u(
236
+ "button",
237
+ {
238
+ type: "button",
239
+ "aria-expanded": !1,
240
+ onClick: () => F(!0),
241
+ className: `${ce} flex w-full items-center justify-center gap-2 py-2.5 text-[12.5px] ${de}`,
242
+ children: [
243
+ /* @__PURE__ */ t(ve, { className: "h-4 w-4", "aria-hidden": !0 }),
244
+ "Show map"
245
+ ]
246
+ },
247
+ e.key
248
+ ) : /* @__PURE__ */ u(
249
+ "div",
250
+ {
251
+ "data-cc-slot": e.key,
252
+ className: o ? "flex min-h-[420px] min-w-0 flex-1 flex-col [&>*]:flex-1" : "min-w-0",
253
+ children: [
254
+ /* @__PURE__ */ t(e.component, {}),
255
+ g === "phone" && /* @__PURE__ */ t(
256
+ "button",
257
+ {
258
+ type: "button",
259
+ "aria-expanded": !0,
260
+ onClick: () => F(!1),
261
+ className: `${ce} mt-2 w-full ${de}`,
262
+ children: "Hide map"
263
+ }
264
+ )
265
+ ]
266
+ },
267
+ e.key
268
+ )
269
+ );
270
+ let b;
271
+ a.columns === "three" ? b = /* @__PURE__ */ u("div", { className: "grid min-h-0 flex-1 grid-cols-[340px_minmax(0,1fr)_360px] gap-3", children: [
272
+ /* @__PURE__ */ t(
273
+ "section",
274
+ {
275
+ "aria-label": "Needs someone now",
276
+ className: "flex min-h-0 flex-col gap-3 overflow-y-auto",
277
+ children: c(a.lead)
278
+ }
279
+ ),
280
+ /* @__PURE__ */ u("div", { className: "flex min-h-0 min-w-0 flex-col gap-3", children: [
281
+ r(!0),
282
+ c(a.under)
283
+ ] }),
284
+ /* @__PURE__ */ t(
285
+ "aside",
286
+ {
287
+ "aria-label": "More on the board",
288
+ className: "flex min-h-0 flex-col gap-3 overflow-y-auto",
289
+ children: c(a.rail)
290
+ }
291
+ )
292
+ ] }) : a.columns === "two" ? b = /* @__PURE__ */ u("div", { className: "grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_380px] gap-3", children: [
293
+ /* @__PURE__ */ u("div", { className: "flex min-h-0 min-w-0 flex-col gap-3", children: [
294
+ r(!0),
295
+ c(a.under)
296
+ ] }),
297
+ /* @__PURE__ */ t(
298
+ "aside",
299
+ {
300
+ "aria-label": "More on the board",
301
+ className: "flex min-h-0 flex-col gap-3 overflow-y-auto",
302
+ children: c(a.rail)
303
+ }
304
+ )
305
+ ] }) : b = /* @__PURE__ */ u("div", { className: "flex flex-col gap-3", children: [
306
+ a.lead.length > 0 && /* @__PURE__ */ t("section", { "aria-label": "Needs someone now", className: "flex flex-col gap-3", children: c(a.lead) }),
307
+ r(!1),
308
+ /* @__PURE__ */ t(
309
+ "aside",
310
+ {
311
+ "aria-label": "More on the board",
312
+ className: `grid gap-3 ${g === "medium" ? "grid-cols-2" : "grid-cols-1"}`,
313
+ children: c(a.rail)
314
+ }
315
+ ),
316
+ c(a.under)
317
+ ] });
318
+ const fe = a.columns !== "one", te = $ && !m, ne = /* @__PURE__ */ t(X.Provider, { value: n, children: /* @__PURE__ */ u(
77
319
  "div",
78
320
  {
79
- className: "flex h-full min-h-0 flex-1 flex-col gap-3 bg-[var(--cc-bg)] p-4 text-[var(--cc-text)]",
80
- style: H(f),
81
- "data-cc-mode": f,
321
+ className: `relative flex min-w-0 flex-col gap-3 bg-[var(--cc-bg)] p-3 text-[var(--cc-text)] sm:p-4 ${fe ? "h-full min-h-0 flex-1" : "min-h-full flex-1"} ${te ? "fixed inset-0 z-[45] overflow-auto" : ""} ${m ? "min-h-screen" : ""}`,
322
+ style: { ...ue(n.mode), ...N ? { zoom: me } : {} },
323
+ "data-cc-mode": n.mode,
324
+ "data-cc-tv": N ? "1" : void 0,
325
+ "data-cc-size": g,
82
326
  children: [
83
- /* @__PURE__ */ t(T, {}),
84
- /* @__PURE__ */ b("div", { className: "grid min-h-0 flex-1 gap-3 xl:grid-cols-[1fr_360px]", children: [
85
- /* @__PURE__ */ t("div", { className: "flex min-h-0 flex-col gap-3", children: c("main") }),
86
- /* @__PURE__ */ t("div", { className: "flex min-h-0 flex-col gap-3 overflow-y-auto", children: c("rail") })
87
- ] }),
88
- c("bottom"),
89
- /* @__PURE__ */ t(D, {})
327
+ /* @__PURE__ */ t(Pe, { helpOpen: T, onHelpOpenChange: h, kioskLabel: j }),
328
+ /* @__PURE__ */ t(De, {}),
329
+ m ? /* @__PURE__ */ t("main", { className: "flex min-h-0 flex-1 flex-col", children: b }) : /* @__PURE__ */ t("section", { "aria-label": "Command Center board", className: "flex min-h-0 flex-1 flex-col", children: b }),
330
+ /* @__PURE__ */ t(Se, {}),
331
+ /* @__PURE__ */ t("div", { className: "sr-only", "aria-live": "polite", "aria-atomic": "true", children: W }),
332
+ !m && /* @__PURE__ */ t(_e, { open: C, onOpenChange: s })
90
333
  ]
91
334
  }
92
335
  ) });
336
+ return te && typeof document < "u" ? ye(ne, document.body) : ne;
93
337
  }
94
338
  export {
95
- G as CommandCenterView
339
+ Ct as CommandCenterView
96
340
  };