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