vueless 0.0.433 → 0.0.435
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 +1 -1
- package/ui.data-table/UTable.vue +22 -0
- package/ui.data-table/UTableRow.vue +62 -25
- package/ui.data-table/config.js +1 -2
- package/ui.data-table/storybook/stories.js +31 -0
- package/ui.data-table/useAttrs.js +0 -3
- package/ui.data-table/utilTable.js +30 -1
- package/web-types.json +16 -1
package/package.json
CHANGED
package/ui.data-table/UTable.vue
CHANGED
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
v-bind="getRowAttrs(row.id)"
|
|
185
185
|
:class="cx([getRowAttrs(row.id).class, getRowClasses(row)])"
|
|
186
186
|
@click="onClickRow"
|
|
187
|
+
@click-cell="onClickCell"
|
|
187
188
|
@toggle-row-visibility="onToggleRowVisibility"
|
|
188
189
|
>
|
|
189
190
|
<template
|
|
@@ -297,6 +298,7 @@ import {
|
|
|
297
298
|
toggleRowVisibility,
|
|
298
299
|
switchRowCheck,
|
|
299
300
|
getFlatRows,
|
|
301
|
+
rowsHasId,
|
|
300
302
|
} from "./utilTable.js";
|
|
301
303
|
|
|
302
304
|
import { PX_IN_REM } from "../constants.js";
|
|
@@ -395,6 +397,12 @@ const emit = defineEmits([
|
|
|
395
397
|
*/
|
|
396
398
|
"clickRow",
|
|
397
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Triggers when the cell is clicked.
|
|
402
|
+
* @property {object} cell
|
|
403
|
+
*/
|
|
404
|
+
"clickCell",
|
|
405
|
+
|
|
398
406
|
/**
|
|
399
407
|
* Triggers when table rows are selected (updated).
|
|
400
408
|
* @property {array} tableRows
|
|
@@ -563,6 +571,16 @@ watch(
|
|
|
563
571
|
tableRows.value = tableRows.value.map((row) => syncRowCheck(row, selectedRows.value));
|
|
564
572
|
},
|
|
565
573
|
);
|
|
574
|
+
watch(
|
|
575
|
+
() => props.rows,
|
|
576
|
+
() => {
|
|
577
|
+
if (!rowsHasId(props.rows)) {
|
|
578
|
+
// eslint-disable-next-line no-console
|
|
579
|
+
console.warn("[Vueless][UTable]: Each table row must have unique id.");
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
{ deep: true, immediate: true },
|
|
583
|
+
);
|
|
566
584
|
|
|
567
585
|
onMounted(() => {
|
|
568
586
|
tableRows.value = props.rows;
|
|
@@ -676,6 +694,10 @@ function onClickRow(row) {
|
|
|
676
694
|
emit("clickRow", row);
|
|
677
695
|
}
|
|
678
696
|
|
|
697
|
+
function onClickCell(cell, row) {
|
|
698
|
+
emit("clickCell", cell, row);
|
|
699
|
+
}
|
|
700
|
+
|
|
679
701
|
function onChangeSelectAll(selectAll) {
|
|
680
702
|
if (selectAll && canSelectAll.value) {
|
|
681
703
|
selectedRows.value = getFlatRows(tableRows.value).map((row) => row.id);
|
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
<td
|
|
19
19
|
v-for="(value, key, index) in getFilteredRow(row, columns)"
|
|
20
20
|
:key="index"
|
|
21
|
-
v-bind="
|
|
22
|
-
:class="
|
|
23
|
-
|
|
24
|
-
"
|
|
21
|
+
v-bind="bodyCellBaseAttrs"
|
|
22
|
+
:class="cx([columns[index].tdClass, getCellClasses(row, key)])"
|
|
23
|
+
@click="onClickCell(value, row)"
|
|
25
24
|
>
|
|
26
25
|
<div
|
|
27
26
|
v-if="(row.row || nestedLevel || row.nestedData) && index === 0"
|
|
@@ -36,20 +35,33 @@
|
|
|
36
35
|
:name="getToggleIconName(row)"
|
|
37
36
|
color="brand"
|
|
38
37
|
v-bind="toggleIconConfig"
|
|
39
|
-
@click="onClickToggleIcon"
|
|
38
|
+
@click.stop="onClickToggleIcon"
|
|
40
39
|
/>
|
|
40
|
+
|
|
41
|
+
<slot :name="`cell-${key}`" :value="value" :row="row" :index="index">
|
|
42
|
+
<div
|
|
43
|
+
v-bind="bodyCellContentAttrs"
|
|
44
|
+
ref="cellRef"
|
|
45
|
+
:class="cx([bodyCellContentAttrs.class, getCellContentClasses(row, key)])"
|
|
46
|
+
:data-test="`${dataTest}-${key}-cell`"
|
|
47
|
+
>
|
|
48
|
+
{{ value.value || value || HYPHEN_SYMBOL }}
|
|
49
|
+
</div>
|
|
50
|
+
</slot>
|
|
41
51
|
</div>
|
|
42
52
|
|
|
43
|
-
<
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
<template v-else>
|
|
54
|
+
<slot :name="`cell-${key}`" :value="value" :row="row" :index="index">
|
|
55
|
+
<div
|
|
56
|
+
v-bind="bodyCellContentAttrs"
|
|
57
|
+
ref="cellRef"
|
|
58
|
+
:class="cx([bodyCellContentAttrs.class, getCellContentClasses(row, key)])"
|
|
59
|
+
:data-test="`${dataTest}-${key}-cell`"
|
|
60
|
+
>
|
|
61
|
+
{{ value.value || value || HYPHEN_SYMBOL }}
|
|
62
|
+
</div>
|
|
63
|
+
</slot>
|
|
64
|
+
</template>
|
|
53
65
|
</td>
|
|
54
66
|
</tr>
|
|
55
67
|
|
|
@@ -78,7 +90,15 @@
|
|
|
78
90
|
:selectable="selectable"
|
|
79
91
|
@toggle-row-visibility="onClickToggleRowChild"
|
|
80
92
|
@click="onClick"
|
|
81
|
-
|
|
93
|
+
>
|
|
94
|
+
<template
|
|
95
|
+
v-for="(value, key, index) in getFilteredRow(row.row, columns)"
|
|
96
|
+
:key="index"
|
|
97
|
+
#[`cell-${key}`]="slotValues"
|
|
98
|
+
>
|
|
99
|
+
<slot :name="`cell-${key}`" :value="slotValues.value" :row="slotValues.row" :index="index" />
|
|
100
|
+
</template>
|
|
101
|
+
</UTableRow>
|
|
82
102
|
|
|
83
103
|
<template v-if="!isSingleNestedRow && row.row.length && !row.nestedData">
|
|
84
104
|
<template v-for="nestedRow in row.row" :key="nestedRow.id">
|
|
@@ -95,7 +115,21 @@
|
|
|
95
115
|
:selectable="selectable"
|
|
96
116
|
@toggle-row-visibility="onClickToggleRowChild"
|
|
97
117
|
@click="onClick"
|
|
98
|
-
|
|
118
|
+
@click-cell="onClickCell"
|
|
119
|
+
>
|
|
120
|
+
<template
|
|
121
|
+
v-for="(value, key, index) in getFilteredRow(nestedRow, columns)"
|
|
122
|
+
:key="index"
|
|
123
|
+
#[`cell-${key}`]="slotValues"
|
|
124
|
+
>
|
|
125
|
+
<slot
|
|
126
|
+
:name="`cell-${key}`"
|
|
127
|
+
:value="slotValues.value"
|
|
128
|
+
:row="slotValues.row"
|
|
129
|
+
:index="index"
|
|
130
|
+
/>
|
|
131
|
+
</template>
|
|
132
|
+
</UTableRow>
|
|
99
133
|
</template>
|
|
100
134
|
</template>
|
|
101
135
|
</template>
|
|
@@ -157,7 +191,7 @@ const props = defineProps({
|
|
|
157
191
|
},
|
|
158
192
|
});
|
|
159
193
|
|
|
160
|
-
const emit = defineEmits(["toggleRowVisibility", "click"]);
|
|
194
|
+
const emit = defineEmits(["toggleRowVisibility", "click", "click-cell"]);
|
|
161
195
|
|
|
162
196
|
const selectedRows = defineModel("selectedRows", { type: Array, default: () => [] });
|
|
163
197
|
|
|
@@ -172,7 +206,6 @@ const {
|
|
|
172
206
|
bodyCellNestedAttrs,
|
|
173
207
|
bodyCellNestedExpandIconAttrs,
|
|
174
208
|
bodyCellNestedCollapseIconAttrs,
|
|
175
|
-
bodyCellNestedRowAttrs,
|
|
176
209
|
bodyCellBaseAttrs,
|
|
177
210
|
} = props.attrs;
|
|
178
211
|
|
|
@@ -206,12 +239,6 @@ function getCellContentClasses(row, key) {
|
|
|
206
239
|
return typeof cellClasses === "function" ? cellClasses(row[key].value, row) : cellClasses;
|
|
207
240
|
}
|
|
208
241
|
|
|
209
|
-
function getCellAttrs(row, cellIndex) {
|
|
210
|
-
const isNestedRow = (row.row || row.nestedData || props.nestedLevel > 0) && cellIndex === 0;
|
|
211
|
-
|
|
212
|
-
return isNestedRow ? bodyCellNestedRowAttrs.value : bodyCellBaseAttrs.value;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
242
|
function getNestedShift() {
|
|
216
243
|
return { marginLeft: `${props.nestedLevel * shift.value}rem` };
|
|
217
244
|
}
|
|
@@ -255,6 +282,12 @@ function setElementTitle(element) {
|
|
|
255
282
|
}
|
|
256
283
|
|
|
257
284
|
function onClickToggleIcon() {
|
|
285
|
+
if (props.row.nestedData) {
|
|
286
|
+
onClickToggleRowChild(props.row.id);
|
|
287
|
+
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
258
291
|
if (isSingleNestedRow.value) {
|
|
259
292
|
onClickToggleRowChild(props.row.row.id);
|
|
260
293
|
|
|
@@ -263,4 +296,8 @@ function onClickToggleIcon() {
|
|
|
263
296
|
|
|
264
297
|
props.row.row.forEach(({ id }) => onClickToggleRowChild(id));
|
|
265
298
|
}
|
|
299
|
+
|
|
300
|
+
function onClickCell(cell, row) {
|
|
301
|
+
emit("click-cell", cell, row);
|
|
302
|
+
}
|
|
266
303
|
</script>
|
package/ui.data-table/config.js
CHANGED
|
@@ -56,11 +56,10 @@ export default /*tw*/ {
|
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
|
-
bodyCellNestedRow: "flex",
|
|
60
59
|
bodyCellContent: "text-ellipsis overflow-hidden",
|
|
61
60
|
bodyCellCheckbox: "first:px-4", // try to remove first
|
|
62
61
|
bodyCellDateDivider: "",
|
|
63
|
-
bodyCellNested: "mr-2
|
|
62
|
+
bodyCellNested: "mr-2 flex gap-0.5",
|
|
64
63
|
bodyCellNestedExpandIcon: {
|
|
65
64
|
component: "{UIcon}",
|
|
66
65
|
wrapper: "rounded-sm",
|
|
@@ -406,6 +406,7 @@ CellSlots.args = {
|
|
|
406
406
|
{ key: "tags", label: "tags" },
|
|
407
407
|
],
|
|
408
408
|
row: {
|
|
409
|
+
id: getRandomId(),
|
|
409
410
|
link: "some link",
|
|
410
411
|
money: {
|
|
411
412
|
sum: 10,
|
|
@@ -416,6 +417,36 @@ CellSlots.args = {
|
|
|
416
417
|
tags: { label: "some tag" },
|
|
417
418
|
variant: "orange",
|
|
418
419
|
},
|
|
420
|
+
row: [
|
|
421
|
+
{
|
|
422
|
+
id: getRandomId(),
|
|
423
|
+
isHidden: false,
|
|
424
|
+
link: "some link",
|
|
425
|
+
money: {
|
|
426
|
+
sum: 10,
|
|
427
|
+
currencySymbol: "$",
|
|
428
|
+
},
|
|
429
|
+
email: "some@email.ua",
|
|
430
|
+
tags: {
|
|
431
|
+
tags: { label: "some tag" },
|
|
432
|
+
variant: "orange",
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
id: getRandomId(),
|
|
437
|
+
isHidden: false,
|
|
438
|
+
link: "some link",
|
|
439
|
+
money: {
|
|
440
|
+
sum: 10,
|
|
441
|
+
currencySymbol: "$",
|
|
442
|
+
},
|
|
443
|
+
email: "some@email.ua",
|
|
444
|
+
tags: {
|
|
445
|
+
tags: { label: "some tag" },
|
|
446
|
+
variant: "orange",
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
],
|
|
419
450
|
},
|
|
420
451
|
|
|
421
452
|
slotTemplate: `
|
|
@@ -52,9 +52,6 @@ export default function useAttrs(
|
|
|
52
52
|
headerCellCheckbox: {
|
|
53
53
|
base: computed(() => [extendingKeysClasses.headerCellBase.value]),
|
|
54
54
|
},
|
|
55
|
-
bodyCellNestedRow: {
|
|
56
|
-
base: computed(() => [extendingKeysClasses.bodyCellBase.value]),
|
|
57
|
-
},
|
|
58
55
|
bodyCellCheckbox: {
|
|
59
56
|
base: computed(() => [extendingKeysClasses.bodyCellBase.value]),
|
|
60
57
|
},
|
|
@@ -60,12 +60,41 @@ export function getFlatRows(tableRows) {
|
|
|
60
60
|
function addRow(row) {
|
|
61
61
|
rows.push(row);
|
|
62
62
|
|
|
63
|
-
if (row.row) {
|
|
63
|
+
if (row.row && !Array.isArray(row.row)) {
|
|
64
64
|
addRow(row.row);
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
if (row.row && Array.isArray(row.row)) {
|
|
68
|
+
row.row.forEach(addRow);
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
tableRows.forEach((row) => addRow(row));
|
|
69
73
|
|
|
70
74
|
return rows;
|
|
71
75
|
}
|
|
76
|
+
|
|
77
|
+
export function rowsHasId(rows) {
|
|
78
|
+
const ids = new Set();
|
|
79
|
+
let totalRows = 0;
|
|
80
|
+
|
|
81
|
+
function addId(row) {
|
|
82
|
+
totalRows++;
|
|
83
|
+
|
|
84
|
+
if (typeof row.id !== "undefined") {
|
|
85
|
+
ids.add(row.id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (row.row && !Array.isArray(row.row)) {
|
|
89
|
+
addId(row.row);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (row.row && Array.isArray(row.row)) {
|
|
93
|
+
row.row.forEach(addId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
rows.forEach((row) => addId(row));
|
|
98
|
+
|
|
99
|
+
return ids.size === totalRows;
|
|
100
|
+
}
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"framework": "vue",
|
|
3
3
|
"name": "vueless",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.435",
|
|
5
5
|
"contributions": {
|
|
6
6
|
"html": {
|
|
7
7
|
"description-markup": "markdown",
|
|
@@ -8401,6 +8401,18 @@
|
|
|
8401
8401
|
}
|
|
8402
8402
|
]
|
|
8403
8403
|
},
|
|
8404
|
+
{
|
|
8405
|
+
"name": "clickCell",
|
|
8406
|
+
"description": "Triggers when the cell is clicked.",
|
|
8407
|
+
"properties": [
|
|
8408
|
+
{
|
|
8409
|
+
"type": [
|
|
8410
|
+
"object"
|
|
8411
|
+
],
|
|
8412
|
+
"name": "cell"
|
|
8413
|
+
}
|
|
8414
|
+
]
|
|
8415
|
+
},
|
|
8404
8416
|
{
|
|
8405
8417
|
"name": "update:rows",
|
|
8406
8418
|
"description": "Triggers when table rows are selected (updated).",
|
|
@@ -8615,6 +8627,9 @@
|
|
|
8615
8627
|
},
|
|
8616
8628
|
{
|
|
8617
8629
|
"name": "click"
|
|
8630
|
+
},
|
|
8631
|
+
{
|
|
8632
|
+
"name": "click-cell"
|
|
8618
8633
|
}
|
|
8619
8634
|
],
|
|
8620
8635
|
"slots": [
|