@stonecrop/atable 0.2.40 → 0.2.41

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": "@stonecrop/atable",
3
- "version": "0.2.40",
3
+ "version": "0.2.41",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -35,8 +35,8 @@
35
35
  "@vueuse/core": "^11.1.0",
36
36
  "uuid": "^10.0.0",
37
37
  "vue": "^3.5.6",
38
- "@stonecrop/utilities": "0.2.40",
39
- "@stonecrop/themes": "0.2.40"
38
+ "@stonecrop/utilities": "0.2.41",
39
+ "@stonecrop/themes": "0.2.41"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@microsoft/api-documenter": "^7.25.3",
@@ -28,6 +28,7 @@
28
28
 
29
29
  <script setup lang="ts">
30
30
  import { KeypressHandlers, defaultKeypressHandlers, useKeyboardNav } from '@stonecrop/utilities'
31
+ import { useElementBounding } from '@vueuse/core'
31
32
  import { computed, CSSProperties, inject, ref, useTemplateRef } from 'vue'
32
33
 
33
34
  import TableDataStore from '.'
@@ -57,6 +58,14 @@ const table = tableData.table
57
58
  const column = tableData.columns[colIndex]
58
59
  const row = tableData.rows[rowIndex]
59
60
 
61
+ const textAlign = computed(() => {
62
+ return column.align || 'center'
63
+ })
64
+
65
+ const cellWidth = computed(() => {
66
+ return column.width || '40ch'
67
+ })
68
+
60
69
  const displayValue = computed(() => {
61
70
  const cellData = tableData.cellData<any>(colIndex, rowIndex)
62
71
  const format = column.format
@@ -84,13 +93,13 @@ const handleInput = () => {
84
93
  }
85
94
 
86
95
  if (column.modalComponent) {
87
- const domRect = cellRef.value.getBoundingClientRect()
96
+ const { top, left, height } = useElementBounding(cellRef)
88
97
  tableData.modal.visible = true
89
98
  tableData.modal.colIndex = colIndex
90
99
  tableData.modal.rowIndex = rowIndex
91
100
  tableData.modal.parent = cellRef.value
92
- tableData.modal.top = domRect.top + domRect.height
93
- tableData.modal.left = domRect.left
101
+ tableData.modal.top = top.value + height.value
102
+ tableData.modal.left = left.value
94
103
  tableData.modal.width = cellWidth.value
95
104
 
96
105
  if (typeof column.modalComponent === 'function') {
@@ -140,14 +149,6 @@ if (addNavigation) {
140
149
  // }
141
150
  // }
142
151
 
143
- const textAlign = computed(() => {
144
- return column.align || 'center'
145
- })
146
-
147
- const cellWidth = computed(() => {
148
- return column.width || '40ch'
149
- })
150
-
151
152
  const onFocus = () => {
152
153
  if (cellRef.value) {
153
154
  currentData.value = cellRef.value.textContent
@@ -63,6 +63,7 @@
63
63
 
64
64
  <script setup lang="ts">
65
65
  import { vOnClickOutside } from '@vueuse/components'
66
+ import { useMutationObserver } from '@vueuse/core'
66
67
  import { nextTick, provide, watch, onMounted, useTemplateRef } from 'vue'
67
68
 
68
69
  import TableDataStore from '.'
@@ -102,12 +103,13 @@ watch(
102
103
  )
103
104
 
104
105
  onMounted(() => {
105
- assignStickyCellWidths()
106
+ if (columns.some(col => col.pinned)) {
107
+ assignStickyCellWidths()
106
108
 
107
- // in tree view, a mutation observer is needed to capture and adjust expanded rows
108
- if (tableData.config.view === 'tree') {
109
- const observer = new MutationObserver(() => assignStickyCellWidths())
110
- observer.observe(tableRef.value, { childList: true, subtree: true })
109
+ // in tree view, also add a mutation observer to capture and adjust expanded rows
110
+ if (tableData.config.view === 'tree') {
111
+ useMutationObserver(tableRef, assignStickyCellWidths, { childList: true, subtree: true })
112
+ }
111
113
  }
112
114
  })
113
115
 
@@ -115,10 +117,14 @@ const assignStickyCellWidths = () => {
115
117
  const table = tableRef.value
116
118
 
117
119
  // set header cell width to match sticky cells' width
118
- const headerCells = Array.from(table.rows[0].cells)
120
+ const headerRow = table.rows[0]
121
+ const firstDataRow = table.rows[1]
122
+ const headerCells = headerRow ? Array.from(headerRow.cells) : []
119
123
  for (const [index, headerCell] of headerCells.entries()) {
120
- const rowCell = table.rows[1].cells[index]
121
- headerCell.style.width = `${rowCell.offsetWidth}px`
124
+ const rowCell = firstDataRow.cells[index]
125
+ if (rowCell) {
126
+ headerCell.style.width = `${rowCell.offsetWidth}px`
127
+ }
122
128
  }
123
129
 
124
130
  // pin cells in row that are sticky