@box/metadata-template-browser 1.18.0 → 1.19.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,57 +1,65 @@
1
- import { useBrowseState as e, useBrowserActions as t, useConsumerState as n, useSearchState as r, useSelectionState as i } from "../esm/lib/contexts/hooks.js";
2
- import { t as a } from "./loader-skeleton.js";
3
- import { BrowseList as o } from "../esm/lib/components/browse-list/browse-list.js";
4
- import { SearchList as s } from "../esm/lib/components/search-list/search-list.js";
5
- import { useIsInitialBrowseLoading as c } from "../esm/lib/hooks/use-is-initial-browse-loading.js";
6
- import l from "clsx";
7
- import { useCallback as u, useMemo as d } from "react";
8
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
9
- import '../styles/metadata-template-browser-list-box.css';var m = {
1
+ import { useBrowseState as e, useBrowserActions as t, useConsumerState as n, useNavigationState as r, useSearchState as i, useSelectionState as a } from "../esm/lib/contexts/hooks.js";
2
+ import { t as o } from "./loader-skeleton.js";
3
+ import { BrowseList as s } from "../esm/lib/components/browse-list/browse-list.js";
4
+ import { SearchList as c } from "../esm/lib/components/search-list/search-list.js";
5
+ import { useIsInitialBrowseLoading as l } from "../esm/lib/hooks/use-is-initial-browse-loading.js";
6
+ import { useFocusFirstRowAfterNavigation as u } from "../esm/lib/hooks/use-focus-first-row-after-navigation.js";
7
+ import d from "clsx";
8
+ import { useCallback as f, useMemo as p, useRef as m } from "react";
9
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
10
+ import '../styles/metadata-template-browser-list-box.css';var _ = {
10
11
  listBox: "_listBox_1qbmg_1",
11
12
  browseWrapper: "_browseWrapper_1qbmg_9",
12
13
  hidden: "_hidden_1qbmg_16"
13
14
  };
14
- function h() {
15
- let { isDisabled: h } = n(), g = c(), { searchValue: _, searchResults: v } = r(), { namespaces: y, templates: b } = e(), { selectedTemplateId: x } = i(), { selectTemplate: S, navigateTo: C } = t(), w = _.length > 0, T = u((e) => {
16
- if (h) return;
15
+ function v() {
16
+ let { isDisabled: v } = n(), y = l(), { searchValue: b, searchResults: x } = i(), { namespaces: S, templates: C, isFetching: w } = e(), { selectedTemplateId: T } = a(), { selectTemplate: E, navigateTo: D } = t(), { path: O } = r(), k = b.length > 0, A = m(null);
17
+ u({
18
+ containerRef: A,
19
+ path: O,
20
+ isFetching: w
21
+ });
22
+ let j = f((e) => {
23
+ if (v) return;
17
24
  let t = String(e);
18
- if (w) {
19
- let e = v.find((e) => e.id === t);
20
- e && S(e);
25
+ if (k) {
26
+ let e = x.find((e) => e.id === t);
27
+ e && E(e);
21
28
  return;
22
29
  }
23
- let n = b.find((e) => e.id === t);
30
+ let n = C.find((e) => e.id === t);
24
31
  if (n) {
25
- S(n);
32
+ E(n);
26
33
  return;
27
34
  }
28
- let r = y.find((e) => e.id === t);
29
- r && C(r);
35
+ let r = S.find((e) => e.id === t);
36
+ r && D(r);
30
37
  }, [
31
- h,
32
- w,
33
38
  v,
34
- b,
35
- y,
39
+ k,
40
+ x,
41
+ C,
36
42
  S,
37
- C
38
- ]), E = d(() => x ? new Set([x]) : /* @__PURE__ */ new Set(), [x]);
39
- return g ? /* @__PURE__ */ f("div", {
40
- className: m.listBox,
41
- children: /* @__PURE__ */ f(a, {})
42
- }) : /* @__PURE__ */ p("div", {
43
- className: m.listBox,
44
- children: [/* @__PURE__ */ f("div", {
45
- "aria-hidden": w,
46
- className: l(m.browseWrapper, w && m.hidden),
47
- children: /* @__PURE__ */ f(o, {
48
- onAction: T,
49
- selectedKeys: E
43
+ E,
44
+ D
45
+ ]), M = p(() => T ? new Set([T]) : /* @__PURE__ */ new Set(), [T]);
46
+ return y ? /* @__PURE__ */ h("div", {
47
+ className: _.listBox,
48
+ children: /* @__PURE__ */ h(o, {})
49
+ }) : /* @__PURE__ */ g("div", {
50
+ className: _.listBox,
51
+ children: [/* @__PURE__ */ h("div", {
52
+ ref: A,
53
+ "aria-hidden": k,
54
+ className: d(_.browseWrapper, k && _.hidden),
55
+ children: /* @__PURE__ */ h(s, {
56
+ onAction: j,
57
+ selectedKeys: M
50
58
  })
51
- }), w && /* @__PURE__ */ f(s, {
52
- onAction: T,
53
- selectedKeys: E
59
+ }), k && /* @__PURE__ */ h(c, {
60
+ onAction: j,
61
+ selectedKeys: M
54
62
  })]
55
63
  });
56
64
  }
57
- export { h as t };
65
+ export { v as t };
@@ -0,0 +1,32 @@
1
+ import { useEffect as e, useRef as t } from "react";
2
+ var n = "[role=\"row\"]";
3
+ function r({ containerRef: r, path: i, isFetching: a }) {
4
+ let o = t(i), s = t(!1);
5
+ e(() => {
6
+ i !== o.current && (o.current = i, s.current = !0);
7
+ let e = r.current;
8
+ if (!s.current || a || !e) return;
9
+ s.current = !1;
10
+ let t = () => {
11
+ let { activeElement: t, body: r } = e.ownerDocument;
12
+ if (!(t === null || t === r || e.contains(t))) return !0;
13
+ let i = e.querySelector(n);
14
+ return i ? (i.focus(), !0) : !1;
15
+ };
16
+ if (t()) return;
17
+ let c = new MutationObserver(() => {
18
+ t() && c.disconnect();
19
+ });
20
+ return c.observe(e, {
21
+ childList: !0,
22
+ subtree: !0
23
+ }), () => {
24
+ c.disconnect();
25
+ };
26
+ }, [
27
+ i,
28
+ a,
29
+ r
30
+ ]);
31
+ }
32
+ export { r as useFocusFirstRowAfterNavigation };
@@ -0,0 +1,28 @@
1
+ import { RefObject } from 'react';
2
+ import { BreadcrumbEntry } from '../types';
3
+ interface UseFocusFirstRowAfterNavigationParams {
4
+ /** Container holding the browse list. The first descendant `[role="row"]` is focused. */
5
+ readonly containerRef: RefObject<HTMLElement | null>;
6
+ /** Current navigation path. A change in reference is treated as a user navigation. */
7
+ readonly path: readonly BreadcrumbEntry[];
8
+ /** True while the post-navigation fetch is in flight. Focus is deferred until it settles. */
9
+ readonly isFetching: boolean;
10
+ }
11
+ /**
12
+ * Restores keyboard focus to the first row of the browse list after a namespace
13
+ * navigation. Without this, the user-activated `NamespaceRow` unmounts during the
14
+ * in-flight fetch (the list is replaced by a loading skeleton), DOM focus drops
15
+ * to `<body>`, and arrow-key navigation appears broken until the user re-tabs in.
16
+ *
17
+ * No-op on initial render — `path` hasn't changed yet, so focus stays wherever
18
+ * the host page placed it. Only user-initiated path transitions trigger the restore.
19
+ *
20
+ * @example
21
+ * const containerRef = useRef<HTMLDivElement>(null);
22
+ * const { path } = useNavigationState();
23
+ * const { isFetching } = useBrowseState();
24
+ * useFocusFirstRowAfterNavigation({ containerRef, path, isFetching });
25
+ * return <div ref={containerRef}><BrowseList ... /></div>;
26
+ */
27
+ export declare function useFocusFirstRowAfterNavigation({ containerRef, path, isFetching, }: UseFocusFirstRowAfterNavigationParams): void;
28
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-template-browser",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
6
  "@box/blueprint-web": "^14.16.0",