UNPKG

vue-gantt-3

Version:

A gantt component for Vue 3

70 lines (69 loc) 2.25 kB
import { treeForEachSkipChildren } from "../utils/common.mjs"; const useGanttExpand = ({ tableViewRef, rowNodeMap, visibleRowIds, rowNodeIds, refreshCells, emitExpandChange }) => { const unExpandRowIds = /* @__PURE__ */ new Set(); const handleSetExpand = (id, expand) => { var _a; const currentRowNode = rowNodeMap.value.get(id); if (currentRowNode) { const startIndex = visibleRowIds.value.findIndex((rowId) => rowId === id); const affectChildren = getAffectChildren(currentRowNode); const newVisibleRowIds = visibleRowIds.value.concat([]); const affectChildrenIds = affectChildren.map((item) => item.id); if (expand) { newVisibleRowIds.splice(startIndex + 1, 0, ...affectChildrenIds); unExpandRowIds.delete(id); } else { newVisibleRowIds.splice(startIndex + 1, affectChildren.length); unExpandRowIds.add(id); } emitExpandChange([...unExpandRowIds]); affectChildren.forEach((node) => node.hide = !expand); visibleRowIds.value = newVisibleRowIds; currentRowNode.expand = expand; (_a = tableViewRef.value) == null ? void 0 : _a.onFilterChanged(); refreshCells([id], true); } }; const expandAll = () => { var _a; visibleRowIds.value = rowNodeIds.value.concat([]); for (let id of unExpandRowIds) { const currentRowNode = rowNodeMap.value.get(id); if (currentRowNode) { const affectChildren = getAffectChildren(currentRowNode); affectChildren.forEach((node) => node.hide = false); currentRowNode.expand = true; } } (_a = tableViewRef.value) == null ? void 0 : _a.onFilterChanged(); refreshCells([...unExpandRowIds], true); unExpandRowIds.clear(); emitExpandChange([...unExpandRowIds]); }; const getAffectChildren = (rowNode) => { let children = rowNode.children || []; const result = []; treeForEachSkipChildren(children, (currentRowNode) => { result.push(currentRowNode); if (!currentRowNode.expand) { return "skipChildren"; } }); return result; }; return { handleSetExpand, expandAll }; }; export { useGanttExpand }; //# sourceMappingURL=useGanttExpand.mjs.map