@abpjs/setting-management 0.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.
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version of
113
+ the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # @abpjs/setting-management
2
+
3
+ > Setting management UI components for ABP Framework in React
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@abpjs/setting-management.svg)](https://www.npmjs.com/package/@abpjs/setting-management)
6
+ [![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
7
+
8
+ ## Overview
9
+
10
+ `@abpjs/setting-management` provides a settings management page layout and tab management for ABP-based React applications. It allows organizing application settings into categorized tabs with a unified UI.
11
+
12
+ This package is a React translation of the original `@abp/ng.setting-management` Angular package.
13
+
14
+ ## Features
15
+
16
+ - **Setting Tabs** - Register and manage setting tabs from different modules
17
+ - **Tab Layout** - Responsive sidebar layout with tab navigation
18
+ - **URL Sync** - Automatic tab selection based on current URL
19
+ - **Ordering** - Tabs sorted by configurable order property
20
+ - **TypeScript** - Full type safety with comprehensive definitions
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ # Using npm
26
+ npm install @abpjs/setting-management
27
+
28
+ # Using yarn
29
+ yarn add @abpjs/setting-management
30
+
31
+ # Using pnpm
32
+ pnpm add @abpjs/setting-management
33
+ ```
34
+
35
+ ### Required Dependencies
36
+
37
+ This package requires the following peer dependencies:
38
+
39
+ ```bash
40
+ npm install @abpjs/core @abpjs/theme-shared react-router-dom
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ### Using the Setting Layout Component
46
+
47
+ ```tsx
48
+ import { useEffect } from 'react';
49
+ import { Outlet } from 'react-router-dom';
50
+ import { SettingLayout, useSettingManagement } from '@abpjs/setting-management';
51
+
52
+ function SettingsPage() {
53
+ const { addSettings } = useSettingManagement();
54
+
55
+ useEffect(() => {
56
+ addSettings([
57
+ { name: 'Account', order: 1, url: '/settings/account' },
58
+ { name: 'Identity', order: 2, url: '/settings/identity' },
59
+ { name: 'Tenant', order: 3, url: '/settings/tenant', requiredPolicy: 'AbpTenantManagement.Tenants' },
60
+ ]);
61
+ }, [addSettings]);
62
+
63
+ return (
64
+ <SettingLayout>
65
+ <Outlet />
66
+ </SettingLayout>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### Using the Hook
72
+
73
+ ```tsx
74
+ import { useSettingManagement } from '@abpjs/setting-management';
75
+
76
+ function SettingsMenu() {
77
+ const {
78
+ settings,
79
+ selected,
80
+ setSelected,
81
+ addSetting,
82
+ removeSetting,
83
+ } = useSettingManagement();
84
+
85
+ return (
86
+ <nav>
87
+ {settings.map(tab => (
88
+ <button
89
+ key={tab.name}
90
+ onClick={() => setSelected(tab)}
91
+ className={selected?.name === tab.name ? 'active' : ''}
92
+ >
93
+ {tab.name}
94
+ </button>
95
+ ))}
96
+ </nav>
97
+ );
98
+ }
99
+ ```
100
+
101
+ ### Registering Settings from Other Modules
102
+
103
+ ```tsx
104
+ // In your account module
105
+ import { useEffect } from 'react';
106
+ import { useSettingManagement } from '@abpjs/setting-management';
107
+
108
+ function AccountModule() {
109
+ const { addSetting } = useSettingManagement();
110
+
111
+ useEffect(() => {
112
+ addSetting({
113
+ name: 'Account',
114
+ order: 1,
115
+ url: '/settings/account',
116
+ });
117
+ }, [addSetting]);
118
+
119
+ return null;
120
+ }
121
+ ```
122
+
123
+ ## Components
124
+
125
+ ### SettingLayout
126
+
127
+ Layout component for the settings management page with sidebar navigation.
128
+
129
+ ```tsx
130
+ import { SettingLayout } from '@abpjs/setting-management';
131
+
132
+ <SettingLayout
133
+ className="my-settings"
134
+ onTabSelect={(tab) => console.log('Selected:', tab.name)}
135
+ >
136
+ {/* Content renders here */}
137
+ </SettingLayout>
138
+ ```
139
+
140
+ **Props:**
141
+
142
+ | Prop | Type | Required | Description |
143
+ |------|------|----------|-------------|
144
+ | `children` | `ReactNode` | No | Content to render in the main area |
145
+ | `className` | `string` | No | Additional CSS class for the container |
146
+ | `onTabSelect` | `(tab: SettingTab) => void` | No | Callback when a tab is selected |
147
+
148
+ ## Hooks
149
+
150
+ ### useSettingManagement
151
+
152
+ Hook for managing setting tabs and selection state.
153
+
154
+ ```tsx
155
+ import { useSettingManagement } from '@abpjs/setting-management';
156
+
157
+ const {
158
+ settings, // All registered tabs (sorted by order)
159
+ selected, // Currently selected tab
160
+ addSetting, // Add a single setting tab
161
+ addSettings, // Add multiple setting tabs
162
+ removeSetting, // Remove a setting tab by name
163
+ setSelected, // Set the selected tab
164
+ selectByName, // Select a tab by name
165
+ selectByUrl, // Select a tab by URL
166
+ clearSettings, // Clear all registered settings
167
+ } = useSettingManagement();
168
+ ```
169
+
170
+ ## Services
171
+
172
+ ### SettingManagementService
173
+
174
+ Service class for managing setting tabs (singleton pattern).
175
+
176
+ ```tsx
177
+ import { getSettingManagementService } from '@abpjs/setting-management';
178
+
179
+ const service = getSettingManagementService();
180
+
181
+ // Add a setting tab
182
+ service.addSetting({
183
+ name: 'My Settings',
184
+ order: 10,
185
+ url: '/settings/my',
186
+ });
187
+
188
+ // Get all settings
189
+ const allSettings = service.settings;
190
+
191
+ // Subscribe to changes
192
+ const unsubscribe = service.subscribe(() => {
193
+ console.log('Settings changed!');
194
+ });
195
+ ```
196
+
197
+ ## Data Models
198
+
199
+ ### SettingTab
200
+
201
+ The `SettingTab` interface is re-exported from `@abpjs/theme-shared`:
202
+
203
+ ```typescript
204
+ import type { SettingTab } from '@abpjs/setting-management';
205
+
206
+ interface SettingTab {
207
+ name: string; // Display name of the tab
208
+ order: number; // Sort order (lower = higher priority)
209
+ requiredPolicy?: string; // Required permission policy
210
+ url?: string; // URL/route for this tab
211
+ }
212
+ ```
213
+
214
+ ## Constants
215
+
216
+ ### SETTING_MANAGEMENT_ROUTES
217
+
218
+ Default route configuration for the setting management module:
219
+
220
+ ```tsx
221
+ import { SETTING_MANAGEMENT_ROUTES } from '@abpjs/setting-management';
222
+
223
+ // Use in your router configuration
224
+ const routes = [
225
+ ...SETTING_MANAGEMENT_ROUTES.routes,
226
+ // your other routes
227
+ ];
228
+ ```
229
+
230
+ ## Router Setup Example
231
+
232
+ ```tsx
233
+ import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
234
+ import { SettingLayout } from '@abpjs/setting-management';
235
+ import AccountSettings from './AccountSettings';
236
+ import IdentitySettings from './IdentitySettings';
237
+
238
+ function App() {
239
+ return (
240
+ <BrowserRouter>
241
+ <Routes>
242
+ <Route path="/settings" element={<SettingsPage />}>
243
+ <Route index element={<Navigate to="account" replace />} />
244
+ <Route path="account" element={<AccountSettings />} />
245
+ <Route path="identity" element={<IdentitySettings />} />
246
+ </Route>
247
+ </Routes>
248
+ </BrowserRouter>
249
+ );
250
+ }
251
+
252
+ function SettingsPage() {
253
+ const { addSettings } = useSettingManagement();
254
+
255
+ useEffect(() => {
256
+ addSettings([
257
+ { name: 'Account', order: 1, url: '/settings/account' },
258
+ { name: 'Identity', order: 2, url: '/settings/identity' },
259
+ ]);
260
+ }, [addSettings]);
261
+
262
+ return (
263
+ <SettingLayout>
264
+ <Outlet />
265
+ </SettingLayout>
266
+ );
267
+ }
268
+ ```
269
+
270
+ ## Related Packages
271
+
272
+ - [@abpjs/core](https://www.npmjs.com/package/@abpjs/core) - Core infrastructure (required)
273
+ - [@abpjs/theme-shared](https://www.npmjs.com/package/@abpjs/theme-shared) - Shared UI components (required)
274
+ - [@abpjs/account](https://www.npmjs.com/package/@abpjs/account) - Account module (provides account settings)
275
+ - [@abpjs/identity](https://www.npmjs.com/package/@abpjs/identity) - Identity management
276
+
277
+ ## Contributing
278
+
279
+ This package is part of the [ABP React](https://github.com/abpjs/abp-react) monorepo. Contributions are welcome!
280
+
281
+ ## License
282
+
283
+ LGPL-3.0 - See [LICENSE](https://github.com/abpjs/abp-react/blob/main/LICENSE) for details.
284
+
285
+ ---
286
+
287
+ **[View Full Documentation](https://docs.abpjs.io/docs/packages/setting-management/overview)** | **[Report Issues](https://github.com/abpjs/abp-react/issues)** | **[View Source](https://github.com/abpjs/abp-react/tree/main/packages/setting-management)**
@@ -0,0 +1,191 @@
1
+ import { SettingTab } from '@abpjs/theme-shared';
2
+ export { SettingTab } from '@abpjs/theme-shared';
3
+ import { ABP } from '@abpjs/core';
4
+ import React from 'react';
5
+
6
+ /**
7
+ * Setting Management Routes
8
+ * Translated from @abp/ng.setting-management v0.9.0
9
+ */
10
+
11
+ /**
12
+ * Default routes for setting management module
13
+ */
14
+ declare const SETTING_MANAGEMENT_ROUTES: {
15
+ routes: ABP.FullRoute[];
16
+ };
17
+
18
+ /**
19
+ * Setting Management Service
20
+ * Translated from @abp/ng.setting-management v0.9.0
21
+ */
22
+
23
+ /**
24
+ * Service for managing settings tabs and selection.
25
+ * This service maintains the list of registered setting tabs
26
+ * and tracks the currently selected tab.
27
+ */
28
+ declare class SettingManagementService {
29
+ private _settings;
30
+ private _selected;
31
+ private _subscribers;
32
+ /**
33
+ * Get all registered settings tabs sorted by order
34
+ */
35
+ get settings(): SettingTab[];
36
+ /**
37
+ * Get the currently selected setting tab
38
+ */
39
+ get selected(): SettingTab | null;
40
+ /**
41
+ * Register a new setting tab
42
+ * @param tab The setting tab to register
43
+ */
44
+ addSetting(tab: SettingTab): void;
45
+ /**
46
+ * Register multiple setting tabs at once
47
+ * @param tabs Array of setting tabs to register
48
+ */
49
+ addSettings(tabs: SettingTab[]): void;
50
+ /**
51
+ * Remove a setting tab by name
52
+ * @param name The name of the setting tab to remove
53
+ */
54
+ removeSetting(name: string): void;
55
+ /**
56
+ * Set the currently selected setting tab
57
+ * @param tab The tab to select (or null to clear selection)
58
+ */
59
+ setSelected(tab: SettingTab | null): void;
60
+ /**
61
+ * Select a setting tab by name
62
+ * @param name The name of the tab to select
63
+ */
64
+ selectByName(name: string): void;
65
+ /**
66
+ * Select a setting tab by URL
67
+ * @param url The URL of the tab to select
68
+ */
69
+ selectByUrl(url: string): void;
70
+ /**
71
+ * Clear all registered settings
72
+ */
73
+ clearSettings(): void;
74
+ /**
75
+ * Subscribe to changes in settings or selection
76
+ * @param callback Function to call when changes occur
77
+ * @returns Unsubscribe function
78
+ */
79
+ subscribe(callback: () => void): () => void;
80
+ private notifySubscribers;
81
+ }
82
+ /**
83
+ * Get the singleton instance of SettingManagementService
84
+ */
85
+ declare function getSettingManagementService(): SettingManagementService;
86
+
87
+ /**
88
+ * Return type for useSettingManagement hook
89
+ */
90
+ interface UseSettingManagementReturn {
91
+ /** All registered setting tabs sorted by order */
92
+ settings: SettingTab[];
93
+ /** Currently selected setting tab */
94
+ selected: SettingTab | null;
95
+ /** Add a new setting tab */
96
+ addSetting: (tab: SettingTab) => void;
97
+ /** Add multiple setting tabs */
98
+ addSettings: (tabs: SettingTab[]) => void;
99
+ /** Remove a setting tab by name */
100
+ removeSetting: (name: string) => void;
101
+ /** Set the selected setting tab */
102
+ setSelected: (tab: SettingTab | null) => void;
103
+ /** Select a setting tab by name */
104
+ selectByName: (name: string) => void;
105
+ /** Select a setting tab by URL */
106
+ selectByUrl: (url: string) => void;
107
+ /** Clear all registered settings */
108
+ clearSettings: () => void;
109
+ }
110
+ /**
111
+ * Hook for managing settings tabs
112
+ *
113
+ * This hook provides access to the setting management service state
114
+ * and methods for managing setting tabs in a React application.
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * function SettingsPage() {
119
+ * const {
120
+ * settings,
121
+ * selected,
122
+ * setSelected,
123
+ * addSetting,
124
+ * } = useSettingManagement();
125
+ *
126
+ * useEffect(() => {
127
+ * addSetting({
128
+ * name: 'My Settings',
129
+ * order: 1,
130
+ * url: '/settings/my',
131
+ * });
132
+ * }, []);
133
+ *
134
+ * return (
135
+ * <div>
136
+ * {settings.map(tab => (
137
+ * <button
138
+ * key={tab.name}
139
+ * onClick={() => setSelected(tab)}
140
+ * className={selected?.name === tab.name ? 'active' : ''}
141
+ * >
142
+ * {tab.name}
143
+ * </button>
144
+ * ))}
145
+ * </div>
146
+ * );
147
+ * }
148
+ * ```
149
+ */
150
+ declare function useSettingManagement(): UseSettingManagementReturn;
151
+
152
+ /**
153
+ * Setting Layout Component
154
+ * Translated from @abp/ng.setting-management v0.9.0
155
+ */
156
+
157
+ interface SettingLayoutProps {
158
+ /** Optional children to render in the content area */
159
+ children?: React.ReactNode;
160
+ /** Optional callback when tab is selected */
161
+ onTabSelect?: (tab: SettingTab) => void;
162
+ /** Optional CSS class for the container */
163
+ className?: string;
164
+ }
165
+ /**
166
+ * Layout component for the settings management page.
167
+ * Displays a list of setting tabs on the left and content on the right.
168
+ *
169
+ * @example
170
+ * ```tsx
171
+ * function SettingsPage() {
172
+ * const { addSettings } = useSettingManagement();
173
+ *
174
+ * useEffect(() => {
175
+ * addSettings([
176
+ * { name: 'Account', order: 1, url: '/settings/account' },
177
+ * { name: 'Tenant', order: 2, url: '/settings/tenant' },
178
+ * ]);
179
+ * }, []);
180
+ *
181
+ * return (
182
+ * <SettingLayout>
183
+ * <Outlet />
184
+ * </SettingLayout>
185
+ * );
186
+ * }
187
+ * ```
188
+ */
189
+ declare function SettingLayout({ children, onTabSelect, className, }: SettingLayoutProps): React.ReactElement;
190
+
191
+ export { SETTING_MANAGEMENT_ROUTES, SettingLayout, type SettingLayoutProps, SettingManagementService, type UseSettingManagementReturn, getSettingManagementService, useSettingManagement };