@nice-code/state 0.12.0 → 0.14.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.
|
@@ -208,6 +208,44 @@ const DEVTOOL_JSON_PUNCTUATION = "#475569";
|
|
|
208
208
|
const MONO_FONT = "ui-monospace, 'Cascadia Code', 'Source Code Pro', monospace";
|
|
209
209
|
const SANS_FONT = "ui-sans-serif, system-ui, sans-serif";
|
|
210
210
|
//#endregion
|
|
211
|
+
//#region ../nice-devtools-shared/src/env.ts
|
|
212
|
+
function readViteEnv() {
|
|
213
|
+
try {
|
|
214
|
+
return import.meta.env;
|
|
215
|
+
} catch {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function readNodeEnv() {
|
|
220
|
+
try {
|
|
221
|
+
return process.env.NODE_ENV;
|
|
222
|
+
} catch {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Whether the devtools should be active.
|
|
228
|
+
*
|
|
229
|
+
* Detection order: Vite's `import.meta.env`, then `process.env.NODE_ENV`, then —
|
|
230
|
+
* if neither is resolvable (e.g. unbundled browser ESM) — default to enabled so
|
|
231
|
+
* the panel never silently vanishes. Real production builds always resolve one
|
|
232
|
+
* of the first two and correctly get `false`.
|
|
233
|
+
*
|
|
234
|
+
* `forceEnable` short-circuits to `true` for consumers who want the panel in
|
|
235
|
+
* production builds as well.
|
|
236
|
+
*/
|
|
237
|
+
function isDevtoolsEnabled(forceEnable) {
|
|
238
|
+
if (forceEnable === true) return true;
|
|
239
|
+
const viteEnv = readViteEnv();
|
|
240
|
+
if (viteEnv != null) {
|
|
241
|
+
if (typeof viteEnv.DEV === "boolean") return viteEnv.DEV;
|
|
242
|
+
if (typeof viteEnv.MODE === "string") return viteEnv.MODE !== "production";
|
|
243
|
+
}
|
|
244
|
+
const nodeEnv = readNodeEnv();
|
|
245
|
+
if (nodeEnv != null) return nodeEnv !== "production";
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
211
249
|
//#region ../nice-devtools-shared/src/format.ts
|
|
212
250
|
/** Pretty-print any value to JSON, degrading gracefully for cyclic / non-JSON values. */
|
|
213
251
|
function safeStringify(value, indent = 2) {
|
|
@@ -2507,7 +2545,7 @@ const EMPTY_SNAPSHOT = {
|
|
|
2507
2545
|
paused: false
|
|
2508
2546
|
};
|
|
2509
2547
|
function NiceStateDevtools({ forceEnable, ...props }) {
|
|
2510
|
-
if (!forceEnable
|
|
2548
|
+
if (!isDevtoolsEnabled(forceEnable)) return null;
|
|
2511
2549
|
return /* @__PURE__ */ jsx(NiceStateDevtools_Panel, { ...props });
|
|
2512
2550
|
}
|
|
2513
2551
|
function NiceStateDevtools_Panel({ core, position: defaultPosition = "dock-right", initialOpen = false }) {
|