@fluentui/react-tree 9.75.0-experimental.css-modules.20261031-810ab07afb.0 → 9.75.1-experimental.positioning-engine.20261103-19efe125d1.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.
- package/CHANGELOG.md +28 -19
- package/README.md +0 -12
- package/dist/index.d.cts +83 -6
- package/dist/index.d.ts +83 -6
- package/lib/Tree.js +1 -1
- package/lib/Tree.js.map +1 -1
- package/lib/TreeItemLayout.js +1 -1
- package/lib/TreeItemLayout.js.map +1 -1
- package/lib/components/FlatTree/useFlatTree.js +28 -3
- package/lib/components/FlatTree/useFlatTree.js.map +1 -1
- package/lib/components/Tree/Tree.types.js +1 -1
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/index.js +1 -1
- package/lib/components/Tree/index.js.map +1 -1
- package/lib/components/Tree/renderTree.js +6 -2
- package/lib/components/Tree/renderTree.js.map +1 -1
- package/lib/components/Tree/useTree.js +75 -6
- package/lib/components/Tree/useTree.js.map +1 -1
- package/lib/components/Tree/useTreeContextValues.js +4 -1
- package/lib/components/Tree/useTreeContextValues.js.map +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js.map +1 -1
- package/lib/components/TreeItemLayout/index.js +1 -1
- package/lib/components/TreeItemLayout/index.js.map +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js +13 -7
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +201 -30
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/hooks/useFlatTreeNavigation.js +3 -4
- package/lib/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib/hooks/useRootTree.js +3 -8
- package/lib/hooks/useRootTree.js.map +1 -1
- package/lib/hooks/useRovingTabIndexBase.js +108 -0
- package/lib/hooks/useRovingTabIndexBase.js.map +1 -0
- package/lib/hooks/useRovingTabIndexes.js +2 -61
- package/lib/hooks/useRovingTabIndexes.js.map +1 -1
- package/lib/hooks/useSubtree.js +1 -11
- package/lib/hooks/useSubtree.js.map +1 -1
- package/lib/hooks/useTreeNavigation.js +6 -84
- package/lib/hooks/useTreeNavigation.js.map +1 -1
- package/lib/hooks/useTreeNavigationBase.js +131 -0
- package/lib/hooks/useTreeNavigationBase.js.map +1 -0
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/utils/queryTreeItemActions.js +29 -0
- package/lib/utils/queryTreeItemActions.js.map +1 -0
- package/lib-commonjs/Tree.cjs +3 -0
- package/lib-commonjs/Tree.cjs.map +1 -1
- package/lib-commonjs/TreeItemLayout.cjs +3 -0
- package/lib-commonjs/TreeItemLayout.cjs.map +1 -1
- package/lib-commonjs/components/FlatTree/useFlatTree.cjs +28 -3
- package/lib-commonjs/components/FlatTree/useFlatTree.cjs.map +1 -1
- package/lib-commonjs/components/Tree/Tree.types.cjs +1 -1
- package/lib-commonjs/components/Tree/Tree.types.cjs.map +1 -1
- package/lib-commonjs/components/Tree/index.cjs +3 -0
- package/lib-commonjs/components/Tree/index.cjs.map +1 -1
- package/lib-commonjs/components/Tree/renderTree.cjs +1 -1
- package/lib-commonjs/components/Tree/renderTree.cjs.map +1 -1
- package/lib-commonjs/components/Tree/useTree.cjs +68 -8
- package/lib-commonjs/components/Tree/useTree.cjs.map +1 -1
- package/lib-commonjs/components/Tree/useTreeContextValues.cjs +4 -1
- package/lib-commonjs/components/Tree/useTreeContextValues.cjs.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/TreeItemLayout.types.cjs +1 -1
- package/lib-commonjs/components/TreeItemLayout/TreeItemLayout.types.cjs.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/index.cjs +3 -0
- package/lib-commonjs/components/TreeItemLayout/index.cjs.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.cjs +9 -6
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.cjs.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.cjs +200 -32
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.cjs.map +1 -1
- package/lib-commonjs/hooks/useFlatTreeNavigation.cjs +3 -4
- package/lib-commonjs/hooks/useFlatTreeNavigation.cjs.map +1 -1
- package/lib-commonjs/hooks/useRootTree.cjs +3 -8
- package/lib-commonjs/hooks/useRootTree.cjs.map +1 -1
- package/lib-commonjs/hooks/useRovingTabIndexBase.cjs +116 -0
- package/lib-commonjs/hooks/useRovingTabIndexBase.cjs.map +1 -0
- package/lib-commonjs/hooks/useRovingTabIndexes.cjs +2 -62
- package/lib-commonjs/hooks/useRovingTabIndexes.cjs.map +1 -1
- package/lib-commonjs/hooks/useSubtree.cjs +1 -11
- package/lib-commonjs/hooks/useSubtree.cjs.map +1 -1
- package/lib-commonjs/hooks/useTreeNavigation.cjs +5 -84
- package/lib-commonjs/hooks/useTreeNavigation.cjs.map +1 -1
- package/lib-commonjs/hooks/useTreeNavigationBase.cjs +140 -0
- package/lib-commonjs/hooks/useTreeNavigationBase.cjs.map +1 -0
- package/lib-commonjs/index.cjs +6 -0
- package/lib-commonjs/index.cjs.map +1 -1
- package/lib-commonjs/utils/queryTreeItemActions.cjs +38 -0
- package/lib-commonjs/utils/queryTreeItemActions.cjs.map +1 -0
- package/package.json +17 -20
- package/lib/components/FlatTree/FlatTree.module.css +0 -7
- package/lib/components/FlatTree/useFlatTreeStyles.styles.css.js +0 -9
- package/lib/components/FlatTree/useFlatTreeStyles.styles.css.js.map +0 -1
- package/lib/components/FlatTree/useFlatTreeStyles.styles.raw.css.js +0 -9
- package/lib/components/FlatTree/useFlatTreeStyles.styles.raw.css.js.map +0 -1
- package/lib/components/Tree/Tree.module.css +0 -11
- package/lib/components/Tree/useTreeStyles.styles.css.js +0 -9
- package/lib/components/Tree/useTreeStyles.styles.css.js.map +0 -1
- package/lib/components/Tree/useTreeStyles.styles.raw.css.js +0 -9
- package/lib/components/Tree/useTreeStyles.styles.raw.css.js.map +0 -1
- package/lib/components/TreeItem/TreeItem.module.css +0 -65
- package/lib/components/TreeItem/useTreeItemStyles.styles.css.js +0 -17
- package/lib/components/TreeItem/useTreeItemStyles.styles.css.js.map +0 -1
- package/lib/components/TreeItem/useTreeItemStyles.styles.raw.css.js +0 -17
- package/lib/components/TreeItem/useTreeItemStyles.styles.raw.css.js.map +0 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.module.css +0 -137
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.css.js +0 -51
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.css.js.map +0 -1
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.raw.css.js +0 -51
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.raw.css.js.map +0 -1
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.module.css +0 -149
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.css.js +0 -51
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.css.js.map +0 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.raw.css.js +0 -51
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.raw.css.js.map +0 -1
- package/lib-commonjs/components/FlatTree/FlatTree.module.css +0 -7
- package/lib-commonjs/components/FlatTree/useFlatTreeStyles.styles.css.cjs +0 -28
- package/lib-commonjs/components/FlatTree/useFlatTreeStyles.styles.css.cjs.map +0 -1
- package/lib-commonjs/components/FlatTree/useFlatTreeStyles.styles.raw.css.cjs +0 -28
- package/lib-commonjs/components/FlatTree/useFlatTreeStyles.styles.raw.css.cjs.map +0 -1
- package/lib-commonjs/components/Tree/Tree.module.css +0 -11
- package/lib-commonjs/components/Tree/useTreeStyles.styles.css.cjs +0 -28
- package/lib-commonjs/components/Tree/useTreeStyles.styles.css.cjs.map +0 -1
- package/lib-commonjs/components/Tree/useTreeStyles.styles.raw.css.cjs +0 -28
- package/lib-commonjs/components/Tree/useTreeStyles.styles.raw.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItem/TreeItem.module.css +0 -65
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.css.cjs +0 -36
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.raw.css.cjs +0 -36
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.raw.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItemLayout/TreeItemLayout.module.css +0 -137
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.css.cjs +0 -70
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.raw.css.cjs +0 -70
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.raw.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/TreeItemPersonaLayout.module.css +0 -149
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.css.cjs +0 -70
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.css.cjs.map +0 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.raw.css.cjs +0 -70
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.raw.css.cjs.map +0 -1
|
@@ -1,27 +1,96 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useEventCallback, useMergedRefs } from "@fluentui/react-utilities";
|
|
4
|
+
import { useFocusFinders, useFocusedElementChange } from "@fluentui/react-tabster";
|
|
5
|
+
import { presenceMotionSlot } from "@fluentui/react-motion";
|
|
6
|
+
import { Collapse } from "@fluentui/react-motion-components-preview";
|
|
4
7
|
import { createNextOpenItems, useControllableOpenItems } from "../../hooks/useControllableOpenItems.js";
|
|
5
8
|
import { createNextNestedCheckedItems, useNestedCheckedItems } from "./useNestedControllableCheckedItems.js";
|
|
6
9
|
import { SubtreeContext } from "../../contexts/subtreeContext.js";
|
|
7
10
|
import { useRootTree } from "../../hooks/useRootTree.js";
|
|
8
11
|
import { useSubtree } from "../../hooks/useSubtree.js";
|
|
9
|
-
import {
|
|
12
|
+
import { findFirstFocusableDOM, useTreeNavigationBase } from "../../hooks/useTreeNavigationBase.js";
|
|
13
|
+
import { useDOMFocusedElementChange } from "../../hooks/useRovingTabIndexBase.js";
|
|
10
14
|
import { useTreeContext_unstable } from "../../contexts/treeContext.js";
|
|
11
15
|
import { ImmutableSet } from "../../utils/ImmutableSet.js";
|
|
12
16
|
import { ImmutableMap } from "../../utils/ImmutableMap.js";
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Create the state required to render Tree.
|
|
19
|
+
*
|
|
20
|
+
* The returned state can be modified with hooks such as useTreeStyles_unstable,
|
|
21
|
+
* before being passed to renderTree_unstable.
|
|
22
|
+
*
|
|
23
|
+
* @param props - props from this instance of Tree
|
|
24
|
+
* @param ref - reference to root HTMLElement of Tree
|
|
25
|
+
*/ export const useTree_unstable = (props, ref)=>{
|
|
26
|
+
const { appearance = 'subtle', size = 'medium', collapseMotion, ...baseProps } = props;
|
|
27
|
+
// Tabster aware focus management, superseding the plain DOM one used by the base hook.
|
|
28
|
+
const state = useTreeInternal(baseProps, ref, useTabsterNavigationOptions);
|
|
29
|
+
if (state.contextType === 'subtree') {
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
33
|
+
components: {
|
|
34
|
+
...state.components,
|
|
35
|
+
collapseMotion: Collapse
|
|
36
|
+
},
|
|
37
|
+
collapseMotion: presenceMotionSlot(collapseMotion, {
|
|
38
|
+
elementType: Collapse,
|
|
39
|
+
defaultProps: {
|
|
40
|
+
visible: state.open,
|
|
41
|
+
unmountOnExit: true
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...state,
|
|
48
|
+
appearance,
|
|
49
|
+
size,
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
51
|
+
components: {
|
|
52
|
+
...state.components,
|
|
53
|
+
collapseMotion: Collapse
|
|
54
|
+
},
|
|
55
|
+
collapseMotion: undefined
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Base state hook for Tree, free of any design props, motion or focus management runtime.
|
|
60
|
+
*
|
|
61
|
+
* Arrow key navigation and the roving tab index are driven by plain DOM focus handling, and closed
|
|
62
|
+
* subtrees are not rendered as there is no collapse motion to unmount them.
|
|
63
|
+
*
|
|
64
|
+
* @param props - props from this instance of Tree
|
|
65
|
+
* @param ref - reference to root HTMLElement of Tree
|
|
66
|
+
*/ export const useTreeBase_unstable = (props, ref)=>{
|
|
67
|
+
return useTreeInternal(props, ref, useDOMNavigationOptions);
|
|
68
|
+
};
|
|
69
|
+
const domNavigationOptions = {
|
|
70
|
+
findFirstFocusable: findFirstFocusableDOM,
|
|
71
|
+
useFocusedElementChange: useDOMFocusedElementChange
|
|
72
|
+
};
|
|
73
|
+
const useDOMNavigationOptions = ()=>domNavigationOptions;
|
|
74
|
+
const useTabsterNavigationOptions = ()=>{
|
|
75
|
+
const { findFirstFocusable } = useFocusFinders();
|
|
76
|
+
return {
|
|
77
|
+
findFirstFocusable,
|
|
78
|
+
useFocusedElementChange
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
function useTreeInternal(props, ref, // Only the root tree drives navigation, so subtrees never pay for the focus management runtime.
|
|
82
|
+
useNavigationOptions) {
|
|
14
83
|
const isRoot = React.useContext(SubtreeContext) === undefined;
|
|
15
84
|
// as level is static, this doesn't break rule of hooks
|
|
16
85
|
// and if this becomes an issue later on, this can be easily converted
|
|
17
86
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
18
|
-
return isRoot ? useNestedRootTree(props, ref) : useNestedSubtree(props, ref);
|
|
19
|
-
}
|
|
20
|
-
function useNestedRootTree(props, ref) {
|
|
87
|
+
return isRoot ? useNestedRootTree(props, ref, useNavigationOptions) : useNestedSubtree(props, ref);
|
|
88
|
+
}
|
|
89
|
+
function useNestedRootTree(props, ref, useNavigationOptions) {
|
|
21
90
|
'use no memo'; // justified: compiler would optimize useNestedRootTree — manual opt-out to preserve runtime behavior
|
|
22
91
|
const [openItems, setOpenItems] = useControllableOpenItems(props);
|
|
23
92
|
const checkedItems = useNestedCheckedItems(props);
|
|
24
|
-
const navigation =
|
|
93
|
+
const navigation = useTreeNavigationBase(props.navigationMode, useNavigationOptions());
|
|
25
94
|
return Object.assign(useRootTree({
|
|
26
95
|
...props,
|
|
27
96
|
openItems,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Tree/useTree.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { TreeProps, TreeState } from './Tree.types';\nimport { createNextOpenItems, useControllableOpenItems } from '../../hooks/useControllableOpenItems';\nimport { createNextNestedCheckedItems, useNestedCheckedItems } from './useNestedControllableCheckedItems';\nimport { SubtreeContext } from '../../contexts/subtreeContext';\nimport { useRootTree } from '../../hooks/useRootTree';\nimport { useSubtree } from '../../hooks/useSubtree';\nimport { useTreeNavigation } from '../../hooks/useTreeNavigation';\nimport { useTreeContext_unstable } from '../../contexts/treeContext';\nimport { ImmutableSet } from '../../utils/ImmutableSet';\nimport { ImmutableMap } from '../../utils/ImmutableMap';\n\nexport const useTree_unstable = (props: TreeProps, ref: React.Ref<HTMLElement>): TreeState => {\n const isRoot = React.useContext(SubtreeContext) === undefined;\n // as level is static, this doesn't break rule of hooks\n // and if this becomes an issue later on, this can be easily converted\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return isRoot ? useNestedRootTree(props, ref) : useNestedSubtree(props, ref);\n};\n\nfunction useNestedRootTree(props: TreeProps, ref: React.Ref<HTMLElement>): TreeState {\n 'use no memo'; // justified: compiler would optimize useNestedRootTree — manual opt-out to preserve runtime behavior\n\n const [openItems, setOpenItems] = useControllableOpenItems(props);\n const checkedItems = useNestedCheckedItems(props);\n const navigation = useTreeNavigation(props.navigationMode);\n\n return Object.assign(\n useRootTree(\n {\n ...props,\n openItems,\n checkedItems,\n onOpenChange: useEventCallback((event, data) => {\n const nextOpenItems = createNextOpenItems(data, openItems);\n props.onOpenChange?.(event, {\n ...data,\n openItems: ImmutableSet.dangerouslyGetInternalSet(nextOpenItems),\n });\n setOpenItems(nextOpenItems);\n }),\n onNavigation: useEventCallback((event, data) => {\n props.onNavigation?.(event, data);\n if (!event.isDefaultPrevented()) {\n navigation.navigate(data, {\n preventScroll: data.isScrollPrevented(),\n });\n }\n }),\n onCheckedChange: useEventCallback((event, data) => {\n const nextCheckedItems = createNextNestedCheckedItems(data, checkedItems);\n props.onCheckedChange?.(event, {\n ...data,\n checkedItems: ImmutableMap.dangerouslyGetInternalMap(nextCheckedItems),\n });\n }),\n },\n useMergedRefs(ref, navigation.treeRef),\n ),\n {\n treeType: 'nested',\n forceUpdateRovingTabIndex: navigation.forceUpdateRovingTabIndex,\n } as const,\n );\n}\n\nfunction useNestedSubtree(props: TreeProps, ref: React.Ref<HTMLElement>): TreeState {\n if (process.env.NODE_ENV === 'development') {\n // this doesn't break rule of hooks, as environment is a static value\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const treeType = useTreeContext_unstable(ctx => ctx.treeType);\n if (treeType === 'flat') {\n throw new Error(/* #__DE-INDENT__ */ `\n @fluentui/react-tree [useTree]:\n Subtrees are not allowed in a FlatTree!\n You cannot use a <Tree> component inside of a <FlatTree> component!\n `);\n }\n }\n return useSubtree(props, ref);\n}\n"],"names":["React","useEventCallback","useMergedRefs","createNextOpenItems","useControllableOpenItems","createNextNestedCheckedItems","useNestedCheckedItems","SubtreeContext","useRootTree","useSubtree","useTreeNavigation","useTreeContext_unstable","ImmutableSet","ImmutableMap","useTree_unstable","props","ref","isRoot","useContext","undefined","useNestedRootTree","useNestedSubtree","openItems","setOpenItems","checkedItems","navigation","navigationMode","Object","assign","onOpenChange","event","data","nextOpenItems","dangerouslyGetInternalSet","onNavigation","isDefaultPrevented","navigate","preventScroll","isScrollPrevented","onCheckedChange","nextCheckedItems","dangerouslyGetInternalMap","treeRef","treeType","forceUpdateRovingTabIndex","process","env","NODE_ENV","ctx","Error"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAE5E,SAASC,mBAAmB,EAAEC,wBAAwB,QAAQ,0CAAuC;AACrG,SAASC,4BAA4B,EAAEC,qBAAqB,QAAQ,yCAAsC;AAC1G,SAASC,cAAc,QAAQ,mCAAgC;AAC/D,SAASC,WAAW,QAAQ,6BAA0B;AACtD,SAASC,UAAU,QAAQ,4BAAyB;AACpD,SAASC,iBAAiB,QAAQ,mCAAgC;AAClE,SAASC,uBAAuB,QAAQ,gCAA6B;AACrE,SAASC,YAAY,QAAQ,8BAA2B;AACxD,SAASC,YAAY,QAAQ,8BAA2B;AAExD,OAAO,MAAMC,mBAAmB,CAACC,OAAkBC;IACjD,MAAMC,SAASjB,MAAMkB,UAAU,CAACX,oBAAoBY;IACpD,uDAAuD;IACvD,sEAAsE;IACtE,sDAAsD;IACtD,OAAOF,SAASG,kBAAkBL,OAAOC,OAAOK,iBAAiBN,OAAOC;AAC1E,EAAE;AAEF,SAASI,kBAAkBL,KAAgB,EAAEC,GAA2B;IACtE,eAAe,qGAAqG;IAEpH,MAAM,CAACM,WAAWC,aAAa,GAAGnB,yBAAyBW;IAC3D,MAAMS,eAAelB,sBAAsBS;IAC3C,MAAMU,aAAaf,kBAAkBK,MAAMW,cAAc;IAEzD,OAAOC,OAAOC,MAAM,CAClBpB,YACE;QACE,GAAGO,KAAK;QACRO;QACAE;QACAK,cAAc5B,iBAAiB,CAAC6B,OAAOC;gBAErChB;YADA,MAAMiB,gBAAgB7B,oBAAoB4B,MAAMT;aAChDP,sBAAAA,MAAMc,YAAY,cAAlBd,0CAAAA,yBAAAA,OAAqBe,OAAO;gBAC1B,GAAGC,IAAI;gBACPT,WAAWV,aAAaqB,yBAAyB,CAACD;YACpD;YACAT,aAAaS;QACf;QACAE,cAAcjC,iBAAiB,CAAC6B,OAAOC;gBACrChB;aAAAA,sBAAAA,MAAMmB,YAAY,cAAlBnB,0CAAAA,yBAAAA,OAAqBe,OAAOC;YAC5B,IAAI,CAACD,MAAMK,kBAAkB,IAAI;gBAC/BV,WAAWW,QAAQ,CAACL,MAAM;oBACxBM,eAAeN,KAAKO,iBAAiB;gBACvC;YACF;QACF;QACAC,iBAAiBtC,iBAAiB,CAAC6B,OAAOC;gBAExChB;YADA,MAAMyB,mBAAmBnC,6BAA6B0B,MAAMP;aAC5DT,yBAAAA,MAAMwB,eAAe,cAArBxB,6CAAAA,4BAAAA,OAAwBe,OAAO;gBAC7B,GAAGC,IAAI;gBACPP,cAAcX,aAAa4B,yBAAyB,CAACD;YACvD;QACF;IACF,GACAtC,cAAcc,KAAKS,WAAWiB,OAAO,IAEvC;QACEC,UAAU;QACVC,2BAA2BnB,WAAWmB,yBAAyB;IACjE;AAEJ;AAEA,SAASvB,iBAAiBN,KAAgB,EAAEC,GAA2B;IACrE,IAAI6B,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QAC1C,qEAAqE;QACrE,sDAAsD;QACtD,MAAMJ,WAAWhC,wBAAwBqC,CAAAA,MAAOA,IAAIL,QAAQ;QAC5D,IAAIA,aAAa,QAAQ;YACvB,MAAM,IAAIM,MAA2B,CAAC;;mEAItC,CAAC;QACH;IACF;IACA,OAAOxC,WAAWM,OAAOC;AAC3B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Tree/useTree.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFocusFinders, useFocusedElementChange } from '@fluentui/react-tabster';\nimport { presenceMotionSlot } from '@fluentui/react-motion';\nimport { Collapse } from '@fluentui/react-motion-components-preview';\nimport type { TreeBaseProps, TreeBaseState, TreeProps, TreeState } from './Tree.types';\nimport { createNextOpenItems, useControllableOpenItems } from '../../hooks/useControllableOpenItems';\nimport { createNextNestedCheckedItems, useNestedCheckedItems } from './useNestedControllableCheckedItems';\nimport { SubtreeContext } from '../../contexts/subtreeContext';\nimport { useRootTree } from '../../hooks/useRootTree';\nimport { useSubtree } from '../../hooks/useSubtree';\nimport { findFirstFocusableDOM, useTreeNavigationBase } from '../../hooks/useTreeNavigationBase';\nimport type { TreeNavigationOptions } from '../../hooks/useTreeNavigationBase';\nimport { useDOMFocusedElementChange } from '../../hooks/useRovingTabIndexBase';\nimport { useTreeContext_unstable } from '../../contexts/treeContext';\nimport { ImmutableSet } from '../../utils/ImmutableSet';\nimport { ImmutableMap } from '../../utils/ImmutableMap';\n\n/**\n * Create the state required to render Tree.\n *\n * The returned state can be modified with hooks such as useTreeStyles_unstable,\n * before being passed to renderTree_unstable.\n *\n * @param props - props from this instance of Tree\n * @param ref - reference to root HTMLElement of Tree\n */\nexport const useTree_unstable = (props: TreeProps, ref: React.Ref<HTMLElement>): TreeState => {\n const { appearance = 'subtle', size = 'medium', collapseMotion, ...baseProps } = props;\n // Tabster aware focus management, superseding the plain DOM one used by the base hook.\n const state = useTreeInternal(baseProps, ref, useTabsterNavigationOptions);\n\n if (state.contextType === 'subtree') {\n return {\n ...state,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n components: { ...state.components, collapseMotion: Collapse },\n collapseMotion: presenceMotionSlot(collapseMotion, {\n elementType: Collapse,\n defaultProps: {\n visible: state.open,\n unmountOnExit: true,\n },\n }),\n };\n }\n\n return {\n ...state,\n appearance,\n size,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n components: { ...state.components, collapseMotion: Collapse },\n collapseMotion: undefined,\n };\n};\n\n/**\n * Base state hook for Tree, free of any design props, motion or focus management runtime.\n *\n * Arrow key navigation and the roving tab index are driven by plain DOM focus handling, and closed\n * subtrees are not rendered as there is no collapse motion to unmount them.\n *\n * @param props - props from this instance of Tree\n * @param ref - reference to root HTMLElement of Tree\n */\nexport const useTreeBase_unstable = (props: TreeBaseProps, ref: React.Ref<HTMLElement>): TreeBaseState => {\n return useTreeInternal(props, ref, useDOMNavigationOptions);\n};\n\nconst domNavigationOptions: TreeNavigationOptions = {\n findFirstFocusable: findFirstFocusableDOM,\n useFocusedElementChange: useDOMFocusedElementChange,\n};\n\nconst useDOMNavigationOptions = (): TreeNavigationOptions => domNavigationOptions;\n\nconst useTabsterNavigationOptions = (): TreeNavigationOptions => {\n const { findFirstFocusable } = useFocusFinders();\n return { findFirstFocusable, useFocusedElementChange };\n};\n\nfunction useTreeInternal(\n props: TreeBaseProps,\n ref: React.Ref<HTMLElement>,\n // Only the root tree drives navigation, so subtrees never pay for the focus management runtime.\n useNavigationOptions: () => TreeNavigationOptions,\n): TreeBaseState {\n const isRoot = React.useContext(SubtreeContext) === undefined;\n // as level is static, this doesn't break rule of hooks\n // and if this becomes an issue later on, this can be easily converted\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return isRoot ? useNestedRootTree(props, ref, useNavigationOptions) : useNestedSubtree(props, ref);\n}\n\nfunction useNestedRootTree(\n props: TreeBaseProps,\n ref: React.Ref<HTMLElement>,\n useNavigationOptions: () => TreeNavigationOptions,\n): TreeBaseState {\n 'use no memo'; // justified: compiler would optimize useNestedRootTree — manual opt-out to preserve runtime behavior\n\n const [openItems, setOpenItems] = useControllableOpenItems(props);\n const checkedItems = useNestedCheckedItems(props);\n const navigation = useTreeNavigationBase(props.navigationMode, useNavigationOptions());\n\n return Object.assign(\n useRootTree(\n {\n ...props,\n openItems,\n checkedItems,\n onOpenChange: useEventCallback((event, data) => {\n const nextOpenItems = createNextOpenItems(data, openItems);\n props.onOpenChange?.(event, {\n ...data,\n openItems: ImmutableSet.dangerouslyGetInternalSet(nextOpenItems),\n });\n setOpenItems(nextOpenItems);\n }),\n onNavigation: useEventCallback((event, data) => {\n props.onNavigation?.(event, data);\n if (!event.isDefaultPrevented()) {\n navigation.navigate(data, {\n preventScroll: data.isScrollPrevented(),\n });\n }\n }),\n onCheckedChange: useEventCallback((event, data) => {\n const nextCheckedItems = createNextNestedCheckedItems(data, checkedItems);\n props.onCheckedChange?.(event, {\n ...data,\n checkedItems: ImmutableMap.dangerouslyGetInternalMap(nextCheckedItems),\n });\n }),\n },\n useMergedRefs(ref, navigation.treeRef),\n ),\n {\n treeType: 'nested',\n forceUpdateRovingTabIndex: navigation.forceUpdateRovingTabIndex,\n } as const,\n );\n}\n\nfunction useNestedSubtree(props: TreeBaseProps, ref: React.Ref<HTMLElement>): TreeBaseState {\n if (process.env.NODE_ENV === 'development') {\n // this doesn't break rule of hooks, as environment is a static value\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const treeType = useTreeContext_unstable(ctx => ctx.treeType);\n if (treeType === 'flat') {\n throw new Error(/* #__DE-INDENT__ */ `\n @fluentui/react-tree [useTree]:\n Subtrees are not allowed in a FlatTree!\n You cannot use a <Tree> component inside of a <FlatTree> component!\n `);\n }\n }\n return useSubtree(props, ref);\n}\n"],"names":["React","useEventCallback","useMergedRefs","useFocusFinders","useFocusedElementChange","presenceMotionSlot","Collapse","createNextOpenItems","useControllableOpenItems","createNextNestedCheckedItems","useNestedCheckedItems","SubtreeContext","useRootTree","useSubtree","findFirstFocusableDOM","useTreeNavigationBase","useDOMFocusedElementChange","useTreeContext_unstable","ImmutableSet","ImmutableMap","useTree_unstable","props","ref","appearance","size","collapseMotion","baseProps","state","useTreeInternal","useTabsterNavigationOptions","contextType","components","elementType","defaultProps","visible","open","unmountOnExit","undefined","useTreeBase_unstable","useDOMNavigationOptions","domNavigationOptions","findFirstFocusable","useNavigationOptions","isRoot","useContext","useNestedRootTree","useNestedSubtree","openItems","setOpenItems","checkedItems","navigation","navigationMode","Object","assign","onOpenChange","event","data","nextOpenItems","dangerouslyGetInternalSet","onNavigation","isDefaultPrevented","navigate","preventScroll","isScrollPrevented","onCheckedChange","nextCheckedItems","dangerouslyGetInternalMap","treeRef","treeType","forceUpdateRovingTabIndex","process","env","NODE_ENV","ctx","Error"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAC5E,SAASC,eAAe,EAAEC,uBAAuB,QAAQ,0BAA0B;AACnF,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,QAAQ,QAAQ,4CAA4C;AAErE,SAASC,mBAAmB,EAAEC,wBAAwB,QAAQ,0CAAuC;AACrG,SAASC,4BAA4B,EAAEC,qBAAqB,QAAQ,yCAAsC;AAC1G,SAASC,cAAc,QAAQ,mCAAgC;AAC/D,SAASC,WAAW,QAAQ,6BAA0B;AACtD,SAASC,UAAU,QAAQ,4BAAyB;AACpD,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,uCAAoC;AAEjG,SAASC,0BAA0B,QAAQ,uCAAoC;AAC/E,SAASC,uBAAuB,QAAQ,gCAA6B;AACrE,SAASC,YAAY,QAAQ,8BAA2B;AACxD,SAASC,YAAY,QAAQ,8BAA2B;AAExD;;;;;;;;CAQC,GACD,OAAO,MAAMC,mBAAmB,CAACC,OAAkBC;IACjD,MAAM,EAAEC,aAAa,QAAQ,EAAEC,OAAO,QAAQ,EAAEC,cAAc,EAAE,GAAGC,WAAW,GAAGL;IACjF,uFAAuF;IACvF,MAAMM,QAAQC,gBAAgBF,WAAWJ,KAAKO;IAE9C,IAAIF,MAAMG,WAAW,KAAK,WAAW;QACnC,OAAO;YACL,GAAGH,KAAK;YACR,4DAA4D;YAC5DI,YAAY;gBAAE,GAAGJ,MAAMI,UAAU;gBAAEN,gBAAgBnB;YAAS;YAC5DmB,gBAAgBpB,mBAAmBoB,gBAAgB;gBACjDO,aAAa1B;gBACb2B,cAAc;oBACZC,SAASP,MAAMQ,IAAI;oBACnBC,eAAe;gBACjB;YACF;QACF;IACF;IAEA,OAAO;QACL,GAAGT,KAAK;QACRJ;QACAC;QACA,4DAA4D;QAC5DO,YAAY;YAAE,GAAGJ,MAAMI,UAAU;YAAEN,gBAAgBnB;QAAS;QAC5DmB,gBAAgBY;IAClB;AACF,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,MAAMC,uBAAuB,CAACjB,OAAsBC;IACzD,OAAOM,gBAAgBP,OAAOC,KAAKiB;AACrC,EAAE;AAEF,MAAMC,uBAA8C;IAClDC,oBAAoB3B;IACpBV,yBAAyBY;AAC3B;AAEA,MAAMuB,0BAA0B,IAA6BC;AAE7D,MAAMX,8BAA8B;IAClC,MAAM,EAAEY,kBAAkB,EAAE,GAAGtC;IAC/B,OAAO;QAAEsC;QAAoBrC;IAAwB;AACvD;AAEA,SAASwB,gBACPP,KAAoB,EACpBC,GAA2B,EAC3B,gGAAgG;AAChGoB,oBAAiD;IAEjD,MAAMC,SAAS3C,MAAM4C,UAAU,CAACjC,oBAAoB0B;IACpD,uDAAuD;IACvD,sEAAsE;IACtE,sDAAsD;IACtD,OAAOM,SAASE,kBAAkBxB,OAAOC,KAAKoB,wBAAwBI,iBAAiBzB,OAAOC;AAChG;AAEA,SAASuB,kBACPxB,KAAoB,EACpBC,GAA2B,EAC3BoB,oBAAiD;IAEjD,eAAe,qGAAqG;IAEpH,MAAM,CAACK,WAAWC,aAAa,GAAGxC,yBAAyBa;IAC3D,MAAM4B,eAAevC,sBAAsBW;IAC3C,MAAM6B,aAAanC,sBAAsBM,MAAM8B,cAAc,EAAET;IAE/D,OAAOU,OAAOC,MAAM,CAClBzC,YACE;QACE,GAAGS,KAAK;QACR0B;QACAE;QACAK,cAAcrD,iBAAiB,CAACsD,OAAOC;gBAErCnC;YADA,MAAMoC,gBAAgBlD,oBAAoBiD,MAAMT;aAChD1B,sBAAAA,MAAMiC,YAAY,cAAlBjC,0CAAAA,yBAAAA,OAAqBkC,OAAO;gBAC1B,GAAGC,IAAI;gBACPT,WAAW7B,aAAawC,yBAAyB,CAACD;YACpD;YACAT,aAAaS;QACf;QACAE,cAAc1D,iBAAiB,CAACsD,OAAOC;gBACrCnC;aAAAA,sBAAAA,MAAMsC,YAAY,cAAlBtC,0CAAAA,yBAAAA,OAAqBkC,OAAOC;YAC5B,IAAI,CAACD,MAAMK,kBAAkB,IAAI;gBAC/BV,WAAWW,QAAQ,CAACL,MAAM;oBACxBM,eAAeN,KAAKO,iBAAiB;gBACvC;YACF;QACF;QACAC,iBAAiB/D,iBAAiB,CAACsD,OAAOC;gBAExCnC;YADA,MAAM4C,mBAAmBxD,6BAA6B+C,MAAMP;aAC5D5B,yBAAAA,MAAM2C,eAAe,cAArB3C,6CAAAA,4BAAAA,OAAwBkC,OAAO;gBAC7B,GAAGC,IAAI;gBACPP,cAAc9B,aAAa+C,yBAAyB,CAACD;YACvD;QACF;IACF,GACA/D,cAAcoB,KAAK4B,WAAWiB,OAAO,IAEvC;QACEC,UAAU;QACVC,2BAA2BnB,WAAWmB,yBAAyB;IACjE;AAEJ;AAEA,SAASvB,iBAAiBzB,KAAoB,EAAEC,GAA2B;IACzE,IAAIgD,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QAC1C,qEAAqE;QACrE,sDAAsD;QACtD,MAAMJ,WAAWnD,wBAAwBwD,CAAAA,MAAOA,IAAIL,QAAQ;QAC5D,IAAIA,aAAa,QAAQ;YACvB,MAAM,IAAIM,MAA2B,CAAC;;mEAItC,CAAC;QACH;IACF;IACA,OAAO7D,WAAWQ,OAAOC;AAC3B"}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
export function useTreeContextValues_unstable(state) {
|
|
4
4
|
if (state.contextType === 'root') {
|
|
5
|
-
const { openItems, level, contextType, treeType, checkedItems, selectionMode, navigationMode,
|
|
5
|
+
const { openItems, level, contextType, treeType, checkedItems, selectionMode, navigationMode, requestTreeResponse, forceUpdateRovingTabIndex } = state;
|
|
6
|
+
// Base state carries no design props, the context falls back to the default design values.
|
|
7
|
+
const appearance = 'appearance' in state ? state.appearance : 'subtle';
|
|
8
|
+
const size = 'size' in state ? state.size : 'medium';
|
|
6
9
|
// contextType is statically determined by the context
|
|
7
10
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
8
11
|
const tree = React.useMemo(()=>({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Tree/useTreeContextValues.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { TreeContextValue } from '../../contexts';\nimport type { TreeContextValues, TreeState } from './Tree.types';\n\nexport function useTreeContextValues_unstable(state: TreeState): TreeContextValues {\n if (state.contextType === 'root') {\n const {\n openItems,\n level,\n contextType,\n treeType,\n checkedItems,\n selectionMode,\n navigationMode,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Tree/useTreeContextValues.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { TreeContextValue } from '../../contexts';\nimport type { TreeBaseState, TreeContextValues, TreeState } from './Tree.types';\n\nexport function useTreeContextValues_unstable(state: TreeState | TreeBaseState): TreeContextValues {\n if (state.contextType === 'root') {\n const {\n openItems,\n level,\n contextType,\n treeType,\n checkedItems,\n selectionMode,\n navigationMode,\n requestTreeResponse,\n forceUpdateRovingTabIndex,\n } = state;\n // Base state carries no design props, the context falls back to the default design values.\n const appearance = 'appearance' in state ? state.appearance : 'subtle';\n const size = 'size' in state ? state.size : 'medium';\n // contextType is statically determined by the context\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const tree = React.useMemo<TreeContextValue>(\n () => ({\n treeType,\n size,\n openItems,\n appearance,\n checkedItems,\n selectionMode,\n navigationMode,\n contextType,\n level,\n requestTreeResponse,\n forceUpdateRovingTabIndex,\n }),\n [\n treeType,\n size,\n openItems,\n appearance,\n checkedItems,\n selectionMode,\n navigationMode,\n contextType,\n level,\n requestTreeResponse,\n forceUpdateRovingTabIndex,\n ],\n );\n\n return { tree };\n }\n return {\n // contextType is statically determined by the context\n // eslint-disable-next-line react-hooks/rules-of-hooks\n tree: React.useMemo(() => ({ level: state.level, contextType: 'subtree' }), [state.level]),\n };\n}\n"],"names":["React","useTreeContextValues_unstable","state","contextType","openItems","level","treeType","checkedItems","selectionMode","navigationMode","requestTreeResponse","forceUpdateRovingTabIndex","appearance","size","tree","useMemo"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAI/B,OAAO,SAASC,8BAA8BC,KAAgC;IAC5E,IAAIA,MAAMC,WAAW,KAAK,QAAQ;QAChC,MAAM,EACJC,SAAS,EACTC,KAAK,EACLF,WAAW,EACXG,QAAQ,EACRC,YAAY,EACZC,aAAa,EACbC,cAAc,EACdC,mBAAmB,EACnBC,yBAAyB,EAC1B,GAAGT;QACJ,2FAA2F;QAC3F,MAAMU,aAAa,gBAAgBV,QAAQA,MAAMU,UAAU,GAAG;QAC9D,MAAMC,OAAO,UAAUX,QAAQA,MAAMW,IAAI,GAAG;QAC5C,sDAAsD;QACtD,sDAAsD;QACtD,MAAMC,OAAOd,MAAMe,OAAO,CACxB,IAAO,CAAA;gBACLT;gBACAO;gBACAT;gBACAQ;gBACAL;gBACAC;gBACAC;gBACAN;gBACAE;gBACAK;gBACAC;YACF,CAAA,GACA;YACEL;YACAO;YACAT;YACAQ;YACAL;YACAC;YACAC;YACAN;YACAE;YACAK;YACAC;SACD;QAGH,OAAO;YAAEG;QAAK;IAChB;IACA,OAAO;QACL,sDAAsD;QACtD,sDAAsD;QACtDA,MAAMd,MAAMe,OAAO,CAAC,IAAO,CAAA;gBAAEV,OAAOH,MAAMG,KAAK;gBAAEF,aAAa;YAAU,CAAA,GAAI;YAACD,MAAMG,KAAK;SAAC;IAC3F;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TreeItemLayout/TreeItemLayout.types.ts"],"sourcesContent":["import type * as React from 'react';\nimport type {\n Slot,\n ComponentProps,\n ComponentState,\n ExtractSlotProps,\n EventData,\n EventHandler,\n} from '@fluentui/react-utilities';\nimport type { ButtonContextValue } from '@fluentui/react-button';\nimport type { Checkbox } from '@fluentui/react-checkbox';\nimport type { Radio } from '@fluentui/react-radio';\n\nexport type TreeItemLayoutActionVisibilityChangeData = (\n | EventData<'mouseover' | 'mouseout', MouseEvent>\n | EventData<'focus' | 'blur', FocusEvent>\n | EventData<'blur', React.FocusEvent>\n) & { visible: boolean };\n\nexport type TreeItemLayoutActionSlotProps = ExtractSlotProps<\n Slot<'div'> & {\n /**\n * Forces visibility of the aside/action content\n */\n visible?: boolean;\n onVisibilityChange?: EventHandler<TreeItemLayoutActionVisibilityChangeData>;\n }\n>;\n\nexport type TreeItemLayoutSlots = {\n root: Slot<'div'>;\n /**\n * Content. Children of the root slot are automatically rendered here\n */\n main: NonNullable<Slot<'div'>>;\n /**\n * Icon slot that renders right before main content\n */\n iconBefore?: Slot<'div'>;\n /**\n * Icon slot that renders right after main content\n */\n iconAfter?: Slot<'div'>;\n /**\n * Expand icon slot,\n * by default renders a chevron icon to indicate opening and closing\n */\n expandIcon?: Slot<'div'>;\n /**\n * Aside content is normally used to render a badge or other non-actionable content\n */\n aside?: Slot<'div'>;\n /**\n * Actionable elements are normally buttons, menus, or other focusable elements.\n * Those elements are only visibly available if the given tree item is currently active.\n *\n * `actions` and `aside` slots are positioned on the exact same spot,\n * so they won't be visible at the same time.\n * `aside` slot is visible by default meanwhile `actions` slot are only visible when the tree item is active.\n *\n * `actions` slot supports a `visible` prop to force visibility of the actions.\n */\n actions?: Slot<TreeItemLayoutActionSlotProps>;\n selector?: Slot<typeof Checkbox> | Slot<typeof Radio>;\n};\n\n/**\n * TreeItemLayout Props\n */\nexport type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutSlots>>;\n\n/**\n * State used in rendering TreeItemLayout\n */\nexport type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots> & {\n buttonContextValue: ButtonContextValue;\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TreeItemLayout/TreeItemLayout.types.ts"],"sourcesContent":["import type * as React from 'react';\nimport type {\n Slot,\n ComponentProps,\n ComponentState,\n ExtractSlotProps,\n EventData,\n EventHandler,\n} from '@fluentui/react-utilities';\nimport type { ButtonContextValue } from '@fluentui/react-button';\nimport type { Checkbox } from '@fluentui/react-checkbox';\nimport type { Radio } from '@fluentui/react-radio';\n\nexport type TreeItemLayoutActionVisibilityChangeData = (\n | EventData<'mouseover' | 'mouseout', MouseEvent>\n | EventData<'focus' | 'blur', FocusEvent>\n | EventData<'blur', React.FocusEvent>\n) & { visible: boolean };\n\nexport type TreeItemLayoutActionSlotProps = ExtractSlotProps<\n Slot<'div'> & {\n /**\n * Forces visibility of the aside/action content\n */\n visible?: boolean;\n onVisibilityChange?: EventHandler<TreeItemLayoutActionVisibilityChangeData>;\n }\n>;\n\nexport type TreeItemLayoutSlots = {\n root: Slot<'div'>;\n /**\n * Content. Children of the root slot are automatically rendered here\n */\n main: NonNullable<Slot<'div'>>;\n /**\n * Icon slot that renders right before main content\n */\n iconBefore?: Slot<'div'>;\n /**\n * Icon slot that renders right after main content\n */\n iconAfter?: Slot<'div'>;\n /**\n * Expand icon slot,\n * by default renders a chevron icon to indicate opening and closing\n */\n expandIcon?: Slot<'div'>;\n /**\n * Aside content is normally used to render a badge or other non-actionable content\n */\n aside?: Slot<'div'>;\n /**\n * Actionable elements are normally buttons, menus, or other focusable elements.\n * Those elements are only visibly available if the given tree item is currently active.\n *\n * `actions` and `aside` slots are positioned on the exact same spot,\n * so they won't be visible at the same time.\n * `aside` slot is visible by default meanwhile `actions` slot are only visible when the tree item is active.\n *\n * `actions` slot supports a `visible` prop to force visibility of the actions.\n */\n actions?: Slot<TreeItemLayoutActionSlotProps>;\n selector?: Slot<typeof Checkbox> | Slot<typeof Radio>;\n};\n\n/**\n * TreeItemLayout Props\n */\nexport type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutSlots>>;\n\n/**\n * State used in rendering TreeItemLayout\n */\nexport type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots> & {\n buttonContextValue: ButtonContextValue;\n};\n\n/**\n * TreeItemLayout slots without any design dependency, used by `useTreeItemLayoutBase_unstable`.\n *\n * The selector renders as a native `input`, of type `checkbox` or `radio` depending on the tree selection mode.\n */\nexport type TreeItemLayoutBaseSlots = Omit<TreeItemLayoutSlots, 'selector'> & {\n selector?: Slot<'input'>;\n};\n\n/**\n * TreeItemLayout props accepted by `useTreeItemLayoutBase_unstable`.\n */\nexport type TreeItemLayoutBaseProps = ComponentProps<Partial<TreeItemLayoutBaseSlots>>;\n\n/**\n * State returned by `useTreeItemLayoutBase_unstable`.\n */\nexport type TreeItemLayoutBaseState = ComponentState<TreeItemLayoutBaseSlots>;\n"],"names":[],"mappings":"AA4FA;;CAEC,GACD,WAA8E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { TreeItemLayout } from "./TreeItemLayout.js";
|
|
2
2
|
export { renderTreeItemLayout_unstable } from "./renderTreeItemLayout.js";
|
|
3
|
-
export { useTreeItemLayout_unstable } from "./useTreeItemLayout.js";
|
|
3
|
+
export { useTreeItemLayoutBase_unstable, useTreeItemLayout_unstable } from "./useTreeItemLayout.js";
|
|
4
4
|
export { treeItemLayoutClassNames, useTreeItemLayoutStyles_unstable } from "./useTreeItemLayoutStyles.styles.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TreeItemLayout/index.ts"],"sourcesContent":["export { TreeItemLayout } from './TreeItemLayout';\nexport type {\n TreeItemLayoutActionSlotProps,\n TreeItemLayoutActionVisibilityChangeData,\n TreeItemLayoutProps,\n TreeItemLayoutSlots,\n TreeItemLayoutState,\n} from './TreeItemLayout.types';\nexport { renderTreeItemLayout_unstable } from './renderTreeItemLayout';\nexport { useTreeItemLayout_unstable } from './useTreeItemLayout';\nexport { treeItemLayoutClassNames, useTreeItemLayoutStyles_unstable } from './useTreeItemLayoutStyles.styles';\n"],"names":["TreeItemLayout","renderTreeItemLayout_unstable","useTreeItemLayout_unstable","treeItemLayoutClassNames","useTreeItemLayoutStyles_unstable"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TreeItemLayout/index.ts"],"sourcesContent":["export { TreeItemLayout } from './TreeItemLayout';\nexport type {\n TreeItemLayoutActionSlotProps,\n TreeItemLayoutActionVisibilityChangeData,\n TreeItemLayoutBaseProps,\n TreeItemLayoutBaseSlots,\n TreeItemLayoutBaseState,\n TreeItemLayoutProps,\n TreeItemLayoutSlots,\n TreeItemLayoutState,\n} from './TreeItemLayout.types';\nexport { renderTreeItemLayout_unstable } from './renderTreeItemLayout';\nexport { useTreeItemLayoutBase_unstable, useTreeItemLayout_unstable } from './useTreeItemLayout';\nexport { treeItemLayoutClassNames, useTreeItemLayoutStyles_unstable } from './useTreeItemLayoutStyles.styles';\n"],"names":["TreeItemLayout","renderTreeItemLayout_unstable","useTreeItemLayoutBase_unstable","useTreeItemLayout_unstable","treeItemLayoutClassNames","useTreeItemLayoutStyles_unstable"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAmB;AAWlD,SAASC,6BAA6B,QAAQ,4BAAyB;AACvE,SAASC,8BAA8B,EAAEC,0BAA0B,QAAQ,yBAAsB;AACjG,SAASC,wBAAwB,EAAEC,gCAAgC,QAAQ,sCAAmC"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@fluentui/react-jsx-runtime/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@fluentui/react-jsx-runtime/jsx-runtime";
|
|
2
2
|
import { assertSlots } from "@fluentui/react-utilities";
|
|
3
3
|
import { ButtonContextProvider } from "@fluentui/react-button";
|
|
4
4
|
/**
|
|
5
5
|
* Render the final JSX of TreeItemLayout
|
|
6
|
+
*
|
|
7
|
+
* The button context is only provided when the state carries one, which is not the case for the
|
|
8
|
+
* state produced by `useTreeItemLayoutBase_unstable`.
|
|
6
9
|
*/ export const renderTreeItemLayout_unstable = (state)=>{
|
|
7
10
|
assertSlots(state);
|
|
11
|
+
const actionsAndAside = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
12
|
+
children: [
|
|
13
|
+
state.actions && /*#__PURE__*/ _jsx(state.actions, {}),
|
|
14
|
+
state.aside && /*#__PURE__*/ _jsx(state.aside, {})
|
|
15
|
+
]
|
|
16
|
+
});
|
|
8
17
|
return /*#__PURE__*/ _jsxs(state.root, {
|
|
9
18
|
children: [
|
|
10
19
|
state.expandIcon && /*#__PURE__*/ _jsx(state.expandIcon, {}),
|
|
@@ -14,13 +23,10 @@ import { ButtonContextProvider } from "@fluentui/react-button";
|
|
|
14
23
|
children: state.root.children
|
|
15
24
|
}),
|
|
16
25
|
state.iconAfter && /*#__PURE__*/ _jsx(state.iconAfter, {}),
|
|
17
|
-
/*#__PURE__*/
|
|
26
|
+
'buttonContextValue' in state ? /*#__PURE__*/ _jsx(ButtonContextProvider, {
|
|
18
27
|
value: state.buttonContextValue,
|
|
19
|
-
children:
|
|
20
|
-
|
|
21
|
-
state.aside && /*#__PURE__*/ _jsx(state.aside, {})
|
|
22
|
-
]
|
|
23
|
-
})
|
|
28
|
+
children: actionsAndAside
|
|
29
|
+
}) : actionsAndAside
|
|
24
30
|
]
|
|
25
31
|
});
|
|
26
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TreeItemLayout/renderTreeItemLayout.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutState, TreeItemLayoutSlots } from './TreeItemLayout.types';\nimport { ButtonContextProvider } from '@fluentui/react-button';\n\n/**\n * Render the final JSX of TreeItemLayout\n */\nexport const renderTreeItemLayout_unstable = (state: TreeItemLayoutState): JSXElement => {\n assertSlots<TreeItemLayoutSlots>(state);\n\n return (\n <state.root>\n {state.expandIcon && <state.expandIcon />}\n {state.selector && <state.selector />}\n {state.iconBefore && <state.iconBefore />}\n <state.main>{state.root.children}</state.main>\n {state.iconAfter && <state.iconAfter />}\n <ButtonContextProvider value={state.buttonContextValue}>\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TreeItemLayout/renderTreeItemLayout.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutBaseState, TreeItemLayoutState, TreeItemLayoutSlots } from './TreeItemLayout.types';\nimport { ButtonContextProvider } from '@fluentui/react-button';\n\n/**\n * Render the final JSX of TreeItemLayout\n *\n * The button context is only provided when the state carries one, which is not the case for the\n * state produced by `useTreeItemLayoutBase_unstable`.\n */\nexport const renderTreeItemLayout_unstable = (state: TreeItemLayoutState | TreeItemLayoutBaseState): JSXElement => {\n assertSlots<TreeItemLayoutSlots>(state);\n\n const actionsAndAside = (\n <>\n {state.actions && <state.actions />}\n {state.aside && <state.aside />}\n </>\n );\n\n return (\n <state.root>\n {state.expandIcon && <state.expandIcon />}\n {state.selector && <state.selector />}\n {state.iconBefore && <state.iconBefore />}\n <state.main>{state.root.children}</state.main>\n {state.iconAfter && <state.iconAfter />}\n {'buttonContextValue' in state ? (\n <ButtonContextProvider value={state.buttonContextValue}>{actionsAndAside}</ButtonContextProvider>\n ) : (\n actionsAndAside\n )}\n </state.root>\n );\n};\n"],"names":["assertSlots","ButtonContextProvider","renderTreeItemLayout_unstable","state","actionsAndAside","actions","aside","root","expandIcon","selector","iconBefore","main","children","iconAfter","value","buttonContextValue"],"mappings":";AAAA,0BAA0B,GAC1B,iDAAiD,GACjD,SAASA,WAAW,QAAQ,4BAA4B;AAGxD,SAASC,qBAAqB,QAAQ,yBAAyB;AAE/D;;;;;CAKC,GACD,OAAO,MAAMC,gCAAgC,CAACC;IAC5CH,YAAiCG;IAEjC,MAAMC,gCACJ;;YACGD,MAAME,OAAO,kBAAI,KAACF,MAAME,OAAO;YAC/BF,MAAMG,KAAK,kBAAI,KAACH,MAAMG,KAAK;;;IAIhC,qBACE,MAACH,MAAMI,IAAI;;YACRJ,MAAMK,UAAU,kBAAI,KAACL,MAAMK,UAAU;YACrCL,MAAMM,QAAQ,kBAAI,KAACN,MAAMM,QAAQ;YACjCN,MAAMO,UAAU,kBAAI,KAACP,MAAMO,UAAU;0BACtC,KAACP,MAAMQ,IAAI;0BAAER,MAAMI,IAAI,CAACK,QAAQ;;YAC/BT,MAAMU,SAAS,kBAAI,KAACV,MAAMU,SAAS;YACnC,wBAAwBV,sBACvB,KAACF;gBAAsBa,OAAOX,MAAMY,kBAAkB;0BAAGX;iBAEzDA;;;AAIR,EAAE"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { getIntrinsicElementProps, isResolvedShorthand, useMergedRefs, slot, useEventCallback, elementContains, useControllableState, useId } from "@fluentui/react-utilities";
|
|
3
|
+
import { getIntrinsicElementProps, isResolvedShorthand, useMergedRefs, slot, useEventCallback, elementContains, useControllableState, useId, useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
|
|
4
4
|
import { useTreeItemContext_unstable, useTreeContext_unstable } from "../../contexts/index.js";
|
|
5
5
|
import { Checkbox } from "@fluentui/react-checkbox";
|
|
6
6
|
import { Radio } from "@fluentui/react-radio";
|
|
7
7
|
import { TreeItemChevron } from "../TreeItemChevron.js";
|
|
8
8
|
import { useArrowNavigationGroup, useIsNavigatingWithKeyboard } from "@fluentui/react-tabster";
|
|
9
9
|
import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts";
|
|
10
|
+
import { registerTreeItemActions } from "../../utils/queryTreeItemActions.js";
|
|
10
11
|
/**
|
|
11
12
|
* Create the state required to render TreeItemLayout.
|
|
12
13
|
*
|
|
@@ -16,13 +17,100 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
16
17
|
* @param props - props from this instance of TreeItemLayout
|
|
17
18
|
* @param ref - reference to root HTMLElement of TreeItemLayout
|
|
18
19
|
*/ export const useTreeItemLayout_unstable = (props, ref)=>{
|
|
19
|
-
const {
|
|
20
|
-
const
|
|
20
|
+
const { selector: selectorProp, ...baseProps } = props;
|
|
21
|
+
const isNavigatingWithKeyboard = useIsNavigatingWithKeyboard();
|
|
22
|
+
const { targetDocument } = useFluent();
|
|
23
|
+
const state = useTreeItemLayoutBase(// The base hook only needs to know whether the consumer provided or disabled the selector,
|
|
24
|
+
// the Fluent selector itself is resolved below.
|
|
25
|
+
{
|
|
26
|
+
...baseProps,
|
|
27
|
+
selector: selectorProp === undefined || selectorProp === null ? selectorProp : {}
|
|
28
|
+
}, ref, targetDocument, isNavigatingWithKeyboard);
|
|
21
29
|
const selectionMode = useTreeContext_unstable((ctx)=>ctx.selectionMode);
|
|
22
30
|
const navigationMode = useTreeContext_unstable((ctx)=>{
|
|
23
31
|
var _ctx_navigationMode;
|
|
24
32
|
return (_ctx_navigationMode = ctx.navigationMode) !== null && _ctx_navigationMode !== void 0 ? _ctx_navigationMode : 'tree';
|
|
25
33
|
});
|
|
34
|
+
const selectionRef = useTreeItemContext_unstable((ctx)=>ctx.selectionRef);
|
|
35
|
+
const checked = useTreeItemContext_unstable((ctx)=>ctx.checked);
|
|
36
|
+
const expandIconRef = useTreeItemContext_unstable((ctx)=>ctx.expandIconRef);
|
|
37
|
+
// Link the selector to the main content unless the consumer provided an accessible name
|
|
38
|
+
const selectorShorthand = isResolvedShorthand(selectorProp) ? selectorProp : undefined;
|
|
39
|
+
const selectorAriaLabelledBy = (selectorShorthand === null || selectorShorthand === void 0 ? void 0 : selectorShorthand['aria-label']) || (selectorShorthand === null || selectorShorthand === void 0 ? void 0 : selectorShorthand['aria-labelledby']) ? undefined : state.main.id;
|
|
40
|
+
const selector = slot.optional(selectorProp, {
|
|
41
|
+
renderByDefault: selectionMode !== 'none',
|
|
42
|
+
defaultProps: {
|
|
43
|
+
checked,
|
|
44
|
+
tabIndex: -1,
|
|
45
|
+
ref: selectionRef,
|
|
46
|
+
'aria-labelledby': selectorAriaLabelledBy
|
|
47
|
+
},
|
|
48
|
+
elementType: selectionMode === 'multiselect' ? Checkbox : Radio
|
|
49
|
+
});
|
|
50
|
+
// Checkbox and Radio slot props omit `ref` from their type, but consumers can still provide it.
|
|
51
|
+
const selectorConsumerRef = selector && selector.ref;
|
|
52
|
+
const selectorRef = useMergedRefs(selectorConsumerRef, selectionRef);
|
|
53
|
+
const selectorWithRef = selector && {
|
|
54
|
+
...selector,
|
|
55
|
+
ref: selectorRef
|
|
56
|
+
};
|
|
57
|
+
const arrowNavigationProps = useArrowNavigationGroup({
|
|
58
|
+
circular: navigationMode === 'tree',
|
|
59
|
+
axis: 'horizontal'
|
|
60
|
+
});
|
|
61
|
+
const expandIcon = state.expandIcon ? slot.optional(props.expandIcon, {
|
|
62
|
+
renderByDefault: true,
|
|
63
|
+
defaultProps: {
|
|
64
|
+
'aria-hidden': true,
|
|
65
|
+
children: /*#__PURE__*/ React.createElement(TreeItemChevron, null),
|
|
66
|
+
ref: expandIconRef
|
|
67
|
+
},
|
|
68
|
+
elementType: 'div'
|
|
69
|
+
}) : undefined;
|
|
70
|
+
const expandIconRefWithConsumer = useMergedRefs(expandIcon === null || expandIcon === void 0 ? void 0 : expandIcon.ref, expandIconRef);
|
|
71
|
+
const expandIconWithRef = expandIcon && {
|
|
72
|
+
...expandIcon,
|
|
73
|
+
ref: expandIconRefWithConsumer
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
...state,
|
|
77
|
+
components: {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
79
|
+
...state.components,
|
|
80
|
+
// Casting here to a union between checkbox and radio
|
|
81
|
+
selector: selectionMode === 'multiselect' ? Checkbox : Radio
|
|
82
|
+
},
|
|
83
|
+
buttonContextValue: {
|
|
84
|
+
size: 'small'
|
|
85
|
+
},
|
|
86
|
+
// Consumer props keep winning over the navigation attributes, matching the base slot ordering.
|
|
87
|
+
actions: state.actions && {
|
|
88
|
+
...arrowNavigationProps,
|
|
89
|
+
...state.actions
|
|
90
|
+
},
|
|
91
|
+
expandIcon: expandIconWithRef,
|
|
92
|
+
selector: selectorWithRef
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Base state hook for TreeItemLayout, free of any focus management runtime and of the Fluent
|
|
97
|
+
* components used for the selector, the expand icon and the actions.
|
|
98
|
+
*
|
|
99
|
+
* The selector slot is rendered as a native `input`, of type `checkbox` in multiselect mode and
|
|
100
|
+
* `radio` in single selection mode, the expand icon has no default content, and the Tabster driven
|
|
101
|
+
* arrow key navigation of the actions is layered on by the wrapping `useTreeItemLayout_unstable` hook.
|
|
102
|
+
*
|
|
103
|
+
* @param props - props from this instance of TreeItemLayout
|
|
104
|
+
* @param ref - reference to root HTMLElement of TreeItemLayout
|
|
105
|
+
*/ export const useTreeItemLayoutBase_unstable = (props, ref)=>{
|
|
106
|
+
const { targetDocument } = useFluent();
|
|
107
|
+
const isNavigatingWithKeyboard = useDOMKeyboardNavigation(targetDocument, Boolean(props.actions));
|
|
108
|
+
return useTreeItemLayoutBase(props, ref, targetDocument, isNavigatingWithKeyboard);
|
|
109
|
+
};
|
|
110
|
+
function useTreeItemLayoutBase(props, ref, targetDocument, isNavigatingWithKeyboard) {
|
|
111
|
+
const { main, iconAfter, iconBefore } = props;
|
|
112
|
+
const layoutRef = useTreeItemContext_unstable((ctx)=>ctx.layoutRef);
|
|
113
|
+
const selectionMode = useTreeContext_unstable((ctx)=>ctx.selectionMode);
|
|
26
114
|
const [isActionsVisibleFromProps, onActionVisibilityChange] = isResolvedShorthand(props.actions) ? [
|
|
27
115
|
props.actions.visible,
|
|
28
116
|
props.actions.onVisibilityChange
|
|
@@ -47,16 +135,37 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
47
135
|
// Link the selector to the main content unless the consumer provided an accessible name
|
|
48
136
|
const selectorShorthand = isResolvedShorthand(props.selector) ? props.selector : undefined;
|
|
49
137
|
const selectorAriaLabelledBy = (selectorShorthand === null || selectorShorthand === void 0 ? void 0 : selectorShorthand['aria-label']) || (selectorShorthand === null || selectorShorthand === void 0 ? void 0 : selectorShorthand['aria-labelledby']) ? undefined : mainContentId;
|
|
50
|
-
|
|
138
|
+
// The mixed state of a native checkbox can only be set through its `indeterminate` DOM property.
|
|
139
|
+
const selectorInputRef = React.useRef(null);
|
|
140
|
+
useIsomorphicLayoutEffect(()=>{
|
|
141
|
+
if (selectorInputRef.current) {
|
|
142
|
+
selectorInputRef.current.indeterminate = checked === 'mixed';
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const selectorSlot = slot.optional(props.selector, {
|
|
51
146
|
renderByDefault: selectionMode !== 'none',
|
|
52
147
|
defaultProps: {
|
|
53
|
-
|
|
148
|
+
type: selectionMode === 'multiselect' ? 'checkbox' : 'radio',
|
|
149
|
+
checked: checked === true,
|
|
54
150
|
tabIndex: -1,
|
|
55
|
-
|
|
56
|
-
|
|
151
|
+
'aria-labelledby': selectorAriaLabelledBy,
|
|
152
|
+
// Changes bubble up to the tree item, which owns the selection state.
|
|
153
|
+
onChange: noop
|
|
57
154
|
},
|
|
58
|
-
elementType:
|
|
155
|
+
elementType: 'input'
|
|
59
156
|
});
|
|
157
|
+
const selectorRef = useMergedRefs(selectorSlot === null || selectorSlot === void 0 ? void 0 : selectorSlot.ref, selectionRef, selectorInputRef);
|
|
158
|
+
// Clicking a native checkbox clears `indeterminate`, which no commit restores if the change is rejected
|
|
159
|
+
const handleSelectorChange = useEventCallback((event)=>{
|
|
160
|
+
var _selectorSlot_onChange;
|
|
161
|
+
selectorSlot === null || selectorSlot === void 0 ? void 0 : (_selectorSlot_onChange = selectorSlot.onChange) === null || _selectorSlot_onChange === void 0 ? void 0 : _selectorSlot_onChange.call(selectorSlot, event);
|
|
162
|
+
event.currentTarget.indeterminate = checked === 'mixed';
|
|
163
|
+
});
|
|
164
|
+
const selector = selectorSlot && {
|
|
165
|
+
...selectorSlot,
|
|
166
|
+
ref: selectorRef,
|
|
167
|
+
onChange: handleSelectorChange
|
|
168
|
+
};
|
|
60
169
|
const mainSlot = slot.always(main, {
|
|
61
170
|
defaultProps: {
|
|
62
171
|
id: selector ? mainContentId : undefined
|
|
@@ -87,8 +196,7 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
87
196
|
setIsActionsVisible,
|
|
88
197
|
onActionVisibilityChange
|
|
89
198
|
]);
|
|
90
|
-
const
|
|
91
|
-
const isNavigatingWithKeyboard = useIsNavigatingWithKeyboard();
|
|
199
|
+
const hasActions = Boolean(props.actions);
|
|
92
200
|
const setActionsInvisibleIfNotFromSubtree = React.useCallback((event)=>{
|
|
93
201
|
const isRelatedTargetFromActions = ()=>Boolean(actionsRefInternal.current && elementContains(actionsRefInternal.current, event.relatedTarget));
|
|
94
202
|
const isRelatedTargetFromTreeItem = ()=>Boolean(treeItemRef.current && elementContains(treeItemRef.current, event.relatedTarget));
|
|
@@ -133,20 +241,18 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
133
241
|
isNavigatingWithKeyboard,
|
|
134
242
|
targetDocument
|
|
135
243
|
]);
|
|
136
|
-
const
|
|
137
|
-
const expandIcon = slot.optional(props.expandIcon, {
|
|
244
|
+
const expandIconSlot = slot.optional(props.expandIcon, {
|
|
138
245
|
renderByDefault: isBranch,
|
|
139
246
|
defaultProps: {
|
|
140
|
-
|
|
141
|
-
'aria-hidden': true,
|
|
142
|
-
ref: expandIconRefs
|
|
247
|
+
'aria-hidden': true
|
|
143
248
|
},
|
|
144
249
|
elementType: 'div'
|
|
145
250
|
});
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
251
|
+
const expandIconRefs = useMergedRefs(expandIconSlot === null || expandIconSlot === void 0 ? void 0 : expandIconSlot.ref, expandIconRef);
|
|
252
|
+
const expandIcon = expandIconSlot && {
|
|
253
|
+
...expandIconSlot,
|
|
254
|
+
ref: expandIconRefs
|
|
255
|
+
};
|
|
150
256
|
const handleActionsBlur = useEventCallback((event)=>{
|
|
151
257
|
if (isResolvedShorthand(props.actions)) {
|
|
152
258
|
var _props_actions_onBlur, _props_actions;
|
|
@@ -160,17 +266,24 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
160
266
|
});
|
|
161
267
|
setIsActionsVisible(isRelatedTargetFromActions);
|
|
162
268
|
});
|
|
163
|
-
const
|
|
164
|
-
const actions = isActionsVisible ? slot.optional(props.actions, {
|
|
269
|
+
const actionsSlot = isActionsVisible ? slot.optional(props.actions, {
|
|
165
270
|
defaultProps: {
|
|
166
|
-
...arrowNavigationProps,
|
|
167
271
|
role: 'toolbar',
|
|
168
|
-
ref: actionsRefs,
|
|
169
272
|
onBlur: handleActionsBlur
|
|
170
273
|
},
|
|
171
274
|
elementType: 'div'
|
|
172
275
|
}) : undefined;
|
|
173
|
-
|
|
276
|
+
// The internal refs are merged after slot resolution, so that a consumer provided ref does not override them
|
|
277
|
+
const actionsRefs = useMergedRefs(actionsSlot === null || actionsSlot === void 0 ? void 0 : actionsSlot.ref, actionsRef, actionsRefInternal, registerTreeItemActions);
|
|
278
|
+
const actions = actionsSlot && {
|
|
279
|
+
...actionsSlot,
|
|
280
|
+
ref: actionsRefs
|
|
281
|
+
};
|
|
282
|
+
if (actions) {
|
|
283
|
+
// .visible .onVisibilityChange are consumed above and should not be propagated to the DOM
|
|
284
|
+
delete actions.visible;
|
|
285
|
+
delete actions.onVisibilityChange;
|
|
286
|
+
}
|
|
174
287
|
React.useEffect(()=>{
|
|
175
288
|
if (treeItemRef.current && hasActions) {
|
|
176
289
|
const treeItemElement = treeItemRef.current;
|
|
@@ -204,11 +317,7 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
204
317
|
iconAfter: 'div',
|
|
205
318
|
actions: 'div',
|
|
206
319
|
aside: 'div',
|
|
207
|
-
|
|
208
|
-
selector: selectionMode === 'multiselect' ? Checkbox : Radio
|
|
209
|
-
},
|
|
210
|
-
buttonContextValue: {
|
|
211
|
-
size: 'small'
|
|
320
|
+
selector: 'input'
|
|
212
321
|
},
|
|
213
322
|
root: slot.always(getIntrinsicElementProps('div', {
|
|
214
323
|
...props,
|
|
@@ -233,7 +342,69 @@ import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts
|
|
|
233
342
|
expandIcon,
|
|
234
343
|
selector
|
|
235
344
|
};
|
|
236
|
-
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Keyboard modality trackers shared by every base layout of a document, so that the number of
|
|
348
|
+
* document listeners does not grow with the number of mounted tree items.
|
|
349
|
+
*/ const domKeyboardNavigationTrackers = new WeakMap();
|
|
350
|
+
// Only pointer activation switches the modality, so that hovering does not discard keyboard focus
|
|
351
|
+
const DOM_POINTER_EVENTS = [
|
|
352
|
+
'pointerdown',
|
|
353
|
+
'mousedown',
|
|
354
|
+
'touchstart'
|
|
355
|
+
];
|
|
356
|
+
function subscribeToDOMKeyboardNavigation(targetDocument) {
|
|
357
|
+
let tracker = domKeyboardNavigationTrackers.get(targetDocument);
|
|
358
|
+
if (!tracker) {
|
|
359
|
+
const onKeyDown = ()=>{
|
|
360
|
+
state.isNavigatingWithKeyboard = true;
|
|
361
|
+
};
|
|
362
|
+
const onPointerInteraction = ()=>{
|
|
363
|
+
state.isNavigatingWithKeyboard = false;
|
|
364
|
+
};
|
|
365
|
+
const state = {
|
|
366
|
+
isNavigatingWithKeyboard: false,
|
|
367
|
+
subscribers: 0,
|
|
368
|
+
dispose: ()=>{
|
|
369
|
+
targetDocument.removeEventListener('keydown', onKeyDown, true);
|
|
370
|
+
DOM_POINTER_EVENTS.forEach((type)=>targetDocument.removeEventListener(type, onPointerInteraction, true));
|
|
371
|
+
domKeyboardNavigationTrackers.delete(targetDocument);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
targetDocument.addEventListener('keydown', onKeyDown, true);
|
|
375
|
+
DOM_POINTER_EVENTS.forEach((type)=>targetDocument.addEventListener(type, onPointerInteraction, true));
|
|
376
|
+
domKeyboardNavigationTrackers.set(targetDocument, state);
|
|
377
|
+
tracker = state;
|
|
378
|
+
}
|
|
379
|
+
tracker.subscribers++;
|
|
380
|
+
return tracker;
|
|
381
|
+
}
|
|
382
|
+
function useDOMKeyboardNavigation(targetDocument, enabled) {
|
|
383
|
+
const trackerRef = React.useRef(null);
|
|
384
|
+
React.useEffect(()=>{
|
|
385
|
+
if (!targetDocument || !enabled) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const tracker = subscribeToDOMKeyboardNavigation(targetDocument);
|
|
389
|
+
trackerRef.current = tracker;
|
|
390
|
+
return ()=>{
|
|
391
|
+
trackerRef.current = null;
|
|
392
|
+
if (--tracker.subscribers === 0) {
|
|
393
|
+
tracker.dispose();
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}, [
|
|
397
|
+
targetDocument,
|
|
398
|
+
enabled
|
|
399
|
+
]);
|
|
400
|
+
return React.useCallback(()=>{
|
|
401
|
+
var _ref;
|
|
402
|
+
var _trackerRef_current;
|
|
403
|
+
return (_ref = (_trackerRef_current = trackerRef.current) === null || _trackerRef_current === void 0 ? void 0 : _trackerRef_current.isNavigatingWithKeyboard) !== null && _ref !== void 0 ? _ref : false;
|
|
404
|
+
}, []);
|
|
405
|
+
}
|
|
406
|
+
function noop() {
|
|
407
|
+
/* noop */ }
|
|
237
408
|
function assertIsRefObject(ref) {
|
|
238
409
|
if (process.env.NODE_ENV !== 'production') {
|
|
239
410
|
if (typeof ref !== 'object' || ref === null || !('current' in ref)) {
|