@isoftdata/svelte-user-configuration 1.0.27 → 1.0.28

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Svelte UserConfiguration
2
2
 
3
+ This Svelte component provides a user configuration interface, including user account details, site access, group membership, and permissions.
4
+
3
5
  ## Install
4
6
 
5
7
  ```sh
@@ -7,23 +9,140 @@ npm i @isoftdata/svelte-user-configuration
7
9
  ```
8
10
 
9
11
  ## Props
10
- | Name | Type | Description | Default Value |
11
- |------|------|-------------|---------------|
12
- | | | | |
13
- | | | | |
14
- | | | | |
12
+
13
+ ### User Account Properties
14
+
15
+ | Prop | Type | Required | Default | Description |
16
+ |------|------|----------|---------|-------------|
17
+ | `userAccount` | `UserAccount` | ✅ | - | The user account information. |
18
+ | `canToggleActive` | `CanToggleActive` | ❌ | `true` | Whether the user can be activated/deactivated. |
19
+ | `canEditAccountInfo` | `CanEditAccountInfo` | ❌ | `true` | Whether account details can be edited. |
20
+ | `doSendPasswordRecoveryToken` | `DoSendPasswordRecoveryToken` | ❌ | `false` | Whether to allow sending password recovery tokens. |
21
+ | `hasPermissionToChangePassword` | `HasPermissionToChangePassword` | ❌ | `false` | Whether the user has permission to change passwords. |
22
+
23
+ ### Site Access Properties
24
+
25
+ | Prop | Type | Required | Default | Description |
26
+ |------|------|----------|---------|-------------|
27
+ | `userSites` | `UserSites` | ✅ | - | List of sites the user has access to. |
28
+ | `canEditSiteAccess` | `CanEditSiteAccess` | ❌ | `true` | Whether site access can be edited. |
29
+
30
+ ### Group Membership Properties
31
+
32
+ | Prop | Type | Required | Default | Description |
33
+ |------|------|----------|---------|-------------|
34
+ | `groupMembership` | `GroupMembership` | ✅ | - | The user's group membership information. |
35
+ | `canEditGroupMembership` | `CanEditGroupMembership` | ❌ | `true` | Whether group memberships can be edited. |
36
+
37
+ ### Permission List Properties
38
+
39
+ | Prop | Type | Required | Default | Description |
40
+ |------|------|----------|---------|-------------|
41
+ | `permissions` | `Permissions` | ✅ | - | The list of permissions for the user. |
42
+ | `permissionValueMap` | `PermissionValueMap` | ✅ | `new Map()` | A mapping of permissions to their values. |
43
+ | `groupPermissionValueMap` | `GroupPermissionValueMap` | ❌ | `undefined` | A mapping of group-based permissions. |
44
+
45
+ ### Other Properties
46
+
47
+ | Prop | Type | Required | Default | Description |
48
+ |------|------|----------|---------|-------------|
49
+ | `siteLabel` | `SiteLabel` | ❌ | `"Site"` | Label for the site. |
50
+ | `userAccountInfoIcon` | `IconName` | ❌ | `"user"` | Icon for the user account section. |
51
+ | `groupMembershipIcon` | `IconName` | ❌ | `"users"` | Icon for the group membership section. |
52
+ | `permissionListIcon` | `IconName` | ❌ | `"user-lock"` | Icon for the permission list section. |
53
+ | `userSiteAccessIcon` | `IconName` | ❌ | `"industry-windows"` | Icon for the site access section. |
54
+ | `permissionListCardHeaderTitle` | `PermissionListCardHeaderTitle` | ❌ | `"Permissions"` | Title for the permission list card header. |
55
+ | `usernameInput` | `HTMLInputElement \| undefined` | ❌ | `undefined` | Reference to the username input element. |
56
+
57
+ ### Callbacks
58
+
59
+ | Prop | Type | Description |
60
+ |------|------|-------------|
61
+ | `error` | `ErrorFn` | Callback for handling errors. |
62
+ | `success` | `SuccessFn` | Callback for handling success messages. |
63
+ | `deactivateUser` | `DeactivateUserFn` | Function to deactivate a user. |
64
+ | `confirmPasswordSet` | `ConfirmPasswordSetFn` | Function called when a password is set. |
65
+ | `accountInfoChanged` | `AccountInfoChangedFn` | Function called when account info changes. |
66
+ | `sendPasswordRecoveryToken` | `SendPasswordRecoveryTokenFn` | Function to send password recovery token. |
67
+ | `generateNewActivationPIN` | `GenerateNewActivationPINFn` | Function to generate a new activation PIN. |
68
+ | `permissionValueChange` | `PermissionValueChangeFn` | Function called when permissions change. |
69
+ | `siteAccessChange` | `SiteAccessChangeFn` | Function called when site access is changed. |
70
+ | `groupMembershipChange` | `GroupMembershipChangeFn` | Function called when group membership changes. |
15
71
 
16
72
  ## Slots
17
- * default - A brief description of the slot, if there is one
73
+ This component provides named slots for injecting additional content.
18
74
 
19
- ## Events
20
- * exampleEvent - A brief description of the event, if there are any
75
+ | Slot Name | Description |
76
+ |-----------|-------------|
77
+ | `userAccountInfo` | Slot at the end of the `userAccountInfo` component's card body |
78
+ | `siteAccess` | Slot at the end of the `siteAccess` component's card body |
79
+ | `userGroupMembership` | Slot at the end of the `userGroupMembership` component's card body |
80
+ | `permissionList` | Slot at the end of the `permissionList` component's card body |
81
+
82
+ ## Usage Example in Svelte 5 w/ Runes
21
83
 
22
- ## Example
23
84
  ```svelte
24
85
  <script lang="ts">
25
- import UserConfiguration from '@isoftdata/svelte-user-configuration'
86
+ import { UserConfiguration, getGroupHighestPermissionValueMap } from '@isoftdata/svelte-user-configuration'
87
+
88
+ interface Props {
89
+ plants: PlantsForDropdown$result['plants']['data']
90
+ groups: Array<Group>
91
+ permissions: UserConfigurationData$result['permissions']['data']
92
+ userAccount: UserAccount
93
+ permissionValueMap?: PermissionValueMap
94
+ groupPermissionMap?: GroupPermissionMap
95
+ authorizedSitesSet?: any
96
+ groupMembershipSet?: any
97
+ }
98
+
99
+ let {
100
+ plants,
101
+ groups,
102
+ permissions,
103
+ userAccount = $bindable(),
104
+ permissionValueMap = $bindable(new SvelteMap()),
105
+ groupPermissionMap = new SvelteMap(),
106
+ authorizedSitesSet = $bindable(new SvelteSet<number>()),
107
+ groupMembershipSet = $bindable(new SvelteSet<number>()),
108
+ }: Props = $props()
109
+
110
+ let userSites = $derived(
111
+ plants.map(({ id, code, name }) => {
112
+ return { id, code, name, isAuthorized: authorizedSitesSet.has(id) }
113
+ }),
114
+ )
115
+ let groupMembership = $derived(
116
+ groups.map(({ id, name }) => {
117
+ return { id, name, isMember: groupMembershipSet.has(id) }
118
+ }),
119
+ )
120
+ let groupPermissionValueMap = $derived(getGroupHighestPermissionValueMap(groupMembershipSet, groupPermissionMap))
26
121
  </script>
27
122
 
28
- <UserConfiguration prop='foo' />
123
+ <UserConfiguration
124
+ siteLabel="Plant"
125
+ bind:userAccount
126
+ bind:usernameInput
127
+ bind:doSendPasswordRecoveryToken={sendPasswordRecoveryToken}
128
+ {userSites}
129
+ {groupMembership}
130
+ {permissions}
131
+ {permissionValueMap}
132
+ {groupPermissionValueMap}
133
+ siteAccessChange={async site => {
134
+ site.isAuthorized ? authorizedSitesSet.add(site.id) : authorizedSitesSet.delete(site.id)
135
+ authorizedSitesSet = new Set(authorizedSitesSet)
136
+ }}
137
+ groupMembershipChange={async ({ id, isMember }) => {
138
+ isMember ? groupMembershipSet.add(id) : groupMembershipSet.delete(id)
139
+ groupMembershipSet = new Set(groupMembershipSet)
140
+ }}
141
+ permissionValueChange={async ({ permissionIds, value }) => {
142
+ for (const id of permissionIds) {
143
+ permissionValueMap.set(id, value)
144
+ }
145
+ permissionValueMap = new Map(permissionValueMap)
146
+ }}
147
+ />
29
148
  ```
@@ -1,5 +1,6 @@
1
1
  <script>import { getContext, tick } from "svelte";
2
2
  import { klona } from "klona";
3
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
3
4
  import Modal from "@isoftdata/svelte-modal";
4
5
  import TextArea from "@isoftdata/svelte-textarea";
5
6
  let show = false;
@@ -14,7 +15,7 @@ export async function open(userAccountCtx) {
14
15
  await tick();
15
16
  textarea?.select();
16
17
  }
17
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
18
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
18
19
  </script>
19
20
 
20
21
  <Modal
@@ -1,7 +1,8 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import Modal from "@isoftdata/svelte-modal";
3
3
  import Input from "@isoftdata/svelte-input";
4
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
4
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
5
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
5
6
  export let sendPasswordRecoveryToken = void 0;
6
7
  export let doSendPasswordRecoveryToken;
7
8
  let resetDate = void 0;
@@ -1,8 +1,9 @@
1
- <script>import { tick, getContext } from "svelte";
1
+ <script>import { klona } from "klona";
2
+ import { tick, getContext } from "svelte";
2
3
  import Input from "@isoftdata/svelte-input";
3
4
  import Modal from "@isoftdata/svelte-modal";
4
5
  import PasswordFields from "@isoftdata/svelte-password-fields";
5
- import { klona } from "klona";
6
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
6
7
  let show = false;
7
8
  let newPassword = "";
8
9
  let confirmPassword = "";
@@ -22,7 +23,7 @@ export async function open(userAccount) {
22
23
  await tick();
23
24
  input?.focus();
24
25
  }
25
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
26
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
26
27
  </script>
27
28
 
28
29
  <Modal
@@ -5,7 +5,8 @@ import Button from "@isoftdata/svelte-button";
5
5
  import Select from "@isoftdata/svelte-select";
6
6
  import { getEventValue } from "@isoftdata/browser-event";
7
7
  import { Table, Td } from "@isoftdata/svelte-table";
8
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
8
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
9
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
9
10
  export let permissions;
10
11
  export let siteLabel = "Site";
11
12
  export let permissionValueChange = void 0;
@@ -1,13 +1,13 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import Icon from "@isoftdata/svelte-icon";
3
3
  import Input from "@isoftdata/svelte-input";
4
- import { translate as defaultTranslate } from "@isoftdata/utility-string";
5
4
  import Button from "@isoftdata/svelte-button";
6
5
  import TextArea from "@isoftdata/svelte-textarea";
7
6
  import PasswordSetModal from "./PasswordSetModal.svelte";
8
7
  import PasswordFields from "@isoftdata/svelte-password-fields";
9
8
  import DeactivateUserModal from "./DeactivateUserModal.svelte";
10
9
  import PasswordRecoveryModal from "./PasswordRecoveryModal.svelte";
10
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
11
11
  export let userAccount;
12
12
  export let icon = "user";
13
13
  export let canToggleActive = true;
@@ -1,7 +1,8 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import Icon from "@isoftdata/svelte-icon";
3
3
  import Checkbox from "@isoftdata/svelte-checkbox";
4
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
4
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
5
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
5
6
  export let groupMembership;
6
7
  export let canEditGroupMembership = true;
7
8
  export let groupMembershipChange = void 0;
@@ -1,7 +1,8 @@
1
1
  <script>import { getContext } from "svelte";
2
- import Checkbox from "@isoftdata/svelte-checkbox";
3
2
  import Icon from "@isoftdata/svelte-icon";
4
- const { t: translate } = getContext("i18next") || { t: (_key, fallback) => fallback };
3
+ import Checkbox from "@isoftdata/svelte-checkbox";
4
+ import { translate as defaultTranslate } from "@isoftdata/utility-string";
5
+ const { t: translate } = getContext("i18next") || { t: defaultTranslate };
5
6
  export let userSites;
6
7
  export let siteLabel = "Site";
7
8
  export let canEditSiteAccess = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoftdata/svelte-user-configuration",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",