@kinetis/vector-ui 0.9.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/app/components/Vx/Action/Dialog.vue +5 -2
  3. package/app/components/Vx/List/BulkBar.vue +8 -4
  4. package/app/components/Vx/List/BulkEdit.vue +6 -3
  5. package/app/components/Vx/List/Pager.vue +49 -0
  6. package/app/components/Vx/Resource/Form.vue +2 -1
  7. package/app/components/Vx/Resource/RelationPanel.vue +28 -7
  8. package/app/components/Vx/Resource/Table.vue +105 -18
  9. package/app/composables/useVectorCursorPager.ts +49 -0
  10. package/app/composables/useVectorNotifications.ts +3 -3
  11. package/app/composables/useVectorResource.ts +7 -2
  12. package/app/i18n/ar/actions.ts +1 -0
  13. package/app/i18n/ar/list.ts +10 -0
  14. package/app/i18n/de/actions.ts +1 -0
  15. package/app/i18n/de/list.ts +10 -0
  16. package/app/i18n/en/actions.ts +1 -0
  17. package/app/i18n/en/list.ts +10 -0
  18. package/app/i18n/es/actions.ts +1 -0
  19. package/app/i18n/es/list.ts +10 -0
  20. package/app/i18n/fr/actions.ts +1 -0
  21. package/app/i18n/fr/list.ts +10 -0
  22. package/app/i18n/he/actions.ts +1 -0
  23. package/app/i18n/he/list.ts +10 -0
  24. package/app/i18n/it/actions.ts +1 -0
  25. package/app/i18n/it/list.ts +10 -0
  26. package/app/i18n/ja/actions.ts +1 -0
  27. package/app/i18n/ja/list.ts +10 -0
  28. package/app/i18n/ko/actions.ts +1 -0
  29. package/app/i18n/ko/list.ts +10 -0
  30. package/app/i18n/nl/actions.ts +1 -0
  31. package/app/i18n/nl/list.ts +10 -0
  32. package/app/i18n/pl/actions.ts +1 -0
  33. package/app/i18n/pl/list.ts +10 -0
  34. package/app/i18n/pt/actions.ts +1 -0
  35. package/app/i18n/pt/list.ts +10 -0
  36. package/app/i18n/pt-BR/actions.ts +1 -0
  37. package/app/i18n/pt-BR/list.ts +10 -0
  38. package/app/i18n/ru/actions.ts +1 -0
  39. package/app/i18n/ru/list.ts +10 -0
  40. package/app/i18n/tr/actions.ts +1 -0
  41. package/app/i18n/tr/list.ts +10 -0
  42. package/app/i18n/uk/actions.ts +1 -0
  43. package/app/i18n/uk/list.ts +10 -0
  44. package/app/i18n/zh-Hans/actions.ts +1 -0
  45. package/app/i18n/zh-Hans/list.ts +10 -0
  46. package/app/types/vector.ts +16 -2
  47. package/app/utils/richtext.ts +6 -2
  48. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,55 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.10.0] - 2026-10-20
11
+
12
+ ### Added
13
+
14
+ - A list whose resource is `withoutCount` pages by previous and next
15
+ with the page number, and shows no total and no last page. "Select all
16
+ matching" and its confirmations name every matching record without a
17
+ count.
18
+ - A list whose resource is `cursorPaging` pages by cursor, keeping the
19
+ cursors it visited so Previous works. It offers no sort, grouping,
20
+ page numbers, total or totals row; search, filters and page size
21
+ return it to the first page, and so does a reload.
22
+ - A relation panel whose target is `withoutCount` pages by previous and
23
+ next, and copying a record's many-to-many memberships walks such a
24
+ target by `hasMore`.
25
+ - `useVectorResource().listByCursor()`, `useVectorCursorPager()`,
26
+ `VxListPager` and the `VectorCursorPage` type. `VectorPage` gains an
27
+ optional `hasMore`.
28
+
29
+ ### Changed
30
+
31
+ - `VectorPage.total` and `lastPage` are now `number | null`: they are
32
+ `null` on a page of a `withoutCount` resource. So are the `count` prop
33
+ of `VxActionDialog` and `VxListBulkEdit` and the `total` prop of
34
+ `VxListBulkBar`, `null` meaning every matching record of a list that
35
+ is not counted. Code that reads these, or renders these components,
36
+ must handle `null`.
37
+
38
+ ### Fixed
39
+
40
+ - A list returns to its first page on a new search, filter, sort, page
41
+ size or saved view only once that page has arrived. A request that
42
+ fails leaves the page number and the rows as they were, instead of
43
+ showing page 1 over the old page's rows; the next step asks for the
44
+ first page again. `VectorPageStep` gains `'first'`.
45
+ - Rich text under the hosted admin's CSP reports no violation. The
46
+ sanitizer's self-test no longer carries `onclick` and `onerror`, which
47
+ the browser checked against `script-src-attr` even in DOMPurify's inert
48
+ document; its attributes still have to be stripped by the allow-list.
49
+
50
+ ## [0.9.4] - 2026-10-19
51
+
52
+ ### Changed
53
+
54
+ - The toast type `useVectorNotifications()` queues is renamed from
55
+ `VectorNotification` to `VectorToast`. `VectorNotification` is now only
56
+ the inbox item from `/vector/notifications`, and Nuxt no longer warns
57
+ about a duplicated auto-import.
58
+
10
59
  ## [0.9.3] - 2026-10-18
11
60
 
12
61
  ### Changed
@@ -8,7 +8,8 @@ const props = defineProps<{
8
8
  resource: VectorResource
9
9
  action: VectorAction
10
10
  selection: VectorSelection | null
11
- count: number
11
+ /** null: every match of a list that is not counted */
12
+ count: number | null
12
13
  }>()
13
14
 
14
15
  const emit = defineEmits<{ done: [affected: number], cancel: [] }>()
@@ -30,7 +31,9 @@ for (const field of props.action.fields) {
30
31
  const subject = computed(() => props.action.standalone
31
32
  ? ''
32
33
  : props.selection?.all
33
- ? t('actions.subjectAll', { label: noun(props.resource.labelSingular), count: props.count })
34
+ ? props.count === null
35
+ ? t('actions.subjectAllUncounted', { label: noun(props.resource.labelSingular) })
36
+ : t('actions.subjectAll', { label: noun(props.resource.labelSingular), count: props.count })
34
37
  : t('actions.subjectCount', { count: props.count, label: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) }))
35
38
 
36
39
  async function run(event: SubmitEventPromise) {
@@ -3,11 +3,15 @@ import type { VectorAction, VectorResource } from '#vector/app/types/vector'
3
3
 
4
4
  // What a selection can do: the built-in edit, delete, restore and
5
5
  // force-delete of the resource and every index action. "All matching" widens the
6
- // selection from the checked rows to every record the list matches.
6
+ // selection from the checked rows to every record the list matches; on a
7
+ // list that is not counted it says so without a number.
7
8
  defineProps<{
8
9
  resource: VectorResource
9
10
  selected: number
10
- total: number
11
+ /** null: the list is not counted */
12
+ total: number | null
13
+ /** Whether, uncounted, the match may hold more than the checked rows. */
14
+ more?: boolean
11
15
  allMatching: boolean
12
16
  trashedOnly: boolean
13
17
  actions: VectorAction[]
@@ -26,8 +30,8 @@ const { t } = useVectorT()
26
30
 
27
31
  <template>
28
32
  <v-sheet color="primary" rounded class="d-flex align-center flex-wrap ga-2 px-4 py-2 mb-2">
29
- <span class="font-weight-medium">{{ allMatching ? t('list.bulk.allMatching', { total }) : t('list.bulk.selected', { count: selected }) }}</span>
30
- <v-btn v-if="!allMatching && total > selected" size="small" variant="outlined" @click="emit('update:allMatching', true)">{{ t('list.bulk.selectAllMatching', { total }) }}</v-btn>
33
+ <span class="font-weight-medium">{{ allMatching ? (total === null ? t('list.bulk.allMatchingUncounted') : t('list.bulk.allMatching', { total })) : t('list.bulk.selected', { count: selected }) }}</span>
34
+ <v-btn v-if="!allMatching && (total === null ? more : total > selected)" size="small" variant="outlined" @click="emit('update:allMatching', true)">{{ total === null ? t('list.bulk.selectAllMatchingUncounted') : t('list.bulk.selectAllMatching', { total }) }}</v-btn>
31
35
  <v-btn v-else-if="allMatching" size="small" variant="outlined" @click="emit('update:allMatching', false)">{{ t('list.bulk.onlyChecked') }}</v-btn>
32
36
  <v-spacer />
33
37
  <template v-if="resource.softDelete && trashedOnly">
@@ -8,7 +8,8 @@ import type { VectorResource, VectorSelection } from '#vector/app/types/vector'
8
8
  const props = defineProps<{
9
9
  resource: VectorResource
10
10
  selection: VectorSelection
11
- count: number
11
+ /** null: every match of a list that is not counted */
12
+ count: number | null
12
13
  }>()
13
14
 
14
15
  const emit = defineEmits<{ done: [affected: number], cancel: [] }>()
@@ -34,7 +35,9 @@ watch(chosen, (names) => {
34
35
  })
35
36
 
36
37
  const subject = computed(() => props.selection.all
37
- ? t('list.bulkEdit.everyMatching', { noun: noun(props.resource.labelSingular), count: props.count })
38
+ ? props.count === null
39
+ ? t('list.bulkEdit.everyMatchingUncounted', { noun: noun(props.resource.labelSingular) })
40
+ : t('list.bulkEdit.everyMatching', { noun: noun(props.resource.labelSingular), count: props.count })
38
41
  : t('list.bulkEdit.some', { count: props.count, noun: noun(props.count === 1 ? props.resource.labelSingular : props.resource.label) }))
39
42
 
40
43
  async function save(event: SubmitEventPromise) {
@@ -83,7 +86,7 @@ async function save(event: SubmitEventPromise) {
83
86
  <v-card-actions>
84
87
  <v-spacer />
85
88
  <v-btn variant="text" :disabled="running" @click="emit('cancel')">{{ t('common.cancel') }}</v-btn>
86
- <v-btn type="submit" color="primary" :loading="running" :disabled="!chosen.length">{{ t('list.bulkEdit.applyTo', { count }) }}</v-btn>
89
+ <v-btn type="submit" color="primary" :loading="running" :disabled="!chosen.length">{{ count === null ? t('list.bulkEdit.applyToAll') : t('list.bulkEdit.applyTo', { count }) }}</v-btn>
87
90
  </v-card-actions>
88
91
  </v-card>
89
92
  </v-form>
@@ -0,0 +1,49 @@
1
+ <script setup lang="ts">
2
+ import { useLocale } from 'vuetify'
3
+
4
+ // The footer of a list that cannot say how many records it has: an
5
+ // uncounted (withoutCount) list shows the page it is on, a cursor list
6
+ // not even that. Previous and next only — no total, no last page.
7
+ defineProps<{
8
+ perPage: number
9
+ perPageOptions: number[]
10
+ /** The page number to show; null shows none (a cursor list). */
11
+ page: number | null
12
+ hasPrevious: boolean
13
+ hasNext: boolean
14
+ disabled?: boolean
15
+ }>()
16
+
17
+ const emit = defineEmits<{
18
+ 'update:perPage': [value: number]
19
+ previous: []
20
+ next: []
21
+ }>()
22
+
23
+ const { t } = useVectorT()
24
+ // Vuetify's own footer strings, in every language it ships
25
+ const { t: vt } = useLocale()
26
+ </script>
27
+
28
+ <template>
29
+ <div class="vx-list-pager d-flex align-center justify-end flex-wrap ga-4 px-4 py-2 text-body-2">
30
+ <div class="d-flex align-center ga-2">
31
+ <span>{{ vt('$vuetify.dataFooter.itemsPerPageText') }}</span>
32
+ <v-select
33
+ :model-value="perPage"
34
+ :items="perPageOptions"
35
+ :aria-label="vt('$vuetify.dataFooter.itemsPerPageText')"
36
+ density="compact"
37
+ variant="outlined"
38
+ hide-details
39
+ style="max-width: 100px"
40
+ @update:model-value="(v: number) => emit('update:perPage', v)"
41
+ />
42
+ </div>
43
+ <span v-if="page !== null" class="vx-list-pager-page">{{ t('list.pager.page', { page }) }}</span>
44
+ <div class="d-flex align-center">
45
+ <v-btn icon="$prev" variant="plain" density="comfortable" :disabled="disabled || !hasPrevious" :aria-label="vt('$vuetify.dataFooter.prevPage')" @click="emit('previous')" />
46
+ <v-btn icon="$next" variant="plain" density="comfortable" :disabled="disabled || !hasNext" :aria-label="vt('$vuetify.dataFooter.nextPage')" @click="emit('next')" />
47
+ </div>
48
+ </div>
49
+ </template>
@@ -131,7 +131,8 @@ async function allRelatedIds(id: string | number, field: VectorField): Promise<u
131
131
  const result = await client.related(id, field.name, { page, perPage })
132
132
  ids.push(...result.data.map(r => r.id))
133
133
 
134
- if (page >= result.lastPage) return ids
134
+ // an uncounted (withoutCount) target has no last page: it says whether another follows
135
+ if (result.lastPage === null ? !result.hasMore : page >= result.lastPage) return ids
135
136
  }
136
137
  }
137
138
 
@@ -41,22 +41,27 @@ const headers = computed(() => [
41
41
 
42
42
  // --- the related page ---------------------------------------------------
43
43
  const items = ref<VectorRecord[]>([])
44
- const total = ref(0)
44
+ /** null when the target resource is not counted (withoutCount): previous and next only */
45
+ const total = ref<number | null>(0)
46
+ const hasMore = ref(false)
45
47
  const page = ref(1)
46
48
  const perPage = ref(10)
47
49
  const sortBy = ref<{ key: string, order: 'asc' | 'desc' }[]>([])
48
50
  const loading = ref(false)
49
51
 
50
- async function load() {
52
+ /** Loads $target, the page shown now by default; the page number moves only once that page has arrived. */
53
+ async function load(target: number = page.value) {
51
54
  loading.value = true
52
55
 
53
56
  try {
54
57
  const result = await client.related(props.record.id, props.field.name, {
55
- page: page.value, perPage: perPage.value,
58
+ page: target, perPage: perPage.value,
56
59
  sort: sortBy.value.map(s => ({ field: s.key, order: s.order })),
57
60
  })
61
+ page.value = target
58
62
  items.value = result.data
59
63
  total.value = result.total
64
+ hasMore.value = result.hasMore ?? false
60
65
  } catch (error) {
61
66
  notifications.error(vectorErrorMessage(error))
62
67
  } finally {
@@ -65,6 +70,8 @@ async function load() {
65
70
  }
66
71
 
67
72
  watch(() => props.record.id, () => { page.value = 1; load() })
73
+ // the table resets the page it pages itself on a new sort; an uncounted panel pages here
74
+ watch(sortBy, () => { if (total.value === null) page.value = 1 }, { deep: true, flush: 'sync' })
68
75
 
69
76
  function open(item: VectorRecord) {
70
77
  if (target.value) navigateTo(`${appConfig.vector.basePath}/r/${target.value.slug}/${encodeURIComponent(String(item.id))}`)
@@ -150,25 +157,26 @@ function label(n: number): string {
150
157
  <v-card-title class="d-flex align-center ga-2 text-subtitle-1">
151
158
  <v-icon v-if="target.icon" :icon="target.icon" size="small" />
152
159
  {{ field.label }}
153
- <v-chip size="x-small" variant="tonal">{{ total }}</v-chip>
160
+ <v-chip v-if="total !== null" size="x-small" variant="tonal">{{ total }}</v-chip>
154
161
  <v-spacer />
155
162
  <v-btn v-if="canAttach" size="small" variant="tonal" prepend-icon="mdi-link-plus" @click="startAttach">{{ t('record.panel.attach') }}</v-btn>
156
163
  <v-btn v-if="canCreate" size="small" variant="tonal" color="primary" prepend-icon="mdi-plus" @click="creating = true">{{ t('record.newTitle', { label: noun(target.labelSingular) }) }}</v-btn>
157
164
  </v-card-title>
158
165
 
159
166
  <v-data-table-server
160
- v-model:page="page"
161
167
  v-model:items-per-page="perPage"
162
168
  v-model:sort-by="sortBy"
169
+ :page="total === null ? 1 : page"
163
170
  :headers="headers"
164
171
  :items="items"
165
- :items-length="total"
172
+ :items-length="total ?? items.length"
166
173
  :loading="loading"
167
174
  :items-per-page-options="[5, 10, 25, 50]"
168
175
  item-value="id"
169
176
  density="compact"
170
177
  hover
171
- @update:options="load"
178
+ @update:page="(p: number) => { if (total !== null) page = p }"
179
+ @update:options="() => load()"
172
180
  @click:row="(_: Event, { item }: { item: VectorRecord }) => open(item)"
173
181
  >
174
182
  <template v-for="column in columns" :key="column.name" #[`item.${column.name}`]="{ item }">
@@ -177,6 +185,19 @@ function label(n: number): string {
177
185
  <template #[`item._actions`]="{ item }">
178
186
  <v-btn icon="mdi-link-off" size="small" variant="text" :aria-label="t('record.panel.detachLabel', { title: String(item[target.titleField] ?? item.id) })" @click.stop="detach(item)" />
179
187
  </template>
188
+ <template v-if="total === null" #bottom>
189
+ <VxListPager
190
+ :per-page="perPage"
191
+ :per-page-options="[5, 10, 25, 50]"
192
+ :page="page"
193
+ :has-previous="page > 1"
194
+ :has-next="hasMore"
195
+ :disabled="loading"
196
+ @update:per-page="(n: number) => { page = 1; perPage = n }"
197
+ @previous="load(page - 1)"
198
+ @next="load(page + 1)"
199
+ />
200
+ </template>
180
201
  <template #no-data>
181
202
  <div class="text-medium-emphasis py-4">{{ t('record.panel.empty', { label: noun(target.label) }) }}</div>
182
203
  </template>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { fieldProps, type VectorAction, type VectorExportFormat, type VectorField, type VectorFilterGroup, type VectorFilterQuery, type VectorFilters, type VectorListState, type VectorPage, type VectorRecord, type VectorResource, type VectorSelection, type VectorSort, type VectorSavedView } from '#vector/app/types/vector'
3
+ import type { VectorPageStep } from '#vector/app/composables/useVectorCursorPager'
3
4
 
4
5
  // The list view: a server-driven table whose every option — page, size,
5
6
  // sort, filters, search, grouping, columns — becomes one list request,
@@ -17,6 +18,11 @@ const preferences = useVectorPreferences()
17
18
  await preferences.load()
18
19
 
19
20
  // --- list state -------------------------------------------------------
21
+ // How the list pages: by page number with a total (the default), by page
22
+ // number without one (withoutCount), or by cursor (cursorPaging), which
23
+ // orders by the identifier and so can neither sort nor group.
24
+ const byCursor = computed(() => props.resource.table.cursorPaging === true)
25
+ const counted = computed(() => !byCursor.value && props.resource.table.withoutCount !== true)
20
26
  const columns = ref<string[]>(preferences.get<string[]>(`columns.${props.resource.slug}`)?.filter(c => props.resource.table.columns.includes(c)) ?? [...props.resource.table.columns])
21
27
  // The filter: conditions that must all hold, "any of" groups of
22
28
  // alternatives, and whatever a saved view holds that the bar cannot edit.
@@ -27,10 +33,11 @@ const search = ref<string | null>('')
27
33
  const term = computed(() => (search.value ?? '').trim())
28
34
  const group = ref<string | null>(null)
29
35
  const trashed = ref<'without' | 'only' | 'with'>('without')
30
- const summaries = ref(props.resource.table.summaries.length > 0)
36
+ const summaries = ref(!byCursor.value && props.resource.table.summaries.length > 0)
31
37
  const page = ref(1)
38
+ const cursors = useVectorCursorPager()
32
39
  const itemsPerPage = ref(props.resource.table.perPage)
33
- const sortBy = ref<{ key: string, order?: boolean | 'asc' | 'desc' }[]>(props.resource.table.defaultSort.map(s => ({ key: s.field, order: s.order })))
40
+ const sortBy = ref<{ key: string, order?: boolean | 'asc' | 'desc' }[]>(byCursor.value ? [] : props.resource.table.defaultSort.map(s => ({ key: s.field, order: s.order })))
34
41
  const activeView = ref<number | null>(null)
35
42
 
36
43
  const fields = computed<VectorField[]>(() => columns.value
@@ -43,7 +50,7 @@ const numeric = (field: VectorField) => ['number', 'money'].includes(field.type
43
50
  const headers = computed(() => fields.value.map(field => ({
44
51
  key: field.name,
45
52
  title: field.label,
46
- sortable: field.sortable,
53
+ sortable: field.sortable && !byCursor.value,
47
54
  align: (numeric(field) ? 'end' : 'start') as 'start' | 'end',
48
55
  nowrap: true,
49
56
  })))
@@ -75,26 +82,59 @@ const state = computed<VectorListState>(() => ({
75
82
 
76
83
  // --- loading ----------------------------------------------------------
77
84
  const items = ref<VectorRecord[]>([])
78
- const total = ref(0)
85
+ /** The match's size; null when the list is not counted. */
86
+ const total = ref<number | null>(0)
87
+ /** Whether a page follows this one, on a list that is not counted. */
88
+ const hasMore = ref(false)
79
89
  const summaryValues = ref<Record<string, number | null>>({})
80
90
  const loading = ref(false)
81
91
  let requestId = 0
92
+ /** Whether the next load goes back to the first page: a changed search, filter, sort or page size asked for it. */
93
+ let restart = false
94
+
95
+ /**
96
+ * Loads the page shown now, or the one $step away on a list that is not
97
+ * counted. The step is taken only once its page has arrived: a request
98
+ * that fails leaves the page number, the cursors and the rows as they were.
99
+ * While a return to the first page is owed, every load is that return.
100
+ */
101
+ async function load(step: VectorPageStep = 'stay') {
102
+ if (restart) step = 'first'
103
+ const cursor = byCursor.value ? cursors.cursorFor(step) : null
104
+ if (byCursor.value && cursor === null) return
82
105
 
83
- async function load() {
84
106
  const id = ++requestId
85
107
  loading.value = true
86
108
 
87
109
  try {
110
+ if (byCursor.value) {
111
+ const result = await client.listByCursor(cursor!, { perPage: itemsPerPage.value, filter: rawFilters(), q: term.value || undefined, columns: columns.value })
112
+
113
+ if (id !== requestId) return
114
+
115
+ cursors.received(step, result)
116
+ restart = false
117
+ items.value = result.data
118
+ total.value = null
119
+ hasMore.value = result.hasMore
120
+ summaryValues.value = {}
121
+ return
122
+ }
123
+
124
+ const target = step === 'first' ? 1 : page.value + (step === 'forward' ? 1 : step === 'back' ? -1 : 0)
88
125
  const sort: VectorSort[] = sortBy.value.map(s => ({ field: s.key, order: s.order === 'desc' ? 'desc' : 'asc' }))
89
126
  const result: VectorPage = await client.list({
90
- page: page.value, perPage: itemsPerPage.value, sort, filter: rawFilters(), q: term.value || undefined,
127
+ page: target, perPage: itemsPerPage.value, sort, filter: rawFilters(), q: term.value || undefined,
91
128
  group: group.value ?? undefined, summaries: summaries.value, columns: columns.value,
92
129
  })
93
130
 
94
131
  if (id !== requestId) return
95
132
 
133
+ page.value = target
134
+ restart = false
96
135
  items.value = result.data
97
136
  total.value = result.total
137
+ hasMore.value = result.hasMore ?? false
98
138
  summaryValues.value = result.summaries ?? {}
99
139
  } catch (error) {
100
140
  notifications.error(vectorErrorMessage(error))
@@ -108,15 +148,40 @@ function rawFilters(): VectorFilterQuery {
108
148
  return wireFilters.value
109
149
  }
110
150
 
111
- const debouncedLoad = useDebounceFn(() => { page.value = 1; load() }, 300)
151
+ /** Back to the first page, as a changed search, filter or page size needs: once that page has arrived. */
152
+ function firstPage() {
153
+ restart = true
154
+ }
155
+
156
+ const debouncedLoad = useDebounceFn(() => { firstPage(); load() }, 300)
112
157
  watch(search, () => debouncedLoad())
113
- watch([filters, groups, advanced, group, trashed, summaries], () => { page.value = 1; load() }, { deep: true })
158
+ watch([filters, groups, advanced, group, trashed, summaries], () => { firstPage(); load() }, { deep: true })
114
159
  watch(columns, (c) => { preferences.put({ [`columns.${props.resource.slug}`]: c }).catch(() => undefined); load() })
115
160
 
116
161
  function onOptions() {
117
162
  load()
118
163
  }
119
164
 
165
+ // The table resets the page it pages itself on a new sort; an uncounted list pages here, so this does, before the table reports the sort
166
+ watch(sortBy, () => { if (!counted.value) firstPage() }, { deep: true, flush: 'sync' })
167
+
168
+ // The pager of a list that is not counted: the table's own footer needs a total.
169
+ const onFirstPage = computed(() => byCursor.value ? !cursors.hasPrevious.value : page.value === 1)
170
+
171
+ function previousPage() {
172
+ if (!onFirstPage.value) load('back')
173
+ }
174
+
175
+ function nextPage() {
176
+ if (byCursor.value ? cursors.hasNext.value : hasMore.value) load('forward')
177
+ }
178
+
179
+ /** A new page size starts again from the first page; the table reports the change, which loads it. */
180
+ function setPerPage(perPage: number) {
181
+ firstPage()
182
+ itemsPerPage.value = perPage
183
+ }
184
+
120
185
  // --- views ------------------------------------------------------------
121
186
  const viewMenu = ref<{ views: VectorSavedView[] } | null>(null)
122
187
 
@@ -163,13 +228,14 @@ function applyView(view: VectorSavedView | null) {
163
228
  groups.value = decoded.groups
164
229
  advanced.value = decoded.advanced
165
230
  search.value = s.q ?? ''
166
- group.value = s.group && known.has(s.group) ? s.group : null
231
+ // a cursor list orders by the identifier: a view's grouping, sort and summaries do not apply to it
232
+ group.value = !byCursor.value && s.group && known.has(s.group) ? s.group : null
167
233
  const sorts = s.sort ? s.sort.split(',').map(e => ({ key: e.replace(/^-/, ''), order: e.startsWith('-') ? 'desc' as const : 'asc' as const })).filter(x => known.has(x.key)) : []
168
- sortBy.value = sorts.length ? sorts : props.resource.table.defaultSort.map(x => ({ key: x.field, order: x.order }))
234
+ sortBy.value = byCursor.value ? [] : sorts.length ? sorts : props.resource.table.defaultSort.map(x => ({ key: x.field, order: x.order }))
169
235
  if (s.columns) columns.value = s.columns.split(',').filter(c => props.resource.table.columns.includes(c))
170
236
  itemsPerPage.value = s.perPage ?? props.resource.table.perPage
171
- summaries.value = s.summaries ?? summaries.value
172
- page.value = 1
237
+ summaries.value = !byCursor.value && (s.summaries ?? summaries.value)
238
+ firstPage()
173
239
  }
174
240
 
175
241
  onMounted(() => {
@@ -186,7 +252,10 @@ watch(items, () => { selected.value = selected.value.filter(id => items.value.so
186
252
  const selection = computed<VectorSelection>(() => allMatching.value
187
253
  ? { all: { filter: rawFilters(), q: term.value || undefined } }
188
254
  : { ids: selected.value })
189
- const selectionCount = computed(() => allMatching.value ? total.value : selected.value.length)
255
+ /** How many records the selection holds; null for every match of a list that is not counted. */
256
+ const selectionCount = computed<number | null>(() => allMatching.value ? total.value : selected.value.length)
257
+ /** Whether "all matching" would add records to the checked rows, on a list that cannot count them. */
258
+ const moreMatching = computed(() => hasMore.value || !onFirstPage.value || selected.value.length < items.value.length)
190
259
  const indexActions = computed(() => props.resource.actions.filter(a => a.showOnIndex && !a.standalone))
191
260
  const standaloneActions = computed(() => props.resource.actions.filter(a => a.showOnIndex && a.standalone))
192
261
  const dialogAction = ref<VectorAction | null>(null)
@@ -195,7 +264,9 @@ const bulkEditing = ref(false)
195
264
  async function operation(op: 'delete' | 'restore' | 'forceDelete') {
196
265
  const n = selectionCount.value
197
266
  const subject = noun(n === 1 ? props.resource.labelSingular : props.resource.label)
198
- const titles = { delete: t('list.operation.deleteTitle', { count: n, noun: subject }), restore: t('list.operation.restoreTitle', { count: n, noun: subject }), forceDelete: t('list.operation.forceDeleteTitle', { count: n, noun: subject }) }
267
+ const titles = n === null
268
+ ? { delete: t('list.operation.deleteAllTitle', { noun: subject }), restore: t('list.operation.restoreAllTitle', { noun: subject }), forceDelete: t('list.operation.forceDeleteAllTitle', { noun: subject }) }
269
+ : { delete: t('list.operation.deleteTitle', { count: n, noun: subject }), restore: t('list.operation.restoreTitle', { count: n, noun: subject }), forceDelete: t('list.operation.forceDeleteTitle', { count: n, noun: subject }) }
199
270
 
200
271
  if (!await confirm({ title: titles[op], text: op === 'restore' ? undefined : (props.resource.softDelete && op === 'delete' ? t('list.operation.toTrash') : t('list.operation.irreversible')), confirmText: op === 'restore' ? t('common.restore') : t('common.delete'), destructive: op !== 'restore' })) return
201
272
 
@@ -362,7 +433,7 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
362
433
  <div class="d-flex align-center flex-wrap ga-2 mb-2">
363
434
  <v-text-field v-model="search" :placeholder="resource.table.search.length ? t('list.search', { label: noun(resource.label) }) : t('list.noSearch')" :disabled="resource.table.search.length === 0" prepend-inner-icon="mdi-magnify" density="compact" hide-details clearable :aria-label="t('common.search')" style="max-width: 320px" />
364
435
  <VxListViewMenu ref="viewMenu" :resource="resource" :current="state" :active-id="activeView" @apply="applyView" @update:active-id="(id: number | null) => activeView = id" />
365
- <v-select v-if="resource.table.groupable.length" v-model="group" :items="[{ title: t('list.noGrouping'), value: null }, ...resource.table.groupable.map(g => ({ title: resource.fields.find(f => f.name === g)?.label ?? g, value: g }))]" :label="t('list.groupBy')" density="compact" hide-details style="max-width: 200px" />
436
+ <v-select v-if="resource.table.groupable.length && !byCursor" v-model="group" :items="[{ title: t('list.noGrouping'), value: null }, ...resource.table.groupable.map(g => ({ title: resource.fields.find(f => f.name === g)?.label ?? g, value: g }))]" :label="t('list.groupBy')" density="compact" hide-details style="max-width: 200px" />
366
437
  <v-select v-if="resource.softDelete" v-model="trashed" :items="[{ title: t('list.trash.active'), value: 'without' }, { title: t('list.trash.only'), value: 'only' }, { title: t('list.trash.with'), value: 'with' }]" density="compact" hide-details :aria-label="t('list.trash.label')" style="max-width: 180px" prepend-inner-icon="mdi-delete-clock-outline" />
367
438
  <v-spacer />
368
439
  <v-btn v-for="action in standaloneActions" :key="action.name" size="small" variant="tonal" :prepend-icon="action.icon ?? undefined" @click="dialogAction = action">{{ action.label }}</v-btn>
@@ -387,6 +458,7 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
387
458
  :resource="resource"
388
459
  :selected="selected.length"
389
460
  :total="total"
461
+ :more="moreMatching"
390
462
  :all-matching="allMatching"
391
463
  :trashed-only="trashed === 'only'"
392
464
  :actions="indexActions"
@@ -409,12 +481,12 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
409
481
 
410
482
  <v-data-table-server
411
483
  v-model="selected"
412
- v-model:page="page"
413
484
  v-model:items-per-page="itemsPerPage"
414
485
  v-model:sort-by="sortBy"
486
+ :page="counted ? page : 1"
415
487
  :headers="headers"
416
488
  :items="items"
417
- :items-length="total"
489
+ :items-length="counted ? total ?? 0 : items.length"
418
490
  :loading="loading"
419
491
  :items-per-page-options="resource.table.perPageOptions"
420
492
  :group-by="group ? [{ key: group, order: 'asc' }] : []"
@@ -423,6 +495,7 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
423
495
  hover
424
496
  fixed-header
425
497
  density="comfortable"
498
+ @update:page="(p: number) => { if (counted) page = p }"
426
499
  @update:options="onOptions"
427
500
  @click:row="(_: Event, { item }: { item: VectorRecord }) => open(item)"
428
501
  >
@@ -472,7 +545,7 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
472
545
  </tr>
473
546
  </template>
474
547
 
475
- <template v-if="summaries && Object.keys(summaryValues).length" #body.append>
548
+ <template v-if="!byCursor && summaries && Object.keys(summaryValues).length" #body.append>
476
549
  <tr class="font-weight-medium bg-surface-light">
477
550
  <td />
478
551
  <td v-if="group" />
@@ -484,6 +557,20 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', warnBeforeUnloa
484
557
  </tr>
485
558
  </template>
486
559
 
560
+ <template v-if="!counted" #bottom>
561
+ <VxListPager
562
+ :per-page="itemsPerPage"
563
+ :per-page-options="resource.table.perPageOptions"
564
+ :page="byCursor ? null : page"
565
+ :has-previous="!onFirstPage"
566
+ :has-next="byCursor ? cursors.hasNext.value : hasMore"
567
+ :disabled="loading"
568
+ @update:per-page="setPerPage"
569
+ @previous="previousPage"
570
+ @next="nextPage"
571
+ />
572
+ </template>
573
+
487
574
  <template #no-data>
488
575
  <v-empty-state icon="mdi-database-off-outline" :title="Object.keys(filters).length || groups.length || advanced.length || term ? t('list.nothingMatches') : t('list.empty', { label: noun(resource.label) })" />
489
576
  </template>
@@ -0,0 +1,49 @@
1
+ /** Where a list goes from the page it shows: nowhere (a reload), the next page, the one before, or back to the first. */
2
+ export type VectorPageStep = 'stay' | 'forward' | 'back' | 'first'
3
+
4
+ /**
5
+ * Keyset paging as a list walks it: the cursor of every page visited so
6
+ * far, so Previous returns to the one before, and the next page's cursor
7
+ * once the current page says another follows. The first page's cursor is
8
+ * the empty string; the API hands out the others, and no cursor can be
9
+ * worked out from a page number, so going back means remembering.
10
+ *
11
+ * A step moves nothing until its page has arrived: `cursorFor()` names
12
+ * the cursor to request, and `received()` takes the step once the answer
13
+ * is in, so a request that fails leaves the list where it was.
14
+ */
15
+ export function useVectorCursorPager() {
16
+ const visited = ref<string[]>([''])
17
+ const next = ref<string | null>(null)
18
+
19
+ /** The cursor the page shown now was requested with. */
20
+ const current = computed(() => visited.value[visited.value.length - 1]!)
21
+ /** Which page this is, counting from 1. */
22
+ const position = computed(() => visited.value.length)
23
+ const hasPrevious = computed(() => visited.value.length > 1)
24
+ const hasNext = computed(() => next.value !== null)
25
+
26
+ /** The cursor to request for $step; null when there is no such page. */
27
+ function cursorFor(step: VectorPageStep): string | null {
28
+ if (step === 'forward') return next.value
29
+ if (step === 'back') return visited.value.length > 1 ? visited.value[visited.value.length - 2]! : null
30
+ if (step === 'first') return ''
31
+ return current.value
32
+ }
33
+
34
+ /** Takes $step now that its page has arrived, and records what the page says about the one after it. */
35
+ function received(step: VectorPageStep, page: { nextCursor: string | null, hasMore: boolean }) {
36
+ if (step === 'forward' && next.value !== null) visited.value = [...visited.value, next.value]
37
+ if (step === 'back' && visited.value.length > 1) visited.value = visited.value.slice(0, -1)
38
+ if (step === 'first') visited.value = ['']
39
+ next.value = page.hasMore ? page.nextCursor : null
40
+ }
41
+
42
+ /** Back to the first page, as a changed search, filter or page size needs. */
43
+ function reset() {
44
+ visited.value = ['']
45
+ next.value = null
46
+ }
47
+
48
+ return { current, position, hasPrevious, hasNext, cursorFor, received, reset }
49
+ }
@@ -1,4 +1,4 @@
1
- export interface VectorNotification {
1
+ export interface VectorToast {
2
2
  text: string
3
3
  color?: 'success' | 'error' | 'warning' | 'info'
4
4
  timeout?: number
@@ -9,9 +9,9 @@ export interface VectorNotification {
9
9
  * store or a fetch hook can notify from anywhere.
10
10
  */
11
11
  export function useVectorNotifications() {
12
- const queue = useState<VectorNotification[]>('vector.notifications', () => [])
12
+ const queue = useState<VectorToast[]>('vector.notifications', () => [])
13
13
 
14
- function notify(text: string, color: VectorNotification['color'] = 'info', timeout?: number) {
14
+ function notify(text: string, color: VectorToast['color'] = 'info', timeout?: number) {
15
15
  queue.value.push({ text, color, timeout })
16
16
  }
17
17
 
@@ -1,4 +1,4 @@
1
- import type { VectorActionResponse, VectorAuditEntry, VectorExportFormat, VectorFilterQuery, VectorImportMode, VectorImportPreview, VectorPage, VectorRecord, VectorRecordPermissions, VectorRelationValue, VectorSelection, VectorSort, VectorUploaded, VectorWidgetData } from '#vector/app/types/vector'
1
+ import type { VectorActionResponse, VectorAuditEntry, VectorCursorPage, VectorExportFormat, VectorFilterQuery, VectorImportMode, VectorImportPreview, VectorPage, VectorRecord, VectorRecordPermissions, VectorRelationValue, VectorSelection, VectorSort, VectorUploaded, VectorWidgetData } from '#vector/app/types/vector'
2
2
 
3
3
  export interface VectorListOptions {
4
4
  page?: number
@@ -84,6 +84,11 @@ export function useVectorResource(slug: MaybeRefOrGetter<string>) {
84
84
  return api<VectorPage>(base(), { query: listQuery(options) })
85
85
  }
86
86
 
87
+ /** A keyset page by the identifier: `''` for the first, then the previous page's `nextCursor`. The API sorts, groups and summarizes nothing under a cursor. */
88
+ function listByCursor(cursor: string, options: Omit<VectorListOptions, 'page' | 'sort' | 'group' | 'summaries'> = {}): Promise<VectorCursorPage> {
89
+ return api<VectorCursorPage>(base(), { query: { ...listQuery(options), cursor } })
90
+ }
91
+
87
92
  function related(id: string | number, relation: string, options: VectorListOptions = {}): Promise<VectorPage> {
88
93
  return api<VectorPage>(`${base()}/${encodeURIComponent(String(id))}/${encodeURIComponent(relation)}`, { query: listQuery(options) })
89
94
  }
@@ -256,7 +261,7 @@ export function useVectorResource(slug: MaybeRefOrGetter<string>) {
256
261
  })
257
262
  }
258
263
 
259
- return { list, related, show, create, update, remove, removeMany, batch, changes, attach, detach, upload, fileBlob, downloadFile, forceRemove, restore, runAction, exportCsv, exportFile, audit, revert, rows, widget, importPreview, importCsv, options }
264
+ return { list, listByCursor, related, show, create, update, remove, removeMany, batch, changes, attach, detach, upload, fileBlob, downloadFile, forceRemove, restore, runAction, exportCsv, exportFile, audit, revert, rows, widget, importPreview, importCsv, options }
260
265
  }
261
266
 
262
267
  /**