@fluentui/react-tree 9.0.0-beta.10 → 9.0.0-beta.12
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 +122 -8
- package/CHANGELOG.md +41 -9
- package/dist/index.d.ts +73 -45
- package/lib/components/Tree/Tree.js.map +1 -1
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/renderTree.js +5 -5
- package/lib/components/Tree/renderTree.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.js +1 -1
- package/lib/components/TreeItem/TreeItem.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.types.js.map +1 -1
- package/lib/components/TreeItem/renderTreeItem.js +6 -6
- package/lib/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItem.js +17 -4
- package/lib/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js.map +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js +4 -4
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +2 -2
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +5 -5
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js +7 -14
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js.map +1 -1
- package/lib/contexts/treeContext.js.map +1 -1
- package/lib/hooks/useFlatTree.js +2 -2
- package/lib/hooks/useFlatTree.js.map +1 -1
- package/lib/hooks/useFlatTreeNavigation.js +7 -5
- package/lib/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib/hooks/useNestedTreeNavigation.js +1 -1
- package/lib/hooks/useNestedTreeNavigation.js.map +1 -1
- package/lib/hooks/useOpenItemsState.js +2 -3
- package/lib/hooks/useOpenItemsState.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/createFlatTreeItems.js +26 -17
- package/lib/utils/createFlatTreeItems.js.map +1 -1
- package/lib/utils/flattenTree.js +8 -4
- package/lib/utils/flattenTree.js.map +1 -1
- package/lib-commonjs/components/Tree/renderTree.js +5 -6
- package/lib-commonjs/components/Tree/renderTree.js.map +1 -1
- package/lib-commonjs/components/TreeItem/TreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/renderTreeItem.js +6 -7
- package/lib-commonjs/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItem.js +17 -5
- package/lib-commonjs/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js +4 -5
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js +2 -2
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +5 -6
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js +11 -19
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTree.js +2 -2
- package/lib-commonjs/hooks/useFlatTree.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTreeNavigation.js +7 -5
- package/lib-commonjs/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useNestedTreeNavigation.js +1 -1
- package/lib-commonjs/hooks/useNestedTreeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useOpenItemsState.js +2 -3
- package/lib-commonjs/hooks/useOpenItemsState.js.map +1 -1
- package/lib-commonjs/utils/createFlatTreeItems.js +26 -20
- package/lib-commonjs/utils/createFlatTreeItems.js.map +1 -1
- package/lib-commonjs/utils/flattenTree.js +8 -4
- package/lib-commonjs/utils/flattenTree.js.map +1 -1
- package/package.json +9 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React"],"sources":["../../../src/components/TreeItem/TreeItem.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport type { ButtonContextValue } from '@fluentui/react-button';\nimport type { TreeItemContextValue } from '../../contexts';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport * as React from 'react';\n\nexport type TreeItemCSSProperties = React.CSSProperties & { [treeItemLevelToken]?: string | number };\
|
|
1
|
+
{"version":3,"names":["React"],"sources":["../../../src/components/TreeItem/TreeItem.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport type { ButtonContextValue } from '@fluentui/react-button';\nimport type { TreeItemContextValue } from '../../contexts';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport * as React from 'react';\n\nexport type TreeItemCSSProperties = React.CSSProperties & { [treeItemLevelToken]?: string | number };\n\nexport type TreeItemSlots = {\n root: Slot<ExtractSlotProps<Slot<'div'> & { style?: TreeItemCSSProperties }>>;\n content: NonNullable<Slot<'div'>>;\n subtree?: Slot<'span'>;\n /**\n * Expand icon slot,\n * by default renders a chevron icon to indicate opening and closing\n */\n expandIcon?: Slot<'span'>;\n /**\n * Actions slot that renders on the end of tree item\n * when the item is hovered/focused\n */\n actions?: Slot<'span'>;\n};\n\nexport type TreeItemContextValues = {\n treeItem: TreeItemContextValue;\n button: ButtonContextValue;\n};\n\n/**\n * TreeItem Props\n */\nexport type TreeItemProps<Value = string> = ComponentProps<Partial<TreeItemSlots>> & {\n value?: Value;\n /**\n * If a TreeItem is a leaf, it'll not present the `expandIcon` slot by default.\n * This attribute is used to force the decision if a TreeItem is a leaf or not. By not providing this property\n * this will be inferred by the presence of a subtree as part of the TreeItem children.\n */\n leaf?: boolean;\n};\n\n/**\n * State used in rendering TreeItem\n */\nexport type TreeItemState = ComponentState<TreeItemSlots> & {\n open: boolean;\n isLeaf: boolean;\n level: number;\n /**\n * By design, a button included on the actions slot should be small\n */\n buttonSize: 'small';\n isActionsVisible: boolean;\n};\n"],"mappings":"AAIA,YAAYA,KAAA,MAAW"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
/** @jsxRuntime classic */ /** @jsx createElement */import { createElement } from '@fluentui/react-jsx-runtime';
|
|
2
|
+
import { getSlotsNext } from '@fluentui/react-utilities';
|
|
3
3
|
import { TreeItemProvider } from '../../contexts';
|
|
4
4
|
import { ButtonContextProvider } from '@fluentui/react-button';
|
|
5
5
|
/**
|
|
@@ -9,11 +9,11 @@ export const renderTreeItem_unstable = (state, contextValues) => {
|
|
|
9
9
|
const {
|
|
10
10
|
slots,
|
|
11
11
|
slotProps
|
|
12
|
-
} =
|
|
13
|
-
return /*#__PURE__*/
|
|
12
|
+
} = getSlotsNext(state);
|
|
13
|
+
return /*#__PURE__*/createElement(TreeItemProvider, {
|
|
14
14
|
value: contextValues.treeItem
|
|
15
|
-
}, /*#__PURE__*/
|
|
15
|
+
}, /*#__PURE__*/createElement(slots.root, slotProps.root, /*#__PURE__*/createElement(slots.content, slotProps.content, slots.expandIcon && /*#__PURE__*/createElement(slots.expandIcon, slotProps.expandIcon), slotProps.content.children, /*#__PURE__*/createElement(ButtonContextProvider, {
|
|
16
16
|
value: contextValues.button
|
|
17
|
-
}, slots.actions && /*#__PURE__*/
|
|
17
|
+
}, slots.actions && /*#__PURE__*/createElement(slots.actions, slotProps.actions))), state.open && slots.subtree && /*#__PURE__*/createElement(slots.subtree, slotProps.subtree)));
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=renderTreeItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createElement","getSlotsNext","TreeItemProvider","ButtonContextProvider","renderTreeItem_unstable","state","contextValues","slots","slotProps","value","treeItem","root","content","expandIcon","children","button","actions","open","subtree"],"sources":["../../../src/components/TreeItem/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, TreeItemSlots, TreeItemContextValues } from './TreeItem.types';\nimport { TreeItemProvider } from '../../contexts';\nimport { ButtonContextProvider } from '@fluentui/react-button';\n\n/**\n * Render the final JSX of TreeItem\n */\nexport const renderTreeItem_unstable = (state: TreeItemState, contextValues: TreeItemContextValues) => {\n const { slots, slotProps } = getSlotsNext<TreeItemSlots>(state);\n\n return (\n <TreeItemProvider value={contextValues.treeItem}>\n <slots.root {...slotProps.root}>\n <slots.content {...slotProps.content}>\n {slots.expandIcon && <slots.expandIcon {...slotProps.expandIcon} />}\n {slotProps.content.children}\n <ButtonContextProvider value={contextValues.button}>\n {slots.actions && <slots.actions {...slotProps.actions} />}\n </ButtonContextProvider>\n </slots.content>\n {state.open && slots.subtree && <slots.subtree {...slotProps.subtree} />}\n </slots.root>\n </TreeItemProvider>\n );\n};\n"],"mappings":"AAAA,2BACA,yBAEA,SAASA,aAAa,QAAQ;AAC9B,SAASC,YAAY,QAAQ;AAE7B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,qBAAqB,QAAQ;AAEtC;;;AAGA,OAAO,MAAMC,uBAAA,GAA0BA,CAACC,KAAA,EAAsBC,aAAA,KAAyC;EACrG,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGP,YAAA,CAA4BI,KAAA;EAEzD,oBACEL,aAfJ,CAeKE,gBAAA;IAAiBO,KAAA,EAAOH,aAAA,CAAcI;kBACrCV,aAhBN,CAgBOO,KAAA,CAAMI,IAAI,EAAKH,SAAA,CAAUG,IAAI,eAC5BX,aAjBR,CAiBSO,KAAA,CAAMK,OAAO,EAAKJ,SAAA,CAAUI,OAAO,EACjCL,KAAA,CAAMM,UAAU,iBAAIb,aAlB/B,CAkBgCO,KAAA,CAAMM,UAAU,EAAKL,SAAA,CAAUK,UAAU,GAC9DL,SAAA,CAAUI,OAAO,CAACE,QAAQ,eAC3Bd,aApBV,CAoBWG,qBAAA;IAAsBM,KAAA,EAAOH,aAAA,CAAcS;KACzCR,KAAA,CAAMS,OAAO,iBAAIhB,aArB9B,CAqB+BO,KAAA,CAAMS,OAAO,EAAKR,SAAA,CAAUQ,OAAO,KAGzDX,KAAA,CAAMY,IAAI,IAAIV,KAAA,CAAMW,OAAO,iBAAIlB,aAxBxC,CAwByCO,KAAA,CAAMW,OAAO,EAAKV,SAAA,CAAUU,OAAO;AAI5E"}
|
|
@@ -18,9 +18,10 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
18
18
|
* @param props - props from this instance of TreeItem
|
|
19
19
|
* @param ref - reference to root HTMLElement of TreeItem
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export function useTreeItem_unstable(props, ref) {
|
|
22
22
|
const [children, subtreeChildren] = React.Children.toArray(props.children);
|
|
23
23
|
const contextLevel = useTreeContext_unstable(ctx => ctx.level);
|
|
24
|
+
const id = useId('fui-TreeItem-', props.id);
|
|
24
25
|
const {
|
|
25
26
|
content,
|
|
26
27
|
subtree,
|
|
@@ -31,13 +32,13 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
31
32
|
onClick,
|
|
32
33
|
onKeyDown,
|
|
33
34
|
['aria-level']: level = contextLevel,
|
|
35
|
+
value = id,
|
|
34
36
|
...rest
|
|
35
37
|
} = props;
|
|
36
38
|
const requestOpenChange = useTreeContext_unstable(ctx => ctx.requestOpenChange);
|
|
37
39
|
const requestNavigation = useTreeContext_unstable(ctx => ctx.requestNavigation);
|
|
38
|
-
const id = useId('fui-TreeItem-', props.id);
|
|
39
40
|
const isBranch = !isLeaf;
|
|
40
|
-
const open = useTreeContext_unstable(ctx => isBranch && ctx.openItems.has(
|
|
41
|
+
const open = useTreeContext_unstable(ctx => isBranch && ctx.openItems.has(value));
|
|
41
42
|
const {
|
|
42
43
|
dir,
|
|
43
44
|
targetDocument
|
|
@@ -50,6 +51,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
50
51
|
if (!open && isBranch) {
|
|
51
52
|
return requestOpenChange({
|
|
52
53
|
event,
|
|
54
|
+
value,
|
|
53
55
|
open: true,
|
|
54
56
|
type: treeDataTypes.arrowRight,
|
|
55
57
|
target: event.currentTarget
|
|
@@ -58,6 +60,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
58
60
|
if (open && isBranch) {
|
|
59
61
|
return requestNavigation({
|
|
60
62
|
event,
|
|
63
|
+
value,
|
|
61
64
|
type: treeDataTypes.arrowRight,
|
|
62
65
|
target: event.currentTarget
|
|
63
66
|
});
|
|
@@ -67,6 +70,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
67
70
|
if (open && isBranch) {
|
|
68
71
|
return requestOpenChange({
|
|
69
72
|
event,
|
|
73
|
+
value,
|
|
70
74
|
open: false,
|
|
71
75
|
type: treeDataTypes.arrowLeft,
|
|
72
76
|
target: event.currentTarget
|
|
@@ -75,6 +79,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
75
79
|
if (!open && level > 1) {
|
|
76
80
|
return requestNavigation({
|
|
77
81
|
event,
|
|
82
|
+
value,
|
|
78
83
|
target: event.currentTarget,
|
|
79
84
|
type: treeDataTypes.arrowLeft
|
|
80
85
|
});
|
|
@@ -83,6 +88,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
83
88
|
const handleEnter = event => {
|
|
84
89
|
requestOpenChange({
|
|
85
90
|
event,
|
|
91
|
+
value,
|
|
86
92
|
open: isLeaf ? open : !open,
|
|
87
93
|
type: treeDataTypes.enter,
|
|
88
94
|
target: event.currentTarget
|
|
@@ -101,12 +107,14 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
101
107
|
const isFromExpandIcon = expandIconRef.current && elementContains(expandIconRef.current, event.target);
|
|
102
108
|
requestOpenChange({
|
|
103
109
|
event,
|
|
110
|
+
value,
|
|
104
111
|
open: isLeaf ? open : !open,
|
|
105
112
|
type: isFromExpandIcon ? treeDataTypes.expandIconClick : treeDataTypes.click,
|
|
106
113
|
target: event.currentTarget
|
|
107
114
|
});
|
|
108
115
|
requestNavigation({
|
|
109
116
|
event,
|
|
117
|
+
value,
|
|
110
118
|
target: event.currentTarget,
|
|
111
119
|
type: treeDataTypes.click
|
|
112
120
|
});
|
|
@@ -129,24 +137,28 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
129
137
|
case End:
|
|
130
138
|
return requestNavigation({
|
|
131
139
|
event,
|
|
140
|
+
value,
|
|
132
141
|
type: treeDataTypes.end,
|
|
133
142
|
target: event.currentTarget
|
|
134
143
|
});
|
|
135
144
|
case Home:
|
|
136
145
|
return requestNavigation({
|
|
137
146
|
event,
|
|
147
|
+
value,
|
|
138
148
|
type: treeDataTypes.home,
|
|
139
149
|
target: event.currentTarget
|
|
140
150
|
});
|
|
141
151
|
case ArrowUp:
|
|
142
152
|
return requestNavigation({
|
|
143
153
|
event,
|
|
154
|
+
value,
|
|
144
155
|
type: treeDataTypes.arrowUp,
|
|
145
156
|
target: event.currentTarget
|
|
146
157
|
});
|
|
147
158
|
case ArrowDown:
|
|
148
159
|
return requestNavigation({
|
|
149
160
|
event,
|
|
161
|
+
value,
|
|
150
162
|
type: treeDataTypes.arrowDown,
|
|
151
163
|
target: event.currentTarget
|
|
152
164
|
});
|
|
@@ -155,6 +167,7 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
155
167
|
if (isTypeAheadCharacter) {
|
|
156
168
|
return requestNavigation({
|
|
157
169
|
event,
|
|
170
|
+
value,
|
|
158
171
|
target: event.currentTarget,
|
|
159
172
|
type: treeDataTypes.typeAhead
|
|
160
173
|
});
|
|
@@ -246,5 +259,5 @@ export const useTreeItem_unstable = (props, ref) => {
|
|
|
246
259
|
}
|
|
247
260
|
})
|
|
248
261
|
};
|
|
249
|
-
}
|
|
262
|
+
}
|
|
250
263
|
//# sourceMappingURL=useTreeItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","getNativeElementProps","isResolvedShorthand","resolveShorthand","useId","ChevronRight12Regular","useFluent_unstable","useEventCallback","expandIconInlineStyles","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","End","Enter","Home","useMergedRefs","elementContains","useTreeContext_unstable","treeDataTypes","useTreeItem_unstable","props","ref","children","subtreeChildren","Children","toArray","contextLevel","ctx","level","content","subtree","expandIcon","leaf","isLeaf","undefined","actions","as","onClick","onKeyDown","rest","requestOpenChange","requestNavigation","id","isBranch","open","openItems","has","dir","targetDocument","expandIconRotation","actionsRef","useRef","expandIconRef","subtreeRef","handleArrowRight","event","type","arrowRight","target","currentTarget","handleArrowLeft","arrowLeft","handleEnter","enter","handleClick","isEventFromActions","current","isEventFromSubtree","isFromExpandIcon","expandIconClick","click","handleKeyDown","isDefaultPrevented","key","end","home","arrowUp","arrowDown","isTypeAheadCharacter","length","match","altKey","ctrlKey","metaKey","typeAhead","isActionsVisible","setActionsVisible","useState","showActions","hideActions","useEffect","handleFocusOut","relatedTarget","addEventListener","passive","removeEventListener","buttonSize","components","root","required","Boolean","defaultProps","tabIndex","role","onMouseOver","onFocus","onMouseOut","onBlur","createElement","style"],"sources":["../../../src/components/TreeItem/useTreeItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, isResolvedShorthand, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { ChevronRight12Regular } from '@fluentui/react-icons';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { expandIconInlineStyles } from './useTreeItemStyles';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Enter, Home } from '@fluentui/keyboard-keys';\nimport { useMergedRefs } 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';\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 const useTreeItem_unstable = (props: TreeItemProps, ref: React.Ref<HTMLDivElement>): TreeItemState => {\n const [children, subtreeChildren] = React.Children.toArray(props.children);\n\n const contextLevel = useTreeContext_unstable(ctx => ctx.level);\n const {\n content,\n subtree,\n expandIcon,\n leaf: isLeaf = subtreeChildren === undefined,\n actions,\n as = 'div',\n onClick,\n onKeyDown,\n ['aria-level']: level = contextLevel,\n ...rest\n } = props;\n\n const requestOpenChange = useTreeContext_unstable(ctx => ctx.requestOpenChange);\n const requestNavigation = useTreeContext_unstable(ctx => ctx.requestNavigation);\n\n const id = useId('fui-TreeItem-', props.id);\n\n const isBranch = !isLeaf;\n\n const open = useTreeContext_unstable(ctx => isBranch && ctx.openItems.has(id));\n const { dir, targetDocument } = useFluent_unstable();\n const expandIconRotation = open ? 90 : dir !== 'rtl' ? 0 : 180;\n\n const actionsRef = React.useRef<HTMLElement>(null);\n const expandIconRef = React.useRef<HTMLElement>(null);\n const subtreeRef = React.useRef<HTMLElement>(null);\n\n const handleArrowRight = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!open && isBranch) {\n return requestOpenChange({ event, open: true, type: treeDataTypes.arrowRight, target: event.currentTarget });\n }\n if (open && isBranch) {\n return requestNavigation({ event, type: treeDataTypes.arrowRight, target: event.currentTarget });\n }\n };\n const handleArrowLeft = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (open && isBranch) {\n return requestOpenChange({ event, open: false, type: treeDataTypes.arrowLeft, target: event.currentTarget });\n }\n if (!open && level > 1) {\n return requestNavigation({ event, target: event.currentTarget, type: treeDataTypes.arrowLeft });\n }\n };\n const handleEnter = (event: React.KeyboardEvent<HTMLDivElement>) => {\n requestOpenChange({ event, open: isLeaf ? open : !open, type: treeDataTypes.enter, target: event.currentTarget });\n };\n\n const handleClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\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 requestOpenChange({\n event,\n open: isLeaf ? open : !open,\n type: isFromExpandIcon ? treeDataTypes.expandIconClick : treeDataTypes.click,\n target: event.currentTarget,\n });\n requestNavigation({ event, target: event.currentTarget, type: treeDataTypes.click });\n });\n\n const handleKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (event.currentTarget !== event.target) {\n return;\n }\n if (event.isDefaultPrevented()) {\n return;\n }\n switch (event.key) {\n case Enter:\n return handleEnter(event);\n case ArrowRight:\n return handleArrowRight(event);\n case ArrowLeft:\n return handleArrowLeft(event);\n case End:\n return requestNavigation({ event, type: treeDataTypes.end, target: event.currentTarget });\n case Home:\n return requestNavigation({ event, type: treeDataTypes.home, target: event.currentTarget });\n case ArrowUp:\n return requestNavigation({ event, type: treeDataTypes.arrowUp, target: event.currentTarget });\n case ArrowDown:\n return requestNavigation({ event, type: treeDataTypes.arrowDown, target: event.currentTarget });\n }\n const isTypeAheadCharacter =\n event.key.length === 1 && event.key.match(/\\w/) && !event.altKey && !event.ctrlKey && !event.metaKey;\n if (isTypeAheadCharacter) {\n return requestNavigation({ event, target: event.currentTarget, type: treeDataTypes.typeAhead });\n }\n });\n\n const [isActionsVisible, setActionsVisible] = React.useState(false);\n const showActions = useEventCallback((event: React.SyntheticEvent) => {\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (!isEventFromSubtree) {\n setActionsVisible(true);\n }\n });\n const hideActions = useEventCallback((event: React.SyntheticEvent) => {\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (!isEventFromSubtree) {\n setActionsVisible(false);\n }\n });\n\n // Listens to focusout event on the document to ensure treeitem actions visibility on portal scenarios\n // TODO: find a better way to ensure this behavior\n React.useEffect(() => {\n if (actionsRef.current) {\n const handleFocusOut = (event: FocusEvent) => {\n setActionsVisible(elementContains(actionsRef.current, event.relatedTarget as Node));\n };\n targetDocument?.addEventListener('focusout', handleFocusOut, { passive: true });\n return () => {\n targetDocument?.removeEventListener('focusout', handleFocusOut);\n };\n }\n }, [targetDocument]);\n\n return {\n isLeaf,\n open,\n level,\n buttonSize: 'small',\n isActionsVisible: actions ? isActionsVisible : false,\n components: {\n content: 'div',\n root: 'div',\n expandIcon: 'span',\n actions: 'span',\n subtree: 'span',\n },\n subtree: resolveShorthand(subtree, {\n required: Boolean(subtreeChildren),\n defaultProps: {\n children: subtreeChildren,\n ref: useMergedRefs(subtreeRef, isResolvedShorthand(subtree) ? subtree.ref : undefined),\n },\n }),\n content: resolveShorthand(content, {\n required: true,\n defaultProps: {\n children,\n },\n }),\n root: getNativeElementProps(as, {\n tabIndex: -1,\n ...rest,\n id,\n ref,\n children: null,\n 'aria-level': level,\n 'aria-expanded': isBranch ? open : undefined,\n role: 'treeitem',\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n onMouseOver: actions ? showActions : undefined,\n onFocus: actions ? showActions : undefined,\n onMouseOut: actions ? hideActions : undefined,\n onBlur: actions ? hideActions : undefined,\n }),\n expandIcon: resolveShorthand(expandIcon, {\n required: isBranch,\n defaultProps: {\n children: <ChevronRight12Regular style={expandIconInlineStyles[expandIconRotation]} />,\n 'aria-hidden': true,\n ref: useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef),\n },\n }),\n actions: resolveShorthand(actions, {\n defaultProps: {\n ref: useMergedRefs(isResolvedShorthand(actions) ? actions.ref : undefined, actionsRef),\n },\n }),\n };\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,qBAAqB,EAAEC,mBAAmB,EAAEC,gBAAgB,EAAEC,KAAK,QAAQ;AACpF,SAASC,qBAAqB,QAAQ;AACtC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,GAAG,EAAEC,KAAK,EAAEC,IAAI,QAAQ;AAC5E,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAEhC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,aAAa,QAAQ;AAE9B;;;;;;;;;AASA,OAAO,MAAMC,oBAAA,GAAuBA,CAACC,KAAA,EAAsBC,GAAA,KAAkD;EAC3G,MAAM,CAACC,QAAA,EAAUC,eAAA,CAAgB,GAAGxB,KAAA,CAAMyB,QAAQ,CAACC,OAAO,CAACL,KAAA,CAAME,QAAQ;EAEzE,MAAMI,YAAA,GAAeT,uBAAA,CAAwBU,GAAA,IAAOA,GAAA,CAAIC,KAAK;EAC7D,MAAM;IACJC,OAAA;IACAC,OAAA;IACAC,UAAA;IACAC,IAAA,EAAMC,MAAA,GAASV,eAAA,KAAoBW,SAAS;IAC5CC,OAAA;IACAC,EAAA,GAAK;IACLC,OAAA;IACAC,SAAA;IACA,CAAC,eAAeV,KAAA,GAAQF,YAAY;IACpC,GAAGa;EAAA,CACJ,GAAGnB,KAAA;EAEJ,MAAMoB,iBAAA,GAAoBvB,uBAAA,CAAwBU,GAAA,IAAOA,GAAA,CAAIa,iBAAiB;EAC9E,MAAMC,iBAAA,GAAoBxB,uBAAA,CAAwBU,GAAA,IAAOA,G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,EAAY;MACvCoE,QAAA,EAAUxD,QAAA;MACV0D,YAAA,EAAc;QACZ/E,QAAA,eAAUvB,KAAA,CAAA6G,aAAA,CAACxG,qBAAA;UAAsByG,KAAA,EAAOtG,sBAAsB,CAAC0C,kBAAA;;QAC/D,eAAe,IAAI;QACnB5B,GAAA,EAAKN,aAAA,CAAcd,mBAAA,CAAoB8B,UAAA,IAAcA,UAAA,CAAWV,GAAG,GAAGa,SAAS,EAAEkB,aAAA;MACnF;IACF;IACAjB,OAAA,EAASjC,gBAAA,CAAiBiC,OAAA,EAAS;MACjCkE,YAAA,EAAc;QACZhF,GAAA,EAAKN,aAAA,CAAcd,mBAAA,CAAoBkC,OAAA,IAAWA,OAAA,CAAQd,GAAG,GAAGa,SAAS,EAAEgB,UAAA;MAC7E;IACF;EACF;AACF"}
|
|
1
|
+
{"version":3,"names":["React","getNativeElementProps","isResolvedShorthand","resolveShorthand","useId","ChevronRight12Regular","useFluent_unstable","useEventCallback","expandIconInlineStyles","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","End","Enter","Home","useMergedRefs","elementContains","useTreeContext_unstable","treeDataTypes","useTreeItem_unstable","props","ref","children","subtreeChildren","Children","toArray","contextLevel","ctx","level","id","content","subtree","expandIcon","leaf","isLeaf","undefined","actions","as","onClick","onKeyDown","value","rest","requestOpenChange","requestNavigation","isBranch","open","openItems","has","dir","targetDocument","expandIconRotation","actionsRef","useRef","expandIconRef","subtreeRef","handleArrowRight","event","type","arrowRight","target","currentTarget","handleArrowLeft","arrowLeft","handleEnter","enter","handleClick","isEventFromActions","current","isEventFromSubtree","isFromExpandIcon","expandIconClick","click","handleKeyDown","isDefaultPrevented","key","end","home","arrowUp","arrowDown","isTypeAheadCharacter","length","match","altKey","ctrlKey","metaKey","typeAhead","isActionsVisible","setActionsVisible","useState","showActions","hideActions","useEffect","handleFocusOut","relatedTarget","addEventListener","passive","removeEventListener","buttonSize","components","root","required","Boolean","defaultProps","tabIndex","role","onMouseOver","onFocus","onMouseOut","onBlur","createElement","style"],"sources":["../../../src/components/TreeItem/useTreeItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, isResolvedShorthand, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { ChevronRight12Regular } from '@fluentui/react-icons';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { expandIconInlineStyles } from './useTreeItemStyles';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Enter, Home } from '@fluentui/keyboard-keys';\nimport { useMergedRefs } 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';\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<Value = string>(\n props: TreeItemProps<Value>,\n ref: React.Ref<HTMLDivElement>,\n): TreeItemState {\n const [children, subtreeChildren] = React.Children.toArray(props.children);\n\n const contextLevel = useTreeContext_unstable(ctx => ctx.level);\n\n const id = useId('fui-TreeItem-', props.id);\n\n const {\n content,\n subtree,\n expandIcon,\n leaf: isLeaf = subtreeChildren === undefined,\n actions,\n as = 'div',\n onClick,\n onKeyDown,\n ['aria-level']: level = contextLevel,\n value = id,\n ...rest\n } = props;\n\n const requestOpenChange = useTreeContext_unstable(ctx => ctx.requestOpenChange);\n const requestNavigation = useTreeContext_unstable(ctx => ctx.requestNavigation);\n\n const isBranch = !isLeaf;\n\n const open = useTreeContext_unstable(ctx => isBranch && ctx.openItems.has(value));\n const { dir, targetDocument } = useFluent_unstable();\n const expandIconRotation = open ? 90 : dir !== 'rtl' ? 0 : 180;\n\n const actionsRef = React.useRef<HTMLElement>(null);\n const expandIconRef = React.useRef<HTMLElement>(null);\n const subtreeRef = React.useRef<HTMLElement>(null);\n\n const handleArrowRight = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!open && isBranch) {\n return requestOpenChange({\n event,\n value,\n open: true,\n type: treeDataTypes.arrowRight,\n target: event.currentTarget,\n });\n }\n if (open && isBranch) {\n return requestNavigation({ event, value, type: treeDataTypes.arrowRight, target: event.currentTarget });\n }\n };\n const handleArrowLeft = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (open && isBranch) {\n return requestOpenChange({\n event,\n value,\n open: false,\n type: treeDataTypes.arrowLeft,\n target: event.currentTarget,\n });\n }\n if (!open && level > 1) {\n return requestNavigation({ event, value, target: event.currentTarget, type: treeDataTypes.arrowLeft });\n }\n };\n const handleEnter = (event: React.KeyboardEvent<HTMLDivElement>) => {\n requestOpenChange({\n event,\n value,\n open: isLeaf ? open : !open,\n type: treeDataTypes.enter,\n target: event.currentTarget,\n });\n };\n\n const handleClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\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 requestOpenChange({\n event,\n value,\n open: isLeaf ? open : !open,\n type: isFromExpandIcon ? treeDataTypes.expandIconClick : treeDataTypes.click,\n target: event.currentTarget,\n });\n requestNavigation({ event, value, target: event.currentTarget, type: treeDataTypes.click });\n });\n\n const handleKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (event.currentTarget !== event.target) {\n return;\n }\n if (event.isDefaultPrevented()) {\n return;\n }\n switch (event.key) {\n case Enter:\n return handleEnter(event);\n case ArrowRight:\n return handleArrowRight(event);\n case ArrowLeft:\n return handleArrowLeft(event);\n case End:\n return requestNavigation({ event, value, type: treeDataTypes.end, target: event.currentTarget });\n case Home:\n return requestNavigation({ event, value, type: treeDataTypes.home, target: event.currentTarget });\n case ArrowUp:\n return requestNavigation({ event, value, type: treeDataTypes.arrowUp, target: event.currentTarget });\n case ArrowDown:\n return requestNavigation({ event, value, type: treeDataTypes.arrowDown, target: event.currentTarget });\n }\n const isTypeAheadCharacter =\n event.key.length === 1 && event.key.match(/\\w/) && !event.altKey && !event.ctrlKey && !event.metaKey;\n if (isTypeAheadCharacter) {\n return requestNavigation({ event, value, target: event.currentTarget, type: treeDataTypes.typeAhead });\n }\n });\n\n const [isActionsVisible, setActionsVisible] = React.useState(false);\n const showActions = useEventCallback((event: React.SyntheticEvent) => {\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (!isEventFromSubtree) {\n setActionsVisible(true);\n }\n });\n const hideActions = useEventCallback((event: React.SyntheticEvent) => {\n const isEventFromSubtree = subtreeRef.current && elementContains(subtreeRef.current, event.target as Node);\n if (!isEventFromSubtree) {\n setActionsVisible(false);\n }\n });\n\n // Listens to focusout event on the document to ensure treeitem actions visibility on portal scenarios\n // TODO: find a better way to ensure this behavior\n React.useEffect(() => {\n if (actionsRef.current) {\n const handleFocusOut = (event: FocusEvent) => {\n setActionsVisible(elementContains(actionsRef.current, event.relatedTarget as Node));\n };\n targetDocument?.addEventListener('focusout', handleFocusOut, { passive: true });\n return () => {\n targetDocument?.removeEventListener('focusout', handleFocusOut);\n };\n }\n }, [targetDocument]);\n\n return {\n isLeaf,\n open,\n level,\n buttonSize: 'small',\n isActionsVisible: actions ? isActionsVisible : false,\n components: {\n content: 'div',\n root: 'div',\n expandIcon: 'span',\n actions: 'span',\n subtree: 'span',\n },\n subtree: resolveShorthand(subtree, {\n required: Boolean(subtreeChildren),\n defaultProps: {\n children: subtreeChildren,\n ref: useMergedRefs(subtreeRef, isResolvedShorthand(subtree) ? subtree.ref : undefined),\n },\n }),\n content: resolveShorthand(content, {\n required: true,\n defaultProps: {\n children,\n },\n }),\n root: getNativeElementProps(as, {\n tabIndex: -1,\n ...rest,\n id,\n ref,\n children: null,\n 'aria-level': level,\n 'aria-expanded': isBranch ? open : undefined,\n role: 'treeitem',\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n onMouseOver: actions ? showActions : undefined,\n onFocus: actions ? showActions : undefined,\n onMouseOut: actions ? hideActions : undefined,\n onBlur: actions ? hideActions : undefined,\n }),\n expandIcon: resolveShorthand(expandIcon, {\n required: isBranch,\n defaultProps: {\n children: <ChevronRight12Regular style={expandIconInlineStyles[expandIconRotation]} />,\n 'aria-hidden': true,\n ref: useMergedRefs(isResolvedShorthand(expandIcon) ? expandIcon.ref : undefined, expandIconRef),\n },\n }),\n actions: resolveShorthand(actions, {\n defaultProps: {\n ref: useMergedRefs(isResolvedShorthand(actions) ? actions.ref : undefined, actionsRef),\n },\n }),\n };\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,qBAAqB,EAAEC,mBAAmB,EAAEC,gBAAgB,EAAEC,KAAK,QAAQ;AACpF,SAASC,qBAAqB,QAAQ;AACtC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,GAAG,EAAEC,KAAK,EAAEC,IAAI,QAAQ;AAC5E,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAEhC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,aAAa,QAAQ;AAE9B;;;;;;;;;AASA,OAAO,SAASC,qBACdC,KAA2B,EAC3BC,GAA8B,EACf;EACf,MAAM,CAACC,QAAA,EAAUC,eAAA,CAAgB,GAAGxB,KAAA,CAAMyB,QAAQ,CAACC,OAAO,CAACL,KAAA,CAAME,QAAQ;EAEzE,MAAMI,YAAA,GAAeT,uBAAA,CAAwBU,GA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;MACdE,YAAA,EAAc;QACZhF;MACF;IACF;IACA6E,IAAA,EAAMnG,qBAAA,CAAsBqC,EAAA,EAAI;MAC9BkE,QAAA,EAAU,CAAC;MACX,GAAG9D,IAAI;MACPZ,EAAA;MACAR,GAAA;MACAC,QAAA,EAAU,IAAI;MACd,cAAcM,KAAA;MACd,iBAAiBgB,QAAA,GAAWC,IAAA,GAAOV,SAAS;MAC5CqE,IAAA,EAAM;MACNlE,OAAA,EAAS2B,WAAA;MACT1B,SAAA,EAAWiC,aAAA;MACXiC,WAAA,EAAarE,OAAA,GAAUqD,WAAA,GAActD,SAAS;MAC9CuE,OAAA,EAAStE,OAAA,GAAUqD,WAAA,GAActD,SAAS;MAC1CwE,UAAA,EAAYvE,OAAA,GAAUsD,WAAA,GAAcvD,SAAS;MAC7CyE,MAAA,EAAQxE,OAAA,GAAUsD,WAAA,GAAcvD;IAClC;IACAH,UAAA,EAAY9B,gBAAA,CAAiB8B,UAAA,EAAY;MACvCoE,QAAA,EAAUxD,QAAA;MACV0D,YAAA,EAAc;QACZhF,QAAA,eAAUvB,KAAA,CAAA8G,aAAA,CAACzG,qBAAA;UAAsB0G,KAAA,EAAOvG,sBAAsB,CAAC2C,kBAAA;;QAC/D,eAAe,IAAI;QACnB7B,GAAA,EAAKN,aAAA,CAAcd,mBAAA,CAAoB+B,UAAA,IAAcA,UAAA,CAAWX,GAAG,GAAGc,SAAS,EAAEkB,aAAA;MACnF;IACF;IACAjB,OAAA,EAASlC,gBAAA,CAAiBkC,OAAA,EAAS;MACjCkE,YAAA,EAAc;QACZjF,GAAA,EAAKN,aAAA,CAAcd,mBAAA,CAAoBmC,OAAA,IAAWA,OAAA,CAAQf,GAAG,GAAGc,SAAS,EAAEgB,UAAA;MAC7E;IACF;EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/components/TreeItemLayout/TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { TreeItemContextValue } from '../../contexts/treeItemContext';\n\nexport type TreeItemLayoutSlots = {\n root: Slot<'
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/components/TreeItemLayout/TreeItemLayout.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { TreeItemContextValue } from '../../contexts/treeItemContext';\n\nexport type TreeItemLayoutSlots = {\n root: Slot<'span'>;\n /**\n * Icon slot that renders right before main content\n */\n iconBefore?: Slot<'span'>;\n /**\n * Icon slot that renders right after main content\n */\n iconAfter?: Slot<'span'>;\n /**\n * slot that render right after main content and iconAfter\n */\n aside?: Slot<'span'>;\n};\n\n/**\n * TreeItemLayout Props\n */\nexport type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutSlots>>;\n\n/**\n * State used in rendering TreeItemLayout\n */\nexport type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots> & TreeItemContextValue;\n"],"mappings":"AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
/** @jsxRuntime classic */ /** @jsx createElement */import { createElement } from '@fluentui/react-jsx-runtime';
|
|
2
|
+
import { getSlotsNext } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
4
|
* Render the final JSX of TreeItemLayout
|
|
5
5
|
*/
|
|
@@ -10,7 +10,7 @@ export const renderTreeItemLayout_unstable = state => {
|
|
|
10
10
|
const {
|
|
11
11
|
slots,
|
|
12
12
|
slotProps
|
|
13
|
-
} =
|
|
14
|
-
return /*#__PURE__*/
|
|
13
|
+
} = getSlotsNext(state);
|
|
14
|
+
return /*#__PURE__*/createElement(slots.root, slotProps.root, slots.iconBefore && /*#__PURE__*/createElement(slots.iconBefore, slotProps.iconBefore), slotProps.root.children, slots.iconAfter && /*#__PURE__*/createElement(slots.iconAfter, slotProps.iconAfter), !isActionsVisible && slots.aside && /*#__PURE__*/createElement(slots.aside, slotProps.aside));
|
|
15
15
|
};
|
|
16
16
|
//# sourceMappingURL=renderTreeItemLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createElement","getSlotsNext","renderTreeItemLayout_unstable","state","isActionsVisible","slots","slotProps","root","iconBefore","children","iconAfter","aside"],"sources":["../../../src/components/TreeItemLayout/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, TreeItemLayoutSlots } from './TreeItemLayout.types';\n\n/**\n * Render the final JSX of TreeItemLayout\n */\nexport const renderTreeItemLayout_unstable = (state: TreeItemLayoutState) => {\n const { isActionsVisible } = state;\n const { slots, slotProps } = getSlotsNext<TreeItemLayoutSlots>(state);\n return (\n <slots.root {...slotProps.root}>\n {slots.iconBefore && <slots.iconBefore {...slotProps.iconBefore} />}\n {slotProps.root.children}\n {slots.iconAfter && <slots.iconAfter {...slotProps.iconAfter} />}\n {!isActionsVisible && slots.aside && <slots.aside {...slotProps.aside} />}\n </slots.root>\n );\n};\n"],"mappings":"AAAA,2BACA,yBAEA,SAASA,aAAa,QAAQ;AAC9B,SAASC,YAAY,QAAQ;AAG7B;;;AAGA,OAAO,MAAMC,6BAAA,GAAiCC,KAAA,IAA+B;EAC3E,MAAM;IAAEC;EAAgB,CAAE,GAAGD,KAAA;EAC7B,MAAM;IAAEE,KAAA;IAAOC;EAAS,CAAE,GAAGL,YAAA,CAAkCE,KAAA;EAC/D,oBACEH,aAbJ,CAaKK,KAAA,CAAME,IAAI,EAAKD,SAAA,CAAUC,IAAI,EAC3BF,KAAA,CAAMG,UAAU,iBAAIR,aAd3B,CAc4BK,KAAA,CAAMG,UAAU,EAAKF,SAAA,CAAUE,UAAU,GAC9DF,SAAA,CAAUC,IAAI,CAACE,QAAQ,EACvBJ,KAAA,CAAMK,SAAS,iBAAIV,aAhB1B,CAgB2BK,KAAA,CAAMK,SAAS,EAAKJ,SAAA,CAAUI,SAAS,GAC3D,CAACN,gBAAA,IAAoBC,KAAA,CAAMM,KAAK,iBAAIX,aAjB3C,CAiB4CK,KAAA,CAAMM,KAAK,EAAKL,SAAA,CAAUK,KAAK;AAG3E"}
|
|
@@ -15,13 +15,13 @@ export const useTreeItemLayout_unstable = (props, ref) => {
|
|
|
15
15
|
iconAfter,
|
|
16
16
|
iconBefore,
|
|
17
17
|
aside,
|
|
18
|
-
as = '
|
|
18
|
+
as = 'span'
|
|
19
19
|
} = props;
|
|
20
20
|
const treeItemContext = useTreeItemContext_unstable();
|
|
21
21
|
return {
|
|
22
22
|
...treeItemContext,
|
|
23
23
|
components: {
|
|
24
|
-
root: '
|
|
24
|
+
root: 'span',
|
|
25
25
|
iconBefore: 'span',
|
|
26
26
|
iconAfter: 'span',
|
|
27
27
|
aside: 'span'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","getNativeElementProps","resolveShorthand","useTreeItemContext_unstable","useTreeItemLayout_unstable","props","ref","iconAfter","iconBefore","aside","as","treeItemContext","components","root","defaultProps"],"sources":["../../../src/components/TreeItemLayout/useTreeItemLayout.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types';\nimport { useTreeItemContext_unstable } from '../../contexts/treeItemContext';\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 { iconAfter, iconBefore, aside, as = '
|
|
1
|
+
{"version":3,"names":["React","getNativeElementProps","resolveShorthand","useTreeItemContext_unstable","useTreeItemLayout_unstable","props","ref","iconAfter","iconBefore","aside","as","treeItemContext","components","root","defaultProps"],"sources":["../../../src/components/TreeItemLayout/useTreeItemLayout.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities';\nimport type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types';\nimport { useTreeItemContext_unstable } from '../../contexts/treeItemContext';\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 { iconAfter, iconBefore, aside, as = 'span' } = props;\n const treeItemContext = useTreeItemContext_unstable();\n\n return {\n ...treeItemContext,\n components: {\n root: 'span',\n iconBefore: 'span',\n iconAfter: 'span',\n aside: 'span',\n },\n root: getNativeElementProps(as, { ...props, ref }),\n iconBefore: resolveShorthand(iconBefore, { defaultProps: { 'aria-hidden': true } }),\n iconAfter: resolveShorthand(iconAfter, { defaultProps: { 'aria-hidden': true } }),\n aside: resolveShorthand(aside, { defaultProps: { 'aria-hidden': true } }),\n };\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ;AAExD,SAASC,2BAA2B,QAAQ;AAE5C;;;;;;;;;AASA,OAAO,MAAMC,0BAAA,GAA6BA,CACxCC,KAAA,EACAC,GAAA,KACwB;EACxB,MAAM;IAAEC,SAAA;IAAWC,UAAA;IAAYC,KAAA;IAAOC,EAAA,GAAK;EAAM,CAAE,GAAGL,KAAA;EACtD,MAAMM,eAAA,GAAkBR,2BAAA;EAExB,OAAO;IACL,GAAGQ,eAAe;IAClBC,UAAA,EAAY;MACVC,IAAA,EAAM;MACNL,UAAA,EAAY;MACZD,SAAA,EAAW;MACXE,KAAA,EAAO;IACT;IACAI,IAAA,EAAMZ,qBAAA,CAAsBS,EAAA,EAAI;MAAE,GAAGL,KAAK;MAAEC;IAAI;IAChDE,UAAA,EAAYN,gBAAA,CAAiBM,UAAA,EAAY;MAAEM,YAAA,EAAc;QAAE,eAAe;MAAK;IAAE;IACjFP,SAAA,EAAWL,gBAAA,CAAiBK,SAAA,EAAW;MAAEO,YAAA,EAAc;QAAE,eAAe;MAAK;IAAE;IAC/EL,KAAA,EAAOP,gBAAA,CAAiBO,KAAA,EAAO;MAAEK,YAAA,EAAc;QAAE,eAAe;MAAK;IAAE;EACzE;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
/** @jsxRuntime classic */ /** @jsx createElement */import { createElement } from '@fluentui/react-jsx-runtime';
|
|
2
|
+
import { getSlotsNext } from '@fluentui/react-utilities';
|
|
3
3
|
import { AvatarContextProvider } from '@fluentui/react-avatar';
|
|
4
4
|
/**
|
|
5
5
|
* Render the final JSX of TreeItemPersonaLayout
|
|
@@ -11,9 +11,9 @@ export const renderTreeItemPersonaLayout_unstable = (state, contextValues) => {
|
|
|
11
11
|
const {
|
|
12
12
|
slots,
|
|
13
13
|
slotProps
|
|
14
|
-
} =
|
|
15
|
-
return /*#__PURE__*/
|
|
14
|
+
} = getSlotsNext(state);
|
|
15
|
+
return /*#__PURE__*/createElement(slots.root, slotProps.root, slots.media && /*#__PURE__*/createElement(AvatarContextProvider, {
|
|
16
16
|
value: contextValues.avatar
|
|
17
|
-
}, /*#__PURE__*/
|
|
17
|
+
}, /*#__PURE__*/createElement(slots.media, slotProps.media)), slots.content && /*#__PURE__*/createElement(slots.content, slotProps.content, slots.main && /*#__PURE__*/createElement(slots.main, slotProps.main), slots.description && /*#__PURE__*/createElement(slots.description, slotProps.description)), !isActionsVisible && slots.aside && /*#__PURE__*/createElement(slots.aside, slotProps.aside));
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=renderTreeItemPersonaLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createElement","getSlotsNext","AvatarContextProvider","renderTreeItemPersonaLayout_unstable","state","contextValues","isActionsVisible","slots","slotProps","root","media","value","avatar","content","main","description","aside"],"sources":["../../../src/components/TreeItemPersonaLayout/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 TreeItemPersonaLayoutSlots,\n TreeItemPersonaLayoutContextValues,\n} from './TreeItemPersonaLayout.types';\nimport { AvatarContextProvider } from '@fluentui/react-avatar';\n\n/**\n * Render the final JSX of TreeItemPersonaLayout\n */\nexport const renderTreeItemPersonaLayout_unstable = (\n state: TreeItemPersonaLayoutState,\n contextValues: TreeItemPersonaLayoutContextValues,\n) => {\n const { isActionsVisible } = state;\n const { slots, slotProps } = getSlotsNext<TreeItemPersonaLayoutSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.media && (\n <AvatarContextProvider value={contextValues.avatar}>\n <slots.media {...slotProps.media} />\n </AvatarContextProvider>\n )}\n {slots.content && (\n <slots.content {...slotProps.content}>\n {slots.main && <slots.main {...slotProps.main} />}\n {slots.description && <slots.description {...slotProps.description} />}\n </slots.content>\n )}\n {!isActionsVisible && slots.aside && <slots.aside {...slotProps.aside} />}\n </slots.root>\n );\n};\n"],"mappings":"AAAA,2BACA,yBAEA,SAASA,aAAa,QAAQ;AAC9B,SAASC,YAAY,QAAQ;AAM7B,SAASC,qBAAqB,QAAQ;AAEtC;;;AAGA,OAAO,MAAMC,oCAAA,GAAuCA,CAClDC,KAAA,EACAC,aAAA,KACG;EACH,MAAM;IAAEC;EAAgB,CAAE,GAAGF,KAAA;EAC7B,MAAM;IAAEG,KAAA;IAAOC;EAAS,CAAE,GAAGP,YAAA,CAAyCG,KAAA;EAEtE,oBACEJ,aAtBJ,CAsBKO,KAAA,CAAME,IAAI,EAAKD,SAAA,CAAUC,IAAI,EAC3BF,KAAA,CAAMG,KAAK,iBACVV,aAxBR,CAwBSE,qBAAA;IAAsBS,KAAA,EAAON,aAAA,CAAcO;kBAC1CZ,aAzBV,CAyBWO,KAAA,CAAMG,KAAK,EAAKF,SAAA,CAAUE,KAAK,IAGnCH,KAAA,CAAMM,OAAO,iBACZb,aA7BR,CA6BSO,KAAA,CAAMM,OAAO,EAAKL,SAAA,CAAUK,OAAO,EACjCN,KAAA,CAAMO,IAAI,iBAAId,aA9BzB,CA8B0BO,KAAA,CAAMO,IAAI,EAAKN,SAAA,CAAUM,IAAI,GAC5CP,KAAA,CAAMQ,WAAW,iBAAIf,aA/BhC,CA+BiCO,KAAA,CAAMQ,WAAW,EAAKP,SAAA,CAAUO,WAAW,IAGrE,CAACT,gBAAA,IAAoBC,KAAA,CAAMS,KAAK,iBAAIhB,aAlC3C,CAkC4CO,KAAA,CAAMS,KAAK,EAAKR,SAAA,CAAUQ,KAAK;AAG3E"}
|
|
@@ -15,10 +15,14 @@ const useRootStyles = /*#__PURE__*/__styles({
|
|
|
15
15
|
base: {
|
|
16
16
|
a9b677: "fly5x3f",
|
|
17
17
|
mc9l5x: "f22iagw",
|
|
18
|
-
Bt984gj: "f122n59"
|
|
18
|
+
Bt984gj: "f122n59",
|
|
19
|
+
Bahqtrf: "fk6fouc",
|
|
20
|
+
Be2twd7: "fkhj508",
|
|
21
|
+
Bhrd7zp: "figsok6",
|
|
22
|
+
Bg96gwp: "f1i3iumi"
|
|
19
23
|
}
|
|
20
24
|
}, {
|
|
21
|
-
d: [".fly5x3f{width:100%;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f122n59{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}"]
|
|
25
|
+
d: [".fly5x3f{width:100%;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f122n59{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}"]
|
|
22
26
|
});
|
|
23
27
|
/**
|
|
24
28
|
* Styles for the expand icon slot
|
|
@@ -52,16 +56,6 @@ const useContentStyles = /*#__PURE__*/__styles({
|
|
|
52
56
|
}, {
|
|
53
57
|
d: [".fly5x3f{width:100%;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".f1ngh7ph{padding-top:var(--spacingVerticalMNudge);}", ".f7x41pl{padding-right:var(--spacingHorizontalXS);}", ".fruq291{padding-left:var(--spacingHorizontalXS);}", ".f5o476b{padding-bottom:var(--spacingVerticalMNudge);}", ".f1f5gg8d{padding-left:var(--spacingHorizontalS);}", ".f1vdfbxk{padding-right:var(--spacingHorizontalS);}", ".f1fps8zv{-webkit-column-gap:var(--spacingVerticalNone);column-gap:var(--spacingVerticalNone);}", ".fws515f{row-gap:var(--spacingHorizontalNone);}"]
|
|
54
58
|
});
|
|
55
|
-
const useMainStyles = /*#__PURE__*/__styles({
|
|
56
|
-
base: {
|
|
57
|
-
Bahqtrf: "fk6fouc",
|
|
58
|
-
Be2twd7: "fkhj508",
|
|
59
|
-
Bhrd7zp: "figsok6",
|
|
60
|
-
Bg96gwp: "f1i3iumi"
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
d: [".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}"]
|
|
64
|
-
});
|
|
65
59
|
const useDescriptionStyles = /*#__PURE__*/__styles({
|
|
66
60
|
base: {
|
|
67
61
|
Bahqtrf: "fk6fouc",
|
|
@@ -93,7 +87,6 @@ export const useTreeItemPersonaLayoutStyles_unstable = state => {
|
|
|
93
87
|
const rootStyles = useRootStyles();
|
|
94
88
|
const mediaStyles = useMediaStyles();
|
|
95
89
|
const contentStyles = useContentStyles();
|
|
96
|
-
const mainStyles = useMainStyles();
|
|
97
90
|
const descriptionStyles = useDescriptionStyles();
|
|
98
91
|
const asideStyles = useAsideStyles();
|
|
99
92
|
state.root.className = mergeClasses(treeItemPersonaLayoutClassNames.root, rootStyles.base, state.root.className);
|
|
@@ -102,7 +95,7 @@ export const useTreeItemPersonaLayoutStyles_unstable = state => {
|
|
|
102
95
|
state.content.className = mergeClasses(treeItemPersonaLayoutClassNames.content, contentStyles.base, state.content.className);
|
|
103
96
|
}
|
|
104
97
|
if (state.main) {
|
|
105
|
-
state.main.className = mergeClasses(treeItemPersonaLayoutClassNames.main,
|
|
98
|
+
state.main.className = mergeClasses(treeItemPersonaLayoutClassNames.main, state.main.className);
|
|
106
99
|
}
|
|
107
100
|
if (state.description) {
|
|
108
101
|
state.description.className = mergeClasses(treeItemPersonaLayoutClassNames.description, descriptionStyles.base, state.description.className);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__styles","mergeClasses","shorthands","tokens","typographyStyles","treeItemPersonaLayoutClassNames","root","media","content","description","aside","main","useRootStyles","base","a9b677","mc9l5x","Bt984gj","
|
|
1
|
+
{"version":3,"names":["__styles","mergeClasses","shorthands","tokens","typographyStyles","treeItemPersonaLayoutClassNames","root","media","content","description","aside","main","useRootStyles","base","a9b677","mc9l5x","Bt984gj","Bahqtrf","Be2twd7","Bhrd7zp","Bg96gwp","d","useMediaStyles","Bqenvij","z8tnut","z189sj","Byoj8tv","uwmqm3","useContentStyles","Beiy3e4","i8kkvl","Belr9w4","useDescriptionStyles","useAsideStyles","Huce71","useTreeItemPersonaLayoutStyles_unstable","state","rootStyles","mediaStyles","contentStyles","descriptionStyles","asideStyles","className"],"sources":["../../../src/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.ts"],"sourcesContent":["import type { TreeItemPersonaLayoutSlots, TreeItemPersonaLayoutState } from './TreeItemPersonaLayout.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\n\nexport const treeItemPersonaLayoutClassNames: SlotClassNames<TreeItemPersonaLayoutSlots> = {\n root: 'fui-TreeItemPersonaLayout',\n media: 'fui-TreeItemPersonaLayout__media',\n content: 'fui-TreeItemPersonaLayout__content',\n description: 'fui-TreeItemPersonaLayout__description',\n aside: 'fui-TreeItemPersonaLayout__aside',\n main: 'fui-TreeItemPersonaLayout__main',\n};\n\n/**\n * Styles for the root slot\n */\nconst useRootStyles = makeStyles({\n base: {\n width: '100%',\n display: 'flex',\n alignItems: 'center',\n ...typographyStyles.body1,\n },\n});\n\n/**\n * Styles for the expand icon slot\n */\nconst useMediaStyles = makeStyles({\n base: {\n display: 'flex',\n alignItems: 'center',\n width: '32px',\n height: '32px',\n ...shorthands.padding(0, tokens.spacingHorizontalXS, 0, tokens.spacingHorizontalXXS),\n },\n});\n\nconst useContentStyles = makeStyles({\n base: {\n width: '100%',\n display: 'flex',\n flexDirection: 'column',\n ...shorthands.padding(\n tokens.spacingVerticalMNudge,\n tokens.spacingHorizontalXS,\n tokens.spacingVerticalMNudge,\n tokens.spacingHorizontalS,\n ),\n ...shorthands.gap(tokens.spacingVerticalNone, tokens.spacingHorizontalNone),\n },\n});\n\nconst useDescriptionStyles = makeStyles({\n base: {\n ...typographyStyles.caption1,\n },\n});\n\nconst useAsideStyles = makeStyles({\n base: {\n display: 'flex',\n flexDirection: 'column',\n whiteSpace: 'nowrap',\n paddingRight: tokens.spacingHorizontalM,\n ...typographyStyles.caption1,\n },\n});\n\n/**\n * Apply styling to the TreeItemPersonaLayout slots based on the state\n */\nexport const useTreeItemPersonaLayoutStyles_unstable = (\n state: TreeItemPersonaLayoutState,\n): TreeItemPersonaLayoutState => {\n const rootStyles = useRootStyles();\n const mediaStyles = useMediaStyles();\n const contentStyles = useContentStyles();\n const descriptionStyles = useDescriptionStyles();\n const asideStyles = useAsideStyles();\n\n state.root.className = mergeClasses(treeItemPersonaLayoutClassNames.root, rootStyles.base, state.root.className);\n\n state.media.className = mergeClasses(treeItemPersonaLayoutClassNames.media, mediaStyles.base, state.media.className);\n\n if (state.content) {\n state.content.className = mergeClasses(\n treeItemPersonaLayoutClassNames.content,\n contentStyles.base,\n state.content.className,\n );\n }\n if (state.main) {\n state.main.className = mergeClasses(treeItemPersonaLayoutClassNames.main, state.main.className);\n }\n if (state.description) {\n state.description.className = mergeClasses(\n treeItemPersonaLayoutClassNames.description,\n descriptionStyles.base,\n state.description.className,\n );\n }\n if (state.aside) {\n state.aside.className = mergeClasses(\n treeItemPersonaLayoutClassNames.aside,\n asideStyles.base,\n state.aside.className,\n );\n }\n\n return state;\n};\n"],"mappings":"AAEA,SAAAA,QAAA,EAAqBC,YAAY,EAAEC,UAAU,QAAQ;AACrD,SAASC,MAAM,EAAEC,gBAAgB,QAAQ;AAEzC,OAAO,MAAMC,+BAAA,GAA8E;EACzFC,IAAA,EAAM;EACNC,KAAA,EAAO;EACPC,OAAA,EAAS;EACTC,WAAA,EAAa;EACbC,KAAA,EAAO;EACPC,IAAA,EAAM;AACR;AAEA;;;AAGA,MAAMC,aAAA,gBAAgBZ,QAAA;EAAAa,IAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;IAAAC,OAAA;EAAA;AAAA;EAAAC,CAAA;AAAA,EAOtB;AAEA;;;AAGA,MAAMC,cAAA,gBAAiBtB,QAAA;EAAAa,IAAA;IAAAE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IN,KAAA,CAAM5B,OAAO,EAAE;IACjB4B,KAAA,CAAM5B,OAAO,CAACkC,SAAS,GAAGzC,YAAA,CACxBI,+BAAA,CAAgCG,OAAO,EACvC+B,aAAA,CAAc1B,IAAI,EAClBuB,KAAA,CAAM5B,OAAO,CAACkC,SAAS;EAE3B;EACA,IAAIN,KAAA,CAAMzB,IAAI,EAAE;IACdyB,KAAA,CAAMzB,IAAI,CAAC+B,SAAS,GAAGzC,YAAA,CAAaI,+BAAA,CAAgCM,IAAI,EAAEyB,KAAA,CAAMzB,IAAI,CAAC+B,SAAS;EAChG;EACA,IAAIN,KAAA,CAAM3B,WAAW,EAAE;IACrB2B,KAAA,CAAM3B,WAAW,CAACiC,SAAS,GAAGzC,YAAA,CAC5BI,+BAAA,CAAgCI,WAAW,EAC3C+B,iBAAA,CAAkB3B,IAAI,EACtBuB,KAAA,CAAM3B,WAAW,CAACiC,SAAS;EAE/B;EACA,IAAIN,KAAA,CAAM1B,KAAK,EAAE;IACf0B,KAAA,CAAM1B,KAAK,CAACgC,SAAS,GAAGzC,YAAA,CACtBI,+BAAA,CAAgCK,KAAK,EACrC+B,WAAA,CAAY5B,IAAI,EAChBuB,KAAA,CAAM1B,KAAK,CAACgC,SAAS;EAEzB;EAEA,OAAON,KAAA;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContextSelector","emptyImmutableSet","defaultContextValue","level","openItems","requestOpenChange","noop","requestNavigation","appearance","size","TreeContext","undefined","Provider","TreeProvider","useTreeContext_unstable","selector","ctx"],"sources":["../../src/contexts/treeContext.ts"],"sourcesContent":["import { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeNavigationData_unstable, TreeOpenChangeData } from '../Tree';\nimport {
|
|
1
|
+
{"version":3,"names":["createContext","useContextSelector","emptyImmutableSet","defaultContextValue","level","openItems","requestOpenChange","noop","requestNavigation","appearance","size","TreeContext","undefined","Provider","TreeProvider","useTreeContext_unstable","selector","ctx"],"sources":["../../src/contexts/treeContext.ts"],"sourcesContent":["import { Context, ContextSelector, createContext, useContextSelector } from '@fluentui/react-context-selector';\nimport { TreeNavigationData_unstable, TreeOpenChangeData } from '../Tree';\nimport { emptyImmutableSet, ImmutableSet } from '../utils/ImmutableSet';\n\nexport type TreeContextValue = {\n level: number;\n appearance: 'subtle' | 'subtle-alpha' | 'transparent';\n size: 'small' | 'medium';\n openItems: ImmutableSet<unknown>;\n /**\n * Requests dialog main component to update it's internal open state\n */\n requestOpenChange(data: TreeOpenChangeData<unknown>): void;\n requestNavigation(data: TreeNavigationData_unstable<unknown>): void;\n};\n\nconst defaultContextValue: TreeContextValue = {\n level: 0,\n openItems: emptyImmutableSet,\n requestOpenChange: noop,\n requestNavigation: 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"],"mappings":"AAAA,SAAmCA,aAAa,EAAEC,kBAAkB,QAAQ;AAE5E,SAASC,iBAAiB,QAAsB;AAchD,MAAMC,mBAAA,GAAwC;EAC5CC,KAAA,EAAO;EACPC,SAAA,EAAWH,iBAAA;EACXI,iBAAA,EAAmBC,IAAA;EACnBC,iBAAA,EAAmBD,IAAA;EACnBE,UAAA,EAAY;EACZC,IAAA,EAAM;AACR;AAEA,SAASH,KAAA,EAAO;EACd;AAGF,OAAO,MAAMI,WAAA,gBAAqDX,aAAA,CAChEY,SAAA;AAGF,OAAO,MAAM;EAAEC,QAAA,EAAUC;AAAY,CAAE,GAAGH,WAAA;AAC1C,OAAO,MAAMI,uBAAA,GAA8BC,QAAA,IACzCf,kBAAA,CAAmBU,WAAA,EAAa,CAACM,GAAA,GAAMd,mBAAmB,KAAKa,QAAA,CAASC,GAAA"}
|
package/lib/hooks/useFlatTree.js
CHANGED
|
@@ -37,13 +37,13 @@ export function useFlatTree_unstable(flatTreeItemProps, options = {}) {
|
|
|
37
37
|
event.preventDefault();
|
|
38
38
|
});
|
|
39
39
|
const getNextNavigableItem = useEventCallback((visibleItems, data) => {
|
|
40
|
-
const item = flatTreeItems.get(data.
|
|
40
|
+
const item = flatTreeItems.get(data.value);
|
|
41
41
|
if (item) {
|
|
42
42
|
switch (data.type) {
|
|
43
43
|
case treeDataTypes.typeAhead:
|
|
44
44
|
return item;
|
|
45
45
|
case treeDataTypes.arrowLeft:
|
|
46
|
-
return flatTreeItems.get(item.
|
|
46
|
+
return flatTreeItems.get(item.parentValue);
|
|
47
47
|
case treeDataTypes.arrowRight:
|
|
48
48
|
return visibleItems[item.index + 1];
|
|
49
49
|
case treeDataTypes.end:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEventCallback","React","createFlatTreeItems","VisibleFlatTreeItemGenerator","treeDataTypes","useFlatTreeNavigation","useOpenItemsState","useFlatTree_unstable","flatTreeItemProps","options","openItems","updateOpenItems","flatTreeItems","useMemo","navigate","navigationRef","handleOpenChange","event","data","_options_onOpenChange","onOpenChange","call","isDefaultPrevented","preventDefault","handleNavigation","_options_onNavigation_unstable","onNavigation_unstable","getNextNavigableItem","visibleItems","item","get","
|
|
1
|
+
{"version":3,"names":["useEventCallback","React","createFlatTreeItems","VisibleFlatTreeItemGenerator","treeDataTypes","useFlatTreeNavigation","useOpenItemsState","useFlatTree_unstable","flatTreeItemProps","options","openItems","updateOpenItems","flatTreeItems","useMemo","navigate","navigationRef","handleOpenChange","event","data","_options_onOpenChange","onOpenChange","call","isDefaultPrevented","preventDefault","handleNavigation","_options_onNavigation_unstable","onNavigation_unstable","getNextNavigableItem","visibleItems","item","get","value","type","typeAhead","arrowLeft","parentValue","arrowRight","index","end","length","home","arrowDown","arrowUp","getTreeProps","useCallback","ref","items"],"sources":["../../src/hooks/useFlatTree.ts"],"sourcesContent":["import { useEventCallback } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { createFlatTreeItems, VisibleFlatTreeItemGenerator } from '../utils/createFlatTreeItems';\nimport { treeDataTypes } from '../utils/tokens';\nimport { useFlatTreeNavigation } from './useFlatTreeNavigation';\nimport { useOpenItemsState } from './useOpenItemsState';\nimport type {\n TreeNavigationData_unstable,\n TreeNavigationEvent_unstable,\n TreeOpenChangeData,\n TreeOpenChangeEvent,\n TreeProps,\n} from '../Tree';\nimport type { TreeItemProps } from '../TreeItem';\n\nexport type FlatTreeItemProps<Value = string> = Omit<TreeItemProps, 'value'> & {\n value: Value;\n parentValue?: Value;\n};\n\nexport type FlatTreeItem<Value = string> = Readonly<MutableFlatTreeItem<Value>>;\n\n/**\n * @internal\n * Used internally on createFlatTreeItems and VisibleFlatTreeItemGenerator\n * to ensure required properties when building a FlatTreeITem\n */\nexport type MutableFlatTreeItem<Value = string> = {\n parentValue?: Value;\n childrenSize: number;\n index: number;\n value: Value;\n level: number;\n ref: React.RefObject<HTMLDivElement>;\n getTreeItemProps(): Required<\n Pick<TreeItemProps<Value>, 'value' | 'aria-setsize' | 'aria-level' | 'aria-posinset' | 'leaf'>\n > &\n TreeItemProps<Value>;\n};\n\nexport type FlatTreeProps<Value = string> = Required<\n Pick<TreeProps<Value>, 'openItems' | 'onOpenChange' | 'onNavigation_unstable'> & { ref: React.Ref<HTMLDivElement> }\n>;\n\n/**\n * FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems\n * in multiple scenarios including virtualization.\n *\n * !!A flat tree is an unofficial spec for tree!!\n *\n * It should be used on cases where more complex interactions with a Tree is required.\n *\n * On simple scenarios it is advised to simply use a nested structure instead.\n */\nexport type FlatTree<Value = string> = {\n /**\n * returns the properties required for the Tree component to work properly.\n * That includes:\n * `openItems`, `onOpenChange`, `onNavigation_unstable` and `ref`\n */\n getTreeProps(): FlatTreeProps<Value>;\n /**\n * internal method used to react to an `onNavigation` event.\n * This method ensures proper navigation on keyboard and mouse interaction.\n * In case of virtualization it might be required to cancel default provided `onNavigation`\n * event and then call this method manually.\n *\n * @example\n * ```ts\n * // react-window\n * const handleNavigation = (event, data) => {\n * event.preventDefault();\n * const nextItem = tree.getNextNavigableItem(data);\n * // scroll to item using virtualization scroll mechanism\n * if (nextItem && document.getElementById(nextItem.id)) {\n * listRef.current.scrollToItem(nextItem.index);\n * }\n * // wait for scrolling to happen and then invoke navigate method\n * requestAnimationFrame(() => {\n * tree.navigate(data);\n * });\n * };\n *```\n */\n navigate(data: TreeNavigationData_unstable<Value>): void;\n /**\n * returns next item to be focused on a navigation.\n * This method is provided to decouple the element that needs to be focused from\n * the action of focusing it itself.\n *\n * On the case of TypeAhead navigation this method returns the current item.\n */\n getNextNavigableItem(\n visibleItems: FlatTreeItem<Value>[],\n data: TreeNavigationData_unstable<Value>,\n ): FlatTreeItem<Value> | undefined;\n /**\n * an iterable containing all visually available flat tree items\n */\n items(): IterableIterator<FlatTreeItem<Value>>;\n};\n\n/**\n * this hook provides FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems\n * in multiple scenarios including virtualization.\n *\n * !!A flat tree is an unofficial spec for tree!!\n *\n * It should be used on cases where more complex interactions with a Tree is required.\n * On simple scenarios it is advised to simply use a nested structure instead.\n *\n * @param flatTreeItemProps - a list of tree items\n * @param options - in case control over the internal openItems is required\n */\nexport function useFlatTree_unstable<Value = string>(\n flatTreeItemProps: FlatTreeItemProps<Value>[],\n options: Pick<TreeProps<Value>, 'openItems' | 'defaultOpenItems' | 'onOpenChange' | 'onNavigation_unstable'> = {},\n): FlatTree<Value> {\n const [openItems, updateOpenItems] = useOpenItemsState(options);\n const flatTreeItems = React.useMemo(() => createFlatTreeItems(flatTreeItemProps), [flatTreeItemProps]);\n const [navigate, navigationRef] = useFlatTreeNavigation(flatTreeItems);\n\n const handleOpenChange = useEventCallback((event: TreeOpenChangeEvent, data: TreeOpenChangeData<Value>) => {\n options.onOpenChange?.(event, data);\n if (!event.isDefaultPrevented()) {\n updateOpenItems(data);\n }\n event.preventDefault();\n });\n\n const handleNavigation = useEventCallback(\n (event: TreeNavigationEvent_unstable, data: TreeNavigationData_unstable<Value>) => {\n options.onNavigation_unstable?.(event, data);\n if (!event.isDefaultPrevented()) {\n navigate(data);\n }\n event.preventDefault();\n },\n );\n\n const getNextNavigableItem = useEventCallback(\n (visibleItems: FlatTreeItem<Value>[], data: TreeNavigationData_unstable<Value>) => {\n const item = flatTreeItems.get(data.value);\n if (item) {\n switch (data.type) {\n case treeDataTypes.typeAhead:\n return item;\n case treeDataTypes.arrowLeft:\n return flatTreeItems.get(item.parentValue!);\n case treeDataTypes.arrowRight:\n return visibleItems[item.index + 1];\n case treeDataTypes.end:\n return visibleItems[visibleItems.length - 1];\n case treeDataTypes.home:\n return visibleItems[0];\n case treeDataTypes.arrowDown:\n return visibleItems[item.index + 1];\n case treeDataTypes.arrowUp:\n return visibleItems[item.index - 1];\n }\n }\n },\n );\n\n const getTreeProps = React.useCallback(\n () => ({\n ref: navigationRef as React.Ref<HTMLDivElement>,\n openItems,\n onOpenChange: handleOpenChange,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n onNavigation_unstable: handleNavigation,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [openItems],\n );\n\n const items = React.useCallback(\n () => VisibleFlatTreeItemGenerator<Value>(openItems, flatTreeItems),\n [openItems, flatTreeItems],\n );\n\n return React.useMemo(\n () => ({ navigate, getTreeProps, getNextNavigableItem, items }),\n [navigate, getTreeProps, getNextNavigableItem, items],\n );\n}\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ;AACjC,YAAYC,KAAA,MAAW;AACvB,SAASC,mBAAmB,EAAEC,4BAA4B,QAAQ;AAClE,SAASC,aAAa,QAAQ;AAC9B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,iBAAiB,QAAQ;AAiGlC;;;;;;;;;;;;AAYA,OAAO,SAASC,qBACdC,iBAA6C,EAC7CC,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AA;QACT,KAAKzB,aAAA,CAAc8B,SAAS;UAC1B,OAAOtB,aAAA,CAAckB,GAAG,CAACD,IAAA,CAAKM,WAAW;QAC3C,KAAK/B,aAAA,CAAcgC,UAAU;UAC3B,OAAOR,YAAY,CAACC,IAAA,CAAKQ,KAAK,GAAG,EAAE;QACrC,KAAKjC,aAAA,CAAckC,GAAG;UACpB,OAAOV,YAAY,CAACA,YAAA,CAAaW,MAAM,GAAG,EAAE;QAC9C,KAAKnC,aAAA,CAAcoC,IAAI;UACrB,OAAOZ,YAAY,CAAC,EAAE;QACxB,KAAKxB,aAAA,CAAcqC,SAAS;UAC1B,OAAOb,YAAY,CAACC,IAAA,CAAKQ,KAAK,GAAG,EAAE;QACrC,KAAKjC,aAAA,CAAcsC,OAAO;UACxB,OAAOd,YAAY,CAACC,IAAA,CAAKQ,KAAK,GAAG,EAAE;MAAA;IAEzC;EACF;EAGF,MAAMM,YAAA,GAAe1C,KAAA,CAAM2C,WAAW,CACpC,OAAO;IACLC,GAAA,EAAK9B,aAAA;IACLL,SAAA;IACAU,YAAA,EAAcJ,gBAAA;IACd;IACAU,qBAAA,EAAuBF;EACzB;EACA;EACA,CAACd,SAAA,CAAU;EAGb,MAAMoC,KAAA,GAAQ7C,KAAA,CAAM2C,WAAW,CAC7B,MAAMzC,4BAAA,CAAoCO,SAAA,EAAWE,aAAA,GACrD,CAACF,SAAA,EAAWE,aAAA,CAAc;EAG5B,OAAOX,KAAA,CAAMY,OAAO,CAClB,OAAO;IAAEC,QAAA;IAAU6B,YAAA;IAAchB,oBAAA;IAAsBmB;EAAM,IAC7D,CAAChC,QAAA,EAAU6B,YAAA,EAAchB,oBAAA,EAAsBmB,KAAA,CAAM;AAEzD"}
|
|
@@ -25,7 +25,7 @@ export function useFlatTreeNavigation(flatTreeItems) {
|
|
|
25
25
|
treeItemWalker.currentElement = data.target;
|
|
26
26
|
return nextTypeAheadElement(treeItemWalker, data.event.key);
|
|
27
27
|
case treeDataTypes.arrowLeft:
|
|
28
|
-
return parentElement(flatTreeItems, data.
|
|
28
|
+
return parentElement(flatTreeItems, data.value);
|
|
29
29
|
case treeDataTypes.arrowRight:
|
|
30
30
|
treeItemWalker.currentElement = data.target;
|
|
31
31
|
return firstChild(data.target, treeItemWalker);
|
|
@@ -64,10 +64,12 @@ function firstChild(target, treeWalker) {
|
|
|
64
64
|
}
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
|
-
function parentElement(flatTreeItems,
|
|
68
|
-
const flatTreeItem = flatTreeItems.get(
|
|
69
|
-
if (flatTreeItem
|
|
70
|
-
|
|
67
|
+
function parentElement(flatTreeItems, value) {
|
|
68
|
+
const flatTreeItem = flatTreeItems.get(value);
|
|
69
|
+
if (flatTreeItem === null || flatTreeItem === void 0 ? void 0 : flatTreeItem.parentValue) {
|
|
70
|
+
const parentItem = flatTreeItems.get(flatTreeItem.parentValue);
|
|
71
|
+
var _parentItem_ref_current;
|
|
72
|
+
return (_parentItem_ref_current = parentItem === null || parentItem === void 0 ? void 0 : parentItem.ref.current) !== null && _parentItem_ref_current !== void 0 ? _parentItem_ref_current : null;
|
|
71
73
|
}
|
|
72
74
|
return null;
|
|
73
75
|
}
|