@hansenexus/hud 0.4.0 → 0.5.1
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 +634 -12
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.cjs +201 -0
- package/dist/next/config.d.cts +87 -0
- package/dist/next/config.d.ts +64 -0
- package/dist/next/config.js +84 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +237 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +72 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
import { HUD_FLAG_SCOPES } from "./flags.js";
|
|
2
|
+
import { a as useDataState, i as syncLocalOverrides, n as applyOverrides, r as errorMessage, s as useMockClientStatus, t as applyMocks } from "./data-store-ChF1td_P.js";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/plugins/data/styles.ts
|
|
6
|
+
/** Data plugin styles, rendered in a `<style>` inside the shadow root. Built on the shell's tokens. */
|
|
7
|
+
const DATA_CSS = `
|
|
8
|
+
.data { display: flex; flex-direction: column; gap: 12px; }
|
|
9
|
+
.data-section { display: flex; flex-direction: column; gap: 6px; }
|
|
10
|
+
.data-heading {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
gap: 8px;
|
|
15
|
+
font-size: 10px;
|
|
16
|
+
font-weight: 600;
|
|
17
|
+
letter-spacing: 0.06em;
|
|
18
|
+
text-transform: uppercase;
|
|
19
|
+
color: var(--hud-fg-muted);
|
|
20
|
+
}
|
|
21
|
+
.data-heading-actions { display: flex; gap: 6px; text-transform: none; letter-spacing: 0; }
|
|
22
|
+
.data-muted { color: var(--hud-fg-muted); }
|
|
23
|
+
.data-hint { margin: 0; color: var(--hud-fg-muted); font-size: 11px; }
|
|
24
|
+
.data-mono { font-family: var(--hud-mono); }
|
|
25
|
+
.data code { font-family: var(--hud-mono); font-size: 10px; }
|
|
26
|
+
.data-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
27
|
+
.data-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
28
|
+
.data-users { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
|
|
29
|
+
.hud .data-user {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: 8px;
|
|
33
|
+
width: 100%;
|
|
34
|
+
padding: 3px 6px;
|
|
35
|
+
border: 1px solid var(--hud-border);
|
|
36
|
+
border-radius: 4px;
|
|
37
|
+
text-align: left;
|
|
38
|
+
}
|
|
39
|
+
.hud .data-user:hover:not(:disabled) { background: var(--hud-bg-subtle); }
|
|
40
|
+
.hud .data-user[aria-pressed="true"] { border-color: var(--hud-accent); }
|
|
41
|
+
.hud .data-user:disabled { opacity: 0.6; cursor: default; }
|
|
42
|
+
.data-badge {
|
|
43
|
+
padding: 0 6px;
|
|
44
|
+
border: 1px solid var(--hud-border);
|
|
45
|
+
border-radius: 999px;
|
|
46
|
+
font-family: var(--hud-mono);
|
|
47
|
+
font-size: 10px;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
}
|
|
50
|
+
.data-badge[data-tone="active"] { color: var(--hud-good); border-color: currentColor; }
|
|
51
|
+
.data-badge[data-tone="poor"] { color: var(--hud-poor); border-color: currentColor; }
|
|
52
|
+
.data-badge[data-tone="muted"] { color: var(--hud-fg-muted); }
|
|
53
|
+
.data-badge[data-tone="override"] {
|
|
54
|
+
color: var(--hud-bg);
|
|
55
|
+
background: var(--hud-warn);
|
|
56
|
+
border-color: var(--hud-warn);
|
|
57
|
+
}
|
|
58
|
+
.data-flags { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
|
59
|
+
.data-flag { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; border-top: 1px solid var(--hud-border); }
|
|
60
|
+
.data-flag:first-child { border-top: 0; }
|
|
61
|
+
.data-segments { display: flex; gap: 2px; margin: 0; padding: 0; border: 0; min-inline-size: 0; }
|
|
62
|
+
.hud .data-segment {
|
|
63
|
+
padding: 2px 6px;
|
|
64
|
+
border: 1px solid var(--hud-border);
|
|
65
|
+
border-radius: 4px;
|
|
66
|
+
font-family: var(--hud-mono);
|
|
67
|
+
font-size: 10px;
|
|
68
|
+
}
|
|
69
|
+
.hud .data-segment:hover:not(:disabled) { background: var(--hud-bg-subtle); }
|
|
70
|
+
.hud .data-segment[aria-pressed="true"] {
|
|
71
|
+
background: var(--hud-accent);
|
|
72
|
+
border-color: var(--hud-accent);
|
|
73
|
+
color: var(--hud-bg);
|
|
74
|
+
}
|
|
75
|
+
.hud .data-segment:disabled { opacity: 0.5; cursor: default; }
|
|
76
|
+
.hud .data-button {
|
|
77
|
+
padding: 2px 10px;
|
|
78
|
+
border: 1px solid var(--hud-border);
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
}
|
|
81
|
+
.hud .data-button:hover:not(:disabled) { background: var(--hud-bg-subtle); }
|
|
82
|
+
.hud .data-button:disabled { opacity: 0.5; cursor: default; }
|
|
83
|
+
.hud .data-button[data-tone="danger"] { border-color: var(--hud-poor); color: var(--hud-poor); }
|
|
84
|
+
.data-seeds, .data-endpoints { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
|
85
|
+
.data-seed, .data-endpoint { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; border-top: 1px solid var(--hud-border); }
|
|
86
|
+
.data-seed:first-child, .data-endpoint:first-child { border-top: 0; }
|
|
87
|
+
.data-seed .data-badge { margin-left: 6px; }
|
|
88
|
+
.data-detail { font-size: 11px; }
|
|
89
|
+
.data-detail summary { cursor: pointer; color: var(--hud-fg-muted); }
|
|
90
|
+
.data-detail pre {
|
|
91
|
+
margin: 4px 0 0;
|
|
92
|
+
max-height: 160px;
|
|
93
|
+
overflow: auto;
|
|
94
|
+
padding: 4px 6px;
|
|
95
|
+
border: 1px solid var(--hud-border);
|
|
96
|
+
border-radius: 4px;
|
|
97
|
+
background: var(--hud-bg-subtle);
|
|
98
|
+
font-family: var(--hud-mono);
|
|
99
|
+
font-size: 10px;
|
|
100
|
+
white-space: pre-wrap;
|
|
101
|
+
}
|
|
102
|
+
.data-field {
|
|
103
|
+
flex: 1;
|
|
104
|
+
min-width: 0;
|
|
105
|
+
padding: 3px 6px;
|
|
106
|
+
border: 1px solid var(--hud-border);
|
|
107
|
+
border-radius: 4px;
|
|
108
|
+
background: var(--hud-bg-subtle);
|
|
109
|
+
color: var(--hud-fg);
|
|
110
|
+
font: inherit;
|
|
111
|
+
font-family: var(--hud-mono);
|
|
112
|
+
font-size: 11px;
|
|
113
|
+
}
|
|
114
|
+
.data-select {
|
|
115
|
+
padding: 2px 4px;
|
|
116
|
+
border: 1px solid var(--hud-border);
|
|
117
|
+
border-radius: 4px;
|
|
118
|
+
background: var(--hud-bg-subtle);
|
|
119
|
+
color: var(--hud-fg);
|
|
120
|
+
font: inherit;
|
|
121
|
+
font-family: var(--hud-mono);
|
|
122
|
+
font-size: 10px;
|
|
123
|
+
}
|
|
124
|
+
.data-result { margin: 0; font-size: 11px; }
|
|
125
|
+
.data-result[data-ok="true"] { color: var(--hud-good); }
|
|
126
|
+
.data-result[data-ok="false"] { color: var(--hud-poor); }
|
|
127
|
+
`;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/plugins/data/data-panel.tsx
|
|
130
|
+
const JSON_HEADERS = { "content-type": "application/json" };
|
|
131
|
+
/** Writes what the server could not: `localStorage` entries of the session. */
|
|
132
|
+
function applyStorage(storage) {
|
|
133
|
+
try {
|
|
134
|
+
for (const [key, value] of Object.entries(storage)) if (value === null) localStorage.removeItem(key);
|
|
135
|
+
else localStorage.setItem(key, value);
|
|
136
|
+
} catch {}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Data panel: the role switch (pick a fixture user; the page reloads signed
|
|
140
|
+
* in as them), feature-flag overrides (cookie or localStorage scope,
|
|
141
|
+
* persisted through the storage seam until reset), the app's seed functions
|
|
142
|
+
* and its mock scenarios (one per endpoint, in the browser and on the
|
|
143
|
+
* server). Needs `data.write` and `dataServer()` in the HUD route.
|
|
144
|
+
*/
|
|
145
|
+
function DataPanel({ ctx }) {
|
|
146
|
+
const state = useDataState(ctx);
|
|
147
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
148
|
+
className: "data",
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsx("style", { children: DATA_CSS }),
|
|
151
|
+
state.status === "loading" && /* @__PURE__ */ jsx("p", {
|
|
152
|
+
className: "data-hint",
|
|
153
|
+
children: "Loading…"
|
|
154
|
+
}),
|
|
155
|
+
state.status === "failed" && /* @__PURE__ */ jsx("p", {
|
|
156
|
+
className: "data-result",
|
|
157
|
+
"data-ok": "false",
|
|
158
|
+
children: state.error
|
|
159
|
+
}),
|
|
160
|
+
state.status === "unavailable" && state.code === 404 && /* @__PURE__ */ jsxs("p", {
|
|
161
|
+
className: "data-hint",
|
|
162
|
+
children: [
|
|
163
|
+
"Role switch and flags need ",
|
|
164
|
+
/* @__PURE__ */ jsx("code", { children: "dataServer()" }),
|
|
165
|
+
" from",
|
|
166
|
+
" ",
|
|
167
|
+
/* @__PURE__ */ jsx("code", { children: "@hansenexus/hud/plugins/data/server" }),
|
|
168
|
+
" in the HUD route."
|
|
169
|
+
]
|
|
170
|
+
}),
|
|
171
|
+
state.status === "unavailable" && state.code === 403 && /* @__PURE__ */ jsxs("p", {
|
|
172
|
+
className: "data-hint",
|
|
173
|
+
children: [
|
|
174
|
+
"This tier denies ",
|
|
175
|
+
/* @__PURE__ */ jsx("code", { children: "data.write" }),
|
|
176
|
+
": no role switch, no flag overrides."
|
|
177
|
+
]
|
|
178
|
+
}),
|
|
179
|
+
state.status === "ready" && /* @__PURE__ */ jsx(Ready, {
|
|
180
|
+
ctx,
|
|
181
|
+
data: state.data
|
|
182
|
+
})
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function Ready({ ctx, data }) {
|
|
187
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
188
|
+
data.auth ? /* @__PURE__ */ jsx(Roles, {
|
|
189
|
+
ctx,
|
|
190
|
+
auth: data.auth
|
|
191
|
+
}) : /* @__PURE__ */ jsxs("section", {
|
|
192
|
+
className: "data-section",
|
|
193
|
+
"aria-label": "Role",
|
|
194
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
195
|
+
className: "data-heading",
|
|
196
|
+
children: "Signed in as"
|
|
197
|
+
}), /* @__PURE__ */ jsxs("p", {
|
|
198
|
+
className: "data-hint",
|
|
199
|
+
children: [
|
|
200
|
+
"No auth adapter: pass ",
|
|
201
|
+
/* @__PURE__ */ jsx("code", { children: "auth" }),
|
|
202
|
+
" to ",
|
|
203
|
+
/* @__PURE__ */ jsx("code", { children: "dataServer()" }),
|
|
204
|
+
" for a role switch."
|
|
205
|
+
]
|
|
206
|
+
})]
|
|
207
|
+
}),
|
|
208
|
+
data.flags ? /* @__PURE__ */ jsx(Flags, {
|
|
209
|
+
ctx,
|
|
210
|
+
definitions: data.flags.definitions,
|
|
211
|
+
overrides: data.flags.overrides
|
|
212
|
+
}) : /* @__PURE__ */ jsxs("section", {
|
|
213
|
+
className: "data-section",
|
|
214
|
+
"aria-label": "Feature flags",
|
|
215
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
216
|
+
className: "data-heading",
|
|
217
|
+
children: "Feature flags"
|
|
218
|
+
}), /* @__PURE__ */ jsxs("p", {
|
|
219
|
+
className: "data-hint",
|
|
220
|
+
children: [
|
|
221
|
+
"No flag source: pass ",
|
|
222
|
+
/* @__PURE__ */ jsx("code", { children: "flags" }),
|
|
223
|
+
" to ",
|
|
224
|
+
/* @__PURE__ */ jsx("code", { children: "dataServer()" }),
|
|
225
|
+
"."
|
|
226
|
+
]
|
|
227
|
+
})]
|
|
228
|
+
}),
|
|
229
|
+
data.seeds ? /* @__PURE__ */ jsx(Seeds, {
|
|
230
|
+
ctx,
|
|
231
|
+
definitions: data.seeds.definitions
|
|
232
|
+
}) : /* @__PURE__ */ jsxs("section", {
|
|
233
|
+
className: "data-section",
|
|
234
|
+
"aria-label": "Seeds",
|
|
235
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
236
|
+
className: "data-heading",
|
|
237
|
+
children: "Seeds"
|
|
238
|
+
}), /* @__PURE__ */ jsxs("p", {
|
|
239
|
+
className: "data-hint",
|
|
240
|
+
children: [
|
|
241
|
+
"No seeds: pass ",
|
|
242
|
+
/* @__PURE__ */ jsx("code", { children: "seeds" }),
|
|
243
|
+
" to ",
|
|
244
|
+
/* @__PURE__ */ jsx("code", { children: "dataServer()" }),
|
|
245
|
+
"."
|
|
246
|
+
]
|
|
247
|
+
})]
|
|
248
|
+
}),
|
|
249
|
+
data.mocks ? /* @__PURE__ */ jsx(Mocks, {
|
|
250
|
+
ctx,
|
|
251
|
+
scenarios: data.mocks.scenarios,
|
|
252
|
+
active: data.mocks.active,
|
|
253
|
+
node: data.mocks.node
|
|
254
|
+
}) : /* @__PURE__ */ jsxs("section", {
|
|
255
|
+
className: "data-section",
|
|
256
|
+
"aria-label": "Mock scenarios",
|
|
257
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
258
|
+
className: "data-heading",
|
|
259
|
+
children: "Mock scenarios"
|
|
260
|
+
}), /* @__PURE__ */ jsxs("p", {
|
|
261
|
+
className: "data-hint",
|
|
262
|
+
children: [
|
|
263
|
+
"No scenarios: pass ",
|
|
264
|
+
/* @__PURE__ */ jsx("code", { children: "mocks" }),
|
|
265
|
+
" to ",
|
|
266
|
+
/* @__PURE__ */ jsx("code", { children: "dataServer()" }),
|
|
267
|
+
"."
|
|
268
|
+
]
|
|
269
|
+
})]
|
|
270
|
+
})
|
|
271
|
+
] });
|
|
272
|
+
}
|
|
273
|
+
/** The seed's result on one line, the whole JSON behind a disclosure when it is long. */
|
|
274
|
+
function describeResult(result) {
|
|
275
|
+
if (result === null) return { text: "done" };
|
|
276
|
+
const text = JSON.stringify(result) ?? "done";
|
|
277
|
+
return text.length > 120 ? {
|
|
278
|
+
text: `${text.slice(0, 117)}…`,
|
|
279
|
+
detail: JSON.stringify(result, null, 2)
|
|
280
|
+
} : { text };
|
|
281
|
+
}
|
|
282
|
+
function Seeds({ ctx, definitions }) {
|
|
283
|
+
const [running, setRunning] = useState(null);
|
|
284
|
+
const [armed, setArmed] = useState(null);
|
|
285
|
+
const [outcomes, setOutcomes] = useState({});
|
|
286
|
+
async function run(seed) {
|
|
287
|
+
if (seed.danger && armed !== seed.id) {
|
|
288
|
+
setArmed(seed.id);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
setArmed(null);
|
|
292
|
+
setRunning(seed.id);
|
|
293
|
+
const started = Date.now();
|
|
294
|
+
try {
|
|
295
|
+
const response = await ctx.api(`/seeds/${encodeURIComponent(seed.id)}`, {
|
|
296
|
+
method: "POST",
|
|
297
|
+
headers: JSON_HEADERS
|
|
298
|
+
});
|
|
299
|
+
const { text, detail } = describeResult(response.result);
|
|
300
|
+
setOutcomes((all) => ({
|
|
301
|
+
...all,
|
|
302
|
+
[seed.id]: {
|
|
303
|
+
ok: true,
|
|
304
|
+
text: `ok · ${response.durationMs} ms · ${text}`,
|
|
305
|
+
...detail ? { detail } : {}
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
} catch (error) {
|
|
309
|
+
setOutcomes((all) => ({
|
|
310
|
+
...all,
|
|
311
|
+
[seed.id]: {
|
|
312
|
+
ok: false,
|
|
313
|
+
text: `failed · ${Date.now() - started} ms · ${errorMessage(error, "seed failed")}`
|
|
314
|
+
}
|
|
315
|
+
}));
|
|
316
|
+
} finally {
|
|
317
|
+
setRunning(null);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
321
|
+
className: "data-section",
|
|
322
|
+
"aria-label": "Seeds",
|
|
323
|
+
children: [
|
|
324
|
+
/* @__PURE__ */ jsx("div", {
|
|
325
|
+
className: "data-heading",
|
|
326
|
+
children: /* @__PURE__ */ jsx("span", { children: "Seeds" })
|
|
327
|
+
}),
|
|
328
|
+
definitions.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
329
|
+
className: "data-hint",
|
|
330
|
+
children: "No seeds are registered."
|
|
331
|
+
}),
|
|
332
|
+
/* @__PURE__ */ jsx("ul", {
|
|
333
|
+
className: "data-seeds",
|
|
334
|
+
children: definitions.map((seed) => {
|
|
335
|
+
const outcome = outcomes[seed.id];
|
|
336
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
337
|
+
className: "data-seed",
|
|
338
|
+
"data-seed-id": seed.id,
|
|
339
|
+
children: [
|
|
340
|
+
/* @__PURE__ */ jsxs("div", {
|
|
341
|
+
className: "data-row",
|
|
342
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
343
|
+
className: "data-grow",
|
|
344
|
+
children: [seed.label, seed.danger && /* @__PURE__ */ jsx("span", {
|
|
345
|
+
className: "data-badge",
|
|
346
|
+
"data-tone": "override",
|
|
347
|
+
children: "danger"
|
|
348
|
+
})]
|
|
349
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
350
|
+
type: "button",
|
|
351
|
+
className: "data-button",
|
|
352
|
+
"data-tone": armed === seed.id ? "danger" : void 0,
|
|
353
|
+
disabled: running !== null,
|
|
354
|
+
onClick: () => run(seed),
|
|
355
|
+
onBlur: () => {
|
|
356
|
+
if (armed === seed.id) setArmed(null);
|
|
357
|
+
},
|
|
358
|
+
children: running === seed.id ? "Running…" : armed === seed.id ? "Confirm" : "Run"
|
|
359
|
+
})]
|
|
360
|
+
}),
|
|
361
|
+
seed.description && /* @__PURE__ */ jsx("p", {
|
|
362
|
+
className: "data-hint",
|
|
363
|
+
children: seed.description
|
|
364
|
+
}),
|
|
365
|
+
outcome && /* @__PURE__ */ jsx("p", {
|
|
366
|
+
className: "data-result data-mono",
|
|
367
|
+
"data-ok": outcome.ok,
|
|
368
|
+
children: outcome.text
|
|
369
|
+
}),
|
|
370
|
+
outcome?.detail && /* @__PURE__ */ jsxs("details", {
|
|
371
|
+
className: "data-detail",
|
|
372
|
+
children: [/* @__PURE__ */ jsx("summary", { children: "result" }), /* @__PURE__ */ jsx("pre", { children: outcome.detail })]
|
|
373
|
+
})
|
|
374
|
+
]
|
|
375
|
+
}, seed.id);
|
|
376
|
+
})
|
|
377
|
+
})
|
|
378
|
+
]
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function statusTone(status) {
|
|
382
|
+
return status === "live" ? "active" : status === "failed" ? "poor" : "muted";
|
|
383
|
+
}
|
|
384
|
+
function Mocks({ ctx, scenarios, active, node }) {
|
|
385
|
+
const client = useMockClientStatus();
|
|
386
|
+
const [busy, setBusy] = useState(false);
|
|
387
|
+
const [result, setResult] = useState(null);
|
|
388
|
+
const endpoints = /* @__PURE__ */ new Map();
|
|
389
|
+
for (const scenario of scenarios) {
|
|
390
|
+
const list = endpoints.get(scenario.endpoint) ?? [];
|
|
391
|
+
list.push(scenario);
|
|
392
|
+
endpoints.set(scenario.endpoint, list);
|
|
393
|
+
}
|
|
394
|
+
const count = Object.keys(active).length;
|
|
395
|
+
async function write(path, method) {
|
|
396
|
+
setBusy(true);
|
|
397
|
+
setResult(null);
|
|
398
|
+
try {
|
|
399
|
+
const response = await ctx.api(path, {
|
|
400
|
+
method,
|
|
401
|
+
headers: JSON_HEADERS
|
|
402
|
+
});
|
|
403
|
+
applyMocks(response.active);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
setResult({
|
|
406
|
+
ok: false,
|
|
407
|
+
text: errorMessage(error, "scenario update failed")
|
|
408
|
+
});
|
|
409
|
+
} finally {
|
|
410
|
+
setBusy(false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const hints = [client.hint, node.hint].filter((hint) => Boolean(hint));
|
|
414
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
415
|
+
className: "data-section",
|
|
416
|
+
"aria-label": "Mock scenarios",
|
|
417
|
+
children: [
|
|
418
|
+
/* @__PURE__ */ jsxs("div", {
|
|
419
|
+
className: "data-heading",
|
|
420
|
+
children: [/* @__PURE__ */ jsxs("span", { children: ["Mock scenarios", count > 0 ? ` (${count} active)` : ""] }), /* @__PURE__ */ jsxs("span", {
|
|
421
|
+
className: "data-heading-actions",
|
|
422
|
+
children: [
|
|
423
|
+
/* @__PURE__ */ jsxs("span", {
|
|
424
|
+
className: "data-badge",
|
|
425
|
+
"data-tone": statusTone(client.status),
|
|
426
|
+
"data-mock-client": client.status,
|
|
427
|
+
children: ["client ", client.status]
|
|
428
|
+
}),
|
|
429
|
+
/* @__PURE__ */ jsxs("span", {
|
|
430
|
+
className: "data-badge",
|
|
431
|
+
"data-tone": statusTone(node.status),
|
|
432
|
+
"data-mock-node": node.status,
|
|
433
|
+
children: ["server ", node.status]
|
|
434
|
+
}),
|
|
435
|
+
count > 0 && /* @__PURE__ */ jsx("button", {
|
|
436
|
+
type: "button",
|
|
437
|
+
className: "data-button",
|
|
438
|
+
disabled: busy,
|
|
439
|
+
onClick: () => write("/mocks", "DELETE"),
|
|
440
|
+
children: "Reset all"
|
|
441
|
+
})
|
|
442
|
+
]
|
|
443
|
+
})]
|
|
444
|
+
}),
|
|
445
|
+
hints.map((hint) => /* @__PURE__ */ jsx("p", {
|
|
446
|
+
className: "data-hint",
|
|
447
|
+
"data-mock-hint": "",
|
|
448
|
+
children: hint
|
|
449
|
+
}, hint)),
|
|
450
|
+
endpoints.size === 0 && /* @__PURE__ */ jsx("p", {
|
|
451
|
+
className: "data-hint",
|
|
452
|
+
children: "No scenarios are registered."
|
|
453
|
+
}),
|
|
454
|
+
/* @__PURE__ */ jsx("ul", {
|
|
455
|
+
className: "data-endpoints",
|
|
456
|
+
children: [...endpoints.entries()].map(([endpoint, alternatives]) => {
|
|
457
|
+
const current = active[endpoint];
|
|
458
|
+
const chosen = alternatives.find((scenario) => scenario.id === current);
|
|
459
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
460
|
+
className: "data-endpoint",
|
|
461
|
+
"data-endpoint": endpoint,
|
|
462
|
+
"data-active": current ?? "",
|
|
463
|
+
children: [
|
|
464
|
+
/* @__PURE__ */ jsx("div", {
|
|
465
|
+
className: "data-row",
|
|
466
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
467
|
+
className: "data-grow data-mono",
|
|
468
|
+
children: endpoint
|
|
469
|
+
})
|
|
470
|
+
}),
|
|
471
|
+
/* @__PURE__ */ jsx("div", {
|
|
472
|
+
className: "data-row",
|
|
473
|
+
children: /* @__PURE__ */ jsxs("fieldset", {
|
|
474
|
+
className: "data-segments",
|
|
475
|
+
"aria-label": `${endpoint} scenario`,
|
|
476
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
477
|
+
type: "button",
|
|
478
|
+
className: "data-segment",
|
|
479
|
+
"aria-pressed": current === void 0,
|
|
480
|
+
disabled: busy,
|
|
481
|
+
onClick: () => {
|
|
482
|
+
if (current) write(`/mocks/${encodeURIComponent(current)}`, "DELETE");
|
|
483
|
+
},
|
|
484
|
+
children: "real"
|
|
485
|
+
}), alternatives.map((scenario) => /* @__PURE__ */ jsx("button", {
|
|
486
|
+
type: "button",
|
|
487
|
+
className: "data-segment",
|
|
488
|
+
"data-scenario-id": scenario.id,
|
|
489
|
+
"aria-pressed": current === scenario.id,
|
|
490
|
+
disabled: busy,
|
|
491
|
+
title: scenario.description,
|
|
492
|
+
onClick: () => {
|
|
493
|
+
if (current !== scenario.id) write(`/mocks/${encodeURIComponent(scenario.id)}`, "PUT");
|
|
494
|
+
},
|
|
495
|
+
children: scenario.label
|
|
496
|
+
}, scenario.id))]
|
|
497
|
+
})
|
|
498
|
+
}),
|
|
499
|
+
chosen?.description && /* @__PURE__ */ jsx("p", {
|
|
500
|
+
className: "data-hint",
|
|
501
|
+
children: chosen.description
|
|
502
|
+
})
|
|
503
|
+
]
|
|
504
|
+
}, endpoint);
|
|
505
|
+
})
|
|
506
|
+
}),
|
|
507
|
+
result && /* @__PURE__ */ jsx("p", {
|
|
508
|
+
className: "data-result",
|
|
509
|
+
"data-ok": result.ok,
|
|
510
|
+
children: result.text
|
|
511
|
+
})
|
|
512
|
+
]
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function Roles({ ctx, auth }) {
|
|
516
|
+
const [busy, setBusy] = useState(false);
|
|
517
|
+
const [result, setResult] = useState(null);
|
|
518
|
+
async function switchTo(user) {
|
|
519
|
+
setBusy(true);
|
|
520
|
+
setResult(null);
|
|
521
|
+
try {
|
|
522
|
+
const body = user ? { id: user.id } : void 0;
|
|
523
|
+
applyStorage((await ctx.api("/role", {
|
|
524
|
+
method: user ? "POST" : "DELETE",
|
|
525
|
+
headers: JSON_HEADERS,
|
|
526
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
527
|
+
})).storage);
|
|
528
|
+
setResult({
|
|
529
|
+
ok: true,
|
|
530
|
+
text: user ? `signed in as ${user.label}, reloading…` : "signed out, reloading…"
|
|
531
|
+
});
|
|
532
|
+
location.reload();
|
|
533
|
+
} catch (error) {
|
|
534
|
+
setResult({
|
|
535
|
+
ok: false,
|
|
536
|
+
text: errorMessage(error, "switch failed")
|
|
537
|
+
});
|
|
538
|
+
setBusy(false);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
542
|
+
className: "data-section",
|
|
543
|
+
"aria-label": "Role",
|
|
544
|
+
children: [
|
|
545
|
+
/* @__PURE__ */ jsxs("div", {
|
|
546
|
+
className: "data-heading",
|
|
547
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Signed in as" }), /* @__PURE__ */ jsx("span", {
|
|
548
|
+
className: "data-muted data-mono",
|
|
549
|
+
children: auth.label
|
|
550
|
+
})]
|
|
551
|
+
}),
|
|
552
|
+
/* @__PURE__ */ jsxs("div", {
|
|
553
|
+
className: "data-row",
|
|
554
|
+
children: [
|
|
555
|
+
/* @__PURE__ */ jsx("span", {
|
|
556
|
+
className: "data-grow",
|
|
557
|
+
"data-current-user": auth.current?.id ?? "",
|
|
558
|
+
children: auth.current ? auth.current.label : /* @__PURE__ */ jsx("span", {
|
|
559
|
+
className: "data-muted",
|
|
560
|
+
children: "anonymous"
|
|
561
|
+
})
|
|
562
|
+
}),
|
|
563
|
+
auth.current?.role && /* @__PURE__ */ jsx("span", {
|
|
564
|
+
className: "data-badge",
|
|
565
|
+
children: auth.current.role
|
|
566
|
+
}),
|
|
567
|
+
auth.current && /* @__PURE__ */ jsx("button", {
|
|
568
|
+
type: "button",
|
|
569
|
+
className: "data-button",
|
|
570
|
+
disabled: busy,
|
|
571
|
+
onClick: () => switchTo(null),
|
|
572
|
+
children: "Sign out"
|
|
573
|
+
})
|
|
574
|
+
]
|
|
575
|
+
}),
|
|
576
|
+
auth.users.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
577
|
+
className: "data-hint",
|
|
578
|
+
children: "The adapter lists no fixture users."
|
|
579
|
+
}),
|
|
580
|
+
/* @__PURE__ */ jsx("ul", {
|
|
581
|
+
className: "data-users",
|
|
582
|
+
children: auth.users.map((user) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", {
|
|
583
|
+
type: "button",
|
|
584
|
+
className: "data-user",
|
|
585
|
+
"data-user-id": user.id,
|
|
586
|
+
"aria-pressed": auth.current?.id === user.id,
|
|
587
|
+
disabled: busy || auth.current?.id === user.id,
|
|
588
|
+
onClick: () => switchTo(user),
|
|
589
|
+
children: [
|
|
590
|
+
/* @__PURE__ */ jsx("span", {
|
|
591
|
+
className: "data-grow",
|
|
592
|
+
children: user.label
|
|
593
|
+
}),
|
|
594
|
+
user.role && /* @__PURE__ */ jsx("span", {
|
|
595
|
+
className: "data-badge",
|
|
596
|
+
children: user.role
|
|
597
|
+
}),
|
|
598
|
+
user.email && /* @__PURE__ */ jsx("span", {
|
|
599
|
+
className: "data-muted data-mono",
|
|
600
|
+
children: user.email
|
|
601
|
+
})
|
|
602
|
+
]
|
|
603
|
+
}) }, user.id))
|
|
604
|
+
}),
|
|
605
|
+
result && /* @__PURE__ */ jsx("p", {
|
|
606
|
+
className: "data-result",
|
|
607
|
+
"data-ok": result.ok,
|
|
608
|
+
children: result.text
|
|
609
|
+
})
|
|
610
|
+
]
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function formatValue(value) {
|
|
614
|
+
if (value === void 0) return "unset";
|
|
615
|
+
return typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
616
|
+
}
|
|
617
|
+
function Flags({ ctx, definitions, overrides }) {
|
|
618
|
+
const [busy, setBusy] = useState(false);
|
|
619
|
+
const [result, setResult] = useState(null);
|
|
620
|
+
const [dirty, setDirty] = useState(false);
|
|
621
|
+
const byKey = new Map(overrides.map((override) => [override.key, override]));
|
|
622
|
+
async function write(path, init) {
|
|
623
|
+
setBusy(true);
|
|
624
|
+
setResult(null);
|
|
625
|
+
try {
|
|
626
|
+
const response = await ctx.api(path, {
|
|
627
|
+
...init,
|
|
628
|
+
headers: JSON_HEADERS
|
|
629
|
+
});
|
|
630
|
+
applyOverrides(response.overrides);
|
|
631
|
+
setDirty(true);
|
|
632
|
+
} catch (error) {
|
|
633
|
+
setResult({
|
|
634
|
+
ok: false,
|
|
635
|
+
text: errorMessage(error, "flag update failed")
|
|
636
|
+
});
|
|
637
|
+
} finally {
|
|
638
|
+
setBusy(false);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const setOverride = (key, value, scope) => {
|
|
642
|
+
const body = {
|
|
643
|
+
value,
|
|
644
|
+
scope
|
|
645
|
+
};
|
|
646
|
+
return write(`/flags/${encodeURIComponent(key)}`, {
|
|
647
|
+
method: "PUT",
|
|
648
|
+
body: JSON.stringify(body)
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
const reset = (key) => write(`/flags/${encodeURIComponent(key)}`, { method: "DELETE" });
|
|
652
|
+
const resetAll = () => write("/flags", { method: "DELETE" });
|
|
653
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
654
|
+
className: "data-section",
|
|
655
|
+
"aria-label": "Feature flags",
|
|
656
|
+
children: [
|
|
657
|
+
/* @__PURE__ */ jsxs("div", {
|
|
658
|
+
className: "data-heading",
|
|
659
|
+
children: [/* @__PURE__ */ jsxs("span", { children: ["Feature flags", overrides.length > 0 ? ` (${overrides.length} overridden)` : ""] }), /* @__PURE__ */ jsxs("span", {
|
|
660
|
+
className: "data-heading-actions",
|
|
661
|
+
children: [overrides.length > 0 && /* @__PURE__ */ jsx("button", {
|
|
662
|
+
type: "button",
|
|
663
|
+
className: "data-button",
|
|
664
|
+
disabled: busy,
|
|
665
|
+
onClick: resetAll,
|
|
666
|
+
children: "Reset all"
|
|
667
|
+
}), dirty && /* @__PURE__ */ jsx("button", {
|
|
668
|
+
type: "button",
|
|
669
|
+
className: "data-button",
|
|
670
|
+
onClick: () => {
|
|
671
|
+
syncLocalOverrides(overrides);
|
|
672
|
+
location.reload();
|
|
673
|
+
},
|
|
674
|
+
children: "Reload"
|
|
675
|
+
})]
|
|
676
|
+
})]
|
|
677
|
+
}),
|
|
678
|
+
definitions.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
679
|
+
className: "data-hint",
|
|
680
|
+
children: "The flag source lists no flags."
|
|
681
|
+
}),
|
|
682
|
+
/* @__PURE__ */ jsx("ul", {
|
|
683
|
+
className: "data-flags",
|
|
684
|
+
children: definitions.map((flag) => /* @__PURE__ */ jsx(FlagRow, {
|
|
685
|
+
flag,
|
|
686
|
+
override: byKey.get(flag.key),
|
|
687
|
+
busy,
|
|
688
|
+
onSet: setOverride,
|
|
689
|
+
onReset: reset
|
|
690
|
+
}, flag.key))
|
|
691
|
+
}),
|
|
692
|
+
dirty && !result && /* @__PURE__ */ jsx("p", {
|
|
693
|
+
className: "data-hint",
|
|
694
|
+
children: "Overrides apply on the next request; reload to see them."
|
|
695
|
+
}),
|
|
696
|
+
result && /* @__PURE__ */ jsx("p", {
|
|
697
|
+
className: "data-result",
|
|
698
|
+
"data-ok": result.ok,
|
|
699
|
+
children: result.text
|
|
700
|
+
})
|
|
701
|
+
]
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function FlagRow({ flag, override, busy, onSet, onReset }) {
|
|
705
|
+
const type = flag.type ?? (typeof flag.value === "boolean" || flag.value === void 0 ? "boolean" : typeof flag.value === "number" ? "number" : "string");
|
|
706
|
+
const [scope, setScope] = useState(override?.scope ?? flag.scope ?? "cookie");
|
|
707
|
+
const [draft, setDraft] = useState(override && typeof override.value !== "boolean" ? String(override.value) : "");
|
|
708
|
+
const submitDraft = () => {
|
|
709
|
+
if (type === "number") {
|
|
710
|
+
const parsed = Number(draft);
|
|
711
|
+
if (draft.trim() === "" || !Number.isFinite(parsed)) return;
|
|
712
|
+
return onSet(flag.key, parsed, scope);
|
|
713
|
+
}
|
|
714
|
+
return onSet(flag.key, draft, scope);
|
|
715
|
+
};
|
|
716
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
717
|
+
className: "data-flag",
|
|
718
|
+
"data-flag-key": flag.key,
|
|
719
|
+
"data-overridden": override ? "true" : "false",
|
|
720
|
+
children: [
|
|
721
|
+
/* @__PURE__ */ jsxs("div", {
|
|
722
|
+
className: "data-row",
|
|
723
|
+
children: [
|
|
724
|
+
/* @__PURE__ */ jsxs("span", {
|
|
725
|
+
className: "data-grow",
|
|
726
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
727
|
+
className: "data-mono",
|
|
728
|
+
children: flag.key
|
|
729
|
+
}), flag.label && /* @__PURE__ */ jsxs("span", {
|
|
730
|
+
className: "data-muted",
|
|
731
|
+
children: [" · ", flag.label]
|
|
732
|
+
})]
|
|
733
|
+
}),
|
|
734
|
+
/* @__PURE__ */ jsx("span", {
|
|
735
|
+
className: "data-badge",
|
|
736
|
+
title: "the source's value",
|
|
737
|
+
children: formatValue(flag.value)
|
|
738
|
+
}),
|
|
739
|
+
override && /* @__PURE__ */ jsxs("span", {
|
|
740
|
+
className: "data-badge",
|
|
741
|
+
"data-tone": "override",
|
|
742
|
+
title: `override, ${override.scope} scope`,
|
|
743
|
+
children: [
|
|
744
|
+
formatValue(override.value),
|
|
745
|
+
" · ",
|
|
746
|
+
override.scope
|
|
747
|
+
]
|
|
748
|
+
})
|
|
749
|
+
]
|
|
750
|
+
}),
|
|
751
|
+
flag.description && /* @__PURE__ */ jsx("p", {
|
|
752
|
+
className: "data-hint",
|
|
753
|
+
children: flag.description
|
|
754
|
+
}),
|
|
755
|
+
/* @__PURE__ */ jsxs("div", {
|
|
756
|
+
className: "data-row",
|
|
757
|
+
children: [
|
|
758
|
+
type === "boolean" ? /* @__PURE__ */ jsxs("fieldset", {
|
|
759
|
+
className: "data-segments",
|
|
760
|
+
"aria-label": `${flag.key} override`,
|
|
761
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
762
|
+
type: "button",
|
|
763
|
+
className: "data-segment",
|
|
764
|
+
"aria-pressed": override?.value === true,
|
|
765
|
+
disabled: busy,
|
|
766
|
+
onClick: () => onSet(flag.key, true, scope),
|
|
767
|
+
children: "on"
|
|
768
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
769
|
+
type: "button",
|
|
770
|
+
className: "data-segment",
|
|
771
|
+
"aria-pressed": override?.value === false,
|
|
772
|
+
disabled: busy,
|
|
773
|
+
onClick: () => onSet(flag.key, false, scope),
|
|
774
|
+
children: "off"
|
|
775
|
+
})]
|
|
776
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
777
|
+
className: "data-field",
|
|
778
|
+
"aria-label": `${flag.key} value`,
|
|
779
|
+
inputMode: type === "number" ? "decimal" : "text",
|
|
780
|
+
value: draft,
|
|
781
|
+
placeholder: formatValue(flag.value),
|
|
782
|
+
onChange: (event) => setDraft(event.target.value),
|
|
783
|
+
onKeyDown: (event) => {
|
|
784
|
+
if (event.key === "Enter") submitDraft();
|
|
785
|
+
}
|
|
786
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
787
|
+
type: "button",
|
|
788
|
+
className: "data-button",
|
|
789
|
+
disabled: busy,
|
|
790
|
+
onClick: submitDraft,
|
|
791
|
+
children: "Set"
|
|
792
|
+
})] }),
|
|
793
|
+
/* @__PURE__ */ jsx("select", {
|
|
794
|
+
className: "data-select",
|
|
795
|
+
"aria-label": `${flag.key} scope`,
|
|
796
|
+
value: scope,
|
|
797
|
+
onChange: (event) => setScope(event.target.value),
|
|
798
|
+
children: HUD_FLAG_SCOPES.map((option) => /* @__PURE__ */ jsx("option", {
|
|
799
|
+
value: option,
|
|
800
|
+
children: option
|
|
801
|
+
}, option))
|
|
802
|
+
}),
|
|
803
|
+
override && /* @__PURE__ */ jsx("button", {
|
|
804
|
+
type: "button",
|
|
805
|
+
className: "data-button",
|
|
806
|
+
"aria-label": `Reset ${flag.key}`,
|
|
807
|
+
disabled: busy,
|
|
808
|
+
onClick: () => onReset(flag.key),
|
|
809
|
+
children: "Reset"
|
|
810
|
+
})
|
|
811
|
+
]
|
|
812
|
+
})
|
|
813
|
+
]
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
//#endregion
|
|
817
|
+
export { DataPanel as default };
|