svelte-tably 1.0.0-next.6 → 1.0.0-next.7
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/dist/Table.svelte +24 -11
- package/package.json +1 -1
package/dist/Table.svelte
CHANGED
|
@@ -180,7 +180,8 @@
|
|
|
180
180
|
const getWidth = (key: string, def: number = 150) => columnWidths[key] || table.columns[key]?.defaults.width || def
|
|
181
181
|
|
|
182
182
|
/** grid-template-columns for widths */
|
|
183
|
-
const style = $derived(
|
|
183
|
+
const style = $derived.by(() => {
|
|
184
|
+
const templateColumns = `
|
|
184
185
|
#${id} > .headers,
|
|
185
186
|
#${id} > .content > .rows > .row,
|
|
186
187
|
#${id} > .statusbar,
|
|
@@ -194,18 +195,29 @@
|
|
|
194
195
|
}).join(' ')
|
|
195
196
|
};
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
`
|
|
199
|
+
|
|
200
|
+
let sum = 0
|
|
201
|
+
const stickyLeft = sticky.map((key, i, arr) => {
|
|
202
|
+
sum += getWidth(arr[i - 1], i === 0 ? 0 : undefined)
|
|
203
|
+
return `
|
|
204
|
+
#${id} .column.sticky[data-column='${key}'] {
|
|
205
|
+
left: ${sum}px;
|
|
206
|
+
}
|
|
207
|
+
`
|
|
208
|
+
}).join('')
|
|
209
|
+
|
|
210
|
+
return templateColumns + stickyLeft
|
|
211
|
+
})
|
|
202
212
|
|
|
203
213
|
function observeColumnWidth(node: HTMLDivElement, isHeader = false) {
|
|
204
214
|
if(!isHeader) return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
|
|
216
|
+
const key = node.getAttribute('data-column')!
|
|
217
|
+
node.style.width = getWidth(key) + 'px'
|
|
218
|
+
|
|
219
|
+
const observer = new MutationObserver(() => columnWidths[key] = parseFloat(node.style.width))
|
|
220
|
+
|
|
209
221
|
observer.observe(node, {attributes: true})
|
|
210
222
|
return { destroy: () => observer.disconnect() }
|
|
211
223
|
}
|
|
@@ -241,7 +253,7 @@
|
|
|
241
253
|
{#if !table.positions.hidden.includes(column)}
|
|
242
254
|
{@const args = arg ? arg(column) : []}
|
|
243
255
|
<div
|
|
244
|
-
class='column sticky'
|
|
256
|
+
class='column sticky'
|
|
245
257
|
use:observeColumnWidth={isHeader}
|
|
246
258
|
data-column={column}
|
|
247
259
|
class:resizeable={table.columns[column].options.resizeable && table.resizeable}
|
|
@@ -284,6 +296,7 @@
|
|
|
284
296
|
{...props}
|
|
285
297
|
onpointerenter={() => hoveredRow = item}
|
|
286
298
|
onpointerleave={() => hoveredRow = null}
|
|
299
|
+
onclickcapture={e => !table.href && e.preventDefault()}
|
|
287
300
|
>
|
|
288
301
|
{#if table.selected && (((selectable === 'hover' && hoveredRow === item) || selectable === 'always') || table.selected.includes(item))}
|
|
289
302
|
<div class='select' class:hover={selectable === 'hover'}>
|