@stonecrop/atable 0.4.10 → 0.4.12

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.
@@ -2,7 +2,9 @@
2
2
  <table
3
3
  ref="table"
4
4
  class="atable"
5
- :style="{ width: store.config.fullWidth ? '100%' : 'auto' }"
5
+ :style="{
6
+ width: store.config.fullWidth ? '100%' : 'auto',
7
+ }"
6
8
  v-on-click-outside="store.closeModal">
7
9
  <slot name="header" :data="store">
8
10
  <ATableHeader :columns="store.columns" :store="store" />
@@ -11,21 +13,35 @@
11
13
  <tbody>
12
14
  <slot name="body" :data="store">
13
15
  <ARow v-for="(row, rowIndex) in store.rows" :key="row.id" :row="row" :rowIndex="rowIndex" :store="store">
14
- <ACell
15
- v-for="(col, colIndex) in store.columns"
16
- :key="col.name"
17
- :store="store"
18
- :col="col"
19
- spellcheck="false"
20
- :pinned="col.pinned"
21
- :rowIndex="rowIndex"
22
- :colIndex="colIndex"
23
- :component="col.cellComponent"
24
- :style="{
25
- textAlign: col?.align || 'center',
26
- minWidth: col?.width || '40ch',
27
- width: store.config.fullWidth ? 'auto' : null,
28
- }" />
16
+ <template v-for="(column, colIndex) in getProcessedColumnsForRow(row)" :key="column.name">
17
+ <component
18
+ v-if="column.isGantt"
19
+ :is="column.ganttComponent || 'AGanttCell'"
20
+ :store="store"
21
+ :color="row.gantt_color"
22
+ :colspan="column.colspan"
23
+ :pinned="column.pinned"
24
+ :rowIndex="rowIndex"
25
+ :colIndex="column.originalIndex ?? colIndex"
26
+ :style="{
27
+ textAlign: column?.align || 'center',
28
+ minWidth: column?.width || '40ch',
29
+ width: store.config.fullWidth ? 'auto' : null,
30
+ }" />
31
+ <component
32
+ v-else
33
+ :is="column.cellComponent || 'ACell'"
34
+ :store="store"
35
+ :pinned="column.pinned"
36
+ :rowIndex="rowIndex"
37
+ :colIndex="colIndex"
38
+ :style="{
39
+ textAlign: column?.align || 'center',
40
+ minWidth: column?.width || '40ch',
41
+ width: store.config.fullWidth ? 'auto' : null,
42
+ }"
43
+ spellcheck="false" />
44
+ </template>
29
45
  </ARow>
30
46
  </slot>
31
47
  </tbody>
@@ -52,7 +68,6 @@ import { vOnClickOutside } from '@vueuse/components'
52
68
  import { useMutationObserver } from '@vueuse/core'
53
69
  import { nextTick, watch, onMounted, useTemplateRef } from 'vue'
54
70
 
55
- import ACell from './ACell.vue'
56
71
  import ARow from './ARow.vue'
57
72
  import ATableHeader from './ATableHeader.vue'
58
73
  import ATableModal from './ATableModal.vue'
@@ -102,7 +117,7 @@ watch(
102
117
  )
103
118
 
104
119
  onMounted(() => {
105
- if (columns.some(col => col.pinned)) {
120
+ if (columns.some(column => column.pinned)) {
106
121
  assignStickyCellWidths()
107
122
 
108
123
  // in tree view, also add a mutation observer to capture and adjust expanded rows
@@ -163,6 +178,33 @@ window.addEventListener('keydown', (event: KeyboardEvent) => {
163
178
  }
164
179
  })
165
180
 
181
+ const getProcessedColumnsForRow = (row: TableRow) => {
182
+ const isGanttRow = row.indent === 0
183
+ const pinnedColumnCount = store.columns.filter(column => column.pinned).length
184
+ if (!isGanttRow || pinnedColumnCount === 0) {
185
+ return store.columns
186
+ }
187
+
188
+ // For Gantt views, first add the pinned columns
189
+ const result: TableColumn[] = []
190
+ for (let i = 0; i < pinnedColumnCount; i++) {
191
+ const column = { ...store.columns[i] }
192
+ column.originalIndex = i // Preserve original index
193
+ result.push(column)
194
+ }
195
+
196
+ // Finally, add the Gantt bar column with a full-width colspan
197
+ result.push({
198
+ ...store.columns[pinnedColumnCount],
199
+ isGantt: true,
200
+ colspan: store.columns.length - pinnedColumnCount,
201
+ originalIndex: pinnedColumnCount,
202
+ width: 'auto', // TODO: refactor to API that can detect when data exists in a cell. Might have be custom and not generalizable
203
+ })
204
+
205
+ return result
206
+ }
207
+
166
208
  defineExpose({ store })
167
209
  </script>
168
210
 
@@ -204,6 +246,7 @@ td.sticky-index {
204
246
  table-layout: auto;
205
247
  width: auto;
206
248
  overflow: clip;
249
+ height: 1px;
207
250
  /* border-left:4px solid var(--sc-form-border); */
208
251
  }
209
252
  .atable th {
@@ -224,4 +267,22 @@ td.sticky-index {
224
267
  .atable th:focus {
225
268
  outline: none;
226
269
  }
270
+
271
+ /* Make sure the vertical indicator doesn't extend into the header */
272
+ .atable:tbody {
273
+ overflow: hidden; /* This ensures the indicator is clipped */
274
+ position: relative; /* Create a stacking context */
275
+ }
276
+
277
+ /* Ensure the indicator stays within the tbody */
278
+ .atable:tbody::before {
279
+ content: '';
280
+ position: absolute;
281
+ top: 0;
282
+ left: 0;
283
+ right: 0;
284
+ height: 1px;
285
+ background-color: transparent;
286
+ z-index: 100;
287
+ }
227
288
  </style>
@@ -35,9 +35,6 @@ const { columns, store } = defineProps<{
35
35
  <style>
36
36
  @import url('@stonecrop/themes/default.css');
37
37
 
38
- .atable-header-row {
39
- display: flex;
40
- }
41
38
  .atable-header-row th {
42
39
  padding-left: 0.5ch !important;
43
40
  font-weight: 700;
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import { App } from 'vue'
2
2
 
3
3
  import ACell from './components/ACell.vue'
4
4
  import AExpansionRow from './components/AExpansionRow.vue'
5
+ import AGanttCell from './components/AGanttCell.vue'
5
6
  import ARow from './components/ARow.vue'
6
7
  import ATable from './components/ATable.vue'
7
8
  import ATableHeader from './components/ATableHeader.vue'
@@ -27,6 +28,7 @@ export type {
27
28
  function install(app: App /* options */) {
28
29
  app.component('ACell', ACell)
29
30
  app.component('AExpansionRow', AExpansionRow)
31
+ app.component('AGanttCell', AGanttCell)
30
32
  app.component('ARow', ARow)
31
33
  app.component('ATable', ATable)
32
34
  app.component('ATableHeader', ATableHeader)
@@ -35,4 +37,15 @@ function install(app: App /* options */) {
35
37
  app.component('ATableModal', ATableModal)
36
38
  }
37
39
 
38
- export { install, ACell, AExpansionRow, ARow, ATable, ATableHeader, ATableLoading, ATableLoadingBar, ATableModal }
40
+ export {
41
+ ACell,
42
+ AExpansionRow,
43
+ AGanttCell,
44
+ ARow,
45
+ ATable,
46
+ ATableHeader,
47
+ ATableLoading,
48
+ ATableLoadingBar,
49
+ ATableModal,
50
+ install,
51
+ }
@@ -119,6 +119,12 @@ export const createTableStore = (initData: {
119
119
  width: config.value.fullWidth ? 'auto' : undefined,
120
120
  })
121
121
 
122
+ const isRowGantt = (rowIndex: number) => {
123
+ const row = rows.value[rowIndex]
124
+ console.log(config.value.view, row.indent)
125
+ return config.value.view === 'gantt' && row.indent === 0
126
+ }
127
+
122
128
  const isRowVisible = (rowIndex: number) => {
123
129
  return config.value.view !== 'tree' || display.value[rowIndex].isRoot || display.value[rowIndex].open
124
130
  }
@@ -218,6 +224,7 @@ export const createTableStore = (initData: {
218
224
  getHeaderCellStyle,
219
225
  getIndent,
220
226
  getRowExpandSymbol,
227
+ isRowGantt,
221
228
  isRowVisible,
222
229
  setCellData,
223
230
  setCellText,
@@ -16,6 +16,12 @@ export type TableColumn = {
16
16
  width?: string
17
17
  pinned?: boolean
18
18
 
19
+ // Gantt-specific fields
20
+ colspan?: number
21
+ ganttComponent?: string
22
+ isGantt?: boolean
23
+ originalIndex?: number
24
+
19
25
  cellComponent?: string
20
26
  cellComponentProps?: Record<string, any>
21
27
  /**
@@ -61,7 +67,7 @@ export type TableConfig = {
61
67
  * - `list-expansion` - carets are displayed in the number column that expand/collapse the row inline
62
68
  * - `tree` - carets are displayed in the number column that expand/collapse grouped rows
63
69
  */
64
- view?: 'uncounted' | 'list' | 'list-expansion' | 'tree'
70
+ view?: 'uncounted' | 'list' | 'list-expansion' | 'tree' | 'gantt'
65
71
  fullWidth?: boolean
66
72
  }
67
73
 
@@ -88,6 +94,11 @@ export type TableRow = {
88
94
  [key: string]: any
89
95
  indent?: number
90
96
  parent?: number
97
+
98
+ /**
99
+ * When a table is being viewed as a Gantt chart, this colour would be applied to the row's gantt bar, if one exists.
100
+ */
101
+ gantt_color?: string
91
102
  }
92
103
 
93
104
  /**