{"version":3,"file":"useGanttExpand.mjs","sources":["../../../src/composables/useGanttExpand.ts"],"sourcesContent":["import type { Ref, ShallowRef } from 'vue';\nimport type { GanttRowNode } from '@/types';\nimport type TableView from \"@/components/tableView/TableView.vue\";\nimport { treeForEachSkipChildren } from \"@/utils/common\";\n\nexport const useGanttExpand = ({\n  tableViewRef,\n  rowNodeMap,\n  visibleRowIds,\n  rowNodeIds,\n  refreshCells,\n  emitExpandChange\n}: {\n  tableViewRef: Ref<InstanceType<typeof TableView>| undefined>,\n  rowNodeMap: ShallowRef<Map<string, GanttRowNode>, Map<string, GanttRowNode>>,\n  visibleRowIds: Ref<string[], string[]>,\n  rowNodeIds: Ref<string[], string[]>,\n  refreshCells: (ids: string[], force?: boolean) => void,\n  emitExpandChange: (ids: string[]) => void\n}) => {\n  const unExpandRowIds = new Set<string>(); // unExpand Row Ids collection, Row default expansion\n\n  const handleSetExpand = (id: string, expand: boolean) => {\n    const currentRowNode = rowNodeMap.value.get(id);\n    if (currentRowNode) {\n      const startIndex = visibleRowIds.value.findIndex(rowId => rowId === id);\n      const affectChildren = getAffectChildren(currentRowNode);\n      const newVisibleRowIds = visibleRowIds.value.concat([]);\n      const affectChildrenIds = affectChildren.map(item => item.id);\n      if (expand) {\n        newVisibleRowIds.splice(startIndex + 1, 0, ...affectChildrenIds);\n        unExpandRowIds.delete(id);\n      } else {\n        newVisibleRowIds.splice(startIndex + 1, affectChildren.length);\n        unExpandRowIds.add(id);\n      }\n      emitExpandChange([...unExpandRowIds]);\n      affectChildren.forEach(node => node.hide = !expand);\n      visibleRowIds.value = newVisibleRowIds;\n      currentRowNode.expand = expand;\n      tableViewRef.value?.onFilterChanged();\n      refreshCells([id], true);\n    }\n  };\n\n  const expandAll = () => {\n    visibleRowIds.value = rowNodeIds.value.concat([]);\n    for (let id of unExpandRowIds) {\n      const currentRowNode = rowNodeMap.value.get(id);\n      if (currentRowNode) {\n        const affectChildren = getAffectChildren(currentRowNode);\n        affectChildren.forEach(node => node.hide = false);\n        currentRowNode.expand = true;\n      }\n    }\n    tableViewRef.value?.onFilterChanged();\n    refreshCells([...unExpandRowIds], true);\n    unExpandRowIds.clear();\n    emitExpandChange([...unExpandRowIds]);\n  };\n\n  /**\n   * get row's children which are showing in gantt\n   * @param rowNode\n   * @returns\n   */\n  const getAffectChildren = (rowNode: GanttRowNode) => {\n    let children = rowNode.children || [];\n    const result: GanttRowNode[] = [];\n\n    treeForEachSkipChildren(children, (currentRowNode) => {\n      result.push(currentRowNode);\n      if (!currentRowNode.expand) {\n        return 'skipChildren';\n      }\n    });\n\n    return result;\n  };\n\n  return {\n    handleSetExpand,\n    expandAll\n  };\n};"],"names":[],"mappings":";AAKO,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAOM;AACE,QAAA,qCAAqB,IAAY;AAEjC,QAAA,kBAAkB,CAAC,IAAY,WAAoB;;AACvD,UAAM,iBAAiB,WAAW,MAAM,IAAI,EAAE;AAC9C,QAAI,gBAAgB;AAClB,YAAM,aAAa,cAAc,MAAM,UAAU,CAAA,UAAS,UAAU,EAAE;AAChE,YAAA,iBAAiB,kBAAkB,cAAc;AACvD,YAAM,mBAAmB,cAAc,MAAM,OAAO,CAAA,CAAE;AACtD,YAAM,oBAAoB,eAAe,IAAI,CAAA,SAAQ,KAAK,EAAE;AAC5D,UAAI,QAAQ;AACV,yBAAiB,OAAO,aAAa,GAAG,GAAG,GAAG,iBAAiB;AAC/D,uBAAe,OAAO,EAAE;AAAA,MAAA,OACnB;AACL,yBAAiB,OAAO,aAAa,GAAG,eAAe,MAAM;AAC7D,uBAAe,IAAI,EAAE;AAAA,MAAA;AAEN,uBAAA,CAAC,GAAG,cAAc,CAAC;AACpC,qBAAe,QAAQ,CAAA,SAAQ,KAAK,OAAO,CAAC,MAAM;AAClD,oBAAc,QAAQ;AACtB,qBAAe,SAAS;AACxB,yBAAa,UAAb,mBAAoB;AACP,m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