@merkaly/nuxt 0.4.3 → 0.4.5
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/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -26,13 +26,18 @@ const module = defineNuxtModule({
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
meta: { name: "@merkaly/nuxt", configKey: "merkaly", compatibility: { nuxt: ">=3.0.0" } },
|
|
29
|
-
moduleDependencies
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
moduleDependencies(nuxt) {
|
|
30
|
+
const dependencies = {
|
|
31
|
+
"@bootstrap-vue-next/nuxt": {},
|
|
32
|
+
"@nuxt/eslint": {},
|
|
33
|
+
"@nuxt/fonts": {},
|
|
34
|
+
"@nuxt/image": {},
|
|
35
|
+
"@vueuse/nuxt": {}
|
|
36
|
+
};
|
|
37
|
+
if (nuxt.options.merkaly?.plausible) {
|
|
38
|
+
dependencies["@nuxtjs/plausible"] = {};
|
|
39
|
+
}
|
|
40
|
+
return dependencies;
|
|
36
41
|
},
|
|
37
42
|
async setup(options, nuxt) {
|
|
38
43
|
const moduleResolver = createResolver(import.meta.url);
|
|
@@ -52,15 +52,26 @@ const visibleItems = computed(() => {
|
|
|
52
52
|
const start = Math.max(0, paginationText.value.values.current - 1);
|
|
53
53
|
return $datagrid.value.items.slice(start, paginationText.value.values.final);
|
|
54
54
|
});
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
const selectionState = computed(() => {
|
|
56
|
+
const selectedItems = [];
|
|
57
|
+
for (const item of $datagrid.value.items) {
|
|
58
|
+
if (item._checked) {
|
|
59
|
+
selectedItems.push(item);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const selectedCount = selectedItems.length;
|
|
63
|
+
const totalCount = $datagrid.value.items.length;
|
|
64
|
+
const allChecked = totalCount > 0 && selectedCount === totalCount;
|
|
65
|
+
const someChecked = selectedCount > 0;
|
|
66
|
+
return {
|
|
67
|
+
allChecked,
|
|
68
|
+
checkboxAllAttrs: {
|
|
69
|
+
checked: allChecked,
|
|
70
|
+
indeterminate: !allChecked && someChecked
|
|
71
|
+
},
|
|
72
|
+
selectedCount,
|
|
73
|
+
selectedItems
|
|
74
|
+
};
|
|
64
75
|
});
|
|
65
76
|
function toggleCheckAll() {
|
|
66
77
|
const allChecked = $datagrid.value.items.every((it) => it._checked);
|
|
@@ -78,15 +89,25 @@ function emitSearch() {
|
|
|
78
89
|
$datagrid.value.page = 1;
|
|
79
90
|
emit("fetch", "search");
|
|
80
91
|
}
|
|
92
|
+
function getRowKey(item, idx) {
|
|
93
|
+
return $datagrid.value.row?.(item, idx)?.key ?? idx;
|
|
94
|
+
}
|
|
95
|
+
function getRowAttrs(item, idx) {
|
|
96
|
+
const row = $datagrid.value.row?.(item, idx);
|
|
97
|
+
return {
|
|
98
|
+
...row?.attrs ?? {},
|
|
99
|
+
...row?.class ? { class: row.class } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
81
102
|
</script>
|
|
82
103
|
|
|
83
104
|
<template>
|
|
84
105
|
<BCard no-body>
|
|
85
|
-
<BCardHeader v-if="!props.hideHeader" class="align-items-center p-4">
|
|
106
|
+
<BCardHeader v-if="!props.hideHeader" class="align-items-center p-4 position-relative">
|
|
86
107
|
<BCardTitle>
|
|
87
|
-
<div v-if="hasBulkSlot && !props.hideSelect &&
|
|
108
|
+
<div v-if="hasBulkSlot && !props.hideSelect && selectionState.selectedCount" class="w-35px">
|
|
88
109
|
<DropdownIcon icon="caret-down" size="sm" toggle-class="p-2">
|
|
89
|
-
<slot name="bulk" v-bind="{ items: selectedItems, count:
|
|
110
|
+
<slot name="bulk" v-bind="{ items: selectionState.selectedItems, count: selectionState.selectedCount }" />
|
|
90
111
|
</DropdownIcon>
|
|
91
112
|
</div>
|
|
92
113
|
|
|
@@ -146,6 +167,14 @@ function emitSearch() {
|
|
|
146
167
|
</BButton>
|
|
147
168
|
</template>
|
|
148
169
|
</div>
|
|
170
|
+
|
|
171
|
+
<BProgress
|
|
172
|
+
v-if="$datagrid.loading"
|
|
173
|
+
:value="100"
|
|
174
|
+
animated
|
|
175
|
+
height="5px"
|
|
176
|
+
class="rounded-0 position-absolute w-100 start-0"
|
|
177
|
+
style="bottom: -6px; z-index: 10" />
|
|
149
178
|
</BCardHeader>
|
|
150
179
|
|
|
151
180
|
<BTableSimple
|
|
@@ -165,12 +194,12 @@ function emitSearch() {
|
|
|
165
194
|
:disabled="$datagrid.loading"
|
|
166
195
|
class="form-check-input"
|
|
167
196
|
type="checkbox"
|
|
168
|
-
v-bind="checkboxAllAttrs"
|
|
197
|
+
v-bind="selectionState.checkboxAllAttrs"
|
|
169
198
|
@input="toggleCheckAll()">
|
|
170
199
|
</div>
|
|
171
200
|
</BTh>
|
|
172
201
|
|
|
173
|
-
<template v-for="
|
|
202
|
+
<template v-for="[key, column] in visibleColumns" :key="key">
|
|
174
203
|
<BTh :class="[column.class, column.thClass]">
|
|
175
204
|
<slot :name="`head[${key}]`" v-bind="{ column, key }">
|
|
176
205
|
<span v-text="column.title ?? sentenceCase(key)" />
|
|
@@ -182,15 +211,7 @@ function emitSearch() {
|
|
|
182
211
|
</BTr>
|
|
183
212
|
</BThead>
|
|
184
213
|
|
|
185
|
-
<BTbody v-if="
|
|
186
|
-
<BTd :colspan="tableColspan">
|
|
187
|
-
<div class="text-center">
|
|
188
|
-
<BSpinner variant="primary" />
|
|
189
|
-
</div>
|
|
190
|
-
</BTd>
|
|
191
|
-
</BTbody>
|
|
192
|
-
|
|
193
|
-
<BTbody v-else-if="!visibleItems.length">
|
|
214
|
+
<BTbody v-if="!visibleItems.length">
|
|
194
215
|
<BTd :colspan="tableColspan">
|
|
195
216
|
<slot name="empty">
|
|
196
217
|
<div class="text-center text-muted" v-text="props.emptyText" />
|
|
@@ -199,8 +220,8 @@ function emitSearch() {
|
|
|
199
220
|
</BTbody>
|
|
200
221
|
|
|
201
222
|
<BTbody v-else class="fw-semibold text-gray-600">
|
|
202
|
-
<template v-for="(item, idx) in visibleItems" :key="idx">
|
|
203
|
-
<BTr>
|
|
223
|
+
<template v-for="(item, idx) in visibleItems" :key="getRowKey(item, idx)">
|
|
224
|
+
<BTr v-bind="getRowAttrs(item, idx)">
|
|
204
225
|
<BTd v-if="hasDetailsSlot" class="p-0 w-25px">
|
|
205
226
|
<BButton
|
|
206
227
|
class="w-25px h-100 rounded-0 p-0 border-end border-dashed"
|
|
@@ -217,10 +238,10 @@ function emitSearch() {
|
|
|
217
238
|
</div>
|
|
218
239
|
</BTd>
|
|
219
240
|
|
|
220
|
-
<template v-for="
|
|
241
|
+
<template v-for="[key, column] in visibleColumns" :key="key">
|
|
221
242
|
<BTd :class="[column.class, column.tdClass]">
|
|
222
243
|
<slot :name="`row[${key}]`" v-bind="{ column, idx, item, key }">
|
|
223
|
-
<span v-text="column.getter?.(item)
|
|
244
|
+
<span v-text="column.getter?.(item) ?? getItemValue(item, key)" />
|
|
224
245
|
</slot>
|
|
225
246
|
</BTd>
|
|
226
247
|
</template>
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
export interface ColumnDefinition<C = unknown> {
|
|
2
2
|
class?: string;
|
|
3
|
-
getter?: (row: C) =>
|
|
3
|
+
getter?: (row: C) => unknown;
|
|
4
4
|
tdClass?: string;
|
|
5
5
|
thClass?: string;
|
|
6
6
|
title?: string;
|
|
7
|
-
type?:
|
|
7
|
+
type?: unknown;
|
|
8
8
|
}
|
|
9
9
|
export type DataGridItem<C> = C;
|
|
10
|
+
export type DataGridRowAttrs = Record<string, unknown>;
|
|
11
|
+
export type DataGridRowKey = string | number;
|
|
12
|
+
export interface DataGridRowDefinition {
|
|
13
|
+
attrs?: DataGridRowAttrs;
|
|
14
|
+
class?: string;
|
|
15
|
+
key?: DataGridRowKey;
|
|
16
|
+
}
|
|
10
17
|
export interface DataGrid<C = unknown> {
|
|
11
18
|
columns: Record<string, ColumnDefinition<C>>;
|
|
12
19
|
error: unknown;
|
|
20
|
+
fn: {
|
|
21
|
+
addItem: (item: C) => DataGridItem<C>[];
|
|
22
|
+
removeItem: (predicate: (item: DataGridItem<C>, index: number) => boolean) => number;
|
|
23
|
+
};
|
|
13
24
|
items: DataGridItem<C>[];
|
|
14
25
|
limit: number;
|
|
15
26
|
loading: boolean;
|
|
16
27
|
page: number;
|
|
28
|
+
row?: (item: C, index: number) => DataGridRowDefinition;
|
|
17
29
|
search: string;
|
|
18
30
|
total: number;
|
|
19
|
-
fn: {
|
|
20
|
-
addItem: (item: C) => DataGridItem<C>[];
|
|
21
|
-
removeItem: (predicate: (item: DataGridItem<C>, index: number) => boolean) => number;
|
|
22
|
-
};
|
|
23
31
|
}
|
|
24
32
|
interface OptionArgs<D> {
|
|
25
33
|
columns: Record<string, ColumnDefinition<D>>;
|
|
@@ -27,6 +35,7 @@ interface OptionArgs<D> {
|
|
|
27
35
|
items?: D[];
|
|
28
36
|
limit?: number;
|
|
29
37
|
loading?: boolean;
|
|
38
|
+
row?: (item: D, index: number) => DataGridRowDefinition;
|
|
30
39
|
search?: string;
|
|
31
40
|
total?: number;
|
|
32
41
|
}
|
|
@@ -3,12 +3,6 @@ export function useDatagrid(params) {
|
|
|
3
3
|
const state = reactive({
|
|
4
4
|
columns: params.columns,
|
|
5
5
|
error: params.error ?? null,
|
|
6
|
-
items: params.items ?? [],
|
|
7
|
-
search: params.search,
|
|
8
|
-
limit: params.limit ?? 10,
|
|
9
|
-
loading: params.loading ?? false,
|
|
10
|
-
page: 1,
|
|
11
|
-
total: params.total ?? 0,
|
|
12
6
|
fn: {
|
|
13
7
|
addItem(item) {
|
|
14
8
|
state.items.push(item);
|
|
@@ -21,7 +15,14 @@ export function useDatagrid(params) {
|
|
|
21
15
|
}
|
|
22
16
|
return index;
|
|
23
17
|
}
|
|
24
|
-
}
|
|
18
|
+
},
|
|
19
|
+
items: params.items ?? [],
|
|
20
|
+
limit: params.limit ?? 10,
|
|
21
|
+
loading: params.loading ?? false,
|
|
22
|
+
page: 1,
|
|
23
|
+
row: params.row,
|
|
24
|
+
search: params.search ?? "",
|
|
25
|
+
total: params.total ?? 0
|
|
25
26
|
});
|
|
26
27
|
return state;
|
|
27
28
|
}
|