@xy-planning-network/trees 0.11.6-dev-4 → 0.11.6-dev-6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xy-planning-network/trees",
3
- "version": "0.11.6-dev-4",
3
+ "version": "0.11.6-dev-6",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "github:xy-planning-network/trees",
@@ -45,9 +45,7 @@ const loadAndRender = (): void => {
45
45
  q: query.value,
46
46
  }
47
47
 
48
- if (!selectionsPersisted.value) {
49
- clearSelections()
50
- }
48
+ clearSelections()
51
49
 
52
50
  BaseAPI.get<TrailsRespPaged<unknown>>(
53
51
  props.tableOptions.url,
@@ -140,10 +138,6 @@ const hasContent = computed((): boolean => {
140
138
  return rows.value.length ? true : false
141
139
  })
142
140
 
143
- const selectionsPersisted = computed(() => {
144
- return props.tableBulkActions.persistent ?? false
145
- })
146
-
147
141
  const clearSelections = () => {
148
142
  selected.value = []
149
143
  }
@@ -153,6 +147,12 @@ const selected = defineModel<number[]>("selected", {
153
147
  default: [],
154
148
  })
155
149
 
150
+ const selectedData = computed((): TableRowData[] => {
151
+ return tableData.value.filter((data) => {
152
+ return selected.value.includes(data?.id)
153
+ })
154
+ })
155
+
156
156
  const selectedOnPage = computed(() => {
157
157
  return selected.value.filter((id) => {
158
158
  return selectable.value.includes(id)
@@ -169,7 +169,11 @@ const bulkActions = computed(() => {
169
169
  ...action,
170
170
  disabled: selected.value.length === 0 || action.disabled,
171
171
  onClick: () =>
172
- action.onClick.apply(undefined, [selected.value, publicMethods]),
172
+ action.onClick.apply(undefined, [
173
+ selected.value,
174
+ selectedData.value,
175
+ publicMethods,
176
+ ]),
173
177
  }
174
178
  })
175
179
  })
@@ -212,21 +216,6 @@ const bulkSelectIndeterminate = computed(
212
216
  const bulkSelectOnChange = (e: Event) => {
213
217
  const isChecked = (e.target as HTMLInputElement).checked
214
218
 
215
- // append all records on current page to existing selection
216
- if (selectionsPersisted.value && isChecked) {
217
- selected.value = [...selected.value, ...selectable.value.map((id) => id)]
218
- return
219
- }
220
-
221
- // remove all records on current page from existing selection
222
- if (selectionsPersisted.value && !isChecked) {
223
- selected.value = selected.value.filter((id) => {
224
- return !selectable.value.includes(id)
225
- })
226
-
227
- return
228
- }
229
-
230
219
  // set all records on current page to selection
231
220
  if (isChecked) {
232
221
  selected.value = selectable.value.map((id) => id)
@@ -238,6 +227,7 @@ const bulkSelectOnChange = (e: Event) => {
238
227
 
239
228
  const publicMethods: DynamicTableAPI = {
240
229
  clearSelection: clearSelections,
230
+ selectedData: selectedData,
241
231
  refresh: loadAndRender,
242
232
  reset: reloadTable,
243
233
  }
@@ -431,11 +421,6 @@ loadAndRender()
431
421
  <span class="font-medium">{{ selectedOnPage.length }}</span>
432
422
  of
433
423
  <span class="font-medium">{{ selectable.length }}</span>
434
- <span v-if="selectionsPersisted">
435
- /
436
- <span class="font-medium">{{ selected.length }}</span>
437
- total
438
- </span>
439
424
  </div>
440
425
 
441
426
  <TableActionButtons :actions="bulkActions" />
@@ -85,7 +85,9 @@ const range = computed(() => {
85
85
  class="flex flex-col items-center space-y-3.5 sm:flex-row sm:space-y-0 sm:gap-x-3 sm:justify-center"
86
86
  >
87
87
  <!--Range details-->
88
- <p class="text-center text-sm text-neutral-700 sm:text-left sm:mr-auto">
88
+ <p
89
+ class="text-center text-sm text-neutral-700 sm:text-left sm:mr-auto sm:w-1/3"
90
+ >
89
91
  Showing
90
92
  <span class="font-medium">{{ range.start }}</span>
91
93
  to
@@ -95,46 +97,50 @@ const range = computed(() => {
95
97
  results
96
98
  </p>
97
99
 
98
- <!--Pager-->
99
- <div class="flex gap-3 items-center justify-center shrink-0">
100
- <button
101
- class="xy-btn-neutral"
102
- :disabled="page <= 1"
103
- type="button"
104
- @click.prevent="page--"
105
- >
106
- &larr; <span class="sr-only">Previous</span>
107
- </button>
108
-
109
- <div class="max-w-[50px]">
110
- <NumberInput
111
- :model-value="page"
112
- :min="1"
113
- :max="pagination.totalPages"
114
- type="number"
115
- @update:model-value="debouncePageInput"
116
- @keydown.down="onDown"
117
- @keydown.up="onUp"
118
- />
100
+ <div
101
+ class="flex flex-col items-center space-y-3.5 sm:flex-row sm:space-y-0 sm:gap-x-3 sm:flex-1"
102
+ >
103
+ <!--Pager-->
104
+ <div class="flex gap-3 items-center justify-center shrink-0 md:w-1/2">
105
+ <button
106
+ class="xy-btn-neutral"
107
+ :disabled="page <= 1"
108
+ type="button"
109
+ @click.prevent="page--"
110
+ >
111
+ &larr; <span class="sr-only">Previous</span>
112
+ </button>
113
+
114
+ <div class="max-w-[50px]">
115
+ <NumberInput
116
+ :model-value="page"
117
+ :min="1"
118
+ :max="pagination.totalPages"
119
+ type="number"
120
+ @update:model-value="debouncePageInput"
121
+ @keydown.down.prevent="onDown"
122
+ @keydown.up.prevent="onUp"
123
+ />
124
+ </div>
125
+
126
+ <div class="text-sm">
127
+ of <span class="font-medium">{{ pagination.totalPages }}</span>
128
+ </div>
129
+
130
+ <button
131
+ class="xy-btn-neutral"
132
+ :disabled="page >= pagination.totalPages"
133
+ type="button"
134
+ @click.prevent="page++"
135
+ >
136
+ <span class="sr-only">Next</span> &rarr;
137
+ </button>
119
138
  </div>
120
139
 
121
- <div class="text-sm">
122
- of <span class="font-medium">{{ pagination.totalPages }}</span>
140
+ <!--Per Page Selector-->
141
+ <div class="max-w-[150px] sm:ml-auto">
142
+ <Select v-model="perPage" :options="pageSelectOpts" />
123
143
  </div>
124
-
125
- <button
126
- class="xy-btn-neutral"
127
- :disabled="page >= pagination.totalPages"
128
- type="button"
129
- @click.prevent="page++"
130
- >
131
- <span class="sr-only">Next</span> &rarr;
132
- </button>
133
- </div>
134
-
135
- <!--Per Page Selector-->
136
- <div class="max-w-[150px] sm:ml-auto">
137
- <Select v-model="perPage" :options="pageSelectOpts" />
138
144
  </div>
139
145
  </div>
140
146
  </template>
@@ -1,4 +1,4 @@
1
- import { VNodeChild } from "vue";
1
+ import { VNodeChild, type ComputedRef } from "vue";
2
2
  import { ActionItem } from "../composables/nav";
3
3
  import { DateRangeProps } from "./date";
4
4
  export interface DynamicTableOptions {
@@ -10,7 +10,12 @@ export interface DynamicTableOptions {
10
10
  search?: boolean;
11
11
  url: string;
12
12
  }
13
- export interface DynamicTableAPI {
13
+ export interface DynamicTableAPI<T = TableRowData> {
14
+ /**
15
+ * Clear the currently selected rows when bulk selections are enabled
16
+ * This method is called when refresh and reset methods are called.
17
+ * @returns void
18
+ */
14
19
  clearSelection: () => void;
15
20
  /**
16
21
  * Force refresh the table data with the current api params state
@@ -22,6 +27,10 @@ export interface DynamicTableAPI {
22
27
  * @returns void
23
28
  */
24
29
  reset: () => void;
30
+ /**
31
+ * The selected data records when bulk actions are enabled on the table
32
+ */
33
+ selectedData: ComputedRef<T[]>;
25
34
  }
26
35
  export interface TableActionItem<T = TableRowData> extends ActionItem {
27
36
  /**
@@ -49,7 +58,7 @@ export interface TableActionItem<T = TableRowData> extends ActionItem {
49
58
  */
50
59
  show?: boolean | ((rowData: T, rowIndex: number) => boolean);
51
60
  }
52
- export interface TableBulkActionItem extends ActionItem {
61
+ export interface TableBulkActionItem<T = TableRowData> extends ActionItem {
53
62
  /**
54
63
  * Whether or not the bulk action item is enabled. Disabled actions are
55
64
  * visible in the UI, but do not trigger click events.
@@ -58,10 +67,11 @@ export interface TableBulkActionItem extends ActionItem {
58
67
  /**
59
68
  * The callback method triggered by the action item buttons click event.
60
69
  * @param selected the array of selected rows by the primary key `id`
70
+ * @param selectedData the array of selected rows as the underlying data type T
61
71
  * @param tableAPI DynamicTableAPI
62
72
  * @returns void
63
73
  */
64
- onClick: (selected: number[], tableAPI: DynamicTableAPI) => void;
74
+ onClick: (selected: number[], selectedData: T[], tableAPI: DynamicTableAPI) => void;
65
75
  /**
66
76
  * Whether or not to visible show the action item in the UI. When all action items
67
77
  * on a table a hidden with show: false, bulk selections are disabled for the table.
@@ -82,11 +92,7 @@ export interface TableBulkActions<T = TableRowData> {
82
92
  /**
83
93
  * an array of TableActionItem definitions
84
94
  */
85
- actions: TableBulkActionItem[];
86
- /**
87
- * whether to persist the selections across pagination, searching, sorting, and filtering
88
- */
89
- persistent?: boolean;
95
+ actions: TableBulkActionItem<T>[];
90
96
  /**
91
97
  * a function that determines if the row can be selected for bulk actions
92
98
  */
@@ -1,4 +1,4 @@
1
- import type { DynamicTableOptions, TableActions, TableBulkActions, TableColumns } from "../../composables/table";
1
+ import type { DynamicTableOptions, TableActions, TableBulkActions, TableColumns, TableRowData } from "../../composables/table";
2
2
  type __VLS_Props = {
3
3
  tableActions?: TableActions<any>;
4
4
  tableBulkActions?: TableBulkActions<any>;
@@ -12,6 +12,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
12
12
  clearSelection: () => void;
13
13
  refresh: () => void;
14
14
  reset: () => void;
15
+ selectedData: import("vue").ComputedRef<TableRowData[]>;
15
16
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
17
  "update:selected": (value: number[]) => any;
17
18
  } & {