@abpjs/theme-shared 2.4.0 → 2.7.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/dist/components/errors/ErrorComponent.d.ts +27 -1
- package/dist/contexts/index.d.ts +1 -0
- package/dist/contexts/modal.context.d.ts +139 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +507 -271
- package/dist/index.mjs +419 -189
- package/dist/models/common.d.ts +10 -1
- package/dist/tokens/append-content.token.d.ts +7 -0
- package/dist/tokens/http-error.token.d.ts +70 -0
- package/dist/tokens/index.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/validation-utils.d.ts +125 -0
- package/package.json +3 -3
package/dist/models/common.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Common types for theme-shared module.
|
|
3
3
|
* Translated from @abp/ng.theme.shared/lib/models/common.ts
|
|
4
4
|
* @since 1.1.0
|
|
5
|
+
* @since 2.7.0 - Added skipHandledErrorCodes, simplified forWhichErrors type
|
|
5
6
|
*/
|
|
6
7
|
import type { ComponentType } from 'react';
|
|
7
8
|
/**
|
|
@@ -19,8 +20,15 @@ export type ErrorScreenErrorCodes = 401 | 403 | 404 | 500;
|
|
|
19
20
|
/**
|
|
20
21
|
* Configuration for HTTP error handling.
|
|
21
22
|
* @since 1.1.0
|
|
23
|
+
* @since 2.7.0 - Added skipHandledErrorCodes, simplified forWhichErrors to array
|
|
22
24
|
*/
|
|
23
25
|
export interface HttpErrorConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Error codes to skip handling (let them pass through).
|
|
28
|
+
* Can be either ErrorScreenErrorCodes or any number.
|
|
29
|
+
* @since 2.7.0
|
|
30
|
+
*/
|
|
31
|
+
skipHandledErrorCodes?: ErrorScreenErrorCodes[] | number[];
|
|
24
32
|
/**
|
|
25
33
|
* Custom error screen configuration.
|
|
26
34
|
*/
|
|
@@ -32,8 +40,9 @@ export interface HttpErrorConfig {
|
|
|
32
40
|
/**
|
|
33
41
|
* Which error codes to show the custom component for.
|
|
34
42
|
* Defaults to all error codes if not specified.
|
|
43
|
+
* @since 2.7.0 - Simplified to just an array of ErrorScreenErrorCodes
|
|
35
44
|
*/
|
|
36
|
-
forWhichErrors?:
|
|
45
|
+
forWhichErrors?: ErrorScreenErrorCodes[];
|
|
37
46
|
/**
|
|
38
47
|
* Whether to hide the close icon on the error screen.
|
|
39
48
|
*/
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Error configuration tokens.
|
|
3
|
+
* Translated from @abp/ng.theme.shared/lib/tokens/http-error.token.ts
|
|
4
|
+
*
|
|
5
|
+
* @since 2.7.0
|
|
6
|
+
*/
|
|
7
|
+
import type { HttpErrorConfig } from '../models/common';
|
|
8
|
+
/**
|
|
9
|
+
* Token name constant for HTTP_ERROR_CONFIG.
|
|
10
|
+
* Matches the Angular InjectionToken name.
|
|
11
|
+
*
|
|
12
|
+
* @since 2.7.0
|
|
13
|
+
*/
|
|
14
|
+
export declare const HTTP_ERROR_CONFIG = "HTTP_ERROR_CONFIG";
|
|
15
|
+
/**
|
|
16
|
+
* Context for HTTP error configuration.
|
|
17
|
+
* Use this to provide custom HTTP error handling configuration.
|
|
18
|
+
*
|
|
19
|
+
* This is the React equivalent of Angular's HTTP_ERROR_CONFIG InjectionToken.
|
|
20
|
+
*
|
|
21
|
+
* @since 2.7.0
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import { HttpErrorConfigContext } from '@abpjs/theme-shared';
|
|
26
|
+
*
|
|
27
|
+
* function App() {
|
|
28
|
+
* const httpErrorConfig: HttpErrorConfig = {
|
|
29
|
+
* skipHandledErrorCodes: [404],
|
|
30
|
+
* errorScreen: {
|
|
31
|
+
* component: MyCustomErrorComponent,
|
|
32
|
+
* forWhichErrors: [401, 403, 500],
|
|
33
|
+
* },
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <HttpErrorConfigContext.Provider value={httpErrorConfig}>
|
|
38
|
+
* <YourApp />
|
|
39
|
+
* </HttpErrorConfigContext.Provider>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const HttpErrorConfigContext: import("react").Context<HttpErrorConfig | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Factory function to create default HTTP error config.
|
|
47
|
+
* Matches Angular's httpErrorConfigFactory function.
|
|
48
|
+
*
|
|
49
|
+
* @returns Default HttpErrorConfig
|
|
50
|
+
* @since 2.7.0
|
|
51
|
+
*/
|
|
52
|
+
export declare function httpErrorConfigFactory(): HttpErrorConfig;
|
|
53
|
+
/**
|
|
54
|
+
* Hook to access the HTTP error configuration.
|
|
55
|
+
*
|
|
56
|
+
* @returns HttpErrorConfig or default config if not provided
|
|
57
|
+
* @since 2.7.0
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* function MyComponent() {
|
|
62
|
+
* const config = useHttpErrorConfig();
|
|
63
|
+
*
|
|
64
|
+
* if (config.skipHandledErrorCodes?.includes(404)) {
|
|
65
|
+
* // Skip handling 404 errors
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function useHttpErrorConfig(): HttpErrorConfig;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utility functions for form validation.
|
|
3
|
+
* Translated from @abp/ng.theme.shared/lib/utils/validation-utils.ts
|
|
4
|
+
*
|
|
5
|
+
* @since 2.7.0
|
|
6
|
+
*/
|
|
7
|
+
import type { RegisterOptions } from 'react-hook-form';
|
|
8
|
+
/**
|
|
9
|
+
* Password validation settings from ABP configuration.
|
|
10
|
+
* These values come from Identity.Settings.Password in the ABP framework.
|
|
11
|
+
* @since 2.7.0
|
|
12
|
+
*/
|
|
13
|
+
export interface PasswordSettings {
|
|
14
|
+
/** Minimum required length for passwords */
|
|
15
|
+
requiredLength?: number;
|
|
16
|
+
/** Maximum allowed length for passwords */
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
/** Whether passwords must contain at least one digit */
|
|
19
|
+
requireDigit?: boolean;
|
|
20
|
+
/** Whether passwords must contain at least one lowercase letter */
|
|
21
|
+
requireLowercase?: boolean;
|
|
22
|
+
/** Whether passwords must contain at least one uppercase letter */
|
|
23
|
+
requireUppercase?: boolean;
|
|
24
|
+
/** Whether passwords must contain at least one non-alphanumeric character */
|
|
25
|
+
requireNonAlphanumeric?: boolean;
|
|
26
|
+
/** Number of unique characters required */
|
|
27
|
+
requiredUniqueChars?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Password validator function type for custom validation.
|
|
31
|
+
* Returns true if valid, or an error message string if invalid.
|
|
32
|
+
* @since 2.7.0
|
|
33
|
+
*/
|
|
34
|
+
export type PasswordValidator = (value: string) => true | string;
|
|
35
|
+
/**
|
|
36
|
+
* Store-like interface for accessing ABP settings.
|
|
37
|
+
* This matches the pattern used by @abpjs/core's useAbpConfig hook.
|
|
38
|
+
* @since 2.7.0
|
|
39
|
+
*/
|
|
40
|
+
export interface SettingsStore {
|
|
41
|
+
getSetting: (key: string) => string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Default password setting keys in ABP Identity module.
|
|
45
|
+
* @since 2.7.0
|
|
46
|
+
*/
|
|
47
|
+
export declare const PASSWORD_SETTING_KEYS: {
|
|
48
|
+
readonly requiredLength: "Abp.Identity.Password.RequiredLength";
|
|
49
|
+
readonly maxLength: "Abp.Identity.Password.MaxLength";
|
|
50
|
+
readonly requireDigit: "Abp.Identity.Password.RequireDigit";
|
|
51
|
+
readonly requireLowercase: "Abp.Identity.Password.RequireLowercase";
|
|
52
|
+
readonly requireUppercase: "Abp.Identity.Password.RequireUppercase";
|
|
53
|
+
readonly requireNonAlphanumeric: "Abp.Identity.Password.RequireNonAlphanumeric";
|
|
54
|
+
readonly requiredUniqueChars: "Abp.Identity.Password.RequiredUniqueChars";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Get password settings from the store.
|
|
58
|
+
* @param store - The settings store (typically from useAbpConfig hook)
|
|
59
|
+
* @returns Password settings object
|
|
60
|
+
* @since 2.7.0
|
|
61
|
+
*/
|
|
62
|
+
export declare function getPasswordSettings(store: SettingsStore): PasswordSettings;
|
|
63
|
+
/**
|
|
64
|
+
* Get password validators based on ABP Identity settings.
|
|
65
|
+
*
|
|
66
|
+
* This is the React equivalent of Angular's getPasswordValidators function.
|
|
67
|
+
* It reads password requirements from ABP settings and returns validation functions
|
|
68
|
+
* compatible with react-hook-form's validate option.
|
|
69
|
+
*
|
|
70
|
+
* @param store - The settings store (typically from useAbpConfig hook)
|
|
71
|
+
* @returns Array of validator functions for password validation
|
|
72
|
+
*
|
|
73
|
+
* @since 2.7.0
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* import { useAbpConfig } from '@abpjs/core';
|
|
78
|
+
* import { getPasswordValidators } from '@abpjs/theme-shared';
|
|
79
|
+
* import { useForm } from 'react-hook-form';
|
|
80
|
+
*
|
|
81
|
+
* function PasswordForm() {
|
|
82
|
+
* const { getSetting } = useAbpConfig();
|
|
83
|
+
* const validators = getPasswordValidators({ getSetting });
|
|
84
|
+
*
|
|
85
|
+
* const { register } = useForm();
|
|
86
|
+
*
|
|
87
|
+
* return (
|
|
88
|
+
* <input
|
|
89
|
+
* {...register('password', {
|
|
90
|
+
* validate: Object.fromEntries(
|
|
91
|
+
* validators.map((v, i) => [`rule${i}`, v])
|
|
92
|
+
* )
|
|
93
|
+
* })}
|
|
94
|
+
* />
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function getPasswordValidators(store: SettingsStore): PasswordValidator[];
|
|
100
|
+
/**
|
|
101
|
+
* Convert password validators to react-hook-form RegisterOptions.
|
|
102
|
+
* This is a convenience function to create validation rules for react-hook-form.
|
|
103
|
+
*
|
|
104
|
+
* @param store - The settings store (typically from useAbpConfig hook)
|
|
105
|
+
* @returns RegisterOptions with validate rules for react-hook-form
|
|
106
|
+
*
|
|
107
|
+
* @since 2.7.0
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* import { useAbpConfig } from '@abpjs/core';
|
|
112
|
+
* import { getPasswordValidationRules } from '@abpjs/theme-shared';
|
|
113
|
+
* import { useForm } from 'react-hook-form';
|
|
114
|
+
*
|
|
115
|
+
* function PasswordForm() {
|
|
116
|
+
* const { getSetting } = useAbpConfig();
|
|
117
|
+
* const { register } = useForm();
|
|
118
|
+
*
|
|
119
|
+
* return (
|
|
120
|
+
* <input {...register('password', getPasswordValidationRules({ getSetting }))} />
|
|
121
|
+
* );
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function getPasswordValidationRules(store: SettingsStore): RegisterOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abpjs/theme-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "ABP Framework Theme Shared components for React - translated from @abp/ng.theme.shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"next-themes": "^0.4.6",
|
|
28
28
|
"react-hook-form": "^7.48.0",
|
|
29
29
|
"react-icons": "^5.5.0",
|
|
30
|
-
"@abpjs/core": "2.
|
|
30
|
+
"@abpjs/core": "2.7.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@abp/ng.theme.shared": "2.
|
|
33
|
+
"@abp/ng.theme.shared": "2.7.0",
|
|
34
34
|
"@vitest/coverage-v8": "^3.2.0"
|
|
35
35
|
},
|
|
36
36
|
"author": "tekthar.com",
|