@regardio/react 0.4.2 → 0.4.3
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/dist/components/heading.d.ts +1 -1
- package/dist/components/item.d.ts +1 -1
- package/package.json +2 -2
- package/dist/utils/locale.d.ts +0 -84
- package/dist/utils/locale.js +0 -36
- package/src/utils/locale.test.ts +0 -148
- package/src/utils/locale.ts +0 -127
|
@@ -4,7 +4,7 @@ import { VariantProps } from 'cva';
|
|
|
4
4
|
import { HTMLAttributes, ElementType } from 'react';
|
|
5
5
|
|
|
6
6
|
declare const heading: (props?: ({
|
|
7
|
-
level?:
|
|
7
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
8
8
|
variant?: undefined;
|
|
9
9
|
} & ({
|
|
10
10
|
class?: cva.ClassValue;
|
|
@@ -48,7 +48,7 @@ declare const themeColors: {
|
|
|
48
48
|
yellow: never[];
|
|
49
49
|
};
|
|
50
50
|
declare const item: (props?: ({
|
|
51
|
-
height?:
|
|
51
|
+
height?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
52
52
|
padding?: "default" | "gutter" | undefined;
|
|
53
53
|
priority?: "high" | "low" | "medium" | undefined;
|
|
54
54
|
themeColor?: "black" | "blue" | "coral" | "cyan" | "gray" | "green" | "lime" | "olive" | "orange" | "pink" | "purple" | "red" | "teal" | "white" | "yellow" | "unstyled" | "neutral" | undefined;
|
package/package.json
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"playwright": "^1.57.0",
|
|
55
55
|
"storybook": "10.1.11",
|
|
56
56
|
"tailwindcss": "4.1.18",
|
|
57
|
-
"tsup": "8.5.
|
|
57
|
+
"tsup": "8.5.1",
|
|
58
58
|
"typescript": "5.9.3",
|
|
59
59
|
"vite": "7.3.0",
|
|
60
60
|
"vitest": "4.0.16"
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
},
|
|
115
115
|
"sideEffects": ["./src/styles/tailwind.css"],
|
|
116
116
|
"type": "module",
|
|
117
|
-
"version": "0.4.
|
|
117
|
+
"version": "0.4.3"
|
|
118
118
|
}
|
package/dist/utils/locale.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { LanguageDetectorLingui } from '@regardio/js/intl/language-detector';
|
|
2
|
-
import { createCookie } from 'react-router';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Configuration options for creating locale utilities
|
|
6
|
-
*/
|
|
7
|
-
interface LocaleConfigOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Default locale to use as fallback
|
|
10
|
-
*/
|
|
11
|
-
defaultLocale: string;
|
|
12
|
-
/**
|
|
13
|
-
* List of supported locales
|
|
14
|
-
*/
|
|
15
|
-
supportedLocales: readonly string[];
|
|
16
|
-
/**
|
|
17
|
-
* Cookie options for storing locale preference
|
|
18
|
-
*/
|
|
19
|
-
cookieOptions?: {
|
|
20
|
-
/**
|
|
21
|
-
* Name of the cookie (default: 'locale')
|
|
22
|
-
*/
|
|
23
|
-
name?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Max age of the cookie in seconds (default: 1 year)
|
|
26
|
-
*/
|
|
27
|
-
maxAge?: number;
|
|
28
|
-
/**
|
|
29
|
-
* Whether the cookie should be HTTP only (default: false)
|
|
30
|
-
*/
|
|
31
|
-
httpOnly?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Whether the cookie should be secure (default: true in production)
|
|
34
|
-
*/
|
|
35
|
-
secure?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* SameSite attribute for the cookie (default: 'lax')
|
|
38
|
-
*/
|
|
39
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Detection options for the language detector
|
|
43
|
-
*/
|
|
44
|
-
detectionOptions?: {
|
|
45
|
-
/**
|
|
46
|
-
* Order of detection methods (default: ['urlPath', 'cookie', 'header'])
|
|
47
|
-
*/
|
|
48
|
-
order?: Array<'urlPath' | 'cookie' | 'header'>;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Result of createLocaleConfig
|
|
53
|
-
*/
|
|
54
|
-
interface LocaleConfig {
|
|
55
|
-
/**
|
|
56
|
-
* Cookie for storing locale preference
|
|
57
|
-
*/
|
|
58
|
-
localeCookie: ReturnType<typeof createCookie>;
|
|
59
|
-
/**
|
|
60
|
-
* Language detector instance
|
|
61
|
-
*/
|
|
62
|
-
languageDetector: LanguageDetectorLingui;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Create locale configuration utilities
|
|
66
|
-
*
|
|
67
|
-
* This function creates a unified locale cookie and language detector
|
|
68
|
-
* based on the provided configuration options.
|
|
69
|
-
*
|
|
70
|
-
* @param options Configuration options
|
|
71
|
-
* @returns Locale configuration utilities
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* // In your app's configuration file
|
|
76
|
-
* const { localeCookie, languageDetector } = createLocaleConfig({
|
|
77
|
-
* defaultLocale: 'en',
|
|
78
|
-
* supportedLocales: ['en', 'de', 'fr'],
|
|
79
|
-
* });
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function createLocaleConfig(options: LocaleConfigOptions): LocaleConfig;
|
|
83
|
-
|
|
84
|
-
export { type LocaleConfig, type LocaleConfigOptions, createLocaleConfig };
|
package/dist/utils/locale.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { LanguageDetectorLingui } from '@regardio/js/intl/language-detector';
|
|
2
|
-
import { createCookie } from 'react-router';
|
|
3
|
-
|
|
4
|
-
// src/utils/locale.ts
|
|
5
|
-
function createLocaleConfig(options) {
|
|
6
|
-
const { defaultLocale, supportedLocales, cookieOptions = {}, detectionOptions = {} } = options;
|
|
7
|
-
const {
|
|
8
|
-
name = "locale",
|
|
9
|
-
maxAge = 60 * 60 * 24 * 365,
|
|
10
|
-
// 1 year
|
|
11
|
-
httpOnly = false,
|
|
12
|
-
secure = import.meta.env.MODE !== "development",
|
|
13
|
-
sameSite = "lax"
|
|
14
|
-
} = cookieOptions;
|
|
15
|
-
const { order = ["urlPath", "cookie", "header"] } = detectionOptions;
|
|
16
|
-
const localeCookie = createCookie(name, {
|
|
17
|
-
httpOnly,
|
|
18
|
-
maxAge,
|
|
19
|
-
sameSite,
|
|
20
|
-
secure
|
|
21
|
-
});
|
|
22
|
-
const languageDetector = new LanguageDetectorLingui({
|
|
23
|
-
detection: {
|
|
24
|
-
cookie: localeCookie,
|
|
25
|
-
fallbackLanguage: defaultLocale,
|
|
26
|
-
order,
|
|
27
|
-
supportedLanguages: [...supportedLocales]
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
languageDetector,
|
|
32
|
-
localeCookie
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { createLocaleConfig };
|
package/src/utils/locale.test.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { LanguageDetectorLingui } from '@regardio/js/intl/language-detector';
|
|
2
|
-
import { beforeEach, describe, expect, test } from 'vitest';
|
|
3
|
-
import { createLocaleConfig } from './locale';
|
|
4
|
-
|
|
5
|
-
describe('createLocaleConfig', () => {
|
|
6
|
-
const originalEnvMode = import.meta.env.MODE;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
// Reset MODE between tests
|
|
10
|
-
import.meta.env.MODE = originalEnvMode;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('creates config with default options', async () => {
|
|
14
|
-
const config = createLocaleConfig({
|
|
15
|
-
defaultLocale: 'en',
|
|
16
|
-
supportedLocales: ['en', 'de'],
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// Verify cookie was created with correct default options
|
|
20
|
-
expect(config.localeCookie).toBeDefined();
|
|
21
|
-
expect(config.localeCookie.name).toBe('locale');
|
|
22
|
-
|
|
23
|
-
// Create a mock request with a cookie
|
|
24
|
-
const request = new Request('https://example.com', {
|
|
25
|
-
headers: {
|
|
26
|
-
Cookie: await config.localeCookie.serialize('en'),
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Parse the cookie to verify it works correctly
|
|
31
|
-
const parsedValue = await config.localeCookie.parse(request.headers.get('Cookie'));
|
|
32
|
-
expect(parsedValue).toBe('en');
|
|
33
|
-
|
|
34
|
-
// Verify language detector was created correctly
|
|
35
|
-
expect(config.languageDetector).toBeInstanceOf(LanguageDetectorLingui);
|
|
36
|
-
|
|
37
|
-
// Test language detector behavior instead of accessing private properties
|
|
38
|
-
const mockRequest = new Request('https://example.com/en/page', {
|
|
39
|
-
headers: { 'Accept-Language': 'de' },
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// With default order (urlPath first), it should detect 'en' from URL path
|
|
43
|
-
const detectedLocale = await config.languageDetector.getLocale(mockRequest);
|
|
44
|
-
expect(detectedLocale).toBe('en');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('creates config with custom cookie options', async () => {
|
|
48
|
-
const config = createLocaleConfig({
|
|
49
|
-
cookieOptions: {
|
|
50
|
-
httpOnly: true,
|
|
51
|
-
maxAge: 3600, // 1 hour
|
|
52
|
-
name: 'custom-locale',
|
|
53
|
-
sameSite: 'strict',
|
|
54
|
-
secure: true,
|
|
55
|
-
},
|
|
56
|
-
defaultLocale: 'fr',
|
|
57
|
-
supportedLocales: ['fr', 'es'],
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Verify cookie name
|
|
61
|
-
expect(config.localeCookie.name).toBe('custom-locale');
|
|
62
|
-
|
|
63
|
-
// Test cookie serialization to verify options indirectly
|
|
64
|
-
const cookieHeader = await config.localeCookie.serialize('fr');
|
|
65
|
-
console.log('Custom cookie header:', cookieHeader);
|
|
66
|
-
expect(typeof cookieHeader).toBe('string');
|
|
67
|
-
// Check for cookie name and value without assuming exact format
|
|
68
|
-
expect(cookieHeader.includes('custom-locale=')).toBe(true);
|
|
69
|
-
expect(/samesite=strict/i.test(cookieHeader)).toBe(true);
|
|
70
|
-
expect(/httponly/i.test(cookieHeader)).toBe(true);
|
|
71
|
-
expect(/secure/i.test(cookieHeader)).toBe(true);
|
|
72
|
-
expect(/max-age=3600/i.test(cookieHeader)).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('creates config with custom detection order', async () => {
|
|
76
|
-
const config = createLocaleConfig({
|
|
77
|
-
defaultLocale: 'de',
|
|
78
|
-
detectionOptions: {
|
|
79
|
-
order: ['header', 'cookie', 'urlPath'],
|
|
80
|
-
},
|
|
81
|
-
supportedLocales: ['de', 'en'],
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Test detection order by creating requests that would give different results
|
|
85
|
-
// based on detection order
|
|
86
|
-
|
|
87
|
-
// This request has 'en' in URL path but 'de' in Accept-Language header
|
|
88
|
-
const mockRequest = new Request('https://example.com/en/page', {
|
|
89
|
-
headers: { 'Accept-Language': 'de' },
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// With custom order (header first), it should detect 'de' from header
|
|
93
|
-
// instead of 'en' from URL path
|
|
94
|
-
const detectedLocale = await config.languageDetector.getLocale(mockRequest);
|
|
95
|
-
expect(detectedLocale).toBe('de');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('secure cookie defaults to true in production environment', async () => {
|
|
99
|
-
// Mock production environment
|
|
100
|
-
import.meta.env.MODE = 'production';
|
|
101
|
-
|
|
102
|
-
const config = createLocaleConfig({
|
|
103
|
-
defaultLocale: 'en',
|
|
104
|
-
supportedLocales: ['en', 'de'],
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Test cookie serialization to verify secure option indirectly
|
|
108
|
-
const cookieHeader = await config.localeCookie.serialize('en');
|
|
109
|
-
console.log('Production cookie header:', cookieHeader);
|
|
110
|
-
expect(typeof cookieHeader).toBe('string');
|
|
111
|
-
// Check for Secure flag without assuming exact format
|
|
112
|
-
expect(/secure/i.test(cookieHeader)).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('secure cookie defaults to false in development environment', async () => {
|
|
116
|
-
// Mock development environment
|
|
117
|
-
import.meta.env.MODE = 'development';
|
|
118
|
-
|
|
119
|
-
const config = createLocaleConfig({
|
|
120
|
-
defaultLocale: 'en',
|
|
121
|
-
supportedLocales: ['en', 'de'],
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Test cookie serialization to verify secure option indirectly
|
|
125
|
-
const cookieHeader = await config.localeCookie.serialize('en');
|
|
126
|
-
console.log('Development cookie header:', cookieHeader);
|
|
127
|
-
expect(typeof cookieHeader).toBe('string');
|
|
128
|
-
// Check for absence of Secure flag without assuming exact format
|
|
129
|
-
expect(/secure/i.test(cookieHeader)).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('handles readonly supportedLocales array', async () => {
|
|
133
|
-
// Create a readonly array
|
|
134
|
-
const supportedLocales = ['en', 'de'] as const;
|
|
135
|
-
|
|
136
|
-
const config = createLocaleConfig({
|
|
137
|
-
defaultLocale: 'en',
|
|
138
|
-
supportedLocales,
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Test that both languages are detected correctly
|
|
142
|
-
const enRequest = new Request('https://example.com/en/page');
|
|
143
|
-
expect(await config.languageDetector.getLocale(enRequest)).toBe('en');
|
|
144
|
-
|
|
145
|
-
const deRequest = new Request('https://example.com/de/page');
|
|
146
|
-
expect(await config.languageDetector.getLocale(deRequest)).toBe('de');
|
|
147
|
-
});
|
|
148
|
-
});
|
package/src/utils/locale.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { LanguageDetectorLingui } from '@regardio/js/intl/language-detector';
|
|
2
|
-
import { createCookie } from 'react-router';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Configuration options for creating locale utilities
|
|
6
|
-
*/
|
|
7
|
-
export interface LocaleConfigOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Default locale to use as fallback
|
|
10
|
-
*/
|
|
11
|
-
defaultLocale: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* List of supported locales
|
|
15
|
-
*/
|
|
16
|
-
supportedLocales: readonly string[];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Cookie options for storing locale preference
|
|
20
|
-
*/
|
|
21
|
-
cookieOptions?: {
|
|
22
|
-
/**
|
|
23
|
-
* Name of the cookie (default: 'locale')
|
|
24
|
-
*/
|
|
25
|
-
name?: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Max age of the cookie in seconds (default: 1 year)
|
|
29
|
-
*/
|
|
30
|
-
maxAge?: number;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Whether the cookie should be HTTP only (default: false)
|
|
34
|
-
*/
|
|
35
|
-
httpOnly?: boolean;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Whether the cookie should be secure (default: true in production)
|
|
39
|
-
*/
|
|
40
|
-
secure?: boolean;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* SameSite attribute for the cookie (default: 'lax')
|
|
44
|
-
*/
|
|
45
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Detection options for the language detector
|
|
50
|
-
*/
|
|
51
|
-
detectionOptions?: {
|
|
52
|
-
/**
|
|
53
|
-
* Order of detection methods (default: ['urlPath', 'cookie', 'header'])
|
|
54
|
-
*/
|
|
55
|
-
order?: Array<'urlPath' | 'cookie' | 'header'>;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Result of createLocaleConfig
|
|
61
|
-
*/
|
|
62
|
-
export interface LocaleConfig {
|
|
63
|
-
/**
|
|
64
|
-
* Cookie for storing locale preference
|
|
65
|
-
*/
|
|
66
|
-
localeCookie: ReturnType<typeof createCookie>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Language detector instance
|
|
70
|
-
*/
|
|
71
|
-
languageDetector: LanguageDetectorLingui;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Create locale configuration utilities
|
|
76
|
-
*
|
|
77
|
-
* This function creates a unified locale cookie and language detector
|
|
78
|
-
* based on the provided configuration options.
|
|
79
|
-
*
|
|
80
|
-
* @param options Configuration options
|
|
81
|
-
* @returns Locale configuration utilities
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* // In your app's configuration file
|
|
86
|
-
* const { localeCookie, languageDetector } = createLocaleConfig({
|
|
87
|
-
* defaultLocale: 'en',
|
|
88
|
-
* supportedLocales: ['en', 'de', 'fr'],
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export function createLocaleConfig(options: LocaleConfigOptions): LocaleConfig {
|
|
93
|
-
const { defaultLocale, supportedLocales, cookieOptions = {}, detectionOptions = {} } = options;
|
|
94
|
-
|
|
95
|
-
const {
|
|
96
|
-
name = 'locale',
|
|
97
|
-
maxAge = 60 * 60 * 24 * 365, // 1 year
|
|
98
|
-
httpOnly = false,
|
|
99
|
-
secure = import.meta.env.MODE !== 'development',
|
|
100
|
-
sameSite = 'lax',
|
|
101
|
-
} = cookieOptions;
|
|
102
|
-
|
|
103
|
-
const { order = ['urlPath', 'cookie', 'header'] } = detectionOptions;
|
|
104
|
-
|
|
105
|
-
// Create cookie for storing locale preference
|
|
106
|
-
const localeCookie = createCookie(name, {
|
|
107
|
-
httpOnly,
|
|
108
|
-
maxAge,
|
|
109
|
-
sameSite,
|
|
110
|
-
secure,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Create language detector instance
|
|
114
|
-
const languageDetector = new LanguageDetectorLingui({
|
|
115
|
-
detection: {
|
|
116
|
-
cookie: localeCookie,
|
|
117
|
-
fallbackLanguage: defaultLocale,
|
|
118
|
-
order,
|
|
119
|
-
supportedLanguages: [...supportedLocales],
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
languageDetector,
|
|
125
|
-
localeCookie,
|
|
126
|
-
};
|
|
127
|
-
}
|