@elliemae/ds-treeview 2.2.0-next.6 → 2.3.0-alpha.1
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/cjs/TreeView.js +49 -27
- package/cjs/TreeView.js.map +7 -0
- package/cjs/TreeViewContext.js +61 -37
- package/cjs/TreeViewContext.js.map +7 -0
- package/cjs/config/cssClassesConstants.js +41 -13
- package/cjs/config/cssClassesConstants.js.map +7 -0
- package/cjs/config/useTreeview.js +116 -78
- package/cjs/config/useTreeview.js.map +7 -0
- package/cjs/index.js +37 -26
- package/cjs/index.js.map +7 -0
- package/cjs/parts/CheckboxSelectable.js +70 -59
- package/cjs/parts/CheckboxSelectable.js.map +7 -0
- package/cjs/parts/ChildrenCountDisplayer.js +45 -28
- package/cjs/parts/ChildrenCountDisplayer.js.map +7 -0
- package/cjs/parts/ExpandCaret.js +85 -83
- package/cjs/parts/ExpandCaret.js.map +7 -0
- package/cjs/parts/Icon.js +46 -31
- package/cjs/parts/Icon.js.map +7 -0
- package/cjs/parts/NestingSpace.js +43 -35
- package/cjs/parts/NestingSpace.js.map +7 -0
- package/cjs/parts/RadioSelectable.js +52 -37
- package/cjs/parts/RadioSelectable.js.map +7 -0
- package/cjs/parts/TreeItem.js +147 -141
- package/cjs/parts/TreeItem.js.map +7 -0
- package/cjs/parts/TreeItemText.js +88 -95
- package/cjs/parts/TreeItemText.js.map +7 -0
- package/cjs/parts/TreeList.js +119 -130
- package/cjs/parts/TreeList.js.map +7 -0
- package/cjs/plugins/dnd/TreeDndPlugin.js +59 -7
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/cjs/plugins/dnd/index.js +28 -9
- package/cjs/plugins/dnd/index.js.map +7 -0
- package/cjs/plugins/index.js +34 -21
- package/cjs/plugins/index.js.map +7 -0
- package/cjs/plugins/roving/TreeRovingPlugin.js +35 -7
- package/cjs/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/cjs/plugins/roving/index.js +28 -9
- package/cjs/plugins/roving/index.js.map +7 -0
- package/cjs/plugins/searchable/SearchableTreePlugin.js +35 -7
- package/cjs/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/cjs/plugins/searchable/index.js +28 -9
- package/cjs/plugins/searchable/index.js.map +7 -0
- package/cjs/plugins/selectable/SelectablePluginTree.js +35 -7
- package/cjs/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/cjs/plugins/selectable/index.js +28 -9
- package/cjs/plugins/selectable/index.js.map +7 -0
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +35 -7
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/cjs/plugins/toolbar/index.js +28 -9
- package/cjs/plugins/toolbar/index.js.map +7 -0
- package/cjs/plugins/tree/TreeDataPlugin.js +35 -7
- package/cjs/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/cjs/plugins/tree/index.js +28 -9
- package/cjs/plugins/tree/index.js.map +7 -0
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +35 -7
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/cjs/plugins/virtualization/index.js +28 -9
- package/cjs/plugins/virtualization/index.js.map +7 -0
- package/cjs/react-desc-prop-types.js +82 -54
- package/cjs/react-desc-prop-types.js.map +7 -0
- package/cjs/related-components/TreeViewSearchBar.js +42 -40
- package/cjs/related-components/TreeViewSearchBar.js.map +7 -0
- package/cjs/sharedTypes.js +27 -2
- package/cjs/sharedTypes.js.map +7 -0
- package/cjs/utils/array-helpers.js +35 -11
- package/cjs/utils/array-helpers.js.map +7 -0
- package/cjs/utils/dnd-helpers.js +146 -0
- package/cjs/utils/dnd-helpers.js.map +7 -0
- package/cjs/utils/group-expands-helpers.js +86 -59
- package/cjs/utils/group-expands-helpers.js.map +7 -0
- package/cjs/utils/keyboard-helpers.js +85 -90
- package/cjs/utils/keyboard-helpers.js.map +7 -0
- package/cjs/utils/object-helpers.js +43 -36
- package/cjs/utils/object-helpers.js.map +7 -0
- package/cjs/utils/refs-helpers.js +43 -22
- package/cjs/utils/refs-helpers.js.map +7 -0
- package/cjs/utils/selectable-helper.js +61 -53
- package/cjs/utils/selectable-helper.js.map +7 -0
- package/cjs/utils/string-helpers.js +35 -7
- package/cjs/utils/string-helpers.js.map +7 -0
- package/cjs/utils/tree-helpers.js +105 -161
- package/cjs/utils/tree-helpers.js.map +7 -0
- package/cjs/utils/useDnDHelpers.js +199 -0
- package/cjs/utils/useDnDHelpers.js.map +7 -0
- package/cjs/utils/useInstanceRefActions.js +54 -43
- package/cjs/utils/useInstanceRefActions.js.map +7 -0
- package/cjs/utils/useTree.js +76 -80
- package/cjs/utils/useTree.js.map +7 -0
- package/esm/TreeView.js +18 -16
- package/esm/TreeView.js.map +7 -0
- package/esm/TreeViewContext.js +32 -31
- package/esm/TreeViewContext.js.map +7 -0
- package/esm/config/cssClassesConstants.js +12 -6
- package/esm/config/cssClassesConstants.js.map +7 -0
- package/esm/config/useTreeview.js +73 -56
- package/esm/config/useTreeview.js.map +7 -0
- package/esm/index.js +8 -9
- package/esm/index.js.map +7 -0
- package/esm/parts/CheckboxSelectable.js +36 -46
- package/esm/parts/CheckboxSelectable.js.map +7 -0
- package/esm/parts/ChildrenCountDisplayer.js +16 -20
- package/esm/parts/ChildrenCountDisplayer.js.map +7 -0
- package/esm/parts/ExpandCaret.js +54 -72
- package/esm/parts/ExpandCaret.js.map +7 -0
- package/esm/parts/Icon.js +16 -22
- package/esm/parts/Icon.js.map +7 -0
- package/esm/parts/NestingSpace.js +14 -27
- package/esm/parts/NestingSpace.js.map +7 -0
- package/esm/parts/RadioSelectable.js +20 -28
- package/esm/parts/RadioSelectable.js.map +7 -0
- package/esm/parts/TreeItem.js +114 -125
- package/esm/parts/TreeItem.js.map +7 -0
- package/esm/parts/TreeItemText.js +58 -85
- package/esm/parts/TreeItemText.js.map +7 -0
- package/esm/parts/TreeList.js +91 -119
- package/esm/parts/TreeList.js.map +7 -0
- package/esm/plugins/dnd/TreeDndPlugin.js +30 -3
- package/esm/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/esm/plugins/dnd/index.js +3 -1
- package/esm/plugins/dnd/index.js.map +7 -0
- package/esm/plugins/index.js +9 -7
- package/esm/plugins/index.js.map +7 -0
- package/esm/plugins/roving/TreeRovingPlugin.js +6 -3
- package/esm/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/esm/plugins/roving/index.js +3 -1
- package/esm/plugins/roving/index.js.map +7 -0
- package/esm/plugins/searchable/SearchableTreePlugin.js +6 -3
- package/esm/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/esm/plugins/searchable/index.js +3 -1
- package/esm/plugins/searchable/index.js.map +7 -0
- package/esm/plugins/selectable/SelectablePluginTree.js +6 -3
- package/esm/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/esm/plugins/selectable/index.js +3 -1
- package/esm/plugins/selectable/index.js.map +7 -0
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +6 -3
- package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/esm/plugins/toolbar/index.js +3 -1
- package/esm/plugins/toolbar/index.js.map +7 -0
- package/esm/plugins/tree/TreeDataPlugin.js +6 -3
- package/esm/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/esm/plugins/tree/index.js +3 -1
- package/esm/plugins/tree/index.js.map +7 -0
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +6 -3
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/esm/plugins/virtualization/index.js +3 -1
- package/esm/plugins/virtualization/index.js.map +7 -0
- package/esm/react-desc-prop-types.js +47 -44
- package/esm/react-desc-prop-types.js.map +7 -0
- package/esm/related-components/TreeViewSearchBar.js +13 -32
- package/esm/related-components/TreeViewSearchBar.js.map +7 -0
- package/esm/sharedTypes.js +2 -1
- package/esm/sharedTypes.js.map +7 -0
- package/esm/utils/array-helpers.js +6 -6
- package/esm/utils/array-helpers.js.map +7 -0
- package/esm/utils/dnd-helpers.js +117 -0
- package/esm/utils/dnd-helpers.js.map +7 -0
- package/esm/utils/group-expands-helpers.js +56 -46
- package/esm/utils/group-expands-helpers.js.map +7 -0
- package/esm/utils/keyboard-helpers.js +46 -74
- package/esm/utils/keyboard-helpers.js.map +7 -0
- package/esm/utils/object-helpers.js +14 -31
- package/esm/utils/object-helpers.js.map +7 -0
- package/esm/utils/refs-helpers.js +15 -19
- package/esm/utils/refs-helpers.js.map +7 -0
- package/esm/utils/selectable-helper.js +32 -43
- package/esm/utils/selectable-helper.js.map +7 -0
- package/esm/utils/string-helpers.js +6 -3
- package/esm/utils/string-helpers.js.map +7 -0
- package/esm/utils/tree-helpers.js +73 -143
- package/esm/utils/tree-helpers.js.map +7 -0
- package/esm/utils/useDnDHelpers.js +170 -0
- package/esm/utils/useDnDHelpers.js.map +7 -0
- package/esm/utils/useInstanceRefActions.js +21 -35
- package/esm/utils/useInstanceRefActions.js.map +7 -0
- package/esm/utils/useTree.js +35 -59
- package/esm/utils/useTree.js.map +7 -0
- package/package.json +19 -35
- package/types/TreeView.d.ts +1 -1
- package/types/parts/TreeItem.d.ts +11 -4
- package/types/parts/TreeList.d.ts +4 -0
- package/types/plugins/dnd/TreeDndPlugin.d.ts +2 -0
- package/types/react-desc-prop-types.d.ts +3 -17
- package/types/sharedTypes.d.ts +8 -1
- package/types/utils/dnd-helpers.d.ts +39 -0
- package/types/utils/keyboard-helpers.d.ts +1 -2
- package/types/utils/refs-helpers.d.ts +1 -1
- package/types/utils/tree-helpers.d.ts +1 -4
- package/types/utils/useDnDHelpers.d.ts +26 -0
- package/types/utils/useTree.d.ts +0 -1
- package/cjs/hoc/DnDTreeContext.js +0 -18
- package/cjs/hoc/SortableItemContext.js +0 -21
- package/cjs/hoc/WithConditionalDnDContext.js +0 -138
- package/cjs/hoc/WithDnDSortableItemContext.js +0 -70
- package/cjs/parts/DnDHandle.js +0 -46
- package/cjs/parts/DropIndicator.js +0 -75
- package/esm/hoc/DnDTreeContext.js +0 -14
- package/esm/hoc/SortableItemContext.js +0 -17
- package/esm/hoc/WithConditionalDnDContext.js +0 -128
- package/esm/hoc/WithDnDSortableItemContext.js +0 -61
- package/esm/parts/DnDHandle.js +0 -38
- package/esm/parts/DropIndicator.js +0 -68
- package/types/hoc/DnDTreeContext.d.ts +0 -14
- package/types/hoc/SortableItemContext.d.ts +0 -19
- package/types/hoc/WithConditionalDnDContext.d.ts +0 -4
- package/types/hoc/WithDnDSortableItemContext.d.ts +0 -4
- package/types/parts/DnDHandle.d.ts +0 -6
- package/types/parts/DropIndicator.d.ts +0 -10
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/tree-helpers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable max-params */\n/* eslint-disable complexity */\n/* eslint-disable max-lines */\nimport { createRef } from 'react';\nimport type TreeModel from 'tree-model';\nimport { standardizeSearchQueryString } from './string-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\n\nexport const walkVisibles = (\n node: DSTreeviewT.Item['node'],\n callback: (node: DSTreeviewT.Item['node']) => void,\n skipRoot = true,\n highlightOnlyQuery = false,\n) => {\n const { children, model } = node;\n const { name, isExpanded, childrenMatchesSearchQuery, matchesSearchQuery } = model;\n\n const shouldSkipBecauseIsRoot = skipRoot && name === '__root';\n const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);\n\n if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);\n\n const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);\n if (shouldWalkChildren) {\n children.forEach((childNode) => {\n walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);\n });\n }\n};\n\nexport const walkParents = (\n nodePath: DSTreeviewT.Item['nodePath'],\n callback: (currParent: DSTreeviewT.Item['node']) => void,\n skipRoot = true,\n) => {\n const parents = [...nodePath].reverse();\n parents.shift(); // remove current node from the parents array\n if (skipRoot) parents.pop(); // remove the root from the parents if skipping root\n parents.forEach(callback);\n};\n\ntype RecursiveCallbackT = (childNode: DSTreeviewT.Item['node'], cb?: RecursiveCallbackT, isFirst?: boolean) => void;\nexport const walkAllNodeChildren = (node: DSTreeviewT.Item['node'], callback: RecursiveCallbackT, isFirst = true) => {\n const { children = [] } = node;\n const shouldWalkChildren = children.length;\n\n if (!isFirst) callback(node);\n\n if (shouldWalkChildren) {\n children.forEach((childNode) => {\n walkAllNodeChildren(childNode, callback, false);\n });\n }\n};\n\nexport const getNodeById = (treeRoot: DSTreeviewT.Item['node'], id: DSTreeviewT.StringOrNum) => {\n const nodes = treeRoot.all((node) => (node as unknown as DSTreeviewT.Item).model.id === id);\n return nodes[0];\n};\n\nexport const cloneNode = (tree: TreeModel, node: DSTreeviewT.Item) => tree.parse(node.model);\n\nexport const itemsShareSameParent = (items: DSTreeviewT.Item[] = []) => {\n if (items.length === 0) throw new Error('Received empty items for comparison');\n if (items.length === 1) return true;\n\n // when moving in first position we receive [undefined,...{items}]\n // when moving in last position we receive [...{items}, undefined]\n const firstExistingItem = items.find((item) => !!item);\n if (!firstExistingItem) throw new Error(\"Received no items, can't retrieve parent\");\n\n const firstExistingItemPath = firstExistingItem.node.getPath();\n // path is like [rootParent, ...[parentsNodes], currentNode]\n // length -1 is the current-node\n // length -2 is the parent-node\n // root node is not printed and is always present so minimum path length is 2 (root + currentNode)\n const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];\n\n return items.every((item) => {\n // undefined nodes count as having the same parent\n if (!item) return true;\n const itemPath = item.node.getPath();\n const itemDirectParent = itemPath[itemPath.length - 2];\n return directParentNode === itemDirectParent;\n });\n};\n\nexport const getItemsParentNode = (items: DSTreeviewT.Item[] = [], skipSameParentCheck = false) => {\n if (items.length === 0) throw new Error(\"Received empty items, can't retrieve parent\");\n\n // in case we already know the items compared shares the same parent\n if (!skipSameParentCheck)\n if (!itemsShareSameParent(items))\n // if we don't know (default, we don't) check if they share the parent\n throw new Error(\"Received items don't share the same parent, can't retrieve parent\");\n\n // when moving in first position we receive [undefined,...{items}]\n // when moving in last position we receive [...{items}, undefined]\n const firstExistingItem = items.find((item) => !!item);\n if (!firstExistingItem) throw new Error(\"Received no items, can't retrieve parent\");\n\n const firstExistingItemPath = firstExistingItem.node.getPath();\n // path is like [rootParent, ...[parentsNodes], currentNode]\n // length -1 is the current-node\n // length -2 is the parent-node\n // root node is not printed and is always present so minimum path length is 2 (root + currentNode)\n const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];\n return directParentNode as unknown as DSTreeviewT.Item['node'];\n};\n\nexport const getNodeMatchesSearchQuery = (node: DSTreeviewT.Item['node'], searchQuery = '') => {\n const standardizedName = standardizeSearchQueryString(node.model.name);\n const standardizedSearchQuery = standardizeSearchQueryString(searchQuery);\n return standardizedName.includes(standardizedSearchQuery);\n};\n\nexport const getChildrenMatchesSearchQuery = (parentNode: DSTreeviewT.Item['node'], searchQuery = '') => {\n let anyChildMatch = false;\n walkAllNodeChildren(parentNode, (node) => {\n if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;\n });\n return anyChildMatch;\n};\n\n/**\n * Mutate in place a node from tree-model normalizing object properties like \"isGroup\" even if user didn't specify it explicitly,\n * after execution the node will have \"nodePath\" \"treeDepth\" \"nodeItemRef\" \"isGroup\" \"isExpanded\"\n * (optionally, based on the provided arguments) \"matchesSearchQuery\" \"childrenMatchesSearchQuery\" \"isChecked\"\n *\n * @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props\n * @param {string} [searchQuery=''] - optional string used to parse \"matchesSearchQuery\"/\"childrenMatchesSearchQuery\" properties\n * @param {Object} [selection=null] - optional selection hashmap used to parse \"isChecked\" properties\n * @param {Object} [expanded=null] - optional expanded hashmap used to parse \"isExpanded\" properties\n */\nexport const enrichNodeModelInPlace = (\n node: TreeModel.Node<DSTreeviewT.SimpleItem>,\n searchQuery = '',\n selection: DSTreeviewT.SelectionItems | null = null,\n expanded: DSTreeviewT.ExpandedItems | null = null,\n) => {\n const path = node.getPath();\n const depth = path.length - 1;\n node.model.nodePath = path;\n node.model.treeDepth = depth;\n\n if (!node.model.nodeItemRef) {\n node.model.nodeItemRef = createRef();\n }\n\n // if a node has children but was not marked as isGroup, force-mark as group\n // this is useful to avoid having to always check both the flag and the children.length...\n if (typeof node.model.isGroup !== 'boolean' && node.model?.children?.length > 0) {\n node.model.isGroup = true;\n }\n\n if (node.model.isGroup && node.model.id !== '__ds_tree_root') {\n if (expanded) node.model.isExpanded = !!expanded[node.model.id];\n else if (typeof node.model.isExpanded !== 'boolean') {\n node.model.isExpanded = false;\n }\n }\n\n node.model.matchesSearchQuery = true;\n node.model.childrenMatchesSearchQuery = false;\n const partiallyEnrichedNode = node as unknown as TreeModel.Node<DSTreeviewT.Item>;\n if (searchQuery) {\n partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);\n\n if (partiallyEnrichedNode.model.isGroup === true) {\n partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(\n partiallyEnrichedNode,\n searchQuery,\n );\n if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;\n }\n }\n if (selection && selection[partiallyEnrichedNode.model.id]) {\n partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];\n }\n};\n\nexport const focusItem = (item: DSTreeviewT.Item | null) => {\n item?.nodeItemRef?.current?.focus();\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAA0B;AAE1B,4BAA6C;AAGtC,MAAM,eA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AC/E,SAAK,MAAM,UAAU;AAAA;AAGvB,MAAI,KAAK,MAAM,WAAW,KAAK,MAAM,OAAO,kBAAkB;AAC5D,QAAI;AAAU,WAAK,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,MAAM;AAAA,aACnD,OAAO,KAAK,MAAM,eAAe,WAAW;AACnD,WAAK,MAAM,aAAa;AAAA;AAAA;AAI5B,OAAK,MAAM,qBAAqB;AAChC,OAAK,MAAM,6BAA6B;AACxC,QAAM,wBAAwB;AAC9B,MAAI,aAAa;AACf,0BAAsB,MAAM,qBAAqB,0BAA0B,uBAAuB;AAElG,QAAI,sBAAsB,MAAM,YAAY,MAAM;AAChD,4BAAsB,MAAM,6BAA6B,8BACvD,uBACA;AAEF,UAAI,sBAAsB,MAAM;AAA4B,8BAAsB,MAAM,aAAa;AAAA;AAAA;AAGzG,MAAI,aAAa,UAAU,sBAAsB,MAAM,KAAK;AAC1D,0BAAsB,MAAM,YAAY,UAAU,sBAAsB,MAAM;AAAA;AAAA;AAI3E,MAAM,YAAY,CAAC,SAAkC;AAC1D,QAAM,aAAa,SAAS;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useDnDHelpers_exports = {};
|
|
29
|
+
__export(useDnDHelpers_exports, {
|
|
30
|
+
useDnDHelpers: () => useDnDHelpers
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_lodash = require("lodash");
|
|
35
|
+
var import_TreeViewContext = __toESM(require("../TreeViewContext"));
|
|
36
|
+
var import_tree_helpers = require("./tree-helpers");
|
|
37
|
+
var import_dnd_helpers = require("./dnd-helpers");
|
|
38
|
+
const useDnDHelpers = () => {
|
|
39
|
+
const ctx = (0, import_react.useContext)(import_TreeViewContext.default);
|
|
40
|
+
const {
|
|
41
|
+
props: { data, onOrderChange, restrictDragAndDrop },
|
|
42
|
+
relativeMouseCord,
|
|
43
|
+
setRelativeMouseCord,
|
|
44
|
+
visibleItems,
|
|
45
|
+
isDragging,
|
|
46
|
+
setIsDragging,
|
|
47
|
+
isKeyboardDragging,
|
|
48
|
+
setIsKeyboardDragging,
|
|
49
|
+
setDraggedItem,
|
|
50
|
+
setFocusedItem,
|
|
51
|
+
triggerTreeRerender,
|
|
52
|
+
tree,
|
|
53
|
+
treeRoot,
|
|
54
|
+
draggedItem
|
|
55
|
+
} = ctx;
|
|
56
|
+
const onSortEnd = (0, import_react.useCallback)(({ oldIndex, newIndex, isKeySorting }) => {
|
|
57
|
+
const { isBefore, isAfter, item: overItem, isValid } = relativeMouseCord;
|
|
58
|
+
if (draggedItem && tree && treeRoot && overItem) {
|
|
59
|
+
let newItems = (0, import_lodash.cloneDeep)(data);
|
|
60
|
+
if (oldIndex === newIndex || !isValid) {
|
|
61
|
+
setIsDragging(false);
|
|
62
|
+
setDraggedItem(null);
|
|
63
|
+
triggerTreeRerender();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const movementDirection = newIndex > oldIndex ? "topToBottom" : "bottomToTop";
|
|
67
|
+
let newNestedIndex;
|
|
68
|
+
let newParentNode;
|
|
69
|
+
if (isKeySorting) {
|
|
70
|
+
const kinship = (0, import_dnd_helpers.inferKeyboardKinshipDrop)({
|
|
71
|
+
items: visibleItems,
|
|
72
|
+
newIndex
|
|
73
|
+
});
|
|
74
|
+
newNestedIndex = kinship.newNestedIndex;
|
|
75
|
+
newParentNode = kinship.newParentNode;
|
|
76
|
+
} else {
|
|
77
|
+
const kinship = (0, import_dnd_helpers.inferHoverItemKinshipDrop)({
|
|
78
|
+
isBefore,
|
|
79
|
+
isAfter,
|
|
80
|
+
overItem,
|
|
81
|
+
movementDirection,
|
|
82
|
+
draggedItem
|
|
83
|
+
});
|
|
84
|
+
newNestedIndex = kinship.newNestedIndex;
|
|
85
|
+
newParentNode = kinship.newParentNode;
|
|
86
|
+
}
|
|
87
|
+
const newMovedItemNode = tree.parse(draggedItem.node.model);
|
|
88
|
+
(0, import_tree_helpers.getNodeById)(treeRoot, draggedItem.id).drop();
|
|
89
|
+
if (newParentNode && typeof newNestedIndex === "number") {
|
|
90
|
+
newParentNode.addChildAtIndex(newMovedItemNode, newNestedIndex);
|
|
91
|
+
if (newParentNode.isRoot()) {
|
|
92
|
+
newItems = [...newParentNode.model.children];
|
|
93
|
+
} else {
|
|
94
|
+
newItems = [...treeRoot.model.children];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
onOrderChange(newItems, data, draggedItem);
|
|
98
|
+
setIsDragging(false);
|
|
99
|
+
setDraggedItem(null);
|
|
100
|
+
triggerTreeRerender();
|
|
101
|
+
}
|
|
102
|
+
}, [
|
|
103
|
+
data,
|
|
104
|
+
draggedItem,
|
|
105
|
+
relativeMouseCord,
|
|
106
|
+
visibleItems,
|
|
107
|
+
tree,
|
|
108
|
+
treeRoot,
|
|
109
|
+
onOrderChange,
|
|
110
|
+
triggerTreeRerender,
|
|
111
|
+
setIsDragging,
|
|
112
|
+
setDraggedItem
|
|
113
|
+
]);
|
|
114
|
+
const onSortStart = (0, import_react.useCallback)(() => {
|
|
115
|
+
}, []);
|
|
116
|
+
const updateBeforeSortStart = (0, import_react.useCallback)((beforeStartArgs) => new Promise((resolve) => {
|
|
117
|
+
const { index, isKeySorting } = beforeStartArgs;
|
|
118
|
+
const item = visibleItems[index];
|
|
119
|
+
const { isExpanded } = item.node.model;
|
|
120
|
+
if (isExpanded) {
|
|
121
|
+
item.node.model.isExpanded = false;
|
|
122
|
+
triggerTreeRerender();
|
|
123
|
+
}
|
|
124
|
+
setRelativeMouseCord(import_TreeViewContext.defaultRelativeMouseCoord);
|
|
125
|
+
setIsKeyboardDragging(isKeySorting);
|
|
126
|
+
setIsDragging(true);
|
|
127
|
+
setDraggedItem(item);
|
|
128
|
+
(0, import_tree_helpers.focusItem)(null);
|
|
129
|
+
setFocusedItem(null);
|
|
130
|
+
if (document.activeElement && typeof document.activeElement.blur === "function")
|
|
131
|
+
document.activeElement.blur();
|
|
132
|
+
resolve(true);
|
|
133
|
+
}), [
|
|
134
|
+
visibleItems,
|
|
135
|
+
setRelativeMouseCord,
|
|
136
|
+
setIsKeyboardDragging,
|
|
137
|
+
setIsDragging,
|
|
138
|
+
setDraggedItem,
|
|
139
|
+
setFocusedItem,
|
|
140
|
+
triggerTreeRerender
|
|
141
|
+
]);
|
|
142
|
+
const onMouseDragOverItem = (0, import_react.useCallback)(({
|
|
143
|
+
event,
|
|
144
|
+
item,
|
|
145
|
+
itemIndex,
|
|
146
|
+
setIsDraggingOverThis,
|
|
147
|
+
openFolderOnHoverTimeout
|
|
148
|
+
}) => {
|
|
149
|
+
const { node } = item;
|
|
150
|
+
const { nodeItemRef } = node.model;
|
|
151
|
+
if (isDragging && !isKeyboardDragging && draggedItem) {
|
|
152
|
+
const rect = nodeItemRef?.current?.getBoundingClientRect();
|
|
153
|
+
if (rect) {
|
|
154
|
+
const x = event.clientX - rect.left;
|
|
155
|
+
const y = event.clientY - rect.top;
|
|
156
|
+
const { height: elementHeight } = rect;
|
|
157
|
+
const dropBeforeMaxY = elementHeight * 0.25;
|
|
158
|
+
const dropAfterMinY = elementHeight - elementHeight * 0.25;
|
|
159
|
+
const isBefore = y < dropBeforeMaxY;
|
|
160
|
+
const isAfter = y > dropAfterMinY;
|
|
161
|
+
const isValid = (0, import_dnd_helpers.isDropValid)({
|
|
162
|
+
isBefore,
|
|
163
|
+
isAfter,
|
|
164
|
+
draggedItem,
|
|
165
|
+
overItem: item,
|
|
166
|
+
restrictDragAndDrop
|
|
167
|
+
});
|
|
168
|
+
setRelativeMouseCord({
|
|
169
|
+
isBefore,
|
|
170
|
+
isAfter,
|
|
171
|
+
isValid,
|
|
172
|
+
item,
|
|
173
|
+
x,
|
|
174
|
+
y,
|
|
175
|
+
relativeElementDOMRect: rect,
|
|
176
|
+
relativeElementIndex: itemIndex
|
|
177
|
+
});
|
|
178
|
+
setIsDraggingOverThis(true);
|
|
179
|
+
if (!openFolderOnHoverTimeout?.current && draggedItem?.id !== item?.id && (item.isGroup || item.children.length > 0) && !restrictDragAndDrop) {
|
|
180
|
+
openFolderOnHoverTimeout.current = setTimeout(() => {
|
|
181
|
+
item.node.model.isExpanded = true;
|
|
182
|
+
openFolderOnHoverTimeout.current = null;
|
|
183
|
+
triggerTreeRerender();
|
|
184
|
+
}, 1e3);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
setRelativeMouseCord(import_TreeViewContext.defaultRelativeMouseCoord);
|
|
189
|
+
}
|
|
190
|
+
}, [isDragging, isKeyboardDragging, draggedItem, restrictDragAndDrop, setRelativeMouseCord, triggerTreeRerender]);
|
|
191
|
+
return {
|
|
192
|
+
updateBeforeSortStart,
|
|
193
|
+
onSortStart,
|
|
194
|
+
onSortEnd,
|
|
195
|
+
onMouseDragOverItem
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
module.exports = __toCommonJS(useDnDHelpers_exports);
|
|
199
|
+
//# sourceMappingURL=useDnDHelpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/useDnDHelpers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-depth */\n/* eslint-disable no-lonely-if */\n/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport React, { useContext, useCallback } from 'react';\nimport { cloneDeep } from 'lodash';\n\nimport TreeViewContext, { defaultRelativeMouseCoord } from '../TreeViewContext';\nimport { getNodeById, focusItem } from './tree-helpers';\nimport { inferHoverItemKinshipDrop, inferKeyboardKinshipDrop, isDropValid } from './dnd-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\n\nexport const useDnDHelpers = () => {\n const ctx = useContext(TreeViewContext);\n\n const {\n props: { data, onOrderChange, restrictDragAndDrop },\n relativeMouseCord,\n setRelativeMouseCord,\n visibleItems,\n isDragging,\n setIsDragging,\n isKeyboardDragging,\n setIsKeyboardDragging,\n setDraggedItem,\n setFocusedItem,\n triggerTreeRerender,\n tree,\n treeRoot,\n draggedItem,\n } = ctx;\n\n const onSortEnd = useCallback(\n ({ oldIndex, newIndex, isKeySorting }: { oldIndex: number; newIndex: number; isKeySorting: boolean }) => {\n const { isBefore, isAfter, item: overItem, isValid } = relativeMouseCord;\n if (draggedItem && tree && treeRoot && overItem) {\n let newItems = cloneDeep(data);\n // if dropping in same position do nothing\n // if the drop is not allowed do nothing\n if (oldIndex === newIndex || !isValid) {\n // onOrderChange(newItems, data);\n setIsDragging(false);\n setDraggedItem(null);\n triggerTreeRerender();\n return;\n }\n\n // if we are moving from topToBottom the offset changes\n const movementDirection = newIndex > oldIndex ? ('topToBottom' as const) : ('bottomToTop' as const);\n\n let newNestedIndex;\n let newParentNode;\n if (isKeySorting) {\n const kinship = inferKeyboardKinshipDrop({\n items: visibleItems,\n\n newIndex,\n });\n newNestedIndex = kinship.newNestedIndex;\n newParentNode = kinship.newParentNode;\n } else {\n const kinship = inferHoverItemKinshipDrop({\n isBefore,\n isAfter,\n overItem,\n movementDirection,\n draggedItem,\n });\n newNestedIndex = kinship.newNestedIndex;\n newParentNode = kinship.newParentNode;\n }\n\n const newMovedItemNode = tree.parse(draggedItem.node.model);\n getNodeById(treeRoot, draggedItem.id).drop();\n if (newParentNode && typeof newNestedIndex === 'number') {\n newParentNode.addChildAtIndex(newMovedItemNode, newNestedIndex);\n\n if (newParentNode.isRoot()) {\n newItems = [...newParentNode.model.children];\n } else {\n newItems = [...treeRoot.model.children];\n }\n }\n\n onOrderChange(newItems, data, draggedItem);\n setIsDragging(false);\n setDraggedItem(null);\n triggerTreeRerender();\n }\n },\n [\n data,\n draggedItem,\n relativeMouseCord,\n visibleItems,\n tree,\n treeRoot,\n onOrderChange,\n triggerTreeRerender,\n setIsDragging,\n setDraggedItem,\n ],\n );\n\n const onSortStart = useCallback(\n () => {},\n // ({ node, index, collection, isKeySorting }, event) => {\n // console.log('node :>> ', node);\n // console.log('isKeySorting :>> ', isKeySorting);\n // console.log('event :>> ', event);\n // const item = collection?.[index] || visibleItems[index];\n // setIsDragging(true);\n // setDraggedItem(item);\n // },\n [],\n );\n\n const updateBeforeSortStart = useCallback(\n (beforeStartArgs: { index: number; isKeySorting: boolean }) =>\n new Promise((resolve) => {\n const { index, isKeySorting } = beforeStartArgs;\n\n const item = visibleItems[index];\n const { isExpanded } = item.node.model;\n\n if (isExpanded) {\n item.node.model.isExpanded = false;\n triggerTreeRerender();\n }\n setRelativeMouseCord(defaultRelativeMouseCoord);\n setIsKeyboardDragging(isKeySorting);\n setIsDragging(true);\n setDraggedItem(item);\n focusItem(null);\n setFocusedItem(null);\n if (document.activeElement && typeof (document.activeElement as HTMLElement).blur === 'function')\n (document.activeElement as HTMLElement).blur();\n resolve(true);\n }),\n [\n visibleItems,\n setRelativeMouseCord,\n setIsKeyboardDragging,\n setIsDragging,\n setDraggedItem,\n setFocusedItem,\n triggerTreeRerender,\n ],\n );\n\n // tracks mouse coords relative to an element to check if the drop happens\n // at the top/center/bottom of an element to choose where to move the element\n // requested in the specs\n const onMouseDragOverItem = useCallback(\n ({\n event,\n item,\n itemIndex,\n setIsDraggingOverThis,\n openFolderOnHoverTimeout,\n }: {\n event: React.MouseEvent<HTMLLIElement>;\n item: DSTreeviewT.Item;\n itemIndex: number;\n setIsDraggingOverThis: DSTreeviewInternalsT.StateSetter<boolean>;\n openFolderOnHoverTimeout: React.MutableRefObject<NodeJS.Timeout | null>;\n }) => {\n const { node } = item;\n const { nodeItemRef } = node.model;\n if (isDragging && !isKeyboardDragging && draggedItem) {\n const rect = nodeItemRef?.current?.getBoundingClientRect();\n if (rect) {\n const x = event.clientX - rect.left; // x position within the element.\n const y = event.clientY - rect.top; // y position within the element.\n\n // by spec we need to track where the drop will happens\n // if drop happens on top 25% drop before\n // if drop happens on bottom of 25% drop after\n // if drop happens in the middle 50% either invalid or drop into children\n const { height: elementHeight } = rect;\n const dropBeforeMaxY = elementHeight * 0.25;\n const dropAfterMinY = elementHeight - elementHeight * 0.25;\n const isBefore = y < dropBeforeMaxY;\n const isAfter = y > dropAfterMinY;\n const isValid = isDropValid({\n isBefore,\n isAfter,\n draggedItem,\n overItem: item,\n restrictDragAndDrop,\n });\n setRelativeMouseCord({\n isBefore,\n isAfter,\n isValid,\n item,\n x,\n y,\n relativeElementDOMRect: rect,\n relativeElementIndex: itemIndex,\n });\n setIsDraggingOverThis(true);\n\n if (\n !openFolderOnHoverTimeout?.current && // only set the interval if it wasn't set already once\n draggedItem?.id !== item?.id && // don't open ghost element\n (item.isGroup || item.children.length > 0) && // only open groups\n !restrictDragAndDrop\n ) {\n openFolderOnHoverTimeout.current = setTimeout(() => {\n item.node.model.isExpanded = true;\n openFolderOnHoverTimeout.current = null;\n triggerTreeRerender();\n }, 1000);\n }\n }\n } else {\n setRelativeMouseCord(defaultRelativeMouseCoord);\n }\n },\n [isDragging, isKeyboardDragging, draggedItem, restrictDragAndDrop, setRelativeMouseCord, triggerTreeRerender],\n );\n\n return {\n updateBeforeSortStart,\n onSortStart,\n onSortEnd,\n onMouseDragOverItem,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADKvB,mBAA+C;AAC/C,oBAA0B;AAE1B,6BAA2D;AAC3D,0BAAuC;AACvC,yBAAiF;AAI1E,MAAM,gBAAgB,MAAM;AACjC,QAAM,MAAM,6BAAW;AAEvB,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM,eAAe;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAEJ,QAAM,YAAY,8BAChB,CAAC,EAAE,UAAU,UAAU,mBAAkF;AACvG,UAAM,EAAE,UAAU,SAAS,MAAM,UAAU,YAAY;AACvD,QAAI,eAAe,QAAQ,YAAY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AO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,20 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useInstanceRefActions_exports = {};
|
|
29
|
+
__export(useInstanceRefActions_exports, {
|
|
30
|
+
useInstanceRefActions: () => useInstanceRefActions
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_tree_helpers = require("./tree-helpers");
|
|
35
|
+
var import_group_expands_helpers = require("./group-expands-helpers");
|
|
36
|
+
const useInstanceRefActions = ({ actions }, ctx) => {
|
|
14
37
|
const {
|
|
15
|
-
props: {
|
|
16
|
-
onItemFocus
|
|
17
|
-
},
|
|
38
|
+
props: { onItemFocus },
|
|
18
39
|
virtualListHelpers,
|
|
19
40
|
treeRoot,
|
|
20
41
|
visibleItems,
|
|
@@ -24,64 +45,54 @@ const useInstanceRefActions = (_ref, ctx) => {
|
|
|
24
45
|
setFocusedItem,
|
|
25
46
|
setLatestToggledItem
|
|
26
47
|
} = ctx;
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
scrollToIndex
|
|
32
|
-
} = React.useMemo(() => virtualListHelpers, [virtualListHelpers]);
|
|
33
|
-
const [expandPromise, setPromise] = React.useState();
|
|
34
|
-
React.useEffect(() => {
|
|
48
|
+
const { current: promises } = (0, import_react.useRef)({});
|
|
49
|
+
const { scrollToIndex } = (0, import_react.useMemo)(() => virtualListHelpers, [virtualListHelpers]);
|
|
50
|
+
const [expandPromise, setPromise] = (0, import_react.useState)();
|
|
51
|
+
(0, import_react.useEffect)(() => {
|
|
35
52
|
if (expandPromise && promises.expandResolve) {
|
|
36
53
|
promises.expandResolve(visibleItems);
|
|
37
54
|
promises.expandResolve = null;
|
|
38
55
|
setPromise(null);
|
|
39
56
|
}
|
|
40
57
|
}, [visibleItems, expandPromise, promises]);
|
|
41
|
-
actions.toggleExpandAll =
|
|
42
|
-
const p = new Promise(resolve => {
|
|
58
|
+
actions.toggleExpandAll = (0, import_react.useCallback)((isExpand) => {
|
|
59
|
+
const p = new Promise((resolve) => {
|
|
43
60
|
promises.expandResolve = resolve;
|
|
44
|
-
if (treeRoot)
|
|
61
|
+
if (treeRoot)
|
|
62
|
+
(0, import_group_expands_helpers.toggleExpandAllHelper)(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
45
63
|
});
|
|
46
64
|
setPromise(p);
|
|
47
65
|
return p;
|
|
48
66
|
}, [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState]);
|
|
49
|
-
actions.scrollTo =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
if (scrollToIndex) scrollToIndex(indx, opts);
|
|
67
|
+
actions.scrollTo = (0, import_react.useCallback)((indx, opts = { align: "start" }) => {
|
|
68
|
+
if (scrollToIndex)
|
|
69
|
+
scrollToIndex(indx, opts);
|
|
54
70
|
}, [scrollToIndex]);
|
|
55
|
-
actions.setSelectedItemByVirtualIndex =
|
|
71
|
+
actions.setSelectedItemByVirtualIndex = (0, import_react.useCallback)((index) => {
|
|
56
72
|
const itemByIndex = visibleItems[index];
|
|
57
73
|
setSelectedItem(itemByIndex);
|
|
58
74
|
}, [visibleItems, setSelectedItem]);
|
|
59
|
-
actions.setFocusedItemByVirtualIndex =
|
|
60
|
-
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
61
|
-
align: 'start',
|
|
62
|
-
withScroll: false
|
|
63
|
-
};
|
|
75
|
+
actions.setFocusedItemByVirtualIndex = (0, import_react.useCallback)((index, opts = { align: "start", withScroll: false }) => {
|
|
64
76
|
const itemByIndex = visibleItems[index];
|
|
65
77
|
const onItemFocusParams = {
|
|
66
78
|
itemIndex: itemByIndex.virtualIndex,
|
|
67
79
|
scrollToItem: () => scrollToIndex(index, opts),
|
|
68
80
|
item: itemByIndex
|
|
69
81
|
};
|
|
70
|
-
|
|
71
82
|
if (opts.withScroll && scrollToIndex) {
|
|
72
83
|
scrollToIndex(index, opts);
|
|
73
84
|
setTimeout(() => {
|
|
74
85
|
setFocusedItem(itemByIndex);
|
|
75
|
-
|
|
86
|
+
(0, import_tree_helpers.focusItem)(itemByIndex);
|
|
76
87
|
onItemFocus(onItemFocusParams);
|
|
77
88
|
}, 300);
|
|
78
89
|
} else {
|
|
79
90
|
setFocusedItem(itemByIndex);
|
|
80
|
-
|
|
91
|
+
(0, import_tree_helpers.focusItem)(itemByIndex);
|
|
81
92
|
onItemFocus(onItemFocusParams);
|
|
82
93
|
}
|
|
83
94
|
}, [visibleItems, scrollToIndex, setFocusedItem, onItemFocus]);
|
|
84
95
|
return actions;
|
|
85
96
|
};
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
module.exports = __toCommonJS(useInstanceRefActions_exports);
|
|
98
|
+
//# sourceMappingURL=useInstanceRefActions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/useInstanceRefActions.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo, useState, useRef, useCallback } from 'react';\nimport { focusItem } from './tree-helpers';\nimport { toggleExpandAllHelper } from './group-expands-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\n\ninterface PromisesRefT {\n expandResolve?: null | ((value: DSTreeviewT.Item[] | PromiseLike<DSTreeviewT.Item[]>) => void);\n scrollTo?: null | ((value: DSTreeviewT.Item[] | PromiseLike<DSTreeviewT.Item[]>) => void);\n}\n\nexport const useInstanceRefActions = ({ actions }: DSTreeviewT.InstanceRef, ctx: DSTreeviewInternalsT.CTX) => {\n const {\n props: { onItemFocus },\n virtualListHelpers,\n treeRoot,\n visibleItems,\n triggerTreeRerender,\n updateUserExpandedState,\n setSelectedItem,\n setFocusedItem,\n setLatestToggledItem,\n } = ctx;\n const { current: promises } = useRef<PromisesRefT>({});\n const { scrollToIndex } = useMemo(() => virtualListHelpers, [virtualListHelpers]);\n const [expandPromise, setPromise] = useState<Promise<DSTreeviewT.Item[]> | undefined | null>();\n\n useEffect(() => {\n if (expandPromise && promises.expandResolve) {\n promises.expandResolve(visibleItems);\n promises.expandResolve = null;\n setPromise(null);\n }\n }, [visibleItems, expandPromise, promises]);\n\n actions.toggleExpandAll = useCallback(\n (isExpand) => {\n const p = new Promise<DSTreeviewT.Item[]>((resolve) => {\n promises.expandResolve = resolve;\n if (treeRoot)\n toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);\n });\n setPromise(p);\n return p;\n },\n [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState],\n );\n actions.scrollTo = useCallback(\n (indx, opts = { align: 'start' }) => {\n if (scrollToIndex) scrollToIndex(indx, opts);\n },\n [scrollToIndex],\n );\n\n actions.setSelectedItemByVirtualIndex = useCallback(\n (index) => {\n const itemByIndex = visibleItems[index];\n setSelectedItem(itemByIndex);\n },\n [visibleItems, setSelectedItem],\n );\n\n actions.setFocusedItemByVirtualIndex = useCallback(\n (index, opts = { align: 'start', withScroll: false }) => {\n const itemByIndex = visibleItems[index];\n const onItemFocusParams = {\n itemIndex: itemByIndex.virtualIndex as number,\n scrollToItem: () => scrollToIndex(index, opts),\n item: itemByIndex,\n };\n\n if (opts.withScroll && scrollToIndex) {\n scrollToIndex(index, opts);\n setTimeout(() => {\n setFocusedItem(itemByIndex);\n focusItem(itemByIndex);\n onItemFocus(onItemFocusParams);\n }, 300);\n } else {\n setFocusedItem(itemByIndex);\n focusItem(itemByIndex);\n onItemFocus(onItemFocusParams);\n }\n },\n [visibleItems, scrollToIndex, setFocusedItem, onItemFocus],\n );\n\n return actions;\n};\n", "import * as React from 'react';\n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AAA,MACzC,MAAM;AAAA;AAGR,QAAI,KAAK,cAAc,eAAe;AACpC,oBAAc,OAAO;AACrB,iBAAW,MAAM;AACf,uBAAe;AACf,2CAAU;AACV,oBAAY;AAAA,SACX;AAAA,WACE;AACL,qBAAe;AACf,yCAAU;AACV,kBAAY;AAAA;AAAA,KAGhB,CAAC,cAAc,eAAe,gBAAgB;AAGhD,SAAO;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/cjs/utils/useTree.js
CHANGED
|
@@ -1,102 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var useTree_exports = {};
|
|
29
|
+
__export(useTree_exports, {
|
|
30
|
+
useTree: () => useTree
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_tree_model = __toESM(require("tree-model"));
|
|
35
|
+
var import_lodash = require("lodash");
|
|
36
|
+
var import_tree_helpers = require("./tree-helpers");
|
|
37
|
+
var import_group_expands_helpers = require("./group-expands-helpers");
|
|
26
38
|
const useTree = (data, props, states) => {
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const tree = React.useMemo(() => new TreeModel__default["default"](), []);
|
|
35
|
-
const [treeData, setTreeData] = React.useState({
|
|
36
|
-
id: '__ds_tree_root',
|
|
37
|
-
name: '__root',
|
|
39
|
+
const { setExpandedGroups } = states;
|
|
40
|
+
const unfrozenData = (0, import_react.useMemo)(() => (0, import_lodash.cloneDeep)(data), [data]);
|
|
41
|
+
const tree = (0, import_react.useMemo)(() => new import_tree_model.default(), []);
|
|
42
|
+
const [treeData, setTreeData] = (0, import_react.useState)({
|
|
43
|
+
id: "__ds_tree_root",
|
|
44
|
+
name: "__root",
|
|
38
45
|
isExpanded: true,
|
|
39
46
|
children: unfrozenData
|
|
40
47
|
});
|
|
41
|
-
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
42
49
|
setTreeData({
|
|
43
|
-
id:
|
|
44
|
-
name:
|
|
50
|
+
id: "__ds_tree_root",
|
|
51
|
+
name: "__root",
|
|
45
52
|
isExpanded: true,
|
|
46
53
|
children: unfrozenData
|
|
47
54
|
});
|
|
48
|
-
}, [unfrozenData]);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const [rerenderItems, setRerenderItems] = React.useState({});
|
|
52
|
-
const triggerTreeRerender = React.useCallback(() => {
|
|
55
|
+
}, [unfrozenData]);
|
|
56
|
+
const [rerenderItems, setRerenderItems] = (0, import_react.useState)({});
|
|
57
|
+
const triggerTreeRerender = (0, import_react.useCallback)(() => {
|
|
53
58
|
setRerenderItems({});
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
React.useEffect(() => {
|
|
59
|
+
}, []);
|
|
60
|
+
const [treeRoot, setTreeRoot] = (0, import_react.useState)(tree.parse(treeData));
|
|
61
|
+
(0, import_react.useEffect)(() => {
|
|
58
62
|
setTreeRoot(tree.parse(treeData));
|
|
59
63
|
}, [treeData, rerenderItems, tree]);
|
|
60
|
-
const [visibleItems, setVisibleItems] =
|
|
61
|
-
const {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
expanded,
|
|
67
|
-
onExpandChange
|
|
68
|
-
} = props;
|
|
69
|
-
const updateUserExpandedState = React.useCallback(() => {
|
|
70
|
-
groupExpandsHelpers.updateExpandedState(treeRoot, onExpandChange);
|
|
71
|
-
}, [treeRoot, onExpandChange]); // we add missing properties to the received Items
|
|
72
|
-
// not the best of the patterns, but it works
|
|
73
|
-
// this is where we convert "SimpleItems" to "Items"
|
|
74
|
-
// this was done to avoid breaking changes back in v1
|
|
75
|
-
|
|
76
|
-
React.useEffect(() => {
|
|
64
|
+
const [visibleItems, setVisibleItems] = (0, import_react.useState)([]);
|
|
65
|
+
const { searchQuery, highlightOnlyQuery, onVisibleItemsChange, selection, expanded, onExpandChange } = props;
|
|
66
|
+
const updateUserExpandedState = (0, import_react.useCallback)(() => {
|
|
67
|
+
(0, import_group_expands_helpers.updateExpandedState)(treeRoot, onExpandChange);
|
|
68
|
+
}, [treeRoot, onExpandChange]);
|
|
69
|
+
(0, import_react.useEffect)(() => {
|
|
77
70
|
const parsedVisibleItems = [];
|
|
78
71
|
const newExpandedHashMap = {};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
treeRoot.walk((node) => {
|
|
73
|
+
const shouldContinueWalking = true;
|
|
74
|
+
(0, import_tree_helpers.enrichNodeModelInPlace)(node, searchQuery, selection, expanded);
|
|
75
|
+
if (node.model.id && node.model.isGroup && node.model.isExpanded)
|
|
76
|
+
newExpandedHashMap[node.model.id] = true;
|
|
84
77
|
return shouldContinueWalking;
|
|
85
78
|
});
|
|
86
|
-
|
|
87
|
-
parsedVisibleItems.push(
|
|
88
|
-
node
|
|
89
|
-
}));
|
|
79
|
+
(0, import_tree_helpers.walkVisibles)(treeRoot, (node) => {
|
|
80
|
+
parsedVisibleItems.push({ ...node.model, node });
|
|
90
81
|
}, true, highlightOnlyQuery);
|
|
91
82
|
setVisibleItems(parsedVisibleItems);
|
|
92
83
|
onVisibleItemsChange(parsedVisibleItems);
|
|
93
|
-
setExpandedGroups(newExpandedHashMap);
|
|
94
|
-
}, [
|
|
84
|
+
setExpandedGroups(newExpandedHashMap);
|
|
85
|
+
}, [
|
|
86
|
+
treeRoot,
|
|
87
|
+
rerenderItems,
|
|
88
|
+
searchQuery,
|
|
89
|
+
highlightOnlyQuery,
|
|
90
|
+
selection,
|
|
91
|
+
expanded,
|
|
92
|
+
setExpandedGroups
|
|
95
93
|
]);
|
|
96
|
-
const flattenedItems = React.useMemo(() => treeHelpers.flattenTreeForDnD(data), [data]);
|
|
97
94
|
return {
|
|
98
95
|
visibleItems,
|
|
99
|
-
flattenedItems,
|
|
100
96
|
tree,
|
|
101
97
|
treeRoot,
|
|
102
98
|
rerenderItems,
|
|
@@ -104,5 +100,5 @@ const useTree = (data, props, states) => {
|
|
|
104
100
|
updateUserExpandedState
|
|
105
101
|
};
|
|
106
102
|
};
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
module.exports = __toCommonJS(useTree_exports);
|
|
104
|
+
//# sourceMappingURL=useTree.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/useTree.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { useState, useCallback, useMemo, useEffect } from 'react';\nimport TreeModel from 'tree-model';\nimport { cloneDeep } from 'lodash';\n\nimport { walkVisibles, enrichNodeModelInPlace } from './tree-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\nimport { updateExpandedState } from './group-expands-helpers';\n\nexport const useTree = (\n data: DSTreeviewT.SimpleItem[],\n props: DSTreeviewT.Props,\n states: {\n setExpandedGroups: DSTreeviewInternalsT.StateSetter<DSTreeviewT.ExpandedItems>;\n },\n) => {\n const { setExpandedGroups } = states;\n const unfrozenData = useMemo(() => cloneDeep(data), [data]);\n\n // convert data into a TreeModel with extra isExpanded prop\n // root element type is an exception, children model is based on what the dev passed on\n // since root is an excepcion we must typecast\n const tree = useMemo(() => new TreeModel(), []);\n const [treeData, setTreeData] = useState({\n id: '__ds_tree_root',\n name: '__root',\n isExpanded: true,\n children: unfrozenData,\n } as unknown as DSTreeviewT.Item);\n\n useEffect(() => {\n setTreeData({\n id: '__ds_tree_root',\n name: '__root',\n isExpanded: true,\n children: unfrozenData,\n } as unknown as DSTreeviewT.Item);\n }, [unfrozenData]);\n\n // expose a way to rerender the tree\n // used for expand functionality\n const [rerenderItems, setRerenderItems] = useState({});\n const triggerTreeRerender = useCallback(() => {\n setRerenderItems({});\n }, []);\n\n // when re-rendering we re-parse the list\n const [treeRoot, setTreeRoot] = useState(tree.parse(treeData));\n useEffect(() => {\n setTreeRoot(tree.parse(treeData));\n }, [treeData, rerenderItems, tree]);\n\n const [visibleItems, setVisibleItems] = useState<DSTreeviewT.Item[]>([]);\n\n const { searchQuery, highlightOnlyQuery, onVisibleItemsChange, selection, expanded, onExpandChange } = props;\n\n const updateUserExpandedState = useCallback(() => {\n updateExpandedState(treeRoot, onExpandChange);\n }, [treeRoot, onExpandChange]);\n // we add missing properties to the received Items\n // not the best of the patterns, but it works\n // this is where we convert \"SimpleItems\" to \"Items\"\n // this was done to avoid breaking changes back in v1\n useEffect(() => {\n const parsedVisibleItems: DSTreeviewT.Item[] = [];\n const newExpandedHashMap: DSTreeviewT.ExpandedItems = {};\n treeRoot.walk((node) => {\n const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking\n enrichNodeModelInPlace(node, searchQuery, selection, expanded);\n if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;\n return shouldContinueWalking;\n });\n\n walkVisibles(\n treeRoot,\n (node) => {\n parsedVisibleItems.push({ ...node.model, node });\n },\n true,\n highlightOnlyQuery,\n );\n setVisibleItems(parsedVisibleItems);\n onVisibleItemsChange(parsedVisibleItems);\n\n setExpandedGroups(newExpandedHashMap);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n treeRoot,\n rerenderItems,\n searchQuery,\n highlightOnlyQuery,\n selection,\n expanded,\n setExpandedGroups,\n // onVisibleItemsChange // evaluate potential performance hit?\n ]);\n\n return {\n visibleItems,\n tree,\n treeRoot,\n rerenderItems,\n triggerTreeRerender,\n updateUserExpandedState,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;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