@fluentui/react-tree 9.0.0-beta.25 → 9.0.0-beta.26
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 +73 -1
- package/CHANGELOG.md +18 -2
- package/dist/index.d.ts +123 -9
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/useRootTree.js +24 -8
- package/lib/components/Tree/useRootTree.js.map +1 -1
- package/lib/components/Tree/useSubtree.js +4 -0
- package/lib/components/Tree/useSubtree.js.map +1 -1
- package/lib/components/Tree/useTreeContextValues.js +4 -2
- package/lib/components/Tree/useTreeContextValues.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.types.js.map +1 -1
- package/lib/components/TreeItem/useTreeItem.js +48 -4
- package/lib/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItemContextValues.js +5 -3
- 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 +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +10 -5
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +15 -8
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -1
- package/lib/contexts/treeContext.js +3 -0
- package/lib/contexts/treeContext.js.map +1 -1
- package/lib/contexts/treeItemSlotsContext.js.map +1 -1
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useFlatControllableCheckedItems.js +76 -0
- package/lib/hooks/useFlatControllableCheckedItems.js.map +1 -0
- package/lib/hooks/useFlatTree.js +16 -5
- package/lib/hooks/useFlatTree.js.map +1 -1
- package/lib/hooks/useNestedControllableCheckedItems.js +107 -0
- package/lib/hooks/useNestedControllableCheckedItems.js.map +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/ImmutableMap.js +37 -0
- package/lib/utils/ImmutableMap.js.map +1 -0
- package/lib/utils/ImmutableSet.js +3 -2
- package/lib/utils/ImmutableSet.js.map +1 -1
- package/lib/utils/createFlatTreeItems.js +60 -8
- package/lib/utils/createFlatTreeItems.js.map +1 -1
- package/lib/utils/tokens.js +2 -1
- package/lib/utils/tokens.js.map +1 -1
- package/lib-commonjs/components/Tree/useRootTree.js +23 -7
- package/lib-commonjs/components/Tree/useRootTree.js.map +1 -1
- package/lib-commonjs/components/Tree/useSubtree.js +4 -0
- package/lib-commonjs/components/Tree/useSubtree.js.map +1 -1
- package/lib-commonjs/components/Tree/useTreeContextValues.js +4 -2
- package/lib-commonjs/components/Tree/useTreeContextValues.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItem.js +48 -4
- package/lib-commonjs/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js +5 -3
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js +11 -6
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +12 -8
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -1
- package/lib-commonjs/contexts/treeContext.js +3 -0
- package/lib-commonjs/contexts/treeContext.js.map +1 -1
- package/lib-commonjs/hooks/index.js +2 -0
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useFlatControllableCheckedItems.js +91 -0
- package/lib-commonjs/hooks/useFlatControllableCheckedItems.js.map +1 -0
- package/lib-commonjs/hooks/useFlatTree.js +14 -3
- package/lib-commonjs/hooks/useFlatTree.js.map +1 -1
- package/lib-commonjs/hooks/useNestedControllableCheckedItems.js +116 -0
- package/lib-commonjs/hooks/useNestedControllableCheckedItems.js.map +1 -0
- package/lib-commonjs/utils/ImmutableMap.js +45 -0
- package/lib-commonjs/utils/ImmutableMap.js.map +1 -0
- package/lib-commonjs/utils/ImmutableSet.js +3 -2
- package/lib-commonjs/utils/ImmutableSet.js.map +1 -1
- package/lib-commonjs/utils/createFlatTreeItems.js +60 -8
- package/lib-commonjs/utils/createFlatTreeItems.js.map +1 -1
- package/lib-commonjs/utils/tokens.js +2 -1
- package/lib-commonjs/utils/tokens.js.map +1 -1
- package/package.json +9 -7
|
@@ -3,9 +3,10 @@ import { getNativeElementProps, isResolvedShorthand, resolveShorthand, useContro
|
|
|
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
|
-
import { treeDataTypes } from '../../utils/tokens';
|
|
7
6
|
import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';
|
|
8
7
|
import { TreeItemChevron } from '../TreeItemChevron';
|
|
8
|
+
import { Space } from '@fluentui/keyboard-keys';
|
|
9
|
+
import { treeDataTypes } from '../../utils/tokens';
|
|
9
10
|
/**
|
|
10
11
|
* Create the state required to render TreeItem.
|
|
11
12
|
*
|
|
@@ -39,11 +40,15 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
39
40
|
const handleActionsRef = (actionsElement)=>{
|
|
40
41
|
setAsideVisible(actionsElement === null);
|
|
41
42
|
};
|
|
42
|
-
const open = useTreeContext_unstable((ctx)=>ctx.openItems.has(value));
|
|
43
43
|
const actionsRef = React.useRef(null);
|
|
44
44
|
const expandIconRef = React.useRef(null);
|
|
45
45
|
const layoutRef = React.useRef(null);
|
|
46
46
|
const subtreeRef = React.useRef(null);
|
|
47
|
+
const selectionRef = React.useRef(null);
|
|
48
|
+
const open = useTreeContext_unstable((ctx)=>ctx.openItems.has(value));
|
|
49
|
+
var _ctx_checkedItems_get;
|
|
50
|
+
const checked = useTreeContext_unstable((ctx)=>(_ctx_checkedItems_get = ctx.checkedItems.get(value)) !== null && _ctx_checkedItems_get !== void 0 ? _ctx_checkedItems_get : false);
|
|
51
|
+
const selectionMode = useTreeContext_unstable((ctx)=>ctx.selectionMode);
|
|
47
52
|
const actionsRefs = useMergedRefs(isResolvedShorthand(actions) ? actions.ref : undefined, handleActionsRef, actionsRef);
|
|
48
53
|
const expandIconRefs = useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef);
|
|
49
54
|
const handleClick = useEventCallback((event)=>{
|
|
@@ -59,6 +64,10 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
59
64
|
if (isEventFromSubtree) {
|
|
60
65
|
return;
|
|
61
66
|
}
|
|
67
|
+
const isEventFromSelection = selectionRef.current && elementContains(selectionRef.current, event.target);
|
|
68
|
+
if (isEventFromSelection) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
62
71
|
const isFromExpandIcon = expandIconRef.current && elementContains(expandIconRef.current, event.target);
|
|
63
72
|
requestTreeResponse({
|
|
64
73
|
event,
|
|
@@ -75,6 +84,13 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
75
84
|
return;
|
|
76
85
|
}
|
|
77
86
|
switch(event.key){
|
|
87
|
+
case Space:
|
|
88
|
+
if (selectionMode !== 'none') {
|
|
89
|
+
var _selectionRef_current;
|
|
90
|
+
(_selectionRef_current = selectionRef.current) === null || _selectionRef_current === void 0 ? void 0 : _selectionRef_current.click();
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
78
94
|
case treeDataTypes.End:
|
|
79
95
|
case treeDataTypes.Home:
|
|
80
96
|
case treeDataTypes.Enter:
|
|
@@ -117,6 +133,22 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
117
133
|
return setActionsVisible(false);
|
|
118
134
|
}
|
|
119
135
|
});
|
|
136
|
+
const handleChange = useEventCallback((event)=>{
|
|
137
|
+
if (event.isDefaultPrevented()) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target);
|
|
141
|
+
if (isEventFromSubtree) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
requestTreeResponse({
|
|
145
|
+
event,
|
|
146
|
+
value,
|
|
147
|
+
itemType,
|
|
148
|
+
type: 'Change',
|
|
149
|
+
target: event.currentTarget
|
|
150
|
+
});
|
|
151
|
+
});
|
|
120
152
|
const isBranch = itemType === 'branch';
|
|
121
153
|
const actionsSlot = React.useMemo(()=>isActionsVisible ? resolveShorthand(actions) : undefined, [
|
|
122
154
|
actions,
|
|
@@ -159,16 +191,28 @@ import { TreeItemChevron } from '../TreeItemChevron';
|
|
|
159
191
|
role: 'treeitem',
|
|
160
192
|
'aria-level': level,
|
|
161
193
|
[dataTreeItemValueAttrName]: value,
|
|
194
|
+
'aria-checked': selectionMode === 'multiselect' ? checked : undefined,
|
|
195
|
+
'aria-selected': selectionMode === 'single' ? checked : undefined,
|
|
162
196
|
'aria-expanded': isBranch ? open : undefined,
|
|
163
197
|
onClick: handleClick,
|
|
164
198
|
onKeyDown: handleKeyDown,
|
|
165
199
|
onMouseOver: handleActionsVisible,
|
|
166
200
|
onFocus: handleActionsVisible,
|
|
167
201
|
onMouseOut: handleActionsInvisible,
|
|
168
|
-
onBlur: handleActionsInvisible
|
|
202
|
+
onBlur: handleActionsInvisible,
|
|
203
|
+
onChange: handleChange
|
|
169
204
|
}),
|
|
170
205
|
actions: actionsSlot,
|
|
171
206
|
aside: asideSlot,
|
|
172
|
-
expandIcon: expandIconSlot
|
|
207
|
+
expandIcon: expandIconSlot,
|
|
208
|
+
selector: selectionMode === 'none' ? undefined : resolveShorthand(selectionMode === 'multiselect' ? props.checkboxIndicator : props.radioIndicator, {
|
|
209
|
+
required: true,
|
|
210
|
+
defaultProps: {
|
|
211
|
+
checked,
|
|
212
|
+
tabIndex: -1,
|
|
213
|
+
'aria-hidden': true,
|
|
214
|
+
ref: selectionRef
|
|
215
|
+
}
|
|
216
|
+
})
|
|
173
217
|
};
|
|
174
218
|
}
|
|
@@ -1 +1 @@
|
|
|
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,qBAAqB;AAErD;;;;;;;;CA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C;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
|
+
{"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 { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';\nimport { TreeItemChevron } from '../TreeItemChevron';\nimport { Space } from '@fluentui/keyboard-keys';\nimport { treeDataTypes } from '../../utils/tokens';\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 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 const selectionRef = React.useRef<HTMLInputElement>(null);\n\n const open = useTreeContext_unstable(ctx => ctx.openItems.has(value));\n const checked = useTreeContext_unstable(ctx => ctx.checkedItems.get(value) ?? false);\n const selectionMode = useTreeContext_unstable(ctx => ctx.selectionMode);\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 isEventFromSelection = selectionRef.current && elementContains(selectionRef.current, event.target as Node);\n if (isEventFromSelection) {\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 Space:\n if (selectionMode !== 'none') {\n selectionRef.current?.click();\n event.preventDefault();\n }\n return;\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 handleChange = useEventCallback((event: React.ChangeEvent<HTMLInputElement>) => {\n if (event.isDefaultPrevented()) {\n return;\n }\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (isEventFromSubtree) {\n return;\n }\n requestTreeResponse({ event, value, itemType, type: 'Change', target: event.currentTarget });\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-checked': selectionMode === 'multiselect' ? checked : undefined,\n 'aria-selected': selectionMode === 'single' ? checked : undefined,\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 onChange: handleChange,\n }),\n actions: actionsSlot,\n aside: asideSlot,\n expandIcon: expandIconSlot,\n selector:\n selectionMode === 'none'\n ? undefined\n : resolveShorthand(selectionMode === 'multiselect' ? props.checkboxIndicator : props.radioIndicator, {\n required: true,\n defaultProps: {\n checked,\n tabIndex: -1,\n 'aria-hidden': true,\n ref: selectionRef,\n // onChange: handleChange,\n },\n }),\n };\n}\n"],"names":["React","getNativeElementProps","isResolvedShorthand","resolveShorthand","useControllableState","useId","useMergedRefs","useEventCallback","elementContains","useTreeContext_unstable","dataTreeItemValueAttrName","TreeItemChevron","Space","treeDataTypes","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","actionsRef","useRef","expandIconRef","layoutRef","subtreeRef","selectionRef","open","openItems","has","checked","checkedItems","get","selectionMode","actionsRefs","expandIconRefs","handleClick","event","isDefaultPrevented","isEventFromActions","current","target","isEventFromSubtree","isEventFromSelection","isFromExpandIcon","currentTarget","type","ExpandIconClick","Click","handleKeyDown","key","click","preventDefault","End","Home","Enter","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","isTypeAheadCharacter","length","match","altKey","ctrlKey","metaKey","TypeAhead","handleActionsVisible","isTargetFromSubtree","Boolean","handleActionsInvisible","isRelatedTargetFromActions","relatedTarget","handleChange","isBranch","actionsSlot","useMemo","asideSlot","expandIconSlot","required","defaultProps","children","components","root","tabIndex","role","onMouseOver","onFocus","onMouseOut","onBlur","onChange","selector","checkboxIndicator","radioIndicator"],"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,uBAA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;YAC3B4E,UAAUL;YACVM,cAAc;gBACZC,wBAAU,oBAAC7F;gBACX,eAAe,IAAI;YACrB;QACF,IACF;QAACe;QAAYuE;KAAS;IAExB,IAAII,gBAAgB;QAClBA,eAAerF,GAAG,GAAG0C;IACvB,CAAC;IAED,OAAO;QACLtC;QACA8B;QACAF;QACAD;QACAtB;QACAN;QACAsF,YAAY;YACVC,MAAM;QACR;QACAA,MAAMzG,sBAAsBuB,IAAI;YAC9BmF,UAAU,CAAC;YACX,GAAG/E,IAAI;YACPZ;YACA4F,MAAM;YACN,cAAczF;YACd,CAACT,0BAA0B,EAAEU;YAC7B,gBAAgBoC,kBAAkB,gBAAgBH,UAAUpB,SAAS;YACrE,iBAAiBuB,kBAAkB,WAAWH,UAAUpB,SAAS;YACjE,iBAAiBgE,WAAW/C,OAAOjB,SAAS;YAC5CX,SAASqC;YACTpC,WAAWiD;YACXqC,aAAanB;YACboB,SAASpB;YACTqB,YAAYlB;YACZmB,QAAQnB;YACRoB,UAAUjB;QACZ;QACAjE,SAASmE;QACTvE,OAAOyE;QACP1E,YAAY2E;QACZa,UACE1D,kBAAkB,SACdvB,YACA9B,iBAAiBqD,kBAAkB,gBAAgBzC,MAAMoG,iBAAiB,GAAGpG,MAAMqG,cAAc,EAAE;YACjGd,UAAU,IAAI;YACdC,cAAc;gBACZlD;gBACAsD,UAAU,CAAC;gBACX,eAAe,IAAI;gBACnB3F,KAAKiC;YAEP;QACF,EAAE;IACV;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
export function useTreeItemContextValues_unstable(state) {
|
|
3
|
-
const { value , itemType , layoutRef , subtreeRef , open , actions , aside , expandIcon } = state;
|
|
3
|
+
const { value , itemType , layoutRef , subtreeRef , open , actions , aside , expandIcon , selector } = state;
|
|
4
4
|
/**
|
|
5
5
|
* This context is created with "@fluentui/react-context-selector",
|
|
6
6
|
* there is no sense to memoize it
|
|
@@ -14,11 +14,13 @@ export function useTreeItemContextValues_unstable(state) {
|
|
|
14
14
|
const treeItemSlots = React.useMemo(()=>({
|
|
15
15
|
actions,
|
|
16
16
|
aside,
|
|
17
|
-
expandIcon
|
|
17
|
+
expandIcon,
|
|
18
|
+
selector
|
|
18
19
|
}), [
|
|
19
20
|
actions,
|
|
20
21
|
aside,
|
|
21
|
-
expandIcon
|
|
22
|
+
expandIcon,
|
|
23
|
+
selector
|
|
22
24
|
]);
|
|
23
25
|
return {
|
|
24
26
|
treeItem,
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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, selector } = 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, selector }),\n [actions, aside, expandIcon, selector],\n );\n\n return { treeItem, treeItemSlots };\n}\n"],"names":["React","useTreeItemContextValues_unstable","state","value","itemType","layoutRef","subtreeRef","open","actions","aside","expandIcon","selector","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,EAAEC,SAAQ,EAAE,GAAGT;IAE/F;;;GAGC,GACD,MAAMU,WAAiC;QACrCT;QACAC;QACAC;QACAC;QACAC;IACF;IAEA,MAAMM,gBAA2Cb,MAAMc,OAAO,CAC5D,IAAO,CAAA;YAAEN;YAASC;YAAOC;YAAYC;QAAS,CAAA,GAC9C;QAACH;QAASC;QAAOC;QAAYC;KAAS;IAGxC,OAAO;QAAEC;QAAUC;IAAc;AACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { ButtonContextValue } from '@fluentui/react-button';\nimport {
|
|
1
|
+
{"version":3,"sources":["TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { ButtonContextValue } from '@fluentui/react-button';\nimport { TreeItemSlotsContextValue } from '../../contexts/treeItemSlotsContext';\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 & TreeItemSlotsContextValue;\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"}
|
|
@@ -5,7 +5,7 @@ import { ButtonContextProvider } from '@fluentui/react-button';
|
|
|
5
5
|
* Render the final JSX of TreeItemLayout
|
|
6
6
|
*/ export const renderTreeItemLayout_unstable = (state)=>{
|
|
7
7
|
const { slots , slotProps } = getSlotsNext(state);
|
|
8
|
-
return /*#__PURE__*/ createElement(slots.root, slotProps.root, slots.expandIcon && /*#__PURE__*/ createElement(slots.expandIcon, slotProps.expandIcon), slots.iconBefore && /*#__PURE__*/ createElement(slots.iconBefore, slotProps.iconBefore), /*#__PURE__*/ createElement(slots.content, slotProps.content, slotProps.root.children), slots.iconAfter && /*#__PURE__*/ createElement(slots.iconAfter, slotProps.iconAfter), /*#__PURE__*/ createElement(ButtonContextProvider, {
|
|
8
|
+
return /*#__PURE__*/ createElement(slots.root, slotProps.root, slots.expandIcon && /*#__PURE__*/ createElement(slots.expandIcon, slotProps.expandIcon), slots.selector && /*#__PURE__*/ createElement(slots.selector, slotProps.selector), slots.iconBefore && /*#__PURE__*/ createElement(slots.iconBefore, slotProps.iconBefore), /*#__PURE__*/ createElement(slots.content, slotProps.content, slotProps.root.children), slots.iconAfter && /*#__PURE__*/ createElement(slots.iconAfter, slotProps.iconAfter), /*#__PURE__*/ createElement(ButtonContextProvider, {
|
|
9
9
|
value: state.buttonContextValue
|
|
10
10
|
}, slots.actions && /*#__PURE__*/ createElement(slots.actions, slotProps.actions), slots.aside && /*#__PURE__*/ createElement(slots.aside, slotProps.aside)));
|
|
11
11
|
};
|
|
@@ -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, 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,
|
|
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.selector && <slots.selector {...slotProps.selector} />}\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","selector","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,QAAQ,kBAAI,AAhBzB,cAgB0BJ,MAAMI,QAAQ,EAAKH,UAAUG,QAAQ,GACxDJ,MAAMK,UAAU,kBAAI,AAjB3B,cAiB4BL,MAAMK,UAAU,EAAKJ,UAAUI,UAAU,iBAC/D,AAlBN,cAkBOL,MAAMM,OAAO,EAAKL,UAAUK,OAAO,EAAGL,UAAUC,IAAI,CAACK,QAAQ,GAC7DP,MAAMQ,SAAS,kBAAI,AAnB1B,cAmB2BR,MAAMQ,SAAS,EAAKP,UAAUO,SAAS,iBAC5D,AApBN,cAoBOX;QAAsBY,OAAOV,MAAMW,kBAAkB;OACnDV,MAAMW,OAAO,kBAAI,AArB1B,cAqB2BX,MAAMW,OAAO,EAAKV,UAAUU,OAAO,GACrDX,MAAMY,KAAK,kBAAI,AAtBxB,cAsByBZ,MAAMY,KAAK,EAAKX,UAAUW,KAAK;AAIxD,EAAE"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
|
-
import { useTreeItemContext_unstable } from '../../contexts
|
|
4
|
-
import {
|
|
3
|
+
import { useTreeItemContext_unstable, useTreeContext_unstable, useTreeItemSlotsContext_unstable } from '../../contexts';
|
|
4
|
+
import { Checkbox } from '@fluentui/react-checkbox';
|
|
5
|
+
import { Radio } from '@fluentui/react-radio';
|
|
5
6
|
/**
|
|
6
7
|
* Create the state required to render TreeItemLayout.
|
|
7
8
|
*
|
|
@@ -12,8 +13,9 @@ import { useTreeItemSlotsContext_unstable } from '../../contexts/treeItemSlotsCo
|
|
|
12
13
|
* @param ref - reference to root HTMLElement of TreeItemLayout
|
|
13
14
|
*/ export const useTreeItemLayout_unstable = (props, ref)=>{
|
|
14
15
|
const { content , iconAfter , iconBefore , as ='span' } = props;
|
|
15
|
-
const { actions , aside , expandIcon } = useTreeItemSlotsContext_unstable();
|
|
16
|
+
const { actions , aside , expandIcon , selector } = useTreeItemSlotsContext_unstable();
|
|
16
17
|
const layoutRef = useTreeItemContext_unstable((ctx)=>ctx.layoutRef);
|
|
18
|
+
const selectionMode = useTreeContext_unstable((ctx)=>ctx.selectionMode);
|
|
17
19
|
return {
|
|
18
20
|
components: {
|
|
19
21
|
root: 'div',
|
|
@@ -22,7 +24,9 @@ import { useTreeItemSlotsContext_unstable } from '../../contexts/treeItemSlotsCo
|
|
|
22
24
|
content: 'div',
|
|
23
25
|
iconAfter: 'div',
|
|
24
26
|
actions: 'div',
|
|
25
|
-
aside: 'div'
|
|
27
|
+
aside: 'div',
|
|
28
|
+
// Casting here to a union between checkbox and radio
|
|
29
|
+
selector: selectionMode === 'multiselect' ? Checkbox : Radio
|
|
26
30
|
},
|
|
27
31
|
buttonContextValue: {
|
|
28
32
|
size: 'small'
|
|
@@ -46,6 +50,7 @@ import { useTreeItemSlotsContext_unstable } from '../../contexts/treeItemSlotsCo
|
|
|
46
50
|
}),
|
|
47
51
|
aside: resolveShorthand(aside),
|
|
48
52
|
actions: resolveShorthand(actions),
|
|
49
|
-
expandIcon: resolveShorthand(expandIcon)
|
|
53
|
+
expandIcon: resolveShorthand(expandIcon),
|
|
54
|
+
selector: resolveShorthand(selector)
|
|
50
55
|
};
|
|
51
56
|
};
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
1
|
+
{"version":3,"sources":["useTreeItemLayout.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport { useTreeItemContext_unstable, useTreeContext_unstable, useTreeItemSlotsContext_unstable } from '../../contexts';\nimport type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types';\nimport { Checkbox, CheckboxProps } from '@fluentui/react-checkbox';\nimport { Radio, RadioProps } from '@fluentui/react-radio';\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, selector } = useTreeItemSlotsContext_unstable();\n\n const layoutRef = useTreeItemContext_unstable(ctx => ctx.layoutRef);\n const selectionMode = useTreeContext_unstable(ctx => ctx.selectionMode);\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 // Casting here to a union between checkbox and radio\n selector: (selectionMode === 'multiselect' ? Checkbox : Radio) as React.ElementType<CheckboxProps | RadioProps>,\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 selector: resolveShorthand(selector),\n };\n};\n"],"names":["React","getNativeElementProps","resolveShorthand","useMergedRefs","useTreeItemContext_unstable","useTreeContext_unstable","useTreeItemSlotsContext_unstable","Checkbox","Radio","useTreeItemLayout_unstable","props","ref","content","iconAfter","iconBefore","as","actions","aside","expandIcon","selector","layoutRef","ctx","selectionMode","components","root","buttonContextValue","size","defaultProps","required"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AACnG,SAASC,2BAA2B,EAAEC,uBAAuB,EAAEC,gCAAgC,QAAQ,iBAAiB;AAExH,SAASC,QAAQ,QAAuB,2BAA2B;AACnE,SAASC,KAAK,QAAoB,wBAAwB;AAE1D;;;;;;;;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,EAAEC,SAAQ,EAAE,GAAGb;IAEjD,MAAMc,YAAYhB,4BAA4BiB,CAAAA,MAAOA,IAAID,SAAS;IAClE,MAAME,gBAAgBjB,wBAAwBgB,CAAAA,MAAOA,IAAIC,aAAa;IAEtE,OAAO;QACLC,YAAY;YACVC,MAAM;YACNN,YAAY;YACZJ,YAAY;YACZF,SAAS;YACTC,WAAW;YACXG,SAAS;YACTC,OAAO;YACP,qDAAqD;YACrDE,UAAWG,kBAAkB,gBAAgBf,WAAWC,KAAK;QAC/D;QACAiB,oBAAoB;YAAEC,MAAM;QAAQ;QACpCF,MAAMvB,sBAAsBc,IAAI;YAAE,GAAGL,KAAK;YAAEC,KAAKR,cAAcQ,KAAKS;QAAW;QAC/EN,YAAYZ,iBAAiBY,YAAY;YAAEa,cAAc;gBAAE,eAAe,IAAI;YAAC;QAAE;QACjFf,SAASV,iBAAiBU,SAAS;YAAEgB,UAAU,IAAI;QAAC;QACpDf,WAAWX,iBAAiBW,WAAW;YAAEc,cAAc;gBAAE,eAAe,IAAI;YAAC;QAAE;QAC/EV,OAAOf,iBAAiBe;QACxBD,SAASd,iBAAiBc;QAC1BE,YAAYhB,iBAAiBgB;QAC7BC,UAAUjB,iBAAiBiB;IAC7B;AACF,EAAE"}
|
|
@@ -10,7 +10,8 @@ export const treeItemLayoutClassNames = {
|
|
|
10
10
|
iconAfter: 'fui-TreeItemLayout__iconAfter',
|
|
11
11
|
expandIcon: 'fui-TreeItemLayout__expandIcon',
|
|
12
12
|
aside: 'fui-TreeItemLayout__aside',
|
|
13
|
-
actions: 'fui-TreeItemLayout__actions'
|
|
13
|
+
actions: 'fui-TreeItemLayout__actions',
|
|
14
|
+
selector: 'fui-TreeItemLayout__selector'
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
17
|
* Styles for the root slot
|
|
@@ -192,7 +193,10 @@ export const useTreeItemLayoutStyles_unstable = state => {
|
|
|
192
193
|
iconAfter,
|
|
193
194
|
iconBefore,
|
|
194
195
|
expandIcon,
|
|
195
|
-
root
|
|
196
|
+
root,
|
|
197
|
+
aside,
|
|
198
|
+
actions,
|
|
199
|
+
selector
|
|
196
200
|
} = state;
|
|
197
201
|
const rootStyles = useRootStyles();
|
|
198
202
|
const actionsStyles = useActionsStyles();
|
|
@@ -216,14 +220,17 @@ export const useTreeItemLayoutStyles_unstable = state => {
|
|
|
216
220
|
if (iconAfter) {
|
|
217
221
|
iconAfter.className = mergeClasses(treeItemLayoutClassNames.iconAfter, iconStyles.base, iconAfterStyles[size], iconAfter.className);
|
|
218
222
|
}
|
|
219
|
-
if (
|
|
220
|
-
|
|
223
|
+
if (actions) {
|
|
224
|
+
actions.className = mergeClasses(treeItemLayoutClassNames.actions, actionsStyles.base, actions.className);
|
|
221
225
|
}
|
|
222
|
-
if (
|
|
223
|
-
|
|
226
|
+
if (aside) {
|
|
227
|
+
aside.className = mergeClasses(treeItemLayoutClassNames.aside, asideStyles.base, aside.className);
|
|
224
228
|
}
|
|
225
|
-
if (
|
|
226
|
-
|
|
229
|
+
if (expandIcon) {
|
|
230
|
+
expandIcon.className = mergeClasses(treeItemLayoutClassNames.expandIcon, expandIconStyles.base, expandIcon.className);
|
|
231
|
+
}
|
|
232
|
+
if (selector) {
|
|
233
|
+
selector.className = mergeClasses(treeItemLayoutClassNames.selector, selector.className);
|
|
227
234
|
}
|
|
228
235
|
return state;
|
|
229
236
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__styles","mergeClasses","shorthands","tokens","typographyStyles","useTreeContext_unstable","treeItemLevelToken","useTreeItemContext_unstable","treeItemLayoutClassNames","root","iconBefore","content","iconAfter","expandIcon","aside","actions","useRootStyles","base","mc9l5x","Bt984gj","sshi5w","B7ck84d","Ijaq50","Br312pm","nk6f5a","Bw0ie65","Bbmb7ep","Beyfa6y","B7oj6ja","Btl43ni","lj723h","ecr2s2","qya0sb","Bi91k9c","Jwef8y","Becwuud","leaf","uwmqm3","branch","medium","Bahqtrf","Be2twd7","Bhrd7zp","Bg96gwp","small","subtle","transparent","De3pzq","d","a","h","useActionsStyles","Frg6f3","qhf8xq","Bj3rh1h","z8tnut","z189sj","Byoj8tv","useAsideStyles","i8kkvl","Belr9w4","useExpandIconStyles","Brf1p80","Bf4jedk","sj55zd","Bh6795r","Bnnss6s","xawz","useContentStyles","useIconStyles","useIconBeforeStyles","useIconAfterStyles","useTreeItemLayoutStyles_unstable","state","rootStyles","actionsStyles","asideStyles","contentStyles","expandIconStyles","iconStyles","iconBeforeStyles","iconAfterStyles","size","ctx","appearance","itemType","className"],"sources":["useTreeItemLayoutStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\nimport { useTreeContext_unstable } from '../../contexts/treeContext';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport { useTreeItemContext_unstable } from '../../contexts/treeItemContext';\nexport const treeItemLayoutClassNames = {\n root: 'fui-TreeItemLayout',\n iconBefore: 'fui-TreeItemLayout__iconBefore',\n content: 'fui-TreeItemLayout__content',\n iconAfter: 'fui-TreeItemLayout__iconAfter',\n expandIcon: 'fui-TreeItemLayout__expandIcon',\n aside: 'fui-TreeItemLayout__aside',\n actions: 'fui-TreeItemLayout__actions'\n};\n/**\n * Styles for the root slot\n */ const useRootStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n minHeight: '32px',\n boxSizing: 'border-box',\n ...shorthands.gridArea('layout'),\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n ':active': {\n color: tokens.colorNeutralForeground2Pressed,\n backgroundColor: tokens.colorSubtleBackgroundPressed,\n // TODO: stop using treeItemLayoutClassNames.expandIcon for styling\n [`& .${treeItemLayoutClassNames.expandIcon}`]: {\n color: tokens.colorNeutralForeground3Pressed\n }\n },\n ':hover': {\n color: tokens.colorNeutralForeground2Hover,\n backgroundColor: tokens.colorSubtleBackgroundHover,\n // TODO: stop using treeItemLayoutClassNames.expandIcon for styling\n [`& .${treeItemLayoutClassNames.expandIcon}`]: {\n color: tokens.colorNeutralForeground3Hover\n }\n }\n },\n leaf: {\n paddingLeft: `calc(var(${treeItemLevelToken}, 1) * ${tokens.spacingHorizontalXXL})`\n },\n branch: {\n paddingLeft: `calc((var(${treeItemLevelToken}, 1) - 1) * ${tokens.spacingHorizontalXXL})`\n },\n medium: {\n ...typographyStyles.body1\n },\n small: {\n minHeight: '24px',\n ...typographyStyles.caption1\n },\n // Appearance variations\n subtle: {},\n 'subtle-alpha': {\n ':hover': {\n backgroundColor: tokens.colorSubtleBackgroundLightAlphaHover\n },\n ':active': {\n backgroundColor: tokens.colorSubtleBackgroundLightAlphaPressed\n }\n },\n transparent: {\n backgroundColor: tokens.colorTransparentBackground,\n ':hover': {\n backgroundColor: tokens.colorTransparentBackgroundHover\n },\n ':active': {\n backgroundColor: tokens.colorTransparentBackgroundPressed\n }\n }\n});\n/**\n * Styles for the action icon slot\n */ const useActionsStyles = makeStyles({\n base: {\n display: 'flex',\n marginLeft: 'auto',\n position: 'relative',\n zIndex: 1,\n ...shorthands.gridArea('aside'),\n ...shorthands.padding(0, tokens.spacingHorizontalS)\n }\n});\n/**\n * Styles for the action icon slot\n */ const useAsideStyles = makeStyles({\n base: {\n display: 'flex',\n marginLeft: 'auto',\n alignItems: 'center',\n zIndex: 0,\n ...shorthands.gridArea('aside'),\n ...shorthands.padding(0, tokens.spacingHorizontalM),\n ...shorthands.gap(tokens.spacingHorizontalXS)\n }\n});\n/**\n * Styles for the expand icon slot\n */ const useExpandIconStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minWidth: '24px',\n boxSizing: 'border-box',\n color: tokens.colorNeutralForeground3,\n ...shorthands.flex(0, 0, 'auto'),\n ...shorthands.padding(tokens.spacingVerticalXS, 0)\n }\n});\n/**\n * Styles for the content slot\n */ const useContentStyles = makeStyles({\n base: {\n ...shorthands.padding(0, tokens.spacingHorizontalXXS)\n }\n});\n/**\n * Styles for the before/after icon slot\n */ const useIconStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n color: tokens.colorNeutralForeground2,\n lineHeight: tokens.lineHeightBase500,\n fontSize: tokens.fontSizeBase500\n }\n});\nconst useIconBeforeStyles = makeStyles({\n medium: {\n paddingRight: tokens.spacingHorizontalXS\n },\n small: {\n paddingRight: tokens.spacingHorizontalXXS\n }\n});\nconst useIconAfterStyles = makeStyles({\n medium: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n small: {\n paddingLeft: tokens.spacingHorizontalXXS\n }\n});\n/**\n * Apply styling to the TreeItemLayout slots based on the state\n */ export const useTreeItemLayoutStyles_unstable = (state)=>{\n const { content , iconAfter , iconBefore , expandIcon , root } = state;\n const rootStyles = useRootStyles();\n const actionsStyles = useActionsStyles();\n const asideStyles = useAsideStyles();\n const contentStyles = useContentStyles();\n const expandIconStyles = useExpandIconStyles();\n const iconStyles = useIconStyles();\n const iconBeforeStyles = useIconBeforeStyles();\n const iconAfterStyles = useIconAfterStyles();\n const size = useTreeContext_unstable((ctx)=>ctx.size);\n const appearance = useTreeContext_unstable((ctx)=>ctx.appearance);\n const itemType = useTreeItemContext_unstable((ctx)=>ctx.itemType);\n root.className = mergeClasses(treeItemLayoutClassNames.root, rootStyles.base, rootStyles[appearance], rootStyles[size], rootStyles[itemType], root.className);\n content.className = mergeClasses(treeItemLayoutClassNames.content, contentStyles.base, content.className);\n if (expandIcon) {\n expandIcon.className = mergeClasses(treeItemLayoutClassNames.expandIcon, expandIconStyles.base, expandIcon.className);\n }\n if (iconBefore) {\n iconBefore.className = mergeClasses(treeItemLayoutClassNames.iconBefore, iconStyles.base, iconBeforeStyles[size], iconBefore.className);\n }\n if (iconAfter) {\n iconAfter.className = mergeClasses(treeItemLayoutClassNames.iconAfter, iconStyles.base, iconAfterStyles[size], iconAfter.className);\n }\n if (state.actions) {\n state.actions.className = mergeClasses(treeItemLayoutClassNames.actions, actionsStyles.base, state.actions.className);\n }\n if (state.aside) {\n state.aside.className = mergeClasses(treeItemLayoutClassNames.aside, asideStyles.base, state.aside.className);\n }\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(treeItemLayoutClassNames.expandIcon, expandIconStyles.base, state.expandIcon.className);\n }\n return state;\n};\n"],"mappings":"AAAA,SAAAA,QAAA,EAAqBC,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;AACrE,SAASC,MAAM,EAAEC,gBAAgB,QAAQ,uBAAuB;AAChE,SAASC,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,2BAA2B,QAAQ,gCAAgC;AAC5E,OAAO,MAAMC,wBAAwB,GAAG;EACpCC,IAAI,EAAE,oBAAoB;EAC1BC,UAAU,EAAE,gCAAgC;EAC5CC,OAAO,EAAE,6BAA6B;EACtCC,SAAS,EAAE,+BAA+B;EAC1CC,UAAU,EAAE,gCAAgC;EAC5CC,KAAK,EAAE,2BAA2B;EAClCC,OAAO,EAAE;AACb,CAAC;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AAC4E,SAAS,CAAC;EAC3I;EACA,IAAI1E,SAAS,EAAE;IACXA,SAAS,CAAC0E,SAAS,GAAGrF,YAAY,CAACO,wBAAwB,CAACI,SAAS,EAAEmE,UAAU,CAAC9D,IAAI,EAAEgE,eAAe,CAACC,IAAI,CAAC,EAAEtE,SAAS,CAAC0E,SAAS,CAAC;EACvI;EACA,IAAIb,KAAK,CAAC1D,OAAO,EAAE;IACf0D,KAAK,CAAC1D,OAAO,CAACuE,SAAS,GAAGrF,YAAY,CAACO,wBAAwB,CAACO,OAAO,EAAE4D,aAAa,CAAC1D,IAAI,EAAEwD,KAAK,CAAC1D,OAAO,CAACuE,SAAS,CAAC;EACzH;EACA,IAAIb,KAAK,CAAC3D,KAAK,EAAE;IACb2D,KAAK,CAAC3D,KAAK,CAACwE,SAAS,GAAGrF,YAAY,CAACO,wBAAwB,CAACM,KAAK,EAAE8D,WAAW,CAAC3D,IAAI,EAAEwD,KAAK,CAAC3D,KAAK,CAACwE,SAAS,CAAC;EACjH;EACA,IAAIb,KAAK,CAAC5D,UAAU,EAAE;IAClB4D,KAAK,CAAC5D,UAAU,CAACyE,SAAS,GAAGrF,YAAY,CAACO,wBAAwB,CAACK,UAAU,EAAEiE,gBAAgB,CAAC7D,IAAI,EAAEwD,KAAK,CAAC5D,UAAU,CAACyE,SAAS,CAAC;EACrI;EACA,OAAOb,KAAK;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"names":["__styles","mergeClasses","shorthands","tokens","typographyStyles","useTreeContext_unstable","treeItemLevelToken","useTreeItemContext_unstable","treeItemLayoutClassNames","root","iconBefore","content","iconAfter","expandIcon","aside","actions","selector","useRootStyles","base","mc9l5x","Bt984gj","sshi5w","B7ck84d","Ijaq50","Br312pm","nk6f5a","Bw0ie65","Bbmb7ep","Beyfa6y","B7oj6ja","Btl43ni","lj723h","ecr2s2","qya0sb","Bi91k9c","Jwef8y","Becwuud","leaf","uwmqm3","branch","medium","Bahqtrf","Be2twd7","Bhrd7zp","Bg96gwp","small","subtle","transparent","De3pzq","d","a","h","useActionsStyles","Frg6f3","qhf8xq","Bj3rh1h","z8tnut","z189sj","Byoj8tv","useAsideStyles","i8kkvl","Belr9w4","useExpandIconStyles","Brf1p80","Bf4jedk","sj55zd","Bh6795r","Bnnss6s","xawz","useContentStyles","useIconStyles","useIconBeforeStyles","useIconAfterStyles","useTreeItemLayoutStyles_unstable","state","rootStyles","actionsStyles","asideStyles","contentStyles","expandIconStyles","iconStyles","iconBeforeStyles","iconAfterStyles","size","ctx","appearance","itemType","className"],"sources":["useTreeItemLayoutStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\nimport { useTreeContext_unstable } from '../../contexts/treeContext';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport { useTreeItemContext_unstable } from '../../contexts/treeItemContext';\nexport const treeItemLayoutClassNames = {\n root: 'fui-TreeItemLayout',\n iconBefore: 'fui-TreeItemLayout__iconBefore',\n content: 'fui-TreeItemLayout__content',\n iconAfter: 'fui-TreeItemLayout__iconAfter',\n expandIcon: 'fui-TreeItemLayout__expandIcon',\n aside: 'fui-TreeItemLayout__aside',\n actions: 'fui-TreeItemLayout__actions',\n selector: 'fui-TreeItemLayout__selector'\n};\n/**\n * Styles for the root slot\n */ const useRootStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n minHeight: '32px',\n boxSizing: 'border-box',\n ...shorthands.gridArea('layout'),\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n ':active': {\n color: tokens.colorNeutralForeground2Pressed,\n backgroundColor: tokens.colorSubtleBackgroundPressed,\n // TODO: stop using treeItemLayoutClassNames.expandIcon for styling\n [`& .${treeItemLayoutClassNames.expandIcon}`]: {\n color: tokens.colorNeutralForeground3Pressed\n }\n },\n ':hover': {\n color: tokens.colorNeutralForeground2Hover,\n backgroundColor: tokens.colorSubtleBackgroundHover,\n // TODO: stop using treeItemLayoutClassNames.expandIcon for styling\n [`& .${treeItemLayoutClassNames.expandIcon}`]: {\n color: tokens.colorNeutralForeground3Hover\n }\n }\n },\n leaf: {\n paddingLeft: `calc(var(${treeItemLevelToken}, 1) * ${tokens.spacingHorizontalXXL})`\n },\n branch: {\n paddingLeft: `calc((var(${treeItemLevelToken}, 1) - 1) * ${tokens.spacingHorizontalXXL})`\n },\n medium: {\n ...typographyStyles.body1\n },\n small: {\n minHeight: '24px',\n ...typographyStyles.caption1\n },\n // Appearance variations\n subtle: {},\n 'subtle-alpha': {\n ':hover': {\n backgroundColor: tokens.colorSubtleBackgroundLightAlphaHover\n },\n ':active': {\n backgroundColor: tokens.colorSubtleBackgroundLightAlphaPressed\n }\n },\n transparent: {\n backgroundColor: tokens.colorTransparentBackground,\n ':hover': {\n backgroundColor: tokens.colorTransparentBackgroundHover\n },\n ':active': {\n backgroundColor: tokens.colorTransparentBackgroundPressed\n }\n }\n});\n/**\n * Styles for the action icon slot\n */ const useActionsStyles = makeStyles({\n base: {\n display: 'flex',\n marginLeft: 'auto',\n position: 'relative',\n zIndex: 1,\n ...shorthands.gridArea('aside'),\n ...shorthands.padding(0, tokens.spacingHorizontalS)\n }\n});\n/**\n * Styles for the action icon slot\n */ const useAsideStyles = makeStyles({\n base: {\n display: 'flex',\n marginLeft: 'auto',\n alignItems: 'center',\n zIndex: 0,\n ...shorthands.gridArea('aside'),\n ...shorthands.padding(0, tokens.spacingHorizontalM),\n ...shorthands.gap(tokens.spacingHorizontalXS)\n }\n});\n/**\n * Styles for the expand icon slot\n */ const useExpandIconStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minWidth: '24px',\n boxSizing: 'border-box',\n color: tokens.colorNeutralForeground3,\n ...shorthands.flex(0, 0, 'auto'),\n ...shorthands.padding(tokens.spacingVerticalXS, 0)\n }\n});\n/**\n * Styles for the content slot\n */ const useContentStyles = makeStyles({\n base: {\n ...shorthands.padding(0, tokens.spacingHorizontalXXS)\n }\n});\n/**\n * Styles for the before/after icon slot\n */ const useIconStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n color: tokens.colorNeutralForeground2,\n lineHeight: tokens.lineHeightBase500,\n fontSize: tokens.fontSizeBase500\n }\n});\nconst useIconBeforeStyles = makeStyles({\n medium: {\n paddingRight: tokens.spacingHorizontalXS\n },\n small: {\n paddingRight: tokens.spacingHorizontalXXS\n }\n});\nconst useIconAfterStyles = makeStyles({\n medium: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n small: {\n paddingLeft: tokens.spacingHorizontalXXS\n }\n});\n/**\n * Apply styling to the TreeItemLayout slots based on the state\n */ export const useTreeItemLayoutStyles_unstable = (state)=>{\n const { content , iconAfter , iconBefore , expandIcon , root , aside , actions , selector } = state;\n const rootStyles = useRootStyles();\n const actionsStyles = useActionsStyles();\n const asideStyles = useAsideStyles();\n const contentStyles = useContentStyles();\n const expandIconStyles = useExpandIconStyles();\n const iconStyles = useIconStyles();\n const iconBeforeStyles = useIconBeforeStyles();\n const iconAfterStyles = useIconAfterStyles();\n const size = useTreeContext_unstable((ctx)=>ctx.size);\n const appearance = useTreeContext_unstable((ctx)=>ctx.appearance);\n const itemType = useTreeItemContext_unstable((ctx)=>ctx.itemType);\n root.className = mergeClasses(treeItemLayoutClassNames.root, rootStyles.base, rootStyles[appearance], rootStyles[size], rootStyles[itemType], root.className);\n content.className = mergeClasses(treeItemLayoutClassNames.content, contentStyles.base, content.className);\n if (expandIcon) {\n expandIcon.className = mergeClasses(treeItemLayoutClassNames.expandIcon, expandIconStyles.base, expandIcon.className);\n }\n if (iconBefore) {\n iconBefore.className = mergeClasses(treeItemLayoutClassNames.iconBefore, iconStyles.base, iconBeforeStyles[size], iconBefore.className);\n }\n if (iconAfter) {\n iconAfter.className = mergeClasses(treeItemLayoutClassNames.iconAfter, iconStyles.base, iconAfterStyles[size], iconAfter.className);\n }\n if (actions) {\n actions.className = mergeClasses(treeItemLayoutClassNames.actions, actionsStyles.base, actions.className);\n }\n if (aside) {\n aside.className = mergeClasses(treeItemLayoutClassNames.aside, asideStyles.base, aside.className);\n }\n if (expandIcon) {\n expandIcon.className = mergeClasses(treeItemLayoutClassNames.expandIcon, expandIconStyles.base, expandIcon.className);\n }\n if (selector) {\n selector.className = mergeClasses(treeItemLayoutClassNames.selector, selector.className);\n }\n return state;\n};\n"],"mappings":"AAAA,SAAAA,QAAA,EAAqBC,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;AACrE,SAASC,MAAM,EAAEC,gBAAgB,QAAQ,uBAAuB;AAChE,SAASC,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,2BAA2B,QAAQ,gCAAgC;AAC5E,OAAO,MAAMC,wBAAwB,GAAG;EACpCC,IAAI,EAAE,oBAAoB;EAC1BC,UAAU,EAAE,gCAAgC;EAC5CC,OAAO,EAAE,6BAA6B;EACtCC,SAAS,EAAE,+BAA+B;EAC1CC,UAAU,EAAE,gCAAgC;EAC5CC,KAAK,EAAE,2BAA2B;EAClCC,OAAO,EAAE,6BAA6B;EACtCC,QAAQ,EAAE;AACd,CAAC;AACD;AACA;AACA;AAAI,MAAMC,aAAa,gBAAGjB,QAAA;EAAAkB,IAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;EAAA;EAAAC,IAAA;IAAAC,MAAA;EAAA;EAAAC,MAAA;IAAAD,MAAA;EAAA;EAAAE,MAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;EAAA;EAAAC,KAAA;IAAAxB,MAAA;IAAAoB,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAA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AE+D,WAAW,CAAC3D,IAAI,EAAEJ,KAAK,CAACyE,SAAS,CAAC;EACrG;EACA,IAAI1E,UAAU,EAAE;IACZA,UAAU,CAAC0E,SAAS,GAAGtF,YAAY,CAACO,wBAAwB,CAACK,UAAU,EAAEkE,gBAAgB,CAAC7D,IAAI,EAAEL,UAAU,CAAC0E,SAAS,CAAC;EACzH;EACA,IAAIvE,QAAQ,EAAE;IACVA,QAAQ,CAACuE,SAAS,GAAGtF,YAAY,CAACO,wBAAwB,CAACQ,QAAQ,EAAEA,QAAQ,CAACuE,SAAS,CAAC;EAC5F;EACA,OAAOb,KAAK;AAChB,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
|
|
2
2
|
import { ImmutableSet } from '../utils/ImmutableSet';
|
|
3
|
+
import { ImmutableMap } from '../utils/ImmutableMap';
|
|
3
4
|
const defaultContextValue = {
|
|
4
5
|
level: 0,
|
|
6
|
+
selectionMode: 'none',
|
|
5
7
|
openItems: ImmutableSet.empty,
|
|
8
|
+
checkedItems: ImmutableMap.empty,
|
|
6
9
|
requestTreeResponse: noop,
|
|
7
10
|
appearance: 'subtle',
|
|
8
11
|
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 { 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'
|
|
1
|
+
{"version":3,"sources":["treeContext.ts"],"sourcesContent":["import { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeCheckedChangeData, TreeNavigationData_unstable, TreeOpenChangeData } from '../Tree';\nimport { TreeItemType, TreeItemValue } from '../TreeItem';\nimport { SelectionMode } from '@fluentui/react-utilities';\nimport { ImmutableSet } from '../utils/ImmutableSet';\nimport { ImmutableMap } from '../utils/ImmutableMap';\n\nexport type TreeContextValue = {\n level: number;\n selectionMode: 'none' | SelectionMode;\n appearance: 'subtle' | 'subtle-alpha' | 'transparent';\n size: 'small' | 'medium';\n openItems: ImmutableSet<TreeItemValue>;\n checkedItems: ImmutableMap<TreeItemValue, 'mixed' | boolean>;\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'>\n | TreeNavigationData_unstable\n | OmitWithoutExpanding<TreeCheckedChangeData, 'checked' | 'selectionMode'>\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 selectionMode: 'none',\n openItems: ImmutableSet.empty,\n checkedItems: ImmutableMap.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","ImmutableMap","defaultContextValue","level","selectionMode","openItems","empty","checkedItems","requestTreeResponse","noop","appearance","size","TreeContext","undefined","Provider","TreeProvider","useTreeContext_unstable","selector","ctx"],"mappings":"AAAA,SAAmCA,aAAa,EAAEC,kBAAkB,QAAQ,mCAAmC;AAI/G,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,YAAY,QAAQ,wBAAwB;AAwBrD,MAAMC,sBAAwC;IAC5CC,OAAO;IACPC,eAAe;IACfC,WAAWL,aAAaM,KAAK;IAC7BC,cAAcN,aAAaK,KAAK;IAChCE,qBAAqBC;IACrBC,YAAY;IACZC,MAAM;AACR;AAEA,SAASF,OAAO;AACd,QAAQ,GACV;AAEA,OAAO,MAAMG,cAAqDd,cAChEe,WACA;AAEF,OAAO,MAAM,EAAEC,UAAUC,aAAY,EAAE,GAAGH,YAAY;AACtD,OAAO,MAAMI,0BAA0B,CAAIC,WACzClB,mBAAmBa,aAAa,CAACM,MAAMhB,mBAAmB,GAAKe,SAASC,MAAM"}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"sources":["treeItemSlotsContext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { TreeItemSlots } from '../TreeItem';\nimport type { Slot } from '@fluentui/react-utilities';\nimport type { Checkbox } from '@fluentui/react-checkbox';\nimport type { Radio } from '@fluentui/react-radio';\n\nexport type TreeItemSlotsContextValue = Pick<TreeItemSlots, 'actions' | 'aside' | 'expandIcon'> & {\n selector?: Slot<typeof Checkbox> | Slot<typeof Radio>;\n};\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;AAU/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 './useControllableOpenItems';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B"}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useFlatTree';\nexport * from './useNestedTreeNavigation';\nexport * from './useControllableOpenItems';\nexport * from './useNestedControllableCheckedItems';\nexport * from './useFlatControllableCheckedItems';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,sCAAsC;AACpD,cAAc,oCAAoC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useControllableState } from '@fluentui/react-utilities';
|
|
2
|
+
import { ImmutableMap } from '../utils/ImmutableMap';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
function initializeMap(iterable) {
|
|
5
|
+
const map = new Map();
|
|
6
|
+
if (iterable === undefined) {
|
|
7
|
+
return ImmutableMap.empty;
|
|
8
|
+
}
|
|
9
|
+
for (const item of iterable){
|
|
10
|
+
if (Array.isArray(item)) {
|
|
11
|
+
map.set(item[0], item[1]);
|
|
12
|
+
} else {
|
|
13
|
+
map.set(item, true);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return ImmutableMap.dangerouslyCreate_unstable(map);
|
|
17
|
+
}
|
|
18
|
+
export function useFlatControllableCheckedItems(props) {
|
|
19
|
+
const [checkedItems, setCheckedItems] = useControllableState({
|
|
20
|
+
initialState: ImmutableMap.empty,
|
|
21
|
+
state: React.useMemo(()=>props.checkedItems && initializeMap(props.checkedItems), [
|
|
22
|
+
props.checkedItems
|
|
23
|
+
]),
|
|
24
|
+
defaultState: ()=>initializeMap(props.defaultCheckedItems)
|
|
25
|
+
});
|
|
26
|
+
return [
|
|
27
|
+
checkedItems,
|
|
28
|
+
setCheckedItems
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
export function createNextFlatCheckedItems(data, previousCheckedItems, flatTreeItems) {
|
|
32
|
+
if (data.selectionMode === 'single') {
|
|
33
|
+
return ImmutableMap.create([
|
|
34
|
+
[
|
|
35
|
+
data.value,
|
|
36
|
+
data.checked
|
|
37
|
+
]
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
const treeItem = flatTreeItems.get(data.value);
|
|
41
|
+
if (!treeItem) {
|
|
42
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.error(`useFlatTree: tree item ${data.value} not found`);
|
|
45
|
+
}
|
|
46
|
+
return previousCheckedItems;
|
|
47
|
+
}
|
|
48
|
+
const nextCheckedItems = new Map(previousCheckedItems);
|
|
49
|
+
for (const children of flatTreeItems.subtree(data.value)){
|
|
50
|
+
nextCheckedItems.set(children.value, data.checked);
|
|
51
|
+
}
|
|
52
|
+
nextCheckedItems.set(data.value, data.checked);
|
|
53
|
+
let isAncestorsMixed = false;
|
|
54
|
+
for (const parent of flatTreeItems.ancestors(treeItem.value)){
|
|
55
|
+
// if one parent is mixed, all ancestors are mixed
|
|
56
|
+
if (isAncestorsMixed) {
|
|
57
|
+
nextCheckedItems.set(parent.value, 'mixed');
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const checkedChildren = [];
|
|
61
|
+
for (const child of flatTreeItems.children(parent.value)){
|
|
62
|
+
var _nextCheckedItems_get;
|
|
63
|
+
if (((_nextCheckedItems_get = nextCheckedItems.get(child.value)) !== null && _nextCheckedItems_get !== void 0 ? _nextCheckedItems_get : false) === data.checked) {
|
|
64
|
+
checkedChildren.push(child);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (checkedChildren.length === parent.childrenValues.length) {
|
|
68
|
+
nextCheckedItems.set(parent.value, data.checked);
|
|
69
|
+
} else {
|
|
70
|
+
// if one parent is mixed, all ancestors are mixed
|
|
71
|
+
isAncestorsMixed = true;
|
|
72
|
+
nextCheckedItems.set(parent.value, 'mixed');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return ImmutableMap.dangerouslyCreate_unstable(nextCheckedItems);
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useFlatControllableCheckedItems.ts"],"sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport type { TreeCheckedChangeData, TreeProps } from '../Tree';\nimport { TreeItemValue } from '../TreeItem';\nimport { ImmutableMap } from '../utils/ImmutableMap';\nimport * as React from 'react';\nimport type { FlatTreeItemProps } from './useFlatTree';\nimport { FlatTreeItems } from '../utils/createFlatTreeItems';\n\nfunction initializeMap(iterable?: Iterable<TreeItemValue | [TreeItemValue, 'mixed' | boolean]>) {\n const map = new Map<TreeItemValue, 'mixed' | boolean>();\n if (iterable === undefined) {\n return ImmutableMap.empty;\n }\n for (const item of iterable) {\n if (Array.isArray(item)) {\n map.set(item[0], item[1]);\n } else {\n map.set(item, true);\n }\n }\n return ImmutableMap.dangerouslyCreate_unstable(map);\n}\n\nexport function useFlatControllableCheckedItems(\n props: Pick<TreeProps, 'checkedItems' | 'defaultCheckedItems' | 'selectionMode'>,\n) {\n const [checkedItems, setCheckedItems] = useControllableState({\n initialState: ImmutableMap.empty,\n state: React.useMemo(() => props.checkedItems && initializeMap(props.checkedItems), [props.checkedItems]),\n defaultState: () => initializeMap(props.defaultCheckedItems),\n });\n\n return [checkedItems, setCheckedItems] as const;\n}\n\nexport function createNextFlatCheckedItems<Props extends FlatTreeItemProps = FlatTreeItemProps>(\n data: Pick<TreeCheckedChangeData, 'value' | 'checked' | 'selectionMode'>,\n previousCheckedItems: ImmutableMap<TreeItemValue, 'mixed' | boolean>,\n flatTreeItems: FlatTreeItems<Props>,\n): ImmutableMap<TreeItemValue, 'mixed' | boolean> {\n if (data.selectionMode === 'single') {\n return ImmutableMap.create([[data.value, data.checked]]);\n }\n const treeItem = flatTreeItems.get(data.value);\n if (!treeItem) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error(`useFlatTree: tree item ${data.value} not found`);\n }\n return previousCheckedItems;\n }\n const nextCheckedItems = new Map(previousCheckedItems);\n for (const children of flatTreeItems.subtree(data.value)) {\n nextCheckedItems.set(children.value, data.checked);\n }\n nextCheckedItems.set(data.value, data.checked);\n\n let isAncestorsMixed = false;\n for (const parent of flatTreeItems.ancestors(treeItem.value)) {\n // if one parent is mixed, all ancestors are mixed\n if (isAncestorsMixed) {\n nextCheckedItems.set(parent.value, 'mixed');\n continue;\n }\n const checkedChildren = [];\n for (const child of flatTreeItems.children(parent.value)) {\n if ((nextCheckedItems.get(child.value) ?? false) === data.checked) {\n checkedChildren.push(child);\n }\n }\n if (checkedChildren.length === parent.childrenValues.length) {\n nextCheckedItems.set(parent.value, data.checked);\n } else {\n // if one parent is mixed, all ancestors are mixed\n isAncestorsMixed = true;\n nextCheckedItems.set(parent.value, 'mixed');\n }\n }\n return ImmutableMap.dangerouslyCreate_unstable(nextCheckedItems);\n}\n"],"names":["useControllableState","ImmutableMap","React","initializeMap","iterable","map","Map","undefined","empty","item","Array","isArray","set","dangerouslyCreate_unstable","useFlatControllableCheckedItems","props","checkedItems","setCheckedItems","initialState","state","useMemo","defaultState","defaultCheckedItems","createNextFlatCheckedItems","data","previousCheckedItems","flatTreeItems","selectionMode","create","value","checked","treeItem","get","process","env","NODE_ENV","console","error","nextCheckedItems","children","subtree","isAncestorsMixed","parent","ancestors","checkedChildren","child","push","length","childrenValues"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4BAA4B;AAGjE,SAASC,YAAY,QAAQ,wBAAwB;AACrD,YAAYC,WAAW,QAAQ;AAI/B,SAASC,cAAcC,QAAuE,EAAE;IAC9F,MAAMC,MAAM,IAAIC;IAChB,IAAIF,aAAaG,WAAW;QAC1B,OAAON,aAAaO,KAAK;IAC3B,CAAC;IACD,KAAK,MAAMC,QAAQL,SAAU;QAC3B,IAAIM,MAAMC,OAAO,CAACF,OAAO;YACvBJ,IAAIO,GAAG,CAACH,IAAI,CAAC,EAAE,EAAEA,IAAI,CAAC,EAAE;QAC1B,OAAO;YACLJ,IAAIO,GAAG,CAACH,MAAM,IAAI;QACpB,CAAC;IACH;IACA,OAAOR,aAAaY,0BAA0B,CAACR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