vueless 0.0.433 → 0.0.434

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": "vueless",
3
- "version": "0.0.433",
3
+ "version": "0.0.434",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -297,6 +297,7 @@ import {
297
297
  toggleRowVisibility,
298
298
  switchRowCheck,
299
299
  getFlatRows,
300
+ rowsHasId,
300
301
  } from "./utilTable.js";
301
302
 
302
303
  import { PX_IN_REM } from "../constants.js";
@@ -563,6 +564,16 @@ watch(
563
564
  tableRows.value = tableRows.value.map((row) => syncRowCheck(row, selectedRows.value));
564
565
  },
565
566
  );
567
+ watch(
568
+ () => props.rows,
569
+ () => {
570
+ if (!rowsHasId(props.rows)) {
571
+ // eslint-disable-next-line no-console
572
+ console.warn("[Vueless][UTable]: Each table row must have unique id.");
573
+ }
574
+ },
575
+ { deep: true, immediate: true },
576
+ );
566
577
 
567
578
  onMounted(() => {
568
579
  tableRows.value = props.rows;
@@ -18,10 +18,8 @@
18
18
  <td
19
19
  v-for="(value, key, index) in getFilteredRow(row, columns)"
20
20
  :key="index"
21
- v-bind="getCellAttrs(row, index)"
22
- :class="
23
- cx([getCellAttrs(row, index).class, columns[index].tdClass, getCellClasses(row, key)])
24
- "
21
+ v-bind="bodyCellBaseAttrs"
22
+ :class="cx([columns[index].tdClass, getCellClasses(row, key)])"
25
23
  >
26
24
  <div
27
25
  v-if="(row.row || nestedLevel || row.nestedData) && index === 0"
@@ -36,20 +34,33 @@
36
34
  :name="getToggleIconName(row)"
37
35
  color="brand"
38
36
  v-bind="toggleIconConfig"
39
- @click="onClickToggleIcon"
37
+ @click.stop="onClickToggleIcon"
40
38
  />
39
+
40
+ <slot :name="`cell-${key}`" :value="value" :row="row" :index="index">
41
+ <div
42
+ v-bind="bodyCellContentAttrs"
43
+ ref="cellRef"
44
+ :class="cx([bodyCellContentAttrs.class, getCellContentClasses(row, key)])"
45
+ :data-test="`${dataTest}-${key}-cell`"
46
+ >
47
+ {{ value.value || value || HYPHEN_SYMBOL }}
48
+ </div>
49
+ </slot>
41
50
  </div>
42
51
 
43
- <slot :name="`cell-${key}`" :value="value" :row="row" :index="index">
44
- <div
45
- v-bind="bodyCellContentAttrs"
46
- ref="cellRef"
47
- :class="cx([bodyCellContentAttrs.class, getCellContentClasses(row, key)])"
48
- :data-test="`${dataTest}-${key}-cell`"
49
- >
50
- {{ value.value || value || HYPHEN_SYMBOL }}
51
- </div>
52
- </slot>
52
+ <template v-else>
53
+ <slot :name="`cell-${key}`" :value="value" :row="row" :index="index">
54
+ <div
55
+ v-bind="bodyCellContentAttrs"
56
+ ref="cellRef"
57
+ :class="cx([bodyCellContentAttrs.class, getCellContentClasses(row, key)])"
58
+ :data-test="`${dataTest}-${key}-cell`"
59
+ >
60
+ {{ value.value || value || HYPHEN_SYMBOL }}
61
+ </div>
62
+ </slot>
63
+ </template>
53
64
  </td>
54
65
  </tr>
55
66
 
@@ -78,7 +89,15 @@
78
89
  :selectable="selectable"
79
90
  @toggle-row-visibility="onClickToggleRowChild"
80
91
  @click="onClick"
81
- />
92
+ >
93
+ <template
94
+ v-for="(value, key, index) in getFilteredRow(row.row, columns)"
95
+ :key="index"
96
+ #[`cell-${key}`]="slotValues"
97
+ >
98
+ <slot :name="`cell-${key}`" :value="slotValues.value" :row="slotValues.row" :index="index" />
99
+ </template>
100
+ </UTableRow>
82
101
 
83
102
  <template v-if="!isSingleNestedRow && row.row.length && !row.nestedData">
84
103
  <template v-for="nestedRow in row.row" :key="nestedRow.id">
@@ -95,7 +114,20 @@
95
114
  :selectable="selectable"
96
115
  @toggle-row-visibility="onClickToggleRowChild"
97
116
  @click="onClick"
98
- />
117
+ >
118
+ <template
119
+ v-for="(value, key, index) in getFilteredRow(nestedRow, columns)"
120
+ :key="index"
121
+ #[`cell-${key}`]="slotValues"
122
+ >
123
+ <slot
124
+ :name="`cell-${key}`"
125
+ :value="slotValues.value"
126
+ :row="slotValues.row"
127
+ :index="index"
128
+ />
129
+ </template>
130
+ </UTableRow>
99
131
  </template>
100
132
  </template>
101
133
  </template>
@@ -172,7 +204,6 @@ const {
172
204
  bodyCellNestedAttrs,
173
205
  bodyCellNestedExpandIconAttrs,
174
206
  bodyCellNestedCollapseIconAttrs,
175
- bodyCellNestedRowAttrs,
176
207
  bodyCellBaseAttrs,
177
208
  } = props.attrs;
178
209
 
@@ -206,12 +237,6 @@ function getCellContentClasses(row, key) {
206
237
  return typeof cellClasses === "function" ? cellClasses(row[key].value, row) : cellClasses;
207
238
  }
208
239
 
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
240
  function getNestedShift() {
216
241
  return { marginLeft: `${props.nestedLevel * shift.value}rem` };
217
242
  }
@@ -255,6 +280,12 @@ function setElementTitle(element) {
255
280
  }
256
281
 
257
282
  function onClickToggleIcon() {
283
+ if (props.row.nestedData) {
284
+ onClickToggleRowChild(props.row.id);
285
+
286
+ return;
287
+ }
288
+
258
289
  if (isSingleNestedRow.value) {
259
290
  onClickToggleRowChild(props.row.row.id);
260
291
 
@@ -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 mt-0.5",
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.433",
4
+ "version": "0.0.434",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",