@dropins/storefront-company-management 1.0.0-alpha2005 → 1.0.0-alpha2007

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.
Files changed (103) hide show
  1. package/api/companyRoles/createCompanyRole.d.ts +7 -0
  2. package/api/companyRoles/deleteCompanyRole.d.ts +7 -0
  3. package/api/companyRoles/getCompanyAclResources.d.ts +7 -0
  4. package/api/companyRoles/getCompanyRole.d.ts +8 -0
  5. package/api/companyRoles/getCompanyRoles.d.ts +8 -0
  6. package/api/companyRoles/graphql/fragments.d.ts +18 -0
  7. package/api/{getCompanyRoles → companyRoles/graphql}/index.d.ts +3 -1
  8. package/api/{getCompanyRoles/graphql/getCompanyRoles.graphql.d.ts → companyRoles/graphql/mutations.d.ts} +4 -2
  9. package/api/companyRoles/graphql/queries.d.ts +21 -0
  10. package/api/companyRoles/index.d.ts +27 -0
  11. package/api/companyRoles/isCompanyRoleNameAvailable.d.ts +7 -0
  12. package/api/companyRoles/updateCompanyRole.d.ts +7 -0
  13. package/api/companyRoles/utils.d.ts +11 -0
  14. package/api/getCompanyStructure/graphql/getCompanyStructure.graphql.d.ts +1 -1
  15. package/api/index.d.ts +1 -1
  16. package/api.js +2 -2
  17. package/api.js.map +1 -1
  18. package/chunks/CompanyLoaders.js +4 -0
  19. package/chunks/CompanyLoaders.js.map +1 -0
  20. package/chunks/CompanyUserForm.js +1 -1
  21. package/chunks/CompanyUserForm.js.map +1 -1
  22. package/chunks/Table.js +4 -0
  23. package/chunks/Table.js.map +1 -0
  24. package/chunks/Tree.js +4 -0
  25. package/chunks/Tree.js.map +1 -0
  26. package/chunks/company-permissions.js +1 -1
  27. package/chunks/company-permissions.js.map +1 -1
  28. package/chunks/{network-error.js → fetch-error.js} +2 -2
  29. package/chunks/fetch-error.js.map +1 -0
  30. package/chunks/fetchUserPermissions.js +2 -2
  31. package/chunks/fetchUserPermissions.js.map +1 -1
  32. package/chunks/getCustomerCompany.js +1 -1
  33. package/chunks/getCustomerCompany.js.map +1 -1
  34. package/chunks/isCompanyRoleNameAvailable.js +121 -0
  35. package/chunks/isCompanyRoleNameAvailable.js.map +1 -0
  36. package/chunks/isCompanyUser.js +3 -43
  37. package/chunks/isCompanyUser.js.map +1 -1
  38. package/chunks/transform-store-config.js +44 -0
  39. package/chunks/transform-store-config.js.map +1 -0
  40. package/chunks/updateCompany.js +1 -1
  41. package/chunks/updateCompany.js.map +1 -1
  42. package/chunks/updateCompanyTeam.js +9 -9
  43. package/chunks/updateCompanyTeam.js.map +1 -1
  44. package/chunks/updateCompanyUser.js +6 -23
  45. package/chunks/updateCompanyUser.js.map +1 -1
  46. package/chunks/updateCompanyUserStatus.js +1 -1
  47. package/chunks/updateCompanyUserStatus.js.map +1 -1
  48. package/chunks/useCompanyContextListener.js.map +1 -1
  49. package/chunks/useCompanyContextListener2.js +4 -0
  50. package/chunks/useCompanyContextListener2.js.map +1 -0
  51. package/chunks/useCompanyRoles.js +4 -0
  52. package/chunks/useCompanyRoles.js.map +1 -0
  53. package/chunks/useInLineAlert.js +1 -1
  54. package/chunks/useInLineAlert.js.map +1 -1
  55. package/chunks/validateCompanyEmail.js +2 -2
  56. package/chunks/validateCompanyEmail.js.map +1 -1
  57. package/components/DeleteRoleModal/DeleteRoleModal.d.ts +9 -0
  58. package/{types/api/getCompanyRolesOptions.types.d.ts → components/DeleteRoleModal/index.d.ts} +3 -5
  59. package/components/EditRoleAndPermission/EditRoleAndPermission.d.ts +24 -0
  60. package/{types/api/getCompanyRolesResponse.types.d.ts → components/EditRoleAndPermission/index.d.ts} +3 -17
  61. package/components/RoleAndPermissionTable/RoleAndPermissionTable.d.ts +20 -0
  62. package/components/RoleAndPermissionTable/index.d.ts +19 -0
  63. package/components/Tree/Tree.d.ts +2 -0
  64. package/components/index.d.ts +4 -1
  65. package/containers/CompanyProfile.js +1 -1
  66. package/containers/CompanyProfile.js.map +1 -1
  67. package/containers/CompanyRegistration.js +1 -1
  68. package/containers/CompanyRegistration.js.map +1 -1
  69. package/containers/CompanyStructure.js +1 -1
  70. package/containers/CompanyStructure.js.map +1 -1
  71. package/containers/CompanyUsers/hooks/index.d.ts +19 -0
  72. package/containers/CompanyUsers/hooks/useCompanyContextListener.d.ts +62 -0
  73. package/containers/CompanyUsers/hooks.d.ts +1 -0
  74. package/containers/CompanyUsers/hooks.js +4 -0
  75. package/containers/CompanyUsers/hooks.js.map +1 -0
  76. package/containers/CompanyUsers.js +1 -1
  77. package/containers/CompanyUsers.js.map +1 -1
  78. package/containers/CustomerCompanyInfo.js +1 -1
  79. package/containers/CustomerCompanyInfo.js.map +1 -1
  80. package/containers/RolesAndPermissions/RolesAndPermissions.d.ts +8 -0
  81. package/containers/RolesAndPermissions/index.d.ts +19 -0
  82. package/containers/RolesAndPermissions.d.ts +3 -0
  83. package/containers/RolesAndPermissions.js +4 -0
  84. package/containers/RolesAndPermissions.js.map +1 -0
  85. package/containers/index.d.ts +1 -0
  86. package/data/models/company-role.d.ts +27 -14
  87. package/data/models/company.d.ts +4 -2
  88. package/data/transforms/transform-company-roles.d.ts +13 -7
  89. package/data/transforms/transform-company-structure.d.ts +2 -1
  90. package/hooks/index.d.ts +1 -0
  91. package/hooks/useCompanyRoles.d.ts +24 -4
  92. package/hooks/useUserPermissions.d.ts +26 -0
  93. package/i18n/en_US.json.d.ts +71 -2
  94. package/lib/company-permissions.d.ts +5 -0
  95. package/package.json +1 -1
  96. package/render.js +9 -6
  97. package/render.js.map +1 -1
  98. package/types/api/companyRoles.types.d.ts +137 -0
  99. package/types/api/index.d.ts +0 -2
  100. package/types/companyPermission.types.d.ts +2 -0
  101. package/types/companyStructure.types.d.ts +3 -0
  102. package/api/getCompanyRoles/getCompanyRoles.d.ts +0 -12
  103. package/chunks/network-error.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ import { CompanyRoleModel, CompanyRoleCreateInputModel } from '../../data/models/company-role';
2
+
3
+ /**
4
+ * Create a new company role
5
+ */
6
+ export declare const createCompanyRole: (input: CompanyRoleCreateInputModel) => Promise<CompanyRoleModel>;
7
+ //# sourceMappingURL=createCompanyRole.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { DeleteCompanyRoleVariables } from '../../types/api/companyRoles.types';
2
+
3
+ /**
4
+ * Delete a company role
5
+ */
6
+ export declare const deleteCompanyRole: (variables: DeleteCompanyRoleVariables) => Promise<boolean>;
7
+ //# sourceMappingURL=deleteCompanyRole.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { CompanyAclResourceModel } from '../../data/models/company-role';
2
+
3
+ /**
4
+ * Fetch all available ACL resources (permissions)
5
+ */
6
+ export declare const getCompanyAclResources: () => Promise<CompanyAclResourceModel[]>;
7
+ //# sourceMappingURL=getCompanyAclResources.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { GetCompanyRoleVariables } from '../../types/api/companyRoles.types';
2
+ import { CompanyRoleModel } from '../../data/models/company-role';
3
+
4
+ /**
5
+ * Fetch a single company role by ID
6
+ */
7
+ export declare const getCompanyRole: (variables: GetCompanyRoleVariables) => Promise<CompanyRoleModel>;
8
+ //# sourceMappingURL=getCompanyRole.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { GetCompanyRolesVariables } from '../../types/api/companyRoles.types';
2
+ import { CompanyRolesResponseModel } from '../../data/models/company-role';
3
+
4
+ /**
5
+ * Fetch all company roles with pagination
6
+ */
7
+ export declare const getCompanyRoles: (variables?: GetCompanyRolesVariables) => Promise<CompanyRolesResponseModel>;
8
+ //# sourceMappingURL=getCompanyRoles.d.ts.map
@@ -0,0 +1,18 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+ export declare const COMPANY_ROLE_FRAGMENT = "\n fragment CompanyRoleFragment on CompanyRole {\n id\n name\n users_count\n permissions {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n }\n }\n }\n }\n }\n }\n";
18
+ //# sourceMappingURL=fragments.d.ts.map
@@ -14,5 +14,7 @@
14
14
  * is strictly forbidden unless prior written permission is obtained
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
- export * from './getCompanyRoles';
17
+ export * from './fragments';
18
+ export * from './queries';
19
+ export * from './mutations';
18
20
  //# sourceMappingURL=index.d.ts.map
@@ -14,5 +14,7 @@
14
14
  * is strictly forbidden unless prior written permission is obtained
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
- export declare const GET_COMPANY_ROLES = "\n query getCompanyRoles($pageSize: Int, $currentPage: Int) {\n company {\n roles(pageSize: $pageSize, currentPage: $currentPage) {\n items {\n id\n name\n }\n total_count\n page_info {\n current_page\n page_size\n total_pages\n }\n }\n }\n }\n";
18
- //# sourceMappingURL=getCompanyRoles.graphql.d.ts.map
17
+ export declare const CREATE_COMPANY_ROLE: string;
18
+ export declare const UPDATE_COMPANY_ROLE: string;
19
+ export declare const DELETE_COMPANY_ROLE = "\n mutation DeleteCompanyRole($id: ID!) {\n deleteCompanyRole(id: $id) {\n success\n }\n }\n";
20
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1,21 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+ export declare const GET_COMPANY_ROLES: string;
18
+ export declare const GET_COMPANY_ROLE: string;
19
+ export declare const GET_COMPANY_ACL_RESOURCES = "\n query GetCompanyAclResources {\n company {\n acl_resources {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n children {\n id\n text\n sort_order\n }\n }\n }\n }\n }\n }\n }\n";
20
+ export declare const IS_COMPANY_ROLE_NAME_AVAILABLE = "\n query IsCompanyRoleNameAvailable($name: String!) {\n isCompanyRoleNameAvailable(name: $name) {\n is_role_name_available\n }\n }\n";
21
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1,27 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+ export { getCompanyRoles } from './getCompanyRoles';
18
+ export { getCompanyRole } from './getCompanyRole';
19
+ export { getCompanyAclResources } from './getCompanyAclResources';
20
+ export { createCompanyRole } from './createCompanyRole';
21
+ export { updateCompanyRole } from './updateCompanyRole';
22
+ export { deleteCompanyRole } from './deleteCompanyRole';
23
+ export { isCompanyRoleNameAvailable } from './isCompanyRoleNameAvailable';
24
+ export { flattenPermissionIds, buildPermissionTree } from './utils';
25
+ export type { CompanyAclResourceModel, CompanyRoleModel, PageInfoModel, CompanyRolesResponseModel, CompanyRoleCreateInputModel, CompanyRoleUpdateInputModel, } from '../../data/models/company-role';
26
+ export type { GetCompanyRolesVariables, GetCompanyRoleVariables, DeleteCompanyRoleVariables, IsCompanyRoleNameAvailableVariables, } from '../../types/api/companyRoles.types';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { IsCompanyRoleNameAvailableVariables } from '../../types/api/companyRoles.types';
2
+
3
+ /**
4
+ * Check if a role name is available
5
+ */
6
+ export declare const isCompanyRoleNameAvailable: (variables: IsCompanyRoleNameAvailableVariables) => Promise<boolean>;
7
+ //# sourceMappingURL=isCompanyRoleNameAvailable.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { CompanyRoleModel, CompanyRoleUpdateInputModel } from '../../data/models/company-role';
2
+
3
+ /**
4
+ * Update an existing company role
5
+ */
6
+ export declare const updateCompanyRole: (input: CompanyRoleUpdateInputModel) => Promise<CompanyRoleModel>;
7
+ //# sourceMappingURL=updateCompanyRole.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { CompanyAclResourceModel } from '../../data/models/company-role';
2
+
3
+ /**
4
+ * Helper function to flatten ACL resources into a list of permission IDs
5
+ */
6
+ export declare const flattenPermissionIds: (resources: CompanyAclResourceModel[]) => string[];
7
+ /**
8
+ * Helper function to build a permission tree from flat permission IDs
9
+ */
10
+ export declare const buildPermissionTree: (allResources: CompanyAclResourceModel[], selectedIds: string[]) => CompanyAclResourceModel[];
11
+ //# sourceMappingURL=utils.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * is strictly forbidden unless prior written permission is obtained
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
- export declare const GET_COMPANY_STRUCTURE = "\n query getCompanyStructure {\n company {\n structure {\n items {\n id\n parent_id\n entity {\n __typename\n ... on CompanyTeam { id structure_id name description }\n ... on Customer { id structure_id firstname lastname }\n }\n }\n }\n }\n }\n";
17
+ export declare const GET_COMPANY_STRUCTURE = "\n query getCompanyStructure {\n company {\n structure {\n items {\n id\n parent_id\n entity {\n __typename\n ... on CompanyTeam { companyTeamId: id structure_id name description }\n ... on Customer { customerId: id structure_id firstname lastname }\n }\n }\n }\n }\n }\n";
18
18
  //# sourceMappingURL=getCompanyStructure.graphql.d.ts.map
package/api/index.d.ts CHANGED
@@ -25,7 +25,6 @@ export * from './createCompanyUser';
25
25
  export * from './deleteCompanyTeam';
26
26
  export * from './deleteCompanyUser';
27
27
  export * from './getCompany';
28
- export * from './getCompanyRoles';
29
28
  export * from './getCompanyStructure';
30
29
  export * from './getCompanyTeam';
31
30
  export * from './getCompanyUser';
@@ -42,4 +41,5 @@ export * from './updateCompanyTeam';
42
41
  export * from './updateCompanyUser';
43
42
  export * from './updateCompanyUserStatus';
44
43
  export * from './validateCompanyEmail';
44
+ export * from './companyRoles';
45
45
  //# sourceMappingURL=index.d.ts.map
package/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{f as n}from"./chunks/network-error.js";import{g,r as E,s as T,a as h,b as S}from"./chunks/network-error.js";import{f as _}from"./chunks/fetchUserPermissions.js";import{D as O,S as A,a as R,c as G,g as F,i as b}from"./chunks/isCompanyUser.js";import{c as I,g as v}from"./chunks/getCustomerCompany.js";import{c as M,d as N,a as P,g as Q,b as D,u as w}from"./chunks/updateCompanyTeam.js";import{c as k,d as q,a as z,g as Y,i as j,u as B}from"./chunks/updateCompanyUser.js";import{g as K,u as V}from"./chunks/updateCompany.js";import{g as Z,u as $}from"./chunks/updateCompanyUserStatus.js";import{g as ae,v as re}from"./chunks/validateCompanyEmail.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/event-bus.js";import"./chunks/company-permissions.js";const y=async(a={})=>({success:!0,config:a}),p=`
3
+ import{f as m,a as i}from"./chunks/fetch-error.js";import{g as x,r as O,s as G,b,c as I}from"./chunks/fetch-error.js";import{f as P}from"./chunks/fetchUserPermissions.js";import{a as v,i as w}from"./chunks/isCompanyUser.js";import{c as L,g as M}from"./chunks/getCustomerCompany.js";import{D,S as k,c as W,g as Y}from"./chunks/transform-store-config.js";import{c as z,d as j,g as B,a as J,u as K,b as V}from"./chunks/updateCompanyTeam.js";import{c as Z,a as $,g as ee,i as ae,u as re}from"./chunks/updateCompanyUser.js";import{g as oe,u as se}from"./chunks/updateCompany.js";import{g as me,u as pe}from"./chunks/updateCompanyUserStatus.js";import{g as ce,v as le}from"./chunks/validateCompanyEmail.js";import{G as c,t as l}from"./chunks/isCompanyRoleNameAvailable.js";import{c as ye,d as Ce,a as fe,g as de,i as ge,u as he}from"./chunks/isCompanyRoleNameAvailable.js";import{a as u}from"./chunks/company-permissions.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/event-bus.js";const E=async e=>{try{const r=await m(c,{variables:e,method:"GET",cache:"no-cache"});return l(r)}catch(r){return i(r)}},T=e=>u(e),R=(e,r)=>{const n=new Set(r),o=a=>{var t;const s=((t=a.children)==null?void 0:t.map(o).filter(p=>p!==null))||[];return n.has(a.id)||s.length>0?{...a,children:s}:null};return e.map(o).filter(a=>a!==null)},S=async(e={})=>({success:!0,config:e}),y=`
4
4
  query GET_CUSTOMER_COMPANIES_WITH_ROLES {
5
5
  customer {
6
6
  companies(input: {}) {
@@ -15,5 +15,5 @@ import{f as n}from"./chunks/network-error.js";import{g,r as E,s as T,a as h,b as
15
15
  }
16
16
  }
17
17
  }
18
- `,f=async()=>{var a,t,o;try{const r=await n(p,{method:"POST"});if((a=r.errors)!=null&&a.length)return!1;const s=(t=r.data)==null?void 0:t.customer;if(!s)return!1;const m=((o=s.companies)==null?void 0:o.items)??[];if(!Array.isArray(m)||m.length===0)return!1;const e=s.role;return e?e.id==="0"||typeof e.id=="number"&&e.id===0||e.name==="Company Administrator":!1}catch(r){return console.error("Error checking if customer is company admin:",r),!1}};export{O as DEFAULT_COUNTRY,A as STORE_CONFIG_DEFAULTS,R as allowCompanyRegistration,I as companyEnabled,G as createCompany,M as createCompanyTeam,k as createCompanyUser,N as deleteCompanyTeam,q as deleteCompanyUser,n as fetchGraphQl,_ as fetchUserPermissions,K as getCompany,z as getCompanyRoles,P as getCompanyStructure,Q as getCompanyTeam,Y as getCompanyUser,Z as getCompanyUsers,g as getConfig,ae as getCountries,v as getCustomerCompany,F as getStoreConfig,y as initialize,f as isCompanyAdmin,b as isCompanyUser,j as isCompanyUserEmailAvailable,E as removeFetchGraphQlHeader,T as setEndpoint,h as setFetchGraphQlHeader,S as setFetchGraphQlHeaders,V as updateCompany,D as updateCompanyStructure,w as updateCompanyTeam,B as updateCompanyUser,$ as updateCompanyUserStatus,re as validateCompanyEmail};
18
+ `,U=async()=>{var e,r,n;try{const o=await m(y,{method:"POST"});if((e=o.errors)!=null&&e.length)return!1;const a=(r=o.data)==null?void 0:r.customer;if(!a)return!1;const s=((n=a.companies)==null?void 0:n.items)??[];if(!Array.isArray(s)||s.length===0)return!1;const t=a.role;return t?t.id==="0"||typeof t.id=="number"&&t.id===0||t.name==="Company Administrator":!1}catch(o){return console.error("Error checking if customer is company admin:",o),!1}};export{D as DEFAULT_COUNTRY,k as STORE_CONFIG_DEFAULTS,v as allowCompanyRegistration,R as buildPermissionTree,L as companyEnabled,W as createCompany,ye as createCompanyRole,z as createCompanyTeam,Z as createCompanyUser,Ce as deleteCompanyRole,j as deleteCompanyTeam,$ as deleteCompanyUser,m as fetchGraphQl,P as fetchUserPermissions,T as flattenPermissionIds,oe as getCompany,fe as getCompanyAclResources,E as getCompanyRole,de as getCompanyRoles,B as getCompanyStructure,J as getCompanyTeam,ee as getCompanyUser,me as getCompanyUsers,x as getConfig,ce as getCountries,M as getCustomerCompany,Y as getStoreConfig,S as initialize,U as isCompanyAdmin,ge as isCompanyRoleNameAvailable,w as isCompanyUser,ae as isCompanyUserEmailAvailable,O as removeFetchGraphQlHeader,G as setEndpoint,b as setFetchGraphQlHeader,I as setFetchGraphQlHeaders,se as updateCompany,he as updateCompanyRole,K as updateCompanyStructure,V as updateCompanyTeam,re as updateCompanyUser,pe as updateCompanyUserStatus,le as validateCompanyEmail};
19
19
  //# sourceMappingURL=api.js.map
package/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["/@dropins/storefront-company-management/src/api/initialize/initialize.ts","/@dropins/storefront-company-management/src/api/isCompanyAdmin/graphql/isCompanyAdmin.graphql.ts","/@dropins/storefront-company-management/src/api/isCompanyAdmin/isCompanyAdmin.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n// import { events } from '@adobe-commerce/event-bus';\n\n\nimport { CompanyDropinConfig } from '../../types/api/initialize.types';\n\nexport const initialize = async (config: CompanyDropinConfig = {}) => {\n return {\n success: true,\n config,\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const GET_CUSTOMER_COMPANIES_WITH_ROLES = /* GraphQL */ `\n query GET_CUSTOMER_COMPANIES_WITH_ROLES {\n customer {\n companies(input: {}) {\n items {\n id\n name\n }\n }\n role {\n id\n name\n }\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n \nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_CUSTOMER_COMPANIES_WITH_ROLES } from './graphql/isCompanyAdmin.graphql';\n\ninterface CompanyRole {\n id: string;\n name: string;\n}\n\ninterface CompanyBasicInfo {\n id: string;\n name: string;\n}\n\ninterface CustomerCompaniesWithRolesResponse {\n customer: {\n companies: {\n items: CompanyBasicInfo[];\n };\n role: CompanyRole | null;\n } | null;\n}\n\n/**\n * Check if the current authenticated customer is a company administrator in any company\n * @returns Promise<boolean> - true if customer is a company admin in at least one company, false otherwise\n */\nexport const isCompanyAdmin = async (): Promise<boolean> => {\n try {\n const response = await fetchGraphQl<CustomerCompaniesWithRolesResponse>(GET_CUSTOMER_COMPANIES_WITH_ROLES, {\n method: 'POST',\n });\n\n if (response.errors?.length) {\n return false;\n }\n\n const customer = response.data?.customer;\n if (!customer) {\n return false;\n }\n\n // Check if user is part of at least one company\n const companies = customer.companies?.items ?? [];\n if (!Array.isArray(companies) || companies.length === 0) {\n return false;\n }\n\n // Check if user has admin role\n const customerRole = customer.role;\n if (!customerRole) {\n return false;\n }\n\n // Check if user is company administrator by role ID or name\n return customerRole.id === '0' || \n (typeof customerRole.id === 'number' && customerRole.id === 0) ||\n customerRole.name === 'Company Administrator';\n } catch (error) {\n console.error('Error checking if customer is company admin:', error);\n return false;\n }\n};\n"],"names":["initialize","config","GET_CUSTOMER_COMPANIES_WITH_ROLES","isCompanyAdmin","response","fetchGraphQl","_a","customer","_b","companies","_c","customerRole","error"],"mappings":"mwBAsBO,MAAMA,EAAa,MAAOC,EAA8B,MACtD,CACL,QAAS,GACT,OAAAA,CACF,GCTWC,EAAkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EC0BlDC,EAAiB,SAA8B,WACtD,GAAA,CACI,MAAAC,EAAW,MAAMC,EAAiDH,EAAmC,CACzG,OAAQ,MAAA,CACT,EAEG,IAAAI,EAAAF,EAAS,SAAT,MAAAE,EAAiB,OACZ,MAAA,GAGH,MAAAC,GAAWC,EAAAJ,EAAS,OAAT,YAAAI,EAAe,SAChC,GAAI,CAACD,EACI,MAAA,GAIT,MAAME,IAAYC,EAAAH,EAAS,YAAT,YAAAG,EAAoB,QAAS,CAAC,EAChD,GAAI,CAAC,MAAM,QAAQD,CAAS,GAAKA,EAAU,SAAW,EAC7C,MAAA,GAIT,MAAME,EAAeJ,EAAS,KAC9B,OAAKI,EAKEA,EAAa,KAAO,KACnB,OAAOA,EAAa,IAAO,UAAYA,EAAa,KAAO,GAC5DA,EAAa,OAAS,wBANpB,SAOFC,EAAO,CACN,eAAA,MAAM,+CAAgDA,CAAK,EAC5D,EAAA,CAEX"}
1
+ {"version":3,"file":"api.js","sources":["/@dropins/storefront-company-management/src/api/companyRoles/getCompanyRole.ts","/@dropins/storefront-company-management/src/api/companyRoles/utils.ts","/@dropins/storefront-company-management/src/api/initialize/initialize.ts","/@dropins/storefront-company-management/src/api/isCompanyAdmin/graphql/isCompanyAdmin.graphql.ts","/@dropins/storefront-company-management/src/api/isCompanyAdmin/isCompanyAdmin.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { fetchGraphQl } from '../fetch-graphql';\nimport { handleNetworkError } from '../../lib/network-error';\nimport { GET_COMPANY_ROLE } from './graphql/queries';\nimport { GetCompanyRoleVariables, GetCompanyRoleResponse } from '../../types/api/companyRoles.types';\nimport { CompanyRoleModel } from '../../data/models/company-role';\nimport { transformGetCompanyRoleResponse } from '../../data/transforms/transform-company-roles';\n\n/**\n * Fetch a single company role by ID\n */\nexport const getCompanyRole = async (\n variables: GetCompanyRoleVariables\n): Promise<CompanyRoleModel> => {\n try {\n const response: GetCompanyRoleResponse = await fetchGraphQl(GET_COMPANY_ROLE, {\n variables,\n method: 'GET',\n cache: 'no-cache',\n });\n\n return transformGetCompanyRoleResponse(response);\n } catch (error) {\n return handleNetworkError(error as Error);\n }\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { flattenIdsToArray } from '../../lib/company-permissions';\nimport { CompanyAclResourceModel } from '../../data/models/company-role';\n\n/**\n * Helper function to flatten ACL resources into a list of permission IDs\n */\nexport const flattenPermissionIds = (resources: CompanyAclResourceModel[]): string[] => {\n return flattenIdsToArray(resources);\n};\n\n/**\n * Helper function to build a permission tree from flat permission IDs\n */\nexport const buildPermissionTree = (\n allResources: CompanyAclResourceModel[],\n selectedIds: string[]\n): CompanyAclResourceModel[] => {\n const selectedSet = new Set(selectedIds);\n \n const filterTree = (resource: CompanyAclResourceModel): CompanyAclResourceModel | null => {\n const filteredChildren = resource.children\n ?.map(filterTree)\n .filter((child): child is CompanyAclResourceModel => child !== null) || [];\n \n if (selectedSet.has(resource.id) || filteredChildren.length > 0) {\n return {\n ...resource,\n children: filteredChildren,\n };\n }\n \n return null;\n };\n \n return allResources\n .map(filterTree)\n .filter((resource): resource is CompanyAclResourceModel => resource !== null);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n// import { events } from '@adobe-commerce/event-bus';\n\n\nimport { CompanyDropinConfig } from '../../types/api/initialize.types';\n\nexport const initialize = async (config: CompanyDropinConfig = {}) => {\n return {\n success: true,\n config,\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const GET_CUSTOMER_COMPANIES_WITH_ROLES = /* GraphQL */ `\n query GET_CUSTOMER_COMPANIES_WITH_ROLES {\n customer {\n companies(input: {}) {\n items {\n id\n name\n }\n }\n role {\n id\n name\n }\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n \nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_CUSTOMER_COMPANIES_WITH_ROLES } from './graphql/isCompanyAdmin.graphql';\n\ninterface CompanyRole {\n id: string;\n name: string;\n}\n\ninterface CompanyBasicInfo {\n id: string;\n name: string;\n}\n\ninterface CustomerCompaniesWithRolesResponse {\n customer: {\n companies: {\n items: CompanyBasicInfo[];\n };\n role: CompanyRole | null;\n } | null;\n}\n\n/**\n * Check if the current authenticated customer is a company administrator in any company\n * @returns Promise<boolean> - true if customer is a company admin in at least one company, false otherwise\n */\nexport const isCompanyAdmin = async (): Promise<boolean> => {\n try {\n const response = await fetchGraphQl<CustomerCompaniesWithRolesResponse>(GET_CUSTOMER_COMPANIES_WITH_ROLES, {\n method: 'POST',\n });\n\n if (response.errors?.length) {\n return false;\n }\n\n const customer = response.data?.customer;\n if (!customer) {\n return false;\n }\n\n // Check if user is part of at least one company\n const companies = customer.companies?.items ?? [];\n if (!Array.isArray(companies) || companies.length === 0) {\n return false;\n }\n\n // Check if user has admin role\n const customerRole = customer.role;\n if (!customerRole) {\n return false;\n }\n\n // Check if user is company administrator by role ID or name\n return customerRole.id === '0' || \n (typeof customerRole.id === 'number' && customerRole.id === 0) ||\n customerRole.name === 'Company Administrator';\n } catch (error) {\n console.error('Error checking if customer is company admin:', error);\n return false;\n }\n};\n"],"names":["getCompanyRole","variables","response","fetchGraphQl","GET_COMPANY_ROLE","transformGetCompanyRoleResponse","error","handleNetworkError","flattenPermissionIds","resources","flattenIdsToArray","buildPermissionTree","allResources","selectedIds","selectedSet","filterTree","resource","filteredChildren","_a","child","initialize","config","GET_CUSTOMER_COMPANIES_WITH_ROLES","isCompanyAdmin","customer","_b","companies","_c","customerRole"],"mappings":"m+BA2Ba,MAAAA,EAAiB,MAC5BC,GAC8B,CAC1B,GAAA,CACI,MAAAC,EAAmC,MAAMC,EAAaC,EAAkB,CAC5E,UAAAH,EACA,OAAQ,MACR,MAAO,UAAA,CACR,EAED,OAAOI,EAAgCH,CAAQ,QACxCI,EAAO,CACd,OAAOC,EAAmBD,CAAc,CAAA,CAE5C,EClBaE,EAAwBC,GAC5BC,EAAkBD,CAAS,EAMv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import{Skeleton as t,SkeletonRow as a,Card as n}from"@dropins/tools/components.js";import{classes as o}from"@dropins/tools/lib.js";const u=({testId:r,withCard:l=!0})=>{const i=s(t,{"data-testid":r||"companySkeletonLoader",children:[e(a,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),e(a,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return l?i:e(n,{variant:"secondary",className:o(["company-company-loaders","company-company-loaders--card-loader"]),children:i})},p=({testId:r})=>e("div",{className:"company-users-skeleton-loader","data-testid":r||"companyUsersSkeletonLoader",children:e(t,{children:e(a,{variant:"row",size:"small",fullWidth:!0,lines:3})})}),g=({rows:r=6})=>s(t,{"data-testid":"companyStructureLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),Array.from({length:r}).map((l,i)=>e(a,{size:"large",fullWidth:!0},i))]}),h=()=>s(t,{"data-testid":"companyUserFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"}),e(a,{size:"large"})]}),z=()=>s(t,{"data-testid":"companyTeamFormLoader",children:[e(a,{variant:"heading",size:"medium"}),e(a,{variant:"empty",size:"small"}),e(a,{size:"large"}),e(a,{size:"large",fullWidth:!0}),e(a,{size:"large"})]});export{h as C,p as a,u as b,z as c,g as d};
4
+ //# sourceMappingURL=CompanyLoaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompanyLoaders.js","sources":["/@dropins/storefront-company-management/src/components/CompanyLoaders/CompanyLoaders.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { Skeleton, SkeletonRow, Card } from '@adobe-commerce/elsie/components';\nimport './CompanyLoaders.css';\nimport { classes } from '@adobe-commerce/elsie/lib';\n\nexport const CompanyCardLoader = ({\n testId,\n withCard = true,\n}: {\n testId?: string;\n withCard?: boolean;\n}) => {\n const defaultSkeleton = (\n <Skeleton data-testid={testId || 'companySkeletonLoader'}>\n <SkeletonRow\n variant=\"heading\"\n size=\"xlarge\"\n fullWidth={false}\n lines={1}\n />\n <SkeletonRow variant=\"heading\" size=\"xlarge\" fullWidth={true} lines={1} />\n <SkeletonRow variant=\"heading\" size=\"xlarge\" fullWidth={true} lines={1} />\n </Skeleton>\n );\n\n if (withCard) {\n return defaultSkeleton;\n }\n\n return (\n <Card\n variant=\"secondary\"\n className={classes([\n 'company-company-loaders',\n 'company-company-loaders--card-loader',\n ])}\n >\n {defaultSkeleton}\n </Card>\n );\n};\n\nexport const CompanyUsersTableLoader = ({ testId }: { testId?: string }) => {\n return (\n <div className=\"company-users-skeleton-loader\" data-testid={testId || 'companyUsersSkeletonLoader'}>\n <Skeleton>\n <SkeletonRow variant=\"row\" size=\"small\" fullWidth={true} lines={3} />\n </Skeleton>\n </div>\n );\n};\n\nexport const CompanyStructureLoader = ({ rows = 6 }: { rows?: number }) => {\n return (\n <Skeleton data-testid=\"companyStructureLoader\">\n <SkeletonRow variant=\"heading\" size=\"medium\" />\n <SkeletonRow variant=\"empty\" size=\"small\" />\n {Array.from({ length: rows }).map((_, i) => (\n <SkeletonRow key={i} size=\"large\" fullWidth={true} />\n ))}\n </Skeleton>\n );\n};\n\nexport const CompanyUserFormLoader = () => {\n return (\n <Skeleton data-testid=\"companyUserFormLoader\">\n <SkeletonRow variant=\"heading\" size=\"medium\" />\n <SkeletonRow variant=\"empty\" size=\"small\" />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" fullWidth={true} />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" />\n </Skeleton>\n );\n};\n\nexport const CompanyTeamFormLoader = () => {\n return (\n <Skeleton data-testid=\"companyTeamFormLoader\">\n <SkeletonRow variant=\"heading\" size=\"medium\" />\n <SkeletonRow variant=\"empty\" size=\"small\" />\n <SkeletonRow size=\"large\" />\n <SkeletonRow size=\"large\" fullWidth={true} />\n <SkeletonRow size=\"large\" />\n </Skeleton>\n );\n};\n"],"names":["CompanyCardLoader","testId","withCard","defaultSkeleton","jsxs","Skeleton","jsx","SkeletonRow","Card","classes","CompanyUsersTableLoader","CompanyStructureLoader","rows","_","CompanyUserFormLoader","CompanyTeamFormLoader"],"mappings":"wMAoBO,MAAMA,EAAoB,CAAC,CAChC,OAAAC,EACA,SAAAC,EAAW,EACb,IAGM,CACJ,MAAMC,EACJC,EAACC,EAAS,CAAA,cAAaJ,GAAU,wBAC/B,SAAA,CAAAK,EAACC,EAAA,CACC,QAAQ,UACR,KAAK,SACL,UAAW,GACX,MAAO,CAAA,CACT,EACAD,EAACC,GAAY,QAAQ,UAAU,KAAK,SAAS,UAAW,GAAM,MAAO,CAAG,CAAA,EACxED,EAACC,GAAY,QAAQ,UAAU,KAAK,SAAS,UAAW,GAAM,MAAO,CAAG,CAAA,CAAA,EAC1E,EAGF,OAAIL,EACKC,EAIPG,EAACE,EAAA,CACC,QAAQ,YACR,UAAWC,EAAQ,CACjB,0BACA,sCAAA,CACD,EAEA,SAAAN,CAAA,CACH,CAEJ,EAEaO,EAA0B,CAAC,CAAE,OAAAT,KAEtCK,EAAC,OAAI,UAAU,gCAAgC,cAAaL,GAAU,6BAClE,WAACI,EACC,CAAA,SAAAC,EAACC,GAAY,QAAQ,MAAM,KAAK,QAAQ,UAAW,GAAM,MAAO,EAAG,EACrE,C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served. */
3
- import{jsxs as B,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as G}from"@dropins/tools/preact-compat.js";import{useState as m,useEffect as O}from"@dropins/tools/preact-hooks.js";import{Card as D,InLineAlert as H,ProgressSpinner as J,Field as _,Input as q,Picker as z,Button as $}from"@dropins/tools/components.js";import{i as K}from"./company-permissions.js";import{g as Q,c as W,u as X,i as Y,a as Z}from"./updateCompanyUser.js";import{useText as L}from"@dropins/tools/i18n.js";import{c as ee}from"./useInLineAlert.js";function te(b){const{mode:N,entityId:p,parentStructureId:g,onSaved:E}=b,c=L({firstNameRequired:"Company.CompanyStructure.shared.validation.firstNameRequired",lastNameRequired:"Company.CompanyStructure.shared.validation.lastNameRequired",emailRequired:"Company.CompanyStructure.shared.validation.emailRequired",emailInvalid:"Company.CompanyStructure.shared.validation.emailInvalid",jobTitleRequired:"Company.CompanyStructure.shared.validation.jobTitleRequired",workPhoneRequired:"Company.CompanyStructure.shared.validation.workPhoneRequired",selectRole:"Company.CompanyStructure.shared.validation.selectRole",createUserError:"Company.CompanyStructure.messages.createUserError",saveUserError:"Company.CompanyStructure.messages.saveUserError"}),[r,y]=m({firstName:"",lastName:"",email:"",jobTitle:"",telephone:"",roleId:"",status:"ACTIVE"}),[R,d]=m({}),[n,f]=m({}),[w,A]=m(!1),[C,U]=m(null),[T,j]=m(null),[I,x]=m(""),[l,t]=m(""),[i,V]=m(!1);O(()=>{N!=="edit"||!p||(A(!0),Q(p).then(e=>{var h;if(!e)return;const a=e.email||"";y(S=>({...S,firstName:e.firstName||"",lastName:e.lastName||"",email:a,jobTitle:e.jobTitle||"",telephone:e.telephone||"",status:e.status||"ACTIVE"})),t(a),(h=e==null?void 0:e.role)!=null&&h.id&&y(S=>({...S,roleId:e.role.id})),V((e==null?void 0:e.isCompanyAdmin)??!1)}).finally(()=>A(!1)))},[N,p]);const P=e=>/.+@.+\..+/.test(e),F=(e,a)=>e==="firstName"?a!=null&&a.trim()?null:c.firstNameRequired:e==="lastName"?a!=null&&a.trim()?null:c.lastNameRequired:e==="email"?a!=null&&a.trim()?P(a.trim())?null:c.emailInvalid:c.emailRequired:e==="roleId"?a?null:c.selectRole:null,M=(e,a)=>{y(h=>({...h,[e]:a})),e==="email"&&j(null),C&&U(null)};return{values:r,errors:R,touched:n,loading:w,setValue:M,onBlur:async(e,a)=>{a!==void 0&&M(e,a),f(v=>({...v,[e]:!0}));const h=a!==void 0?a:r[e],S=F(e,h);if(d(S?v=>({...v,[e]:S}):v=>{const o={...v};return delete o[e],o}),e==="email"){const o=(a!==void 0?a:r.email||"").trim();if(N==="edit"&&o.toLowerCase()===(l||"").trim().toLowerCase()){j(null);return}if(P(o)&&o!==I){const u=await Y(o);x(o),j(u),u===!1&&d(k=>({...k,email:"A user with this email address is already a member of your company."}))}}},submit:async()=>{const e=["firstName","lastName","email","roleId"],a={};for(const o of e){const u=F(o,r[o]);u&&(a[o]=u)}if(d(a),f({firstName:!0,lastName:!0,email:!0,roleId:!0}),Object.keys(a).length||T===!1){setTimeout(()=>{const o=document.querySelector(".company-user-form__content .dropin-field__hint--error");if(o){const u=o.closest(".dropin-field");if(u){u.scrollIntoView({behavior:"smooth",block:"center"});const k=u.querySelector("input, select");k&&k.focus()}}},100);return}const h=`${r.firstName||""} ${r.lastName||""}`.trim()||r.email||"",v=i||K({id:r.roleId})?"ACTIVE":r.status;try{if(N==="add"){const o=await W({email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",roleId:r.roleId,status:v,targetId:g??null});if(!o){U(c.createUserError);return}E({label:h,structureId:o.structureId,entityId:o.id,type:"user"})}else p&&(await X({id:p,email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",status:v,roleId:r.roleId}),E({label:h,entityId:p,type:"user"}))}catch(o){const u=o instanceof Error?o.message:c.saveUserError;U(u)}},isCompanyAdmin:i,generalError:C}}function ae(){const b=L({loadRolesError:"Company.CompanyStructure.messages.loadRolesError"}),[N,p]=m([]),[g,E]=m(!0),[c,r]=m(null);return O(()=>{let y=!0;return E(!0),Z({pageSize:1e3}).then(R=>{y&&p(R)}).catch(()=>{y&&r(b.loadRolesError)}).finally(()=>{y&&E(!1)}),()=>{y=!1}},[b.loadRolesError]),{roles:N,loading:g,error:c}}const pe=G(({mode:b,entityId:N,parentStructureId:p,permissions:g,onSaved:E,onCancel:c})=>{const r=(g==null?void 0:g.canEditUsers)??!1,{roles:y,loading:R}=ae(),{values:d,errors:n,touched:f,loading:w,setValue:A,onBlur:C,submit:U,isCompanyAdmin:T,generalError:j}=te({mode:b,entityId:N,parentStructureId:p,onSaved:E}),[I,x]=m(!1),l=L({addUser:"Company.CompanyStructure.shared.titles.addUser",editUser:"Company.CompanyStructure.shared.titles.editUser",jobTitle:"Company.CompanyStructure.shared.fields.jobTitle",userRole:"Company.CompanyStructure.shared.fields.userRole",firstName:"Company.CompanyStructure.shared.fields.firstName",lastName:"Company.CompanyStructure.shared.fields.lastName",email:"Company.CompanyStructure.shared.fields.email",workPhoneNumber:"Company.CompanyStructure.shared.fields.workPhoneNumber",status:"Company.CompanyStructure.shared.fields.status",selectRole:"Company.CompanyStructure.shared.options.selectRole",active:"Company.CompanyStructure.shared.options.active",inactive:"Company.CompanyStructure.shared.options.inactive",companyAdministrator:"Company.CompanyStructure.shared.options.companyAdministrator",save:"Company.CompanyStructure.shared.buttons.save",cancel:"Company.CompanyStructure.shared.buttons.cancel"});return B("div",{children:[s("h3",{className:"acm-structure-panel__title",children:b==="add"?l.addUser:l.editUser}),B(D,{variant:"secondary",className:`company-user-form__card ${I?"is-working":""}`,children:[j?s(H,{className:"company-user-form__notification",type:"error",variant:"secondary",heading:j}):null,I?s("div",{className:"company-user-form__overlay","aria-live":"polite",children:s(J,{size:"small"})}):null,w||R?s(ee,{}):B("div",{className:"company-user-form__content",children:[s(_,{label:l.jobTitle,className:"acm-structure-panel__field",error:f.jobTitle&&n.jobTitle?n.jobTitle:void 0,children:s(q,{name:"job_title",type:"text",value:d.jobTitle||"",onBlur:t=>{const i=t.target;C("jobTitle",i.value)},variant:"primary",size:"medium"})}),s(_,{label:l.userRole,required:!0,className:"acm-structure-panel__field",error:!T&&f.roleId&&n.roleId?n.roleId:void 0,disabled:T,children:T?s(z,{name:"role",value:"MA==",options:[{value:"MA==",text:l.companyAdministrator}]}):s(z,{name:"role",value:d.roleId||"placeholder",onChange:t=>{var i,V;return A("roleId",String(((i=t==null?void 0:t.target)==null?void 0:i.value)==="placeholder"?"":((V=t==null?void 0:t.target)==null?void 0:V.value)??""))},onBlur:t=>{const i=t.target;C("roleId",i.value==="placeholder"?"":i.value)},options:[{value:"placeholder",text:l.selectRole,disabled:!0},...y.map(t=>({value:t.id,text:t.name}))]})}),s(_,{label:l.firstName,required:!0,className:"acm-structure-panel__field",error:f.firstName&&n.firstName?n.firstName:void 0,children:s(q,{name:"first_name",type:"text",value:d.firstName,onBlur:t=>{const i=t.target;C("firstName",i.value)},variant:"primary",size:"medium"})}),s(_,{label:l.lastName,required:!0,className:"acm-structure-panel__field",error:f.lastName&&n.lastName?n.lastName:void 0,children:s(q,{name:"last_name",type:"text",value:d.lastName,onBlur:t=>{const i=t.target;C("lastName",i.value)},variant:"primary",size:"medium"})}),s(_,{label:l.email,required:!0,className:"acm-structure-panel__field",error:f.email&&n.email?n.email:void 0,children:s(q,{name:"email",type:"email",value:d.email,onBlur:t=>{const i=t.target;C("email",i.value)},placeholder:"jdoe@example.com",variant:"primary",size:"medium"})}),s(_,{label:l.workPhoneNumber,className:"acm-structure-panel__field",error:f.telephone&&n.telephone?n.telephone:void 0,children:s(q,{name:"telephone",type:"text",value:d.telephone||"",onBlur:t=>{const i=t.target;C("telephone",i.value)},variant:"primary",size:"medium"})}),s(_,{label:l.status,className:"acm-structure-panel__field",disabled:T||!r,children:s(z,{name:"status",value:d.status,onChange:t=>{var i;return A("status",String(((i=t==null?void 0:t.target)==null?void 0:i.value)??"ACTIVE"))},options:[{value:"ACTIVE",text:l.active},{value:"INACTIVE",text:l.inactive}]})})]})]}),w||R?null:B("div",{className:"acm-structure-modal__actions",children:[s($,{type:"button",variant:"primary",disabled:I||!r,onClick:async()=>{if(!I){x(!0);try{await U()}finally{x(!1)}}},children:l.save}),s($,{type:"button",variant:"secondary",disabled:I,onClick:c,children:l.cancel})]})]})});export{pe as C};
3
+ import{jsxs as B,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{memo as O}from"@dropins/tools/preact-compat.js";import{useState as c,useEffect as G}from"@dropins/tools/preact-hooks.js";import{Card as D,InLineAlert as H,ProgressSpinner as J,Field as b,Input as j,Picker as L,Button as M}from"@dropins/tools/components.js";import{i as K}from"./company-permissions.js";import{g as Q,c as W,u as X,i as Y}from"./updateCompanyUser.js";import{useText as $}from"@dropins/tools/i18n.js";import{u as Z}from"./useCompanyRoles.js";import{C as ee}from"./CompanyLoaders.js";function ae(A){const{mode:g,entityId:h,parentStructureId:_,onSaved:U}=A,u=$({firstNameRequired:"Company.CompanyStructure.shared.validation.firstNameRequired",lastNameRequired:"Company.CompanyStructure.shared.validation.lastNameRequired",emailRequired:"Company.CompanyStructure.shared.validation.emailRequired",emailInvalid:"Company.CompanyStructure.shared.validation.emailInvalid",jobTitleRequired:"Company.CompanyStructure.shared.validation.jobTitleRequired",workPhoneRequired:"Company.CompanyStructure.shared.validation.workPhoneRequired",selectRole:"Company.CompanyStructure.shared.validation.selectRole",createUserError:"Company.CompanyStructure.messages.createUserError",saveUserError:"Company.CompanyStructure.messages.saveUserError"}),[r,E]=c({firstName:"",lastName:"",email:"",jobTitle:"",telephone:"",roleId:"",status:"ACTIVE"}),[q,m]=c({}),[n,p]=c({}),[w,T]=c(!1),[y,R]=c(null),[I,S]=c(null),[v,x]=c(""),[l,a]=c(""),[i,V]=c(!1);G(()=>{g!=="edit"||!h||(T(!0),Q(h).then(e=>{var f;if(!e)return;const t=e.email||"";E(N=>({...N,firstName:e.firstName||"",lastName:e.lastName||"",email:t,jobTitle:e.jobTitle||"",telephone:e.telephone||"",status:e.status||"ACTIVE"})),a(t),(f=e==null?void 0:e.role)!=null&&f.id&&E(N=>({...N,roleId:e.role.id})),V((e==null?void 0:e.isCompanyAdmin)??!1)}).finally(()=>T(!1)))},[g,h]);const P=e=>/.+@.+\..+/.test(e),z=(e,t)=>e==="firstName"?t!=null&&t.trim()?null:u.firstNameRequired:e==="lastName"?t!=null&&t.trim()?null:u.lastNameRequired:e==="email"?t!=null&&t.trim()?P(t.trim())?null:u.emailInvalid:u.emailRequired:e==="roleId"?t?null:u.selectRole:null,F=(e,t)=>{E(f=>({...f,[e]:t})),e==="email"&&S(null),y&&R(null)};return{values:r,errors:q,touched:n,loading:w,setValue:F,onBlur:async(e,t)=>{t!==void 0&&F(e,t),p(C=>({...C,[e]:!0}));const f=t!==void 0?t:r[e],N=z(e,f);if(m(N?C=>({...C,[e]:N}):C=>{const o={...C};return delete o[e],o}),e==="email"){const o=(t!==void 0?t:r.email||"").trim();if(g==="edit"&&o.toLowerCase()===(l||"").trim().toLowerCase()){S(null);return}if(P(o)&&o!==v){const d=await Y(o);x(o),S(d),d===!1&&m(k=>({...k,email:"A user with this email address is already a member of your company."}))}}},submit:async()=>{const e=["firstName","lastName","email","roleId"],t={};for(const o of e){const d=z(o,r[o]);d&&(t[o]=d)}if(m(t),p({firstName:!0,lastName:!0,email:!0,roleId:!0}),Object.keys(t).length||I===!1){setTimeout(()=>{const o=document.querySelector(".company-user-form__content .dropin-field__hint--error");if(o){const d=o.closest(".dropin-field");if(d){d.scrollIntoView({behavior:"smooth",block:"center"});const k=d.querySelector("input, select");k&&k.focus()}}},100);return}const f=`${r.firstName||""} ${r.lastName||""}`.trim()||r.email||"",C=i||K({id:r.roleId})?"ACTIVE":r.status;try{if(g==="add"){const o=await W({email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",roleId:r.roleId,status:C,targetId:_??null});if(!o){R(u.createUserError);return}U({label:f,structureId:o.structureId,entityId:o.id,type:"user"})}else h&&(await X({id:h,email:r.email||"",firstName:r.firstName||"",lastName:r.lastName||"",jobTitle:r.jobTitle||"",telephone:r.telephone||"",status:C,roleId:r.roleId}),U({label:f,entityId:h,type:"user"}))}catch(o){const d=o instanceof Error?o.message:u.saveUserError;R(d)}},isCompanyAdmin:i,generalError:y}}const pe=O(({mode:A,entityId:g,parentStructureId:h,permissions:_,onSaved:U,onCancel:u})=>{const r=(_==null?void 0:_.canEditUsers)??!1,{roles:E,isLoading:q}=Z(),{values:m,errors:n,touched:p,loading:w,setValue:T,onBlur:y,submit:R,isCompanyAdmin:I,generalError:S}=ae({mode:A,entityId:g,parentStructureId:h,onSaved:U}),[v,x]=c(!1),l=$({addUser:"Company.CompanyStructure.shared.titles.addUser",editUser:"Company.CompanyStructure.shared.titles.editUser",jobTitle:"Company.CompanyStructure.shared.fields.jobTitle",userRole:"Company.CompanyStructure.shared.fields.userRole",firstName:"Company.CompanyStructure.shared.fields.firstName",lastName:"Company.CompanyStructure.shared.fields.lastName",email:"Company.CompanyStructure.shared.fields.email",workPhoneNumber:"Company.CompanyStructure.shared.fields.workPhoneNumber",status:"Company.CompanyStructure.shared.fields.status",selectRole:"Company.CompanyStructure.shared.options.selectRole",active:"Company.CompanyStructure.shared.options.active",inactive:"Company.CompanyStructure.shared.options.inactive",companyAdministrator:"Company.CompanyStructure.shared.options.companyAdministrator",save:"Company.CompanyStructure.shared.buttons.save",cancel:"Company.CompanyStructure.shared.buttons.cancel"});return B("div",{children:[s("h3",{className:"acm-structure-panel__title",children:A==="add"?l.addUser:l.editUser}),B(D,{variant:"secondary",className:`company-user-form__card ${v?"is-working":""}`,children:[S?s(H,{className:"company-user-form__notification",type:"error",variant:"secondary",heading:S}):null,v?s("div",{className:"company-user-form__overlay","aria-live":"polite",children:s(J,{size:"small"})}):null,w||q?s(ee,{}):B("div",{className:"company-user-form__content",children:[s(b,{label:l.jobTitle,className:"acm-structure-panel__field",error:p.jobTitle&&n.jobTitle?n.jobTitle:void 0,children:s(j,{name:"job_title",type:"text",value:m.jobTitle||"",onBlur:a=>{const i=a.target;y("jobTitle",i.value)},variant:"primary",size:"medium"})}),s(b,{label:l.userRole,required:!0,className:"acm-structure-panel__field",error:!I&&p.roleId&&n.roleId?n.roleId:void 0,disabled:I,children:I?s(L,{name:"role",value:"MA==",options:[{value:"MA==",text:l.companyAdministrator}]}):s(L,{name:"role",value:m.roleId||"placeholder",onChange:a=>{var i,V;return T("roleId",String(((i=a==null?void 0:a.target)==null?void 0:i.value)==="placeholder"?"":((V=a==null?void 0:a.target)==null?void 0:V.value)??""))},onBlur:a=>{const i=a.target;y("roleId",i.value==="placeholder"?"":i.value)},options:[{value:"placeholder",text:l.selectRole,disabled:!0},...E.map(a=>({value:a.id,text:a.name}))]})}),s(b,{label:l.firstName,required:!0,className:"acm-structure-panel__field",error:p.firstName&&n.firstName?n.firstName:void 0,children:s(j,{name:"first_name",type:"text",value:m.firstName,onBlur:a=>{const i=a.target;y("firstName",i.value)},variant:"primary",size:"medium"})}),s(b,{label:l.lastName,required:!0,className:"acm-structure-panel__field",error:p.lastName&&n.lastName?n.lastName:void 0,children:s(j,{name:"last_name",type:"text",value:m.lastName,onBlur:a=>{const i=a.target;y("lastName",i.value)},variant:"primary",size:"medium"})}),s(b,{label:l.email,required:!0,className:"acm-structure-panel__field",error:p.email&&n.email?n.email:void 0,children:s(j,{name:"email",type:"email",value:m.email,onBlur:a=>{const i=a.target;y("email",i.value)},placeholder:"jdoe@example.com",variant:"primary",size:"medium"})}),s(b,{label:l.workPhoneNumber,className:"acm-structure-panel__field",error:p.telephone&&n.telephone?n.telephone:void 0,children:s(j,{name:"telephone",type:"text",value:m.telephone||"",onBlur:a=>{const i=a.target;y("telephone",i.value)},variant:"primary",size:"medium"})}),s(b,{label:l.status,className:"acm-structure-panel__field",disabled:I||!r,children:s(L,{name:"status",value:m.status,onChange:a=>{var i;return T("status",String(((i=a==null?void 0:a.target)==null?void 0:i.value)??"ACTIVE"))},options:[{value:"ACTIVE",text:l.active},{value:"INACTIVE",text:l.inactive}]})})]})]}),w||q?null:B("div",{className:"acm-structure-modal__actions",children:[s(M,{type:"button",variant:"primary",disabled:v||!r,onClick:async()=>{if(!v){x(!0);try{await R()}finally{x(!1)}}},children:l.save}),s(M,{type:"button",variant:"secondary",disabled:v,onClick:u,children:l.cancel})]})]})});export{pe as C};
4
4
  //# sourceMappingURL=CompanyUserForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompanyUserForm.js","sources":["/@dropins/storefront-company-management/src/hooks/useCompanyUserForm.ts","/@dropins/storefront-company-management/src/hooks/useCompanyRoles.ts","/@dropins/storefront-company-management/src/components/CompanyUserForm/CompanyUserForm.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { useEffect, useState } from 'preact/hooks';\nimport { createCompanyUser, getCompanyUser, isCompanyUserEmailAvailable, updateCompanyUser } from '@/company-management/api';\nimport { isCompanyAdministrator } from '@/company-management/lib';\nimport { CompanyUserModel } from '@/company-management/data/models';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nexport type UserStatus = 'ACTIVE' | 'INACTIVE';\n\n\nexport function useCompanyUserForm(opts: {\n mode: 'add' | 'edit';\n entityId?: string;\n parentStructureId?: string | null;\n onSaved: (result: { label: string; structureId?: string; entityId?: string; type: 'user' }) => void;\n}) {\n const { mode, entityId, parentStructureId, onSaved } = opts;\n \n const translations = useText({\n firstNameRequired: 'Company.CompanyStructure.shared.validation.firstNameRequired',\n lastNameRequired: 'Company.CompanyStructure.shared.validation.lastNameRequired',\n emailRequired: 'Company.CompanyStructure.shared.validation.emailRequired',\n emailInvalid: 'Company.CompanyStructure.shared.validation.emailInvalid',\n jobTitleRequired: 'Company.CompanyStructure.shared.validation.jobTitleRequired',\n workPhoneRequired: 'Company.CompanyStructure.shared.validation.workPhoneRequired',\n selectRole: 'Company.CompanyStructure.shared.validation.selectRole',\n createUserError: 'Company.CompanyStructure.messages.createUserError',\n saveUserError: 'Company.CompanyStructure.messages.saveUserError',\n });\n const [values, setValues] = useState<Partial<CompanyUserModel> & { roleId: string; status: UserStatus }>({ \n firstName: '', \n lastName: '', \n email: '', \n jobTitle: '', \n telephone: '', \n roleId: '', \n status: 'ACTIVE' \n });\n const [errors, setErrors] = useState<Record<string, string>>({});\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n const [loading, setLoading] = useState(false);\n const [generalError, setGeneralError] = useState<string | null>(null);\n const [emailAvailable, setEmailAvailable] = useState<boolean | null>(null);\n const [emailChecked, setEmailChecked] = useState<string>('');\n const [originalEmail, setOriginalEmail] = useState<string>('');\n const [isCompanyAdmin, setIsCompanyAdmin] = useState<boolean>(false);\n\n useEffect(() => {\n if (mode !== 'edit' || !entityId) return;\n setLoading(true);\n void getCompanyUser(entityId).then((u) => {\n if (!u) return;\n const loadedEmail = u.email || '';\n setValues((v) => ({ ...v, firstName: u.firstName || '', lastName: u.lastName || '', email: loadedEmail, jobTitle: u.jobTitle || '', telephone: u.telephone || '', status: (u.status || 'ACTIVE') as UserStatus }));\n setOriginalEmail(loadedEmail);\n if (u?.role?.id) setValues((v) => ({ ...v, roleId: u.role!.id }));\n setIsCompanyAdmin(u?.isCompanyAdmin ?? false);\n }).finally(() => setLoading(false));\n }, [mode, entityId]);\n\n const isEmailValid = (value: string): boolean => /.+@.+\\..+/.test(value);\n const validateField = (field: keyof CompanyUserModel | 'roleId', value: any): string | null => {\n if (field === 'firstName') return value?.trim() ? null : translations.firstNameRequired;\n if (field === 'lastName') return value?.trim() ? null : translations.lastNameRequired;\n if (field === 'email') {\n if (!value?.trim()) return translations.emailRequired;\n return isEmailValid(value.trim()) ? null : translations.emailInvalid;\n }\n // jobTitle and telephone are now optional fields (USF-3012)\n if (field === 'roleId') return value ? null : translations.selectRole;\n return null;\n };\n\n const setValue = (field: keyof CompanyUserModel | 'roleId', value: any) => {\n setValues((v) => ({ ...v, [field]: value }));\n if (field === 'email') setEmailAvailable(null);\n if (generalError) setGeneralError(null);\n };\n\n const onBlur = async (field: keyof CompanyUserModel | 'roleId', value?: any) => {\n // Update form data if value is provided (this preserves spaces and other characters)\n if (value !== undefined) {\n setValue(field, value);\n }\n \n setTouched((t) => ({ ...t, [field]: true }));\n \n // Use provided value or current state value for validation\n const valueToValidate = value !== undefined ? value : values[field];\n const err = validateField(field, valueToValidate);\n if (err) {\n setErrors((p) => ({ ...p, [field]: err }));\n } else {\n // Clear error if field is now valid\n setErrors((p) => {\n const newErrors = { ...p };\n delete newErrors[field];\n return newErrors;\n });\n }\n \n if (field === 'email') {\n const emailValue = value !== undefined ? value : (values.email || '');\n const trimmed = emailValue.trim();\n if (mode === 'edit' && trimmed.toLowerCase() === (originalEmail || '').trim().toLowerCase()) {\n setEmailAvailable(null);\n return;\n }\n if (isEmailValid(trimmed) && trimmed !== emailChecked) {\n const available = await isCompanyUserEmailAvailable(trimmed);\n setEmailChecked(trimmed);\n setEmailAvailable(available);\n if (available === false) setErrors((p) => ({ ...p, email: 'A user with this email address is already a member of your company.' }));\n }\n }\n };\n\n const submit = async () => {\n // Only validate required fields (USF-3012: jobTitle and telephone are now optional)\n const fields: (keyof CompanyUserModel | 'roleId')[] = ['firstName', 'lastName', 'email', 'roleId'];\n const next: Record<string, string> = {};\n for (const f of fields) {\n const err = validateField(f, values[f]);\n if (err) next[f as string] = err;\n }\n setErrors(next);\n setTouched({ firstName: true, lastName: true, email: true, roleId: true });\n if (Object.keys(next).length || emailAvailable === false) {\n // Scroll to the first error field\n setTimeout(() => {\n const firstErrorField = document.querySelector('.company-user-form__content .dropin-field__hint--error');\n if (firstErrorField) {\n const fieldContainer = firstErrorField.closest('.dropin-field');\n if (fieldContainer) {\n fieldContainer.scrollIntoView({ behavior: 'smooth', block: 'center' });\n const input = fieldContainer.querySelector('input, select') as HTMLElement;\n if (input) {\n input.focus();\n }\n }\n }\n }, 100);\n return;\n }\n\n const label = `${values.firstName || ''} ${values.lastName || ''}`.trim() || values.email || '';\n const adminEffective = isCompanyAdmin || isCompanyAdministrator({ id: values.roleId });\n const effectiveStatus = adminEffective ? 'ACTIVE' : values.status;\n try {\n if (mode === 'add') {\n const res = await createCompanyUser({ email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', roleId: values.roleId, status: effectiveStatus, targetId: parentStructureId ?? null });\n if (!res) {\n setGeneralError(translations.createUserError);\n return;\n }\n onSaved({ label, structureId: res.structureId, entityId: res.id, type: 'user' });\n } else if (entityId) {\n await updateCompanyUser({ id: entityId, email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', status: effectiveStatus, roleId: values.roleId });\n onSaved({ label, entityId, type: 'user' });\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : translations.saveUserError;\n setGeneralError(errorMessage);\n }\n };\n\n return { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError };\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { useEffect, useState } from 'preact/hooks';\nimport { getCompanyRoles } from '@/company-management/api';\nimport { CompanyRoleModel } from '@/company-management/data/models';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nexport function useCompanyRoles() {\n const translations = useText({\n loadRolesError: 'Company.CompanyStructure.messages.loadRolesError',\n });\n \n const [roles, setRoles] = useState<CompanyRoleModel[]>([]);\n const [loading, setLoading] = useState<boolean>(true);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let isMounted = true;\n setLoading(true);\n void getCompanyRoles({ pageSize: 1000 })\n .then((items) => { if (isMounted) setRoles(items); })\n .catch(() => { if (isMounted) setError(translations.loadRolesError); })\n .finally(() => { if (isMounted) setLoading(false); });\n return () => { isMounted = false; };\n }, [translations.loadRolesError]);\n\n return { roles, loading, error };\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { FunctionComponent } from 'preact';\nimport { memo } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport { Field, Input, Button, Card, Picker, ProgressSpinner, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { CompanyUserFormLoader } from '@/company-management/components/CompanyLoaders';\nimport { useCompanyUserForm } from '@/company-management/hooks/useCompanyUserForm';\nimport { useCompanyRoles } from '@/company-management/hooks/useCompanyRoles';\nimport { CompanyUserFormProps } from '@/company-management/types/companyForm.types';\nimport './CompanyUserForm.css';\n\n/**\n * CompanyUserForm component for creating and editing company users\n * Provides form fields for user information including name, email, role, and status\n */\nexport const CompanyUserForm: FunctionComponent<CompanyUserFormProps> = memo(({ mode, entityId, parentStructureId, permissions, onSaved, onCancel }) => {\n const canEditUsers = permissions?.canEditUsers ?? false;\n const { roles, loading: rolesLoading } = useCompanyRoles();\n const { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError } = useCompanyUserForm({ mode, entityId, parentStructureId, onSaved });\n const [saving, setSaving] = useState(false);\n \n const translations = useText({\n addUser: 'Company.CompanyStructure.shared.titles.addUser',\n editUser: 'Company.CompanyStructure.shared.titles.editUser',\n jobTitle: 'Company.CompanyStructure.shared.fields.jobTitle',\n userRole: 'Company.CompanyStructure.shared.fields.userRole',\n firstName: 'Company.CompanyStructure.shared.fields.firstName',\n lastName: 'Company.CompanyStructure.shared.fields.lastName',\n email: 'Company.CompanyStructure.shared.fields.email',\n workPhoneNumber: 'Company.CompanyStructure.shared.fields.workPhoneNumber',\n status: 'Company.CompanyStructure.shared.fields.status',\n selectRole: 'Company.CompanyStructure.shared.options.selectRole',\n active: 'Company.CompanyStructure.shared.options.active',\n inactive: 'Company.CompanyStructure.shared.options.inactive',\n companyAdministrator: 'Company.CompanyStructure.shared.options.companyAdministrator',\n save: 'Company.CompanyStructure.shared.buttons.save',\n cancel: 'Company.CompanyStructure.shared.buttons.cancel',\n });\n\n return (\n <div>\n <h3 className=\"acm-structure-panel__title\">{mode === 'add' ? translations.addUser : translations.editUser}</h3>\n <Card variant=\"secondary\" className={`company-user-form__card ${saving ? 'is-working' : ''}`}>\n {generalError ? (\n <InLineAlert \n className=\"company-user-form__notification\" \n type=\"error\" \n variant=\"secondary\" \n heading={generalError} \n />\n ) : null}\n {saving ? <div className=\"company-user-form__overlay\" aria-live=\"polite\"><ProgressSpinner size=\"small\" /></div> : null}\n {loading || rolesLoading ? (\n <CompanyUserFormLoader />\n ) : (\n <div className=\"company-user-form__content\">\n\n <Field label={translations.jobTitle} className=\"acm-structure-panel__field\" error={touched.jobTitle && errors.jobTitle ? errors.jobTitle : undefined}>\n <Input name=\"job_title\" type=\"text\" value={values.jobTitle || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('jobTitle', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.userRole} required className=\"acm-structure-panel__field\" error={!isCompanyAdmin && touched.roleId && errors.roleId ? errors.roleId : undefined} disabled={isCompanyAdmin}>\n {isCompanyAdmin ? (\n <Picker name=\"role\" value={'MA=='} options={[{ value: 'MA==', text: translations.companyAdministrator }]} />\n ) : (\n <Picker\n name=\"role\"\n value={values.roleId || 'placeholder'}\n onChange={(e: any) => setValue('roleId', String(e?.target?.value === 'placeholder' ? '' : e?.target?.value ?? ''))}\n onBlur={(e: Event) => { const target = e.target as HTMLSelectElement; void onBlur('roleId', target.value === 'placeholder' ? '' : target.value); }}\n options={[{ value: 'placeholder', text: translations.selectRole, disabled: true }, ...roles.map((r) => ({ value: r.id, text: r.name }))]}\n />\n )}\n </Field>\n\n <Field label={translations.firstName} required className=\"acm-structure-panel__field\" error={touched.firstName && errors.firstName ? errors.firstName : undefined}>\n <Input name=\"first_name\" type=\"text\" value={values.firstName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('firstName', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.lastName} required className=\"acm-structure-panel__field\" error={touched.lastName && errors.lastName ? errors.lastName : undefined}>\n <Input name=\"last_name\" type=\"text\" value={values.lastName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('lastName', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.email} required className=\"acm-structure-panel__field\" error={touched.email && errors.email ? errors.email : undefined}>\n <Input name=\"email\" type=\"email\" value={values.email} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; void onBlur('email', target.value); }} placeholder=\"jdoe@example.com\" variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.workPhoneNumber} className=\"acm-structure-panel__field\" error={touched.telephone && errors.telephone ? errors.telephone : undefined}>\n <Input name=\"telephone\" type=\"text\" value={values.telephone || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('telephone', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.status} className=\"acm-structure-panel__field\" disabled={isCompanyAdmin || !canEditUsers}>\n <Picker\n name=\"status\"\n value={values.status}\n onChange={(e: any) => setValue('status', String(e?.target?.value ?? 'ACTIVE'))}\n options={[{ value: 'ACTIVE', text: translations.active }, { value: 'INACTIVE', text: translations.inactive }]}\n />\n </Field>\n </div>\n )}\n </Card>\n {!(loading || rolesLoading) ? (\n <div className=\"acm-structure-modal__actions\">\n <Button type=\"button\" variant=\"primary\" disabled={saving || !canEditUsers} onClick={async () => { if (saving) return; setSaving(true); try { await submit(); } finally { setSaving(false); } }}>\n {translations.save}\n </Button>\n <Button\n type=\"button\"\n variant=\"secondary\"\n disabled={saving}\n onClick={onCancel}\n >\n {translations.cancel}\n </Button>\n </div>\n ) : null}\n </div>\n );\n});\n\nexport default CompanyUserForm;\n"],"names":["useCompanyUserForm","opts","mode","entityId","parentStructureId","onSaved","translations","useText","values","setValues","useState","errors","setErrors","touched","setTouched","loading","setLoading","generalError","setGeneralError","emailAvailable","setEmailAvailable","emailChecked","setEmailChecked","originalEmail","setOriginalEmail","isCompanyAdmin","setIsCompanyAdmin","useEffect","getCompanyUser","u","loadedEmail","v","_a","isEmailValid","value","validateField","field","setValue","t","valueToValidate","err","p","newErrors","trimmed","available","isCompanyUserEmailAvailable","fields","next","f","firstErrorField","fieldContainer","input","label","effectiveStatus","isCompanyAdministrator","res","createCompanyUser","updateCompanyUser","error","errorMessage","useCompanyRoles","roles","setRoles","setError","isMounted","getCompanyRoles","items","CompanyUserForm","memo","permissions","onCancel","canEditUsers","rolesLoading","onBlur","submit","saving","setSaving","jsx","jsxs","Card","InLineAlert","ProgressSpinner","CompanyUserFormLoader","Field","Input","e","target","Picker","_b","r","Button"],"mappings":"2hBAyBO,SAASA,GAAmBC,EAKhC,CACD,KAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,kBAAAC,EAAmB,QAAAC,CAAY,EAAAJ,EAEjDK,EAAeC,EAAQ,C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,GAAI,OAAS6E,GAAa,CAAE,MAAMC,EAASD,EAAE,OAAmCZ,EAAA,YAAaa,EAAO,KAAK,CAAM,EAAA,QAAQ,UAAU,KAAK,SAAS,CAChN,CAAA,EAEAT,EAACM,EAAM,CAAA,MAAO7E,EAAa,OAAQ,UAAU,6BAA6B,SAAUmB,GAAkB,CAAC8C,EACrG,SAAAM,EAACU,EAAA,CACC,KAAK,SACL,MAAO/E,EAAO,OACd,SAAW6E,GAAW,OAAA,OAAAhD,EAAS,SAAU,SAAOL,EAAAqD,GAAA,YAAAA,EAAG,SAAH,YAAArD,EAAW,QAAS,QAAQ,CAAC,GAC7E,QAAS,CAAC,CAAE,MAAO,SAAU,KAAM1B,EAAa,MAAO,EAAG,CAAE,MAAO,WAAY,KAAMA,EAAa,QAAU,CAAA,CAAA,CAAA,CAEhH,CAAA,CAAA,CACF,CAAA,CAAA,EAEJ,EACGS,GAAWyD,EAcV,KAbDM,EAAA,MAAA,CAAI,UAAU,+BACb,SAAA,CAACD,EAAAa,EAAA,CAAO,KAAK,SAAS,QAAQ,UAAU,SAAUf,GAAU,CAACJ,EAAc,QAAS,SAAY,CAAE,GAAI,CAAAI,EAAgB,CAAAC,EAAU,EAAI,EAAO,GAAA,CAAE,MAAMF,EAAO,CAAA,QAAK,CAAUE,EAAU,EAAK,CAAA,EAAG,EACxL,WAAa,KAChB,EACAC,EAACa,EAAA,CACC,KAAK,SACL,QAAQ,YACR,SAAUf,EACV,QAASL,EAER,SAAahE,EAAA,MAAA,CAAA,CAChB,CAAA,CACF,CACE,EACN,CAEJ,CAAC"}
1
+ {"version":3,"file":"CompanyUserForm.js","sources":["/@dropins/storefront-company-management/src/hooks/useCompanyUserForm.ts","/@dropins/storefront-company-management/src/components/CompanyUserForm/CompanyUserForm.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { useEffect, useState } from 'preact/hooks';\nimport { createCompanyUser, getCompanyUser, isCompanyUserEmailAvailable, updateCompanyUser } from '@/company-management/api';\nimport { isCompanyAdministrator } from '@/company-management/lib';\nimport { CompanyUserModel } from '@/company-management/data/models';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nexport type UserStatus = 'ACTIVE' | 'INACTIVE';\n\n\nexport function useCompanyUserForm(opts: {\n mode: 'add' | 'edit';\n entityId?: string;\n parentStructureId?: string | null;\n onSaved: (result: { label: string; structureId?: string; entityId?: string; type: 'user' }) => void;\n}) {\n const { mode, entityId, parentStructureId, onSaved } = opts;\n \n const translations = useText({\n firstNameRequired: 'Company.CompanyStructure.shared.validation.firstNameRequired',\n lastNameRequired: 'Company.CompanyStructure.shared.validation.lastNameRequired',\n emailRequired: 'Company.CompanyStructure.shared.validation.emailRequired',\n emailInvalid: 'Company.CompanyStructure.shared.validation.emailInvalid',\n jobTitleRequired: 'Company.CompanyStructure.shared.validation.jobTitleRequired',\n workPhoneRequired: 'Company.CompanyStructure.shared.validation.workPhoneRequired',\n selectRole: 'Company.CompanyStructure.shared.validation.selectRole',\n createUserError: 'Company.CompanyStructure.messages.createUserError',\n saveUserError: 'Company.CompanyStructure.messages.saveUserError',\n });\n const [values, setValues] = useState<Partial<CompanyUserModel> & { roleId: string; status: UserStatus }>({ \n firstName: '', \n lastName: '', \n email: '', \n jobTitle: '', \n telephone: '', \n roleId: '', \n status: 'ACTIVE' \n });\n const [errors, setErrors] = useState<Record<string, string>>({});\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n const [loading, setLoading] = useState(false);\n const [generalError, setGeneralError] = useState<string | null>(null);\n const [emailAvailable, setEmailAvailable] = useState<boolean | null>(null);\n const [emailChecked, setEmailChecked] = useState<string>('');\n const [originalEmail, setOriginalEmail] = useState<string>('');\n const [isCompanyAdmin, setIsCompanyAdmin] = useState<boolean>(false);\n\n useEffect(() => {\n if (mode !== 'edit' || !entityId) return;\n setLoading(true);\n void getCompanyUser(entityId).then((u) => {\n if (!u) return;\n const loadedEmail = u.email || '';\n setValues((v) => ({ ...v, firstName: u.firstName || '', lastName: u.lastName || '', email: loadedEmail, jobTitle: u.jobTitle || '', telephone: u.telephone || '', status: (u.status || 'ACTIVE') as UserStatus }));\n setOriginalEmail(loadedEmail);\n if (u?.role?.id) setValues((v) => ({ ...v, roleId: u.role!.id }));\n setIsCompanyAdmin(u?.isCompanyAdmin ?? false);\n }).finally(() => setLoading(false));\n }, [mode, entityId]);\n\n const isEmailValid = (value: string): boolean => /.+@.+\\..+/.test(value);\n const validateField = (field: keyof CompanyUserModel | 'roleId', value: any): string | null => {\n if (field === 'firstName') return value?.trim() ? null : translations.firstNameRequired;\n if (field === 'lastName') return value?.trim() ? null : translations.lastNameRequired;\n if (field === 'email') {\n if (!value?.trim()) return translations.emailRequired;\n return isEmailValid(value.trim()) ? null : translations.emailInvalid;\n }\n // jobTitle and telephone are now optional fields (USF-3012)\n if (field === 'roleId') return value ? null : translations.selectRole;\n return null;\n };\n\n const setValue = (field: keyof CompanyUserModel | 'roleId', value: any) => {\n setValues((v) => ({ ...v, [field]: value }));\n if (field === 'email') setEmailAvailable(null);\n if (generalError) setGeneralError(null);\n };\n\n const onBlur = async (field: keyof CompanyUserModel | 'roleId', value?: any) => {\n // Update form data if value is provided (this preserves spaces and other characters)\n if (value !== undefined) {\n setValue(field, value);\n }\n \n setTouched((t) => ({ ...t, [field]: true }));\n \n // Use provided value or current state value for validation\n const valueToValidate = value !== undefined ? value : values[field];\n const err = validateField(field, valueToValidate);\n if (err) {\n setErrors((p) => ({ ...p, [field]: err }));\n } else {\n // Clear error if field is now valid\n setErrors((p) => {\n const newErrors = { ...p };\n delete newErrors[field];\n return newErrors;\n });\n }\n \n if (field === 'email') {\n const emailValue = value !== undefined ? value : (values.email || '');\n const trimmed = emailValue.trim();\n if (mode === 'edit' && trimmed.toLowerCase() === (originalEmail || '').trim().toLowerCase()) {\n setEmailAvailable(null);\n return;\n }\n if (isEmailValid(trimmed) && trimmed !== emailChecked) {\n const available = await isCompanyUserEmailAvailable(trimmed);\n setEmailChecked(trimmed);\n setEmailAvailable(available);\n if (available === false) setErrors((p) => ({ ...p, email: 'A user with this email address is already a member of your company.' }));\n }\n }\n };\n\n const submit = async () => {\n // Only validate required fields (USF-3012: jobTitle and telephone are now optional)\n const fields: (keyof CompanyUserModel | 'roleId')[] = ['firstName', 'lastName', 'email', 'roleId'];\n const next: Record<string, string> = {};\n for (const f of fields) {\n const err = validateField(f, values[f]);\n if (err) next[f as string] = err;\n }\n setErrors(next);\n setTouched({ firstName: true, lastName: true, email: true, roleId: true });\n if (Object.keys(next).length || emailAvailable === false) {\n // Scroll to the first error field\n setTimeout(() => {\n const firstErrorField = document.querySelector('.company-user-form__content .dropin-field__hint--error');\n if (firstErrorField) {\n const fieldContainer = firstErrorField.closest('.dropin-field');\n if (fieldContainer) {\n fieldContainer.scrollIntoView({ behavior: 'smooth', block: 'center' });\n const input = fieldContainer.querySelector('input, select') as HTMLElement;\n if (input) {\n input.focus();\n }\n }\n }\n }, 100);\n return;\n }\n\n const label = `${values.firstName || ''} ${values.lastName || ''}`.trim() || values.email || '';\n const adminEffective = isCompanyAdmin || isCompanyAdministrator({ id: values.roleId });\n const effectiveStatus = adminEffective ? 'ACTIVE' : values.status;\n try {\n if (mode === 'add') {\n const res = await createCompanyUser({ email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', roleId: values.roleId, status: effectiveStatus, targetId: parentStructureId ?? null });\n if (!res) {\n setGeneralError(translations.createUserError);\n return;\n }\n onSaved({ label, structureId: res.structureId, entityId: res.id, type: 'user' });\n } else if (entityId) {\n await updateCompanyUser({ id: entityId, email: values.email || '', firstName: values.firstName || '', lastName: values.lastName || '', jobTitle: values.jobTitle || '', telephone: values.telephone || '', status: effectiveStatus, roleId: values.roleId });\n onSaved({ label, entityId, type: 'user' });\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : translations.saveUserError;\n setGeneralError(errorMessage);\n }\n };\n\n return { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError };\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport { FunctionComponent } from 'preact';\nimport { memo } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport { Field, Input, Button, Card, Picker, ProgressSpinner, InLineAlert } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { CompanyUserFormLoader } from '@/company-management/components/CompanyLoaders';\nimport { useCompanyUserForm } from '@/company-management/hooks/useCompanyUserForm';\nimport { useCompanyRoles } from '@/company-management/hooks/useCompanyRoles';\nimport { CompanyUserFormProps } from '@/company-management/types/companyForm.types';\nimport './CompanyUserForm.css';\n\n/**\n * CompanyUserForm component for creating and editing company users\n * Provides form fields for user information including name, email, role, and status\n */\nexport const CompanyUserForm: FunctionComponent<CompanyUserFormProps> = memo(({ mode, entityId, parentStructureId, permissions, onSaved, onCancel }) => {\n const canEditUsers = permissions?.canEditUsers ?? false;\n const { roles, isLoading: rolesLoading } = useCompanyRoles();\n const { values, errors, touched, loading, setValue, onBlur, submit, isCompanyAdmin, generalError } = useCompanyUserForm({ mode, entityId, parentStructureId, onSaved });\n const [saving, setSaving] = useState(false);\n \n const translations = useText({\n addUser: 'Company.CompanyStructure.shared.titles.addUser',\n editUser: 'Company.CompanyStructure.shared.titles.editUser',\n jobTitle: 'Company.CompanyStructure.shared.fields.jobTitle',\n userRole: 'Company.CompanyStructure.shared.fields.userRole',\n firstName: 'Company.CompanyStructure.shared.fields.firstName',\n lastName: 'Company.CompanyStructure.shared.fields.lastName',\n email: 'Company.CompanyStructure.shared.fields.email',\n workPhoneNumber: 'Company.CompanyStructure.shared.fields.workPhoneNumber',\n status: 'Company.CompanyStructure.shared.fields.status',\n selectRole: 'Company.CompanyStructure.shared.options.selectRole',\n active: 'Company.CompanyStructure.shared.options.active',\n inactive: 'Company.CompanyStructure.shared.options.inactive',\n companyAdministrator: 'Company.CompanyStructure.shared.options.companyAdministrator',\n save: 'Company.CompanyStructure.shared.buttons.save',\n cancel: 'Company.CompanyStructure.shared.buttons.cancel',\n });\n\n return (\n <div>\n <h3 className=\"acm-structure-panel__title\">{mode === 'add' ? translations.addUser : translations.editUser}</h3>\n <Card variant=\"secondary\" className={`company-user-form__card ${saving ? 'is-working' : ''}`}>\n {generalError ? (\n <InLineAlert \n className=\"company-user-form__notification\" \n type=\"error\" \n variant=\"secondary\" \n heading={generalError} \n />\n ) : null}\n {saving ? <div className=\"company-user-form__overlay\" aria-live=\"polite\"><ProgressSpinner size=\"small\" /></div> : null}\n {loading || rolesLoading ? (\n <CompanyUserFormLoader />\n ) : (\n <div className=\"company-user-form__content\">\n\n <Field label={translations.jobTitle} className=\"acm-structure-panel__field\" error={touched.jobTitle && errors.jobTitle ? errors.jobTitle : undefined}>\n <Input name=\"job_title\" type=\"text\" value={values.jobTitle || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('jobTitle', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.userRole} required className=\"acm-structure-panel__field\" error={!isCompanyAdmin && touched.roleId && errors.roleId ? errors.roleId : undefined} disabled={isCompanyAdmin}>\n {isCompanyAdmin ? (\n <Picker name=\"role\" value={'MA=='} options={[{ value: 'MA==', text: translations.companyAdministrator }]} />\n ) : (\n <Picker\n name=\"role\"\n value={values.roleId || 'placeholder'}\n onChange={(e: any) => setValue('roleId', String(e?.target?.value === 'placeholder' ? '' : e?.target?.value ?? ''))}\n onBlur={(e: Event) => { const target = e.target as HTMLSelectElement; void onBlur('roleId', target.value === 'placeholder' ? '' : target.value); }}\n options={[{ value: 'placeholder', text: translations.selectRole, disabled: true }, ...roles.map((r) => ({ value: r.id, text: r.name }))]}\n />\n )}\n </Field>\n\n <Field label={translations.firstName} required className=\"acm-structure-panel__field\" error={touched.firstName && errors.firstName ? errors.firstName : undefined}>\n <Input name=\"first_name\" type=\"text\" value={values.firstName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('firstName', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.lastName} required className=\"acm-structure-panel__field\" error={touched.lastName && errors.lastName ? errors.lastName : undefined}>\n <Input name=\"last_name\" type=\"text\" value={values.lastName} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('lastName', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.email} required className=\"acm-structure-panel__field\" error={touched.email && errors.email ? errors.email : undefined}>\n <Input name=\"email\" type=\"email\" value={values.email} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; void onBlur('email', target.value); }} placeholder=\"jdoe@example.com\" variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.workPhoneNumber} className=\"acm-structure-panel__field\" error={touched.telephone && errors.telephone ? errors.telephone : undefined}>\n <Input name=\"telephone\" type=\"text\" value={values.telephone || ''} onBlur={(e: Event) => { const target = e.target as HTMLInputElement; onBlur('telephone', target.value); }} variant=\"primary\" size=\"medium\" />\n </Field>\n\n <Field label={translations.status} className=\"acm-structure-panel__field\" disabled={isCompanyAdmin || !canEditUsers}>\n <Picker\n name=\"status\"\n value={values.status}\n onChange={(e: any) => setValue('status', String(e?.target?.value ?? 'ACTIVE'))}\n options={[{ value: 'ACTIVE', text: translations.active }, { value: 'INACTIVE', text: translations.inactive }]}\n />\n </Field>\n </div>\n )}\n </Card>\n {!(loading || rolesLoading) ? (\n <div className=\"acm-structure-modal__actions\">\n <Button type=\"button\" variant=\"primary\" disabled={saving || !canEditUsers} onClick={async () => { if (saving) return; setSaving(true); try { await submit(); } finally { setSaving(false); } }}>\n {translations.save}\n </Button>\n <Button\n type=\"button\"\n variant=\"secondary\"\n disabled={saving}\n onClick={onCancel}\n >\n {translations.cancel}\n </Button>\n </div>\n ) : null}\n </div>\n );\n});\n\nexport default CompanyUserForm;\n"],"names":["useCompanyUserForm","opts","mode","entityId","parentStructureId","onSaved","translations","useText","values","setValues","useState","errors","setErrors","touched","setTouched","loading","setLoading","generalError","setGeneralError","emailAvailable","setEmailAvailable","emailChecked","setEmailChecked","originalEmail","setOriginalEmail","isCompanyAdmin","setIsCompanyAdmin","useEffect","getCompanyUser","u","loadedEmail","v","_a","isEmailValid","value","validateField","field","setValue","t","valueToValidate","err","p","newErrors","trimmed","available","isCompanyUserEmailAvailable","fields","next","f","firstErrorField","fieldContainer","input","label","effectiveStatus","isCompanyAdministrator","res","createCompanyUser","updateCompanyUser","error","errorMessage","CompanyUserForm","memo","permissions","onCancel","canEditUsers","roles","rolesLoading","useCompanyRoles","onBlur","submit","saving","setSaving","jsx","jsxs","Card","InLineAlert","ProgressSpinner","CompanyUserFormLoader","Field","Input","e","target","Picker","_b","r","Button"],"mappings":"6jBAyBO,SAASA,GAAmBC,EAKhC,CACD,KAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,kBAAAC,EAAmB,QAAAC,CAAY,EAAAJ,EAEjDK,EAAeC,EAAQ,CAC3B,kBAAmB,+DACnB,iBAAkB,8DAClB,cAAe,2DACf,aAAc,0DACd,iBAAkB,8DAClB,kBAAmB,+DACnB,WAAY,wDACZ,gBAAiB,oDACjB,cAAe,iDAAA,CAChB,EACK,CAACC,EAAQC,CAAS,EAAIC,EA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,EAAG,EACxL,WAAa,KAChB,EACAC,EAACa,EAAA,CACC,KAAK,SACL,QAAQ,YACR,SAAUf,EACV,QAASP,EAER,SAAazD,EAAA,MAAA,CAAA,CAChB,CAAA,CACF,CACE,EACN,CAEJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ /*! Copyright 2025 Adobe
2
+ All Rights Reserved. */
3
+ import{jsx as r,jsxs as o}from"@dropins/tools/preact-jsx-runtime.js";import{Fragment as T}from"@dropins/tools/preact.js";import{classes as c,VComponent as b}from"@dropins/tools/lib.js";import{Button as A,Icon as $,Skeleton as u,SkeletonRow as x}from"@dropins/tools/components.js";import{useText as C}from"@dropins/tools/i18n.js";const U=({className:p,children:R,columns:s=[],rowData:y=[],mobileLayout:h="none",caption:n,expandedRows:f=new Set,loading:B=!1,skeletonRowCount:N=10,onSortChange:_,...g})=>{const d=C({sortedAscending:"Dropin.Table.sortedAscending",sortedDescending:"Dropin.Table.sortedDescending",sortBy:"Dropin.Table.sortBy"}),D=e=>{if(!_)return;let t;e.sortBy===!0?t="asc":e.sortBy==="asc"?t="desc":t=!0,_(e.key,t)},m=e=>{if(e.sortBy===void 0)return null;let t,a;return e.sortBy==="asc"?(t="ChevronUp",a=d.sortedAscending.replace("{label}",e.label)):e.sortBy==="desc"?(t="ChevronDown",a=d.sortedDescending.replace("{label}",e.label)):(t="Sort",a=d.sortBy.replace("{label}",e.label)),r(A,{variant:"tertiary",size:"medium",className:"dropin-table__header__sort-button",icon:r($,{source:t}),"aria-label":a,onClick:()=>D(e)})},k=()=>Array.from({length:N},(e,t)=>r("tr",{className:"dropin-table__body__row",children:s.map(a=>r("td",{className:"dropin-table__body__cell","data-label":a.label,children:r(u,{children:r(x,{variant:"row",size:"small",fullWidth:!0})})},a.key))},`skeleton-${t}`)),w=()=>y.map((e,t)=>{const a=e._rowDetails!==void 0,S=f.has(t);return o(T,{children:[r("tr",{className:"dropin-table__body__row",children:s.map(l=>{const i=e[l.key];return typeof i=="string"||typeof i=="number"?r("td",{className:"dropin-table__body__cell","data-label":l.label,children:i},l.key):r("td",{className:"dropin-table__body__cell","data-label":l.label,children:r(b,{node:i})},l.key)})}),a&&S&&r("tr",{className:"dropin-table__row-details dropin-table__row-details--expanded",id:`row-${t}-details`,children:r("td",{className:"dropin-table__row-details__cell",colSpan:s.length,role:"region","aria-labelledby":`row-${t}-details`,children:typeof e._rowDetails=="string"?e._rowDetails:r(b,{node:e._rowDetails})})},`${t}-details`)]},t)}),v=e=>{if(e.sortBy===!0)return"none";if(e.sortBy==="asc")return"ascending";if(e.sortBy==="desc")return"descending"};return r("div",{className:c(["dropin-table",`dropin-table--mobile-layout-${h}`,p]),children:o("table",{...g,className:"dropin-table__table",children:[n&&r("caption",{className:"dropin-table__caption",children:n}),r("thead",{className:"dropin-table__header",children:r("tr",{className:"dropin-table__header__row",children:s.map(e=>o("th",{className:c(["dropin-table__header__cell",["dropin-table__header__cell--sorted",e.sortBy==="asc"||e.sortBy==="desc"],["dropin-table__header__cell--sortable",e.sortBy!==void 0]]),"aria-sort":v(e),children:[e.label,m(e)]},e.key))})}),r("tbody",{className:"dropin-table__body",children:B?k():w()})]})})};export{U as T};
4
+ //# sourceMappingURL=Table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Table.js","sources":["../../node_modules/@adobe-commerce/elsie/src/components/Table/Table.tsx"],"sourcesContent":["/********************************************************************\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { FunctionComponent, VNode, Fragment } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\nimport { classes, VComponent } from '@adobe-commerce/elsie/lib';\nimport { Icon, Button, Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\n\nimport '@adobe-commerce/elsie/components/Table/Table.css';\n\ntype Sortable = 'asc' | 'desc' | true;\n\ntype Column = {\n key: string;\n label: string;\n sortBy?: Sortable;\n};\n\ntype RowData = {\n [key: string]: VNode | string | number | undefined;\n _rowDetails?: VNode | string; // Special property for expandable row content\n};\n\nexport interface TableProps extends Omit<HTMLAttributes<HTMLTableElement>, 'loading'> {\n columns: Column[];\n rowData: RowData[];\n mobileLayout?: 'stacked' | 'none';\n caption?: string;\n expandedRows?: Set<number>;\n loading?: boolean;\n skeletonRowCount?: number;\n onSortChange?: (columnKey: string, direction: Sortable) => void;\n}\n\nexport const Table: FunctionComponent<TableProps> = ({\n className,\n children,\n columns = [],\n rowData = [],\n mobileLayout = 'none',\n caption,\n expandedRows = new Set(),\n loading = false,\n skeletonRowCount = 10,\n onSortChange,\n ...props\n}) => {\n const translations = useText({\n sortedAscending: 'Dropin.Table.sortedAscending',\n sortedDescending: 'Dropin.Table.sortedDescending',\n sortBy: 'Dropin.Table.sortBy',\n });\n\n const handleSort = (column: Column) => {\n if (!onSortChange) return;\n\n // Determine next sort direction\n let nextDirection: Sortable;\n if (column.sortBy === true) {\n nextDirection = 'asc';\n } else if (column.sortBy === 'asc') {\n nextDirection = 'desc';\n } else {\n nextDirection = true;\n }\n\n onSortChange(column.key, nextDirection);\n };\n\n const renderSortButton = (column: Column) => {\n if (column.sortBy === undefined) return null;\n\n let iconSource: string;\n let ariaLabel: string;\n\n if (column.sortBy === 'asc') {\n iconSource = 'ChevronUp';\n ariaLabel = translations.sortedAscending.replace('{label}', column.label);\n } else if (column.sortBy === 'desc') {\n iconSource = 'ChevronDown';\n ariaLabel = translations.sortedDescending.replace('{label}', column.label);\n } else {\n iconSource = 'Sort';\n ariaLabel = translations.sortBy.replace('{label}', column.label);\n }\n\n return (\n <Button\n variant=\"tertiary\"\n size=\"medium\"\n className=\"dropin-table__header__sort-button\"\n icon={<Icon source={iconSource} />}\n aria-label={ariaLabel}\n onClick={() => handleSort(column)}\n />\n );\n };\n\n const renderSkeletonRows = () => {\n return Array.from({ length: skeletonRowCount }, (_, rowIndex) => (\n <tr key={`skeleton-${rowIndex}`} className=\"dropin-table__body__row\">\n {columns.map((column) => (\n <td key={column.key} className=\"dropin-table__body__cell\" data-label={column.label}>\n <Skeleton>\n <SkeletonRow variant=\"row\" size=\"small\" fullWidth />\n </Skeleton>\n </td>\n ))}\n </tr>\n ));\n };\n\n const renderDataRows = () => {\n return rowData.map((row, rowIndex) => {\n const hasDetails = row._rowDetails !== undefined;\n const isExpanded = expandedRows.has(rowIndex);\n\n return (\n <Fragment key={rowIndex}>\n <tr className=\"dropin-table__body__row\">\n {columns.map((column) => {\n const cell = row[column.key];\n\n if (typeof cell === 'string' || typeof cell === 'number') {\n return (\n <td key={column.key} className=\"dropin-table__body__cell\" data-label={column.label}>\n {cell}\n </td>\n );\n }\n\n return (\n <td key={column.key} className=\"dropin-table__body__cell\" data-label={column.label}>\n <VComponent node={cell!} />\n </td>\n );\n })}\n </tr>\n {hasDetails && isExpanded && (\n <tr\n key={`${rowIndex}-details`}\n className=\"dropin-table__row-details dropin-table__row-details--expanded\"\n id={`row-${rowIndex}-details`}\n >\n <td\n className=\"dropin-table__row-details__cell\"\n colSpan={columns.length}\n role=\"region\"\n aria-labelledby={`row-${rowIndex}-details`}\n >\n {typeof row._rowDetails === 'string' ? row._rowDetails : <VComponent node={row._rowDetails!} />}\n </td>\n </tr>\n )}\n </Fragment>\n );\n });\n };\n\n const getAriaSort = (column: Column): 'none' | 'ascending' | 'descending' | 'other' | undefined => {\n if (column.sortBy === true) return 'none';\n if (column.sortBy === 'asc') return 'ascending';\n if (column.sortBy === 'desc') return 'descending';\n return undefined;\n };\n\n return (\n <div className={classes(['dropin-table', `dropin-table--mobile-layout-${mobileLayout}`, className])}>\n <table {...props} className=\"dropin-table__table\">\n {caption && <caption className=\"dropin-table__caption\">{caption}</caption>}\n <thead className=\"dropin-table__header\">\n <tr className=\"dropin-table__header__row\">\n {columns.map((column) => (\n <th\n key={column.key}\n className={classes([\n 'dropin-table__header__cell',\n ['dropin-table__header__cell--sorted', column.sortBy === 'asc' || column.sortBy === 'desc'],\n ['dropin-table__header__cell--sortable', column.sortBy !== undefined]\n ])}\n aria-sort={getAriaSort(column)}\n >\n {column.label}\n {renderSortButton(column)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody className=\"dropin-table__body\">\n {loading ? (\n // Render skeleton rows when loading\n renderSkeletonRows()\n ) : (\n // Render actual data when not loading\n renderDataRows()\n )}\n </tbody>\n </table>\n </div>\n );\n};\n"],"names":["Table","className","children","columns","rowData","mobileLayout","caption","expandedRows","loading","skeletonRowCount","onSortChange","props","translations","useText","handleSort","column","nextDirection","renderSortButton","iconSource","ariaLabel","jsx","Button","Icon","renderSkeletonRows","_","rowIndex","Skeleton","SkeletonRow","renderDataRows","row","hasDetails","isExpanded","Fragment","cell","VComponent","getAriaSort","classes","jsxs"],"mappings":"yUAyCO,MAAMA,EAAuC,CAAC,CACnD,UAAAC,EACA,SAAAC,EACA,QAAAC,EAAU,CAAC,EACX,QAAAC,EAAU,CAAC,EACX,aAAAC,EAAe,OACf,QAAAC,EACA,aAAAC,MAAmB,IACnB,QAAAC,EAAU,GACV,iBAAAC,EAAmB,GACnB,aAAAC,EACA,GAAGC,CACL,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,gBAAiB,+BACjB,iBAAkB,gCAClB,OAAQ,qBAAA,CACT,EAEKC,EAAcC,GAAmB,CACrC,GAAI,CAACL,EAAc,OAGf,IAAAM,EACAD,EAAO,SAAW,GACJC,EAAA,MACPD,EAAO,SAAW,MACXC,EAAA,OAEAA,EAAA,GAGLN,EAAAK,EAAO,IAAKC,CAAa,CACxC,EAEMC,EAAoBF,GAAmB,CACvC,GAAAA,EAAO,SAAW,OAAkB,OAAA,KAEpC,IAAAG,EACAC,EAEA,OAAAJ,EAAO,SAAW,OACPG,EAAA,YACbC,EAAYP,EAAa,gBAAgB,QAAQ,UAAWG,EAAO,KAAK,GAC/DA,EAAO,SAAW,QACdG,EAAA,cACbC,EAAYP,EAAa,iBAAiB,QAAQ,UAAW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dropins/tools/preact-jsx-runtime.js";import{useMemo as W,useRef as X,useCallback as g}from"@dropins/tools/preact-hooks.js";import{Checkbox as se}from"@dropins/tools/components.js";const ae=(k,_=!1)=>{const x=new Map;for(const h of k){const w=h.parentId??null,f=x.get(w)??[];f.push(h),x.set(w,f)}if(!_)for(const[,h]of x)h.sort((w,f)=>w.label.localeCompare(f.label));return x},ie=({items:k,rootId:_=null,className:x,expandedIds:h,selectedId:w=null,selectedIds:f,onExpandedChange:q,onSelectedChange:R,onSelectedIdsChange:j,renderNode:Y,role:Z="tree",preserveOrder:v=!1,draggable:C,canDrop:A,onMove:F,isCheckable:M,checkedIds:T,onCheckedChange:b,biDirectionalChecking:N=!1,renderExpander:B,renderCheckbox:E,renderIcon:G})=>{const y=W(()=>ae(k,v),[k,v]),S=X(null),K=X(!1),d=W(()=>new Map(k.map(e=>[e.id,e])),[k]),I=(e,n)=>{const c=[],o=[n];for(;o.length;){const t=o.pop(),s=e.get(t)??[];for(const r of s)c.push(r.id),o.push(r.id)}return c},D=g(e=>I(y,e),[y]),u=g(e=>M?M(e):!0,[M]),z=g(e=>{if(!d.get(e))return{checked:!1,indeterminate:!1};const c=T??new Set;if(N){if(c.has(e))return{checked:!0,indeterminate:!1};const s=D(e).filter(l=>{const p=d.get(l);return p?u(p):!1});return s.length===0?{checked:!1,indeterminate:!1}:s.reduce((l,p)=>c.has(p)?l+1:l,0)===0?{checked:!1,indeterminate:!1}:{checked:!1,indeterminate:!0}}const o=[e,...D(e)].filter(s=>{const r=d.get(s);return r?u(r):!1});if(o.length===0)return{checked:!1,indeterminate:!1};const t=o.reduce((s,r)=>c.has(r)?s+1:s,0);return t===0?{checked:!1,indeterminate:!1}:t===o.length?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}},[d,D,u,T,N]),H=g(e=>{if(!b)return;const n=new Set(T??[]),{checked:c}=z(e),o=D(e),t=[e,...o].filter(s=>{const r=d.get(s);return r?u(r):!1});if(c)for(const s of t)n.delete(s);else for(const s of t)n.add(s);if(N){const s=d.get(e);if(s){let r=s.parentId;for(;r;){const l=d.get(r);if(!l||!u(l))break;c?(y.get(r)??[]).some(P=>u(P)&&n.has(P.id))||n.delete(r):n.add(r),r=l.parentId}}}b(n)},[T,b,z,D,d,y,u,N]),ee=g(e=>$(se,{name:`tree-checkbox-${Math.random().toString(36).substr(2,9)}`,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onCheck}),[]),J=g(e=>{const n=new Set(h);n.has(e)?n.delete(e):n.add(e),q(n)},[h,q]),te=g(e=>{const n=d.get(e);if(n&&u(n)&&b&&H(e),!j){R==null||R(e);return}const c=!!K.current,o=c?new Set(f??[]):new Set;c&&o.has(e)?o.delete(e):o.add(e),j(o),K.current=!1},[R,j,f,d,u,b,H]),L=(e,n)=>{const c=y.get(e)??[];return c.length?$("ul",{role:n===1?Z:"group",className:n===1?x??"acm-tree":"acm-tree__group",children:c.map((t,s)=>{const r=(y.get(t.id)??[]).length>0,l=h.has(t.id),p=f?f.has(t.id):w===t.id,O=!!(C!=null&&C(t)),P=a=>A?A(a,t.id):a!==t.id,Q=r?()=>B?B({expanded:l,hasChildren:r,toggle:()=>J(t.id)}):null:void 0,U=(()=>{if(!b)return;const a=d.get(t.id);if(!a||!u(a))return;const i=z(t.id),m=E||ee;return()=>m({checked:i.checked,indeterminate:i.indeterminate,onCheck:()=>H(t.id)})})(),V=G?()=>G({item:t,level:n,hasChildren:r,expanded:l}):void 0,ne=Y({item:t,level:n,expanded:l,selected:!!p,hasChildren:r,toggle:()=>J(t.id),select:()=>te(t.id),...Q?{expander:Q}:{},...U?{checkbox:U}:{},...V?{icon:V}:{}});return re("li",{role:"treeitem",className:"acm-tree__item","data-level":n,"aria-expanded":r?l:void 0,"aria-selected":p||void 0,"aria-level":n,"aria-setsize":c.length,"aria-posinset":s+1,draggable:O,onMouseDown:a=>{K.current=!!(a.metaKey||a.ctrlKey)},onDragStart:a=>{var i;if(a.stopPropagation(),!!O){S.current=t.id;try{(i=a.dataTransfer)==null||i.setData("text/plain",t.id)}catch{}}},onDragOver:a=>{var m;a.stopPropagation();const i=S.current??(((m=a.dataTransfer)==null?void 0:m.getData("text/plain"))||"");i&&P(i)&&a.preventDefault()},onDrop:a=>{var m;a.stopPropagation();const i=S.current??(((m=a.dataTransfer)==null?void 0:m.getData("text/plain"))||"");S.current=null,i&&P(i)&&(F==null||F({id:i,newParentId:t.id}))},children:[ne,r&&l?L(t.id,n+1):null]},t.id)})}):null};return $("div",{className:"acm-tree-root",children:L(_,1)})};export{ie as T};
4
+ //# sourceMappingURL=Tree.js.map