package.build.lib.features.Expanding.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
The newest version!
{"version":3,"file":"Expanding.js","sources":["../../../src/features/Expanding.ts"],"sourcesContent":["import { RowModel } from '..'\nimport { TableFeature } from '../core/table'\nimport { OnChangeFn, Table, Row, Updater, RowData } from '../types'\nimport { makeStateUpdater } from '../utils'\n\nexport type ExpandedStateList = Record\nexport type ExpandedState = true | Record\nexport interface ExpandedTableState {\n expanded: ExpandedState\n}\n\nexport interface ExpandedRow {\n toggleExpanded: (expanded?: boolean) => void\n getIsExpanded: () => boolean\n getCanExpand: () => boolean\n getToggleExpandedHandler: () => () => void\n}\n\nexport interface ExpandedOptions {\n manualExpanding?: boolean\n onExpandedChange?: OnChangeFn\n autoResetExpanded?: boolean\n enableExpanding?: boolean\n getExpandedRowModel?: (table: Table) => () => RowModel\n getIsRowExpanded?: (row: Row) => boolean\n getRowCanExpand?: (row: Row) => boolean\n paginateExpandedRows?: boolean\n}\n\nexport interface ExpandedInstance {\n _autoResetExpanded: () => void\n setExpanded: (updater: Updater) => void\n toggleAllRowsExpanded: (expanded?: boolean) => void\n resetExpanded: (defaultState?: boolean) => void\n getCanSomeRowsExpand: () => boolean\n getToggleAllRowsExpandedHandler: () => (event: unknown) => void\n getIsSomeRowsExpanded: () => boolean\n getIsAllRowsExpanded: () => boolean\n getExpandedDepth: () => number\n getExpandedRowModel: () => RowModel\n _getExpandedRowModel?: () => RowModel\n getPreExpandedRowModel: () => RowModel\n}\n\n//\n\nexport const Expanding: TableFeature = {\n getInitialState: (state): ExpandedTableState => {\n return {\n expanded: {},\n ...state,\n }\n },\n\n getDefaultOptions: (\n table: Table\n ): ExpandedOptions => {\n return {\n onExpandedChange: makeStateUpdater('expanded', table),\n paginateExpandedRows: true,\n }\n },\n\n createTable: (\n table: Table\n ): ExpandedInstance => {\n let registered = false\n let queued = false\n\n return {\n _autoResetExpanded: () => {\n if (!registered) {\n table._queue(() => {\n registered = true\n })\n return\n }\n\n if (\n table.options.autoResetAll ??\n table.options.autoResetExpanded ??\n !table.options.manualExpanding\n ) {\n if (queued) return\n queued = true\n table._queue(() => {\n table.resetExpanded()\n queued = false\n })\n }\n },\n setExpanded: updater => table.options.onExpandedChange?.(updater),\n toggleAllRowsExpanded: expanded => {\n if (expanded ?? !table.getIsAllRowsExpanded()) {\n table.setExpanded(true)\n } else {\n table.setExpanded({})\n }\n },\n resetExpanded: defaultState => {\n table.setExpanded(\n defaultState ? {} : table.initialState?.expanded ?? {}\n )\n },\n getCanSomeRowsExpand: () => {\n return table\n .getPrePaginationRowModel()\n .flatRows.some(row => row.getCanExpand())\n },\n getToggleAllRowsExpandedHandler: () => {\n return (e: unknown) => {\n ;(e as any).persist?.()\n table.toggleAllRowsExpanded()\n }\n },\n getIsSomeRowsExpanded: () => {\n const expanded = table.getState().expanded\n return expanded === true || Object.values(expanded).some(Boolean)\n },\n getIsAllRowsExpanded: () => {\n const expanded = table.getState().expanded\n\n // If expanded is true, save some cycles and return true\n if (typeof expanded === 'boolean') {\n return expanded === true\n }\n\n if (!Object.keys(expanded).length) {\n return false\n }\n\n // If any row is not expanded, return false\n if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {\n return false\n }\n\n // They must all be expanded :shrug:\n return true\n },\n getExpandedDepth: () => {\n let maxDepth = 0\n\n const rowIds =\n table.getState().expanded === true\n ? Object.keys(table.getRowModel().rowsById)\n : Object.keys(table.getState().expanded)\n\n rowIds.forEach(id => {\n const splitId = id.split('.')\n maxDepth = Math.max(maxDepth, splitId.length)\n })\n\n return maxDepth\n },\n getPreExpandedRowModel: () => table.getSortedRowModel(),\n getExpandedRowModel: () => {\n if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {\n table._getExpandedRowModel = table.options.getExpandedRowModel(table)\n }\n\n if (table.options.manualExpanding || !table._getExpandedRowModel) {\n return table.getPreExpandedRowModel()\n }\n\n return table._getExpandedRowModel()\n },\n }\n },\n\n createRow: (\n row: Row,\n table: Table\n ): ExpandedRow => {\n return {\n toggleExpanded: expanded => {\n table.setExpanded(old => {\n const exists = old === true ? true : !!old?.[row.id]\n\n let oldExpanded: ExpandedStateList = {}\n\n if (old === true) {\n Object.keys(table.getRowModel().rowsById).forEach(rowId => {\n oldExpanded[rowId] = true\n })\n } else {\n oldExpanded = old\n }\n\n expanded = expanded ?? !exists\n\n if (!exists && expanded) {\n return {\n ...oldExpanded,\n [row.id]: true,\n }\n }\n\n if (exists && !expanded) {\n const { [row.id]: _, ...rest } = oldExpanded\n return rest\n }\n\n return old\n })\n },\n getIsExpanded: () => {\n const expanded = table.getState().expanded\n\n return !!(\n table.options.getIsRowExpanded?.(row) ??\n (expanded === true || expanded?.[row.id])\n )\n },\n getCanExpand: () => {\n return (\n table.options.getRowCanExpand?.(row) ??\n ((table.options.enableExpanding ?? true) && !!row.subRows?.length)\n )\n },\n getToggleExpandedHandler: () => {\n const canExpand = row.getCanExpand()\n\n return () => {\n if (!canExpand) return\n row.toggleExpanded()\n }\n },\n }\n },\n}\n"],"names":["Expanding","getInitialState","state","expanded","getDefaultOptions","table","onExpandedChange","makeStateUpdater","paginateExpandedRows","createTable","registered","queued","_autoResetExpanded","_ref","_table$options$autoRe","_queue","options","autoResetAll","autoResetExpanded","manualExpanding","resetExpanded","setExpanded","updater","toggleAllRowsExpanded","getIsAllRowsExpanded","defaultState","_table$initialState$e","_table$initialState","initialState","getCanSomeRowsExpand","getPrePaginationRowModel","flatRows","some","row","getCanExpand","getToggleAllRowsExpandedHandler","e","persist","getIsSomeRowsExpanded","getState","Object","values","Boolean","keys","length","getRowModel","getIsExpanded","getExpandedDepth","maxDepth","rowIds","rowsById","forEach","id","splitId","split","Math","max","getPreExpandedRowModel","getSortedRowModel","getExpandedRowModel","_getExpandedRowModel","createRow","toggleExpanded","old","_expanded","exists","oldExpanded","rowId","_","rest","_table$options$getIsR","getIsRowExpanded","_table$options$getRow","_table$options$enable","_row$subRows","getRowCanExpand","enableExpanding","subRows","getToggleExpandedHandler","canExpand"],"mappings":";;;;;;;;;;;;;;;;AA4CA;;AAEO,MAAMA,SAAuB,GAAG;EACrCC,eAAe,EAAGC,KAAK,IAAyB;IAC9C,OAAO;MACLC,QAAQ,EAAE,EAAE;MACZ,GAAGD,KAAAA;KACJ,CAAA;GACF;EAEDE,iBAAiB,EACfC,KAAmB,IACQ;IAC3B,OAAO;AACLC,MAAAA,gBAAgB,EAAEC,sBAAgB,CAAC,UAAU,EAAEF,KAAK,CAAC;AACrDG,MAAAA,oBAAoB,EAAE,IAAA;KACvB,CAAA;GACF;EAEDC,WAAW,EACTJ,KAAmB,IACS;IAC5B,IAAIK,UAAU,GAAG,KAAK,CAAA;IACtB,IAAIC,MAAM,GAAG,KAAK,CAAA;IAElB,OAAO;MACLC,kBAAkB,EAAEA,MAAM;QAAA,IAAAC,IAAA,EAAAC,qBAAA,CAAA;QACxB,IAAI,CAACJ,UAAU,EAAE;UACfL,KAAK,CAACU,MAAM,CAAC,MAAM;AACjBL,YAAAA,UAAU,GAAG,IAAI,CAAA;AACnB,WAAC,CAAC,CAAA;AACF,UAAA,OAAA;AACF,SAAA;QAEA,IAAAG,CAAAA,IAAA,GAAAC,CAAAA,qBAAA,GACET,KAAK,CAACW,OAAO,CAACC,YAAY,KAAAH,IAAAA,GAAAA,qBAAA,GAC1BT,KAAK,CAACW,OAAO,CAACE,iBAAiB,KAAA,IAAA,GAAAL,IAAA,GAC/B,CAACR,KAAK,CAACW,OAAO,CAACG,eAAe,EAC9B;AACA,UAAA,IAAIR,MAAM,EAAE,OAAA;AACZA,UAAAA,MAAM,GAAG,IAAI,CAAA;UACbN,KAAK,CAACU,MAAM,CAAC,MAAM;YACjBV,KAAK,CAACe,aAAa,EAAE,CAAA;AACrBT,YAAAA,MAAM,GAAG,KAAK,CAAA;AAChB,WAAC,CAAC,CAAA;AACJ,SAAA;OACD;AACDU,MAAAA,WAAW,EAAEC,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