dn-react-router-toolkit 0.3.3 → 0.3.4

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.
@@ -0,0 +1,3 @@
1
+ declare function env(key: string): string;
2
+
3
+ export { env };
@@ -0,0 +1,3 @@
1
+ declare function env(key: string): string;
2
+
3
+ export { env };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/client/env.ts
21
+ var env_exports = {};
22
+ __export(env_exports, {
23
+ env: () => env
24
+ });
25
+ module.exports = __toCommonJS(env_exports);
26
+ function env(key) {
27
+ if (typeof window === "undefined") {
28
+ return process.env[key] || "";
29
+ }
30
+ return window.ENV?.[key] || "";
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ env
35
+ });
@@ -0,0 +1,10 @@
1
+ // src/client/env.ts
2
+ function env(key) {
3
+ if (typeof window === "undefined") {
4
+ return process.env[key] || "";
5
+ }
6
+ return window.ENV?.[key] || "";
7
+ }
8
+ export {
9
+ env
10
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ declare function EnvLoader({ dataKey }: {
4
+ dataKey?: string;
5
+ }): React.JSX.Element | undefined;
6
+
7
+ export { EnvLoader };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ declare function EnvLoader({ dataKey }: {
4
+ dataKey?: string;
5
+ }): React.JSX.Element | undefined;
6
+
7
+ export { EnvLoader };
@@ -27,28 +27,29 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/client/client_env.tsx
31
- var client_env_exports = {};
32
- __export(client_env_exports, {
33
- ClientEnv: () => ClientEnv
30
+ // src/client/env_loader.tsx
31
+ var env_loader_exports = {};
32
+ __export(env_loader_exports, {
33
+ EnvLoader: () => EnvLoader
34
34
  });
35
- module.exports = __toCommonJS(client_env_exports);
35
+ module.exports = __toCommonJS(env_loader_exports);
36
36
  var import_react = __toESM(require("react"));
37
37
  var import_react_router = require("react-router");
38
- function ClientEnv({ dataKey = "ENV" }) {
38
+ function EnvLoader({ dataKey = "ENV" }) {
39
39
  const data = (0, import_react_router.useRouteLoaderData)("root");
40
- return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, data && /* @__PURE__ */ import_react.default.createElement(
40
+ if (!data) {
41
+ return;
42
+ }
43
+ return /* @__PURE__ */ import_react.default.createElement(
41
44
  "script",
42
45
  {
43
46
  dangerouslySetInnerHTML: {
44
- __html: `window.process = ${JSON.stringify({
45
- env: data?.[dataKey]
46
- })}`
47
+ __html: `window.ENV = ${JSON.stringify(data[dataKey])};`
47
48
  }
48
49
  }
49
- ));
50
+ );
50
51
  }
51
52
  // Annotate the CommonJS export names for ESM import in node:
52
53
  0 && (module.exports = {
53
- ClientEnv
54
+ EnvLoader
54
55
  });
@@ -0,0 +1,20 @@
1
+ // src/client/env_loader.tsx
2
+ import React from "react";
3
+ import { useRouteLoaderData } from "react-router";
4
+ function EnvLoader({ dataKey = "ENV" }) {
5
+ const data = useRouteLoaderData("root");
6
+ if (!data) {
7
+ return;
8
+ }
9
+ return /* @__PURE__ */ React.createElement(
10
+ "script",
11
+ {
12
+ dangerouslySetInnerHTML: {
13
+ __html: `window.ENV = ${JSON.stringify(data[dataKey])};`
14
+ }
15
+ }
16
+ );
17
+ }
18
+ export {
19
+ EnvLoader
20
+ };
@@ -1,3 +1,4 @@
1
- export { ClientEnv } from './client_env.mjs';
1
+ export { env } from './env.mjs';
2
+ export { EnvLoader } from './env_loader.mjs';
2
3
  export { useUserAgent } from './use_user_agent.mjs';
3
4
  import 'react';
@@ -1,3 +1,4 @@
1
- export { ClientEnv } from './client_env.js';
1
+ export { env } from './env.js';
2
+ export { EnvLoader } from './env_loader.js';
2
3
  export { useUserAgent } from './use_user_agent.js';
3
4
  import 'react';
@@ -30,26 +30,36 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/client/index.ts
31
31
  var client_exports = {};
32
32
  __export(client_exports, {
33
- ClientEnv: () => ClientEnv,
33
+ EnvLoader: () => EnvLoader,
34
+ env: () => env,
34
35
  useUserAgent: () => useUserAgent
35
36
  });
36
37
  module.exports = __toCommonJS(client_exports);
37
38
 
38
- // src/client/client_env.tsx
39
+ // src/client/env.ts
40
+ function env(key) {
41
+ if (typeof window === "undefined") {
42
+ return process.env[key] || "";
43
+ }
44
+ return window.ENV?.[key] || "";
45
+ }
46
+
47
+ // src/client/env_loader.tsx
39
48
  var import_react = __toESM(require("react"));
40
49
  var import_react_router = require("react-router");
41
- function ClientEnv({ dataKey = "ENV" }) {
50
+ function EnvLoader({ dataKey = "ENV" }) {
42
51
  const data = (0, import_react_router.useRouteLoaderData)("root");
43
- return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, data && /* @__PURE__ */ import_react.default.createElement(
52
+ if (!data) {
53
+ return;
54
+ }
55
+ return /* @__PURE__ */ import_react.default.createElement(
44
56
  "script",
45
57
  {
46
58
  dangerouslySetInnerHTML: {
47
- __html: `window.process = ${JSON.stringify({
48
- env: data?.[dataKey]
49
- })}`
59
+ __html: `window.ENV = ${JSON.stringify(data[dataKey])};`
50
60
  }
51
61
  }
52
- ));
62
+ );
53
63
  }
54
64
 
55
65
  // src/client/use_user_agent.tsx
@@ -64,6 +74,7 @@ function useUserAgent() {
64
74
  }
65
75
  // Annotate the CommonJS export names for ESM import in node:
66
76
  0 && (module.exports = {
67
- ClientEnv,
77
+ EnvLoader,
78
+ env,
68
79
  useUserAgent
69
80
  });
@@ -1,18 +1,27 @@
1
- // src/client/client_env.tsx
1
+ // src/client/env.ts
2
+ function env(key) {
3
+ if (typeof window === "undefined") {
4
+ return process.env[key] || "";
5
+ }
6
+ return window.ENV?.[key] || "";
7
+ }
8
+
9
+ // src/client/env_loader.tsx
2
10
  import React from "react";
3
11
  import { useRouteLoaderData } from "react-router";
4
- function ClientEnv({ dataKey = "ENV" }) {
12
+ function EnvLoader({ dataKey = "ENV" }) {
5
13
  const data = useRouteLoaderData("root");
6
- return /* @__PURE__ */ React.createElement(React.Fragment, null, data && /* @__PURE__ */ React.createElement(
14
+ if (!data) {
15
+ return;
16
+ }
17
+ return /* @__PURE__ */ React.createElement(
7
18
  "script",
8
19
  {
9
20
  dangerouslySetInnerHTML: {
10
- __html: `window.process = ${JSON.stringify({
11
- env: data?.[dataKey]
12
- })}`
21
+ __html: `window.ENV = ${JSON.stringify(data[dataKey])};`
13
22
  }
14
23
  }
15
- ));
24
+ );
16
25
  }
17
26
 
18
27
  // src/client/use_user_agent.tsx
@@ -26,6 +35,7 @@ function useUserAgent() {
26
35
  return { userAgent, isMobile, isTablet, isDesktop };
27
36
  }
28
37
  export {
29
- ClientEnv,
38
+ EnvLoader,
39
+ env,
30
40
  useUserAgent
31
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-router-toolkit",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- declare function ClientEnv({ dataKey }: {
4
- dataKey?: string;
5
- }): React.JSX.Element;
6
-
7
- export { ClientEnv };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- declare function ClientEnv({ dataKey }: {
4
- dataKey?: string;
5
- }): React.JSX.Element;
6
-
7
- export { ClientEnv };
@@ -1,19 +0,0 @@
1
- // src/client/client_env.tsx
2
- import React from "react";
3
- import { useRouteLoaderData } from "react-router";
4
- function ClientEnv({ dataKey = "ENV" }) {
5
- const data = useRouteLoaderData("root");
6
- return /* @__PURE__ */ React.createElement(React.Fragment, null, data && /* @__PURE__ */ React.createElement(
7
- "script",
8
- {
9
- dangerouslySetInnerHTML: {
10
- __html: `window.process = ${JSON.stringify({
11
- env: data?.[dataKey]
12
- })}`
13
- }
14
- }
15
- ));
16
- }
17
- export {
18
- ClientEnv
19
- };