@box/combobox-with-api 1.42.33 → 1.42.34

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 (28) hide show
  1. package/dist/chunks/combobox-with-api-error.js +18 -0
  2. package/dist/chunks/combobox-with-api-pagination.js +168 -0
  3. package/dist/chunks/combobox-with-api-pagination2.js +229 -0
  4. package/dist/chunks/combobox-with-api-tree-view.js +423 -0
  5. package/dist/chunks/dynamic-loading-tree.js +299 -326
  6. package/dist/chunks/treeReducer.js +60 -78
  7. package/dist/esm/index.js +6 -16
  8. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-container.js +47 -52
  9. package/dist/esm/lib/components/combobox-with-api/combobox-with-api-error.js +2 -26
  10. package/dist/esm/lib/components/combobox-with-api/combobox-with-api.js +16 -36
  11. package/dist/esm/lib/components/combobox-with-api/messages.js +6 -10
  12. package/dist/esm/lib/components/combobox-with-api-pagination/combobox-with-api-pagination.js +2 -214
  13. package/dist/esm/lib/components/combobox-with-api-pagination/index.js +3 -205
  14. package/dist/esm/lib/components/combobox-with-api-pagination/messages.js +31 -33
  15. package/dist/esm/lib/components/combobox-with-api-pagination/request.js +4 -6
  16. package/dist/esm/lib/components/combobox-with-api-pagination/use-async-list.js +113 -128
  17. package/dist/esm/lib/components/combobox-with-api-pagination/utils/is-abort-error.js +8 -10
  18. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-controllable-state.js +32 -34
  19. package/dist/esm/lib/components/combobox-with-api-pagination/utils/use-intersection-observer.js +72 -82
  20. package/dist/esm/lib/components/combobox-with-api-tree-view/combobox-with-api-tree-view.js +133 -174
  21. package/dist/esm/lib/components/combobox-with-api-tree-view/dynamic-loading-tree.js +2 -10
  22. package/dist/esm/lib/components/combobox-with-api-tree-view/index.js +3 -464
  23. package/dist/esm/lib/components/combobox-with-api-tree-view/tree-utils.js +17 -26
  24. package/dist/esm/lib/components/combobox-with-api-tree-view/treeReducer.js +2 -6
  25. package/dist/styles/combobox-with-api-error.css +1 -1
  26. package/dist/styles/combobox-with-api-pagination.css +1 -1
  27. package/dist/styles/dynamic-loading-tree.css +1 -1
  28. package/package.json +7 -7
@@ -1,85 +1,75 @@
1
- import { useState as y, useRef as R, useCallback as f } from "react";
2
- const k = "0px", g = [0];
3
- function C() {
4
- const b = /* @__PURE__ */ new Map();
5
- function a({
6
- root: s,
7
- rootMargin: t,
8
- threshold: c
9
- }) {
10
- let r = b.get(s);
11
- r || (r = /* @__PURE__ */ new Map(), b.set(s, r));
12
- const i = JSON.stringify({
13
- rootMargin: t,
14
- threshold: c
15
- });
16
- let n = r.get(i);
17
- if (!n) {
18
- const e = /* @__PURE__ */ new Map();
19
- n = {
20
- observer: new IntersectionObserver((O) => {
21
- O.forEach((v) => {
22
- e.get(v.target)?.(v);
23
- });
24
- }, {
25
- root: s,
26
- rootMargin: t,
27
- threshold: c
28
- }),
29
- entryCallbacks: e
30
- }, r.set(i, n);
31
- }
32
- return {
33
- observe: (e, l) => {
34
- n?.entryCallbacks.set(e, l), n?.observer.observe(e);
35
- },
36
- unobserve: (e) => {
37
- n?.entryCallbacks.delete(e), n?.observer.unobserve(e);
38
- }
39
- };
40
- }
41
- return {
42
- getObserver: a
43
- };
1
+ import { useCallback as e, useRef as t, useState as n } from "react";
2
+ var r = "0px", i = [0];
3
+ function a() {
4
+ let e = /* @__PURE__ */ new Map();
5
+ function t({ root: t, rootMargin: n, threshold: r }) {
6
+ let i = e.get(t);
7
+ i || (i = /* @__PURE__ */ new Map(), e.set(t, i));
8
+ let a = JSON.stringify({
9
+ rootMargin: n,
10
+ threshold: r
11
+ }), o = i.get(a);
12
+ if (!o) {
13
+ let e = /* @__PURE__ */ new Map();
14
+ o = {
15
+ observer: new IntersectionObserver((t) => {
16
+ t.forEach((t) => {
17
+ e.get(t.target)?.(t);
18
+ });
19
+ }, {
20
+ root: t,
21
+ rootMargin: n,
22
+ threshold: r
23
+ }),
24
+ entryCallbacks: e
25
+ }, i.set(a, o);
26
+ }
27
+ return {
28
+ observe: (e, t) => {
29
+ o?.entryCallbacks.set(e, t), o?.observer.observe(e);
30
+ },
31
+ unobserve: (e) => {
32
+ o?.entryCallbacks.delete(e), o?.observer.unobserve(e);
33
+ }
34
+ };
35
+ }
36
+ return { getObserver: t };
44
37
  }
45
- const E = C();
46
- function p(b) {
47
- const a = b?.rootMargin ?? k, s = b?.threshold ?? g, t = R(null), c = R(null), r = R(null), [i, n] = y(), e = f(() => {
48
- const o = t.current;
49
- if (!o) {
50
- n(void 0);
51
- return;
52
- }
53
- const u = E.getObserver({
54
- root: c.current,
55
- rootMargin: a,
56
- threshold: s
57
- });
58
- u.observe(o, (h) => {
59
- n(h);
60
- }), r.current = u;
61
- }, [a, s]), l = f(() => {
62
- const o = r.current, u = t.current;
63
- u && o?.unobserve(u), r.current = null;
64
- }, []), O = f((o) => {
65
- l(), t.current = o, e();
66
- }, [e, l]), v = f((o) => {
67
- l(), c.current = o, e();
68
- }, [e, l]);
69
- return [O, {
70
- entry: i,
71
- rootRef: v
72
- }];
38
+ var o = a();
39
+ function s(a) {
40
+ let s = a?.rootMargin ?? r, c = a?.threshold ?? i, l = t(null), u = t(null), d = t(null), [f, p] = n(), m = e(() => {
41
+ let e = l.current;
42
+ if (!e) {
43
+ p(void 0);
44
+ return;
45
+ }
46
+ let t = o.getObserver({
47
+ root: u.current,
48
+ rootMargin: s,
49
+ threshold: c
50
+ });
51
+ t.observe(e, (e) => {
52
+ p(e);
53
+ }), d.current = t;
54
+ }, [s, c]), h = e(() => {
55
+ let e = d.current, t = l.current;
56
+ t && e?.unobserve(t), d.current = null;
57
+ }, []);
58
+ return [e((e) => {
59
+ h(), l.current = e, m();
60
+ }, [m, h]), {
61
+ entry: f,
62
+ rootRef: e((e) => {
63
+ h(), u.current = e, m();
64
+ }, [m, h])
65
+ }];
73
66
  }
74
- function w(b) {
75
- const [a, s] = p(b), t = !!s.entry?.isIntersecting, [c, r] = y(t);
76
- return t && !c && r(!0), [a, {
77
- ...s,
78
- isVisible: t,
79
- wasEverVisible: c
80
- }];
67
+ function c(e) {
68
+ let [t, r] = s(e), i = !!r.entry?.isIntersecting, [a, o] = n(i);
69
+ return i && !a && o(!0), [t, {
70
+ ...r,
71
+ isVisible: i,
72
+ wasEverVisible: a
73
+ }];
81
74
  }
82
- export {
83
- C as createObserverCache,
84
- w as useTrackVisibility
85
- };
75
+ export { a as createObserverCache, c as useTrackVisibility };
@@ -1,175 +1,134 @@
1
- import { useComboboxStore as $, ComboboxProvider as ee, PopoverAnchor as oe, Combobox as te, ComboboxCancel as le, ComboboxPopover as ae, ComboboxItem as se } from "@ariakit/react";
2
- import { useLabelable as ne, ChipsGroup as re, InputChip as ie, IconButton as ce } from "@box/blueprint-web";
3
- import { XMark as ue, Search as me } from "@box/blueprint-web-assets/icons/Fill";
4
- import { Size6 as R, Size1 as pe, IconIconOnLightSecondary as de } from "@box/blueprint-web-assets/tokens/tokens";
5
- import d from "clsx";
6
- import { forwardRef as be, useId as he, useState as b, useRef as h, useCallback as A } from "react";
7
- import { useIntl as fe } from "react-intl";
8
- import O from "../combobox-with-api-pagination/messages.js";
9
- import { useControllableState as Ce } from "../combobox-with-api-pagination/utils/use-controllable-state.js";
10
- import { s as t, D as ge } from "../../../../chunks/dynamic-loading-tree.js";
11
- import { jsxs as r, jsx as o } from "react/jsx-runtime";
12
- const ve = () => /* @__PURE__ */ o(me, {
13
- color: de,
14
- height: R,
15
- role: "presentation",
16
- style: {
17
- padding: pe,
18
- boxSizing: "border-box"
19
- },
20
- width: R
21
- }), ze = /* @__PURE__ */ be(function(T, Ie) {
22
- const {
23
- className: B,
24
- closeOnSelection: E = !1,
25
- dataTargetId: k,
26
- defaultFetcher: z,
27
- defaultValue: D = [],
28
- disabled: n,
29
- hideLabel: f,
30
- initialOpen: M = !1,
31
- label: P,
32
- levels: W,
33
- loadingAriaLabel: F,
34
- multiselect: C = !1,
35
- noResultMessage: j,
36
- onValueChange: G,
37
- onOpenChange: K,
38
- placeholder: U,
39
- portalElement: X,
40
- selectableLevels: q,
41
- treeAriaLabel: H,
42
- value: J
43
- } = T, {
44
- formatMessage: g
45
- } = fe(), i = he(), [v, x] = b(M), [a, c] = Ce({
46
- prop: J,
47
- defaultProp: D,
48
- onChange: G
49
- }), [I, S] = b(""), V = h(null), [Q, w] = b(!1), Y = A(() => w(!0), []), Z = A(() => w(!1), []), L = h("");
50
- Q || (L.current = I.trimStart());
51
- const u = $({
52
- includesBaseElement: !0,
53
- virtualFocus: !1,
54
- value: I,
55
- setValue: (e) => {
56
- S(e);
57
- },
58
- open: v,
59
- setOpen: (e) => {
60
- x(e), K?.(e);
61
- }
62
- }), y = a.length > 0, N = a.length > 0, _ = ne(P, i), m = h(null);
63
- return /* @__PURE__ */ r(ee, {
64
- store: u,
65
- children: [/* @__PURE__ */ o(oe, {
66
- children: /* @__PURE__ */ r("div", {
67
- className: d(t.container, B, {
68
- [t.disabled]: n
69
- }),
70
- children: [/* @__PURE__ */ o(_, {
71
- className: d(t.label, {
72
- [t.hiddenLabel]: f
73
- }),
74
- hideLabel: f
75
- }), /* @__PURE__ */ o("div", {
76
- children: /* @__PURE__ */ r("div", {
77
- className: d(t.comboboxContainer, {
78
- [t.withChips]: N,
79
- [t.withComboboxButtons]: y
80
- }),
81
- children: [N && /* @__PURE__ */ o(re, {
82
- children: a.map((e) => /* @__PURE__ */ o(ie, {
83
- label: e.displayValue,
84
- onDelete: () => {
85
- if (n)
86
- return;
87
- const l = a.filter((s) => s.value !== e.value);
88
- c(l);
89
- },
90
- tooltip: e.displayValue
91
- }, e.value))
92
- }), /* @__PURE__ */ r("div", {
93
- className: t.textInputWrapper,
94
- children: [/* @__PURE__ */ o(te, {
95
- ref: V,
96
- "aria-haspopup": "tree",
97
- className: t.textInput,
98
- "data-target-id": k,
99
- disabled: n,
100
- id: i,
101
- onCompositionEnd: Z,
102
- onCompositionStart: Y,
103
- placeholder: U,
104
- store: u
105
- }), /* @__PURE__ */ o("div", {
106
- className: t.comboboxButtons,
107
- children: y ? /* @__PURE__ */ o(le, {
108
- disabled: n,
109
- onClick: () => {
110
- c([]);
111
- },
112
- render: (e) => /* @__PURE__ */ o(ce, {
113
- ...e,
114
- "aria-label": "Clear selection",
115
- icon: ue,
116
- size: "x-small"
117
- }),
118
- store: u
119
- }) : /* @__PURE__ */ o(ve, {})
120
- })]
121
- })]
122
- })
123
- })]
124
- })
125
- }), /* @__PURE__ */ o(ae, {
126
- "aria-labelledby": i,
127
- className: t.popover,
128
- fitViewport: !0,
129
- gutter: 8,
130
- portal: !0,
131
- portalElement: X,
132
- sameWidth: !0,
133
- children: /* @__PURE__ */ o(se, {
134
- onFocusVisible: (e) => {
135
- m.current?.firstChild?.focus();
136
- },
137
- onKeyDown: (e) => {
138
- if (e.key === "ArrowUp") {
139
- const l = m.current?.firstChild;
140
- document.activeElement === l && (l.blur(), V.current?.focus());
141
- }
142
- },
143
- children: /* @__PURE__ */ o(ge, {
144
- ref: m,
145
- ariaLabel: H,
146
- defaultFetcher: z,
147
- levels: W,
148
- loadingAriaLabel: F || g(O.loadingAriaLabel),
149
- multiselect: C,
150
- noResultMessage: j || g(O.noResults),
151
- onSelect: (e) => {
152
- const {
153
- metadata: l
154
- } = e.element;
155
- let s = [];
156
- e.isSelected ? (C && (s = a.filter((p) => p.value !== e.element.id)), s.push({
157
- value: e.element.id,
158
- displayValue: l.displayValue,
159
- level: l.level,
160
- selectable: l.selectable,
161
- ancestors: l.ancestors
162
- }), E && s.length > a.length && x(!1)) : s = a.filter((p) => p.value !== e.element.id), c(s), S("");
163
- },
164
- open: v,
165
- searchInput: L.current,
166
- selectableLevels: q,
167
- selectedNodes: a.map((e) => e.value)
168
- })
169
- })
170
- })]
171
- });
1
+ import e from "../combobox-with-api-pagination/messages.js";
2
+ import { useControllableState as t } from "../combobox-with-api-pagination/utils/use-controllable-state.js";
3
+ import { n, t as r } from "../../../../chunks/dynamic-loading-tree.js";
4
+ import { Combobox as i, ComboboxCancel as a, ComboboxItem as ee, ComboboxPopover as o, ComboboxProvider as s, PopoverAnchor as c, useComboboxStore as l } from "@ariakit/react";
5
+ import { ChipsGroup as te, IconButton as ne, InputChip as re, useLabelable as ie } from "@box/blueprint-web";
6
+ import { Search as u, XMark as d } from "@box/blueprint-web-assets/icons/Fill";
7
+ import { IconIconOnLightSecondary as f, Size1 as p, Size6 as m } from "@box/blueprint-web-assets/tokens/tokens";
8
+ import h from "clsx";
9
+ import { forwardRef as g, useCallback as _, useId as v, useRef as y, useState as b } from "react";
10
+ import { useIntl as ae } from "react-intl";
11
+ import { jsx as x, jsxs as S } from "react/jsx-runtime";
12
+ var oe = () => /* @__PURE__ */ x(u, {
13
+ color: f,
14
+ height: m,
15
+ role: "presentation",
16
+ style: {
17
+ padding: p,
18
+ boxSizing: "border-box"
19
+ },
20
+ width: m
21
+ }), C = /* @__PURE__ */ g(function(u, f) {
22
+ let { className: p, closeOnSelection: m = !1, dataTargetId: g, defaultFetcher: C, defaultValue: se = [], disabled: w, hideLabel: T, initialOpen: E = !1, label: D, levels: O, loadingAriaLabel: k, multiselect: A = !1, noResultMessage: j, onValueChange: M, onOpenChange: N, placeholder: P, portalElement: F, selectableLevels: I, treeAriaLabel: L, value: R } = u, { formatMessage: z } = ae(), B = v(), [V, H] = b(E), [U, W] = t({
23
+ prop: R,
24
+ defaultProp: se,
25
+ onChange: M
26
+ }), [G, K] = b(""), q = y(null), [ce, J] = b(!1), le = _(() => J(!0), []), ue = _(() => J(!1), []), Y = y("");
27
+ ce || (Y.current = G.trimStart());
28
+ let X = l({
29
+ includesBaseElement: !0,
30
+ virtualFocus: !1,
31
+ value: G,
32
+ setValue: (e) => {
33
+ K(e);
34
+ },
35
+ open: V,
36
+ setOpen: (e) => {
37
+ H(e), N?.(e);
38
+ }
39
+ }), Z = U.length > 0, Q = U.length > 0, de = ie(D, B), $ = y(null);
40
+ return /* @__PURE__ */ S(s, {
41
+ store: X,
42
+ children: [/* @__PURE__ */ x(c, { children: /* @__PURE__ */ S("div", {
43
+ className: h(n.container, p, { [n.disabled]: w }),
44
+ children: [/* @__PURE__ */ x(de, {
45
+ className: h(n.label, { [n.hiddenLabel]: T }),
46
+ hideLabel: T
47
+ }), /* @__PURE__ */ x("div", { children: /* @__PURE__ */ S("div", {
48
+ className: h(n.comboboxContainer, {
49
+ [n.withChips]: Q,
50
+ [n.withComboboxButtons]: Z
51
+ }),
52
+ children: [Q && /* @__PURE__ */ x(te, { children: U.map((e) => /* @__PURE__ */ x(re, {
53
+ label: e.displayValue,
54
+ onDelete: () => {
55
+ w || W(U.filter((t) => t.value !== e.value));
56
+ },
57
+ tooltip: e.displayValue
58
+ }, e.value)) }), /* @__PURE__ */ S("div", {
59
+ className: n.textInputWrapper,
60
+ children: [/* @__PURE__ */ x(i, {
61
+ ref: q,
62
+ "aria-haspopup": "tree",
63
+ className: n.textInput,
64
+ "data-target-id": g,
65
+ disabled: w,
66
+ id: B,
67
+ onCompositionEnd: ue,
68
+ onCompositionStart: le,
69
+ placeholder: P,
70
+ store: X
71
+ }), /* @__PURE__ */ x("div", {
72
+ className: n.comboboxButtons,
73
+ children: Z ? /* @__PURE__ */ x(a, {
74
+ disabled: w,
75
+ onClick: () => {
76
+ W([]);
77
+ },
78
+ render: (e) => /* @__PURE__ */ x(ne, {
79
+ ...e,
80
+ "aria-label": "Clear selection",
81
+ icon: d,
82
+ size: "x-small"
83
+ }),
84
+ store: X
85
+ }) : /* @__PURE__ */ x(oe, {})
86
+ })]
87
+ })]
88
+ }) })]
89
+ }) }), /* @__PURE__ */ x(o, {
90
+ "aria-labelledby": B,
91
+ className: n.popover,
92
+ fitViewport: !0,
93
+ gutter: 8,
94
+ portal: !0,
95
+ portalElement: F,
96
+ sameWidth: !0,
97
+ children: /* @__PURE__ */ x(ee, {
98
+ onFocusVisible: (e) => {
99
+ ($.current?.firstChild)?.focus();
100
+ },
101
+ onKeyDown: (e) => {
102
+ if (e.key === "ArrowUp") {
103
+ let e = $.current?.firstChild;
104
+ document.activeElement === e && (e.blur(), q.current?.focus());
105
+ }
106
+ },
107
+ children: /* @__PURE__ */ x(r, {
108
+ ref: $,
109
+ ariaLabel: L,
110
+ defaultFetcher: C,
111
+ levels: O,
112
+ loadingAriaLabel: k || z(e.loadingAriaLabel),
113
+ multiselect: A,
114
+ noResultMessage: j || z(e.noResults),
115
+ onSelect: (e) => {
116
+ let { metadata: t } = e.element, n = [];
117
+ e.isSelected ? (A && (n = U.filter((t) => t.value !== e.element.id)), n.push({
118
+ value: e.element.id,
119
+ displayValue: t.displayValue,
120
+ level: t.level,
121
+ selectable: t.selectable,
122
+ ancestors: t.ancestors
123
+ }), m && n.length > U.length && H(!1)) : n = U.filter((t) => t.value !== e.element.id), W(n), K("");
124
+ },
125
+ open: V,
126
+ searchInput: Y.current,
127
+ selectableLevels: I,
128
+ selectedNodes: U.map((e) => e.value)
129
+ })
130
+ })
131
+ })]
132
+ });
172
133
  });
173
- export {
174
- ze as ComboboxWithApiTreeView
175
- };
134
+ export { C as ComboboxWithApiTreeView };
@@ -1,10 +1,2 @@
1
- import "@box/blueprint-web";
2
- import "@box/tree";
3
- import "react";
4
- import "./tree-utils.js";
5
- import "../../../../chunks/treeReducer.js";
6
- import { D as n } from "../../../../chunks/dynamic-loading-tree.js";
7
- import "react/jsx-runtime";
8
- export {
9
- n as DynamicLoadingTree
10
- };
1
+ import { t as e } from "../../../../chunks/dynamic-loading-tree.js";
2
+ export { e as DynamicLoadingTree };