@teo-garcia/react-shared 0.1.9 → 1.0.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.
- package/README.md +8 -11
- package/dist/components/error-boundary/error-boundary.d.ts.map +1 -1
- package/dist/components/error-boundary/error-boundary.js +1 -1
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -5
- package/dist/hooks/index.d.ts +6 -5
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +6 -4
- package/dist/hooks/use-debounce.d.ts +2 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-debounce.js +9 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
- package/dist/hooks/use-local-storage.d.ts +2 -0
- package/dist/hooks/use-local-storage.d.ts.map +1 -0
- package/dist/hooks/use-local-storage.js +37 -0
- package/dist/hooks/use-media-query.d.ts +2 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +18 -0
- package/dist/hooks/use-on-click-outside.d.ts +3 -0
- package/dist/hooks/use-on-click-outside.d.ts.map +1 -0
- package/dist/hooks/use-on-click-outside.js +17 -0
- package/dist/hooks/use-previous.d.ts +2 -0
- package/dist/hooks/use-previous.d.ts.map +1 -0
- package/dist/hooks/use-previous.js +8 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/test-utils/index.d.ts +14 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +22 -0
- package/dist/types.d.ts +0 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +5 -0
- package/dist/utils/index.d.ts +1 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -5
- package/package.json +60 -45
- package/dist/adapters/environment/index.d.ts +0 -6
- package/dist/adapters/environment/index.d.ts.map +0 -1
- package/dist/adapters/environment/index.js +0 -5
- package/dist/adapters/environment/next.d.ts +0 -17
- package/dist/adapters/environment/next.d.ts.map +0 -1
- package/dist/adapters/environment/next.js +0 -20
- package/dist/adapters/environment/vite.d.ts +0 -17
- package/dist/adapters/environment/vite.d.ts.map +0 -1
- package/dist/adapters/environment/vite.js +0 -20
- package/dist/adapters/index.d.ts +0 -9
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -8
- package/dist/adapters/theme/custom.d.ts +0 -32
- package/dist/adapters/theme/custom.d.ts.map +0 -1
- package/dist/adapters/theme/custom.js +0 -26
- package/dist/adapters/theme/index.d.ts +0 -6
- package/dist/adapters/theme/index.d.ts.map +0 -1
- package/dist/adapters/theme/index.js +0 -5
- package/dist/adapters/theme/next-themes.d.ts +0 -18
- package/dist/adapters/theme/next-themes.d.ts.map +0 -1
- package/dist/adapters/theme/next-themes.js +0 -23
- package/dist/components/theme-switch/index.d.ts +0 -3
- package/dist/components/theme-switch/index.d.ts.map +0 -1
- package/dist/components/theme-switch/index.js +0 -1
- package/dist/components/theme-switch/theme-switch.d.ts +0 -36
- package/dist/components/theme-switch/theme-switch.d.ts.map +0 -1
- package/dist/components/theme-switch/theme-switch.js +0 -74
- package/dist/components/viewport-info/index.d.ts +0 -3
- package/dist/components/viewport-info/index.d.ts.map +0 -1
- package/dist/components/viewport-info/index.js +0 -1
- package/dist/components/viewport-info/viewport-info.d.ts +0 -40
- package/dist/components/viewport-info/viewport-info.d.ts.map +0 -1
- package/dist/components/viewport-info/viewport-info.js +0 -69
- package/dist/hooks/use-healthcheck.d.ts +0 -42
- package/dist/hooks/use-healthcheck.d.ts.map +0 -1
- package/dist/hooks/use-healthcheck.js +0 -53
- package/dist/utils/environment.d.ts +0 -71
- package/dist/utils/environment.d.ts.map +0 -1
- package/dist/utils/environment.js +0 -86
- package/dist/utils/msw.d.ts +0 -54
- package/dist/utils/msw.d.ts.map +0 -1
- package/dist/utils/msw.js +0 -62
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Environment detection utilities
|
|
3
|
-
*
|
|
4
|
-
* These utilities help detect the runtime environment (development, production, server, client).
|
|
5
|
-
* They work across different frameworks by checking both process.env and import.meta.env.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Check if running in development mode
|
|
9
|
-
* Works with both Next.js (process.env) and Vite (import.meta.env)
|
|
10
|
-
*
|
|
11
|
-
* @returns true if in development mode
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { isDevelopment } from '@teo-garcia/react-shared/utils'
|
|
16
|
-
*
|
|
17
|
-
* if (isDevelopment()) {
|
|
18
|
-
* console.log('Running in dev mode')
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const isDevelopment: () => boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Check if running in production mode
|
|
25
|
-
* Works with both Next.js (process.env) and Vite (import.meta.env)
|
|
26
|
-
*
|
|
27
|
-
* @returns true if in production mode
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* import { isProduction } from '@teo-garcia/react-shared/utils'
|
|
32
|
-
*
|
|
33
|
-
* if (isProduction()) {
|
|
34
|
-
* // Enable analytics
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare const isProduction: () => boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Check if code is running on the server (SSR)
|
|
41
|
-
* Works by detecting the absence of window object
|
|
42
|
-
*
|
|
43
|
-
* @returns true if running on server
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```tsx
|
|
47
|
-
* import { isServer } from '@teo-garcia/react-shared/utils'
|
|
48
|
-
*
|
|
49
|
-
* if (isServer()) {
|
|
50
|
-
* // Server-only code
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare const isServer: () => boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Check if code is running on the client (browser)
|
|
57
|
-
* Works by detecting the presence of window object
|
|
58
|
-
*
|
|
59
|
-
* @returns true if running on client
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```tsx
|
|
63
|
-
* import { isClient } from '@teo-garcia/react-shared/utils'
|
|
64
|
-
*
|
|
65
|
-
* if (isClient()) {
|
|
66
|
-
* // Client-only code like localStorage access
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export declare const isClient: () => boolean;
|
|
71
|
-
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,QAAO,OAYhC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,QAAO,OAE/B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Environment detection utilities
|
|
3
|
-
*
|
|
4
|
-
* These utilities help detect the runtime environment (development, production, server, client).
|
|
5
|
-
* They work across different frameworks by checking both process.env and import.meta.env.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Check if running in development mode
|
|
9
|
-
* Works with both Next.js (process.env) and Vite (import.meta.env)
|
|
10
|
-
*
|
|
11
|
-
* @returns true if in development mode
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { isDevelopment } from '@teo-garcia/react-shared/utils'
|
|
16
|
-
*
|
|
17
|
-
* if (isDevelopment()) {
|
|
18
|
-
* console.log('Running in dev mode')
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const isDevelopment = () => {
|
|
23
|
-
// Check process.env first (Next.js, Node.js)
|
|
24
|
-
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
// Check import.meta.env (Vite, modern bundlers)
|
|
28
|
-
if (typeof import.meta !== 'undefined' && import.meta.env?.DEV === true) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Check if running in production mode
|
|
35
|
-
* Works with both Next.js (process.env) and Vite (import.meta.env)
|
|
36
|
-
*
|
|
37
|
-
* @returns true if in production mode
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* import { isProduction } from '@teo-garcia/react-shared/utils'
|
|
42
|
-
*
|
|
43
|
-
* if (isProduction()) {
|
|
44
|
-
* // Enable analytics
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export const isProduction = () => {
|
|
49
|
-
return !isDevelopment();
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Check if code is running on the server (SSR)
|
|
53
|
-
* Works by detecting the absence of window object
|
|
54
|
-
*
|
|
55
|
-
* @returns true if running on server
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```tsx
|
|
59
|
-
* import { isServer } from '@teo-garcia/react-shared/utils'
|
|
60
|
-
*
|
|
61
|
-
* if (isServer()) {
|
|
62
|
-
* // Server-only code
|
|
63
|
-
* }
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export const isServer = () => {
|
|
67
|
-
return typeof window === 'undefined';
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Check if code is running on the client (browser)
|
|
71
|
-
* Works by detecting the presence of window object
|
|
72
|
-
*
|
|
73
|
-
* @returns true if running on client
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```tsx
|
|
77
|
-
* import { isClient } from '@teo-garcia/react-shared/utils'
|
|
78
|
-
*
|
|
79
|
-
* if (isClient()) {
|
|
80
|
-
* // Client-only code like localStorage access
|
|
81
|
-
* }
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
export const isClient = () => {
|
|
85
|
-
return !isServer();
|
|
86
|
-
};
|
package/dist/utils/msw.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock Service Worker (MSW) setup utilities
|
|
3
|
-
*
|
|
4
|
-
* These utilities help set up MSW for API mocking in development and testing.
|
|
5
|
-
* They provide consistent factories for creating MSW workers across projects.
|
|
6
|
-
*/
|
|
7
|
-
import type { RequestHandler } from 'msw';
|
|
8
|
-
/**
|
|
9
|
-
* Creates and starts a browser MSW worker
|
|
10
|
-
* Use this in client-side applications (Next.js, React Router, etc.)
|
|
11
|
-
*
|
|
12
|
-
* @param handlers - Array of request handlers to use
|
|
13
|
-
* @param options - MSW worker options
|
|
14
|
-
* @returns Promise that resolves when worker is started
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
|
|
19
|
-
* import { handlers } from './handlers'
|
|
20
|
-
*
|
|
21
|
-
* // In your app initialization
|
|
22
|
-
* if (isDevelopment()) {
|
|
23
|
-
* await setupMSWBrowser(handlers)
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare const setupMSWBrowser: (handlers: RequestHandler[], options?: {
|
|
28
|
-
onUnhandledRequest?: "bypass" | "warn" | "error";
|
|
29
|
-
}) => Promise<import("msw/browser").SetupWorker>;
|
|
30
|
-
/**
|
|
31
|
-
* Creates and starts a Node.js MSW server
|
|
32
|
-
* Use this in server-side applications and tests
|
|
33
|
-
*
|
|
34
|
-
* @param handlers - Array of request handlers to use
|
|
35
|
-
* @param options - MSW server options
|
|
36
|
-
* @returns Promise that resolves to the server instance
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```tsx
|
|
40
|
-
* import { setupMSWServer } from '@teo-garcia/react-shared/utils'
|
|
41
|
-
* import { handlers } from './handlers'
|
|
42
|
-
*
|
|
43
|
-
* // In your test setup
|
|
44
|
-
* const server = await setupMSWServer(handlers)
|
|
45
|
-
*
|
|
46
|
-
* beforeAll(() => server.listen())
|
|
47
|
-
* afterEach(() => server.resetHandlers())
|
|
48
|
-
* afterAll(() => server.close())
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare const setupMSWServer: (handlers: RequestHandler[], options?: {
|
|
52
|
-
onUnhandledRequest?: "bypass" | "warn" | "error";
|
|
53
|
-
}) => Promise<import("msw/node").SetupServerApi>;
|
|
54
|
-
//# sourceMappingURL=msw.d.ts.map
|
package/dist/utils/msw.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"msw.d.ts","sourceRoot":"","sources":["../../src/utils/msw.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA"}
|
package/dist/utils/msw.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock Service Worker (MSW) setup utilities
|
|
3
|
-
*
|
|
4
|
-
* These utilities help set up MSW for API mocking in development and testing.
|
|
5
|
-
* They provide consistent factories for creating MSW workers across projects.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Creates and starts a browser MSW worker
|
|
9
|
-
* Use this in client-side applications (Next.js, React Router, etc.)
|
|
10
|
-
*
|
|
11
|
-
* @param handlers - Array of request handlers to use
|
|
12
|
-
* @param options - MSW worker options
|
|
13
|
-
* @returns Promise that resolves when worker is started
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
|
|
18
|
-
* import { handlers } from './handlers'
|
|
19
|
-
*
|
|
20
|
-
* // In your app initialization
|
|
21
|
-
* if (isDevelopment()) {
|
|
22
|
-
* await setupMSWBrowser(handlers)
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export const setupMSWBrowser = async (handlers, options) => {
|
|
27
|
-
const { setupWorker } = await import('msw/browser');
|
|
28
|
-
const worker = setupWorker(...handlers);
|
|
29
|
-
await worker.start({
|
|
30
|
-
onUnhandledRequest: options?.onUnhandledRequest ?? 'bypass',
|
|
31
|
-
});
|
|
32
|
-
return worker;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Creates and starts a Node.js MSW server
|
|
36
|
-
* Use this in server-side applications and tests
|
|
37
|
-
*
|
|
38
|
-
* @param handlers - Array of request handlers to use
|
|
39
|
-
* @param options - MSW server options
|
|
40
|
-
* @returns Promise that resolves to the server instance
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* import { setupMSWServer } from '@teo-garcia/react-shared/utils'
|
|
45
|
-
* import { handlers } from './handlers'
|
|
46
|
-
*
|
|
47
|
-
* // In your test setup
|
|
48
|
-
* const server = await setupMSWServer(handlers)
|
|
49
|
-
*
|
|
50
|
-
* beforeAll(() => server.listen())
|
|
51
|
-
* afterEach(() => server.resetHandlers())
|
|
52
|
-
* afterAll(() => server.close())
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export const setupMSWServer = async (handlers, options) => {
|
|
56
|
-
const { setupServer } = await import('msw/node');
|
|
57
|
-
const server = setupServer(...handlers);
|
|
58
|
-
server.listen({
|
|
59
|
-
onUnhandledRequest: options?.onUnhandledRequest ?? 'bypass',
|
|
60
|
-
});
|
|
61
|
-
return server;
|
|
62
|
-
};
|