@box/user-selector 2.1.36 → 2.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/buildOptionsWithOverlay.js +1 -22
- package/dist/chunks/user-selector-headless.module.js +1 -14
- package/dist/chunks/user-selector-list-item.js +1 -84
- package/dist/chunks/user-selector.js +1 -89
- package/dist/esm/index.js +1 -4
- package/dist/esm/lib/messages.js +1 -44
- package/dist/esm/lib/shared.js +1 -7
- package/dist/esm/lib/user-selector-container.js +1 -30
- package/dist/esm/lib/user-selector-headless/components/user-avatar.js +1 -26
- package/dist/esm/lib/user-selector-headless/components/user-selector-content.js +1 -28
- package/dist/esm/lib/user-selector-headless/components/user-selector-default-empty.js +1 -38
- package/dist/esm/lib/user-selector-headless/components/user-selector-default-error.js +1 -14
- package/dist/esm/lib/user-selector-headless/components/user-selector-skeleton.js +1 -21
- package/dist/esm/lib/user-selector-headless/hooks/use-avatars.js +1 -14
- package/dist/esm/lib/user-selector-headless/hooks/use-keyboard-navigation.js +1 -25
- package/dist/esm/lib/user-selector-headless/hooks/use-select-options.js +1 -25
- package/dist/esm/lib/user-selector-headless/user-selector-context.js +1 -7
- package/dist/esm/lib/user-selector-headless/user-selector-headless.js +1 -172
- package/dist/esm/lib/user-selector-list-item.js +1 -2
- package/dist/esm/lib/user-selector.js +1 -2
- package/dist/esm/lib/utils/VariantsAggregator.js +1 -27
- package/dist/esm/lib/utils/buildOptionsWithOverlay.js +1 -2
- package/dist/esm/lib/utils/defaultRenderCustomOption.js +1 -11
- package/dist/esm/lib/utils/getInitials.js +1 -5
- package/dist/esm/lib/utils/isUserContactType.js +1 -4
- package/package.json +8 -8
|
@@ -1,22 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
function n(n, r, i) {
|
|
3
|
-
if (!n || n.length === 0) return n ?? void 0;
|
|
4
|
-
let a = [...n];
|
|
5
|
-
if (i >= 0 && i < a.length - 1) {
|
|
6
|
-
let e = {
|
|
7
|
-
name: "",
|
|
8
|
-
value: t
|
|
9
|
-
};
|
|
10
|
-
a = [
|
|
11
|
-
...a.slice(0, i + 1),
|
|
12
|
-
e,
|
|
13
|
-
...a.slice(i + 1)
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
return r && a.length > 0 && i >= 0 && (a = [{
|
|
17
|
-
name: "",
|
|
18
|
-
value: e,
|
|
19
|
-
label: r
|
|
20
|
-
}, ...a]), a;
|
|
21
|
-
}
|
|
22
|
-
export { e as n, t as r, n as t };
|
|
1
|
+
var OVERLAY_HEADER_VALUE=`__combobox_overlay_header__`,OVERLAY_SEPARATOR_VALUE=`__combobox_overlay_separator__`;function buildOptionsWithOverlay(options,overlayTitle,overlayDividerIndex){if(!options||options.length===0)return options??void 0;let result=[...options];if(overlayDividerIndex>=0&&overlayDividerIndex<result.length-1){let dividerOption={name:``,value:OVERLAY_SEPARATOR_VALUE};result=[...result.slice(0,overlayDividerIndex+1),dividerOption,...result.slice(overlayDividerIndex+1)]}return overlayTitle&&result.length>0&&overlayDividerIndex>=0&&(result=[{name:``,value:OVERLAY_HEADER_VALUE,label:overlayTitle},...result]),result}export{OVERLAY_HEADER_VALUE as n,OVERLAY_SEPARATOR_VALUE as r,buildOptionsWithOverlay as t};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import '../styles/user-selector-headless.css';var
|
|
2
|
-
userSelectorListItemBase: "_userSelectorListItemBase_17ynx_1",
|
|
3
|
-
userSelectorInviteRow: "_userSelectorInviteRow_17ynx_1",
|
|
4
|
-
popoverContainer: "_popoverContainer_17ynx_18",
|
|
5
|
-
popoverContent: "_popoverContent_17ynx_26",
|
|
6
|
-
userSelectorListItem: "_userSelectorListItem_17ynx_1",
|
|
7
|
-
listItemAvatar: "_listItemAvatar_17ynx_37",
|
|
8
|
-
userSelectorGhostStateItem: "_userSelectorGhostStateItem_17ynx_41",
|
|
9
|
-
titleGhost: "_titleGhost_17ynx_47",
|
|
10
|
-
userSelectorEmptyText: "_userSelectorEmptyText_17ynx_51",
|
|
11
|
-
userSelectorEmptyContainer: "_userSelectorEmptyContainer_17ynx_55",
|
|
12
|
-
userSelectorInviteButtonIcon: "_userSelectorInviteButtonIcon_17ynx_70"
|
|
13
|
-
};
|
|
14
|
-
export { e as t };
|
|
1
|
+
import '../styles/user-selector-headless.css';var user_selector_headless_module_default={userSelectorListItemBase:`_userSelectorListItemBase_17ynx_1`,userSelectorInviteRow:`_userSelectorInviteRow_17ynx_1`,popoverContainer:`_popoverContainer_17ynx_18`,popoverContent:`_popoverContent_17ynx_26`,userSelectorListItem:`_userSelectorListItem_17ynx_1`,listItemAvatar:`_listItemAvatar_17ynx_37`,userSelectorGhostStateItem:`_userSelectorGhostStateItem_17ynx_41`,titleGhost:`_titleGhost_17ynx_47`,userSelectorEmptyText:`_userSelectorEmptyText_17ynx_51`,userSelectorEmptyContainer:`_userSelectorEmptyContainer_17ynx_55`,userSelectorInviteButtonIcon:`_userSelectorInviteButtonIcon_17ynx_70`};export{user_selector_headless_module_default as t};
|
|
@@ -1,84 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isUserContactType as t } from "../esm/lib/utils/isUserContactType.js";
|
|
3
|
-
import n, { forwardRef as r } from "react";
|
|
4
|
-
import i from "clsx";
|
|
5
|
-
import { useIntl as a } from "react-intl";
|
|
6
|
-
import { Combobox as o, Text as s, Tooltip as c } from "@box/blueprint-web";
|
|
7
|
-
import { AvatarPlusBadge as l } from "@box/blueprint-web-assets/icons/Line";
|
|
8
|
-
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
-
import '../styles/user-selector-list-item.css';var f = {
|
|
10
|
-
userSelectorListItemBase: "_userSelectorListItemBase_1m2q6_1",
|
|
11
|
-
userSelectorListItem: "_userSelectorListItem_1m2q6_1",
|
|
12
|
-
listItemAvatar: "_listItemAvatar_1m2q6_18",
|
|
13
|
-
userInfo: "_userInfo_1m2q6_21",
|
|
14
|
-
title: "_title_1m2q6_28",
|
|
15
|
-
userName: "_userName_1m2q6_34",
|
|
16
|
-
userEmail: "_userEmail_1m2q6_35",
|
|
17
|
-
userSelectorListItemInviteIcon: "_userSelectorListItemInviteIcon_1m2q6_43"
|
|
18
|
-
}, p = /*#__PURE__*/ r(({ renderAvatar: t, title: r, subtitle: o, onClick: p, className: m, id: h, selected: g, isCollaborator: _ = !0, ...v }, y) => {
|
|
19
|
-
let b = /*#__PURE__*/ n.cloneElement(t(), { className: i(f.listItemAvatar) }), { formatMessage: x } = a(), S = /* @__PURE__ */ d("div", {
|
|
20
|
-
ref: y,
|
|
21
|
-
"aria-selected": g,
|
|
22
|
-
className: i(f.userSelectorListItem, m),
|
|
23
|
-
id: h,
|
|
24
|
-
...p ? { onClick: p } : {},
|
|
25
|
-
...v,
|
|
26
|
-
children: [
|
|
27
|
-
b,
|
|
28
|
-
/* @__PURE__ */ d("div", {
|
|
29
|
-
className: i(f.userInfo),
|
|
30
|
-
children: [/* @__PURE__ */ u("div", {
|
|
31
|
-
className: i(f.title),
|
|
32
|
-
children: /* @__PURE__ */ u(s, {
|
|
33
|
-
as: "span",
|
|
34
|
-
className: i(f.userName),
|
|
35
|
-
variant: "bodyDefaultSemibold",
|
|
36
|
-
children: r
|
|
37
|
-
})
|
|
38
|
-
}), /* @__PURE__ */ u(s, {
|
|
39
|
-
as: "span",
|
|
40
|
-
className: i(f.userEmail),
|
|
41
|
-
color: "textOnLightSecondary",
|
|
42
|
-
variant: "caption",
|
|
43
|
-
children: o
|
|
44
|
-
})]
|
|
45
|
-
}),
|
|
46
|
-
!_ && /* @__PURE__ */ u(l, { className: f.userSelectorListItemInviteIcon })
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
return _ ? S : /* @__PURE__ */ u(c, {
|
|
50
|
-
content: x(e.inviteCollaboratorsTooltip),
|
|
51
|
-
side: "right",
|
|
52
|
-
children: S
|
|
53
|
-
});
|
|
54
|
-
}), m = /*#__PURE__*/ r(({ renderAvatar: t, userContact: n, onClick: r, id: i, ...o }, s) => {
|
|
55
|
-
let c = a().formatMessage(e.userName, {
|
|
56
|
-
name: n.name,
|
|
57
|
-
isCurrentUser: !!n.isCurrentUser
|
|
58
|
-
});
|
|
59
|
-
return /* @__PURE__ */ u(p, {
|
|
60
|
-
ref: s,
|
|
61
|
-
id: i,
|
|
62
|
-
onClick: () => {
|
|
63
|
-
r?.(n, i);
|
|
64
|
-
},
|
|
65
|
-
renderAvatar: () => t(n),
|
|
66
|
-
subtitle: n.email,
|
|
67
|
-
title: c,
|
|
68
|
-
...o
|
|
69
|
-
});
|
|
70
|
-
}), h = /*#__PURE__*/ r(function(e, n) {
|
|
71
|
-
let { className: r, userContact: i, renderAvatar: a, renderCustomOption: s, ...c } = e, l = t(i), d = l ? !0 : i.hideOnClick ?? !0;
|
|
72
|
-
return /* @__PURE__ */ u(o.Option, {
|
|
73
|
-
ref: n,
|
|
74
|
-
className: r,
|
|
75
|
-
hideOnClick: d,
|
|
76
|
-
value: i.value,
|
|
77
|
-
...c,
|
|
78
|
-
children: l ? /* @__PURE__ */ u(m, {
|
|
79
|
-
renderAvatar: a,
|
|
80
|
-
userContact: i
|
|
81
|
-
}) : s(i, () => a(i))
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
export { m as n, p as r, h as t };
|
|
1
|
+
import messages from"../esm/lib/messages.js";import{isUserContactType}from"../esm/lib/utils/isUserContactType.js";import React,{forwardRef}from"react";import clsx from"clsx";import{useIntl}from"react-intl";import{Combobox,Text,Tooltip}from"@box/blueprint-web";import{AvatarPlusBadge}from"@box/blueprint-web-assets/icons/Line";import{jsx,jsxs}from"react/jsx-runtime";import '../styles/user-selector-list-item.css';var user_selector_list_item_module_default={userSelectorListItemBase:`_userSelectorListItemBase_1m2q6_1`,userSelectorListItem:`_userSelectorListItem_1m2q6_1`,listItemAvatar:`_listItemAvatar_1m2q6_18`,userInfo:`_userInfo_1m2q6_21`,title:`_title_1m2q6_28`,userName:`_userName_1m2q6_34`,userEmail:`_userEmail_1m2q6_35`,userSelectorListItemInviteIcon:`_userSelectorListItemInviteIcon_1m2q6_43`},UserSelectorListItemInfo=forwardRef(({renderAvatar,title,subtitle,onClick,className,id,selected,isCollaborator=!0,...rest},forwardedRef)=>{let avatar=React.cloneElement(renderAvatar(),{className:clsx(user_selector_list_item_module_default.listItemAvatar)}),{formatMessage}=useIntl(),content=jsxs(`div`,{ref:forwardedRef,"aria-selected":selected,className:clsx(user_selector_list_item_module_default.userSelectorListItem,className),id,...onClick?{onClick}:{},...rest,children:[avatar,jsxs(`div`,{className:clsx(user_selector_list_item_module_default.userInfo),children:[jsx(`div`,{className:clsx(user_selector_list_item_module_default.title),children:jsx(Text,{as:`span`,className:clsx(user_selector_list_item_module_default.userName),variant:`bodyDefaultSemibold`,children:title})}),jsx(Text,{as:`span`,className:clsx(user_selector_list_item_module_default.userEmail),color:`textOnLightSecondary`,variant:`caption`,children:subtitle})]}),!isCollaborator&&jsx(AvatarPlusBadge,{className:user_selector_list_item_module_default.userSelectorListItemInviteIcon})]});return isCollaborator?content:jsx(Tooltip,{content:formatMessage(messages.inviteCollaboratorsTooltip),side:`right`,children:content})}),UserSelectorListItem=forwardRef(({renderAvatar,userContact,onClick,id,...rest},forwardedRef)=>{let usernameText=useIntl().formatMessage(messages.userName,{name:userContact.name,isCurrentUser:!!userContact.isCurrentUser});return jsx(UserSelectorListItemInfo,{ref:forwardedRef,id,onClick:()=>{onClick?.(userContact,id)},renderAvatar:()=>renderAvatar(userContact),subtitle:userContact.email,title:usernameText,...rest})}),UserSelectorComboboxOption=forwardRef(function(props,forwardedRef){let{className,userContact,renderAvatar,renderCustomOption,...optionProps}=props,isUserOption=isUserContactType(userContact),hideOnClick=isUserOption?!0:userContact.hideOnClick??!0;return jsx(Combobox.Option,{ref:forwardedRef,className,hideOnClick,value:userContact.value,...optionProps,children:isUserOption?jsx(UserSelectorListItem,{renderAvatar,userContact}):renderCustomOption(userContact,()=>renderAvatar(userContact))})});export{UserSelectorListItem as n,UserSelectorListItemInfo as r,UserSelectorComboboxOption as t};
|
|
@@ -1,89 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "../esm/lib/messages.js";
|
|
3
|
-
import { t as n } from "./user-selector-list-item.js";
|
|
4
|
-
import { isUserContactType as r } from "../esm/lib/utils/isUserContactType.js";
|
|
5
|
-
import { defaultRenderCustomOption as i } from "../esm/lib/utils/defaultRenderCustomOption.js";
|
|
6
|
-
import { getInitials as a } from "../esm/lib/utils/getInitials.js";
|
|
7
|
-
import { useCallback as o } from "react";
|
|
8
|
-
import s from "clsx";
|
|
9
|
-
import { useIntl as c } from "react-intl";
|
|
10
|
-
import { Avatar as l, Combobox as u, Divider as d, IconBadge as f, Text as p } from "@box/blueprint-web";
|
|
11
|
-
import { ComboboxWithApi as m } from "@box/combobox-with-api";
|
|
12
|
-
import { jsx as h } from "react/jsx-runtime";
|
|
13
|
-
import '../styles/user-selector.css';var g = {
|
|
14
|
-
overlayHeader: "_overlayHeader_u0715_1",
|
|
15
|
-
overlaySeparatorOption: "_overlaySeparatorOption_u0715_8",
|
|
16
|
-
textArea: "_textArea_u0715_15"
|
|
17
|
-
}, _ = (_) => {
|
|
18
|
-
let { fetchedAvatarUrls: v, fetchUsers: y, onSelectedUsersChange: b, selectedUsers: x, variant: S, className: C, defaultOptions: w, overlayDividerIndex: T, overlayTitle: E, renderCustomOption: D = i, ...O } = _, k = c(), A = (e) => {
|
|
19
|
-
if (!(e.value === "__combobox_overlay_header__" || e.value === "__combobox_overlay_separator__")) {
|
|
20
|
-
if (r(e)) {
|
|
21
|
-
let { name: n, isExternalUser: r, id: i } = e, o = /* @__PURE__ */ h(l, {
|
|
22
|
-
alt: k.formatMessage(t.userAvatar),
|
|
23
|
-
colorIndex: i,
|
|
24
|
-
src: v[i],
|
|
25
|
-
text: a(n)
|
|
26
|
-
});
|
|
27
|
-
return r ? /* @__PURE__ */ h(f, {
|
|
28
|
-
offset: {
|
|
29
|
-
right: -4,
|
|
30
|
-
bottom: -2
|
|
31
|
-
},
|
|
32
|
-
size: "medium",
|
|
33
|
-
variant: "collaborator-external",
|
|
34
|
-
children: o
|
|
35
|
-
}) : o;
|
|
36
|
-
}
|
|
37
|
-
return /* @__PURE__ */ h(l, { ...e.avatar });
|
|
38
|
-
}
|
|
39
|
-
}, j = (e) => {
|
|
40
|
-
if (!r(e)) return e.chipVariant;
|
|
41
|
-
}, M = o(async (t) => {
|
|
42
|
-
let n = await y(t);
|
|
43
|
-
if (!E || T == null || T < 0) return n;
|
|
44
|
-
let r = new Set(x.map((e) => e.value)), i = n.filter((e) => !r.has(e.value)), a = n.slice(0, T + 1).filter((e) => !r.has(e.value)).length;
|
|
45
|
-
return e(i, E, a > 0 ? a - 1 : -1);
|
|
46
|
-
}, [
|
|
47
|
-
y,
|
|
48
|
-
E,
|
|
49
|
-
T,
|
|
50
|
-
x
|
|
51
|
-
]);
|
|
52
|
-
return /* @__PURE__ */ h(m, {
|
|
53
|
-
as: "input",
|
|
54
|
-
className: s(C, S === "textarea" && g.textArea),
|
|
55
|
-
defaultOptions: w,
|
|
56
|
-
displayAvatar: A,
|
|
57
|
-
displayChipVariant: j,
|
|
58
|
-
displayValue: (e) => e.name,
|
|
59
|
-
fetcher: M,
|
|
60
|
-
freeInput: !1,
|
|
61
|
-
loadingAriaLabel: k.formatMessage(t.loading),
|
|
62
|
-
multiselect: !0,
|
|
63
|
-
noResultMessage: k.formatMessage(t.noResults),
|
|
64
|
-
onValueChange: b,
|
|
65
|
-
renderOption: (e) => e.value === "__combobox_overlay_header__" && "label" in e ? /* @__PURE__ */ h(u.Option, {
|
|
66
|
-
className: g.overlayHeader,
|
|
67
|
-
disabled: !0,
|
|
68
|
-
value: e.value,
|
|
69
|
-
children: /* @__PURE__ */ h(p, {
|
|
70
|
-
as: "span",
|
|
71
|
-
variant: "bodySmallSemibold",
|
|
72
|
-
color: "textOnLightSecondary",
|
|
73
|
-
children: e.label
|
|
74
|
-
})
|
|
75
|
-
}) : e.value === "__combobox_overlay_separator__" ? /* @__PURE__ */ h(u.Option, {
|
|
76
|
-
className: g.overlaySeparatorOption,
|
|
77
|
-
disabled: !0,
|
|
78
|
-
value: e.value,
|
|
79
|
-
children: /* @__PURE__ */ h(d, { "aria-hidden": !0 })
|
|
80
|
-
}) : /* @__PURE__ */ h(n, {
|
|
81
|
-
renderAvatar: A,
|
|
82
|
-
renderCustomOption: D,
|
|
83
|
-
userContact: e
|
|
84
|
-
}),
|
|
85
|
-
value: x,
|
|
86
|
-
...O
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
export { _ as t };
|
|
1
|
+
import{t as buildOptionsWithOverlay}from"./buildOptionsWithOverlay.js";import messages from"../esm/lib/messages.js";import{t as UserSelectorComboboxOption}from"./user-selector-list-item.js";import{isUserContactType}from"../esm/lib/utils/isUserContactType.js";import{defaultRenderCustomOption}from"../esm/lib/utils/defaultRenderCustomOption.js";import{getInitials}from"../esm/lib/utils/getInitials.js";import{useCallback}from"react";import clsx from"clsx";import{useIntl}from"react-intl";import{Avatar,Combobox,Divider,IconBadge,Text}from"@box/blueprint-web";import{ComboboxWithApi}from"@box/combobox-with-api";import{jsx}from"react/jsx-runtime";import '../styles/user-selector.css';var user_selector_module_default={overlayHeader:`_overlayHeader_u0715_1`,overlaySeparatorOption:`_overlaySeparatorOption_u0715_8`,textArea:`_textArea_u0715_15`},UserSelector=props=>{let{fetchedAvatarUrls,fetchUsers,onSelectedUsersChange,selectedUsers,variant,className,defaultOptions,overlayDividerIndex,overlayTitle,renderCustomOption=defaultRenderCustomOption,...rest}=props,intl=useIntl(),renderAvatar=option=>{if(!(option.value===`__combobox_overlay_header__`||option.value===`__combobox_overlay_separator__`)){if(isUserContactType(option)){let{name,isExternalUser,id}=option,avatar=jsx(Avatar,{alt:intl.formatMessage(messages.userAvatar),colorIndex:id,src:fetchedAvatarUrls[id],text:getInitials(name)});return isExternalUser?jsx(IconBadge,{offset:{right:-4,bottom:-2},size:`medium`,variant:`collaborator-external`,children:avatar}):avatar}return jsx(Avatar,{...option.avatar})}},displayChipVariant=option=>{if(!isUserContactType(option))return option.chipVariant},fetcherWithOverlay=useCallback(async inputValue=>{let options=await fetchUsers(inputValue);if(!overlayTitle||overlayDividerIndex==null||overlayDividerIndex<0)return options;let selectedValues=new Set(selectedUsers.map(s=>s.value)),visibleOptions=options.filter(opt=>!selectedValues.has(opt.value)),beforeCount=options.slice(0,overlayDividerIndex+1).filter(opt=>!selectedValues.has(opt.value)).length;return buildOptionsWithOverlay(visibleOptions,overlayTitle,beforeCount>0?beforeCount-1:-1)},[fetchUsers,overlayTitle,overlayDividerIndex,selectedUsers]);return jsx(ComboboxWithApi,{as:`input`,className:clsx(className,variant===`textarea`&&user_selector_module_default.textArea),defaultOptions,displayAvatar:renderAvatar,displayChipVariant,displayValue:option=>option.name,fetcher:fetcherWithOverlay,freeInput:!1,loadingAriaLabel:intl.formatMessage(messages.loading),multiselect:!0,noResultMessage:intl.formatMessage(messages.noResults),onValueChange:onSelectedUsersChange,renderOption:option=>option.value===`__combobox_overlay_header__`&&`label`in option?jsx(Combobox.Option,{className:user_selector_module_default.overlayHeader,disabled:!0,value:option.value,children:jsx(Text,{as:`span`,variant:`bodySmallSemibold`,color:`textOnLightSecondary`,children:option.label})}):option.value===`__combobox_overlay_separator__`?jsx(Combobox.Option,{className:user_selector_module_default.overlaySeparatorOption,disabled:!0,value:option.value,children:jsx(Divider,{"aria-hidden":!0})}):jsx(UserSelectorComboboxOption,{renderAvatar,renderCustomOption,userContact:option}),value:selectedUsers,...rest})};export{UserSelector as t};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { UserSelectorContainer as n } from "./lib/user-selector-container.js";
|
|
3
|
-
import { UserSelectorHeadless as r } from "./lib/user-selector-headless/user-selector-headless.js";
|
|
4
|
-
export { e as OVERLAY_HEADER_VALUE, t as OVERLAY_SEPARATOR_VALUE, n as UserSelectorContainer, r as UserSelectorHeadless };
|
|
1
|
+
import{n as OVERLAY_HEADER_VALUE,r as OVERLAY_SEPARATOR_VALUE}from"../chunks/buildOptionsWithOverlay.js";import{UserSelectorContainer}from"./lib/user-selector-container.js";import{UserSelectorHeadless}from"./lib/user-selector-headless/user-selector-headless.js";export{OVERLAY_HEADER_VALUE,OVERLAY_SEPARATOR_VALUE,UserSelectorContainer,UserSelectorHeadless};
|
package/dist/esm/lib/messages.js
CHANGED
|
@@ -1,44 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var t = e({
|
|
3
|
-
loading: {
|
|
4
|
-
id: "groupSharedFeatures.userSelector.loading",
|
|
5
|
-
defaultMessage: "Loading"
|
|
6
|
-
},
|
|
7
|
-
noResults: {
|
|
8
|
-
id: "groupSharedFeatures.userSelector.noResults",
|
|
9
|
-
defaultMessage: "No results"
|
|
10
|
-
},
|
|
11
|
-
tryAgain: {
|
|
12
|
-
id: "groupSharedFeatures.userSelector.tryAgain",
|
|
13
|
-
defaultMessage: "Try again"
|
|
14
|
-
},
|
|
15
|
-
userAvatar: {
|
|
16
|
-
id: "groupSharedFeatures.userSelector.userAvatar",
|
|
17
|
-
defaultMessage: "User avatar"
|
|
18
|
-
},
|
|
19
|
-
userName: {
|
|
20
|
-
id: "groupSharedFeatures.userSelector.userName",
|
|
21
|
-
defaultMessage: "{name} {isCurrentUser, select, true { (me)} other {}}"
|
|
22
|
-
},
|
|
23
|
-
errorMessage: {
|
|
24
|
-
id: "groupSharedFeatures.userSelector.errorMessage",
|
|
25
|
-
defaultMessage: "We were unable to load users"
|
|
26
|
-
},
|
|
27
|
-
errorMessageDescription: {
|
|
28
|
-
id: "groupSharedFeatures.userSelector.errorMessageDescription",
|
|
29
|
-
defaultMessage: "Please try again later"
|
|
30
|
-
},
|
|
31
|
-
emptyMessage: {
|
|
32
|
-
id: "groupSharedFeatures.userSelector.emptyMessage",
|
|
33
|
-
defaultMessage: "NO COLLABORATORS FOUND"
|
|
34
|
-
},
|
|
35
|
-
inviteCollaborators: {
|
|
36
|
-
id: "groupSharedFeatures.userSelector.inviteCollaborators",
|
|
37
|
-
defaultMessage: "Invite Collaborators"
|
|
38
|
-
},
|
|
39
|
-
inviteCollaboratorsTooltip: {
|
|
40
|
-
id: "groupSharedFeatures.userSelector.inviteCollaboratorsTooltip",
|
|
41
|
-
defaultMessage: "This person doesn't have access and won't be notified unless invited."
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
export { t as default };
|
|
1
|
+
import{defineMessages}from"react-intl";var messages=defineMessages({loading:{id:`groupSharedFeatures.userSelector.loading`,defaultMessage:`Loading`},noResults:{id:`groupSharedFeatures.userSelector.noResults`,defaultMessage:`No results`},tryAgain:{id:`groupSharedFeatures.userSelector.tryAgain`,defaultMessage:`Try again`},userAvatar:{id:`groupSharedFeatures.userSelector.userAvatar`,defaultMessage:`User avatar`},userName:{id:`groupSharedFeatures.userSelector.userName`,defaultMessage:`{name} {isCurrentUser, select, true { (me)} other {}}`},errorMessage:{id:`groupSharedFeatures.userSelector.errorMessage`,defaultMessage:`We were unable to load users`},errorMessageDescription:{id:`groupSharedFeatures.userSelector.errorMessageDescription`,defaultMessage:`Please try again later`},emptyMessage:{id:`groupSharedFeatures.userSelector.emptyMessage`,defaultMessage:`NO COLLABORATORS FOUND`},inviteCollaborators:{id:`groupSharedFeatures.userSelector.inviteCollaborators`,defaultMessage:`Invite Collaborators`},inviteCollaboratorsTooltip:{id:`groupSharedFeatures.userSelector.inviteCollaboratorsTooltip`,defaultMessage:`This person doesn't have access and won't be notified unless invited.`}});export{messages as default};
|
package/dist/esm/lib/shared.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t } from "../../chunks/user-selector.js";
|
|
3
|
-
import { defaultRenderCustomOption as n } from "./utils/defaultRenderCustomOption.js";
|
|
4
|
-
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
5
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
6
|
-
var c = ({ fetchAvatarUrls: c, fetchUsers: l, onSelectedUsersChange: u, selectedUsers: d, renderCustomOption: f = n, ...p }) => {
|
|
7
|
-
let m = a(!0), [h, g] = o([]), [_, v] = o({}), y = r(async (e) => {
|
|
8
|
-
let t = await l(e);
|
|
9
|
-
return g(t), t;
|
|
10
|
-
}, [l, g]), b = r(async (e) => {
|
|
11
|
-
try {
|
|
12
|
-
v(await c(e));
|
|
13
|
-
} catch {
|
|
14
|
-
v({});
|
|
15
|
-
}
|
|
16
|
-
}, [c, v]);
|
|
17
|
-
return i(() => {
|
|
18
|
-
m.current && (m.current = !1, d.length > 0 && g(d.filter(e)));
|
|
19
|
-
}, [d, g]), i(() => {
|
|
20
|
-
h.length > 0 && b(h.filter(e));
|
|
21
|
-
}, [h, b]), /* @__PURE__ */ s(t, {
|
|
22
|
-
fetchedAvatarUrls: _,
|
|
23
|
-
fetchUsers: y,
|
|
24
|
-
onSelectedUsersChange: u,
|
|
25
|
-
renderCustomOption: f,
|
|
26
|
-
selectedUsers: d,
|
|
27
|
-
...p
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
export { c as UserSelectorContainer };
|
|
1
|
+
import{isUserContactType}from"./utils/isUserContactType.js";import{t as UserSelector}from"../../chunks/user-selector.js";import{defaultRenderCustomOption}from"./utils/defaultRenderCustomOption.js";import{useCallback,useEffect,useRef,useState}from"react";import{jsx}from"react/jsx-runtime";var UserSelectorContainer=({fetchAvatarUrls,fetchUsers,onSelectedUsersChange,selectedUsers,renderCustomOption=defaultRenderCustomOption,...rest})=>{let isFirstRender=useRef(!0),[fetchedOptions,setFetchedOptions]=useState([]),[fetchedAvatarUrls,setFetchedAvatarUrls]=useState({}),fetchOptions=useCallback(async inputVal=>{let options=await fetchUsers(inputVal);return setFetchedOptions(options),options},[fetchUsers,setFetchedOptions]),getAvatarUrls=useCallback(async users=>{try{setFetchedAvatarUrls(await fetchAvatarUrls(users))}catch{setFetchedAvatarUrls({})}},[fetchAvatarUrls,setFetchedAvatarUrls]);return useEffect(()=>{isFirstRender.current&&(isFirstRender.current=!1,selectedUsers.length>0&&setFetchedOptions(selectedUsers.filter(isUserContactType)))},[selectedUsers,setFetchedOptions]),useEffect(()=>{fetchedOptions.length>0&&getAvatarUrls(fetchedOptions.filter(isUserContactType))},[fetchedOptions,getAvatarUrls]),jsx(UserSelector,{fetchedAvatarUrls,fetchUsers:fetchOptions,onSelectedUsersChange,renderCustomOption,selectedUsers,...rest})};export{UserSelectorContainer};
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getInitials as t } from "../../utils/getInitials.js";
|
|
3
|
-
import { useUserSelector as n } from "../user-selector-context.js";
|
|
4
|
-
import { t as r } from "../../../../chunks/user-selector-headless.module.js";
|
|
5
|
-
import { useIntl as i } from "react-intl";
|
|
6
|
-
import { Avatar as a, IconBadge as o } from "@box/blueprint-web";
|
|
7
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
8
|
-
var c = ({ userContact: c }) => {
|
|
9
|
-
let l = i(), { avatars: u } = n(), d = t(c.name), f = /* @__PURE__ */ s(a, {
|
|
10
|
-
alt: l.formatMessage(e.userAvatar),
|
|
11
|
-
className: r.listItemAvatar,
|
|
12
|
-
colorIndex: c.id,
|
|
13
|
-
src: u[c.id],
|
|
14
|
-
text: d
|
|
15
|
-
});
|
|
16
|
-
return c.isExternalUser ? /* @__PURE__ */ s(o, {
|
|
17
|
-
offset: {
|
|
18
|
-
right: -4,
|
|
19
|
-
bottom: -2
|
|
20
|
-
},
|
|
21
|
-
size: "medium",
|
|
22
|
-
variant: "collaborator-external",
|
|
23
|
-
children: f
|
|
24
|
-
}) : f;
|
|
25
|
-
};
|
|
26
|
-
export { c as UserAvatar };
|
|
1
|
+
import messages from"../../messages.js";import{getInitials}from"../../utils/getInitials.js";import{useUserSelector}from"../user-selector-context.js";import{t as user_selector_headless_module_default}from"../../../../chunks/user-selector-headless.module.js";import{useIntl}from"react-intl";import{Avatar,IconBadge}from"@box/blueprint-web";import{jsx}from"react/jsx-runtime";var UserAvatar=({userContact})=>{let intl=useIntl(),{avatars}=useUserSelector(),initials=getInitials(userContact.name),avatar=jsx(Avatar,{alt:intl.formatMessage(messages.userAvatar),className:user_selector_headless_module_default.listItemAvatar,colorIndex:userContact.id,src:avatars[userContact.id],text:initials});return userContact.isExternalUser?jsx(IconBadge,{offset:{right:-4,bottom:-2},size:`medium`,variant:`collaborator-external`,children:avatar}):avatar};export{UserAvatar};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useUserSelector as t } from "../user-selector-context.js";
|
|
3
|
-
import { t as n } from "../../../../chunks/user-selector-headless.module.js";
|
|
4
|
-
import { UserAvatar as r } from "./user-avatar.js";
|
|
5
|
-
import { UserSelectorDefaultEmpty as i } from "./user-selector-default-empty.js";
|
|
6
|
-
import { UserSelectorDefaultError as a } from "./user-selector-default-error.js";
|
|
7
|
-
import { UserSelectorSkeleton as o } from "./user-selector-skeleton.js";
|
|
8
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
9
|
-
var c = ({ renderError: c, renderEmpty: l, loadingAriaLabel: u, optionRefs: d, handleOptionClick: f, options: p, isEmpty: m, isLoading: h, error: g, handleInvite: _ }) => {
|
|
10
|
-
let { value: v, activeId: y, getOptionId: b } = t();
|
|
11
|
-
return g ? c ? c(g) : /* @__PURE__ */ s(a, {}) : m ? l ? l(v) : /* @__PURE__ */ s(i, { handleInvite: _ }) : h ? /* @__PURE__ */ s(o, { loadingAriaLabel: u }) : p.map((t) => {
|
|
12
|
-
let i = b(t);
|
|
13
|
-
return /* @__PURE__ */ s(e, {
|
|
14
|
-
ref: (e) => {
|
|
15
|
-
e ? d.current.set(i, e) : d.current.delete(i);
|
|
16
|
-
},
|
|
17
|
-
className: n.userSelectorListItem,
|
|
18
|
-
id: i,
|
|
19
|
-
isCollaborator: t.isCollaborator,
|
|
20
|
-
onClick: f,
|
|
21
|
-
renderAvatar: () => /* @__PURE__ */ s(r, { userContact: t }),
|
|
22
|
-
role: "option",
|
|
23
|
-
selected: i === y,
|
|
24
|
-
userContact: t
|
|
25
|
-
}, t.id);
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
export { c as UserSelectorContent };
|
|
1
|
+
import{n as UserSelectorListItem}from"../../../../chunks/user-selector-list-item.js";import{useUserSelector}from"../user-selector-context.js";import{t as user_selector_headless_module_default}from"../../../../chunks/user-selector-headless.module.js";import{UserAvatar}from"./user-avatar.js";import{UserSelectorDefaultEmpty}from"./user-selector-default-empty.js";import{UserSelectorDefaultError}from"./user-selector-default-error.js";import{UserSelectorSkeleton}from"./user-selector-skeleton.js";import{jsx}from"react/jsx-runtime";var UserSelectorContent=({renderError,renderEmpty,loadingAriaLabel,optionRefs,handleOptionClick,options,isEmpty,isLoading,error,handleInvite})=>{let{value,activeId,getOptionId}=useUserSelector();return error?renderError?renderError(error):jsx(UserSelectorDefaultError,{}):isEmpty?renderEmpty?renderEmpty(value):jsx(UserSelectorDefaultEmpty,{handleInvite}):isLoading?jsx(UserSelectorSkeleton,{loadingAriaLabel}):options.map(option=>{let id=getOptionId(option);return jsx(UserSelectorListItem,{ref:el=>{el?optionRefs.current.set(id,el):optionRefs.current.delete(id)},className:user_selector_headless_module_default.userSelectorListItem,id,isCollaborator:option.isCollaborator,onClick:handleOptionClick,renderAvatar:()=>jsx(UserAvatar,{userContact:option}),role:`option`,selected:id===activeId,userContact:option},option.id)})};export{UserSelectorContent};
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useUserSelector as t } from "../user-selector-context.js";
|
|
3
|
-
import { t as n } from "../../../../chunks/user-selector-headless.module.js";
|
|
4
|
-
import { useCallback as r } from "react";
|
|
5
|
-
import { useIntl as i } from "react-intl";
|
|
6
|
-
import { Text as a } from "@box/blueprint-web";
|
|
7
|
-
import { AvatarPlusBadge as o } from "@box/blueprint-web-assets/icons/Line";
|
|
8
|
-
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
9
|
-
var l = ({ handleInvite: l }) => {
|
|
10
|
-
let { formatMessage: u } = i(), { value: d } = t(), f = r(() => {
|
|
11
|
-
l?.(d);
|
|
12
|
-
}, [l, d]);
|
|
13
|
-
return /* @__PURE__ */ c("div", {
|
|
14
|
-
className: n.userSelectorEmptyContainer,
|
|
15
|
-
children: [/* @__PURE__ */ s(a, {
|
|
16
|
-
as: "span",
|
|
17
|
-
className: n.userSelectorEmptyText,
|
|
18
|
-
color: "textOnLightSecondary",
|
|
19
|
-
variant: "label",
|
|
20
|
-
children: u(e.emptyMessage)
|
|
21
|
-
}), l && /* @__PURE__ */ c("button", {
|
|
22
|
-
className: n.userSelectorInviteRow,
|
|
23
|
-
onClick: f,
|
|
24
|
-
tabIndex: 0,
|
|
25
|
-
type: "button",
|
|
26
|
-
children: [/* @__PURE__ */ s("span", {
|
|
27
|
-
className: n.userSelectorInviteButtonIcon,
|
|
28
|
-
children: /* @__PURE__ */ s(o, {})
|
|
29
|
-
}), /* @__PURE__ */ s(a, {
|
|
30
|
-
as: "span",
|
|
31
|
-
className: n.userName,
|
|
32
|
-
variant: "bodyDefault",
|
|
33
|
-
children: u(e.inviteCollaborators)
|
|
34
|
-
})]
|
|
35
|
-
})]
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
export { l as UserSelectorDefaultEmpty };
|
|
1
|
+
import messages from"../../messages.js";import{useUserSelector}from"../user-selector-context.js";import{t as user_selector_headless_module_default}from"../../../../chunks/user-selector-headless.module.js";import{useCallback}from"react";import{useIntl}from"react-intl";import{Text}from"@box/blueprint-web";import{AvatarPlusBadge}from"@box/blueprint-web-assets/icons/Line";import{jsx,jsxs}from"react/jsx-runtime";var UserSelectorDefaultEmpty=({handleInvite})=>{let{formatMessage}=useIntl(),{value}=useUserSelector(),handleOnInviteClick=useCallback(()=>{handleInvite?.(value)},[handleInvite,value]);return jsxs(`div`,{className:user_selector_headless_module_default.userSelectorEmptyContainer,children:[jsx(Text,{as:`span`,className:user_selector_headless_module_default.userSelectorEmptyText,color:`textOnLightSecondary`,variant:`label`,children:formatMessage(messages.emptyMessage)}),handleInvite&&jsxs(`button`,{className:user_selector_headless_module_default.userSelectorInviteRow,onClick:handleOnInviteClick,tabIndex:0,type:`button`,children:[jsx(`span`,{className:user_selector_headless_module_default.userSelectorInviteButtonIcon,children:jsx(AvatarPlusBadge,{})}),jsx(Text,{as:`span`,className:user_selector_headless_module_default.userName,variant:`bodyDefault`,children:formatMessage(messages.inviteCollaborators)})]})]})};export{UserSelectorDefaultEmpty};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FormattedMessage as t, useIntl as n } from "react-intl";
|
|
3
|
-
import { InlineNotice as r } from "@box/blueprint-web";
|
|
4
|
-
import { jsx as i } from "react/jsx-runtime";
|
|
5
|
-
var a = () => {
|
|
6
|
-
let { formatMessage: a } = n();
|
|
7
|
-
return /* @__PURE__ */ i(r, {
|
|
8
|
-
title: a(e.errorMessage),
|
|
9
|
-
variant: "error",
|
|
10
|
-
variantIconAriaLabel: "error",
|
|
11
|
-
children: /* @__PURE__ */ i(t, { ...e.errorMessageDescription })
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
export { a as UserSelectorDefaultError };
|
|
1
|
+
import messages from"../../messages.js";import{FormattedMessage,useIntl}from"react-intl";import{InlineNotice}from"@box/blueprint-web";import{jsx}from"react/jsx-runtime";var UserSelectorDefaultError=()=>{let{formatMessage}=useIntl();return jsx(InlineNotice,{title:formatMessage(messages.errorMessage),variant:`error`,variantIconAriaLabel:`error`,children:jsx(FormattedMessage,{...messages.errorMessageDescription})})};export{UserSelectorDefaultError};
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Ghost as t } from "@box/blueprint-web";
|
|
3
|
-
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
-
import { Size5 as i, Size8 as a } from "@box/blueprint-web-assets/tokens/tokens";
|
|
5
|
-
var o = ({ loadingAriaLabel: o }) => /* @__PURE__ */ n("div", {
|
|
6
|
-
"aria-label": o,
|
|
7
|
-
children: Array.from({ length: 4 }, (o, s) => /* @__PURE__ */ r("div", {
|
|
8
|
-
className: e.userSelectorGhostStateItem,
|
|
9
|
-
children: [/* @__PURE__ */ n(t, {
|
|
10
|
-
className: e.titleGhost,
|
|
11
|
-
height: a,
|
|
12
|
-
variant: "rectangle",
|
|
13
|
-
width: a
|
|
14
|
-
}), /* @__PURE__ */ n(t, {
|
|
15
|
-
height: i,
|
|
16
|
-
variant: "rectangle",
|
|
17
|
-
width: "100%"
|
|
18
|
-
})]
|
|
19
|
-
}, s))
|
|
20
|
-
});
|
|
21
|
-
export { o as UserSelectorSkeleton };
|
|
1
|
+
import{t as user_selector_headless_module_default}from"../../../../chunks/user-selector-headless.module.js";import{Ghost}from"@box/blueprint-web";import{jsx,jsxs}from"react/jsx-runtime";import{Size5,Size8}from"@box/blueprint-web-assets/tokens/tokens";var UserSelectorSkeleton=({loadingAriaLabel})=>jsx(`div`,{"aria-label":loadingAriaLabel,children:Array.from({length:4},(_,i)=>jsxs(`div`,{className:user_selector_headless_module_default.userSelectorGhostStateItem,children:[jsx(Ghost,{className:user_selector_headless_module_default.titleGhost,height:Size8,variant:`rectangle`,width:Size8}),jsx(Ghost,{height:Size5,variant:`rectangle`,width:`100%`})]},i))});export{UserSelectorSkeleton};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var r = ({ fetchAvatarUrls: r, options: i }) => {
|
|
3
|
-
let [a, o] = n({}), s = e(async (e) => {
|
|
4
|
-
try {
|
|
5
|
-
o(await r(e));
|
|
6
|
-
} catch {
|
|
7
|
-
o({});
|
|
8
|
-
}
|
|
9
|
-
}, [r, o]);
|
|
10
|
-
return t(() => {
|
|
11
|
-
i.length > 0 && s(i);
|
|
12
|
-
}, [i, s]), { avatars: a };
|
|
13
|
-
};
|
|
14
|
-
export { r as useAvatars };
|
|
1
|
+
import{useCallback,useEffect,useState}from"react";var useAvatars=({fetchAvatarUrls,options})=>{let[avatars,setAvatars]=useState({}),getAvatarUrls=useCallback(async users=>{try{setAvatars(await fetchAvatarUrls(users))}catch{setAvatars({})}},[fetchAvatarUrls,setAvatars]);return useEffect(()=>{options.length>0&&getAvatarUrls(options)},[options,getAvatarUrls]),{avatars}};export{useAvatars};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var t = ({ isLoading: t, error: n, isEmpty: r, open: i, selectNext: a, selectPrevious: o, selectItem: s }) => e((e) => {
|
|
3
|
-
if (!(!i || t || n || r)) switch (e.key) {
|
|
4
|
-
case "ArrowDown":
|
|
5
|
-
e.preventDefault(), a();
|
|
6
|
-
break;
|
|
7
|
-
case "ArrowUp":
|
|
8
|
-
e.preventDefault(), o();
|
|
9
|
-
break;
|
|
10
|
-
case "Enter":
|
|
11
|
-
case " ":
|
|
12
|
-
e.preventDefault(), s();
|
|
13
|
-
break;
|
|
14
|
-
default: break;
|
|
15
|
-
}
|
|
16
|
-
}, [
|
|
17
|
-
n,
|
|
18
|
-
r,
|
|
19
|
-
t,
|
|
20
|
-
i,
|
|
21
|
-
a,
|
|
22
|
-
o,
|
|
23
|
-
s
|
|
24
|
-
]);
|
|
25
|
-
export { t as useKeyboardNavigation };
|
|
1
|
+
import{useCallback}from"react";var useKeyboardNavigation=({isLoading,error,isEmpty,open,selectNext,selectPrevious,selectItem})=>useCallback(event=>{if(!(!open||isLoading||error||isEmpty))switch(event.key){case`ArrowDown`:event.preventDefault(),selectNext();break;case`ArrowUp`:event.preventDefault(),selectPrevious();break;case`Enter`:case` `:event.preventDefault(),selectItem();break;default:break}},[error,isEmpty,isLoading,open,selectNext,selectPrevious,selectItem]);export{useKeyboardNavigation};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import i from "lodash/debounce";
|
|
3
|
-
var a = ({ fetcher: a, value: o, debounceTime: s = 250, allowEmptyQuery: c = !1 }) => {
|
|
4
|
-
let [l, u] = r(!1), [d, f] = r(!1), [p, m] = r(null), [h, g] = r([]), _ = e(async (e) => {
|
|
5
|
-
try {
|
|
6
|
-
let t = await a(e);
|
|
7
|
-
f(t?.length === 0), g(t);
|
|
8
|
-
} catch (e) {
|
|
9
|
-
m(e);
|
|
10
|
-
} finally {
|
|
11
|
-
u(!1);
|
|
12
|
-
}
|
|
13
|
-
}, [a]), v = n(() => i(_, s), [_, s]);
|
|
14
|
-
return t(() => (o.length || c ? (u(!0), m(null), f(!1), v(o)) : (v.cancel(), u(!1), g([]), m(null), f(!1)), () => v.cancel()), [
|
|
15
|
-
o,
|
|
16
|
-
v,
|
|
17
|
-
c
|
|
18
|
-
]), {
|
|
19
|
-
isLoading: l,
|
|
20
|
-
isEmpty: d,
|
|
21
|
-
error: p,
|
|
22
|
-
options: h
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export { a as useSelectOptions };
|
|
1
|
+
import{useCallback,useEffect,useMemo,useState}from"react";import _debounce from"lodash/debounce";var useSelectOptions=({fetcher,value,debounceTime=250,allowEmptyQuery=!1})=>{let[isLoading,setIsLoading]=useState(!1),[isEmpty,setIsEmpty]=useState(!1),[error,setError]=useState(null),[options,setOptions]=useState([]),fetchOptions=useCallback(async queryVal=>{try{let data=await fetcher(queryVal);setIsEmpty(data?.length===0),setOptions(data)}catch(err){setError(err)}finally{setIsLoading(!1)}},[fetcher]),debouncedFetchOptions=useMemo(()=>_debounce(fetchOptions,debounceTime),[fetchOptions,debounceTime]);return useEffect(()=>(value.length||allowEmptyQuery?(setIsLoading(!0),setError(null),setIsEmpty(!1),debouncedFetchOptions(value)):(debouncedFetchOptions.cancel(),setIsLoading(!1),setOptions([]),setError(null),setIsEmpty(!1)),()=>debouncedFetchOptions.cancel()),[value,debouncedFetchOptions,allowEmptyQuery]),{isLoading,isEmpty,error,options}};export{useSelectOptions};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var n = /*#__PURE__*/ e(null), r = () => {
|
|
3
|
-
let e = t(n);
|
|
4
|
-
if (!e) throw Error("useUserSelector must be used within a UserSelectorProvider");
|
|
5
|
-
return e;
|
|
6
|
-
};
|
|
7
|
-
export { n as UserSelectorContext, r as useUserSelector };
|
|
1
|
+
import{createContext,useContext}from"react";var UserSelectorContext=createContext(null),useUserSelector=()=>{let context=useContext(UserSelectorContext);if(!context)throw Error(`useUserSelector must be used within a UserSelectorProvider`);return context};export{UserSelectorContext,useUserSelector};
|
|
@@ -1,172 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t } from "../../../chunks/user-selector-headless.module.js";
|
|
3
|
-
import { UserSelectorContent as n } from "./components/user-selector-content.js";
|
|
4
|
-
import { useAvatars as r } from "./hooks/use-avatars.js";
|
|
5
|
-
import { useKeyboardNavigation as i } from "./hooks/use-keyboard-navigation.js";
|
|
6
|
-
import { useSelectOptions as a } from "./hooks/use-select-options.js";
|
|
7
|
-
import { forwardRef as o, useCallback as s, useEffect as c, useId as l, useImperativeHandle as u, useMemo as d, useRef as f, useState as p } from "react";
|
|
8
|
-
import m from "clsx";
|
|
9
|
-
import { Popover as h } from "@box/blueprint-web";
|
|
10
|
-
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
11
|
-
var v = /*#__PURE__*/ o(({ fetchUsers: o, fetchAvatarUrls: v, open: y, value: b, rootElement: x, onSelectedUserChange: S, inputElementRef: C, focusOnOpen: w = !1, renderError: T, renderEmpty: E, loadingAriaLabel: D, ariaRoleDescription: O, nativeFocusEnabled: k = !0, allowEmptyQuery: A = !1, onInvite: j, popoverContentContainerProps: M }, N) => {
|
|
12
|
-
let [P, F] = p(null), { options: I, isEmpty: L, isLoading: R, error: z } = a({
|
|
13
|
-
fetcher: o,
|
|
14
|
-
value: b,
|
|
15
|
-
allowEmptyQuery: A
|
|
16
|
-
}), { avatars: B } = r({
|
|
17
|
-
fetchAvatarUrls: v,
|
|
18
|
-
options: I
|
|
19
|
-
}), V = l(), H = f(/* @__PURE__ */ new Map()), U = d(() => `listbox-${V}`, [V]), W = s((e) => `${V}-option-${e.id}`, [V]), G = s((e) => {
|
|
20
|
-
let t = H.current.get(e);
|
|
21
|
-
if (t) {
|
|
22
|
-
if (F(e), k) {
|
|
23
|
-
t.focus();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
t.scrollIntoView({
|
|
27
|
-
behavior: "smooth",
|
|
28
|
-
block: "nearest",
|
|
29
|
-
inline: "nearest"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}, [k]), K = d(() => I.findIndex((e) => W(e) === P), [
|
|
33
|
-
P,
|
|
34
|
-
W,
|
|
35
|
-
I
|
|
36
|
-
]), q = s(() => {
|
|
37
|
-
C.current?.focus(), F(null);
|
|
38
|
-
}, [C]), J = s(() => {
|
|
39
|
-
if (P) {
|
|
40
|
-
let e = I.find((e) => W(e) === P);
|
|
41
|
-
e && S(e);
|
|
42
|
-
}
|
|
43
|
-
}, [
|
|
44
|
-
S,
|
|
45
|
-
P,
|
|
46
|
-
W,
|
|
47
|
-
I
|
|
48
|
-
]), Y = s(() => {
|
|
49
|
-
if (I.length !== 0) {
|
|
50
|
-
if (K < I.length - 1) {
|
|
51
|
-
G(W(I[K + 1]));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (k) {
|
|
55
|
-
q();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
G(W(I[0]));
|
|
59
|
-
}
|
|
60
|
-
}, [
|
|
61
|
-
K,
|
|
62
|
-
G,
|
|
63
|
-
W,
|
|
64
|
-
I,
|
|
65
|
-
k,
|
|
66
|
-
q
|
|
67
|
-
]), X = s(() => {
|
|
68
|
-
if (I.length !== 0) {
|
|
69
|
-
if (K > 0) {
|
|
70
|
-
G(W(I[K - 1]));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (k) {
|
|
74
|
-
q();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
G(W(I[I.length - 1]));
|
|
78
|
-
}
|
|
79
|
-
}, [
|
|
80
|
-
K,
|
|
81
|
-
G,
|
|
82
|
-
W,
|
|
83
|
-
I,
|
|
84
|
-
k,
|
|
85
|
-
q
|
|
86
|
-
]), Z = i({
|
|
87
|
-
isLoading: R,
|
|
88
|
-
error: z,
|
|
89
|
-
isEmpty: L,
|
|
90
|
-
open: y,
|
|
91
|
-
selectNext: Y,
|
|
92
|
-
selectPrevious: X,
|
|
93
|
-
selectItem: J
|
|
94
|
-
}), Q = s((e, t) => {
|
|
95
|
-
G(t), S(e);
|
|
96
|
-
}, [G, S]);
|
|
97
|
-
u(N, () => ({
|
|
98
|
-
focusFirstOption: () => {
|
|
99
|
-
I.length > 0 && G(W(I[0]));
|
|
100
|
-
},
|
|
101
|
-
focusLastOption: () => {
|
|
102
|
-
I.length > 0 && G(W(I[I.length - 1]));
|
|
103
|
-
},
|
|
104
|
-
selectNext: Y,
|
|
105
|
-
selectPrevious: X,
|
|
106
|
-
selectItem: J
|
|
107
|
-
}), [
|
|
108
|
-
G,
|
|
109
|
-
W,
|
|
110
|
-
I,
|
|
111
|
-
Y,
|
|
112
|
-
X,
|
|
113
|
-
J
|
|
114
|
-
]), c(() => {
|
|
115
|
-
I.length > 0 && w && G(W(I[0]));
|
|
116
|
-
}, [
|
|
117
|
-
I,
|
|
118
|
-
y,
|
|
119
|
-
W,
|
|
120
|
-
G,
|
|
121
|
-
w
|
|
122
|
-
]);
|
|
123
|
-
let $ = {
|
|
124
|
-
fetchUsers: o,
|
|
125
|
-
fetchAvatarUrls: v,
|
|
126
|
-
onSelectedUserChange: S,
|
|
127
|
-
value: b,
|
|
128
|
-
avatars: B,
|
|
129
|
-
activeId: P,
|
|
130
|
-
setActiveId: F,
|
|
131
|
-
listboxId: U,
|
|
132
|
-
getOptionId: W
|
|
133
|
-
};
|
|
134
|
-
return /* @__PURE__ */ g(e.Provider, {
|
|
135
|
-
value: $,
|
|
136
|
-
children: /* @__PURE__ */ _(h.Root, {
|
|
137
|
-
modal: !1,
|
|
138
|
-
open: y,
|
|
139
|
-
children: [/* @__PURE__ */ g(h.Anchor, { children: x }), /* @__PURE__ */ g(h.ContentContainer, {
|
|
140
|
-
...M,
|
|
141
|
-
align: "start",
|
|
142
|
-
className: m(t.popoverContainer, M?.className),
|
|
143
|
-
onOpenAutoFocus: (e) => {
|
|
144
|
-
e.preventDefault();
|
|
145
|
-
},
|
|
146
|
-
children: /* @__PURE__ */ g(h.MainContent, {
|
|
147
|
-
"aria-activedescendant": P,
|
|
148
|
-
"aria-owns": Array.from(H.current.values()).map((e) => e.id).join(" "),
|
|
149
|
-
"aria-roledescription": O,
|
|
150
|
-
className: t.popoverContent,
|
|
151
|
-
id: U,
|
|
152
|
-
onKeyDown: Z,
|
|
153
|
-
role: "listbox",
|
|
154
|
-
tabIndex: -1,
|
|
155
|
-
children: /* @__PURE__ */ g(n, {
|
|
156
|
-
error: z,
|
|
157
|
-
handleInvite: j,
|
|
158
|
-
handleOptionClick: Q,
|
|
159
|
-
isEmpty: L,
|
|
160
|
-
isLoading: R,
|
|
161
|
-
loadingAriaLabel: D,
|
|
162
|
-
optionRefs: H,
|
|
163
|
-
options: I,
|
|
164
|
-
renderEmpty: E,
|
|
165
|
-
renderError: T
|
|
166
|
-
})
|
|
167
|
-
})
|
|
168
|
-
})]
|
|
169
|
-
})
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
export { v as UserSelectorHeadless };
|
|
1
|
+
import{UserSelectorContext}from"./user-selector-context.js";import{t as user_selector_headless_module_default}from"../../../chunks/user-selector-headless.module.js";import{UserSelectorContent}from"./components/user-selector-content.js";import{useAvatars}from"./hooks/use-avatars.js";import{useKeyboardNavigation}from"./hooks/use-keyboard-navigation.js";import{useSelectOptions}from"./hooks/use-select-options.js";import{forwardRef,useCallback,useEffect,useId,useImperativeHandle,useMemo,useRef,useState}from"react";import clsx from"clsx";import{Popover}from"@box/blueprint-web";import{jsx,jsxs}from"react/jsx-runtime";var UserSelectorHeadless=forwardRef(({fetchUsers,fetchAvatarUrls,open,value,rootElement,onSelectedUserChange,inputElementRef,focusOnOpen=!1,renderError,renderEmpty,loadingAriaLabel,ariaRoleDescription,nativeFocusEnabled=!0,allowEmptyQuery=!1,onInvite,popoverContentContainerProps},ref)=>{let[activeId,setActiveId]=useState(null),{options,isEmpty,isLoading,error}=useSelectOptions({fetcher:fetchUsers,value,allowEmptyQuery}),{avatars}=useAvatars({fetchAvatarUrls,options}),uniqueId=useId(),optionRefs=useRef(new Map),listboxId=useMemo(()=>`listbox-${uniqueId}`,[uniqueId]),getOptionId=useCallback(optionValue=>`${uniqueId}-option-${optionValue.id}`,[uniqueId]),focusOption=useCallback(id=>{let element=optionRefs.current.get(id);if(element){if(setActiveId(id),nativeFocusEnabled){element.focus();return}element.scrollIntoView({behavior:`smooth`,block:`nearest`,inline:`nearest`})}},[nativeFocusEnabled]),currentIndex=useMemo(()=>options.findIndex(opt=>getOptionId(opt)===activeId),[activeId,getOptionId,options]),switchFocusToInput=useCallback(()=>{inputElementRef.current?.focus(),setActiveId(null)},[inputElementRef]),selectItem=useCallback(()=>{if(activeId){let selectedOption=options.find(opt=>getOptionId(opt)===activeId);selectedOption&&onSelectedUserChange(selectedOption)}},[onSelectedUserChange,activeId,getOptionId,options]),selectNext=useCallback(()=>{if(options.length!==0){if(currentIndex<options.length-1){focusOption(getOptionId(options[currentIndex+1]));return}if(nativeFocusEnabled){switchFocusToInput();return}focusOption(getOptionId(options[0]))}},[currentIndex,focusOption,getOptionId,options,nativeFocusEnabled,switchFocusToInput]),selectPrevious=useCallback(()=>{if(options.length!==0){if(currentIndex>0){focusOption(getOptionId(options[currentIndex-1]));return}if(nativeFocusEnabled){switchFocusToInput();return}focusOption(getOptionId(options[options.length-1]))}},[currentIndex,focusOption,getOptionId,options,nativeFocusEnabled,switchFocusToInput]),handleKeyDown=useKeyboardNavigation({isLoading,error,isEmpty,open,selectNext,selectPrevious,selectItem}),handleOptionClick=useCallback((userContact,id)=>{focusOption(id),onSelectedUserChange(userContact)},[focusOption,onSelectedUserChange]);useImperativeHandle(ref,()=>({focusFirstOption:()=>{options.length>0&&focusOption(getOptionId(options[0]))},focusLastOption:()=>{options.length>0&&focusOption(getOptionId(options[options.length-1]))},selectNext,selectPrevious,selectItem}),[focusOption,getOptionId,options,selectNext,selectPrevious,selectItem]),useEffect(()=>{options.length>0&&focusOnOpen&&focusOption(getOptionId(options[0]))},[options,open,getOptionId,focusOption,focusOnOpen]);let contextValue={fetchUsers,fetchAvatarUrls,onSelectedUserChange,value,avatars,activeId,setActiveId,listboxId,getOptionId};return jsx(UserSelectorContext.Provider,{value:contextValue,children:jsxs(Popover.Root,{modal:!1,open,children:[jsx(Popover.Anchor,{children:rootElement}),jsx(Popover.ContentContainer,{...popoverContentContainerProps,align:`start`,className:clsx(user_selector_headless_module_default.popoverContainer,popoverContentContainerProps?.className),onOpenAutoFocus:e=>{e.preventDefault()},children:jsx(Popover.MainContent,{"aria-activedescendant":activeId,"aria-owns":Array.from(optionRefs.current.values()).map(e=>e.id).join(` `),"aria-roledescription":ariaRoleDescription,className:user_selector_headless_module_default.popoverContent,id:listboxId,onKeyDown:handleKeyDown,role:`listbox`,tabIndex:-1,children:jsx(UserSelectorContent,{error,handleInvite:onInvite,handleOptionClick,isEmpty,isLoading,loadingAriaLabel,optionRefs,options,renderEmpty,renderError})})})]})})});export{UserSelectorHeadless};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { n as UserSelectorComboboxOption, e as UserSelectorListItem, t as UserSelectorListItemInfo };
|
|
1
|
+
import{n as UserSelectorListItem,r as UserSelectorListItemInfo,t as UserSelectorComboboxOption}from"../../chunks/user-selector-list-item.js";export{UserSelectorComboboxOption,UserSelectorListItem,UserSelectorListItemInfo};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { e as default };
|
|
1
|
+
import{t as UserSelector}from"../../chunks/user-selector.js";export{UserSelector as default};
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Text as t } from "@box/blueprint-web";
|
|
3
|
-
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
-
var i = ({ defaultProps: i, DefaultComponentTemplate: a, variantsMap: o, containerStyle: s }) => {
|
|
5
|
-
let c = Object.entries(o);
|
|
6
|
-
return /* @__PURE__ */ n("div", {
|
|
7
|
-
style: {
|
|
8
|
-
display: "grid",
|
|
9
|
-
gridTemplateColumns: "auto auto",
|
|
10
|
-
alignItems: "baseline",
|
|
11
|
-
gap: "254px 12px",
|
|
12
|
-
...s
|
|
13
|
-
},
|
|
14
|
-
children: c.map(([o, { props: s = {}, ComponentTemplate: c }]) => /* @__PURE__ */ r(e, { children: [/* @__PURE__ */ n(t, {
|
|
15
|
-
as: "span",
|
|
16
|
-
color: "textOnLightSecondary",
|
|
17
|
-
style: { textTransform: "uppercase" },
|
|
18
|
-
variant: "bodyDefaultBold",
|
|
19
|
-
children: o
|
|
20
|
-
}), /* @__PURE__ */ n("div", { children: n(c || a, {
|
|
21
|
-
...i,
|
|
22
|
-
...s
|
|
23
|
-
}) })] }, o))
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
i.displayName = "variants";
|
|
27
|
-
export { i as VariantsAggregator };
|
|
1
|
+
import{Fragment}from"react";import{Text}from"@box/blueprint-web";import{jsx,jsxs}from"react/jsx-runtime";var VariantsAggregator=({defaultProps,DefaultComponentTemplate,variantsMap,containerStyle})=>{let variantsArray=Object.entries(variantsMap);return jsx(`div`,{style:{display:`grid`,gridTemplateColumns:`auto auto`,alignItems:`baseline`,gap:`254px 12px`,...containerStyle},children:variantsArray.map(([variant,{props={},ComponentTemplate}])=>jsxs(Fragment,{children:[jsx(Text,{as:`span`,color:`textOnLightSecondary`,style:{textTransform:`uppercase`},variant:`bodyDefaultBold`,children:variant}),jsx(`div`,{children:jsx(ComponentTemplate||DefaultComponentTemplate,{...defaultProps,...props})})]},variant))})};VariantsAggregator.displayName=`variants`;export{VariantsAggregator};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { e as buildOptionsWithOverlay };
|
|
1
|
+
import{t as buildOptionsWithOverlay}from"../../../chunks/buildOptionsWithOverlay.js";export{buildOptionsWithOverlay};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "react";
|
|
3
|
-
import { jsx as t } from "react/jsx-runtime";
|
|
4
|
-
function n(n, r) {
|
|
5
|
-
return /* @__PURE__ */ t(e, {
|
|
6
|
-
renderAvatar: r,
|
|
7
|
-
subtitle: n.subtitle,
|
|
8
|
-
title: n.name
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export { n as defaultRenderCustomOption };
|
|
1
|
+
import{r as UserSelectorListItemInfo}from"../../../chunks/user-selector-list-item.js";import"react";import{jsx}from"react/jsx-runtime";function defaultRenderCustomOption(option,renderAvatar){return jsx(UserSelectorListItemInfo,{renderAvatar,subtitle:option.subtitle,title:option.name})}export{defaultRenderCustomOption};
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
let t = e.replace(/[[({<]+.*[\])}>]+/g, "").trim();
|
|
3
|
-
return (t.slice(0, 1) + t.slice(t.lastIndexOf(" ") + 1, t.lastIndexOf(" ") + 2)).toUpperCase();
|
|
4
|
-
};
|
|
5
|
-
export { e as getInitials };
|
|
1
|
+
var getInitials=name=>{let cleanedName=name.replace(/[[({<]+.*[\])}>]+/g,``).trim();return(cleanedName.slice(0,1)+cleanedName.slice(cleanedName.lastIndexOf(` `)+1,cleanedName.lastIndexOf(` `)+2)).toUpperCase()};export{getInitials};
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/user-selector",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.38",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@box/blueprint-web": "^16.
|
|
6
|
-
"@box/blueprint-web-assets": "^5.5.
|
|
7
|
-
"@box/combobox-with-api": "^2.1.
|
|
5
|
+
"@box/blueprint-web": "^16.13.1",
|
|
6
|
+
"@box/blueprint-web-assets": "^5.5.10",
|
|
7
|
+
"@box/combobox-with-api": "^2.1.37",
|
|
8
8
|
"lodash": "^4.17.15",
|
|
9
9
|
"react": "^17.0.0 || ^18.0.0",
|
|
10
10
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
11
11
|
"react-intl": "^6.4.2"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@box/blueprint-web": "^16.
|
|
15
|
-
"@box/blueprint-web-assets": "^5.5.
|
|
16
|
-
"@box/combobox-with-api": "^2.1.
|
|
17
|
-
"@box/storybook-utils": "^1.1.
|
|
14
|
+
"@box/blueprint-web": "^16.13.1",
|
|
15
|
+
"@box/blueprint-web-assets": "^5.5.10",
|
|
16
|
+
"@box/combobox-with-api": "^2.1.37",
|
|
17
|
+
"@box/storybook-utils": "^1.1.34",
|
|
18
18
|
"@types/lodash": "^4.17.14",
|
|
19
19
|
"react": "^18.3.0",
|
|
20
20
|
"react-dom": "^18.3.0",
|