@fluentui/react-tree 9.0.0-beta.24 → 9.0.0-beta.25
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.json +46 -1
- package/CHANGELOG.md +16 -2
- package/dist/index.d.ts +75 -49
- package/lib/components/Tree/Tree.types.js +1 -1
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/useRootTree.js +55 -73
- package/lib/components/Tree/useRootTree.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.types.js.map +1 -1
- package/lib/components/TreeItem/renderTreeItem.js +4 -2
- package/lib/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItem.js +58 -16
- package/lib/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItemContextValues.js +13 -6
- package/lib/components/TreeItem/useTreeItemContextValues.js.map +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js.map +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +7 -28
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.types.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js.map +1 -1
- package/lib/contexts/index.js +1 -0
- package/lib/contexts/index.js.map +1 -1
- package/lib/contexts/treeContext.js +2 -2
- package/lib/contexts/treeContext.js.map +1 -1
- package/lib/contexts/treeItemContext.js +0 -4
- package/lib/contexts/treeItemContext.js.map +1 -1
- package/lib/contexts/treeItemSlotsContext.js +9 -0
- package/lib/contexts/treeItemSlotsContext.js.map +1 -0
- package/lib/hooks/index.js +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableOpenItems.js +25 -0
- package/lib/hooks/useControllableOpenItems.js.map +1 -0
- package/lib/hooks/useFlatTree.js +3 -3
- package/lib/hooks/useFlatTree.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/ImmutableSet.js +16 -9
- package/lib/utils/ImmutableSet.js.map +1 -1
- package/lib/utils/createFlatTreeItems.js.map +1 -1
- package/lib/utils/flattenTree.js +0 -5
- package/lib/utils/flattenTree.js.map +1 -1
- package/lib-commonjs/components/Tree/Tree.types.js +0 -2
- package/lib-commonjs/components/Tree/Tree.types.js.map +1 -1
- package/lib-commonjs/components/Tree/useRootTree.js +54 -72
- package/lib-commonjs/components/Tree/useRootTree.js.map +1 -1
- package/lib-commonjs/components/TreeItem/renderTreeItem.js +3 -1
- package/lib-commonjs/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItem.js +57 -15
- package/lib-commonjs/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js +14 -6
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js +6 -26
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib-commonjs/contexts/index.js +1 -0
- package/lib-commonjs/contexts/index.js.map +1 -1
- package/lib-commonjs/contexts/treeContext.js +1 -1
- package/lib-commonjs/contexts/treeContext.js.map +1 -1
- package/lib-commonjs/contexts/treeItemContext.js +0 -4
- package/lib-commonjs/contexts/treeItemContext.js.map +1 -1
- package/lib-commonjs/contexts/treeItemSlotsContext.js +25 -0
- package/lib-commonjs/contexts/treeItemSlotsContext.js.map +1 -0
- package/lib-commonjs/hooks/index.js +1 -1
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/{useOpenItemsState.js → useControllableOpenItems.js} +15 -14
- package/lib-commonjs/hooks/useControllableOpenItems.js.map +1 -0
- package/lib-commonjs/hooks/useFlatTree.js +3 -3
- package/lib-commonjs/hooks/useFlatTree.js.map +1 -1
- package/lib-commonjs/utils/ImmutableSet.js +21 -16
- package/lib-commonjs/utils/ImmutableSet.js.map +1 -1
- package/lib-commonjs/utils/flattenTree.js +0 -5
- package/lib-commonjs/utils/flattenTree.js.map +1 -1
- package/package.json +5 -5
- package/lib/hooks/useOpenItemsState.js +0 -28
- package/lib/hooks/useOpenItemsState.js.map +0 -1
- package/lib-commonjs/hooks/useOpenItemsState.js.map +0 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/** @jsxRuntime classic */ /** @jsx createElement */ import { createElement } from '@fluentui/react-jsx-runtime';
|
|
2
2
|
import { getSlotsNext } from '@fluentui/react-utilities';
|
|
3
|
-
import { TreeItemProvider } from '../../contexts';
|
|
3
|
+
import { TreeItemProvider, TreeItemSlotsProvider } from '../../contexts';
|
|
4
4
|
/**
|
|
5
5
|
* Render the final JSX of TreeItem
|
|
6
6
|
*/ export const renderTreeItem_unstable = (state, contextValues)=>{
|
|
7
7
|
const { slots , slotProps } = getSlotsNext(state);
|
|
8
8
|
return /*#__PURE__*/ createElement(slots.root, slotProps.root, /*#__PURE__*/ createElement(TreeItemProvider, {
|
|
9
9
|
value: contextValues.treeItem
|
|
10
|
-
},
|
|
10
|
+
}, /*#__PURE__*/ createElement(TreeItemSlotsProvider, {
|
|
11
|
+
value: contextValues.treeItemSlots
|
|
12
|
+
}, slotProps.root.children)));
|
|
11
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["renderTreeItem.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeItemState,
|
|
1
|
+
{"version":3,"sources":["renderTreeItem.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeItemState, TreeItemContextValues, TreeItemInternalSlot } from './TreeItem.types';\nimport { TreeItemProvider, TreeItemSlotsProvider } from '../../contexts';\n\n/**\n * Render the final JSX of TreeItem\n */\nexport const renderTreeItem_unstable = (state: TreeItemState, contextValues: TreeItemContextValues) => {\n const { slots, slotProps } = getSlotsNext<TreeItemInternalSlot>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <TreeItemProvider value={contextValues.treeItem}>\n <TreeItemSlotsProvider value={contextValues.treeItemSlots}>{slotProps.root.children}</TreeItemSlotsProvider>\n </TreeItemProvider>\n </slots.root>\n );\n};\n"],"names":["createElement","getSlotsNext","TreeItemProvider","TreeItemSlotsProvider","renderTreeItem_unstable","state","contextValues","slots","slotProps","root","value","treeItem","treeItemSlots","children"],"mappings":"AAAA,wBAAwB,GACxB,uBAAuB,GAEvB,SAASA,aAAa,QAAQ,8BAA8B;AAC5D,SAASC,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,gBAAgB,EAAEC,qBAAqB,QAAQ,iBAAiB;AAEzE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC,gBAAyC;IACrG,MAAM,EAAEC,MAAK,EAAEC,UAAS,EAAE,GAAGP,aAAmCI;IAEhE,qBACE,AAdJ,cAcKE,MAAME,IAAI,EAAKD,UAAUC,IAAI,gBAC5B,AAfN,cAeOP;QAAiBQ,OAAOJ,cAAcK,QAAQ;qBAC7C,AAhBR,cAgBSR;QAAsBO,OAAOJ,cAAcM,aAAa;OAAGJ,UAAUC,IAAI,CAACI,QAAQ;AAI3F,EAAE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { getNativeElementProps, useId, useMergedRefs } from '@fluentui/react-utilities';
|
|
2
|
+
import { getNativeElementProps, isResolvedShorthand, resolveShorthand, useControllableState, useId, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
3
|
import { useEventCallback } from '@fluentui/react-utilities';
|
|
4
4
|
import { elementContains } from '@fluentui/react-portal';
|
|
5
5
|
import { useTreeContext_unstable } from '../../contexts/index';
|
|
6
6
|
import { treeDataTypes } from '../../utils/tokens';
|
|
7
7
|
import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';
|
|
8
|
+
import { TreeItemChevron } from '../TreeItemChevron';
|
|
8
9
|
/**
|
|
9
10
|
* Create the state required to render TreeItem.
|
|
10
11
|
*
|
|
@@ -17,18 +18,34 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
17
18
|
var _props_value;
|
|
18
19
|
const contextLevel = useTreeContext_unstable((ctx)=>ctx.level);
|
|
19
20
|
const value = useId('fuiTreeItemValue-', (_props_value = props.value) === null || _props_value === void 0 ? void 0 : _props_value.toString());
|
|
20
|
-
const { onClick , onKeyDown , as ='div' , itemType ='leaf' , 'aria-level': level = contextLevel , ...rest } = props;
|
|
21
|
+
const { onClick , onKeyDown , as ='div' , itemType ='leaf' , 'aria-level': level = contextLevel , expandIcon , aside , ...rest } = props;
|
|
21
22
|
const requestTreeResponse = useTreeContext_unstable((ctx)=>ctx.requestTreeResponse);
|
|
22
|
-
const [
|
|
23
|
+
const [isActionsVisibleExternal, actions] = isResolvedShorthand(props.actions) ? [
|
|
24
|
+
props.actions.visible,
|
|
25
|
+
{
|
|
26
|
+
...props.actions,
|
|
27
|
+
visible: undefined
|
|
28
|
+
}
|
|
29
|
+
] : [
|
|
30
|
+
undefined,
|
|
31
|
+
props.actions
|
|
32
|
+
];
|
|
33
|
+
const [isActionsVisible, setActionsVisible] = useControllableState({
|
|
34
|
+
state: isActionsVisibleExternal,
|
|
35
|
+
defaultState: false,
|
|
36
|
+
initialState: false
|
|
37
|
+
});
|
|
23
38
|
const [isAsideVisible, setAsideVisible] = React.useState(true);
|
|
24
|
-
const handleActionsRef = (
|
|
25
|
-
setAsideVisible(
|
|
39
|
+
const handleActionsRef = (actionsElement)=>{
|
|
40
|
+
setAsideVisible(actionsElement === null);
|
|
26
41
|
};
|
|
27
42
|
const open = useTreeContext_unstable((ctx)=>ctx.openItems.has(value));
|
|
28
43
|
const actionsRef = React.useRef(null);
|
|
29
44
|
const expandIconRef = React.useRef(null);
|
|
30
45
|
const layoutRef = React.useRef(null);
|
|
31
46
|
const subtreeRef = React.useRef(null);
|
|
47
|
+
const actionsRefs = useMergedRefs(isResolvedShorthand(actions) ? actions.ref : undefined, handleActionsRef, actionsRef);
|
|
48
|
+
const expandIconRefs = useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef);
|
|
32
49
|
const handleClick = useEventCallback((event)=>{
|
|
33
50
|
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
34
51
|
if (event.isDefaultPrevented()) {
|
|
@@ -45,17 +62,16 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
45
62
|
const isFromExpandIcon = expandIconRef.current && elementContains(expandIconRef.current, event.target);
|
|
46
63
|
requestTreeResponse({
|
|
47
64
|
event,
|
|
48
|
-
itemType,
|
|
49
65
|
value,
|
|
66
|
+
itemType,
|
|
67
|
+
target: event.currentTarget,
|
|
50
68
|
type: isFromExpandIcon ? treeDataTypes.ExpandIconClick : treeDataTypes.Click
|
|
51
69
|
});
|
|
52
70
|
});
|
|
53
71
|
const handleKeyDown = useEventCallback((event)=>{
|
|
54
72
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
if (event.currentTarget !== event.target) {
|
|
73
|
+
// Ignore keyboard events that do not originate from the current tree item.
|
|
74
|
+
if (event.isDefaultPrevented() || event.currentTarget !== event.target) {
|
|
59
75
|
return;
|
|
60
76
|
}
|
|
61
77
|
switch(event.key){
|
|
@@ -68,6 +84,7 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
68
84
|
case treeDataTypes.ArrowRight:
|
|
69
85
|
return requestTreeResponse({
|
|
70
86
|
event,
|
|
87
|
+
target: event.currentTarget,
|
|
71
88
|
value,
|
|
72
89
|
itemType,
|
|
73
90
|
type: event.key
|
|
@@ -77,6 +94,7 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
77
94
|
if (isTypeAheadCharacter) {
|
|
78
95
|
requestTreeResponse({
|
|
79
96
|
event,
|
|
97
|
+
target: event.currentTarget,
|
|
80
98
|
value,
|
|
81
99
|
itemType,
|
|
82
100
|
type: treeDataTypes.TypeAhead
|
|
@@ -99,16 +117,37 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
99
117
|
return setActionsVisible(false);
|
|
100
118
|
}
|
|
101
119
|
});
|
|
120
|
+
const isBranch = itemType === 'branch';
|
|
121
|
+
const actionsSlot = React.useMemo(()=>isActionsVisible ? resolveShorthand(actions) : undefined, [
|
|
122
|
+
actions,
|
|
123
|
+
isActionsVisible
|
|
124
|
+
]);
|
|
125
|
+
if (actionsSlot) {
|
|
126
|
+
actionsSlot.ref = actionsRefs;
|
|
127
|
+
}
|
|
128
|
+
const asideSlot = React.useMemo(()=>isAsideVisible ? resolveShorthand(aside) : undefined, [
|
|
129
|
+
aside,
|
|
130
|
+
isAsideVisible
|
|
131
|
+
]);
|
|
132
|
+
const expandIconSlot = React.useMemo(()=>resolveShorthand(expandIcon, {
|
|
133
|
+
required: isBranch,
|
|
134
|
+
defaultProps: {
|
|
135
|
+
children: /*#__PURE__*/ React.createElement(TreeItemChevron, null),
|
|
136
|
+
'aria-hidden': true
|
|
137
|
+
}
|
|
138
|
+
}), [
|
|
139
|
+
expandIcon,
|
|
140
|
+
isBranch
|
|
141
|
+
]);
|
|
142
|
+
if (expandIconSlot) {
|
|
143
|
+
expandIconSlot.ref = expandIconRefs;
|
|
144
|
+
}
|
|
102
145
|
return {
|
|
103
146
|
value,
|
|
104
147
|
open,
|
|
105
148
|
subtreeRef,
|
|
106
|
-
actionsRef: useMergedRefs(actionsRef, handleActionsRef),
|
|
107
|
-
expandIconRef,
|
|
108
149
|
layoutRef,
|
|
109
150
|
itemType,
|
|
110
|
-
isActionsVisible,
|
|
111
|
-
isAsideVisible,
|
|
112
151
|
level,
|
|
113
152
|
components: {
|
|
114
153
|
root: 'div'
|
|
@@ -120,13 +159,16 @@ import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromEleme
|
|
|
120
159
|
role: 'treeitem',
|
|
121
160
|
'aria-level': level,
|
|
122
161
|
[dataTreeItemValueAttrName]: value,
|
|
123
|
-
'aria-expanded':
|
|
162
|
+
'aria-expanded': isBranch ? open : undefined,
|
|
124
163
|
onClick: handleClick,
|
|
125
164
|
onKeyDown: handleKeyDown,
|
|
126
165
|
onMouseOver: handleActionsVisible,
|
|
127
166
|
onFocus: handleActionsVisible,
|
|
128
167
|
onMouseOut: handleActionsInvisible,
|
|
129
168
|
onBlur: handleActionsInvisible
|
|
130
|
-
})
|
|
169
|
+
}),
|
|
170
|
+
actions: actionsSlot,
|
|
171
|
+
aside: asideSlot,
|
|
172
|
+
expandIcon: expandIconSlot
|
|
131
173
|
};
|
|
132
174
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTreeItem.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { elementContains } from '@fluentui/react-portal';\nimport type { TreeItemProps, TreeItemState } from './TreeItem.types';\nimport { useTreeContext_unstable } from '../../contexts/index';\nimport { treeDataTypes } from '../../utils/tokens';\nimport { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';\n\n/**\n * Create the state required to render TreeItem.\n *\n * The returned state can be modified with hooks such as useTreeItemStyles_unstable,\n * before being passed to renderTreeItem_unstable.\n *\n * @param props - props from this instance of TreeItem\n * @param ref - reference to root HTMLElement of TreeItem\n */\nexport function useTreeItem_unstable(props: TreeItemProps, ref: React.Ref<HTMLDivElement>): TreeItemState {\n const contextLevel = useTreeContext_unstable(ctx => ctx.level);\n\n const value = useId('fuiTreeItemValue-', props.value?.toString());\n\n const { onClick, onKeyDown, as = 'div', itemType = 'leaf', 'aria-level': level = contextLevel, ...rest } = props;\n\n const requestTreeResponse = useTreeContext_unstable(ctx => ctx.requestTreeResponse);\n\n const [isActionsVisible, setActionsVisible] = React.useState(false);\n const [isAsideVisible, setAsideVisible] = React.useState(true);\n\n const handleActionsRef = (actions: HTMLDivElement | null) => {\n setAsideVisible(actions === null);\n };\n\n const open = useTreeContext_unstable(ctx => ctx.openItems.has(value));\n\n const actionsRef = React.useRef<HTMLDivElement>(null);\n const expandIconRef = React.useRef<HTMLDivElement>(null);\n const layoutRef = React.useRef<HTMLDivElement>(null);\n const subtreeRef = React.useRef<HTMLDivElement>(null);\n\n const handleClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n if (event.isDefaultPrevented()) {\n return;\n }\n const isEventFromActions = actionsRef.current && elementContains(actionsRef.current, event.target as Node);\n if (isEventFromActions) {\n return;\n }\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (isEventFromSubtree) {\n return;\n }\n const isFromExpandIcon = expandIconRef.current && elementContains(expandIconRef.current, event.target as Node);\n requestTreeResponse({\n event,\n itemType,\n value,\n type: isFromExpandIcon ? treeDataTypes.ExpandIconClick : treeDataTypes.Click,\n });\n });\n\n const handleKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (event.isDefaultPrevented()) {\n return;\n }\n if (event.currentTarget !== event.target) {\n return;\n }\n switch (event.key) {\n case treeDataTypes.End:\n case treeDataTypes.Home:\n case treeDataTypes.Enter:\n case treeDataTypes.ArrowUp:\n case treeDataTypes.ArrowDown:\n case treeDataTypes.ArrowLeft:\n case treeDataTypes.ArrowRight:\n return requestTreeResponse({ event, value, itemType, type: event.key });\n }\n const isTypeAheadCharacter =\n event.key.length === 1 && event.key.match(/\\w/) && !event.altKey && !event.ctrlKey && !event.metaKey;\n if (isTypeAheadCharacter) {\n requestTreeResponse({ event, value, itemType, type: treeDataTypes.TypeAhead });\n }\n });\n\n const handleActionsVisible = useEventCallback((event: React.FocusEvent | React.MouseEvent) => {\n const isTargetFromSubtree = Boolean(\n subtreeRef.current && elementContains(subtreeRef.current, event.target as Node),\n );\n if (!isTargetFromSubtree) {\n setActionsVisible(true);\n }\n });\n\n const handleActionsInvisible = useEventCallback((event: React.FocusEvent | React.MouseEvent) => {\n const isTargetFromSubtree = Boolean(\n subtreeRef.current && elementContains(subtreeRef.current, event.target as Node),\n );\n const isRelatedTargetFromActions = Boolean(\n actionsRef.current && elementContains(actionsRef.current, event.relatedTarget as Node),\n );\n if (isRelatedTargetFromActions) {\n return setActionsVisible(true);\n }\n if (!isTargetFromSubtree) {\n return setActionsVisible(false);\n }\n });\n\n return {\n value,\n open,\n subtreeRef,\n actionsRef: useMergedRefs(actionsRef, handleActionsRef),\n expandIconRef,\n layoutRef,\n itemType,\n isActionsVisible,\n isAsideVisible,\n level,\n components: {\n root: 'div',\n },\n root: getNativeElementProps(as, {\n tabIndex: -1,\n ...rest,\n ref,\n role: 'treeitem',\n 'aria-level': level,\n [dataTreeItemValueAttrName]: value,\n 'aria-expanded': itemType === 'branch' ? open : undefined,\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n onMouseOver: handleActionsVisible,\n onFocus: handleActionsVisible,\n onMouseOut: handleActionsInvisible,\n onBlur: handleActionsInvisible,\n }),\n };\n}\n"],"names":["React","getNativeElementProps","useId","useMergedRefs","useEventCallback","elementContains","useTreeContext_unstable","treeDataTypes","dataTreeItemValueAttrName","useTreeItem_unstable","props","ref","contextLevel","ctx","level","value","toString","onClick","onKeyDown","as","itemType","rest","requestTreeResponse","isActionsVisible","setActionsVisible","useState","isAsideVisible","setAsideVisible","handleActionsRef","actions","open","openItems","has","actionsRef","useRef","expandIconRef","layoutRef","subtreeRef","handleClick","event","isDefaultPrevented","isEventFromActions","current","target","isEventFromSubtree","isFromExpandIcon","type","ExpandIconClick","Click","handleKeyDown","currentTarget","key","End","Home","Enter","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","isTypeAheadCharacter","length","match","altKey","ctrlKey","metaKey","TypeAhead","handleActionsVisible","isTargetFromSubtree","Boolean","handleActionsInvisible","isRelatedTargetFromActions","relatedTarget","components","root","tabIndex","role","undefined","onMouseOver","onFocus","onMouseOut","onBlur"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,qBAAqB,EAAEC,KAAK,EAAEC,aAAa,QAAQ,4BAA4B;AACxF,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,SAASC,uBAAuB,QAAQ,uBAAuB;AAC/D,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,yBAAyB,QAAQ,0CAA0C;AAEpF;;;;;;;;CAQC,GACD,OAAO,SAASC,qBAAqBC,KAAoB,EAAEC,GAA8B,EAAiB;QAG/DD;IAFzC,MAAME,eAAeN,wBAAwBO,CAAAA,MAAOA,IAAIC,KAAK;IAE7D,MAAMC,QAAQb,MAAM,qBAAqBQ,CAAAA,eAAAA,MAAMK,KAAK,cAAXL,0BAAAA,KAAAA,IAAAA,aAAaM;IAEtD,MAAM,EAAEC,QAAO,EAAEC,UAAS,EAAEC,IAAK,MAAK,EAAEC,UAAW,OAAM,EAAE,cAAcN,QAAQF,YAAY,CAAA,EAAE,GAAGS,MAAM,GAAGX;IAE3G,MAAMY,sBAAsBhB,wBAAwBO,CAAAA,MAAOA,IAAIS,mBAAmB;IAElF,MAAM,CAACC,kBAAkBC,kBAAkB,GAAGxB,MAAMyB,QAAQ,CAAC,KAAK;IAClE,MAAM,CAACC,gBAAgBC,gBAAgB,GAAG3B,MAAMyB,QAAQ,CAAC,IAAI;IAE7D,MAAMG,mBAAmB,CAACC,UAAmC;QAC3DF,gBAAgBE,YAAY,IAAI;IAClC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sBAAsBkB,IAAI;YAC9BuD,UAAU,CAAC;YACX,GAAGrD,IAAI;YACPV;YACAgE,MAAM;YACN,cAAc7D;YACd,CAACN,0BAA0B,EAAEO;YAC7B,iBAAiBK,aAAa,WAAWU,OAAO8C,SAAS;YACzD3D,SAASqB;YACTpB,WAAW+B;YACX4B,aAAaX;YACbY,SAASZ;YACTa,YAAYV;YACZW,QAAQX;QACV;IACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"sources":["useTreeItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getNativeElementProps,\n isResolvedShorthand,\n resolveShorthand,\n useControllableState,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { elementContains } from '@fluentui/react-portal';\nimport type { TreeItemProps, TreeItemSlots, TreeItemState } from './TreeItem.types';\nimport { useTreeContext_unstable } from '../../contexts/index';\nimport { treeDataTypes } from '../../utils/tokens';\nimport { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';\nimport { TreeItemChevron } from '../TreeItemChevron';\n\n/**\n * Create the state required to render TreeItem.\n *\n * The returned state can be modified with hooks such as useTreeItemStyles_unstable,\n * before being passed to renderTreeItem_unstable.\n *\n * @param props - props from this instance of TreeItem\n * @param ref - reference to root HTMLElement of TreeItem\n */\nexport function useTreeItem_unstable(props: TreeItemProps, ref: React.Ref<HTMLDivElement>): TreeItemState {\n const contextLevel = useTreeContext_unstable(ctx => ctx.level);\n\n const value = useId('fuiTreeItemValue-', props.value?.toString());\n\n const {\n onClick,\n onKeyDown,\n as = 'div',\n itemType = 'leaf',\n 'aria-level': level = contextLevel,\n expandIcon,\n aside,\n ...rest\n } = props;\n\n const requestTreeResponse = useTreeContext_unstable(ctx => ctx.requestTreeResponse);\n\n const [isActionsVisibleExternal, actions]: [boolean | undefined, TreeItemSlots['actions']] = isResolvedShorthand(\n props.actions,\n )\n ? // .visible prop should not be propagated to the DOM\n [props.actions.visible, { ...props.actions, visible: undefined }]\n : [undefined, props.actions];\n\n const [isActionsVisible, setActionsVisible] = useControllableState({\n state: isActionsVisibleExternal,\n defaultState: false,\n initialState: false,\n });\n const [isAsideVisible, setAsideVisible] = React.useState(true);\n\n const handleActionsRef = (actionsElement: HTMLDivElement | null) => {\n setAsideVisible(actionsElement === null);\n };\n\n const open = useTreeContext_unstable(ctx => ctx.openItems.has(value));\n\n const actionsRef = React.useRef<HTMLDivElement>(null);\n const expandIconRef = React.useRef<HTMLDivElement>(null);\n const layoutRef = React.useRef<HTMLDivElement>(null);\n const subtreeRef = React.useRef<HTMLDivElement>(null);\n\n const actionsRefs = useMergedRefs(\n isResolvedShorthand(actions) ? actions.ref : undefined,\n handleActionsRef,\n actionsRef,\n );\n const expandIconRefs = useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef);\n\n const handleClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n if (event.isDefaultPrevented()) {\n return;\n }\n const isEventFromActions = actionsRef.current && elementContains(actionsRef.current, event.target as Node);\n if (isEventFromActions) {\n return;\n }\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (isEventFromSubtree) {\n return;\n }\n const isFromExpandIcon = expandIconRef.current && elementContains(expandIconRef.current, event.target as Node);\n requestTreeResponse({\n event,\n value,\n itemType,\n target: event.currentTarget,\n type: isFromExpandIcon ? treeDataTypes.ExpandIconClick : treeDataTypes.Click,\n });\n });\n\n const handleKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n // Ignore keyboard events that do not originate from the current tree item.\n if (event.isDefaultPrevented() || event.currentTarget !== event.target) {\n return;\n }\n switch (event.key) {\n case treeDataTypes.End:\n case treeDataTypes.Home:\n case treeDataTypes.Enter:\n case treeDataTypes.ArrowUp:\n case treeDataTypes.ArrowDown:\n case treeDataTypes.ArrowLeft:\n case treeDataTypes.ArrowRight:\n return requestTreeResponse({ event, target: event.currentTarget, value, itemType, type: event.key });\n }\n const isTypeAheadCharacter =\n event.key.length === 1 && event.key.match(/\\w/) && !event.altKey && !event.ctrlKey && !event.metaKey;\n if (isTypeAheadCharacter) {\n requestTreeResponse({ event, target: event.currentTarget, value, itemType, type: treeDataTypes.TypeAhead });\n }\n });\n\n const handleActionsVisible = useEventCallback((event: React.FocusEvent | React.MouseEvent) => {\n const isTargetFromSubtree = Boolean(\n subtreeRef.current && elementContains(subtreeRef.current, event.target as Node),\n );\n if (!isTargetFromSubtree) {\n setActionsVisible(true);\n }\n });\n\n const handleActionsInvisible = useEventCallback((event: React.FocusEvent | React.MouseEvent) => {\n const isTargetFromSubtree = Boolean(\n subtreeRef.current && elementContains(subtreeRef.current, event.target as Node),\n );\n const isRelatedTargetFromActions = Boolean(\n actionsRef.current && elementContains(actionsRef.current, event.relatedTarget as Node),\n );\n if (isRelatedTargetFromActions) {\n return setActionsVisible(true);\n }\n if (!isTargetFromSubtree) {\n return setActionsVisible(false);\n }\n });\n\n const isBranch = itemType === 'branch';\n\n const actionsSlot = React.useMemo(\n () => (isActionsVisible ? resolveShorthand(actions) : undefined),\n [actions, isActionsVisible],\n );\n if (actionsSlot) {\n actionsSlot.ref = actionsRefs;\n }\n const asideSlot = React.useMemo(\n () => (isAsideVisible ? resolveShorthand(aside) : undefined),\n [aside, isAsideVisible],\n );\n const expandIconSlot = React.useMemo(\n () =>\n resolveShorthand(expandIcon, {\n required: isBranch,\n defaultProps: {\n children: <TreeItemChevron />,\n 'aria-hidden': true,\n },\n }),\n [expandIcon, isBranch],\n );\n if (expandIconSlot) {\n expandIconSlot.ref = expandIconRefs;\n }\n\n return {\n value,\n open,\n subtreeRef,\n layoutRef,\n itemType,\n level,\n components: {\n root: 'div',\n },\n root: getNativeElementProps(as, {\n tabIndex: -1,\n ...rest,\n ref,\n role: 'treeitem',\n 'aria-level': level,\n [dataTreeItemValueAttrName]: value,\n 'aria-expanded': isBranch ? open : undefined,\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n onMouseOver: handleActionsVisible,\n onFocus: handleActionsVisible,\n onMouseOut: handleActionsInvisible,\n onBlur: handleActionsInvisible,\n }),\n actions: actionsSlot,\n aside: asideSlot,\n expandIcon: expandIconSlot,\n };\n}\n"],"names":["React","getNativeElementProps","isResolvedShorthand","resolveShorthand","useControllableState","useId","useMergedRefs","useEventCallback","elementContains","useTreeContext_unstable","treeDataTypes","dataTreeItemValueAttrName","TreeItemChevron","useTreeItem_unstable","props","ref","contextLevel","ctx","level","value","toString","onClick","onKeyDown","as","itemType","expandIcon","aside","rest","requestTreeResponse","isActionsVisibleExternal","actions","visible","undefined","isActionsVisible","setActionsVisible","state","defaultState","initialState","isAsideVisible","setAsideVisible","useState","handleActionsRef","actionsElement","open","openItems","has","actionsRef","useRef","expandIconRef","layoutRef","subtreeRef","actionsRefs","expandIconRefs","handleClick","event","isDefaultPrevented","isEventFromActions","current","target","isEventFromSubtree","isFromExpandIcon","currentTarget","type","ExpandIconClick","Click","handleKeyDown","key","End","Home","Enter","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","isTypeAheadCharacter","length","match","altKey","ctrlKey","metaKey","TypeAhead","handleActionsVisible","isTargetFromSubtree","Boolean","handleActionsInvisible","isRelatedTargetFromActions","relatedTarget","isBranch","actionsSlot","useMemo","asideSlot","expandIconSlot","required","defaultProps","children","components","root","tabIndex","role","onMouseOver","onFocus","onMouseOut","onBlur"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,qBAAqB,EACrBC,mBAAmB,EACnBC,gBAAgB,EAChBC,oBAAoB,EACpBC,KAAK,EACLC,aAAa,QACR,4BAA4B;AACnC,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,SAASC,uBAAuB,QAAQ,uBAAuB;AAC/D,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,yBAAyB,QAAQ,0CAA0C;AACpF,SAASC,eAAe,QAAQ,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ACfA,YAAYzE,GAAG,GAAGoC;IACpB,CAAC;IACD,MAAMuC,YAAY1F,MAAMyF,OAAO,CAC7B,IAAOnD,iBAAiBnC,iBAAiBuB,SAASM,SAAS,EAC3D;QAACN;QAAOY;KAAe;IAEzB,MAAMqD,iBAAiB3F,MAAMyF,OAAO,CAClC,IACEtF,iBAAiBsB,YAAY;YAC3BmE,UAAUL;YACVM,cAAc;gBACZC,wBAAU,oBAAClF;gBACX,eAAe,IAAI;YACrB;QACF,IACF;QAACa;QAAY8D;KAAS;IAExB,IAAII,gBAAgB;QAClBA,eAAe5E,GAAG,GAAGqC;IACvB,CAAC;IAED,OAAO;QACLjC;QACAwB;QACAO;QACAD;QACAzB;QACAN;QACA6E,YAAY;YACVC,MAAM;QACR;QACAA,MAAM/F,sBAAsBsB,IAAI;YAC9B0E,UAAU,CAAC;YACX,GAAGtE,IAAI;YACPZ;YACAmF,MAAM;YACN,cAAchF;YACd,CAACP,0BAA0B,EAAEQ;YAC7B,iBAAiBoE,WAAW5C,OAAOX,SAAS;YAC5CX,SAASgC;YACT/B,WAAW2C;YACXkC,aAAalB;YACbmB,SAASnB;YACToB,YAAYjB;YACZkB,QAAQlB;QACV;QACAtD,SAAS0D;QACT9D,OAAOgE;QACPjE,YAAYkE;IACd;AACF,CAAC"}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
export function useTreeItemContextValues_unstable(state) {
|
|
2
|
-
const { value ,
|
|
3
|
+
const { value , itemType , layoutRef , subtreeRef , open , actions , aside , expandIcon } = state;
|
|
3
4
|
/**
|
|
4
5
|
* This context is created with "@fluentui/react-context-selector",
|
|
5
6
|
* there is no sense to memoize it
|
|
6
7
|
*/ const treeItem = {
|
|
7
|
-
isActionsVisible,
|
|
8
|
-
isAsideVisible,
|
|
9
8
|
value,
|
|
10
|
-
actionsRef,
|
|
11
9
|
itemType,
|
|
12
10
|
layoutRef,
|
|
13
11
|
subtreeRef,
|
|
14
|
-
expandIconRef,
|
|
15
12
|
open
|
|
16
13
|
};
|
|
14
|
+
const treeItemSlots = React.useMemo(()=>({
|
|
15
|
+
actions,
|
|
16
|
+
aside,
|
|
17
|
+
expandIcon
|
|
18
|
+
}), [
|
|
19
|
+
actions,
|
|
20
|
+
aside,
|
|
21
|
+
expandIcon
|
|
22
|
+
]);
|
|
17
23
|
return {
|
|
18
|
-
treeItem
|
|
24
|
+
treeItem,
|
|
25
|
+
treeItemSlots
|
|
19
26
|
};
|
|
20
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTreeItemContextValues.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["useTreeItemContextValues.ts"],"sourcesContent":["import * as React from 'react';\nimport type { TreeItemContextValues, TreeItemState } from './TreeItem.types';\nimport type { TreeItemContextValue, TreeItemSlotsContextValue } from '../../contexts';\n\nexport function useTreeItemContextValues_unstable(state: TreeItemState): TreeItemContextValues {\n const { value, itemType, layoutRef, subtreeRef, open, actions, aside, expandIcon } = state;\n\n /**\n * This context is created with \"@fluentui/react-context-selector\",\n * there is no sense to memoize it\n */\n const treeItem: TreeItemContextValue = {\n value,\n itemType,\n layoutRef,\n subtreeRef,\n open,\n };\n\n const treeItemSlots: TreeItemSlotsContextValue = React.useMemo(\n () => ({ actions, aside, expandIcon }),\n [actions, aside, expandIcon],\n );\n\n return { treeItem, treeItemSlots };\n}\n"],"names":["React","useTreeItemContextValues_unstable","state","value","itemType","layoutRef","subtreeRef","open","actions","aside","expandIcon","treeItem","treeItemSlots","useMemo"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B,OAAO,SAASC,kCAAkCC,KAAoB,EAAyB;IAC7F,MAAM,EAAEC,MAAK,EAAEC,SAAQ,EAAEC,UAAS,EAAEC,WAAU,EAAEC,KAAI,EAAEC,QAAO,EAAEC,MAAK,EAAEC,WAAU,EAAE,GAAGR;IAErF;;;GAGC,GACD,MAAMS,WAAiC;QACrCR;QACAC;QACAC;QACAC;QACAC;IACF;IAEA,MAAMK,gBAA2CZ,MAAMa,OAAO,CAC5D,IAAO,CAAA;YAAEL;YAASC;YAAOC;QAAW,CAAA,GACpC;QAACF;QAASC;QAAOC;KAAW;IAG9B,OAAO;QAAEC;QAAUC;IAAc;AACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState,
|
|
1
|
+
{"version":3,"sources":["TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { ButtonContextValue } from '@fluentui/react-button';\nimport { TreeItemSlots } from '../TreeItem/TreeItem.types';\n\nexport type TreeItemLayoutSlots = {\n root: Slot<'div'>;\n /**\n * Content. Children of the root slot are automatically rendered here\n */\n content: 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\nexport type TreeItemLayoutInternalSlots = TreeItemLayoutSlots & Pick<TreeItemSlots, 'actions' | 'aside' | 'expandIcon'>;\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<TreeItemLayoutInternalSlots> & {\n buttonContextValue: ButtonContextValue;\n};\n"],"names":[],"mappings":"AAAA,WAgCE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["renderTreeItemLayout.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutState,
|
|
1
|
+
{"version":3,"sources":["renderTreeItemLayout.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutState, TreeItemLayoutInternalSlots } 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) => {\n const { slots, slotProps } = getSlotsNext<TreeItemLayoutInternalSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.expandIcon && <slots.expandIcon {...slotProps.expandIcon} />}\n {slots.iconBefore && <slots.iconBefore {...slotProps.iconBefore} />}\n <slots.content {...slotProps.content}>{slotProps.root.children}</slots.content>\n {slots.iconAfter && <slots.iconAfter {...slotProps.iconAfter} />}\n <ButtonContextProvider value={state.buttonContextValue}>\n {slots.actions && <slots.actions {...slotProps.actions} />}\n {slots.aside && <slots.aside {...slotProps.aside} />}\n </ButtonContextProvider>\n </slots.root>\n );\n};\n"],"names":["createElement","getSlotsNext","ButtonContextProvider","renderTreeItemLayout_unstable","state","slots","slotProps","root","expandIcon","iconBefore","content","children","iconAfter","value","buttonContextValue","actions","aside"],"mappings":"AAAA,wBAAwB,GACxB,uBAAuB,GAEvB,SAASA,aAAa,QAAQ,8BAA8B;AAC5D,SAASC,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,qBAAqB,QAAQ,yBAAyB;AAE/D;;CAEC,GACD,OAAO,MAAMC,gCAAgC,CAACC,QAA+B;IAC3E,MAAM,EAAEC,MAAK,EAAEC,UAAS,EAAE,GAAGL,aAA0CG;IAEvE,qBACE,AAdJ,cAcKC,MAAME,IAAI,EAAKD,UAAUC,IAAI,EAC3BF,MAAMG,UAAU,kBAAI,AAf3B,cAe4BH,MAAMG,UAAU,EAAKF,UAAUE,UAAU,GAC9DH,MAAMI,UAAU,kBAAI,AAhB3B,cAgB4BJ,MAAMI,UAAU,EAAKH,UAAUG,UAAU,iBAC/D,AAjBN,cAiBOJ,MAAMK,OAAO,EAAKJ,UAAUI,OAAO,EAAGJ,UAAUC,IAAI,CAACI,QAAQ,GAC7DN,MAAMO,SAAS,kBAAI,AAlB1B,cAkB2BP,MAAMO,SAAS,EAAKN,UAAUM,SAAS,iBAC5D,AAnBN,cAmBOV;QAAsBW,OAAOT,MAAMU,kBAAkB;OACnDT,MAAMU,OAAO,kBAAI,AApB1B,cAoB2BV,MAAMU,OAAO,EAAKT,UAAUS,OAAO,GACrDV,MAAMW,KAAK,kBAAI,AArBxB,cAqByBX,MAAMW,KAAK,EAAKV,UAAUU,KAAK;AAIxD,EAAE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { getNativeElementProps,
|
|
2
|
+
import { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
3
|
import { useTreeItemContext_unstable } from '../../contexts/treeItemContext';
|
|
4
|
-
import {
|
|
4
|
+
import { useTreeItemSlotsContext_unstable } from '../../contexts/treeItemSlotsContext';
|
|
5
5
|
/**
|
|
6
6
|
* Create the state required to render TreeItemLayout.
|
|
7
7
|
*
|
|
@@ -11,15 +11,9 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
11
11
|
* @param props - props from this instance of TreeItemLayout
|
|
12
12
|
* @param ref - reference to root HTMLElement of TreeItemLayout
|
|
13
13
|
*/ export const useTreeItemLayout_unstable = (props, ref)=>{
|
|
14
|
-
const { content , iconAfter , iconBefore ,
|
|
14
|
+
const { content , iconAfter , iconBefore , as ='span' } = props;
|
|
15
|
+
const { actions , aside , expandIcon } = useTreeItemSlotsContext_unstable();
|
|
15
16
|
const layoutRef = useTreeItemContext_unstable((ctx)=>ctx.layoutRef);
|
|
16
|
-
const expandIconRef = useTreeItemContext_unstable((ctx)=>ctx.expandIconRef);
|
|
17
|
-
const isActionsVisibleContext = useTreeItemContext_unstable((ctx)=>ctx.isActionsVisible);
|
|
18
|
-
const isAsideVisible = useTreeItemContext_unstable((ctx)=>ctx.isAsideVisible);
|
|
19
|
-
var _ref;
|
|
20
|
-
const isActionsVisible = (_ref = isResolvedShorthand(actions) ? actions.visible : undefined) !== null && _ref !== void 0 ? _ref : isActionsVisibleContext;
|
|
21
|
-
const isBranch = useTreeItemContext_unstable((ctx)=>ctx.itemType === 'branch');
|
|
22
|
-
const actionsRef = useMergedRefs(isResolvedShorthand(actions) ? actions.ref : undefined, useTreeItemContext_unstable((ctx)=>ctx.actionsRef));
|
|
23
17
|
return {
|
|
24
18
|
components: {
|
|
25
19
|
root: 'div',
|
|
@@ -50,23 +44,8 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
50
44
|
'aria-hidden': true
|
|
51
45
|
}
|
|
52
46
|
}),
|
|
53
|
-
aside:
|
|
54
|
-
actions:
|
|
55
|
-
|
|
56
|
-
...actions,
|
|
57
|
-
visible: undefined
|
|
58
|
-
} : actions, {
|
|
59
|
-
defaultProps: {
|
|
60
|
-
ref: actionsRef
|
|
61
|
-
}
|
|
62
|
-
}) : undefined,
|
|
63
|
-
expandIcon: resolveShorthand(expandIcon, {
|
|
64
|
-
required: isBranch,
|
|
65
|
-
defaultProps: {
|
|
66
|
-
children: /*#__PURE__*/ React.createElement(TreeItemChevron, null),
|
|
67
|
-
'aria-hidden': true,
|
|
68
|
-
ref: useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef)
|
|
69
|
-
}
|
|
70
|
-
})
|
|
47
|
+
aside: resolveShorthand(aside),
|
|
48
|
+
actions: resolveShorthand(actions),
|
|
49
|
+
expandIcon: resolveShorthand(expandIcon)
|
|
71
50
|
};
|
|
72
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTreeItemLayout.
|
|
1
|
+
{"version":3,"sources":["useTreeItemLayout.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types';\nimport { useTreeItemContext_unstable } from '../../contexts/treeItemContext';\nimport { useTreeItemSlotsContext_unstable } from '../../contexts/treeItemSlotsContext';\n\n/**\n * Create the state required to render TreeItemLayout.\n *\n * The returned state can be modified with hooks such as useTreeItemLayoutStyles_unstable,\n * before being passed to renderTreeItemLayout_unstable.\n *\n * @param props - props from this instance of TreeItemLayout\n * @param ref - reference to root HTMLElement of TreeItemLayout\n */\nexport const useTreeItemLayout_unstable = (\n props: TreeItemLayoutProps,\n ref: React.Ref<HTMLElement>,\n): TreeItemLayoutState => {\n const { content, iconAfter, iconBefore, as = 'span' } = props;\n\n const { actions, aside, expandIcon } = useTreeItemSlotsContext_unstable();\n\n const layoutRef = useTreeItemContext_unstable(ctx => ctx.layoutRef);\n\n return {\n components: {\n root: 'div',\n expandIcon: 'div',\n iconBefore: 'div',\n content: 'div',\n iconAfter: 'div',\n actions: 'div',\n aside: 'div',\n },\n buttonContextValue: { size: 'small' },\n root: getNativeElementProps(as, { ...props, ref: useMergedRefs(ref, layoutRef) }),\n iconBefore: resolveShorthand(iconBefore, { defaultProps: { 'aria-hidden': true } }),\n content: resolveShorthand(content, { required: true }),\n iconAfter: resolveShorthand(iconAfter, { defaultProps: { 'aria-hidden': true } }),\n aside: resolveShorthand(aside),\n actions: resolveShorthand(actions),\n expandIcon: resolveShorthand(expandIcon),\n };\n};\n"],"names":["React","getNativeElementProps","resolveShorthand","useMergedRefs","useTreeItemContext_unstable","useTreeItemSlotsContext_unstable","useTreeItemLayout_unstable","props","ref","content","iconAfter","iconBefore","as","actions","aside","expandIcon","layoutRef","ctx","components","root","buttonContextValue","size","defaultProps","required"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAEnG,SAASC,2BAA2B,QAAQ,iCAAiC;AAC7E,SAASC,gCAAgC,QAAQ,sCAAsC;AAEvF;;;;;;;;CAQC,GACD,OAAO,MAAMC,6BAA6B,CACxCC,OACAC,MACwB;IACxB,MAAM,EAAEC,QAAO,EAAEC,UAAS,EAAEC,WAAU,EAAEC,IAAK,OAAM,EAAE,GAAGL;IAExD,MAAM,EAAEM,QAAO,EAAEC,MAAK,EAAEC,WAAU,EAAE,GAAGV;IAEvC,MAAMW,YAAYZ,4BAA4Ba,CAAAA,MAAOA,IAAID,SAAS;IAElE,OAAO;QACLE,YAAY;YACVC,MAAM;YACNJ,YAAY;YACZJ,YAAY;YACZF,SAAS;YACTC,WAAW;YACXG,SAAS;YACTC,OAAO;QACT;QACAM,oBAAoB;YAAEC,MAAM;QAAQ;QACpCF,MAAMlB,sBAAsBW,IAAI;YAAE,GAAGL,KAAK;YAAEC,KAAKL,cAAcK,KAAKQ;QAAW;QAC/EL,YAAYT,iBAAiBS,YAAY;YAAEW,cAAc;gBAAE,eAAe,IAAI;YAAC;QAAE;QACjFb,SAASP,iBAAiBO,SAAS;YAAEc,UAAU,IAAI;QAAC;QACpDb,WAAWR,iBAAiBQ,WAAW;YAAEY,cAAc;gBAAE,eAAe,IAAI;YAAC;QAAE;QAC/ER,OAAOZ,iBAAiBY;QACxBD,SAASX,iBAAiBW;QAC1BE,YAAYb,iBAAiBa;IAC/B;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TreeItemPersonaLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { AvatarContextValue, AvatarSize } from '@fluentui/react-avatar';\nimport { ButtonContextValue } from '@fluentui/react-button';\nimport {
|
|
1
|
+
{"version":3,"sources":["TreeItemPersonaLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { AvatarContextValue, AvatarSize } from '@fluentui/react-avatar';\nimport { ButtonContextValue } from '@fluentui/react-button';\nimport { TreeItemSlots } from '../TreeItem/TreeItem.types';\n\nexport type TreeItemPersonaLayoutContextValues = {\n avatar: AvatarContextValue;\n};\n\nexport type TreeItemPersonaLayoutSlots = {\n root: NonNullable<Slot<'div'>>;\n /**\n * Avatar to display.\n */\n media: NonNullable<Slot<'div'>>;\n /**\n * Content. Children of the root slot are automatically rendered here\n */\n content: NonNullable<Slot<'div'>>;\n /**\n * Secondary text that describes or complements the content\n */\n description?: Slot<'div'>;\n};\n\nexport type TreeItemPersonaLayoutInternalSlots = TreeItemPersonaLayoutSlots &\n Pick<TreeItemSlots, 'actions' | 'aside' | 'expandIcon'>;\n\n/**\n * TreeItemPersonaLayout Props\n */\nexport type TreeItemPersonaLayoutProps = ComponentProps<Partial<TreeItemPersonaLayoutSlots>>;\n\n/**\n * State used in rendering TreeItemPersonaLayout\n */\nexport type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutInternalSlots> & {\n avatarSize: AvatarSize;\n buttonContextValue: ButtonContextValue;\n};\n"],"names":[],"mappings":"AAAA,WAuCE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["renderTreeItemPersonaLayout.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type {\n TreeItemPersonaLayoutState,\n TreeItemPersonaLayoutContextValues,\n
|
|
1
|
+
{"version":3,"sources":["renderTreeItemPersonaLayout.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type {\n TreeItemPersonaLayoutState,\n TreeItemPersonaLayoutContextValues,\n TreeItemPersonaLayoutInternalSlots,\n} from './TreeItemPersonaLayout.types';\nimport { AvatarContextProvider } from '@fluentui/react-avatar';\nimport { ButtonContextProvider } from '@fluentui/react-button';\n\n/**\n * Render the final JSX of TreeItemPersonaLayout\n */\nexport const renderTreeItemPersonaLayout_unstable = (\n state: TreeItemPersonaLayoutState,\n contextValues: TreeItemPersonaLayoutContextValues,\n) => {\n const { slots, slotProps } = getSlotsNext<TreeItemPersonaLayoutInternalSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.expandIcon && <slots.expandIcon {...slotProps.expandIcon} />}\n <AvatarContextProvider value={contextValues.avatar}>\n <slots.media {...slotProps.media} />\n </AvatarContextProvider>\n <slots.content {...slotProps.content} />\n {slots.description && <slots.description {...slotProps.description} />}\n <ButtonContextProvider value={state.buttonContextValue}>\n {slots.actions && <slots.actions {...slotProps.actions} />}\n {slots.aside && <slots.aside {...slotProps.aside} />}\n </ButtonContextProvider>\n </slots.root>\n );\n};\n"],"names":["createElement","getSlotsNext","AvatarContextProvider","ButtonContextProvider","renderTreeItemPersonaLayout_unstable","state","contextValues","slots","slotProps","root","expandIcon","value","avatar","media","content","description","buttonContextValue","actions","aside"],"mappings":"AAAA,wBAAwB,GACxB,uBAAuB,GAEvB,SAASA,aAAa,QAAQ,8BAA8B;AAC5D,SAASC,YAAY,QAAQ,4BAA4B;AAMzD,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,qBAAqB,QAAQ,yBAAyB;AAE/D;;CAEC,GACD,OAAO,MAAMC,uCAAuC,CAClDC,OACAC,gBACG;IACH,MAAM,EAAEC,MAAK,EAAEC,UAAS,EAAE,GAAGP,aAAiDI;IAE9E,qBACE,AAtBJ,cAsBKE,MAAME,IAAI,EAAKD,UAAUC,IAAI,EAC3BF,MAAMG,UAAU,kBAAI,AAvB3B,cAuB4BH,MAAMG,UAAU,EAAKF,UAAUE,UAAU,iBAC/D,AAxBN,cAwBOR;QAAsBS,OAAOL,cAAcM,MAAM;qBAChD,AAzBR,cAyBSL,MAAMM,KAAK,EAAKL,UAAUK,KAAK,kBAElC,AA3BN,cA2BON,MAAMO,OAAO,EAAKN,UAAUM,OAAO,GACnCP,MAAMQ,WAAW,kBAAI,AA5B5B,cA4B6BR,MAAMQ,WAAW,EAAKP,UAAUO,WAAW,iBAClE,AA7BN,cA6BOZ;QAAsBQ,OAAON,MAAMW,kBAAkB;OACnDT,MAAMU,OAAO,kBAAI,AA9B1B,cA8B2BV,MAAMU,OAAO,EAAKT,UAAUS,OAAO,GACrDV,MAAMW,KAAK,kBAAI,AA/BxB,cA+ByBX,MAAMW,KAAK,EAAKV,UAAUU,KAAK;AAIxD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTreeItemPersonaLayout.
|
|
1
|
+
{"version":3,"sources":["useTreeItemPersonaLayout.ts"],"sourcesContent":["import * as React from 'react';\nimport type { TreeItemPersonaLayoutProps, TreeItemPersonaLayoutState } from './TreeItemPersonaLayout.types';\nimport { resolveShorthand } from '@fluentui/react-utilities';\nimport { useTreeContext_unstable } from '../../contexts';\nimport { treeAvatarSize } from '../../utils/tokens';\nimport { useTreeItemLayout_unstable } from '../TreeItemLayout/useTreeItemLayout';\n\n/**\n * Create the state required to render TreeItemPersonaLayout.\n *\n * The returned state can be modified with hooks such as useTreeItemPersonaLayoutStyles_unstable,\n * before being passed to renderTreeItemPersonaLayout_unstable.\n *\n * @param props - props from this instance of TreeItemPersonaLayout\n * @param ref - reference to root HTMLElement of TreeItemPersonaLayout\n */\nexport const useTreeItemPersonaLayout_unstable = (\n props: TreeItemPersonaLayoutProps,\n ref: React.Ref<HTMLSpanElement>,\n): TreeItemPersonaLayoutState => {\n const { media, children, content, description } = props;\n\n const treeItemLayoutState = useTreeItemLayout_unstable(\n {\n ...props,\n iconBefore: null,\n iconAfter: null,\n },\n ref,\n );\n\n const size = useTreeContext_unstable(ctx => ctx.size);\n return {\n ...treeItemLayoutState,\n components: {\n expandIcon: 'div',\n content: 'div',\n description: 'div',\n root: 'div',\n media: 'div',\n aside: 'div',\n actions: 'div',\n },\n avatarSize: treeAvatarSize[size],\n content: resolveShorthand(content, { required: true, defaultProps: { children } }),\n media: resolveShorthand(media, { required: true }),\n description: resolveShorthand(description),\n };\n};\n"],"names":["React","resolveShorthand","useTreeContext_unstable","treeAvatarSize","useTreeItemLayout_unstable","useTreeItemPersonaLayout_unstable","props","ref","media","children","content","description","treeItemLayoutState","iconBefore","iconAfter","size","ctx","components","expandIcon","root","aside","actions","avatarSize","required","defaultProps"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,uBAAuB,QAAQ,iBAAiB;AACzD,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,0BAA0B,QAAQ,sCAAsC;AAEjF;;;;;;;;CAQC,GACD,OAAO,MAAMC,oCAAoC,CAC/CC,OACAC,MAC+B;IAC/B,MAAM,EAAEC,MAAK,EAAEC,SAAQ,EAAEC,QAAO,EAAEC,YAAW,EAAE,GAAGL;IAElD,MAAMM,sBAAsBR,2BAC1B;QACE,GAAGE,KAAK;QACRO,YAAY,IAAI;QAChBC,WAAW,IAAI;IACjB,GACAP;IAGF,MAAMQ,OAAOb,wBAAwBc,CAAAA,MAAOA,IAAID,IAAI;IACpD,OAAO;QACL,GAAGH,mBAAmB;QACtBK,YAAY;YACVC,YAAY;YACZR,SAAS;YACTC,aAAa;YACbQ,MAAM;YACNX,OAAO;YACPY,OAAO;YACPC,SAAS;QACX;QACAC,YAAYnB,cAAc,CAACY,KAAK;QAChCL,SAAST,iBAAiBS,SAAS;YAAEa,UAAU,IAAI;YAAEC,cAAc;gBAAEf;YAAS;QAAE;QAChFD,OAAOP,iBAAiBO,OAAO;YAAEe,UAAU,IAAI;QAAC;QAChDZ,aAAaV,iBAAiBU;IAChC;AACF,EAAE"}
|
package/lib/contexts/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './treeContext';\nexport * from './treeItemContext';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB"}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './treeContext';\nexport * from './treeItemContext';\nexport * from './treeItemSlotsContext';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB;AAClC,cAAc,yBAAyB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
|
|
2
|
-
import {
|
|
2
|
+
import { ImmutableSet } from '../utils/ImmutableSet';
|
|
3
3
|
const defaultContextValue = {
|
|
4
4
|
level: 0,
|
|
5
|
-
openItems:
|
|
5
|
+
openItems: ImmutableSet.empty,
|
|
6
6
|
requestTreeResponse: noop,
|
|
7
7
|
appearance: 'subtle',
|
|
8
8
|
size: 'medium'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["treeContext.ts"],"sourcesContent":["import { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeNavigationData_unstable, TreeOpenChangeData } from '../Tree';\nimport {
|
|
1
|
+
{"version":3,"sources":["treeContext.ts"],"sourcesContent":["import { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeNavigationData_unstable, TreeOpenChangeData } from '../Tree';\nimport { TreeItemType, TreeItemValue } from '../TreeItem';\nimport { ImmutableSet } from '../utils/ImmutableSet';\n\nexport type TreeContextValue = {\n level: number;\n appearance: 'subtle' | 'subtle-alpha' | 'transparent';\n size: 'small' | 'medium';\n openItems: ImmutableSet<TreeItemValue>;\n /**\n * requests root Tree component to respond to some tree item event,\n */\n requestTreeResponse(request: TreeItemRequest): void;\n};\n\nexport type TreeItemRequest = { itemType: TreeItemType } & (\n | OmitWithoutExpanding<TreeOpenChangeData, 'open' | 'openItems'>\n | TreeNavigationData_unstable\n);\n\n// helper type that avoids the expansion of unions while inferring it, should work exactly the same as Omit\ntype OmitWithoutExpanding<P, K extends string | number | symbol> = P extends unknown ? Omit<P, K> : P;\n\nconst defaultContextValue: TreeContextValue = {\n level: 0,\n openItems: ImmutableSet.empty,\n requestTreeResponse: noop,\n appearance: 'subtle',\n size: 'medium',\n};\n\nfunction noop() {\n /* noop */\n}\n\nexport const TreeContext: Context<TreeContextValue | undefined> = createContext<TreeContextValue | undefined>(\n undefined,\n);\n\nexport const { Provider: TreeProvider } = TreeContext;\nexport const useTreeContext_unstable = <T>(selector: ContextSelector<TreeContextValue, T>): T =>\n useContextSelector(TreeContext, (ctx = defaultContextValue) => selector(ctx));\n"],"names":["createContext","useContextSelector","ImmutableSet","defaultContextValue","level","openItems","empty","requestTreeResponse","noop","appearance","size","TreeContext","undefined","Provider","TreeProvider","useTreeContext_unstable","selector","ctx"],"mappings":"AAAA,SAAmCA,aAAa,EAAEC,kBAAkB,QAAQ,mCAAmC;AAG/G,SAASC,YAAY,QAAQ,wBAAwB;AAqBrD,MAAMC,sBAAwC;IAC5CC,OAAO;IACPC,WAAWH,aAAaI,KAAK;IAC7BC,qBAAqBC;IACrBC,YAAY;IACZC,MAAM;AACR;AAEA,SAASF,OAAO;AACd,QAAQ,GACV;AAEA,OAAO,MAAMG,cAAqDX,cAChEY,WACA;AAEF,OAAO,MAAM,EAAEC,UAAUC,aAAY,EAAE,GAAGH,YAAY;AACtD,OAAO,MAAMI,0BAA0B,CAAIC,WACzCf,mBAAmBU,aAAa,CAACM,MAAMd,mBAAmB,GAAKa,SAASC,MAAM"}
|
|
@@ -2,10 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
|
|
3
3
|
const defaultContextValue = {
|
|
4
4
|
value: '',
|
|
5
|
-
isActionsVisible: false,
|
|
6
|
-
isAsideVisible: true,
|
|
7
|
-
actionsRef: React.createRef(),
|
|
8
|
-
expandIconRef: React.createRef(),
|
|
9
5
|
layoutRef: React.createRef(),
|
|
10
6
|
subtreeRef: React.createRef(),
|
|
11
7
|
itemType: 'leaf',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["treeItemContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeItemType } from '../TreeItem';\n\nexport type TreeItemContextValue = {\n
|
|
1
|
+
{"version":3,"sources":["treeItemContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeItemType } from '../TreeItem';\n\nexport type TreeItemContextValue = {\n layoutRef: React.Ref<HTMLDivElement>;\n subtreeRef: React.Ref<HTMLDivElement>;\n itemType: TreeItemType;\n value: string;\n open: boolean;\n};\n\nconst defaultContextValue: TreeItemContextValue = {\n value: '',\n layoutRef: React.createRef(),\n subtreeRef: React.createRef(),\n itemType: 'leaf',\n open: false,\n};\n\nexport const TreeItemContext: Context<TreeItemContextValue | undefined> = createContext<\n TreeItemContextValue | undefined\n>(undefined);\n\nexport const { Provider: TreeItemProvider } = TreeItemContext;\nexport const useTreeItemContext_unstable = <T>(selector: ContextSelector<TreeItemContextValue, T>): T =>\n useContextSelector(TreeItemContext, (ctx = defaultContextValue) => selector(ctx));\n"],"names":["React","createContext","useContextSelector","defaultContextValue","value","layoutRef","createRef","subtreeRef","itemType","open","TreeItemContext","undefined","Provider","TreeItemProvider","useTreeItemContext_unstable","selector","ctx"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAAmCC,aAAa,EAAEC,kBAAkB,QAAQ,mCAAmC;AAW/G,MAAMC,sBAA4C;IAChDC,OAAO;IACPC,WAAWL,MAAMM,SAAS;IAC1BC,YAAYP,MAAMM,SAAS;IAC3BE,UAAU;IACVC,MAAM,KAAK;AACb;AAEA,OAAO,MAAMC,kBAA6DT,cAExEU,WAAW;AAEb,OAAO,MAAM,EAAEC,UAAUC,iBAAgB,EAAE,GAAGH,gBAAgB;AAC9D,OAAO,MAAMI,8BAA8B,CAAIC,WAC7Cb,mBAAmBQ,iBAAiB,CAACM,MAAMb,mBAAmB,GAAKY,SAASC,MAAM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const defaultContextValue = {
|
|
3
|
+
actions: undefined,
|
|
4
|
+
aside: undefined,
|
|
5
|
+
expandIcon: undefined
|
|
6
|
+
};
|
|
7
|
+
export const TreeItemSlotsContext = React.createContext(undefined);
|
|
8
|
+
export const { Provider: TreeItemSlotsProvider } = TreeItemSlotsContext;
|
|
9
|
+
export const useTreeItemSlotsContext_unstable = ()=>React.useContext(TreeItemSlotsContext) || defaultContextValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["treeItemSlotsContext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { TreeItemSlots } from '../TreeItem';\n\nexport type TreeItemSlotsContextValue = Pick<TreeItemSlots, 'actions' | 'aside' | 'expandIcon'>;\n\nconst defaultContextValue: TreeItemSlotsContextValue = {\n actions: undefined,\n aside: undefined,\n expandIcon: undefined,\n};\n\nexport const TreeItemSlotsContext: React.Context<TreeItemSlotsContextValue | undefined> = React.createContext<\n TreeItemSlotsContextValue | undefined\n>(undefined);\n\nexport const { Provider: TreeItemSlotsProvider } = TreeItemSlotsContext;\nexport const useTreeItemSlotsContext_unstable = (): TreeItemSlotsContextValue =>\n React.useContext(TreeItemSlotsContext) || defaultContextValue;\n"],"names":["React","defaultContextValue","actions","undefined","aside","expandIcon","TreeItemSlotsContext","createContext","Provider","TreeItemSlotsProvider","useTreeItemSlotsContext_unstable","useContext"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAK/B,MAAMC,sBAAiD;IACrDC,SAASC;IACTC,OAAOD;IACPE,YAAYF;AACd;AAEA,OAAO,MAAMG,uBAA6EN,MAAMO,aAAa,CAE3GJ,WAAW;AAEb,OAAO,MAAM,EAAEK,UAAUC,sBAAqB,EAAE,GAAGH,qBAAqB;AACxE,OAAO,MAAMI,mCAAmC,IAC9CV,MAAMW,UAAU,CAACL,yBAAyBL,oBAAoB"}
|
package/lib/hooks/index.js
CHANGED
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useFlatTree';\nexport * from './useNestedTreeNavigation';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useFlatTree';\nexport * from './useNestedTreeNavigation';\nexport * from './useControllableOpenItems';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useControllableState } from '@fluentui/react-utilities';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ImmutableSet } from '../utils/ImmutableSet';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/ export function useControllableOpenItems(props) {
|
|
7
|
+
return useControllableState({
|
|
8
|
+
state: React.useMemo(()=>props.openItems && ImmutableSet.create(props.openItems), [
|
|
9
|
+
props.openItems
|
|
10
|
+
]),
|
|
11
|
+
defaultState: props.defaultOpenItems && (()=>ImmutableSet.create(props.defaultOpenItems)),
|
|
12
|
+
initialState: ImmutableSet.empty
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function createNextOpenItems(data, previousOpenItems) {
|
|
16
|
+
if (data.value === null) {
|
|
17
|
+
return previousOpenItems;
|
|
18
|
+
}
|
|
19
|
+
const previousOpenItemsHasId = previousOpenItems.has(data.value);
|
|
20
|
+
if (data.open ? previousOpenItemsHasId : !previousOpenItemsHasId) {
|
|
21
|
+
return previousOpenItems;
|
|
22
|
+
}
|
|
23
|
+
const nextOpenItems = ImmutableSet.create(previousOpenItems);
|
|
24
|
+
return data.open ? nextOpenItems.add(data.value) : nextOpenItems.delete(data.value);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useControllableOpenItems.ts"],"sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { ImmutableSet } from '../utils/ImmutableSet';\nimport type { TreeOpenChangeData, TreeProps } from '../components/Tree/Tree.types';\nimport type { TreeItemValue } from '../components/TreeItem/TreeItem.types';\n\n/**\n * @internal\n */\nexport function useControllableOpenItems(props: Pick<TreeProps, 'openItems' | 'defaultOpenItems'>) {\n return useControllableState({\n state: React.useMemo(() => props.openItems && ImmutableSet.create(props.openItems), [props.openItems]),\n defaultState: props.defaultOpenItems && (() => ImmutableSet.create(props.defaultOpenItems)),\n initialState: ImmutableSet.empty,\n });\n}\n\nexport function createNextOpenItems(\n data: Pick<TreeOpenChangeData, 'value' | 'open'>,\n previousOpenItems: ImmutableSet<TreeItemValue>,\n): ImmutableSet<TreeItemValue> {\n if (data.value === null) {\n return previousOpenItems;\n }\n const previousOpenItemsHasId = previousOpenItems.has(data.value);\n if (data.open ? previousOpenItemsHasId : !previousOpenItemsHasId) {\n return previousOpenItems;\n }\n const nextOpenItems = ImmutableSet.create(previousOpenItems);\n return data.open ? nextOpenItems.add(data.value) : nextOpenItems.delete(data.value);\n}\n"],"names":["useControllableState","React","ImmutableSet","useControllableOpenItems","props","state","useMemo","openItems","create","defaultState","defaultOpenItems","initialState","empty","createNextOpenItems","data","previousOpenItems","value","previousOpenItemsHasId","has","open","nextOpenItems","add","delete"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4BAA4B;AACjE,YAAYC,WAAW,QAAQ;AAC/B,SAASC,YAAY,QAAQ,wBAAwB;AAIrD;;CAEC,GACD,OAAO,SAASC,yBAAyBC,KAAwD,EAAE;IACjG,OAAOJ,qBAAqB;QAC1BK,OAAOJ,MAAMK,OAAO,CAAC,IAAMF,MAAMG,SAAS,IAAIL,aAAaM,MAAM,CAACJ,MAAMG,SAAS,GAAG;YAACH,MAAMG,SAAS;SAAC;QACrGE,cAAcL,MAAMM,gBAAgB,IAAK,CAAA,IAAMR,aAAaM,MAAM,CAACJ,MAAMM,gBAAgB,CAAA;QACzFC,cAAcT,aAAaU,KAAK;IAClC;AACF,CAAC;AAED,OAAO,SAASC,oBACdC,IAAgD,EAChDC,iBAA8C,EACjB;IAC7B,IAAID,KAAKE,KAAK,KAAK,IAAI,EAAE;QACvB,OAAOD;IACT,CAAC;IACD,MAAME,yBAAyBF,kBAAkBG,GAAG,CAACJ,KAAKE,KAAK;IAC/D,IAAIF,KAAKK,IAAI,GAAGF,yBAAyB,CAACA,sBAAsB,EAAE;QAChE,OAAOF;IACT,CAAC;IACD,MAAMK,gBAAgBlB,aAAaM,MAAM,CAACO;IAC1C,OAAOD,KAAKK,IAAI,GAAGC,cAAcC,GAAG,CAACP,KAAKE,KAAK,IAAII,cAAcE,MAAM,CAACR,KAAKE,KAAK,CAAC;AACrF,CAAC"}
|
package/lib/hooks/useFlatTree.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { createFlatTreeItems, VisibleFlatTreeItemGenerator } from '../utils/createFlatTreeItems';
|
|
4
4
|
import { treeDataTypes } from '../utils/tokens';
|
|
5
5
|
import { useFlatTreeNavigation } from './useFlatTreeNavigation';
|
|
6
|
-
import {
|
|
6
|
+
import { useControllableOpenItems } from './useControllableOpenItems';
|
|
7
7
|
import { dataTreeItemValueAttrName } from '../utils/getTreeItemValueFromElement';
|
|
8
8
|
/**
|
|
9
9
|
* this hook provides FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems
|
|
@@ -17,17 +17,17 @@ import { dataTreeItemValueAttrName } from '../utils/getTreeItemValueFromElement'
|
|
|
17
17
|
* @param flatTreeItemProps - a list of tree items
|
|
18
18
|
* @param options - in case control over the internal openItems is required
|
|
19
19
|
*/ export function useFlatTree_unstable(flatTreeItemProps, options = {}) {
|
|
20
|
-
const [openItems, updateOpenItems] = useOpenItemsState(options);
|
|
21
20
|
const flatTreeItems = React.useMemo(()=>createFlatTreeItems(flatTreeItemProps), [
|
|
22
21
|
flatTreeItemProps
|
|
23
22
|
]);
|
|
23
|
+
const [openItems, setOpenItems] = useControllableOpenItems(options);
|
|
24
24
|
const [navigate, navigationRef] = useFlatTreeNavigation(flatTreeItems);
|
|
25
25
|
const treeRef = React.useRef(null);
|
|
26
26
|
const handleOpenChange = useEventCallback((event, data)=>{
|
|
27
27
|
var _options_onOpenChange;
|
|
28
28
|
(_options_onOpenChange = options.onOpenChange) === null || _options_onOpenChange === void 0 ? void 0 : _options_onOpenChange.call(options, event, data);
|
|
29
29
|
if (!event.isDefaultPrevented()) {
|
|
30
|
-
|
|
30
|
+
setOpenItems(data.openItems);
|
|
31
31
|
}
|
|
32
32
|
event.preventDefault();
|
|
33
33
|
});
|