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

package.lib.components.VDataTable.composables.paginate.mjs.map Maven / Gradle / Ivy

{"version":3,"file":"paginate.mjs","names":["useProxiedModel","computed","inject","provide","watch","watchEffect","clamp","getCurrentInstance","propsFactory","makeDataTablePaginateProps","page","type","Number","String","default","itemsPerPage","VDataTablePaginationSymbol","Symbol","for","createPagination","props","undefined","value","providePagination","options","itemsLength","startIndex","stopIndex","Math","min","pageCount","ceil","setItemsPerPage","nextPage","prevPage","setPage","data","usePagination","Error","usePaginatedItems","vm","items","paginatedItems","slice","val","emit"],"sources":["../../../../src/components/VDataTable/composables/paginate.ts"],"sourcesContent":["// Composables\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Utilities\nimport { computed, inject, provide, watch, watchEffect } from 'vue'\nimport { clamp, getCurrentInstance, propsFactory } from '@/util'\n\n// Types\nimport type { InjectionKey, Ref } from 'vue'\nimport type { Group } from './group'\nimport type { EventProp } from '@/util'\n\nexport const makeDataTablePaginateProps = propsFactory({\n  page: {\n    type: [Number, String],\n    default: 1,\n  },\n  itemsPerPage: {\n    type: [Number, String],\n    default: 10,\n  },\n}, 'DataTable-paginate')\n\nconst VDataTablePaginationSymbol: InjectionKey<{\n  page: Ref\n  itemsPerPage: Ref\n  startIndex: Ref\n  stopIndex: Ref\n  pageCount: Ref\n  itemsLength: Ref\n  prevPage: () => void\n  nextPage: () => void\n  setPage: (value: number) => void\n  setItemsPerPage: (value: number) => void\n}> = Symbol.for('vuetify:data-table-pagination')\n\ntype PaginationProps = {\n  page: number | string\n  'onUpdate:page': EventProp | undefined\n  itemsPerPage: number | string\n  'onUpdate:itemsPerPage': EventProp | undefined\n  itemsLength?: number | string\n}\n\nexport function createPagination (props: PaginationProps) {\n  const page = useProxiedModel(props, 'page', undefined, value => +(value ?? 1))\n  const itemsPerPage = useProxiedModel(props, 'itemsPerPage', undefined, value => +(value ?? 10))\n\n  return { page, itemsPerPage }\n}\n\nexport function providePagination (options: {\n  page: Ref\n  itemsPerPage: Ref\n  itemsLength: Ref\n}) {\n  const { page, itemsPerPage, itemsLength } = options\n\n  const startIndex = computed(() => {\n    if (itemsPerPage.value === -1) return 0\n\n    return itemsPerPage.value * (page.value - 1)\n  })\n  const stopIndex = computed(() => {\n    if (itemsPerPage.value === -1) return itemsLength.value\n\n    return Math.min(itemsLength.value, startIndex.value + itemsPerPage.value)\n  })\n\n  const pageCount = computed(() => {\n    if (itemsPerPage.value === -1 || itemsLength.value === 0) return 1\n\n    return Math.ceil(itemsLength.value / itemsPerPage.value)\n  })\n\n  watchEffect(() => {\n    if (page.value > pageCount.value) {\n      page.value = pageCount.value\n    }\n  })\n\n  function setItemsPerPage (value: number) {\n    itemsPerPage.value = value\n    page.value = 1\n  }\n\n  function nextPage () {\n    page.value = clamp(page.value + 1, 1, pageCount.value)\n  }\n\n  function prevPage () {\n    page.value = clamp(page.value - 1, 1, pageCount.value)\n  }\n\n  function setPage (value: number) {\n    page.value = clamp(value, 1, pageCount.value)\n  }\n\n  const data = { page, itemsPerPage, startIndex, stopIndex, pageCount, itemsLength, nextPage, prevPage, setPage, setItemsPerPage }\n\n  provide(VDataTablePaginationSymbol, data)\n\n  return data\n}\n\nexport function usePagination () {\n  const data = inject(VDataTablePaginationSymbol)\n\n  if (!data) throw new Error('Missing pagination!')\n\n  return data\n}\n\nexport function usePaginatedItems  (options: {\n  items: Ref)[]>\n  startIndex: Ref\n  stopIndex: Ref\n  itemsPerPage: Ref\n}) {\n  const vm = getCurrentInstance('usePaginatedItems')\n\n  const { items, startIndex, stopIndex, itemsPerPage } = options\n  const paginatedItems = computed(() => {\n    if (itemsPerPage.value <= 0) return items.value\n\n    return items.value.slice(startIndex.value, stopIndex.value)\n  })\n\n  watch(paginatedItems, val => {\n    vm.emit('update:currentItems', val)\n  })\n\n  return { paginatedItems }\n}\n"],"mappings":"AAAA;AAAA,SACSA,eAAe,iDAExB;AACA,SAASC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KA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