vueless 0.0.821 → 0.0.823
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 +25 -8
- package/ui.data-table/UTableRow.vue +6 -124
- package/ui.data-table/types.ts +6 -11
- package/ui.data-table/utilTable.ts +13 -9
package/package.json
CHANGED
package/ui.data-table/UTable.vue
CHANGED
|
@@ -45,6 +45,7 @@ import type {
|
|
|
45
45
|
UTableRowAttrs,
|
|
46
46
|
Config,
|
|
47
47
|
DateDivider,
|
|
48
|
+
FlatRow,
|
|
48
49
|
} from "./types.ts";
|
|
49
50
|
|
|
50
51
|
defineOptions({ inheritAttrs: false });
|
|
@@ -116,12 +117,12 @@ const actionHeaderRowRef = useTemplateRef<HTMLDivElement>("action-header-row");
|
|
|
116
117
|
const i18nGlobal = tm(COMPONENT_NAME);
|
|
117
118
|
const currentLocale = computed(() => merge({}, defaultConfig.i18n, i18nGlobal, props.config.i18n));
|
|
118
119
|
|
|
119
|
-
const sortedRows: ComputedRef<
|
|
120
|
+
const sortedRows: ComputedRef<FlatRow[]> = computed(() => {
|
|
120
121
|
const headerKeys = props.columns.map((column) =>
|
|
121
122
|
typeof column === "object" ? column.key : column,
|
|
122
123
|
);
|
|
123
124
|
|
|
124
|
-
return
|
|
125
|
+
return flatTableRows.value.map((row) => {
|
|
125
126
|
const rowEntries = Object.entries(row);
|
|
126
127
|
|
|
127
128
|
const sortedEntries: typeof rowEntries = new Array(rowEntries.length);
|
|
@@ -141,7 +142,7 @@ const sortedRows: ComputedRef<Row[]> = computed(() => {
|
|
|
141
142
|
|
|
142
143
|
const sortedRow = Object.fromEntries(sortedEntries.filter((value) => value));
|
|
143
144
|
|
|
144
|
-
return sortedRow as
|
|
145
|
+
return sortedRow as FlatRow;
|
|
145
146
|
});
|
|
146
147
|
});
|
|
147
148
|
|
|
@@ -188,7 +189,7 @@ const isCheckedMoreOneTableItems = computed(() => {
|
|
|
188
189
|
|
|
189
190
|
const tableRowWidthStyle = computed(() => ({ width: `${tableWidth.value / PX_IN_REM}rem` }));
|
|
190
191
|
|
|
191
|
-
const flatTableRows = computed(() => getFlatRows(
|
|
192
|
+
const flatTableRows = computed(() => getFlatRows(tableRows.value));
|
|
192
193
|
|
|
193
194
|
const isSelectedAllRows = computed(() => {
|
|
194
195
|
return selectedRows.value.length === flatTableRows.value.length;
|
|
@@ -266,6 +267,7 @@ function onWindowResize() {
|
|
|
266
267
|
function getDateDividerData(rowDate: string | Date | undefined) {
|
|
267
268
|
if (!rowDate) {
|
|
268
269
|
return {
|
|
270
|
+
date: "",
|
|
269
271
|
label: "",
|
|
270
272
|
config: {},
|
|
271
273
|
};
|
|
@@ -282,6 +284,7 @@ function getDateDividerData(rowDate: string | Date | undefined) {
|
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
return {
|
|
287
|
+
date: dividerItem?.date || "",
|
|
285
288
|
label: dividerItem?.label || String(rowDate),
|
|
286
289
|
config: dividerItem?.config,
|
|
287
290
|
};
|
|
@@ -415,8 +418,22 @@ function clearSelectedItems() {
|
|
|
415
418
|
selectedRows.value = [];
|
|
416
419
|
}
|
|
417
420
|
|
|
418
|
-
function onToggleRowVisibility(
|
|
419
|
-
|
|
421
|
+
function onToggleRowVisibility(row: FlatRow | Row) {
|
|
422
|
+
const nestedRows = flatTableRows.value.filter((flatRow) => flatRow.parentId === row.id);
|
|
423
|
+
|
|
424
|
+
if (row.nestedData && row.nestedData.hasOwnProperty("isShown")) {
|
|
425
|
+
row.nestedData.isShown = !row.nestedData.isShown;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (nestedRows.length) {
|
|
429
|
+
let updatedRows: Row[] = [];
|
|
430
|
+
|
|
431
|
+
nestedRows.forEach((nestedRow) => {
|
|
432
|
+
updatedRows = tableRows.value.map((row) => toggleRowVisibility({ ...row }, nestedRow.id));
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
tableRows.value = updatedRows;
|
|
436
|
+
}
|
|
420
437
|
}
|
|
421
438
|
|
|
422
439
|
function onToggleExpand(row: Row, expanded: boolean) {
|
|
@@ -695,7 +712,7 @@ const {
|
|
|
695
712
|
<UTableRow
|
|
696
713
|
v-for="(row, rowIndex) in sortedRows"
|
|
697
714
|
:key="row.id"
|
|
698
|
-
v-memo="[selectedRows.includes(row.id), isRowSelectedWithin(rowIndex)]"
|
|
715
|
+
v-memo="[selectedRows.includes(row.id), row.isShown, isRowSelectedWithin(rowIndex)]"
|
|
699
716
|
:selectable="selectable"
|
|
700
717
|
:row="row"
|
|
701
718
|
:is-date-divider="isShownDateDivider(rowIndex)"
|
|
@@ -705,7 +722,7 @@ const {
|
|
|
705
722
|
:date-divider-data="getDateDividerData(row.rowDate)"
|
|
706
723
|
:attrs="tableRowAttrs as unknown as UTableRowAttrs"
|
|
707
724
|
:cols-count="colsCount"
|
|
708
|
-
:nested-level="0"
|
|
725
|
+
:nested-level="Number(row.nestedLevel || 0)"
|
|
709
726
|
:empty-cell-label="emptyCellLabel"
|
|
710
727
|
:data-test="getDataTest('row')"
|
|
711
728
|
@click="onClickRow"
|
|
@@ -16,16 +16,7 @@ import UDivider from "../ui.container-divider/UDivider.vue";
|
|
|
16
16
|
import defaultConfig from "./config.ts";
|
|
17
17
|
import type { Config as UDividerConfig } from "../ui.container-divider/types.ts";
|
|
18
18
|
|
|
19
|
-
import type {
|
|
20
|
-
RowId,
|
|
21
|
-
Cell,
|
|
22
|
-
CellObject,
|
|
23
|
-
Row,
|
|
24
|
-
RowScopedExpandProps,
|
|
25
|
-
RowScopedProps,
|
|
26
|
-
UTableRowProps,
|
|
27
|
-
Config,
|
|
28
|
-
} from "./types.ts";
|
|
19
|
+
import type { RowId, Cell, CellObject, Row, UTableRowProps, Config } from "./types.ts";
|
|
29
20
|
|
|
30
21
|
const NESTED_ROW_SHIFT_REM = 1;
|
|
31
22
|
const LAST_NESTED_ROW_SHIFT_REM = 1.1;
|
|
@@ -71,13 +62,6 @@ const toggleIconConfig = computed(() => {
|
|
|
71
62
|
: props.attrs.bodyCellNestedExpandIconAttrs.value;
|
|
72
63
|
});
|
|
73
64
|
|
|
74
|
-
const isSingleNestedRow = computed(() => !Array.isArray(props.row.row));
|
|
75
|
-
|
|
76
|
-
const singleNestedRow = computed(() =>
|
|
77
|
-
Array.isArray(props.row.row) ? props.row.row.at(0) : props.row.row,
|
|
78
|
-
);
|
|
79
|
-
const nestedRows = computed(() => props.row.row as unknown as Row[]);
|
|
80
|
-
|
|
81
65
|
const isNestedRowEmpty = computed(() => {
|
|
82
66
|
if (!props.row.row) return true;
|
|
83
67
|
|
|
@@ -180,12 +164,6 @@ function getNestedCheckboxShift() {
|
|
|
180
164
|
return { transform: `translateX(${props.nestedLevel * LAST_NESTED_ROW_SHIFT_REM}rem)` };
|
|
181
165
|
}
|
|
182
166
|
|
|
183
|
-
function onClickToggleRowChild(rowId: string | number) {
|
|
184
|
-
if (props.row.row || props.row.nestedData) {
|
|
185
|
-
emit("toggleRowVisibility", rowId);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
167
|
function onClick(row: Row) {
|
|
190
168
|
emit("click", row);
|
|
191
169
|
}
|
|
@@ -224,20 +202,8 @@ function setElementTitle(element: HTMLElement) {
|
|
|
224
202
|
}
|
|
225
203
|
}
|
|
226
204
|
|
|
227
|
-
function onClickToggleIcon() {
|
|
228
|
-
|
|
229
|
-
onClickToggleRowChild(props.row.id);
|
|
230
|
-
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (isSingleNestedRow.value) {
|
|
235
|
-
onClickToggleRowChild((props.row.row as Row).id);
|
|
236
|
-
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
(props.row.row as Row[]).forEach(({ id }) => onClickToggleRowChild(id));
|
|
205
|
+
function onClickToggleIcon(row: Row) {
|
|
206
|
+
emit("toggleRowVisibility", row);
|
|
241
207
|
}
|
|
242
208
|
|
|
243
209
|
function onClickCell(cell: unknown | string | number, row: Row, key: string | number) {
|
|
@@ -296,7 +262,7 @@ const { getDataTest } = useUI<Config>(defaultConfig);
|
|
|
296
262
|
v-bind="attrs.bodySelectedDateDividerAttrs.value"
|
|
297
263
|
:config="
|
|
298
264
|
getMergedConfig({
|
|
299
|
-
defaultConfig: attrs.
|
|
265
|
+
defaultConfig: attrs.bodySelectedDateDividerAttrs.value.config,
|
|
300
266
|
globalConfig: dateDividerData.config,
|
|
301
267
|
}) as UDividerConfig
|
|
302
268
|
"
|
|
@@ -305,6 +271,7 @@ const { getDataTest } = useUI<Config>(defaultConfig);
|
|
|
305
271
|
</tr>
|
|
306
272
|
|
|
307
273
|
<tr
|
|
274
|
+
v-if="row.isShown || typeof row.isShown === 'undefined'"
|
|
308
275
|
v-bind="{ ...$attrs, ...getRowAttrs(row) }"
|
|
309
276
|
:class="cx([getRowAttrs(row).class, getRowClasses(row)])"
|
|
310
277
|
@click="onClick(props.row)"
|
|
@@ -340,7 +307,7 @@ const { getDataTest } = useUI<Config>(defaultConfig);
|
|
|
340
307
|
>
|
|
341
308
|
<div
|
|
342
309
|
:data-row-toggle-icon="row.id"
|
|
343
|
-
@click.stop="() => (onClickToggleIcon(), onToggleExpand(row))"
|
|
310
|
+
@click.stop="() => (onClickToggleIcon(row), onToggleExpand(row))"
|
|
344
311
|
>
|
|
345
312
|
<slot name="expand" :row="row" :expanded="isExpanded(row)">
|
|
346
313
|
<div
|
|
@@ -403,89 +370,4 @@ const { getDataTest } = useUI<Config>(defaultConfig);
|
|
|
403
370
|
</td>
|
|
404
371
|
</tr>
|
|
405
372
|
</template>
|
|
406
|
-
|
|
407
|
-
<UTableRow
|
|
408
|
-
v-if="isSingleNestedRow && singleNestedRow && singleNestedRow.isShown && !row.nestedData"
|
|
409
|
-
v-bind="{
|
|
410
|
-
...$attrs,
|
|
411
|
-
...getRowAttrs(singleNestedRow),
|
|
412
|
-
}"
|
|
413
|
-
:is-date-divider="isDateDivider"
|
|
414
|
-
:selected-within="selectedWithin"
|
|
415
|
-
:date-divider-data="dateDividerData"
|
|
416
|
-
:cols-count="colsCount"
|
|
417
|
-
:class="cx([getRowAttrs(singleNestedRow).class, getRowClasses(singleNestedRow)])"
|
|
418
|
-
:attrs="attrs"
|
|
419
|
-
:columns="columns"
|
|
420
|
-
:row="row.row as Row"
|
|
421
|
-
:data-test="getDataTest()"
|
|
422
|
-
:nested-level="nestedLevel + 1"
|
|
423
|
-
:config="config"
|
|
424
|
-
:selectable="selectable"
|
|
425
|
-
:empty-cell-label="emptyCellLabel"
|
|
426
|
-
@toggle-checkbox="onInputCheckbox"
|
|
427
|
-
@toggle-expand="onToggleExpand"
|
|
428
|
-
@toggle-row-visibility="onClickToggleRowChild"
|
|
429
|
-
@click="onClick"
|
|
430
|
-
@dblclick="onDoubleClick"
|
|
431
|
-
>
|
|
432
|
-
<template
|
|
433
|
-
v-for="(value, key, index) in mapRowColumns(singleNestedRow, columns)"
|
|
434
|
-
:key="index"
|
|
435
|
-
#[`cell-${key}`]="slotValues: RowScopedProps"
|
|
436
|
-
>
|
|
437
|
-
<slot :name="`cell-${key}`" :value="slotValues.value" :row="slotValues.row" :index="index" />
|
|
438
|
-
</template>
|
|
439
|
-
|
|
440
|
-
<template #expand="slotValues: RowScopedExpandProps">
|
|
441
|
-
<slot name="expand" :row="slotValues.row" :expanded="slotValues.expanded" />
|
|
442
|
-
</template>
|
|
443
|
-
</UTableRow>
|
|
444
|
-
|
|
445
|
-
<template v-if="!isSingleNestedRow && nestedRows.length && !row.nestedData">
|
|
446
|
-
<template v-for="nestedRow in nestedRows" :key="nestedRow.id">
|
|
447
|
-
<UTableRow
|
|
448
|
-
v-if="nestedRow.isShown"
|
|
449
|
-
v-bind="{
|
|
450
|
-
...$attrs,
|
|
451
|
-
...getRowAttrs(nestedRow),
|
|
452
|
-
}"
|
|
453
|
-
:class="cx([getRowAttrs(nestedRow).class, getRowClasses(nestedRow)])"
|
|
454
|
-
:attrs="attrs"
|
|
455
|
-
:is-date-divider="isDateDivider"
|
|
456
|
-
:selected-within="selectedWithin"
|
|
457
|
-
:date-divider-data="dateDividerData"
|
|
458
|
-
:cols-count="colsCount"
|
|
459
|
-
:columns="columns"
|
|
460
|
-
:row="nestedRow"
|
|
461
|
-
:data-test="getDataTest()"
|
|
462
|
-
:nested-level="nestedLevel + 1"
|
|
463
|
-
:config="config"
|
|
464
|
-
:selectable="selectable"
|
|
465
|
-
:empty-cell-label="emptyCellLabel"
|
|
466
|
-
@toggle-expand="onToggleExpand"
|
|
467
|
-
@toggle-row-visibility="onClickToggleRowChild"
|
|
468
|
-
@click="onClick"
|
|
469
|
-
@dblclick="onDoubleClick"
|
|
470
|
-
@click-cell="onClickCell"
|
|
471
|
-
@toggle-checkbox="onInputCheckbox"
|
|
472
|
-
>
|
|
473
|
-
<template
|
|
474
|
-
v-for="(value, key, index) in mapRowColumns(nestedRow, columns)"
|
|
475
|
-
:key="index"
|
|
476
|
-
#[`cell-${key}`]="slotValues: RowScopedProps"
|
|
477
|
-
>
|
|
478
|
-
<slot
|
|
479
|
-
:name="`cell-${key}`"
|
|
480
|
-
:value="slotValues.value"
|
|
481
|
-
:row="slotValues.row"
|
|
482
|
-
:index="index"
|
|
483
|
-
/>
|
|
484
|
-
</template>
|
|
485
|
-
<template #expand="slotValues: RowScopedExpandProps">
|
|
486
|
-
<slot name="expand" :row="slotValues.row" :expanded="slotValues.expanded" />
|
|
487
|
-
</template>
|
|
488
|
-
</UTableRow>
|
|
489
|
-
</template>
|
|
490
|
-
</template>
|
|
491
373
|
</template>
|
package/ui.data-table/types.ts
CHANGED
|
@@ -38,6 +38,11 @@ export interface Row {
|
|
|
38
38
|
[key: string]: Cell | RowKeys;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
export interface FlatRow extends Row {
|
|
42
|
+
parentId?: RowId;
|
|
43
|
+
nestedLeveL: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
export interface ColumnObject {
|
|
42
47
|
key: string;
|
|
43
48
|
label?: string;
|
|
@@ -49,16 +54,6 @@ export interface ColumnObject {
|
|
|
49
54
|
|
|
50
55
|
export type Column = ColumnObject | string;
|
|
51
56
|
|
|
52
|
-
export interface RowScopedProps {
|
|
53
|
-
value: unknown | string | number;
|
|
54
|
-
row: Row;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface RowScopedExpandProps {
|
|
58
|
-
expanded: boolean;
|
|
59
|
-
row: Row;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
57
|
export interface UTableProps {
|
|
63
58
|
/**
|
|
64
59
|
* Table columns (headers).
|
|
@@ -135,7 +130,7 @@ export interface UTableRowAttrs {
|
|
|
135
130
|
}
|
|
136
131
|
|
|
137
132
|
export interface UTableRowProps {
|
|
138
|
-
row:
|
|
133
|
+
row: FlatRow;
|
|
139
134
|
columns: ColumnObject[];
|
|
140
135
|
emptyCellLabel?: string;
|
|
141
136
|
selectable: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getRandomId } from "../utils/helper.ts";
|
|
2
2
|
|
|
3
|
-
import type { Column, ColumnObject, Row, RowData, RowId } from "./types.ts";
|
|
3
|
+
import type { Column, ColumnObject, FlatRow, Row, RowData, RowId } from "./types.ts";
|
|
4
4
|
|
|
5
5
|
export function normalizeColumns(columns: Column[]): ColumnObject[] {
|
|
6
6
|
return columns.map((column) =>
|
|
@@ -50,8 +50,6 @@ export function toggleRowVisibility(row: Row, targetRowId: string | number) {
|
|
|
50
50
|
if (row.id === targetRowId) {
|
|
51
51
|
if (row.hasOwnProperty("isShown")) {
|
|
52
52
|
row.isShown = !row.isShown;
|
|
53
|
-
} else if (row.nestedData && row.nestedData.hasOwnProperty("isShown")) {
|
|
54
|
-
row.nestedData.isShown = !row.nestedData.isShown;
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
return row;
|
|
@@ -87,21 +85,27 @@ export function switchRowCheck(row: Row, isChecked: boolean) {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
export function getFlatRows(tableRows: Row[]) {
|
|
90
|
-
const rows:
|
|
88
|
+
const rows: FlatRow[] = [];
|
|
91
89
|
|
|
92
|
-
function addRow(row: Row) {
|
|
93
|
-
|
|
90
|
+
function addRow(row: Row, nestedLevel: number, parentId?: string | number) {
|
|
91
|
+
if (parentId) {
|
|
92
|
+
row.parentId = parentId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
row.nestedLevel = nestedLevel;
|
|
96
|
+
|
|
97
|
+
rows.push(row as FlatRow);
|
|
94
98
|
|
|
95
99
|
if (row.row && !Array.isArray(row.row)) {
|
|
96
|
-
addRow(row.row);
|
|
100
|
+
addRow(row.row, nestedLevel + 1, row.id);
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
if (row.row && Array.isArray(row.row)) {
|
|
100
|
-
row.row.forEach(addRow);
|
|
104
|
+
row.row.forEach((nestedRow) => addRow(nestedRow, nestedLevel + 1, row.id));
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
tableRows.forEach((row) => addRow(row));
|
|
108
|
+
tableRows.forEach((row) => addRow(row, 0));
|
|
105
109
|
|
|
106
110
|
return rows;
|
|
107
111
|
}
|