@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,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* creates a list of flat tree items
|
|
3
|
-
* and provides a map to access each item by id
|
|
4
|
-
*/ "use strict";
|
|
1
|
+
"use strict";
|
|
5
2
|
Object.defineProperty(exports, "__esModule", {
|
|
6
3
|
value: true
|
|
7
4
|
});
|
|
@@ -16,9 +13,11 @@ _export(exports, {
|
|
|
16
13
|
flatTreeRootId: ()=>flatTreeRootId,
|
|
17
14
|
VisibleFlatTreeItemGenerator: ()=>VisibleFlatTreeItemGenerator
|
|
18
15
|
});
|
|
16
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
17
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
19
18
|
function createFlatTreeItems(flatTreeItemProps) {
|
|
20
19
|
const root = createFlatTreeRootItem();
|
|
21
|
-
const
|
|
20
|
+
const itemsPerValue = new Map([
|
|
22
21
|
[
|
|
23
22
|
flatTreeRootId,
|
|
24
23
|
root
|
|
@@ -26,9 +25,9 @@ function createFlatTreeItems(flatTreeItemProps) {
|
|
|
26
25
|
]);
|
|
27
26
|
const items = [];
|
|
28
27
|
for(let index = 0; index < flatTreeItemProps.length; index++){
|
|
29
|
-
const {
|
|
28
|
+
const { parentValue =flatTreeRootId , ...treeItemProps } = flatTreeItemProps[index];
|
|
30
29
|
const nextItemProps = flatTreeItemProps[index + 1];
|
|
31
|
-
const currentParent =
|
|
30
|
+
const currentParent = itemsPerValue.get(parentValue);
|
|
32
31
|
if (!currentParent) {
|
|
33
32
|
if (process.env.NODE_ENV === 'development') {
|
|
34
33
|
// eslint-disable-next-line no-console
|
|
@@ -36,46 +35,53 @@ function createFlatTreeItems(flatTreeItemProps) {
|
|
|
36
35
|
}
|
|
37
36
|
break;
|
|
38
37
|
}
|
|
39
|
-
const isLeaf = (nextItemProps === null || nextItemProps === void 0 ? void 0 : nextItemProps.
|
|
38
|
+
const isLeaf = (nextItemProps === null || nextItemProps === void 0 ? void 0 : nextItemProps.parentValue) !== treeItemProps.value;
|
|
40
39
|
var _currentParent_level;
|
|
41
40
|
const currentLevel = ((_currentParent_level = currentParent.level) !== null && _currentParent_level !== void 0 ? _currentParent_level : 0) + 1;
|
|
42
41
|
const currentChildrenSize = ++currentParent.childrenSize;
|
|
42
|
+
const ref = /*#__PURE__*/ _react.createRef();
|
|
43
43
|
const flatTreeItem = {
|
|
44
|
-
|
|
44
|
+
value: treeItemProps.value,
|
|
45
45
|
getTreeItemProps: ()=>({
|
|
46
46
|
...treeItemProps,
|
|
47
47
|
'aria-level': currentLevel,
|
|
48
48
|
'aria-posinset': currentChildrenSize,
|
|
49
49
|
'aria-setsize': currentParent.childrenSize,
|
|
50
|
-
leaf: isLeaf
|
|
50
|
+
leaf: isLeaf,
|
|
51
|
+
// a reference to every parent element is necessary to ensure navigation
|
|
52
|
+
ref: flatTreeItem.childrenSize > 0 ? ref : undefined
|
|
51
53
|
}),
|
|
54
|
+
ref,
|
|
52
55
|
level: currentLevel,
|
|
53
|
-
|
|
56
|
+
parentValue,
|
|
54
57
|
childrenSize: 0,
|
|
55
58
|
index: -1
|
|
56
59
|
};
|
|
57
|
-
|
|
60
|
+
itemsPerValue.set(flatTreeItem.value, flatTreeItem);
|
|
58
61
|
items.push(flatTreeItem);
|
|
59
62
|
}
|
|
60
63
|
return {
|
|
61
64
|
root,
|
|
62
65
|
size: items.length,
|
|
63
66
|
getByIndex: (index)=>items[index],
|
|
64
|
-
get: (id)=>
|
|
65
|
-
set: (id, value)=>
|
|
67
|
+
get: (id)=>itemsPerValue.get(id),
|
|
68
|
+
set: (id, value)=>itemsPerValue.set(id, value)
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
const flatTreeRootId = '__fuiFlatTreeRoot';
|
|
69
72
|
function createFlatTreeRootItem() {
|
|
70
73
|
return {
|
|
71
|
-
|
|
74
|
+
ref: {
|
|
75
|
+
current: null
|
|
76
|
+
},
|
|
77
|
+
value: flatTreeRootId,
|
|
72
78
|
getTreeItemProps: ()=>{
|
|
73
79
|
if (process.env.NODE_ENV !== 'production') {
|
|
74
80
|
// eslint-disable-next-line no-console
|
|
75
81
|
console.error('useFlatTree: internal error, trying to access treeitem props from invalid root element');
|
|
76
82
|
}
|
|
77
83
|
return {
|
|
78
|
-
|
|
84
|
+
value: flatTreeRootId,
|
|
79
85
|
'aria-setsize': -1,
|
|
80
86
|
'aria-level': -1,
|
|
81
87
|
'aria-posinset': -1,
|
|
@@ -97,7 +103,7 @@ function* VisibleFlatTreeItemGenerator(openItems, flatTreeItems) {
|
|
|
97
103
|
for(let index = 0, visibleIndex = 0; index < flatTreeItems.size; index++){
|
|
98
104
|
const item = flatTreeItems.getByIndex(index);
|
|
99
105
|
var _flatTreeItems_get;
|
|
100
|
-
const parent = item.
|
|
106
|
+
const parent = item.parentValue ? (_flatTreeItems_get = flatTreeItems.get(item.parentValue)) !== null && _flatTreeItems_get !== void 0 ? _flatTreeItems_get : flatTreeItems.root : flatTreeItems.root;
|
|
101
107
|
if (isItemVisible(item, openItems, flatTreeItems)) {
|
|
102
108
|
item.index = visibleIndex++;
|
|
103
109
|
yield item;
|
|
@@ -110,11 +116,11 @@ function isItemVisible(item, openItems, flatTreeItems) {
|
|
|
110
116
|
if (item.level === 1) {
|
|
111
117
|
return true;
|
|
112
118
|
}
|
|
113
|
-
while(item.
|
|
114
|
-
if (!openItems.has(item.
|
|
119
|
+
while(item.parentValue && item.parentValue !== flatTreeItems.root.value){
|
|
120
|
+
if (!openItems.has(item.parentValue)) {
|
|
115
121
|
return false;
|
|
116
122
|
}
|
|
117
|
-
const parent = flatTreeItems.get(item.
|
|
123
|
+
const parent = flatTreeItems.get(item.parentValue);
|
|
118
124
|
if (!parent) {
|
|
119
125
|
return false;
|
|
120
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/createFlatTreeItems.js"],"sourcesContent":["/**\n * creates a list of flat tree items\n * and provides a map to access each item by id\n
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/createFlatTreeItems.js"],"sourcesContent":["import * as React from 'react';\n/**\n * creates a list of flat tree items\n * and provides a map to access each item by id\n */\nexport function createFlatTreeItems(flatTreeItemProps) {\n const root = createFlatTreeRootItem();\n const itemsPerValue = new Map([[flatTreeRootId, root]]);\n const items = [];\n for (let index = 0; index < flatTreeItemProps.length; index++) {\n const {\n parentValue = flatTreeRootId,\n ...treeItemProps\n } = flatTreeItemProps[index];\n const nextItemProps = flatTreeItemProps[index + 1];\n const currentParent = itemsPerValue.get(parentValue);\n if (!currentParent) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error(`useFlatTree: item ${flatTreeItemProps[index].id} is wrongly positioned, did you properly ordered provided item props? make sure provided items are organized`);\n }\n break;\n }\n const isLeaf = (nextItemProps === null || nextItemProps === void 0 ? void 0 : nextItemProps.parentValue) !== treeItemProps.value;\n var _currentParent_level;\n const currentLevel = ((_currentParent_level = currentParent.level) !== null && _currentParent_level !== void 0 ? _currentParent_level : 0) + 1;\n const currentChildrenSize = ++currentParent.childrenSize;\n const ref = /*#__PURE__*/React.createRef();\n const flatTreeItem = {\n value: treeItemProps.value,\n getTreeItemProps: () => ({\n ...treeItemProps,\n 'aria-level': currentLevel,\n 'aria-posinset': currentChildrenSize,\n 'aria-setsize': currentParent.childrenSize,\n leaf: isLeaf,\n // a reference to every parent element is necessary to ensure navigation\n ref: flatTreeItem.childrenSize > 0 ? ref : undefined\n }),\n ref,\n level: currentLevel,\n parentValue,\n childrenSize: 0,\n index: -1\n };\n itemsPerValue.set(flatTreeItem.value, flatTreeItem);\n items.push(flatTreeItem);\n }\n return {\n root,\n size: items.length,\n getByIndex: index => items[index],\n get: id => itemsPerValue.get(id),\n set: (id, value) => itemsPerValue.set(id, value)\n };\n}\nexport const flatTreeRootId = '__fuiFlatTreeRoot';\nfunction createFlatTreeRootItem() {\n return {\n ref: {\n current: null\n },\n value: flatTreeRootId,\n getTreeItemProps: () => {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('useFlatTree: internal error, trying to access treeitem props from invalid root element');\n }\n return {\n value: flatTreeRootId,\n 'aria-setsize': -1,\n 'aria-level': -1,\n 'aria-posinset': -1,\n leaf: true\n };\n },\n childrenSize: 0,\n get index() {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('useFlatTree: internal error, trying to access treeitem props from invalid root element');\n }\n return -1;\n },\n level: 0\n };\n}\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function* VisibleFlatTreeItemGenerator(openItems, flatTreeItems) {\n for (let index = 0, visibleIndex = 0; index < flatTreeItems.size; index++) {\n const item = flatTreeItems.getByIndex(index);\n var _flatTreeItems_get;\n const parent = item.parentValue ? (_flatTreeItems_get = flatTreeItems.get(item.parentValue)) !== null && _flatTreeItems_get !== void 0 ? _flatTreeItems_get : flatTreeItems.root : flatTreeItems.root;\n if (isItemVisible(item, openItems, flatTreeItems)) {\n item.index = visibleIndex++;\n yield item;\n } else {\n index += parent.childrenSize - 1 + item.childrenSize;\n }\n }\n}\nfunction isItemVisible(item, openItems, flatTreeItems) {\n if (item.level === 1) {\n return true;\n }\n while (item.parentValue && item.parentValue !== flatTreeItems.root.value) {\n if (!openItems.has(item.parentValue)) {\n return false;\n }\n const parent = flatTreeItems.get(item.parentValue);\n if (!parent) {\n return false;\n }\n item = parent;\n }\n return true;\n}\n//# sourceMappingURL=createFlatTreeItems.js.map"],"names":["createFlatTreeItems","flatTreeRootId","VisibleFlatTreeItemGenerator","flatTreeItemProps","root","createFlatTreeRootItem","itemsPerValue","Map","items","index","length","parentValue","treeItemProps","nextItemProps","currentParent","get","process","env","NODE_ENV","console","error","id","isLeaf","value","_currentParent_level","currentLevel","level","currentChildrenSize","childrenSize","ref","React","createRef","flatTreeItem","getTreeItemProps","leaf","undefined","set","push","size","getByIndex","current","openItems","flatTreeItems","visibleIndex","item","_flatTreeItems_get","parent","isItemVisible","has"],"mappings":";;;;;;;;;;;IAKgBA,mBAAmB,MAAnBA;IAmDHC,cAAc,MAAdA;IAgCIC,4BAA4B,MAA5BA;;;6DAxFM;AAKhB,SAASF,oBAAoBG,iBAAiB,EAAE;IACrD,MAAMC,OAAOC;IACb,MAAMC,gBAAgB,IAAIC,IAAI;QAAC;YAACN;YAAgBG;SAAK;KAAC;IACtD,MAAMI,QAAQ,EAAE;IAChB,IAAK,IAAIC,QAAQ,GAAGA,QAAQN,kBAAkBO,MAAM,EAAED,QAAS;QAC7D,MAAM,EACJE,aAAcV,eAAc,EAC5B,GAAGW,eACJ,GAAGT,iBAAiB,CAACM,MAAM;QAC5B,MAAMI,gBAAgBV,iBAAiB,CAACM,QAAQ,EAAE;QAClD,MAAMK,gBAAgBR,cAAcS,GAAG,CAACJ;QACxC,IAAI,CAACG,eAAe;YAClB,IAAIE,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;gBAC1C,sCAAsC;gBACtCC,QAAQC,KAAK,CAAC,CAAC,kBAAkB,EAAEjB,iBAAiB,CAACM,MAAM,CAACY,EAAE,CAAC,4GAA4G,CAAC;YAC9K,CAAC;YACD,KAAM;QACR,CAAC;QACD,MAAMC,SAAS,AAACT,CAAAA,kBAAkB,IAAI,IAAIA,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcF,WAAW,AAAD,MAAOC,cAAcW,KAAK;QAChI,IAAIC;QACJ,MAAMC,eAAe,AAAC,CAAA,AAACD,CAAAA,uBAAuBV,cAAcY,KAAK,AAAD,MAAO,IAAI,IAAIF,yBAAyB,KAAK,IAAIA,uBAAuB,CAAC,AAAD,IAAK;QAC7I,MAAMG,sBAAsB,EAAEb,cAAcc,YAAY;QACxD,MAAMC,MAAM,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;IACtE,IAAK,IAAIjC,QAAQ,GAAGkC,eAAe,GAAGlC,QAAQiC,cAAcJ,IAAI,EAAE7B,QAAS;QACzE,MAAMmC,OAAOF,cAAcH,UAAU,CAAC9B;QACtC,IAAIoC;QACJ,MAAMC,SAASF,KAAKjC,WAAW,GAAG,AAACkC,CAAAA,qBAAqBH,cAAc3B,GAAG,CAAC6B,KAAKjC,WAAW,CAAA,MAAO,IAAI,IAAIkC,uBAAuB,KAAK,IAAIA,qBAAqBH,cAActC,IAAI,GAAGsC,cAActC,IAAI;QACrM,IAAI2C,cAAcH,MAAMH,WAAWC,gBAAgB;YACjDE,KAAKnC,KAAK,GAAGkC;YACb,MAAMC;QACR,OAAO;YACLnC,SAASqC,OAAOlB,YAAY,GAAG,IAAIgB,KAAKhB,YAAY;QACtD,CAAC;IACH;AACF;AACA,SAASmB,cAAcH,IAAI,EAAEH,SAAS,EAAEC,aAAa,EAAE;IACrD,IAAIE,KAAKlB,KAAK,KAAK,GAAG;QACpB,OAAO,IAAI;IACb,CAAC;IACD,MAAOkB,KAAKjC,WAAW,IAAIiC,KAAKjC,WAAW,KAAK+B,cAActC,IAAI,CAACmB,KAAK,CAAE;QACxE,IAAI,CAACkB,UAAUO,GAAG,CAACJ,KAAKjC,WAAW,GAAG;YACpC,OAAO,KAAK;QACd,CAAC;QACD,MAAMmC,SAASJ,cAAc3B,GAAG,CAAC6B,KAAKjC,WAAW;QACjD,IAAI,CAACmC,QAAQ;YACX,OAAO,KAAK;QACd,CAAC;QACDF,OAAOE;IACT;IACA,OAAO,IAAI;AACb,EACA,+CAA+C"}
|
|
@@ -18,12 +18,14 @@ let count = 1;
|
|
|
18
18
|
function flattenTreeRecursive(items, parent, level = 1) {
|
|
19
19
|
return items.reduce((acc, { subtree , ...item }, index)=>{
|
|
20
20
|
var _item_id;
|
|
21
|
+
const id = (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : `fui-FlatTreeItem-${count++}`;
|
|
22
|
+
var _item_value;
|
|
21
23
|
const flatTreeItem = {
|
|
22
24
|
'aria-level': level,
|
|
23
25
|
'aria-posinset': index + 1,
|
|
24
26
|
'aria-setsize': items.length,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
parentValue: parent === null || parent === void 0 ? void 0 : parent.value,
|
|
28
|
+
value: (_item_value = item.value) !== null && _item_value !== void 0 ? _item_value : id,
|
|
27
29
|
leaf: subtree === undefined,
|
|
28
30
|
...item
|
|
29
31
|
};
|
|
@@ -40,12 +42,14 @@ const flattenTreeFromElement = (root, parent, level = 1)=>{
|
|
|
40
42
|
return children.reduce((acc, curr, index)=>{
|
|
41
43
|
const [content, subtree] = _react.Children.toArray(curr.props.children);
|
|
42
44
|
var _curr_props_id;
|
|
45
|
+
const id = (_curr_props_id = curr.props.id) !== null && _curr_props_id !== void 0 ? _curr_props_id : `fui-FlatTreeItem-${count++}`;
|
|
46
|
+
var _curr_props_value;
|
|
43
47
|
const flatTreeItem = {
|
|
44
48
|
'aria-level': level,
|
|
45
49
|
'aria-posinset': index + 1,
|
|
46
50
|
'aria-setsize': children.length,
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
parentValue: parent === null || parent === void 0 ? void 0 : parent.value,
|
|
52
|
+
value: (_curr_props_value = curr.props.value) !== null && _curr_props_value !== void 0 ? _curr_props_value : id,
|
|
49
53
|
leaf: subtree === undefined,
|
|
50
54
|
...curr.props,
|
|
51
55
|
children: content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/utils/flattenTree.js"],"sourcesContent":["import * as React from 'react';\nlet count = 1;\nfunction flattenTreeRecursive(items, parent, level = 1) {\n return items.reduce((acc, {\n subtree,\n ...item\n }, index) => {\n var _item_id;\n const flatTreeItem = {\n 'aria-level': level,\n 'aria-posinset': index + 1,\n 'aria-setsize': items.length,\n
|
|
1
|
+
{"version":3,"sources":["../../lib/utils/flattenTree.js"],"sourcesContent":["import * as React from 'react';\nlet count = 1;\nfunction flattenTreeRecursive(items, parent, level = 1) {\n return items.reduce((acc, {\n subtree,\n ...item\n }, index) => {\n var _item_id;\n const id = (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : `fui-FlatTreeItem-${count++}`;\n var _item_value;\n const flatTreeItem = {\n 'aria-level': level,\n 'aria-posinset': index + 1,\n 'aria-setsize': items.length,\n parentValue: parent === null || parent === void 0 ? void 0 : parent.value,\n value: (_item_value = item.value) !== null && _item_value !== void 0 ? _item_value : id,\n leaf: subtree === undefined,\n ...item\n };\n acc.push(flatTreeItem);\n if (subtree !== undefined) {\n acc.push(...flattenTreeRecursive(subtree, flatTreeItem, level + 1));\n }\n return acc;\n }, []);\n}\n/**\n * Converts a nested structure to a flat one which can be consumed by `useFlatTreeItems`\n * @example\n * ```tsx\n * const defaultItems = flattenTree_unstable([\n * {\n * children: <TreeItemLayout>level 1, item 1</TreeItemLayout>,\n * subtree: [\n * {\n * children: <TreeItemLayout>level 2, item 1</TreeItemLayout>,\n * },\n * {\n * children: <TreeItemLayout>level 2, item 2</TreeItemLayout>,\n * },\n * {\n * children: <TreeItemLayout>level 2, item 3</TreeItemLayout>,\n * },\n * ],\n * },\n * {\n * children: <TreeItemLayout>level 1, item 2</TreeItemLayout>,\n * subtree: [\n * {\n * children: <TreeItemLayout>level 2, item 1</TreeItemLayout>,\n * subtree: [\n * {\n * children: <TreeItemLayout>level 3, item 1</TreeItemLayout>,\n * subtree: [\n * {\n * children: <TreeItemLayout>level 4, item 1</TreeItemLayout>,\n * },\n * ],\n * },\n * ],\n * },\n * ],\n * },\n * ]);\n * ```\n */ // eslint-disable-next-line @typescript-eslint/naming-convention\nexport const flattenTree_unstable = items => flattenTreeRecursive(items);\n/**\n * @internal\n */\nexport const flattenTreeFromElement = (root, parent, level = 1) => {\n const children = React.Children.toArray(root.props.children);\n return children.reduce((acc, curr, index) => {\n const [content, subtree] = React.Children.toArray(curr.props.children);\n var _curr_props_id;\n const id = (_curr_props_id = curr.props.id) !== null && _curr_props_id !== void 0 ? _curr_props_id : `fui-FlatTreeItem-${count++}`;\n var _curr_props_value;\n const flatTreeItem = {\n 'aria-level': level,\n 'aria-posinset': index + 1,\n 'aria-setsize': children.length,\n parentValue: parent === null || parent === void 0 ? void 0 : parent.value,\n value: (_curr_props_value = curr.props.value) !== null && _curr_props_value !== void 0 ? _curr_props_value : id,\n leaf: subtree === undefined,\n ...curr.props,\n children: content\n };\n acc.push(flatTreeItem);\n if (subtree !== undefined) {\n acc.push(...flattenTreeFromElement(subtree, flatTreeItem, level + 1));\n }\n return acc;\n }, []);\n};\n//# sourceMappingURL=flattenTree.js.map"],"names":["flattenTree_unstable","flattenTreeFromElement","count","flattenTreeRecursive","items","parent","level","reduce","acc","subtree","item","index","_item_id","id","_item_value","flatTreeItem","length","parentValue","value","leaf","undefined","push","root","children","React","Children","toArray","props","curr","content","_curr_props_id","_curr_props_value"],"mappings":";;;;;;;;;;;IAkEaA,oBAAoB,MAApBA;IAIAC,sBAAsB,MAAtBA;;;6DAtEU;AACvB,IAAIC,QAAQ;AACZ,SAASC,qBAAqBC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,CAAC,EAAE;IACtD,OAAOF,MAAMG,MAAM,CAAC,CAACC,KAAK,EACxBC,QAAO,EACP,GAAGC,MACJ,EAAEC,QAAU;QACX,IAAIC;QACJ,MAAMC,KAAK,AAACD,CAAAA,WAAWF,KAAKG,EAAE,AAAD,MAAO,IAAI,IAAID,aAAa,KAAK,IAAIA,WAAW,CAAC,iBAAiB,EAAEV,QAAQ,CAAC;QAC1G,IAAIY;QACJ,MAAMC,eAAe;YACnB,cAAcT;YACd,iBAAiBK,QAAQ;YACzB,gBAAgBP,MAAMY,MAAM;YAC5BC,aAAaZ,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOa,KAAK;YACzEA,OAAO,AAACJ,CAAAA,cAAcJ,KAAKQ,KAAK,AAAD,MAAO,IAAI,IAAIJ,gBAAgB,KAAK,IAAIA,cAAcD,EAAE;YACvFM,MAAMV,YAA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T,GAAG,EAAE;AACP,GACA,uCAAuC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-tree",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
3
|
+
"version": "9.0.0-beta.12",
|
|
4
4
|
"description": "React components for building web experiences",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -36,16 +36,17 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@fluentui/keyboard-keys": "^9.0.2",
|
|
39
|
-
"@fluentui/react-aria": "^9.3.
|
|
40
|
-
"@fluentui/react-avatar": "^9.4.
|
|
41
|
-
"@fluentui/react-button": "^9.3.
|
|
42
|
-
"@fluentui/react-context-selector": "^9.1.
|
|
39
|
+
"@fluentui/react-aria": "^9.3.18",
|
|
40
|
+
"@fluentui/react-avatar": "^9.4.10",
|
|
41
|
+
"@fluentui/react-button": "^9.3.10",
|
|
42
|
+
"@fluentui/react-context-selector": "^9.1.18",
|
|
43
43
|
"@fluentui/react-icons": "^2.0.196",
|
|
44
|
-
"@fluentui/react-portal": "^9.2.
|
|
44
|
+
"@fluentui/react-portal": "^9.2.6",
|
|
45
45
|
"@fluentui/react-shared-contexts": "^9.3.3",
|
|
46
|
-
"@fluentui/react-tabster": "^9.6.
|
|
46
|
+
"@fluentui/react-tabster": "^9.6.5",
|
|
47
47
|
"@fluentui/react-theme": "^9.1.7",
|
|
48
|
-
"@fluentui/react-utilities": "^9.
|
|
48
|
+
"@fluentui/react-utilities": "^9.8.0",
|
|
49
|
+
"@fluentui/react-jsx-runtime": "9.0.0-alpha.2",
|
|
49
50
|
"@griffel/react": "^1.5.2",
|
|
50
51
|
"@swc/helpers": "^0.4.14"
|
|
51
52
|
},
|