All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.lib.features.Pagination.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"Pagination.js","sources":["../../../src/features/Pagination.ts"],"sourcesContent":["import { TableFeature } from '../core/table'\nimport { OnChangeFn, Table, RowModel, Updater, RowData } from '../types'\nimport { functionalUpdate, makeStateUpdater, memo } from '../utils'\n\nexport interface PaginationState {\n  pageIndex: number\n  pageSize: number\n}\n\nexport interface PaginationTableState {\n  pagination: PaginationState\n}\n\nexport interface PaginationInitialTableState {\n  pagination?: Partial\n}\n\nexport interface PaginationOptions {\n  pageCount?: number\n  manualPagination?: boolean\n  onPaginationChange?: OnChangeFn\n  autoResetPageIndex?: boolean\n  getPaginationRowModel?: (table: Table) => () => RowModel\n}\n\nexport interface PaginationDefaultOptions {\n  onPaginationChange: OnChangeFn\n}\n\nexport interface PaginationInstance {\n  _autoResetPageIndex: () => void\n  setPagination: (updater: Updater) => void\n  resetPagination: (defaultState?: boolean) => void\n  setPageIndex: (updater: Updater) => void\n  resetPageIndex: (defaultState?: boolean) => void\n  setPageSize: (updater: Updater) => void\n  resetPageSize: (defaultState?: boolean) => void\n  setPageCount: (updater: Updater) => void\n  getPageOptions: () => number[]\n  getCanPreviousPage: () => boolean\n  getCanNextPage: () => boolean\n  previousPage: () => void\n  nextPage: () => void\n  getPrePaginationRowModel: () => RowModel\n  getPaginationRowModel: () => RowModel\n  _getPaginationRowModel?: () => RowModel\n  getPageCount: () => number\n}\n\n//\n\nconst defaultPageIndex = 0\nconst defaultPageSize = 10\n\nconst getDefaultPaginationState = (): PaginationState => ({\n  pageIndex: defaultPageIndex,\n  pageSize: defaultPageSize,\n})\n\nexport const Pagination: TableFeature = {\n  getInitialState: (state): PaginationTableState => {\n    return {\n      ...state,\n      pagination: {\n        ...getDefaultPaginationState(),\n        ...state?.pagination,\n      },\n    }\n  },\n\n  getDefaultOptions: (\n    table: Table\n  ): PaginationDefaultOptions => {\n    return {\n      onPaginationChange: makeStateUpdater('pagination', table),\n    }\n  },\n\n  createTable: (\n    table: Table\n  ): PaginationInstance => {\n    let registered = false\n    let queued = false\n\n    return {\n      _autoResetPageIndex: () => {\n        if (!registered) {\n          table._queue(() => {\n            registered = true\n          })\n          return\n        }\n\n        if (\n          table.options.autoResetAll ??\n          table.options.autoResetPageIndex ??\n          !table.options.manualPagination\n        ) {\n          if (queued) return\n          queued = true\n          table._queue(() => {\n            table.resetPageIndex()\n            queued = false\n          })\n        }\n      },\n      setPagination: updater => {\n        const safeUpdater: Updater = old => {\n          let newState = functionalUpdate(updater, old)\n\n          return newState\n        }\n\n        return table.options.onPaginationChange?.(safeUpdater)\n      },\n      resetPagination: defaultState => {\n        table.setPagination(\n          defaultState\n            ? getDefaultPaginationState()\n            : table.initialState.pagination ?? getDefaultPaginationState()\n        )\n      },\n      setPageIndex: updater => {\n        table.setPagination(old => {\n          let pageIndex = functionalUpdate(updater, old.pageIndex)\n\n          const maxPageIndex =\n            typeof table.options.pageCount === 'undefined' ||\n            table.options.pageCount === -1\n              ? Number.MAX_SAFE_INTEGER\n              : table.options.pageCount - 1\n\n          pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex))\n\n          return {\n            ...old,\n            pageIndex,\n          }\n        })\n      },\n      resetPageIndex: defaultState => {\n        table.setPageIndex(\n          defaultState\n            ? defaultPageIndex\n            : table.initialState?.pagination?.pageIndex ?? defaultPageIndex\n        )\n      },\n      resetPageSize: defaultState => {\n        table.setPageSize(\n          defaultState\n            ? defaultPageSize\n            : table.initialState?.pagination?.pageSize ?? defaultPageSize\n        )\n      },\n      setPageSize: updater => {\n        table.setPagination(old => {\n          const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))\n          const topRowIndex = old.pageSize * old.pageIndex!\n          const pageIndex = Math.floor(topRowIndex / pageSize)\n\n          return {\n            ...old,\n            pageIndex,\n            pageSize,\n          }\n        })\n      },\n      setPageCount: updater =>\n        table.setPagination(old => {\n          let newPageCount = functionalUpdate(\n            updater,\n            table.options.pageCount ?? -1\n          )\n\n          if (typeof newPageCount === 'number') {\n            newPageCount = Math.max(-1, newPageCount)\n          }\n\n          return {\n            ...old,\n            pageCount: newPageCount,\n          }\n        }),\n\n      getPageOptions: memo(\n        () => [table.getPageCount()],\n        pageCount => {\n          let pageOptions: number[] = []\n          if (pageCount && pageCount > 0) {\n            pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)\n          }\n          return pageOptions\n        },\n        {\n          key: process.env.NODE_ENV === 'development' && 'getPageOptions',\n          debug: () => table.options.debugAll ?? table.options.debugTable,\n        }\n      ),\n\n      getCanPreviousPage: () => table.getState().pagination.pageIndex > 0,\n\n      getCanNextPage: () => {\n        const { pageIndex } = table.getState().pagination\n\n        const pageCount = table.getPageCount()\n\n        if (pageCount === -1) {\n          return true\n        }\n\n        if (pageCount === 0) {\n          return false\n        }\n\n        return pageIndex < pageCount - 1\n      },\n\n      previousPage: () => {\n        return table.setPageIndex(old => old - 1)\n      },\n\n      nextPage: () => {\n        return table.setPageIndex(old => {\n          return old + 1\n        })\n      },\n\n      getPrePaginationRowModel: () => table.getExpandedRowModel(),\n      getPaginationRowModel: () => {\n        if (\n          !table._getPaginationRowModel &&\n          table.options.getPaginationRowModel\n        ) {\n          table._getPaginationRowModel =\n            table.options.getPaginationRowModel(table)\n        }\n\n        if (table.options.manualPagination || !table._getPaginationRowModel) {\n          return table.getPrePaginationRowModel()\n        }\n\n        return table._getPaginationRowModel()\n      },\n\n      getPageCount: () => {\n        return (\n          table.options.pageCount ??\n          Math.ceil(\n            table.getPrePaginationRowModel().rows.length /\n              table.getState().pagination.pageSize\n          )\n        )\n      },\n    }\n  },\n}\n"],"names":["defaultPageIndex","defaultPageSize","getDefaultPaginationState","pageIndex","pageSize","Pagination","getInitialState","state","pagination","getDefaultOptions","table","onPaginationChange","makeStateUpdater","createTable","registered","queued","_autoResetPageIndex","_ref","_table$options$autoRe","_queue","options","autoResetAll","autoResetPageIndex","manualPagination","resetPageIndex","setPagination","updater","safeUpdater","old","newState","functionalUpdate","resetPagination","defaultState","_table$initialState$p","initialState","setPageIndex","maxPageIndex","pageCount","Number","MAX_SAFE_INTEGER","Math","max","min","_table$initialState$p2","_table$initialState","_table$initialState$p3","resetPageSize","_table$initialState$p4","_table$initialState2","_table$initialState2$","setPageSize","topRowIndex","floor","setPageCount","_table$options$pageCo","newPageCount","getPageOptions","memo","getPageCount","pageOptions","Array","fill","map","_","i","key","process","env","NODE_ENV","debug","_table$options$debugA","debugAll","debugTable","getCanPreviousPage","getState","getCanNextPage","previousPage","nextPage","getPrePaginationRowModel","getExpandedRowModel","getPaginationRowModel","_getPaginationRowModel","_table$options$pageCo2","ceil","rows","length"],"mappings":";;;;;;;;;;;;;;;;AAiDA;;AAEA,MAAMA,gBAAgB,GAAG,CAAC,CAAA;AAC1B,MAAMC,eAAe,GAAG,EAAE,CAAA;AAE1B,MAAMC,yBAAyB,GAAGA,OAAwB;AACxDC,EAAAA,SAAS,EAAEH,gBAAgB;AAC3BI,EAAAA,QAAQ,EAAEH,eAAAA;AACZ,CAAC,CAAC,CAAA;AAEK,MAAMI,UAAwB,GAAG;EACtCC,eAAe,EAAGC,KAAK,IAA2B;IAChD,OAAO;AACL,MAAA,GAAGA,KAAK;AACRC,MAAAA,UAAU,EAAE;QACV,GAAGN,yBAAyB,EAAE;AAC9B,QAAA,IAAGK,KAAK,IAAA,IAAA,GAAA,KAAA,CAAA,GAALA,KAAK,CAAEC,UAAU,CAAA;AACtB,OAAA;KACD,CAAA;GACF;EAEDC,iBAAiB,EACfC,KAAmB,IACU;IAC7B,OAAO;AACLC,MAAAA,kBAAkB,EAAEC,sBAAgB,CAAC,YAAY,EAAEF,KAAK,CAAA;KACzD,CAAA;GACF;EAEDG,WAAW,EACTH,KAAmB,IACW;IAC9B,IAAII,UAAU,GAAG,KAAK,CAAA;IACtB,IAAIC,MAAM,GAAG,KAAK,CAAA;IAElB,OAAO;MACLC,mBAAmB,EAAEA,MAAM;QAAA,IAAAC,IAAA,E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