@box/unified-share-modal 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- import fe from "clsx";
2
- import { useState as he, useRef as pe, useEffect as R, useCallback as v } from "react";
1
+ import he from "clsx";
2
+ import { useState as pe, useRef as fe, useEffect as R, useCallback as C } from "react";
3
3
  import { createPortal as be } from "react-dom";
4
4
  import { useIntl as ge } from "react-intl";
5
- import { useBlueprintModernization as Ce, useNotification as ve, useUniqueId as Se, useLabelable as Ue, Tooltip as _e, Focusable as ye, Text as Fe, Modal as S } from "@box/blueprint-web";
6
- import { Globe as Le } from "@box/blueprint-web-assets/icons/Medium";
5
+ import { useBlueprintModernization as Ce, useNotification as ve, useUniqueId as Se, useLabelable as Ue, Tooltip as _e, Focusable as Fe, Text as Le, Modal as v } from "@box/blueprint-web";
6
+ import { Globe as xe } from "@box/blueprint-web-assets/icons/Medium";
7
7
  import { bpSize040 as P } from "@box/blueprint-web-assets/tokens/tokens";
8
- import { UserSelectorContainer as xe } from "@box/user-selector";
9
- import { CollaborationRole as Be } from "./collaboration-role.js";
10
- import { SharedWithAvatars as Ee } from "./shared-with-avatars.js";
8
+ import { UserSelectorContainer as ye } from "@box/user-selector";
9
+ import { CollaborationRole as Ee } from "./collaboration-role.js";
10
+ import { SharedWithAvatars as Be } from "./shared-with-avatars.js";
11
11
  import { ShieldRestrictionNotice as Ae } from "./shield-restriction-notice.js";
12
12
  import { TextAreaContainer as Ne } from "./text-area-container.js";
13
13
  import o from "./messages.js";
@@ -16,18 +16,19 @@ import { useFormValidation as Pe } from "../../../hooks/use-form-validation.js";
16
16
  import { useCollaborationForm as ke } from "../../../hooks/use-collaboration-form.js";
17
17
  import { useUnifiedShareFormContext as Ve } from "../../../contexts/unified-share-form-context.js";
18
18
  import { useUnifiedShareModalContext as Ie } from "../../../contexts/unified-share-modal-context.js";
19
- import '../../../../../styles/collaboration-section.css';const Te = "_container_1e2gg_2", De = "_label_1e2gg_8", Me = "_modernized_1e2gg_15", ze = "_security_1e2gg_33", Oe = "_icon_1e2gg_37", we = "_access_1e2gg_43", c = {
20
- container: Te,
21
- label: De,
22
- modernized: Me,
23
- security: ze,
24
- icon: Oe,
25
- access: we
19
+ import { parseEmails as Te } from "../../../utils/email.js";
20
+ import '../../../../../styles/collaboration-section.css';const De = "_container_1e2gg_2", Me = "_label_1e2gg_8", ze = "_modernized_1e2gg_15", Oe = "_security_1e2gg_33", we = "_icon_1e2gg_37", We = "_access_1e2gg_43", c = {
21
+ container: De,
22
+ label: Me,
23
+ modernized: ze,
24
+ security: Oe,
25
+ icon: we,
26
+ access: We
26
27
  };
27
- function at() {
28
+ function lt() {
28
29
  const {
29
30
  formatMessage: t
30
- } = ge(), [U, B] = he(), {
31
+ } = ge(), [S, y] = pe(), {
31
32
  enableModernizedComponents: k
32
33
  } = Ce(), {
33
34
  addNotification: V
@@ -35,7 +36,7 @@ function at() {
35
36
  validateShieldRestriction: I
36
37
  } = Pe(), {
37
38
  contactValue: T,
38
- containerRef: _,
39
+ containerRef: U,
39
40
  form: n,
40
41
  setForm: d,
41
42
  setUserContacts: D,
@@ -44,7 +45,7 @@ function at() {
44
45
  } = Ve(), {
45
46
  collaborationAccess: z,
46
47
  collaborationNotices: O,
47
- config: f,
48
+ config: h,
48
49
  contactService: w,
49
50
  isFetching: W,
50
51
  isSubmitting: m,
@@ -56,7 +57,7 @@ function at() {
56
57
  permissions: $ = {},
57
58
  type: H
58
59
  } = j, {
59
- getContacts: y,
60
+ getContacts: _,
60
61
  getContactsAvatarUrls: F
61
62
  } = w, {
62
63
  sendInvitations: J,
@@ -68,27 +69,27 @@ function at() {
68
69
  errors: X,
69
70
  handleFormReset: E,
70
71
  handleFormSubmit: Y,
71
- handleSelectedUsersChange: h,
72
+ handleSelectedUsersChange: p,
72
73
  handleUserSelectorBlur: Z,
73
74
  updateContactValue: ee
74
- } = ke(L, x), te = K === "desktop", u = n === "default" || n === "invite", a = n === "invite" || n === "email", oe = i.some((e) => e.isExternalUser), A = pe(n === "email" ? "email" : "invite");
75
+ } = ke(L, x), te = K === "desktop", u = n === "default" || n === "invite", a = n === "invite" || n === "email", oe = i.some((e) => e.isExternalUser), B = fe(n === "email" ? "email" : "invite");
75
76
  R(() => {
76
- A.current = n === "email" ? "email" : "invite";
77
+ B.current = n === "email" ? "email" : "invite";
77
78
  }, [n]), R(() => {
78
- (!i.length || !i.some((e) => e.chipVariant === "error")) && B(null);
79
+ (!i.length || !i.some((e) => e.chipVariant === "error")) && y(null);
79
80
  }, [i]);
80
- const re = v((e) => (e.stopPropagation(), !0), []), ie = v((e) => y ? y(e, A.current) : Promise.resolve([]), [y]), ne = v((e) => F ? F(e) : Promise.resolve({}), [F]), ae = (e) => {
81
+ const re = C((e) => (e.stopPropagation(), !0), []), ie = C((e) => _ ? _(e, B.current) : Promise.resolve([]), [_]), ne = C((e) => F ? F(e) : Promise.resolve({}), [F]), ae = (e) => {
81
82
  a || d("invite"), ee(e);
82
- }, se = v(async (e) => {
83
- const s = e.clipboardData.getData("text").trim();
84
- s && (i.some((g) => g.email === s) || (e.preventDefault(), a || d("invite"), await h([...i, {
83
+ }, se = C((e) => {
84
+ const s = e.clipboardData.getData("text");
85
+ Te(s).length !== 0 && (e.preventDefault(), a || d("invite"), p([...i, {
85
86
  value: s
86
- }])));
87
- }, [h, a, d, i]), le = () => {
87
+ }]));
88
+ }, [p, a, d, i]), le = () => {
88
89
  E(), d("default");
89
90
  }, ce = async () => {
90
91
  try {
91
- if (U) {
92
+ if (S) {
92
93
  const e = I(i, M);
93
94
  if (e) {
94
95
  V({
@@ -109,34 +110,34 @@ function at() {
109
110
  return;
110
111
  const {
111
112
  shieldRestriction: s
112
- } = e, g = [...s.restrictedEmails ?? [], ...s.restrictedGroups ?? []], ue = i.map((C) => g.includes(C.email) || g.includes(`${C.id}`) ? {
113
- ...C,
113
+ } = e, N = [...s.restrictedEmails ?? [], ...s.restrictedGroups ?? []], ue = i.map((g) => N.includes(g.email) || N.includes(`${g.id}`) ? {
114
+ ...g,
114
115
  chipVariant: "error"
115
- } : C);
116
- B(s), D(ue);
116
+ } : g);
117
+ y(s), D(ue);
117
118
  }
118
119
  };
119
- let p, b = !1;
120
- u && !$.canInviteCollaborator && (p = t(o.inviteDisabledTooltip), b = !0), u && H === "web_link" && (p = t(o.inviteWebLinkDisabledTooltip), b = !0);
121
- const N = Se("user-contacts-"), de = t(u ? o.invitePeopleLabel : o.emailSharedLinkLabel), me = Ue(de, N);
120
+ let f, b = !1;
121
+ u && !$.canInviteCollaborator && (f = t(o.inviteDisabledTooltip), b = !0), u && H === "web_link" && (f = t(o.inviteWebLinkDisabledTooltip), b = !0);
122
+ const A = Se("user-contacts-"), de = t(u ? o.invitePeopleLabel : o.emailSharedLinkLabel), me = Ue(de, A);
122
123
  return /* @__PURE__ */ l("form", {
123
124
  className: c.container,
124
125
  onSubmit: (e) => e.preventDefault(),
125
- children: [U && /* @__PURE__ */ r(Ae, {
126
- error: U,
126
+ children: [S && /* @__PURE__ */ r(Ae, {
127
+ error: S,
127
128
  isLoading: m,
128
- onSelectedUsersChange: h
129
+ onSelectedUsersChange: p
129
130
  }), O, /* @__PURE__ */ l("div", {
130
- children: [u && f.collaborators && /* @__PURE__ */ r(Ee, {}), /* @__PURE__ */ r(me, {
131
- className: fe(c.label, k && c.modernized)
131
+ children: [u && h.collaborators && /* @__PURE__ */ r(Be, {}), /* @__PURE__ */ r(me, {
132
+ className: he(c.label, k && c.modernized)
132
133
  }), /* @__PURE__ */ r(_e, {
133
- content: p,
134
+ content: f,
134
135
  "data-testid": "user-contacts-tooltip",
135
- open: p ? void 0 : !1,
136
+ open: f ? void 0 : !1,
136
137
  side: "bottom",
137
- children: /* @__PURE__ */ r(ye, {
138
+ children: /* @__PURE__ */ r(Fe, {
138
139
  focusable: b,
139
- children: /* @__PURE__ */ r(xe, {
140
+ children: /* @__PURE__ */ r(ye, {
140
141
  className: "collaboration-user-selector",
141
142
  clearButtonAriaLabel: t(o.clearButton),
142
143
  clearOnBlur: !1,
@@ -146,15 +147,15 @@ function at() {
146
147
  fetchAvatarUrls: ne,
147
148
  fetchUsers: ie,
148
149
  hideOnEscape: re,
149
- idForLabel: N,
150
+ idForLabel: A,
150
151
  inputValue: T,
151
152
  label: null,
152
153
  onBlur: Z,
153
154
  onInputValueChange: ae,
154
155
  onPaste: se,
155
- onSelectedUsersChange: h,
156
+ onSelectedUsersChange: p,
156
157
  placeholder: i.length ? "" : t(o.invitePeoplePlaceholder),
157
- portalElement: _,
158
+ portalElement: U,
158
159
  selectedUsers: i,
159
160
  selectOnEnterOrTab: !0,
160
161
  variant: a ? "textarea" : "input"
@@ -162,39 +163,39 @@ function at() {
162
163
  })
163
164
  }), u && /* @__PURE__ */ l("div", {
164
165
  className: c.access,
165
- children: [f.collaborationRole && /* @__PURE__ */ r(Be, {}), z]
166
+ children: [h.collaborationRole && /* @__PURE__ */ r(Ee, {}), z]
166
167
  })]
167
- }), a && f.collaborationMessage && /* @__PURE__ */ r(Ne, {
168
- maxCount: f.collaborationMessageLimit
168
+ }), a && h.collaborationMessage && /* @__PURE__ */ r(Ne, {
169
+ maxCount: h.collaborationMessageLimit
169
170
  }), a && oe && /* @__PURE__ */ l("div", {
170
171
  className: c.security,
171
- children: [/* @__PURE__ */ r(Le, {
172
+ children: [/* @__PURE__ */ r(xe, {
172
173
  className: c.icon,
173
174
  height: P,
174
175
  width: P
175
- }), /* @__PURE__ */ r(Fe, {
176
+ }), /* @__PURE__ */ r(Le, {
176
177
  as: "span",
177
178
  color: "textOnLightSecondary",
178
179
  children: t(o.contentSharedWithExternalCollaborators)
179
180
  })]
180
- }), a && _ && /* @__PURE__ */ be(/* @__PURE__ */ l(Re, {
181
- children: [!W && /* @__PURE__ */ l(S.Footer, {
182
- children: [/* @__PURE__ */ r(S.Footer.SecondaryButton, {
181
+ }), a && U && /* @__PURE__ */ be(/* @__PURE__ */ l(Re, {
182
+ children: [!W && /* @__PURE__ */ l(v.Footer, {
183
+ children: [/* @__PURE__ */ r(v.Footer.SecondaryButton, {
183
184
  disabled: m,
184
185
  onClick: le,
185
186
  children: t(o.cancelButton)
186
- }), /* @__PURE__ */ r(S.Footer.PrimaryButton, {
187
+ }), /* @__PURE__ */ r(v.Footer.PrimaryButton, {
187
188
  loading: m,
188
189
  loadingAriaLabel: t(o.loadingLabel),
189
190
  onClick: ce,
190
191
  children: t(o.sendButton)
191
192
  })]
192
- }), !m && !te && /* @__PURE__ */ r(S.Close, {
193
+ }), !m && !te && /* @__PURE__ */ r(v.Close, {
193
194
  "aria-label": t(o.closeButton)
194
195
  })]
195
- }), _)]
196
+ }), U)]
196
197
  });
197
198
  }
198
199
  export {
199
- at as CollaborationSection
200
+ lt as CollaborationSection
200
201
  };
@@ -1,52 +1,47 @@
1
- import { useState as C } from "react";
2
- import { useIntl as g } from "react-intl";
3
- import { useUniqueId as p, TextArea as b, Text as A } from "@box/blueprint-web";
1
+ import { useState as g } from "react";
2
+ import { useIntl as f } from "react-intl";
3
+ import { useUniqueId as C, TextArea as p, Text as b } from "@box/blueprint-web";
4
4
  import a from "./messages.js";
5
- import { jsxs as M, jsx as i } from "react/jsx-runtime";
6
- import { useUnifiedShareModalContext as _ } from "../../../contexts/unified-share-modal-context.js";
7
- import { useUnifiedShareFormContext as v } from "../../../contexts/unified-share-form-context.js";
8
- import '../../../../../styles/text-area-container.css';const S = "_textArea_v76md_1", y = "_textCount_v76md_5", u = {
9
- textArea: S,
10
- textCount: y
5
+ import { jsxs as A, jsx as r } from "react/jsx-runtime";
6
+ import { useUnifiedShareModalContext as M } from "../../../contexts/unified-share-modal-context.js";
7
+ import { useUnifiedShareFormContext as _ } from "../../../contexts/unified-share-form-context.js";
8
+ import '../../../../../styles/text-area-container.css';const v = "_textArea_v76md_1", S = "_textCount_v76md_5", i = {
9
+ textArea: v,
10
+ textCount: S
11
11
  };
12
- function q(c) {
12
+ function N(m) {
13
13
  const {
14
14
  formatMessage: t
15
- } = g(), {
15
+ } = f(), {
16
16
  isSubmitting: l
17
+ } = M(), {
18
+ messageValue: c,
19
+ setMessageValue: u
17
20
  } = _(), {
18
- messageValue: m,
19
- setMessageValue: x
20
- } = v(), {
21
21
  maxCount: e
22
- } = c, [o, d] = C(e), s = p("text-count-"), h = (f) => {
23
- const n = f.target.value;
24
- if (typeof e == "number") {
25
- const r = e - n.length;
26
- if (r < 0)
27
- return;
28
- d(r);
29
- }
30
- x(n);
22
+ } = m, [o, x] = g(e), s = C("text-count-"), d = (h) => {
23
+ const n = h.target.value;
24
+ typeof e == "number" && x(e - n.length), u(n);
31
25
  };
32
- return /* @__PURE__ */ M("div", {
33
- children: [/* @__PURE__ */ i(b, {
34
- className: u.textArea,
26
+ return /* @__PURE__ */ A("div", {
27
+ children: [/* @__PURE__ */ r(p, {
28
+ className: i.textArea,
35
29
  disabled: l,
36
30
  label: t(a.shareMessageLabel),
31
+ maxLength: e,
37
32
  minRows: 3,
38
- onChange: h,
33
+ onChange: d,
39
34
  placeholder: t(a.shareMessagePlaceholder),
40
- value: m,
35
+ value: c,
41
36
  ...e && {
42
37
  "aria-describedby": s
43
38
  }
44
- }), !!e && /* @__PURE__ */ i(A, {
39
+ }), !!e && /* @__PURE__ */ r(b, {
45
40
  "aria-label": t(a.shareMessageCharacterCountAriaLabel, {
46
41
  count: o
47
42
  }),
48
43
  as: "span",
49
- className: u.textCount,
44
+ className: i.textCount,
50
45
  color: "textOnLightSecondary",
51
46
  id: s,
52
47
  children: o
@@ -54,5 +49,5 @@ function q(c) {
54
49
  });
55
50
  }
56
51
  export {
57
- q as TextAreaContainer
52
+ N as TextAreaContainer
58
53
  };
@@ -1,96 +1,95 @@
1
- import { useCallback as c } from "react";
2
- import { useUnifiedShareFormContext as q } from "../contexts/unified-share-form-context.js";
3
- import { useUnifiedShareModalContext as M } from "../contexts/unified-share-modal-context.js";
4
- import { useFormValidation as O } from "./use-form-validation.js";
5
- import { useSharingAction as P } from "./use-sharing-action.js";
6
- import { parseEmails as k } from "../utils/email.js";
7
- const Q = (U, w) => {
1
+ import A from "lodash/differenceBy";
2
+ import O from "lodash/uniqBy";
3
+ import { useCallback as l } from "react";
4
+ import { useUnifiedShareFormContext as M } from "../contexts/unified-share-form-context.js";
5
+ import { useUnifiedShareModalContext as P } from "../contexts/unified-share-modal-context.js";
6
+ import { useFormValidation as T } from "./use-form-validation.js";
7
+ import { useSharingAction as D } from "./use-sharing-action.js";
8
+ import { parseEmails as J } from "../utils/email.js";
9
+ const Z = (F, U) => {
8
10
  const {
9
- errors: g,
10
- setFieldError: r,
11
- validateCollaborationLimit: l,
12
- validateUserContact: C,
11
+ errors: h,
12
+ setFieldError: a,
13
+ validateCollaborationLimit: c,
14
+ validateUserContact: g,
13
15
  validateUserSelector: u
14
- } = O(), {
15
- config: x,
16
- contactService: E
17
- } = M(), {
18
- collaborationLimit: s
19
- } = x, {
20
- collaborationRole: y,
21
- form: V,
22
- messageValue: R,
16
+ } = T(), {
17
+ config: y,
18
+ contactService: w
19
+ } = P(), {
20
+ collaborationLimit: i
21
+ } = y, {
22
+ collaborationRole: E,
23
+ form: x,
24
+ messageValue: L,
23
25
  setContactValue: m,
24
- setMessageValue: L,
25
- setUserContacts: d,
26
- shieldRestriction: f,
27
- userContacts: o
28
- } = q(), {
29
- onAction: A
30
- } = P(U, w), {
26
+ setMessageValue: R,
27
+ setUserContacts: f,
28
+ shieldRestriction: d,
29
+ userContacts: s
30
+ } = M(), {
31
+ onAction: V
32
+ } = D(F, U), {
31
33
  getContactsByEmail: p
32
- } = E, v = () => {
33
- d([]), m(""), L(""), r("user-contact", "");
34
- }, B = c((t) => {
35
- l(o, s) || r("user-contact", ""), m(t);
36
- }, [s, m, r, o, l]), S = c(async (t) => {
37
- const a = t.filter((e) => e.id === void 0).map((e) => e.value);
38
- let i = {};
39
- return p && a.length > 0 && (i = await p(a) ?? {}), t.map((e) => e.id !== void 0 ? e : i[e.value] || {
40
- email: e.value,
41
- id: 0,
42
- isExternalUser: !0,
43
- name: e.value,
44
- value: e.value
34
+ } = w, b = () => {
35
+ f([]), m(""), R(""), a("user-contact", "");
36
+ }, B = l((t) => {
37
+ c(s, i) || a("user-contact", ""), m(t);
38
+ }, [i, m, a, s, c]), S = l(async (t) => {
39
+ const n = {};
40
+ if (p && t.length > 0) {
41
+ const e = await p(t);
42
+ for (const o of Object.keys(e))
43
+ n[o.toLowerCase()] = e[o];
44
+ }
45
+ return t.map((e) => {
46
+ const o = n[e.toLowerCase()];
47
+ return o || {
48
+ email: e,
49
+ id: 0,
50
+ isExternalUser: !0,
51
+ name: e,
52
+ value: e
53
+ };
45
54
  });
46
- }, [p]), h = c(async (t) => {
47
- r("user-contact", ""), u(t);
48
- let a;
49
- if (t.length < o.length)
50
- a = t;
51
- else if (t[t.length - 1].id !== void 0)
52
- a = [...o, t[t.length - 1]];
55
+ }, [p]), C = l(async (t) => {
56
+ a("user-contact", ""), u(t);
57
+ let n;
58
+ if (t.length <= s.length || t[t.length - 1].id !== void 0)
59
+ n = t;
53
60
  else {
54
- const i = t[t.length - 1].value, e = k(i);
55
- if (e.length === 0) {
56
- C(i);
57
- return;
58
- }
59
- const b = new Set(o.filter((n) => !!n.email).map((n) => n.email.toLowerCase())), T = e.filter((n) => {
60
- const F = n.toLowerCase();
61
- return b.has(F) ? !1 : (b.add(F), !0);
62
- }), j = await S(T.map((n) => ({
63
- value: n
64
- })));
65
- a = [...o, ...j];
61
+ const e = t.slice(0, -1), o = t[t.length - 1].value, v = J(o);
62
+ v.length === 0 && g(o);
63
+ const j = e.filter((r) => r.email).map((r) => r.email), k = O(A(v, j, (r) => r.toLowerCase()), (r) => r.toLowerCase()), q = await S(k);
64
+ n = [...e, ...q];
66
65
  }
67
- s && l(a, s), d(a);
68
- }, [s, S, r, d, o, l, C, u]), I = c((t) => {
69
- const a = t.relatedTarget?.closest(".collaboration-user-selector");
70
- if (document.querySelector('div[role="listbox"][aria-labelledby^="user-contacts"]')?.contains(t.relatedTarget) || a)
66
+ i && c(n, i), f(n);
67
+ }, [i, S, a, f, s, c, g, u]), I = l((t) => {
68
+ const n = t.relatedTarget?.closest(".collaboration-user-selector");
69
+ if (document.querySelector('div[role="listbox"][aria-labelledby^="user-contacts"]')?.contains(t.relatedTarget) || n)
71
70
  return;
72
- const e = t.target.value.trim();
73
- e && h([...o, {
74
- value: e
71
+ const o = t.target.value.trim();
72
+ o && C([...s, {
73
+ value: o
75
74
  }]);
76
- }, [h, o]);
75
+ }, [C, s]);
77
76
  return {
78
- errors: g,
79
- handleFormReset: v,
77
+ errors: h,
78
+ handleFormReset: b,
80
79
  handleFormSubmit: async () => {
81
- if (g["user-contact"] || u(o))
80
+ if (h["user-contact"] || u(s))
82
81
  return !0;
83
82
  const t = {
84
- contacts: o,
85
- message: R
83
+ contacts: s,
84
+ message: L
86
85
  };
87
- return V === "invite" && (t.role = y.id), f.isJustificationAllowed && (t.justificationReason = f.justificationReason, t.classificationId = f.classificationId), await A(t), v(), !1;
86
+ return x === "invite" && (t.role = E.id), d.isJustificationAllowed && (t.justificationReason = d.justificationReason, t.classificationId = d.classificationId), await V(t), b(), !1;
88
87
  },
89
- handleSelectedUsersChange: h,
88
+ handleSelectedUsersChange: C,
90
89
  handleUserSelectorBlur: I,
91
90
  updateContactValue: B
92
91
  };
93
92
  };
94
93
  export {
95
- Q as useCollaborationForm
94
+ Z as useCollaborationForm
96
95
  };