@abpjs/theme-shared 2.4.0 → 2.9.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.
@@ -2,8 +2,15 @@
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
6
+ * @since 2.9.0 - Added LocaleDirection type
5
7
  */
6
8
  import type { ComponentType } from 'react';
9
+ /**
10
+ * Locale direction for RTL/LTR support.
11
+ * @since 2.9.0
12
+ */
13
+ export type LocaleDirection = 'ltr' | 'rtl';
7
14
  /**
8
15
  * Root parameters for ThemeSharedModule configuration.
9
16
  * @since 1.1.0
@@ -19,8 +26,15 @@ export type ErrorScreenErrorCodes = 401 | 403 | 404 | 500;
19
26
  /**
20
27
  * Configuration for HTTP error handling.
21
28
  * @since 1.1.0
29
+ * @since 2.7.0 - Added skipHandledErrorCodes, simplified forWhichErrors to array
22
30
  */
23
31
  export interface HttpErrorConfig {
32
+ /**
33
+ * Error codes to skip handling (let them pass through).
34
+ * Can be either ErrorScreenErrorCodes or any number.
35
+ * @since 2.7.0
36
+ */
37
+ skipHandledErrorCodes?: ErrorScreenErrorCodes[] | number[];
24
38
  /**
25
39
  * Custom error screen configuration.
26
40
  */
@@ -32,8 +46,9 @@ export interface HttpErrorConfig {
32
46
  /**
33
47
  * Which error codes to show the custom component for.
34
48
  * Defaults to all error codes if not specified.
49
+ * @since 2.7.0 - Simplified to just an array of ErrorScreenErrorCodes
35
50
  */
36
- forWhichErrors?: [ErrorScreenErrorCodes] | [ErrorScreenErrorCodes, ErrorScreenErrorCodes] | [ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes] | [ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes];
51
+ forWhichErrors?: ErrorScreenErrorCodes[];
37
52
  /**
38
53
  * Whether to hide the close icon on the error screen.
39
54
  */
@@ -9,18 +9,23 @@
9
9
  * - Removed deprecated cancelCopy/yesCopy
10
10
  *
11
11
  * @since 2.1.0 - Added Status enum (confirmation-specific, replaces Toaster.Status usage)
12
+ * @since 2.9.0 - Added dismissible property, deprecated closable
12
13
  */
13
14
  import type { Config } from '@abpjs/core';
14
15
  export declare namespace Confirmation {
15
16
  /**
16
17
  * Options for configuring a confirmation dialog.
17
18
  * @since 2.0.0 - No longer extends Toaster.Options
19
+ * @since 2.9.0 - Added dismissible, deprecated closable
18
20
  */
19
21
  interface Options {
20
22
  /** Unique identifier for the confirmation */
21
23
  id?: string | number;
22
- /** Whether the confirmation can be closed by clicking outside or pressing escape */
23
- closable?: boolean;
24
+ /**
25
+ * Whether the confirmation can be dismissed by clicking outside or pressing escape.
26
+ * @since 2.9.0
27
+ */
28
+ dismissible?: boolean;
24
29
  /** Parameters for localizing the message */
25
30
  messageLocalizationParams?: string[];
26
31
  /** Parameters for localizing the title */
@@ -33,6 +38,11 @@ export declare namespace Confirmation {
33
38
  cancelText?: Config.LocalizationParam;
34
39
  /** Custom text for the yes button */
35
40
  yesText?: Config.LocalizationParam;
41
+ /**
42
+ * Whether the confirmation can be closed by clicking outside or pressing escape.
43
+ * @deprecated Use dismissible instead. To be deleted in v3.0.
44
+ */
45
+ closable?: boolean;
36
46
  }
37
47
  /**
38
48
  * Dialog data structure for confirmation dialogs.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Append content token.
3
+ * Re-exported from constants for consistency with Angular API.
4
+ *
5
+ * @since 2.7.0
6
+ */
7
+ export { ThemeSharedAppendContentContext, THEME_SHARED_APPEND_CONTENT, } from '../constants/append-content';
@@ -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;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Theme shared tokens.
3
+ * Translated from @abp/ng.theme.shared/lib/tokens
4
+ *
5
+ * @since 2.7.0
6
+ * @since 2.9.0 - Added LAZY_STYLES token
7
+ */
8
+ export * from './append-content.token';
9
+ export * from './http-error.token';
10
+ export * from './lazy-styles.token';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Lazy Styles Token
3
+ * Translated from @abp/ng.theme.shared/lib/tokens/lazy-styles.token.ts
4
+ *
5
+ * Provides configuration for lazy-loaded stylesheets with RTL/LTR support.
6
+ *
7
+ * @since 2.9.0
8
+ */
9
+ /**
10
+ * Default lazy styles configuration.
11
+ * @since 2.9.0
12
+ */
13
+ export declare const DEFAULT_LAZY_STYLES: string[];
14
+ /**
15
+ * Context for lazy styles configuration.
16
+ * @since 2.9.0
17
+ */
18
+ export declare const LazyStylesContext: import("react").Context<string[]>;
19
+ /**
20
+ * Hook to get lazy styles configuration.
21
+ * @returns Array of style patterns with {{dir}} placeholder
22
+ * @since 2.9.0
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * function MyComponent() {
27
+ * const lazyStyles = useLazyStyles();
28
+ * // lazyStyles = ['bootstrap-{{dir}}.min.css']
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function useLazyStyles(): string[];
33
+ /**
34
+ * LAZY_STYLES constant for backwards compatibility.
35
+ * In React, use LazyStylesContext or useLazyStyles() hook instead.
36
+ * @since 2.9.0
37
+ */
38
+ export declare const LAZY_STYLES: string[];
@@ -1 +1,3 @@
1
1
  export * from './styles';
2
+ export * from './nav-items';
3
+ export * from './validation-utils';
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Nav Items Utility
3
+ * Translated from @abp/ng.theme.shared/lib/utils/nav-items.ts
4
+ *
5
+ * Provides functions for managing navigation items dynamically.
6
+ *
7
+ * @since 2.9.0
8
+ */
9
+ import { ComponentType } from 'react';
10
+ /**
11
+ * Navigation item configuration.
12
+ * @since 2.9.0
13
+ */
14
+ export interface NavItem {
15
+ /**
16
+ * React component to render for this nav item.
17
+ */
18
+ component?: ComponentType<any>;
19
+ /**
20
+ * Raw HTML string to render (use with caution for XSS).
21
+ */
22
+ html?: string;
23
+ /**
24
+ * Action to execute when the nav item is clicked.
25
+ */
26
+ action?: () => void;
27
+ /**
28
+ * Order for sorting nav items. Lower numbers appear first.
29
+ */
30
+ order?: number;
31
+ /**
32
+ * Permission required to show this nav item.
33
+ */
34
+ permission?: string;
35
+ }
36
+ type NavItemSubscriber = (items: NavItem[]) => void;
37
+ /**
38
+ * Add a navigation item.
39
+ * @param item - The nav item to add
40
+ * @since 2.9.0
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * addNavItem({
45
+ * component: MyComponent,
46
+ * order: 10,
47
+ * permission: 'AbpIdentity.Users',
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function addNavItem(item: NavItem): void;
52
+ /**
53
+ * Remove a navigation item.
54
+ * @param item - The nav item to remove
55
+ * @since 2.9.0
56
+ */
57
+ export declare function removeNavItem(item: NavItem): void;
58
+ /**
59
+ * Clear all navigation items.
60
+ * @since 2.9.0
61
+ */
62
+ export declare function clearNavItems(): void;
63
+ /**
64
+ * Get current navigation items.
65
+ * @returns Array of nav items
66
+ * @since 2.9.0
67
+ */
68
+ export declare function getNavItemsSync(): NavItem[];
69
+ /**
70
+ * Subscribe to navigation item changes.
71
+ * Returns an unsubscribe function.
72
+ *
73
+ * @param callback - Function to call when nav items change
74
+ * @returns Unsubscribe function
75
+ * @since 2.9.0
76
+ *
77
+ * @example
78
+ * ```tsx
79
+ * const unsubscribe = subscribeToNavItems((items) => {
80
+ * console.log('Nav items changed:', items);
81
+ * });
82
+ *
83
+ * // Later, to unsubscribe:
84
+ * unsubscribe();
85
+ * ```
86
+ */
87
+ export declare function subscribeToNavItems(callback: NavItemSubscriber): () => void;
88
+ /**
89
+ * Get navigation items as an observable-like interface.
90
+ * Compatible with Angular's Observable pattern.
91
+ *
92
+ * @returns Object with subscribe method
93
+ * @since 2.9.0
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * const subscription = getNavItems().subscribe((items) => {
98
+ * console.log('Nav items:', items);
99
+ * });
100
+ *
101
+ * // Later, to unsubscribe:
102
+ * subscription.unsubscribe();
103
+ * ```
104
+ */
105
+ export declare function getNavItems(): {
106
+ subscribe: (callback: NavItemSubscriber) => {
107
+ unsubscribe: () => void;
108
+ };
109
+ };
110
+ export {};
@@ -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.4.0",
3
+ "version": "2.9.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.4.0"
30
+ "@abpjs/core": "2.9.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@abp/ng.theme.shared": "2.4.0",
33
+ "@abp/ng.theme.shared": "2.9.0",
34
34
  "@vitest/coverage-v8": "^3.2.0"
35
35
  },
36
36
  "author": "tekthar.com",